Repository navigation
Apple M4 Pro and A18 Pro CPU performance counters (one PMU per SoC) - #865
Merged
Merged
Conversation
Add the core PMU compatibles for the M4 Pro (Brava E and P cores) and the A18 Pro (Tahiti E and P cores). The names follow the CPU node compatibles these SoCs already use (apple,brava-e, apple,tahiti-p and so on). Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
The Brava (M4 Pro) and Tahiti (A18 Pro) cores keep the M1 PMU register interface, but select events differently. Measured on both SoCs, on the E and P cores, by counting reference loops with a known instruction mix with interrupts disabled: - PMC0 counts core cycles and PMC1 retired instructions, exactly (a loop of 100000 iterations of three instructions reads 300018 on PMC1). - All ten counters are 64 bits wide, and the overflow flag in PMSR sets when a counter crosses bit 63, not bit 47. This is the M2 behaviour. - PMCR1 keeps the M1 EL0/EL1 filter layout. - PMESR0 and PMESR1 hold one 16-bit event field per counter (counters 2-5 and 6-9) instead of the M1's 8-bit fields. With event 0x08 in every field, counters 2-7 all count the same instructions as PMC1. Counters 8 and 9 stay at zero, so they are not exposed. - The event numbers are new: 0x08 instructions, 0x21 branches (both exact on every loop), 0x22 mispredicted branches (conditional and indirect), 0x04 loads, 0x03 L1D load misses. The M1 numbers do not apply. Add PMUs for these cores that expose counters 0-7, program 16-bit event fields, and handle 63-bit overflow. Cycles keep the M1 event number and go to the fixed counter only, because no configurable event is known to count cycles. Move the driver's private filter flags in config_base above the 16-bit event field. Event placement is now a per-PMU choice, so M1 and M2 behave as before. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Describe the E and P core PMUs on the M4 Pro and A18 Pro. Each one takes its FIQ from the AIC, and the AIC affinities route each PMU FIQ to its own cluster's CPUs, as on t8112. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Build the driver's event placement code on the host against a model of PMESR0/1. The test checks that: - M4/A18 events land in one 16-bit field per counter; - the M1 8-bit layout is unchanged; - cycles go only to PMC0 and instructions to PMC1 first; - counters 8 and 9 are never used; - the private filter flags stay clear of the 16-bit event field. Four mutations, one per rule, must each be caught. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Contributor
Author
|
M1 Pro (T6000, Firestorm/Icestorm) regression check of the shared M1/M2 path, 7.3.0-aurora-fleet14o-pmu2 one-shot (boot f6d24f06) against the fleet14o default on the same machine:
|
The E and P cores of the T6040 (M4 Pro) and T8140 (A18 Pro) share one PMU event encoding and counter layout, so a single PMU instance covers both clusters. Replace the per-cluster brava/tahiti compatibles with apple,t6040-pmu and apple,t8140-pmu. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Counting the same reference loops on both core types of each SoC gives the same set of nonzero event numbers, the same 16-bit PMESR fields and the same working counters (0-7) on the E and P cores. Only the microarchitectural counts differ. One arm_pmu instance can therefore drive both clusters. A single instance matters for KVM. Its default guest PMU is backed by one host PMU, and with per-cluster PMUs those backing events stop counting whenever the vCPU thread runs on the other cluster. The only way around that is KVM_ARM_VCPU_PMU_V3_SET_PMU plus pinning in the VMM. With one PMU spanning all CPUs, guest counters keep counting across migration. Register the PMU as apple,t6040-pmu or apple,t8140-pmu, named after the SoC. The event table, counters and overflow handling are unchanged. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
Replace the per-cluster pmu-e/pmu-p nodes and their AIC affinities with one pmu node per SoC on the P-cluster PMU FIQ. The AIC already delivers the PMU FIQ of either cluster as that interrupt, and with no affinity partition the interrupt covers every CPU. Assisted-by: LLM Signed-off-by: Ryan Murray <[email protected]>
RyanTheTide
marked this pull request as ready for review
November 2, 2026 17:38
Contributor
Author
|
Neo (J700, A18 Pro) hardware test of the gaps2 build (7.3.0-aurora-fleet14p-gaps2, source afdbf9b8, J700 DTB 805f9b1d with the new pmu node), one-shot Stage 2 trial with the old Stage 2 restored on the trial boot itself. Passes:
Fails:
Logs are in the aurora-ctl reports under gaps-20261103/neo-gaps2-trial. The Neo is back on fleet14p with Stage 2 4015aaff. |
DjDeveloperr
added a commit
that referenced
this pull request
Dec 1, 2026
The T8140 PMU description and driver support landed on main with #865, so take main's pmu.yaml, t8140.dtsi and apple_m1_cpu_pmu.c. Also take main's cpu_errata.c: main keeps T8140 out of apple_cpus while its IMPDEF PMUv3 traps are unverified and already treats its vGIC SEIS as broken. What this branch still adds is the bounded deferred stage-2 TLB invalidation in kvm_pgtable_stage2_unmap(). Signed-off-by: DjDeveloperr <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CPU performance counters for the M4 Pro (T6040, Brava cores) and the A18 Pro (T8140, Tahiti cores). Until now neither machine had a hardware PMU in perf, so
perf statandperf recordonly had software events.What the hardware does
These were measured with a throwaway kernel module. It programs the PMU on one CPU of each core type and counts five reference loops with a known instruction mix, with interrupts off:
The results are identical on Brava E/P and Tahiti E/P:
The event numbers are new; the M1 numbers count nothing. Counts per iteration:
No configurable event in 0x000-0xfff counts cycles, so cycles stay on PMC0.
One PMU per SoC
The E and P cores share the event encoding, the 16-bit fields and the working counters, as the tables above show, so one PMU instance covers both clusters. That matters for KVM. A guest PMU is backed by perf events on one host PMU. With per-cluster PMUs, those events stop counting while the vCPU thread runs on the other cluster, unless the VMM uses KVM_ARM_VCPU_PMU_V3_SET_PMU and pins the vCPUs. One PMU spanning all CPUs keeps guest counters counting across migration. #731 took this approach for the fixed counters; this PR keeps it and adds counters 2-7 and the event table.
The test is
kvmpmu, a small standalone program: one vCPU with an emulated PMUv3 counts PMCCNTR and INST_RETIRED over a fixed loop, while the host moves the vCPU thread between an E and a P core after every loop. On the M1 Pro, which has per-cluster PMUs, the guest counts 2000005 instructions per phase on the P core and 2 on the E core (6 of 12 phases counting). The Neo result with this PR will be posted below.Changes
format/eventis config:0-15), and the PMUv3 common-event map for KVM guests (INST_RETIRED, CPU_CYCLES, BR_RETIRED). The driver's private filter flags move above the 16-bit event field. Event placement is now per PMU. M1 and M2 behave as before.Testing
hw perfevents: enabled with apple_t6040_pmu PMU driver, 8 (0,000000ff) counters available, one PMU with cpus=0-13. Its sysfs events are cycles, instructions, branches, branch-misses, loads and l1d-load-misses.🤖 Generated with Claude Code