Repository navigation
Add PmcProbe: Apple Silicon PMU probe for lookup branch mispredicts - #36
Merged
Merged
Conversation
A small harness that reads per-thread PMU counters (cycles, instructions, branches, branch mispredicts) around the same lookup loops as ReadBenchmark, across three node layouts (sorted digests + SIMD window, Eytzinger digests, no digests) and three key patterns (fixed, memorizable repeating sequence, never-repeating sequence). Uses the private kperf/kperfdata frameworks via P/Invoke (the machinery behind Instruments); requires sudo, Apple Silicon only — see the README for usage, caveats, and measured M5 results. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Kpc.cs holds the kperf/kperfdata P/Invoke surface, Pmc.cs the event setup and per-thread counter reads, Program.cs the benchmark driver. No behaviour change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pmc.Read now returns a PmcCounters value instead of filling a ulong[]. The struct pins one 8-byte slot per event in EventNames order, exposes an indexer over the slots, a subtraction operator for deltas, and owns the markdown header/cell rendering that Program previously hand-rolled. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The kernel fills the counter buffer in physical-slot order while PmcCounters fields sit in event order; kpep's register map connects the two. Init now verifies the map is the identity permutation (and probes one short read) — when it is, Read hands the struct itself to kpc_get_thread_counters with no scratch buffer or permute, and falls back to the permuted path otherwise. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…is identity" This reverts commit f8fe3a3.
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.
Adds
sandbox/PmcProbe, a diagnostics harness that reads Apple Silicon PMU counters around the same lookup loops asReadBenchmark, to verify that the timing gap between predictable and unpredictable key streams is caused by branch mispredictions rather than caches.kperf/kperfdataframeworks (the machinery behind Instruments); C# port of ibireme'skpc_demo.csudo, Apple Silicon only, dev-machine diagnostics — caveats documented in the README along with measured M5 resultsHighlights from the M5 run (per lookup): mispredicts are ~0 whenever the predictor can memorize the key stream, 3.1 (digest+SIMD) / 6.1 (no digest) on truly random keys, and ~0 for the branch-free Eytzinger descent; the cycle deltas put one mispredict at ~40 effective cycles.
🤖 Generated with Claude Code