Skip to contentSkip to conversation

perf/x86: Add Intel cstate PMUs support

PATCH New [email protected] 2 participants 2 messages Sep 28, 2015 – Oct 6, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 perf/x86: Add Intel cstate PMUs support

From: Kan Liang <[email protected]>

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 run 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 run in C6 state.

---

Changes since V1:
- Kernel take care of mapping pkg c6 to correct msr

Changes since V2:
- Remove macros to make the code more readable.
- Similar as MSR PMU, dynamically probe and insert events into sysfs attrs.
- Check valid events in event_init
- Some minor changes like rename

Not change:
(Stephane once suggested to create a unified power PMU which include both RAPL and cstate PMUs. I didn't do that in this patch, because cstate events could be per-socket or per-core. It's hard to be handled in one PMU especially for cpumask.)

 arch/x86/kernel/cpu/Makefile                  |   1 +
 arch/x86/kernel/cpu/perf_event_intel_cstate.c | 694 ++++++++++++++++++++++++++
 2 files changed, 695 insertions(+)
 create mode 100644 arch/x86/kernel/cpu/perf_event_intel_cstate.c
arch/x86/kernel/cpu/Makefile +1 -0
index 4eb065c..5803130 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_p6.o perf_event_knc.o perf_event_p4.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_rapl.o perf_event_intel_cqm.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_pt.o perf_event_intel_bts.o
+obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_cstate.o
 
 obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE)	+= perf_event_intel_uncore.o \
 					   perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/perf_event_intel_cstate.c new file +694 -0

694 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw
perf/x86: Add Intel cstate PMUs support
Commit-ID:  7ce1346a6842550a3c4c453cdf1c7b81fb60b07e
Gitweb:     http://git.kernel.org/tip/7ce1346a6842550a3c4c453cdf1c7b81fb60b07e
Author:     Kan Liang <[email protected]>
AuthorDate: Mon, 28 Sep 2015 08:30:04 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 6 Oct 2015 17:31:51 +0200

perf/x86: Add Intel cstate PMUs support

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.

---
 arch/x86/kernel/cpu/Makefile                  |   1 +
 arch/x86/kernel/cpu/perf_event_intel_cstate.c | 694 ++++++++++++++++++++++++++
 2 files changed, 695 insertions(+)
arch/x86/kernel/cpu/Makefile +1 -0
index 4eb065c..5803130 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_p6.o perf_event_knc.o perf_event_p4.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_lbr.o perf_event_intel_ds.o perf_event_intel.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_rapl.o perf_event_intel_cqm.o
 obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_pt.o perf_event_intel_bts.o
+obj-$(CONFIG_CPU_SUP_INTEL)		+= perf_event_intel_cstate.o
 
 obj-$(CONFIG_PERF_EVENTS_INTEL_UNCORE)	+= perf_event_intel_uncore.o \
 					   perf_event_intel_uncore_snb.o \
arch/x86/kernel/cpu/perf_event_intel_cstate.c new file +694 -0

694 lines not on this page · raw message