• S
    perf/core: Fix group scheduling with mixed hw and sw events · a1150c20
    Song Liu 提交于
    When hw and sw events are mixed in the same group, they are all attached
    to the hw perf_event_context. This sometimes requires moving group of
    perf_event to a different context.
    
    We found a bug in how the kernel handles this, for example if we do:
    
       perf stat -e '{faults,ref-cycles,faults}'  -I 1000
    
         1.005591180              1,297      faults
         1.005591180        457,476,576      ref-cycles
         1.005591180    <not supported>      faults
    
    First, sw event "faults" is attached to the sw context, and becomes the
    group leader. Then, hw event "ref-cycles" is attached, so both events
    are moved to the hw context. Last, another sw "faults" tries to attach,
    but it fails because of mismatch between the new target ctx (from sw
    pmu) and the group_leader's ctx (hw context, same as ref-cycles).
    
    The broken condition is:
       group_leader is sw event;
       group_leader is on hw context;
       add a sw event to the group.
    
    Fix this scenario by checking group_leader's context (instead of just
    event type). If group_leader is on hw context, use the ->pmu of this
    context to look up context for the new event.
    Signed-off-by: NSong Liu <songliubraving@fb.com>
    Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: <kernel-team@fb.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
    Cc: Jiri Olsa <jolsa@redhat.com>
    Cc: Linus Torvalds <torvalds@linux-foundation.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>
    Fixes: b04243ef ("perf: Complete software pmu grouping")
    Link: http://lkml.kernel.org/r/20180503194716.162815-1-songliubraving@fb.comSigned-off-by: NIngo Molnar <mingo@kernel.org>
    a1150c20
perf_event.h 39.1 KB