Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

16.5 The PMU as a validation instrument

16.3 covers how to program PMUv3. This section is about using the counts as evidence. Many memory-system properties have no architecturally visible result: a mis-programmed MAIR_EL1 that makes a buffer Write-Back instead of Non-cacheable still returns the right data. A TLBI that misses its target still “works” until the stale entry is used, and a speculation barrier that does nothing looks identical to one that works. Event counts turn these invisible properties into numbers that a directed test can check.

Ground rules for counting as an oracle

The architecture defines event numbers and their intent, but leaves exactly what is counted largely to the implementation:

  • Architectural events (INST_RETIRED 0x08, EXC_TAKEN 0x09, BR_RETIRED 0x21, LD_RETIRED/ST_RETIRED 0x06/0x07 where implemented) count things defined by the instruction stream. They are the stable reference.
  • Microarchitectural events (L1D_CACHE_REFILL 0x03, L1D_TLB_REFILL 0x05, INST_SPEC 0x1B, BUS_ACCESS 0x19, DTLB_WALK 0x34 and so on) have common numbers, but whether a given access counts (a prefetch, a speculative access, a walk that hits a walk cache) is IMPLEMENTATION DEFINED. Check the core’s TRM.
  • Presence is discoverable: PMCEID0_EL0/PMCEID1_EL0 (and the upper halves for 0x4000+ events) report which common events are implemented. A test must skip, not fail, when an event is absent.
  • Accuracy: the Arm ARM does not require exact counts in general. Counting near a boundary such as an exception entry, a filter change or an ISB may be off by a small number of events. Design tests so that the expected outcomes differ by orders of magnitude (“≈0 vs ≈N”), not by a few counts.

Bracket the region of interest with context synchronization, so that the counter enable and the read are not reordered with the code under test:

    // x0 = event number, counter 0. Assumes PMCR_EL0.E = 1 and filtering set (16.3)
    msr   PMEVTYPER0_EL0, x0
    msr   PMEVCNTR0_EL0, xzr
    mov   x1, #1
    msr   PMCNTENSET_EL0, x1
    isb                         // counter enabled before the test region starts
    bl    test_body
    isb                         // test region's instructions have executed
    mrs   x2, PMEVCNTR0_EL0

The ISB bounds the instruction stream. Memory accesses still outstanding (a posted store, or a refill in flight) may be counted after the read. If the event concerns memory traffic, put a DSB before the final ISB (7.6). Filter by EL (PMEVTYPER<n>_EL0.P/U/NSK/NSH/M) so that an interrupt handler running during the test does not contaminate the count. Better still, mask interrupts and confirm that EXC_TAKEN is 0 over the region.

Oracle 1: memory attributes

A cacheability bug never produces wrong data on a single PE. It only changes performance, or, with a non-coherent agent, breaks a DMA protocol later (8.7). The PMU makes it visible directly:

TestMappingExpected L1D_CACHE_REFILL per passExpected BUS_ACCESS
Stream reads over a buffer 4× L1D size, twiceNormal WB, Inner Shareable≈ size / line size on each pass≈ refills × (line / bus width)
Same bufferNormal Non-cacheable≈ 0≈ size / access size, or less if the core gathers accesses
Same buffer, fits in L1DNormal WB≈ size / line on pass 1, ≈ 0 on pass 2≈ 0 on pass 2
Same bufferDevice-nGnRE≈ 0≈ one per access, with no gathering

Interpreting failures:

  • NC mapping but refills ≈ size/line. The effective attribute is Cacheable. Look for a wrong AttrIndx or MAIR slot (6.5), stage 2 combining (with HCR_EL2.FWB stage 2 can force Write-Back: 11.3), or a different alias of the same PA (6.6).
  • WB mapping but refills ≈ 0 and BUS_ACCESS high. Caching is not happening. Check SCTLR_ELx.C, the HCR_EL2.CD/DC bits, and TCR_ELx.IRGN/ORGN for walks.
  • Second pass still refills on a fitting buffer. Either something is cleaning and invalidating (a stray set/way loop), or the lines are being evicted by another agent’s snoops.

Hardware prefetchers make Cacheable refill counts noisy, though not NC ones. Non-cacheable accesses can be speculative, but they do not allocate. Use PMMIR_EL1.BUS_WIDTH (below) to convert BUS_ACCESS into bytes instead of guessing the bus width.

Oracle 2: TLB maintenance effectiveness

The full sequence in 9.1 (store descriptor; DSB ISHST; TLBI; DSB ISH; ISB) can be checked functionally by remapping a page and reading a signature. But that only proves the final translation is right. It cannot tell “the TLBI worked” apart from “the entry was never cached”. Counting can:

  1. Touch N distinct pages (N below the L1 DTLB capacity) twice. On the second pass L1D_TLB_REFILL ≈ 0, which proves the entries are cached.
  2. Issue the maintenance under test: TLBI VAE1IS per page, TLBI ASIDE1IS, or a range TLBI RVAE1IS.
  3. Touch the pages again. DTLB_WALK should be ≈ N, and L1D_TLB_REFILL ≈ N.
Observation after step 3Likely cause
DTLB_WALK ≈ NThe invalidation reached this PE’s TLBs
DTLB_WALK ≈ 0The TLBI targeted the wrong ASID/VMID/regime, the wrong VA (for example a missing >> 12 in the operand), or TTL/range fields excluded the entries
≈ N for the issuing PE, ≈ 0 on a remote PE that also cached themBroadcast failed. Check shareability (an IS vs non-IS op), whether the remote PE has joined the DVM domain (17.5), and interconnect DVM routing
L1 refills ≈ N but DTLB_WALK ≈ 0Only the L1 micro-TLB was invalidated, and the L2 TLB still held the entries. A TLBI must remove matching entries from every level of TLB that caches them, so unless the L2 TLB was legitimately refilled in between (descriptors left valid allow speculative walks to re-cache them, and whether such walks are counted is IMPLEMENTATION DEFINED), this is a candidate core or interconnect bug

For the remote-PE case, run the counter on the other PE, have that PE re-touch the pages after a flag handshake, and read its own count. DTLB_WALK counts data TLB accesses that needed at least one translation table walk access. Walk caches typically hold only table (non-leaf) entries, so a walk after a leaf invalidation still fetches the leaf descriptor and is counted; whether a walk fully satisfied from internal structures counts is IMPLEMENTATION DEFINED. L2D_TLB_REFILL (0x2D) helps separate the levels.

Validation note: pair the TLBI oracle with an interconnect counter. On a CMN-based system the DVM node counts DVM operations and syncs. A broadcast TLBI ...IS that is not visible as a DVM op at the interconnect, while the local PE does re-walk, means the PE treated it as local. That points at a shareability bug in the maintenance code, or at a PE that is outside the DVM domain because of the DSU/cluster configuration. Confirm with the remote DTLB_WALK count described above.

Oracle 3: speculation

INST_SPEC (0x1B) counts operations speculatively executed, and INST_RETIRED (0x08) counts instructions architecturally executed. Their difference, together with BR_MIS_PRED (0x10) and BR_MIS_PRED_RETIRED (0x22), gives a coarse view of work thrown away. The units differ: INST_SPEC may count micro-operations, so the ratio is only meaningful relative to a baseline on the same core.

Uses in validation:

  • Barrier effectiveness. Train a branch, then mispredict into a region that would issue loads. With SB (or CSDB plus masking, 14.3) placed after the branch, the speculatively executed loads should disappear. The useful counters are an L1D access or refill count on a probe buffer, read only as a performance signal. The architectural proof that a gadget is closed is still a timing-channel test, and the PMU only supports the claim.
  • Predictor invalidation on a world switch. After CFP RCTX/CPP RCTX or a BHB clear (14.4, 14.7), a previously well-trained indirect branch should show a burst of BR_MIS_PRED. If it does not, the restriction did not affect the predictor that the test trained, which is IMPLEMENTATION DEFINED. Report it, but do not treat it alone as an architectural violation.
  • Event filtering leakage. With PMEVTYPER<n>_EL0 filtering out EL3 (and MDCR_EL3.SPME == 0), the counts must not include EL3 work. An SMC-heavy loop is a cheap test that the prohibition works (16.3).

Oracle 4: barrier and maintenance cost

Bring-up questions such as “how long does a DSB ISH take on this die”, “is a DC CIVAC over 1 MB going to the SLC or to DRAM” and “what does a TLBI VMALLE1IS cost across four chiplets” are answered with CPU_CYCLES (or PMCCNTR_EL0) around a loop, as a mean over many iterations:

/* cycles per DSB ISH with k outstanding stores; run on an otherwise idle system */
for (i = 0; i < ITER; i++) {
    for (j = 0; j < k; j++)
        buf[j * 16] = i;            /* separate lines */
    asm volatile("dsb ish" ::: "memory");
}

Sweep k, the memory type of buf and the cluster/die location of the line’s home node. A DSB’s cost is dominated by what has to complete. A flat curve means the stores complete quickly (for example into a nearby SLC). A step at a die boundary shows cross-die completion latency, which also bounds the latency of TLBI broadcast. Most cores also provide the Arm-recommended IMPLEMENTATION DEFINED events ISB_SPEC, DSB_SPEC and DMB_SPEC (commonly 0x7C–0x7E, check the TRM), plus STALL_BACKEND/STALL_BACKEND_MEM to attribute the stall cycles.

PMMIR_EL1: machine description

PMMIR_EL1 (FEAT_PMUv3p4) describes the PMU’s own scaling so that a tool does not hard-code it:

FieldMeaning
SLOTS [7:0]Largest increment of STALL_SLOT per cycle, that is the pipeline width used for top-down analysis: STALL_SLOT / (SLOTS × CPU_CYCLES) is the fraction of slots lost
BUS_SLOTS [15:8]Largest increment of BUS_ACCESS per BUS_CYCLES cycle
BUS_WIDTH [19:16]Bytes per BUS_ACCESS, encoded as a power of two (0 = not specified)
THWIDTH [23:20]Width of the PMEVTYPER<n>_EL0.TH threshold field (FEAT_PMUv3_TH, 16.3)
EDGE [27:24]Edge-detection support (FEAT_PMUv3_EDGE)

Read it once in the test harness and log it with the results. A mismatch between PMMIR_EL1 and the TRM is itself a finding.

System PMUs: counting beyond the PE

The PE PMU sees only the PE’s side of a transaction. To prove where a transaction went, use the system PMUs:

  • CMN interconnect PMU. Each crosspoint has a Debug/Trace Monitor (DTM) with a few local counters and flit watchpoints, aggregated into global counters in the Debug/Trace Controller (DTC). Node-specific events include HN-F SLC hits and misses, snoop-filter activity and PoC queue occupancy, and DVM node operations. Typical checks: whether a DC CVAC loop actually generates CleanShared requests at the HN-F (8.3), whether a “Non-shareable” buffer is generating snoops, and how traffic splits across per-die SLCs. The event list is product-specific (CMN-600/650/700/S3 differ). Linux arm-cmn exposes it, but on pre-silicon you program the PMU registers through MMIO directly.
  • SMMU PMCG (Performance Monitor Counter Group, defined in SMMUv3, IHI0070). Each TCU/TBU may have one. The architected events are cycles (0), transactions (1), TLB misses (2), configuration cache misses (3), translation table walk accesses (4), configuration structure accesses (5), and PCIe ATS translation requests received (6) and ATS-translated transactions passed through (7). Counters can be filtered by StreamID through SMMU_PMCG_SMR<n> with a span option. Use it to check that a device’s DMA really goes through translation (transactions > 0 for its StreamID), and that invalidating with CMD_TLBI_* causes walks (11.5). In ACPI, PMCGs are IORT nodes.
  • CoreSight PMU architecture (IHI0091) PMUs in memory controllers, PCIe root complexes, caches and other devices. With ACPI these are described by the APMT (Arm Performance Monitoring Unit Table, DEN0117). Each node gives the PMU’s base address, interrupt, node type (memory controller, SMMU, PCIe root complex, ACPI device, CPU cache) and processor affinity. Linux’s arm_cspmu driver consumes it. Table details are in 18.6.
  • FEAT_SPMU (permitted from v8.8) gives System PMUs a System-register interface (SPMCR_EL0, SPMSELR_EL0 and so on), so some cluster-level PMUs are reachable without MMIO.
  • MPAM monitors (memory-bandwidth and cache-storage usage per PARTID/PMG) are a related family, covered in 8.9.

Bring-up note: system PMUs are often clock- or power-gated, Secure-only by default, or locked behind an IMPLEMENTATION DEFINED “secure access” bit. If every counter reads 0, check the PMU’s own enable and the security configuration of its register frame before suspecting the event. A PMCG or CMN PMU that the firmware leaves Secure-only is a common reason why the OS driver probes but counts nothing.

Checkpoint

Q16.5.1 A test maps a 1 MB buffer as Normal Non-cacheable at stage 1 and streams reads over it twice from EL1 under a hypervisor. L1D_CACHE_REFILL is about 16 K on each pass (64-byte lines). What is the most useful first hypothesis?

  • A. The core’s prefetcher is refilling Non-cacheable lines, which the architecture permits
  • B. The PMU counts Non-cacheable accesses as refills, so the test is invalid
  • C. The effective memory type is Cacheable, for example because stage 2 with HCR_EL2.FWB == 1 forces Write-Back, or because a Cacheable alias is in use
  • D. The TLB is missing on every line, and each miss is counted as a refill
Answer

C. A refill count of ≈ size/line, repeated on the second pass, is the signature of Cacheable lines being allocated and evicted. Non-cacheable accesses do not allocate in the cache, so A describes something that cannot produce refills. B is a possible IMPLEMENTATION DEFINED quirk, but it is the least likely explanation and is checked last, against the TRM. D confuses L1D_CACHE_REFILL with L1D_TLB_REFILL, and 1 MB in 4 KB pages would give ≈ 256 walks, not 16 K.

Read more: Arm ARM (DDI0487), Combining stage 1 and stage 2 memory type attributes; HCR_EL2.FWB; PMU common event L1D_CACHE_REFILL

Q16.5.2 PE0 caches 32 pages in its TLB, then PE1 issues TLBI VAE1IS for each page followed by DSB ISH. PE0 then re-touches the pages and its DTLB_WALK count increases by 0. PE1 re-touching its own copies shows 32 walks. Which conclusion is best supported?

  • A. The invalidation did not reach PE0. Suspect the broadcast path or PE0’s DVM-domain membership before suspecting the maintenance code’s operands
  • B. PE0’s walk cache satisfied the walks, so DTLB_WALK did not count them
  • C. The test is invalid because DTLB_WALK only counts walks caused by instruction fetches
  • D. PE1 forgot the ISB, so its TLBIs were not executed
Answer

A. The same operands invalidated PE1’s own entries (32 walks), so ASID, VA and regime are right, and the difference is whether the broadcast reached PE0. B is the tempting option, but walk caches typically hold table entries, not leaf descriptors, so re-walking an invalidated page still makes a translation table access and is counted; and PE1, with similar walk caches, did see 32 walks. C confuses it with ITLB_WALK. A missing ISB on PE1 (D) affects PE1’s own later instruction stream, not whether its broadcast TLBIs complete, which the DSB ISH guarantees.

Read more: Arm ARM (DDI0487), TLB maintenance instructions, broadcast; PMU common events DTLB_WALK and L1D_TLB_REFILL

Q16.5.3 Why should a validation tool read PMMIR_EL1 rather than hard-code constants from the core’s TRM?

  • A. PMMIR_EL1 reports which common events are implemented
  • B. PMMIR_EL1.SLOTS reports the number of event counters, which varies by core
  • C. It is needed to enable thresholding, which is otherwise UNDEFINED
  • D. It describes the scaling of slot and bus events (SLOTS, BUS_SLOTS, BUS_WIDTH), so that metrics such as slot-loss fraction and bytes transferred are computed correctly on any core
Answer

D. PMMIR_EL1 is the machine-description register for interpreting STALL_SLOT and BUS_ACCESS. Event presence (A) is in PMCEID0/1_EL0. The number of counters (B) is PMCR_EL0.N. THWIDTH reports the threshold width, but reading it is not what enables thresholding (C).

Read more: Arm ARM (DDI0487), PMMIR_EL1; PMCEID0_EL0; PMCR_EL0