Skip to content

perf: apple_m1: map the generic L1D read-miss event on M1, M2, M4 and T6050 - #2517

Open
satchlj wants to merge 2 commits into
integration/aurorafrom
satchlj/perf-apple-l1d-read-miss-cache-map-20261120
Open

satchlj wants to merge 2 commits into
integration/aurorafrom
satchlj/perf-apple-l1d-read-miss-cache-map-20261120

Conversation

@satchlj

@satchlj satchlj commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf.

perf: apple_m1: give the M1, M2, M4 and T6050 CPU PMUs a generic cache map with one entry. L1D | OP_READ | RESULT_MISS maps to each PMU's L1D read-miss counter. Commit 1 maps the existing named l1d-load-misses event on M4 and T6050. Commit 2 maps M1_PMU_PERFCTR_L1D_CACHE_MISS_LD (0xa3) on M1 and M2. Every other cache event stays unsupported.

Why: without a cache map, armpmu_map_event() refuses every PERF_TYPE_HW_CACHE event on Apple cores. #2482 (MEM_SPREAD) asks for exactly this event, so in this tree it classifies nothing on any Apple SoC, as Ryan pointed out there. #2482 depends on this PR.

Selection: by each core's own PMU match data (m1_pmu_map_event, m2_pmu_map_event, m4_pmu_map_event, t6050_pmu_map_event), using event numbers already in the tree.

Testing

  • Commit 1 on J775c (T6050), lobata cand-3, 2026-11-20: built without warnings in drivers/perf. L1-dcache-load-misses counted 900,381,519 and l1d-load-misses 900,456,498 on the same run (see the comment below).
  • The 11 commits since 26294e82 don't touch drivers/perf.
  • The revised head builds drivers/perf/apple_m1_cpu_pmu.o for ARM64 in neo-build. Hardware rows for the revised head are pending on M1/M2 and M4. MEM_SPREAD rows on M1 Pro and M2 are requested on sched/fair: spread memory-bound tasks across LLCs (MEM_SPREAD, stacked on #2481) #2482.

Assisted-by: LLM (Claude:Opus 5.5, Codex:GPT-6.2)

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: J775c (T6050) row for this head: it builds, and the generic event counts the same counter.

Kernel: lobata's cand-3, integration/aurora 61295c26102d + 80 commits including this PR at fc44f45472 (2026-11-20). The build had no warnings in drivers/perf.

perf stat -e L1-dcache-load-misses,l1d-load-misses -- taskset -c 12 7zz b 1 -mmt1, on an S core:

Event Count
L1-dcache-load-misses (generic, PERF_TYPE_HW_CACHE) 900,381,519
l1d-load-misses (the driver's named event) 900,456,498

Not tested on M4.

🤖 Generated with Claude Code

@satchlj

satchlj commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf: a second commit, 9491b9317, maps the same generic event on M1 and M2 to their L1D_CACHE_MISS_LD (0xa3), with default counter placement. That's so the MEM_SPREAD rows requested on #2482 mean something on M1 Pro and M2.

It is not built yet and untested on M1/M2. A check there: perf stat -e L1-dcache-load-misses,r0a3 -- <workload> on a Firestorm core, where both counts should match. I've updated the description.

🤖 Generated with Claude Code

@satchlj satchlj changed the title perf: apple_m1: map the generic L1D read-miss event on M4 and T6050 perf: apple_m1: map the generic L1D read-miss event on M1, M2, M4 and T6050 Nov 20, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 1.

The mapping itself is sound: each core's map_event now passes its own cache map, every entry other than L1D | OP_READ | RESULT_MISS stays CACHE_OP_UNSUPPORTED, and the event numbers are the ones the driver already uses for l1d-load-misses (M4 0x03, T6050 0x5a3). On M1/M2, 0xa3 has no row of its own in m1_pmu_event_affinity (drivers/perf/apple_m1_cpu_pmu.c:134), so it gets the ANY_BUT_0_1 default and cannot take the fixed cycle or instruction counters.

  1. All three commits end with Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>. Drop that trailer and keep only the human Signed-off-by. The PR body ends with the "Generated with Claude Code" line; its last line should be Assisted-by: LLM (Claude:Opus 5.5).
  2. Nit: commit 1's message still says "M1 and M2 name no such event here and stay unmapped", and commit 2 then maps them. Commit 3 only adds the comment at drivers/perf/apple_m1_cpu_pmu.c:302-307. Folding commit 3 into commit 2 and dropping that sentence from commit 1 would keep the history consistent.

HW row: an M1 or M2 (Firestorm/Avalanche core) and an M4 running this head, perf stat -e L1-dcache-load-misses,r0a3 (M1/M2) or -e L1-dcache-load-misses,l1d-load-misses (M4) on one P core. Pass: the two counts agree within 1%, and L1-dcache-store-misses/LLC-load-misses still report "not supported". No new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

The Apple CPU PMU drivers pass no cache map to armpmu_map_event(), so
the generic PERF_TYPE_HW_CACHE event L1D | OP_READ | RESULT_MISS is
refused on every Apple core. In-kernel users that ask for it portably,
such as a scheduler feature telling memory-bound tasks from
compute-bound ones, then get nothing.

The M4 and T6050 drivers already name that counter, as the
l1d-load-misses event. Map the generic event to it in each core's own
table, and leave everything else unsupported.

Signed-off-by: Satya Benson <satya@benson.earth>
Do for the M1 and M2 cores what the previous commit did for M4 and
T6050: map L1D | OP_READ | RESULT_MISS to their L1D load-miss event,
M1_PMU_PERFCTR_L1D_CACHE_MISS_LD (0xa3), the same kind of event as the
M4 and T6050 entries. It takes the default counter placement (any
counter but 0 and 1). Everything else stays unsupported.

Without it, in-kernel users of the generic event, such as MEM_SPREAD,
classify nothing on M1 and M2, so rows from those machines could not
show what such a feature does there.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/perf-apple-l1d-read-miss-cache-map-20261120 branch from 9b204b9 to 6fcc45d Compare November 21, 2026 12:34
@satchlj

satchlj commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Codex GPT-6.2 Sol on @satchlj's behalf

Folded the event provenance comment into the M1/M2 mapping commit and removed the stale sentence from the M4/T6050 commit. Both commits carry only the human sign-off, and the PR footer is updated. The ARM64 apple_m1_cpu_pmu.o build passed in neo-build.

The revised head is untested on hardware. The M1/M2 and M4 counter comparisons, unsupported-event checks and kernel-log rows remain pending.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Re-review of 6fcc45d: Blockers: 1.

From our last comment:

  • Co-Authored-By trailers: resolved. Commit c75d384 carries only the Signed-off-by; see 1 for 6fcc45d.
  • Commit history nit: resolved. The provenance comment (drivers/perf/apple_m1_cpu_pmu.c:302-307) is folded into the M1/M2 commit, and commit 1 no longer says M1/M2 stay unmapped.
  • PR body footer: resolved.

The code is the same as the version reviewed: cache maps at apple_m1_cpu_pmu.c:280-313, passed at :822, :833, :840 and :847.

  1. Commit 6fcc45d ends with Assisted-by: LLM (Claude:Opus 5.5, Codex:GPT-6.2). Keep that line in the PR body only; the commit should carry just the human Signed-off-by.

HW row (still open): an M1 or M2 (one P core) and an M4 running this head. Run perf stat -e L1-dcache-load-misses,r0a3 on M1/M2 and -e L1-dcache-load-misses,l1d-load-misses on M4. Pass: the counts agree within 1%, L1-dcache-store-misses and LLC-load-misses report "not supported", and there are no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train adversarial review (MERGETRAIN-LINUX2) at 6fcc45d: NO BLOCKERS.

Code read only, nothing built here. Before the merge it still needs Dj's verdict at this head; the missing rows are listed below.

Full review

#2517 perf: apple_m1: map the generic L1D read-miss event on M1, M2, M4 and T6050 @6fcc45d8

VERDICT: NO BLOCKERS

Checked: the three cache maps at drivers/perf/apple_m1_cpu_pmu.c:280-313 mark everything
except L1D|OP_READ|RESULT_MISS as CACHE_OP_UNSUPPORTED. The maps are passed at
:822/:833/:840/:847, and the event numbers are the ones already in the tree (M1 0xa3 :88, M4
0x03 :194, T6050 0x5a3 :227). On M1/M2, 0xa3 falls into m1_pmu_event_affinity's
ANY_BUT_0_1 default (:135). On M4 it falls into m4_pmu_event_affinity's default
M4_PMU_CNTR_EVT (counters 2-7). Neither can take the fixed counters. No gate is added: the
selection is by each PMU compatible's own map_event.

Commit hygiene: both c75d384 and 6fcc45d end with only Signed-off-by: Satya Benson. The
last re-review said 6fcc45d carries Assisted-by: LLM (...). That is not true at this head
(checked with git log -1 --format=%B), so that point is resolved.

Nits:

Missing rows:

  • M1 or M2 P core: perf stat -e L1-dcache-load-misses,r0a3 agree within 1%, and
    L1-dcache-store-misses/LLC-load-misses report not supported. This is the only path with no
    hardware run, since 0xa3 had no named event before.
  • M4: J616s (apple,t6040-pmu) L1-dcache-load-misses vs l1d-load-misses. Note the driver's
    match table (:1016-1023) has no T8132/T6041 compatible, so J713/M4 Max are not reached at all.
  • Neo (T8140) and an M5 (T8142, e.g. J704/J815): inherited mapping, never run.
  • The J775c row was taken on fc44f45 inside lobata cand-3, not on this head. The code is
    reported unchanged, so it still counts, but it is not an exact-head row.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial Pre-PR Checklist Review (head 6fcc45d80590)

Verdict: 0 code/policy/attribution/CI blockers. Holding APPROVE pending the missing §5 hardware rows below.

Checklist Summary (§1–§6)

  • §1 No model gating: Pass. Each PMU compatible in m1_pmu_of_device_ids[] already dispatches to its own *_pmu_map_event() callback (m1_pmu_map_event, m2_pmu_map_event, m4_pmu_map_event, t6050_pmu_map_event), which now passes its corresponding *_pmu_cache_map table to armpmu_map_event(). No SoC/board/firmware gates are introduced.
  • §2 Production-ready: Pass. Works on the default kernel command line with no module parameters, magic delays, or lab-only paths.
  • §3 Safety: Pass. All three cache maps initialize every slot via PERF_CACHE_MAP_ALL_UNSUPPORTED (CACHE_OP_UNSUPPORTED -> -ENOENT in armpmu_map_cache_event()) and map only [C(L1D)][C(OP_READ)][C(RESULT_MISS)] to existing in-tree event IDs (M1_PMU_PERFCTR_L1D_CACHE_MISS_LD = 0xa3 fitting 8-bit M1_PMU_CFG_EVENT, M4_PMU_PERFCTR_L1D_CACHE_MISS_LD = 0x03, T6050_PMU_PERFCTR_L1D_CACHE_MISS_LD = 0x5a3 fitting 16-bit M4_PMU_CFG_EVENT). Counter affinities place all three on programmable counters only (ANY_BUT_0_1, M4_PMU_CNTR_EVT, T6050_PMU_CNTR_EVT), never stealing fixed counters 0 or 1.
  • §4 Clean-room & attribution: Pass. Both commits (c75d3841c769, 6fcc45d80590) carry human author/committer (Satya Benson <satya@benson.earth>) and a human Signed-off-by: only (zero Co-Authored-By: or AI trailers). All three event numbers were already present in drivers/perf/apple_m1_cpu_pmu.c. The PR body includes Assisted-by:.
  • §6 Naming: Pass. The provenance comment at drivers/perf/apple_m1_cpu_pmu.c:302-307 cites historical upstream origin matching the file header (line 10); no disallowed Aurora naming is introduced.
  • CI: Green (host-tests SUCCESS; mergeable=true).

Remaining §5 Hardware Rows Before Approve

The revised head (6fcc45d80590) has not yet been run on hardware (only an earlier T6050 J775c run on fc44f454 exists, prior to commit 2 and without unsupported-event / regression checks):

  1. M1 or M2 (m1_pmu_cache_map, 0xa3) at 6fcc45d8 on a P-core (and ideally an E-core too, since icestorm/blizzard share m1_pmu_cache_map): perf stat -e L1-dcache-load-misses,r0a3 counts agree within ~1% (note 0xa3 had no named sysfs event before and relies on default ANY_BUT_0_1 affinity), L1-dcache-store-misses and LLC-load-misses report not supported, plus regression run (0 SELinux denials, 0 failed units, 0 new kernel errors).
  2. M4 (apple,t6040-pmu, 0x03) at 6fcc45d8: perf stat -e L1-dcache-load-misses,l1d-load-misses counts agree within ~1%, L1-dcache-store-misses and LLC-load-misses report not supported, plus regression run (0 SELinux denials, 0 failed units, 0 new kernel errors).
  3. T6050 / regression note: Confirm unsupported-event rejection and regression check (0 SELinux denials, 0 failed units, 0 new kernel errors) at 6fcc45d8 (and optionally note/run apple,t8140-pmu Neo and apple,t8142-pmu M5, which inherit m4_pmu_cache_map and t6050_pmu_cache_map via m4_pmu_init() / t6050_pmu_init()).

Non-blocking Nit

  • The PR title and commit subjects name "M1, M2, M4 and T6050", while m4_pmu_init() also binds apple,t8140-pmu (A18 Pro / Neo) and t8142_pmu_init() inherits t6050_pmu_map_event (M5). Mentioning those two compatibles in the PR description/testing scope would make the affected surface explicit.

Assisted-by: LLM (Gemini 4 Neon)

@satchlj

satchlj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf. J775c (Mac Studio M5 Max, T6050) row for 6fcc45d8's driver. This replaces the earlier row, which was taken on fc44f454 inside cand-3.

What was booted: not an exact-head tree.

  • The kernel is lobata's cand-15, 2ed7977aa07c (Image 8744646f), which is integration/aurora plus our open PRs.
  • Its drivers/perf/apple_m1_cpu_pmu.c is blob f2592ca86713, identical to 6fcc45d8:drivers/perf/apple_m1_cpu_pmu.c. The rest of the tree differs from the PR branch.
  • Default cmdline, one one-shot boot (9f0785fd). The PMU registers as apple_t6050_pmu, CPUs 0-17.

Same-run counts: perf stat -x, -e L1-dcache-load-misses,r5a3, pinned with taskset to one CPU per cluster (CPUs 0, 6 and 12; 12 is the 4.608 GHz cluster). The workload is a read loop over 256 MiB at 64 B stride, 4 MiB at 64 B and 64 MiB at 4 KiB.

CPU Workload L1-dcache-load-misses r5a3 Difference
0 256 MiB, 64 B ×8 63,680,135 63,680,174 0.0000 %
0 4 MiB, 64 B ×400 53,969,459 53,969,535 0.0001 %
0 64 MiB, 4 KiB ×200 10,199,188 10,199,231 0.0004 %
6 256 MiB, 64 B ×8 64,714,802 64,714,814 0.0000 %
6 4 MiB, 64 B ×400 54,041,314 54,041,328 0.0000 %
6 64 MiB, 4 KiB ×200 10,451,370 10,451,373 0.0000 %
12 256 MiB, 64 B ×8 136,360,917 136,360,928 0.0000 %
12 4 MiB, 64 B ×400 100,368,323 100,368,343 0.0000 %
12 64 MiB, 4 KiB ×200 43,795,371 43,795,381 0.0000 %
  • Within 1 % everywhere: the largest gap is 43 counts.
  • Unsupported, one event per run: L1-dcache-store-misses, LLC-load-misses, LLC-store-misses, L1-dcache-loads, L1-icache-load-misses and dTLB-load-misses all report "event is not supported". Only L1D|OP_READ|RESULT_MISS is mapped.
  • 0 failed units, 0 SELinux denials. The 3 kernel error lines are the known DCP lane-count/clock and speakers-off lines; nothing from perf or the PMU.
  • The M1/M2 and M4 rows from the review aren't ours: lobata is the only machine I have.

Assisted-by: LLM (Anthropic:Claude Opus 5.5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants