16.3 PMUv3
The Performance Monitors Extension (FEAT_PMUv3) is the per-PE event counting block. It is optional in the architecture but present on effectively every A-profile core. This section covers its programming model: counters, filtering, prohibition and the extensions up to PMUv3p9. Using the counts as a validation oracle is the subject of 16.5. The version is in ID_AA64DFR0_EL1.PMUVer (0b0001 PMUv3, 0b0100 p1, 0b0101 p4, 0b0110 p5, 0b0111 p7, 0b1000 p8, 0b1001 p9; 0b1111 means an IMPLEMENTATION DEFINED non-PMUv3 PMU). This field uses the PMU’s alternative ID scheme, not the signed/unsigned rule of 1.1.
Registers
| Register | Role |
|---|---|
PMCR_EL0 | global control and N (number of event counters, up to 31) |
PMEVCNTR<n>_EL0, PMEVTYPER<n>_EL0 | event counter n and its event/filter selection |
PMCCNTR_EL0, PMCCFILTR_EL0 | 64-bit cycle counter and its filter |
PMCNTENSET/CLR_EL0 | per-counter enable (bit 31 = cycle counter, bit 32 = instruction counter, p9) |
PMOVSSET/CLR_EL0 | overflow status |
PMINTENSET/CLR_EL1 | overflow interrupt enable |
PMSELR_EL0 + PMXEVTYPER/PMXEVCNTR_EL0 | indirect access by index |
PMCEID0/1_EL0 | which common events are implemented |
PMUSERENR_EL0 | EL0 access (EN, SW, CR, ER, and from p9 UEN, IR, TID) |
PMSWINC_EL0 | software increment (event 0x00) |
PMCR_EL0 bits: E [0] enable all, P [1] reset event counters, C [2] reset cycle counter, D [3] divide cycle counter by 64 (deprecated in AArch64), X [4] export events to trace, DP [5] disable the cycle counter where event counting is prohibited, LC [6] cycle counter overflows at 64 bits, LP [7] event counters overflow at 64 bits (p5), FZO [9] freeze on overflow (p7), N [15:11], IDCODE [23:16], IMP [31:24], FZS [32] freeze on an SPE buffer event.
A counter counts only when PMCR_EL0.E, its PMCNTENSET bit, its filter and the prohibition rules below all allow it. Event numbers 0x0000–0x003F and 0x4000–0x403F are the common architectural and microarchitectural events, reported in PMCEID0/1_EL0. PMUv3p8 extends the common space to 0x0040–0x00BF and 0x4040–0x40BF, and removes the CONSTRAINED UNPREDICTABLE behaviour of selecting an unimplemented event. Everything else is IMPLEMENTATION DEFINED per core.
Filtering by Exception level and Security state
PMEVTYPER<n>_EL0 (and PMCCFILTR_EL0, with evtCount RES0) filter with a scheme that confuses everyone once:
| Bit | Field | Rule |
|---|---|---|
| 31 | P | 1: do not count at EL1 |
| 30 | U | 1: do not count at EL0 |
| 29 | NSK | Non-secure EL1 is counted only if NSK == P |
| 28 | NSU | Non-secure EL0 is counted only if NSU == U |
| 27 | NSH | 1: count at (Non-secure) EL2 |
| 26 | M | EL3 is counted only if M == P |
| 25 | MT | FEAT_MTPMU: count events from all threads of the core |
| 24 | SH | Secure EL2 is counted only if SH != NSH |
| 22:20 | RLK, RLU, RLH | RME: Realm EL1 is counted only if RLK == P, Realm EL0 only if RLU == U, and Realm EL2 only if RLH != NSH (the SH rule) |
| 15:0 | evtCount | event number (16 bits from p1) |
P and U set a baseline, and the per-state bits flip it. So P=0, M=0 counts EL1 and EL3, and to count “EL1 but not EL3” you must set M=1. EL2 is excluded by default (NSH=0).
Above the filter sit the prohibition controls. These are owned by higher ELs and the filter cannot override them:
MDCR_EL3.SPME[17]: 0 prohibits counting in Secure state (and, with p7 andMPMX == 0, at EL3). It resets to 0, so out of reset the Secure world is invisible to the PMU. Before FEAT_Debugv8p2 the decision also involved theSPNIDENauthentication signal (16.2).MDCR_EL3.SCCD[23] (p5): prohibits the cycle counter in Secure state and at EL3.MDCR_EL3.MPMX[35] andMCCD[34] (p7):MPMX = 1prohibits counting at EL3, independently of the rest of the Secure state, andMCCD = 1stopsPMCCNTR_EL0at EL3. TF-A setsSPME = 0,SCCD = 1,MCCD = 1andMPMX = 0. Firmware cycles are therefore never attributed to Normal-world measurements, but they are lost from the timeline.MDCR_EL2.HPMD[17] (p1) prohibits counting at EL2, andHCCD[23] (p5) does the same for the cycle counter.MDCR_EL2.HPMN[4:0] splits the counters into a first range[0, HPMN), owned by EL1/EL0, and a second range[HPMN, N), owned by EL2. At EL1,PMCR_EL0.Nreads asHPMN.MDCR_EL2.HPMEenables the second range, andHLP(p5) sets its overflow width.PMCR_EL0.DP: when 1, the cycle counter obeys the same prohibitions as the event counters. When 0, many of the controls above leavePMCCNTR_EL0running.
Traps: MDCR_EL3.TPM [6] and MDCR_EL2.TPM [6]/TPMCR [5] trap PMU accesses. PMUSERENR_EL0 gates EL0.
Security note: a cycle or event counter that runs across a world switch is a timing side channel into the Secure or Realm world. Keep
SPME = 0, setSCCD/MCCDand keepPMCR_EL0.DP = 1. When the Secure world wants its own profiling, context-switch the PMU in the SPMC rather than relaxingSPMEglobally. See 14.7 for the wider world-switch hygiene.
A minimal counting sequence
// EL1: count INST_RETIRED (0x08) at EL0+EL1 only, plus cycles, 64-bit cycle counter
mov x0, #0x08
orr x0, x0, #(1 << 26) // M=1 != P=0 -> exclude EL3
msr pmevtyper0_el0, x0 // NSH=0 -> exclude EL2
mov x0, #(1 << 26)
msr pmccfiltr_el0, x0
mov x0, #1 // counter 0
orr x0, x0, #(1 << 31) // cycle counter
msr pmcntenset_el0, x0
mrs x0, pmcr_el0
orr x0, x0, #(1 << 6) // LC
orr x0, x0, #0x7 // E | P | C (reset both, enable)
msr pmcr_el0, x0
isb // counting is not guaranteed to start before this
// ... measured code ...
isb
mrs x1, pmevcntr0_el0
mrs x2, pmccntr_el0
PMU register writes are ordinary system-register writes. A context synchronization event (ISB) is what guarantees that the enable takes effect for following instructions. Without the second ISB, the MRS can execute out of order with the code under measurement. Counts of speculative events (INST_SPEC, cache refills) include work from mis-speculated paths, and even INST_RETIRED is attributed at a boundary the architecture does not make cycle-exact.
Multi-core counting pitfalls
- Counters are per PE. No architectural “start all cores” exists: each core sets its own
PMCR_EL0.E, so start skew is the IPI latency. There is no architected CTI output that starts or stops PMU counting. The CTI can only broadcast a PMU overflow (CTI input 1) to other cores, for example to cross-halt them (16.2), and with FEAT_PMUv3_SS a capture event takes a snapshot (below). The practical approach is to readCNTVCT_EL0next to every sample and align the samples afterwards. - Heterogeneous clusters have different
PMCEIDsets and different IMPLEMENTATION DEFINED event numbers. The same raw event number can mean different things on a big core and a LITTLE core, which is why Linux registers one PMU instance per core type. - Migration: an OS that moves a thread between cores mid-measurement mixes counters unless it virtualises them (perf does, a bare-metal harness usually does not).
- SMT/MT: with FEAT_MTPMU, the
MTbit decides whether events from sibling threads are included. Since v8.6 an IMPLEMENTATION DEFINED alternative is no longer permitted. - Low-power states: whether
CPU_CYCLESandPMCCNTR_EL0advance in WFI depends on the clocking and is effectively IMPLEMENTATION DEFINED. The counters are in the Core power domain and are lost on power-down unless firmware or the OS saves them. - Overflow interrupt: a PPI, INTID 23 by BSA/SBSA convention, so it is per-PE by construction. Its interaction with
PMCR_EL0.FZOis covered below.
The extensions
| Feature | Version | Adds |
|---|---|---|
| FEAT_PMUv3p1 | v8.1 | 16-bit evtCount, MDCR_EL2.HPMD |
| FEAT_PMUv3p4 | v8.4 | PMMIR_EL1 (used in 16.5) |
| FEAT_PMUv3p5 | v8.5 | 64-bit event counters (PMCR_EL0.LP, MDCR_EL2.HLP), MDCR_EL3.SCCD, MDCR_EL2.HCCD |
| FEAT_PMUv3p7 | v8.7 | PMCR_EL0.FZO, MDCR_EL2.HPMFZO (freeze on overflow), MDCR_EL3.MPMX/MCCD |
| FEAT_PMUv3p8 | v8.8 | wider common event space, defined behaviour for unimplemented events |
| FEAT_PMUv3_TH | v8.8 | threshold counting: PMEVTYPER<n>_EL0.TH [43:32] and TC [63:61], width in PMMIR_EL1.THWIDTH |
| FEAT_PMUv3p9 | v8.9 | PMUSERENR_EL0.UEN with PMUACR_EL1, EDECR.PME |
| FEAT_PMUv3_ICNTR | v8.9 | fixed instruction counter PMICNTR_EL0 + PMICFILTR_EL0 |
| FEAT_PMUv3_SS | v8.9 | snapshots: PMSSCR_EL1, PMEVCNTSVR<n>_EL1, PMCCNTSVR_EL1, PMICNTSVR_EL1 |
| FEAT_PMUv3_EXT64 | v8.9 | 64-bit external (memory-mapped) PMU interface |
The pN versions are cumulative, and each one requires the previous. A PE of architecture version v8.x that implements FEAT_PMUv3 must report at least the highest pN at or below x. For example, a v8.7 PE with a PMU cannot report p5. The _TH, _ICNTR, _SS, _EDGE and _EXT64 features remain optional. For the exact rules, see the PMUVer field description and DDI0487 A2.
Freeze on overflow (p7). With PMCR_EL0.FZO = 1, the first-range counters (and the cycle counter if DP = 1, and the instruction counter) stop while any first-range overflow flag in PMOVSCLR_EL0 is set. Without it, counters keep running in the window between the overflow and the interrupt handler reading them, which skews ratios computed in the handler. MDCR_EL2.HPMFZO does the same for the second range.
Thresholding (FEAT_PMUv3_TH). For events that can increment by more than 1 per cycle (for example “operations retired” on a wide core, or occupancy-style events), TC selects a comparison of the per-cycle increment against TH: not-equal, equal, greater-or-equal or less-than. Each has a variant that adds the increment and a “count” variant that adds 1 per qualifying cycle. “Cycles with at least 4 retirements” becomes a single counter, TC=0b101, TH=4. FEAT_PMUv3_EDGE adds edge detection (count transitions), and FEAT_PMUv3_TH2 can chain the even/odd counter pair.
EL0 access (p9). The legacy PMUSERENR_EL0.{EN,ER,CR,SW} is all-or-nothing. With UEN = 1, EL0 can access only the counters whose bits are set in PMUACR_EL1 (P[30:0] event counters, C [31] cycle, F0 [32] instruction counter), while PMCR_EL0 stays trapped. IR makes the instruction counter read-only at EL0. This lets a kernel give a user-space JIT or profiler direct MRS access to its own counters.
Fixed instruction counter (FEAT_PMUv3_ICNTR). PMICNTR_EL0 counts INST_RETIRED without using an event counter. It is filtered by PMICFILTR_EL0 with the same P/U/NSK/... scheme and controlled at bit 32 (F0) of PMCNTENSET, PMOVSSET and related registers.
Snapshots (FEAT_PMUv3_SS). Writing PMSSCR_EL1.SS = 1, or an external capture event, copies all counters into the shadow ...SVR registers at one instant. SS reads 1 until the capture completes, and NC = 0 reports that a capture has happened. This answers “read 8 counters coherently” without stopping counting. It is gated by MDCR_EL3.EnPMSS and MDCR_EL2.PMSSE.
EXT64. The external (memory-mapped) PMU interface supports 64-bit accesses and maps the upper halves of registers such as PMCR_EL0 and PMEVTYPER<n>_EL0, so an external agent can read a 64-bit counter in one access. With a 32-bit-only interface, the agent must read high, low and high again, and retry if the high word changed.
Bring-up note: TF-A programs the PMU security controls in
lib/extensions/pmuv3/, and enables EL2-owned controls such asMDCR_EL2.HPMN = Nwhen EL2 is unused. If Linux reports fewer counters than the TRM promises, checkMDCR_EL2.HPMN(EL1 seesPMCR_EL0.N == HPMN) before suspecting the silicon. If Secure-world benchmarks read zero,SPME = 0is doing its job.
Validation note: filter correctness is a cheap and high-value test. Count
INST_RETIREDwith{P,U,NSK,NSU,M,NSH}swept over all combinations while running a known instruction count at each EL (anSMCround-trip covers EL3, anHVCcovers EL2). Every combination has a closed-form expected result, and a mismatch is an RTL or model bug in filter decode. Repeat withMDCR_EL3.SPME,MPMXandPMCR_EL0.DPtoggled to check the prohibition priority, and withFZO = 1and a counter preloaded to0xFFFF_FFFF(LP = 0) to check that counting freezes on the overflow cycle.
Checkpoint
Q16.3.1 Firmware with EL3 implemented sets PMEVTYPER0_EL0 = 0x08 (INST_RETIRED, all filter bits zero), and MDCR_EL3.SPME = 1. Normal-world software reads a count that is noticeably larger than the instruction count of its loop, which contains SMC calls. Why?
- A.
INST_RETIREDcounts speculatively executed instructions - B.
NSK = 0withP = 0excludes Non-secure EL1, so the count comes only from EL3 - C. The counter is 32-bit and wrapped
- D.
M == P == 0, so EL3 is counted, and withSPME = 1so is Secure state, which includes the firmware run by eachSMC
Answer
D. EL3 is counted when M == P, and with SPME=1 nothing prohibits Secure counting. Excluding EL3 needs M = 1, and excluding Secure EL1 and EL0 relies on keeping SPME = 0. Option A is wrong because INST_RETIRED counts architecturally executed instructions (INST_SPEC is the speculative one). Option B inverts the rule: Non-secure EL1 is counted when NSK == P.
Read more: Arm ARM (DDI0487), PMEVTYPER<n>_EL0, MDCR_EL3.SPME, “Prohibiting event and cycle counting”
Q16.3.2 An overflow handler computes IPC from two counters that were configured to overflow together. The ratios are noisy. Which PMUv3 extension addresses the skew most directly?
- A. FEAT_PMUv3p5 64-bit counters, because overflow becomes rarer
- B. FEAT_PMUv3p7
PMCR_EL0.FZO, which stops the affected counters while an overflow flag is set, so the handler reads values frozen at the overflow - C. FEAT_PMUv3_TH thresholding
- D.
PMUACR_EL1, so EL0 can read the counters faster
Answer
B. Without freeze, both counters keep counting until the handler’s MRS, including the handler’s own instructions. FZO freezes the counters at the overflow. Option A reduces how often the problem occurs but not the skew when it does. FEAT_PMUv3_SS snapshots would also help, but they are not offered here.
Read more: Arm ARM (DDI0487), PMCR_EL0.FZO, MDCR_EL2.HPMFZO
Q16.3.3 A Linux guest under KVM sees PMCR_EL0.N == 4 on a core whose TRM documents 6 event counters. Which is the most likely explanation?
- A.
MDCR_EL2.HPMN == 4. EL1 sees only the first range, and counters 4–5 are reserved to EL2 - B.
MDCR_EL3.SPME == 0hides counters from the Normal world - C. The core implements PMUv3p1 only, which caps
Nat 4 - D.
PMUSERENR_EL0.EN == 0reducesNas seen from EL1
Answer
A. PMCR_EL0.N reads as HPMN from EL1 and EL0 when EL2 is implemented and enabled. That is how a hypervisor partitions the counters. SPME prohibits counting in Secure state and does not change N, which rules out B. PMUSERENR_EL0 controls only EL0 access, which rules out D.
Read more: Arm ARM (DDI0487), MDCR_EL2.HPMN, PMCR_EL0.N