diff options
author | David Carrillo-Cisneros <davidcc@google.com> | 2016-11-01 14:52:58 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@kernel.org> | 2016-11-15 08:18:22 -0500 |
commit | 864c2357ca898c6171fe5284f5ecc795c8ce27a8 (patch) | |
tree | e0c20d547643510866dc617d83fb1e5eab7f67bd | |
parent | e76d21c40bd6c67fd4e2c1540d77e113df962b4d (diff) |
perf/core: Do not set cpuctx->cgrp for unscheduled cgroups
Commit:
db4a835601b7 ("perf/core: Set cgroup in CPU contexts for new cgroup events")
failed to verify that event->cgrp is actually the scheduled cgroup
in a CPU before setting cpuctx->cgrp. This patch fixes that.
Now that there is a different path for scheduled and unscheduled
cgroup, add a warning to catch when cpuctx->cgrp is still set after
the last cgroup event has been unsheduled.
To verify the bug:
# Create 2 cgroups.
mkdir /dev/cgroups/devices/g1
mkdir /dev/cgroups/devices/g2
# launch a task, bind it to a cpu and move it to g1
CPU=2
while :; do : ; done &
P=$!
taskset -pc $CPU $P
echo $P > /dev/cgroups/devices/g1/tasks
# monitor g2 (it runs no tasks) and observe output
perf stat -e cycles -I 1000 -C $CPU -G g2
# time counts unit events
1.000091408 7,579,527 cycles g2
2.000350111 <not counted> cycles g2
3.000589181 <not counted> cycles g2
4.000771428 <not counted> cycles g2
# note first line that displays that a task run in g2, despite
# g2 having no tasks. This is because cpuctx->cgrp was wrongly
# set when context of new event was installed.
# After applying the fix we obtain the right output:
perf stat -e cycles -I 1000 -C $CPU -G g2
# time counts unit events
1.000119615 <not counted> cycles g2
2.000389430 <not counted> cycles g2
3.000590962 <not counted> cycles g2
Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Paul Turner <pjt@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vegard Nossum <vegard.nossum@gmail.com>
Link: http://lkml.kernel.org/r/1478026378-86083-1-git-send-email-davidcc@google.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r-- | kernel/events/core.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c index 0e292132efac..ff230bb4a02e 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c | |||
@@ -902,6 +902,17 @@ list_update_cgroup_event(struct perf_event *event, | |||
902 | * this will always be called from the right CPU. | 902 | * this will always be called from the right CPU. |
903 | */ | 903 | */ |
904 | cpuctx = __get_cpu_context(ctx); | 904 | cpuctx = __get_cpu_context(ctx); |
905 | |||
906 | /* Only set/clear cpuctx->cgrp if current task uses event->cgrp. */ | ||
907 | if (perf_cgroup_from_task(current, ctx) != event->cgrp) { | ||
908 | /* | ||
909 | * We are removing the last cpu event in this context. | ||
910 | * If that event is not active in this cpu, cpuctx->cgrp | ||
911 | * should've been cleared by perf_cgroup_switch. | ||
912 | */ | ||
913 | WARN_ON_ONCE(!add && cpuctx->cgrp); | ||
914 | return; | ||
915 | } | ||
905 | cpuctx->cgrp = add ? event->cgrp : NULL; | 916 | cpuctx->cgrp = add ? event->cgrp : NULL; |
906 | } | 917 | } |
907 | 918 | ||