• Jiri Olsa's avatar
    perf/x86/intel: Add proper condition to run sched_task callbacks · df6c3db8
    Jiri Olsa authored
    We have 2 functions using the same sched_task callback:
    
      - PEBS drain for free running counters
      - LBR save/store
    
    Both of them are called from intel_pmu_sched_task() and
    either of them can be unwillingly triggered when the
    other one is configured to run.
    
    Let's say there's PEBS drain configured in sched_task
    callback for the event, but in the callback itself
    (intel_pmu_sched_task()) we will also run the code for
    LBR save/restore, which we did not ask for, but the
    code in intel_pmu_sched_task() does not check for that.
    
    This can lead to extra cycles in some perf monitoring,
    like when we monitor PEBS event without LBR data.
    
      # perf record --no-timestamp -c 10000 -e cycles:p ./perf bench sched pipe -l 1000000
    
      (We need PEBS, non freq/non timestamp event to enable
       the sched_task callback)
    
    The perf stat of cycles and msr:write_msr for above
    command before the change:
      ...
      Performance counter stats for './perf record --no-timestamp -c 10000 -e cycles:p \
                                     ./perf bench sched pipe -l 1000000' (5 runs):
    
        18,519,557,441      cycles:k
            91,195,527      msr:write_msr
    
          29.334476406 seconds time elapsed
    
    And after the change:
      ...
      Performance counter stats for './perf record --no-timestamp -c 10000 -e cycles:p \
                                     ./perf bench sched pipe -l 1000000' (5 runs):
    
        18,704,973,540      cycles:k
            27,184,720      msr:write_msr
    
          16.977875900 seconds time elapsed
    
    There's no affect on cycles:k because the sched_task happens
    with events switched off, however the msr:write_msr tracepoint
    counter together with almost 50% of time speedup show the
    improvement.
    
    Monitoring LBR event and having extra PEBS drain processing
    in sched_task callback showed just a little speedup, because
    the drain function does not do much extra work in case there
    is no PEBS data.
    
    Adding conditions to recognize the configured work that needs
    to be done in the x86_pmu's sched_task callback.
    Suggested-by: default avatarPeter Zijlstra <peterz@infradead.org>
    Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
    Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Kan Liang <kan.liang@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Link: http://lkml.kernel.org/r/20170719075247.GA27506@kravaSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    df6c3db8
lbr.c 29.6 KB