Skip to content

Commit e19cd0b

Browse files
Chengming ZhouPeter Zijlstra
authored andcommitted
perf/core: Always set cpuctx cgrp when enable cgroup event
When enable a cgroup event, cpuctx->cgrp setting is conditional on the current task cgrp matching the event's cgroup, so have to do it for every new event. It brings complexity but no advantage. To keep it simple, this patch would always set cpuctx->cgrp when enable the first cgroup event, and reset to NULL when disable the last cgroup event. Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/r/20220329154523.86438-5-zhouchengming@bytedance.com
1 parent 96492a6 commit e19cd0b

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

kernel/events/core.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -967,22 +967,10 @@ perf_cgroup_event_enable(struct perf_event *event, struct perf_event_context *ct
967967
*/
968968
cpuctx = container_of(ctx, struct perf_cpu_context, ctx);
969969

970-
/*
971-
* Since setting cpuctx->cgrp is conditional on the current @cgrp
972-
* matching the event's cgroup, we must do this for every new event,
973-
* because if the first would mismatch, the second would not try again
974-
* and we would leave cpuctx->cgrp unset.
975-
*/
976-
if (ctx->is_active && !cpuctx->cgrp) {
977-
struct perf_cgroup *cgrp = perf_cgroup_from_task(current, ctx);
978-
979-
if (cgroup_is_descendant(cgrp->css.cgroup, event->cgrp->css.cgroup))
980-
cpuctx->cgrp = cgrp;
981-
}
982-
983970
if (ctx->nr_cgroups++)
984971
return;
985972

973+
cpuctx->cgrp = perf_cgroup_from_task(current, ctx);
986974
list_add(&cpuctx->cgrp_cpuctx_entry,
987975
per_cpu_ptr(&cgrp_cpuctx_list, event->cpu));
988976
}
@@ -1004,9 +992,7 @@ perf_cgroup_event_disable(struct perf_event *event, struct perf_event_context *c
1004992
if (--ctx->nr_cgroups)
1005993
return;
1006994

1007-
if (ctx->is_active && cpuctx->cgrp)
1008-
cpuctx->cgrp = NULL;
1009-
995+
cpuctx->cgrp = NULL;
1010996
list_del(&cpuctx->cgrp_cpuctx_entry);
1011997
}
1012998

0 commit comments

Comments
 (0)