Commit f841b68
perf/core: Fix cgroup events tracking
We encounter perf warnings when using cgroup events like:
cd /sys/fs/cgroup
mkdir test
perf stat -e cycles -a -G test
Which then triggers:
WARNING: CPU: 0 PID: 690 at kernel/events/core.c:849 perf_cgroup_switch+0xb2/0xc0
Call Trace:
<TASK>
__schedule+0x4ae/0x9f0
? _raw_spin_unlock_irqrestore+0x23/0x40
? __cond_resched+0x18/0x20
preempt_schedule_common+0x2d/0x70
__cond_resched+0x18/0x20
wait_for_completion+0x2f/0x160
? cpu_stop_queue_work+0x9e/0x130
affine_move_task+0x18a/0x4f0
WARNING: CPU: 0 PID: 690 at kernel/events/core.c:829 ctx_sched_in+0x1cf/0x1e0
Call Trace:
<TASK>
? ctx_sched_out+0xb7/0x1b0
perf_cgroup_switch+0x88/0xc0
__schedule+0x4ae/0x9f0
? _raw_spin_unlock_irqrestore+0x23/0x40
? __cond_resched+0x18/0x20
preempt_schedule_common+0x2d/0x70
__cond_resched+0x18/0x20
wait_for_completion+0x2f/0x160
? cpu_stop_queue_work+0x9e/0x130
affine_move_task+0x18a/0x4f0
The above two warnings are not complete here since I remove other
unimportant information. The problem is caused by the perf cgroup
events tracking:
CPU0 CPU1
perf_event_open()
perf_event_alloc()
account_event()
account_event_cpu()
atomic_inc(perf_cgroup_events)
__perf_event_task_sched_out()
if (atomic_read(perf_cgroup_events))
perf_cgroup_switch()
// kernel/events/core.c:849
WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0)
if (READ_ONCE(cpuctx->cgrp) == cgrp) // false
return
perf_ctx_lock()
ctx_sched_out()
cpuctx->cgrp = cgrp
ctx_sched_in()
perf_cgroup_set_timestamp()
// kernel/events/core.c:829
WARN_ON_ONCE(!ctx->nr_cgroups)
perf_ctx_unlock()
perf_install_in_context()
cpu_function_call()
__perf_install_in_context()
add_event_to_ctx()
list_add_event()
perf_cgroup_event_enable()
ctx->nr_cgroups++
cpuctx->cgrp = X
We can see from above that we wrongly use percpu atomic perf_cgroup_events
to check if we need to perf_cgroup_switch(), which should only be used
when we know this CPU has cgroup events enabled.
The commit bd27568 ("perf: Rewrite core context handling") change
to have only one context per-CPU, so we can just use cpuctx->cgrp to
check if this CPU has cgroup events enabled.
So percpu atomic perf_cgroup_events is not needed.
Fixes: bd27568 ("perf: Rewrite core context handling")
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: Ravi Bangoria <ravi.bangoria@amd.com>
Link: https://lkml.kernel.org/r/20221207124023.66252-1-zhouchengming@bytedance.com1 parent e2d3714 commit f841b68
1 file changed
+10
-32
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | 383 | | |
385 | 384 | | |
386 | 385 | | |
| |||
389 | 388 | | |
390 | 389 | | |
391 | 390 | | |
392 | | - | |
393 | 391 | | |
394 | 392 | | |
395 | 393 | | |
| |||
844 | 842 | | |
845 | 843 | | |
846 | 844 | | |
847 | | - | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
848 | 851 | | |
849 | 852 | | |
| 853 | + | |
| 854 | + | |
850 | 855 | | |
851 | 856 | | |
852 | 857 | | |
| |||
3631 | 3636 | | |
3632 | 3637 | | |
3633 | 3638 | | |
3634 | | - | |
3635 | | - | |
| 3639 | + | |
3636 | 3640 | | |
3637 | 3641 | | |
3638 | 3642 | | |
| |||
4974 | 4978 | | |
4975 | 4979 | | |
4976 | 4980 | | |
4977 | | - | |
4978 | | - | |
4979 | | - | |
4980 | | - | |
4981 | | - | |
4982 | | - | |
4983 | | - | |
4984 | | - | |
4985 | | - | |
4986 | 4981 | | |
4987 | 4982 | | |
4988 | 4983 | | |
| |||
5048 | 5043 | | |
5049 | 5044 | | |
5050 | 5045 | | |
5051 | | - | |
5052 | | - | |
5053 | 5046 | | |
5054 | 5047 | | |
5055 | 5048 | | |
| |||
11679 | 11672 | | |
11680 | 11673 | | |
11681 | 11674 | | |
11682 | | - | |
11683 | | - | |
11684 | | - | |
11685 | | - | |
11686 | | - | |
11687 | | - | |
11688 | | - | |
11689 | | - | |
11690 | | - | |
11691 | 11675 | | |
11692 | 11676 | | |
11693 | 11677 | | |
| |||
11775 | 11759 | | |
11776 | 11760 | | |
11777 | 11761 | | |
11778 | | - | |
11779 | | - | |
11780 | 11762 | | |
11781 | 11763 | | |
11782 | 11764 | | |
| |||
12822 | 12804 | | |
12823 | 12805 | | |
12824 | 12806 | | |
12825 | | - | |
12826 | 12807 | | |
12827 | 12808 | | |
12828 | 12809 | | |
12829 | 12810 | | |
12830 | 12811 | | |
12831 | | - | |
12832 | 12812 | | |
12833 | 12813 | | |
12834 | 12814 | | |
| |||
12847 | 12827 | | |
12848 | 12828 | | |
12849 | 12829 | | |
12850 | | - | |
12851 | 12830 | | |
12852 | 12831 | | |
12853 | 12832 | | |
| |||
13742 | 13721 | | |
13743 | 13722 | | |
13744 | 13723 | | |
13745 | | - | |
13746 | | - | |
| 13724 | + | |
13747 | 13725 | | |
13748 | 13726 | | |
13749 | 13727 | | |
| |||
0 commit comments