Skip to content

perf_events: add support for Intel fixed counter 2

Stephane Eranian lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2perf_events: improve X86 constraint management for fixed countersarch/x86/kernel/cpu/perf_event.c arch/x86/kernel/cpu/perf_event_intel_ds.c+15 -100 replies
1/2perf_events: add support for Intel fixed counter 2 This patch adds support for the unhalted_reference_cycles event which measures reference cycles, i.e., elapsed cycles at the nominal clock speed of the CPU. This event can only be measured by fixed counter 2.arch/x86/kernel/cpu/perf_event.c arch/x86/kernel/cpu/perf_event_intel.c+38 -70 replies

Reviews trailers per patch

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

Read the v1 thread

Cover letter [PATCH 0/2] perf_events: add support for Intel fixed counter 2

This short series of patches adds support for Intel fixed counter 2 on processors which implement architectural perfmon v2 and later.

Fixed counter 2 is wired to count reference cycles. It corrresponds to architected event UNHALTED_REFERENCE_CYCLES. This is a very useful event because:
- it is imune to Turbo Mode on Intel Nehalem and follow-ons
- it is imune to frequency scaling, including during idle

In other words, it keeps a constant correlation to time. It is therefore a good source a reliable timings comparable to TSC.

The other advantage of providing access to this counter is that it offers an additional cycle-counting counter. This is useful when the NMI watchdog is active because it already consumes one such counter.

The difficulty in providing access to the counter (and event) is that the encoding 0x013c is ambiguous. It also corresponds to event CPU_CLK_UNHALTED:REF_P (or BUS) which is measured on generic counters. The issue is that this event counts a different kind of cycles: bus cycles. Thus, the event code 0x13c is not enough to differentiate what the user wants.

This series of patches solves this problem by introducing a custom encoding for UNHALTED_REFERENCE_CYCLES (0xff3c) and improving the constraint infrastructure to handle events which can ONLY be measured on fixed counters.

The UNHALTED_REFERENCE_CYCLES (and fixed counter 2) is available on all Intel processors since architectural perfmon v2 (Intel Yonah).

[PATCH 0/2] - Introduction
[PATCH 1/2] - Improvement to X86 constraints management [PATCH 0/2] - add fixed counter 2 support

---