perf/core: Fix the unthrottle logic
authorPeter Zijlstra <peterz@infradead.org>
Thu, 10 Mar 2016 14:39:24 +0000 (15:39 +0100)
committerIngo Molnar <mingo@kernel.org>
Mon, 21 Mar 2016 08:08:14 +0000 (09:08 +0100)
Its possible to IOC_PERIOD while the event is throttled, this would
re-start the event and the next tick would then try to unthrottle it,
and find the event wasn't actually stopped anymore.

This would tickle a WARN in the x86-pmu code which isn't expecting to
start a !stopped event.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: dvyukov@google.com
Cc: oleg@redhat.com
Cc: panand@redhat.com
Cc: sasha.levin@oracle.com
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/20160310143924.GR6356@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
kernel/events/core.c

index 712570dddacde345c481f86b8631df75b798a33b..d3947739041541d1ebb682c484383c143ebd02c4 100644 (file)
@@ -4210,6 +4210,14 @@ static void __perf_event_period(struct perf_event *event,
        active = (event->state == PERF_EVENT_STATE_ACTIVE);
        if (active) {
                perf_pmu_disable(ctx->pmu);
+               /*
+                * We could be throttled; unthrottle now to avoid the tick
+                * trying to unthrottle while we already re-started the event.
+                */
+               if (event->hw.interrupts == MAX_INTERRUPTS) {
+                       event->hw.interrupts = 0;
+                       perf_log_throttle(event, 1);
+               }
                event->pmu->stop(event, PERF_EF_UPDATE);
        }