Repository navigation
perf, arm64: T6030 (M3 Pro) CPU PMU and KVM guest PMUv3 - #4277
Conversation
The T6030 (M3 Pro) gets one CPU PMU node for both of its clusters, as the T6040 and T6050 do. Signed-off-by: DjDeveloperr <hey@djdev.me>
The M3 generation cores select events with 16-bit fields laid out as on M4: PMESR0 holds counters 2-5 and PMESR1 counters 6-9. XNU's H15 configuration (pexpert/pexpert/arm64/H15.h, used for the T6030, T6031 and T8122) sets CPMU_16BIT_EVENTS, CPMU_PMC_COUNT 10 and CPMU_64BIT_PMCS, and its kpc.c programs PMESR0/1 that way. XNU's CPC event list (osfmk/arm64/cpc_arm64_events.c) gives the event numbers, the same list for all three SoCs: CORE_ACTIVE_CYCLE is 0x002 and INST_ALL 0x08c, as on M1, while L1D_CACHE_MISS_LD, for example, moved from 0xa3 to 0x5a3. Counters 0 and 1 count cycles and instructions. The list doesn't say which of counters 2-9 count which event, so only those two back the generic and PMUv3 events. Raw events can use counters 2-9. Use one PMU for both clusters, as from M4 on. XNU programs the same event list on both core types, and a KVM guest's counters then keep counting when its vCPU moves between clusters. Signed-off-by: DjDeveloperr <hey@djdev.me>
KVM offers guests a PMUv3 only when the IMPDEF PMUv3 traps are on (ARM64_WORKAROUND_PMUV3_IMPDEF_TRAPS), and those match only the M1 and M2 cores. On an M3 Pro a guest's PMCR_EL0 read therefore takes an undefined instruction exception. That was reported for the Windows 11 Arm64 boot loader under EDK2 and QEMU with KVM. Add the T6030 cores' part numbers, 0x044 and 0x045 (m1n1's midr.h), in a list of their own. apple_cpus also turns on the GICv3 SEIS workaround, which the T6030 isn't known to need. Signed-off-by: DjDeveloperr <hey@djdev.me>
One node for both clusters: the AIC raises both core types' PMU FIQs as AIC_CPU_PMU_P. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Reviewed 539d1c95fcee and found no code blockers. The binding and driver match the single PMU node on J514s and J516s. I checked the T6030 event IDs against Apple’s published event table. Only cycles (0x002) and instructions (0x08c) are mapped to generic perf and guest PMUv3 events. Counters 2–9 remain available for raw events. The E and P core IDs are confined to the PMUv3 trap list, leaving the interrupt-controller workaround unchanged. The W=1 initializer warnings follow the existing table pattern. Merge still needs green CI and the J516s counts, overflow interrupts, guest PMCR read, and cross-cluster migration result.
|
Hardware check on MacBook Pro 16-inch M3 Pro (J516s, T6030: P-cores Everest Stock baseline (
|
| Cluster | Raw ID | Event | Counters 2–9 mask | Counts (c2..c9) |
|---|---|---|---|---|
P (0x045) |
0x08d |
INST_BRANCH |
000+++00 |
0 0 0 20000006 20000006 20000006 0 0 |
P (0x045) |
0x095 |
INST_INT_LD |
000+++00 |
0 0 0 20000002 20000002 20000002 0 0 |
P (0x045) |
0x09b |
INST_LDST |
000+++00 |
0 0 0 20000002 20000002 20000002 0 0 |
P (0x045) |
0x0cb |
BRANCH_MISPRED_NONSPEC |
++++++++ |
0 0 0 1 1 1 0 0 |
P (0x045) |
0x5a3 |
L1D_CACHE_MISS_LD |
00000000 |
0 0 0 0 0 0 0 0 |
P (0x045) |
0x0bf |
L1D_CACHE_MISS_LD_NONSPEC |
00000000 |
0 0 0 0 0 0 0 0 |
E (0x044) |
0x08d |
INST_BRANCH |
000+++00 |
0 0 0 20000006 20000006 20000006 0 0 |
E (0x044) |
0x095 |
INST_INT_LD |
000+++00 |
0 0 0 20000002 20000002 20000002 0 0 |
E (0x044) |
0x09b |
INST_LDST |
000+++00 |
0 0 0 20000002 20000002 20000002 0 0 |
E (0x044) |
0x0cb |
BRANCH_MISPRED_NONSPEC |
++++++++ |
0 0 0 4 4 4 0 0 |
E (0x044) |
0x5a3 |
L1D_CACHE_MISS_LD |
00000000 |
0 0 0 0 0 0 0 0 |
E (0x044) |
0x0bf |
L1D_CACHE_MISS_LD_NONSPEC |
00000000 |
0 0 0 0 0 0 0 0 |
The cycles-anywhere mutation rewrites the first "return BIT(0);" in the driver and needs it to be unique. The T6030 affinity function adds a second one, so anchor the mutation to M4's CORE_ACTIVE_CYCLE case. Signed-off-by: DjDeveloperr <hey@djdev.me>
DjDeveloperr
left a comment
There was a problem hiding this comment.
The host run at 539d1c95fcee passed 1,172 of 1,173 jobs. The cycles-anywhere control found two copies of its match string after the T6030 table was added and stopped before testing the mutation. At 5e65274965a8 the control targets the M4 case explicitly. I ran the normal test and all four negative controls on pc at that head, and all behaved as expected. The commit changes only the host test, so the J516s 19/19 result still covers the kernel change. The fresh hosted checks are pending.
|
Merged as |
|
This might be the wrong solution |
|
Post-merge code review of Concrete issues / gaps
Architectural / scope notes
The M3 hardware findings themselves (16-bit |
What: Give the M3 Pro (T6030: J514s, J516s) a CPU PMU and turn on the IMPDEF PMUv3 traps on its cores, so KVM can offer guests a PMUv3. A guest's
mrs pmcr_el0then stops taking an undefined-instruction exception. That exception was reported for the Windows 11 Arm64 boot loader under EDK2 with QEMU/KVM on an M3 Pro.Tested: J516s row at
539d1c95, the kernel and device trees of this head (the commit after it changes only a host test): VERDICT PASS, 19/19 checks (receipt in the comments). On P and E cores: exact instruction counts, overflow IRQs for every sample, KVM_CAP_ARM_PMU_V3 = 1, the guest's PMCR_EL0 read, exact guest INST_RETIRED on P, on E and across P/E migrations, guest overflow, KUnit 24/24 at boot. Stock7.3.0-f3822shows the reported fault: the cap is 0 and the guest's PMCR_EL0 read takes EC 0. Host:checkpatch --strictclean on all five commits;dt_binding_check(arm/pmu.yaml) andCHECK_DTBS(both T6030 boards) clean;apple-m4-pmu-tests5/5 with all mutations.Risk: two-way · T6030 (M3 Pro). It sets HACR_EL2 bit 56 on T6030 cores, the trap M1/M2 already use. There is no public basis for that bit on M3, so the J516s row's guest PMCR_EL0 read is what proves it.
Not yet: Nothing for the T6030 itself. Follow-ups: T6031 and T8122, and generic branch events. The J516s survey: INST_BRANCH, INST_INT_LD and INST_LDST count only on counters 5-7; L1D_CACHE_MISS_LD 0x5a3 and its NONSPEC 0x0bf counted on no counter, so L1D misses stay unmapped.
Details
Problem (checked on main)
t6030.dtsihas no CPU PMU node, andapple_m1_cpu_pmu.chas no M3 entry, so the M3 Pro has noperfhardware counters.has_impdef_pmuv3()incpu_errata.cmatches only the M1 and M2 cores (apple_cpus).kvm_arm_pmu_get_pmuver_limit()treats the IMPDEF PMU as absent, sokvm_host_pmu_init()registers no host PMU.KVM_CAP_ARM_PMU_V3is then 0, QEMU refusespmu=on, and a guest's PMUv3 system register access is undefined.Change
dt-bindings: arm: pmu:apple,t6030-pmu.drivers/perf: apple_m1: T6030 tables. The M3 cores select events with 16-bit fields laid out as on M4 (PMESR0 for counters 2-5, PMESR1 for 6-9) and have 64-bit counters. Counters 0 and 1 are cycles and instructions. Only those two back generic and PMUv3 events; raw events can use counters 2-9. There is one PMU for both clusters, as from M4 on, so a KVM guest's counters keep counting when its vCPU moves between clusters. QEMU doesn't pin vCPUs. KUnit: an M3 variant and an M3 test case.arm64: errata: the T6030 part numbers 0x044 (Sawtooth) and 0x045 (Everest) go in a list of their own for the IMPDEF PMUv3 traps. Adding them toapple_cpuswould also turn on the GICv3 SEIS workaround, which the T6030 isn't known to need.arm64: dts: apple: t6030: thepmunode. The AIC raises both core types' PMU FIQs asAIC_CPU_PMU_P.Public basis
pexpert/pexpert/arm64/H15.h(used for the T6030, T6031 and T8122):CPMU_PMC_COUNT 10,CPMU_64BIT_PMCS 1,CPMU_16BIT_EVENTS 1. XNU'sosfmk/arm64/kpc.cprograms PMESR0/PMESR1 with 16-bit fields at(counter - 2|6) * 16.osfmk/arm64/cpc_arm64_events.c: one T6030 list, identical to the T6031 and T8122 lists. CORE_ACTIVE_CYCLE is 0x002 and INST_ALL 0x08c, as on M1. Many events have a prefix above the low byte now, for example L1D_CACHE_MISS_LD 0x5a3 (M1: 0xa3) and L1I_TLB_MISS_DEMAND 0x1d4. The list doesn't say which of counters 2-9 count which event, so this PR maps nothing beyond the fixed counters.src/midr.h(T6030 Sawtooth 0x44, Everest 0x45). Read on the J516s on 12-04: MIDR_EL1 0x611f0441 on the six 2.748 GHzapple,sawtoothcores and 0x611f0451 on the six 4.056 GHzapple,everestcores.Not in this PR
Evidence
work/j516s-c1608-pmu-20261204on Mini (one trial boot with the stock Stage 2 and this PR's DTB). It runsperf_event_opencounts and sampling on P and E cores, plus a minimal KVM guest with no QEMU. Its control is a vCPU without PMUv3, which reproduces the reported fault (EC 0 at the PMCR_EL0 read).build/dt-binding-check.log,build/dtbs-check.log,build/w1.logandbuild/dt-diff-vs-main.txtin the kit.