• Kan Liang's avatar
    perf/x86: Add Intel cstate PMUs support · 7ce1346a
    Kan Liang authored
    This patch adds new PMUs to support cstate related free running
    (read-only) counters. These counters may be used simultaneously by other
    tools, such as turbostat. However, it still make sense to implement them
    in perf. Because we can conveniently collect them together with other
    events, and allow to use them from tools without special MSR access
    code.
    
    These counters include CORE_C*_RESIDENCY and PKG_C*_RESIDENCY.
    According to counters' scope and category, two PMUs are registered with
    the perf_event core subsystem.
    
     - 'cstate_core': The counter is available for each physical core. The
                      counters include CORE_C*_RESIDENCY.
    
     - 'cstate_pkg':  The counter is available for each physical package. The
                      counters include PKG_C*_RESIDENCY.
    
    The events are exposed in sysfs for use by perf stat and other tools.
    The files are:
    
      /sys/devices/cstate_core/events/c*-residency
      /sys/devices/cstate_pkg/events/c*-residency
    
    These events only support system-wide mode counting.
    The /sys/devices/cstate_*/cpumask file can be used by tools to figure
    out which CPUs to monitor by default.
    
    The PMU type (attr->type) is dynamically allocated and is available from
    /sys/devices/core_misc/type and /sys/device/cstate_*/type.
    
    Sampling is not supported.
    
    Here is an example.
    
     - To caculate the fraction of time when the core is running in C6 state
       CORE_C6_time% = CORE_C6_RESIDENCY / TSC
    
     # perf stat -x, -e"cstate_core/c6-residency/,msr/tsc/" -C0 -- taskset -c 0 sleep 5
    
       11838820015,,cstate_core/c6-residency/,5175919658,100.00
       11877130740,,msr/tsc/,5175922010,100.00
    
     For sleep, 99.7% of time we ran in C6 state.
    
     # perf stat -x, -e"cstate_core/c6-residency/,msr/tsc/" -C0 -- taskset -c 0 busyloop
    
       1253316,,cstate_core/c6-residency/,4360969154,100.00
       10012635248,,msr/tsc/,4360972366,100.00
    
     For busyloop, 0.01% of time we ran in C6 state.
    Signed-off-by: default avatarKan Liang <kan.liang@intel.com>
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Cc: Arjan van de Ven <arjan@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: Thomas Gleixner <tglx@linutronix.de>
    Cc: acme@kernel.org
    Cc: eranian@google.com
    Link: http://lkml.kernel.org/r/1443443404-8581-1-git-send-email-kan.liang@intel.comSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
    7ce1346a
Makefile 2.32 KB