Skip to content

Commit 836196b

Browse files
captain5050Ingo Molnar
authored andcommitted
perf/core: Add per perf_cpu_context min_heap storage
The storage required for visit_groups_merge's min heap needs to vary in order to support more iterators, such as when multiple nested cgroups' events are being visited. This change allows for 2 iterators and doesn't support growth. Based-on-work-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 6eef8a7 commit 836196b

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

include/linux/perf_event.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,13 @@ struct perf_cpu_context {
862862
int sched_cb_usage;
863863

864864
int online;
865+
/*
866+
* Per-CPU storage for iterators used in visit_groups_merge. The default
867+
* storage is of size 2 to hold the CPU and any CPU event iterators.
868+
*/
869+
int heap_size;
870+
struct perf_event **heap;
871+
struct perf_event *heap_default[2];
865872
};
866873

867874
struct perf_output_handle {

kernel/events/core.c

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,22 +3423,34 @@ static void __heap_add(struct min_heap *heap, struct perf_event *event)
34233423
}
34243424
}
34253425

3426-
static noinline int visit_groups_merge(struct perf_event_groups *groups,
3427-
int cpu,
3426+
static noinline int visit_groups_merge(struct perf_cpu_context *cpuctx,
3427+
struct perf_event_groups *groups, int cpu,
34283428
int (*func)(struct perf_event *, void *),
34293429
void *data)
34303430
{
34313431
/* Space for per CPU and/or any CPU event iterators. */
34323432
struct perf_event *itrs[2];
3433-
struct min_heap event_heap = {
3434-
.data = itrs,
3435-
.nr = 0,
3436-
.size = ARRAY_SIZE(itrs),
3437-
};
3438-
struct perf_event **evt = event_heap.data;
3433+
struct min_heap event_heap;
3434+
struct perf_event **evt;
34393435
int ret;
34403436

3441-
__heap_add(&event_heap, perf_event_groups_first(groups, -1));
3437+
if (cpuctx) {
3438+
event_heap = (struct min_heap){
3439+
.data = cpuctx->heap,
3440+
.nr = 0,
3441+
.size = cpuctx->heap_size,
3442+
};
3443+
} else {
3444+
event_heap = (struct min_heap){
3445+
.data = itrs,
3446+
.nr = 0,
3447+
.size = ARRAY_SIZE(itrs),
3448+
};
3449+
/* Events not within a CPU context may be on any CPU. */
3450+
__heap_add(&event_heap, perf_event_groups_first(groups, -1));
3451+
}
3452+
evt = event_heap.data;
3453+
34423454
__heap_add(&event_heap, perf_event_groups_first(groups, cpu));
34433455

34443456
min_heapify_all(&event_heap, &perf_min_heap);
@@ -3492,7 +3504,10 @@ ctx_pinned_sched_in(struct perf_event_context *ctx,
34923504
{
34933505
int can_add_hw = 1;
34943506

3495-
visit_groups_merge(&ctx->pinned_groups,
3507+
if (ctx != &cpuctx->ctx)
3508+
cpuctx = NULL;
3509+
3510+
visit_groups_merge(cpuctx, &ctx->pinned_groups,
34963511
smp_processor_id(),
34973512
merge_sched_in, &can_add_hw);
34983513
}
@@ -3503,7 +3518,10 @@ ctx_flexible_sched_in(struct perf_event_context *ctx,
35033518
{
35043519
int can_add_hw = 1;
35053520

3506-
visit_groups_merge(&ctx->flexible_groups,
3521+
if (ctx != &cpuctx->ctx)
3522+
cpuctx = NULL;
3523+
3524+
visit_groups_merge(cpuctx, &ctx->flexible_groups,
35073525
smp_processor_id(),
35083526
merge_sched_in, &can_add_hw);
35093527
}
@@ -10364,6 +10382,9 @@ int perf_pmu_register(struct pmu *pmu, const char *name, int type)
1036410382
cpuctx->online = cpumask_test_cpu(cpu, perf_online_mask);
1036510383

1036610384
__perf_mux_hrtimer_init(cpuctx, cpu);
10385+
10386+
cpuctx->heap_size = ARRAY_SIZE(cpuctx->heap_default);
10387+
cpuctx->heap = cpuctx->heap_default;
1036710388
}
1036810389

1036910390
got_cpu_context:

0 commit comments

Comments
 (0)