Skip to content

perf_events: add support for Intel reference cycles event

Stephane Eranian lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 13 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/4perf_events: enable raw event support for Intel unhalted_reference_cycles eventarch/x86/include/asm/perf_event.h arch/x86/kernel/cpu/perf_event.c arch/x86/kernel/cpu/perf_event_intel.c+20 -181 reply
2/4perf_event: add PERF_COUNT_HW_REF_CPU_CYCLES generic PMU eventinclude/linux/perf_event.h+1 -010 replies
3/4perf_events: add Intel X86 mapping for PERF_COUNT_HW_REF_CPU_CYCLESarch/x86/kernel/cpu/perf_event_intel.c+1 -01 reply
4/4perf: add support for PERF_HW_COUNT_REF_CPU_CYCLEStools/perf/util/parse-events.c+2 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/4] perf_events: add support for Intel reference cycles event

The unhalted_reference_cycles is a very useful event which counts cycles at the reference CPU clock speed (same as TSC if processors supports constant_tsc). That means, it keeps a constant correlation with wall-clock time while the processor is not halted, unlike its counter-part unhalted_core_cycles. The latter event, used by generic PMU event cycles in the perf tool is subject to frequency down-scaling AND Turbo mode fluctuations.

The unhlated_reference_cycles is NOT equivalent to wall clock time because it counts only when the processor is not in halted state. But this limitation impacts only system-wide measurements.

The unhalted_reference_cycles can only be counted on fixed counter 2. As such, it does not have an event encoding. Fixed counters can only measure one (hardwired) event. Yet, with perf_events user manipulates events and not counters, thus each event needs an encoding. That encoding is then used by the kernel to identify the event and schedule it on the proper counter.

Up until now, there was no encoding chosen for unhalted_reference_cycles, thus it could not be scheduled properly and thus it was not supported.

This patch uses the encoding 0x0300. That means event code 0x00, umask 0x3. That event code is not used by Intel on any existing processor. We have also checked with Intel and it seems that they don't plan on using it in the future.

With this patch, it is possible to see the effect of Turbo mode:

$ perf stat -e unhalted_reference_cycles,unhalted_core_cycles ./noploop 1
noploop for 1 seconds

Performance counter stats for './noploop 1':

3,197,640,960 unhalted_reference_cycles
3,595,043,997 unhalted_core_cycles

1.000732233 seconds time elapsed

---

Stephane Eranian (4):
perf_events: enable raw event support for Intel
unhalted_reference_cycles event
perf_event: add PERF_COUNT_HW_REF_CPU_CYCLES generic PMU event
perf_events: add Intel X86 mapping for PERF_COUNT_HW_REF_CPU_CYCLES
perf: add support for PERF_HW_COUNT_REF_CPU_CYCLES

 arch/x86/include/asm/perf_event.h      |   15 ++++++++-------
 arch/x86/kernel/cpu/perf_event.c       |    8 +++++++-
 arch/x86/kernel/cpu/perf_event_intel.c |   16 ++++++----------
 include/linux/perf_event.h             |    1 +
 tools/perf/util/parse-events.c         |    2 ++
 5 files changed, 24 insertions(+), 18 deletions(-)