Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1517135

Re: [PATCH] perf/x86: Fix overlap counter scheduling bug

From Peter Zijlstra <peterz@infradead.org>
Newsgroups linux.kernel
Subject Re: [PATCH] perf/x86: Fix overlap counter scheduling bug
Date 2016-11-08 13:30 +0100
Message-ID <sBdHk-SQ-27@gated-at.bofh.it> (permalink)
References <syJu2-26a-21@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Tue, Nov 01, 2016 at 04:44:28PM +0100, Jiri Olsa wrote:
> My fuzzer testing hits following warning in the counter scheduling code:
> 
>   WARNING: CPU: 0 PID: 0 at arch/x86/events/core.c:718 perf_assign_events+0x2ae/0x2c0
>   Call Trace:
>    <IRQ>
>    dump_stack+0x68/0x93
>    __warn+0xcb/0xf0
>    warn_slowpath_null+0x1d/0x20
>    perf_assign_events+0x2ae/0x2c0
>    uncore_assign_events+0x1a7/0x250 [intel_uncore]
>    uncore_pmu_event_add+0x7a/0x3c0 [intel_uncore]
>    event_sched_in.isra.104+0xf6/0x2e0
>    group_sched_in+0x6e/0x190
>    ...
> 
> The reason is that the counter scheduling code assumes
> overlap constraints with mask weight < SCHED_STATES_MAX.
> 
> This assumption is broken with uncore cbox constraint
> added for snbep in:


>   3b19e4c98c03 perf/x86: Fix event constraint for SandyBridge-EP C-Box

   3b19e4c98c03 ("perf/x86: Fix event constraint for SandyBridge-EP C-Box")

Is the right form.

> It's also easily triggered by running following perf command
> on snbep box:
>    # perf stat -e 'uncore_cbox_0/event=0x1f/,uncore_cbox_0/event=0x1f/,uncore_cbox_0/event=0x1f/' -a
> 
> Fixing this by increasing the SCHED_STATES_MAX to 3 and adding build
> check for EVENT_CONSTRAINT_OVERLAP macro.


> -#define	SCHED_STATES_MAX	2
> +#define SCHED_STATES_MAX 3

Us having to increase this is ff'ing sad :/ That's seriously challenged
hardware :/

> +
> +/* Check we dont overlap beyond the states max. */
> +#define OVERLAP_CHECK(n)   (!!sizeof(char[1 - 2*!!(HWEIGHT(n) > SCHED_STATES_MAX)]))
> +#define OVERLAP_HWEIGHT(n) (OVERLAP_CHECK(n)*HWEIGHT(n))

I'm not sure I get how this is correct at all. You cannot tell by a
single mask what the overlap is. You need all the masks.

The point is that that PMU has constraints like:

 0x01 - 0001
 0x03 - 0011
 0x0e - 1110
 0x0c - 1100

Which gets us a total of 4 overlapping counter masks, and that would
indeed lead to max 3 retries I think.

Now, I would much rather solve this by changing the constraint like the
below, that yields:

 0x01 - 0001
 0x03 - 0011

 0x0c - 1100

Which is two distinct groups, only one of which has overlap. And the one
with overlap only has 2 overlapping masks, giving a max reties of 1.


diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 272427700d48..71bc348736bd 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -669,7 +669,7 @@ static struct event_constraint snbep_uncore_cbox_constraints[] = {
 	UNCORE_EVENT_CONSTRAINT(0x1c, 0xc),
 	UNCORE_EVENT_CONSTRAINT(0x1d, 0xc),
 	UNCORE_EVENT_CONSTRAINT(0x1e, 0xc),
-	EVENT_CONSTRAINT_OVERLAP(0x1f, 0xe, 0xff),
+	UNCORE_EVENT_CONSTRAINT(0x1f, 0xc); /* should be 0x0e but that gives scheduling pain */
 	UNCORE_EVENT_CONSTRAINT(0x21, 0x3),
 	UNCORE_EVENT_CONSTRAINT(0x23, 0x3),
 	UNCORE_EVENT_CONSTRAINT(0x31, 0x3),

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] perf/x86: Fix overlap counter scheduling bug Jiri Olsa <jolsa@kernel.org> - 2016-11-01 16:50 +0100
  Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Peter Zijlstra <peterz@infradead.org> - 2016-11-08 13:30 +0100
    Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Jiri Olsa <jolsa@redhat.com> - 2016-11-08 14:20 +0100
    Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Andi Kleen <andi@firstfloor.org> - 2016-11-08 16:20 +0100
      RE: [PATCH] perf/x86: Fix overlap counter scheduling bug "Liang, Kan" <kan.liang@intel.com> - 2016-11-08 17:30 +0100
        Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Peter Zijlstra <peterz@infradead.org> - 2016-11-08 18:00 +0100
          RE: [PATCH] perf/x86: Fix overlap counter scheduling bug "Liang, Kan" <kan.liang@intel.com> - 2016-11-08 18:30 +0100
            Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Peter Zijlstra <peterz@infradead.org> - 2016-11-08 19:30 +0100
              Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Robert Richter <rric@kernel.org> - 2016-11-09 15:30 +0100
                Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Peter Zijlstra <peterz@infradead.org> - 2016-11-09 17:00 +0100
                Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Ingo Molnar <mingo@kernel.org> - 2016-11-10 09:10 +0100
                Re: [PATCH] perf/x86: Fix overlap counter scheduling bug Peter Zijlstra <peterz@infradead.org> - 2016-11-10 17:50 +0100

csiph-web