Skip to content

Commit a48a36b

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf: Add PERF_EV_CAP_READ_SCOPE
Usually, an event can be read from any CPU of the scope. It doesn't need to be read from the advertised CPU. Add a new event cap, PERF_EV_CAP_READ_SCOPE. An event of a PMU with scope can be read from any active CPU in the scope. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20240802151643.1691631-3-kan.liang@linux.intel.com
1 parent 4ba4f1a commit a48a36b

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

include/linux/perf_event.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,13 @@ typedef void (*perf_overflow_handler_t)(struct perf_event *,
636636
* PERF_EV_CAP_SIBLING: An event with this flag must be a group sibling and
637637
* cannot be a group leader. If an event with this flag is detached from the
638638
* group it is scheduled out and moved into an unrecoverable ERROR state.
639+
* PERF_EV_CAP_READ_SCOPE: A CPU event that can be read from any CPU of the
640+
* PMU scope where it is active.
639641
*/
640642
#define PERF_EV_CAP_SOFTWARE BIT(0)
641643
#define PERF_EV_CAP_READ_ACTIVE_PKG BIT(1)
642644
#define PERF_EV_CAP_SIBLING BIT(2)
645+
#define PERF_EV_CAP_READ_SCOPE BIT(3)
643646

644647
#define SWEVENT_HLIST_BITS 8
645648
#define SWEVENT_HLIST_SIZE (1 << SWEVENT_HLIST_BITS)

kernel/events/core.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4556,16 +4556,24 @@ struct perf_read_data {
45564556
int ret;
45574557
};
45584558

4559+
static inline const struct cpumask *perf_scope_cpu_topology_cpumask(unsigned int scope, int cpu);
4560+
45594561
static int __perf_event_read_cpu(struct perf_event *event, int event_cpu)
45604562
{
4563+
int local_cpu = smp_processor_id();
45614564
u16 local_pkg, event_pkg;
45624565

45634566
if ((unsigned)event_cpu >= nr_cpu_ids)
45644567
return event_cpu;
45654568

4566-
if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) {
4567-
int local_cpu = smp_processor_id();
4569+
if (event->group_caps & PERF_EV_CAP_READ_SCOPE) {
4570+
const struct cpumask *cpumask = perf_scope_cpu_topology_cpumask(event->pmu->scope, event_cpu);
4571+
4572+
if (cpumask && cpumask_test_cpu(local_cpu, cpumask))
4573+
return local_cpu;
4574+
}
45684575

4576+
if (event->group_caps & PERF_EV_CAP_READ_ACTIVE_PKG) {
45694577
event_pkg = topology_physical_package_id(event_cpu);
45704578
local_pkg = topology_physical_package_id(local_cpu);
45714579

@@ -11905,7 +11913,7 @@ static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
1190511913
if (cpu >= nr_cpu_ids)
1190611914
ret = -ENODEV;
1190711915
else
11908-
event->cpu = cpu;
11916+
event->event_caps |= PERF_EV_CAP_READ_SCOPE;
1190911917
} else {
1191011918
ret = -ENODEV;
1191111919
}

0 commit comments

Comments
 (0)