Skip to content

host/sysprof: the Mac's GPU clock, power and limits in their own trace (DM_SYSPROF) - #1041

Open
moretti wants to merge 1 commit into
seedds:mainfrom
moretti:host-profiler
Open

moretti wants to merge 1 commit into
seedds:mainfrom
moretti:host-profiler

Conversation

@moretti

@moretti moretti commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Narrowed to the Mac sampler, as asked. DM_SYSPROF=<file> (off by default, its own switch, separate from DM_NVN_TSV) writes what macOS did with the GPU and the process every 100 ms. Each sample is stamped on the same clock as the frame trace's @t_s, so with both switches set the two files line up by time.

DM_SYSPROF=<file>       rows: t_s  metric  value   (t_s = when the counters were read)
  dt_ms                 the interval the sample covers
  gpu_pstate            mean performance state while powered (P1 = lowest clock)
  gpu_mhz               mean clock, only when the frequency table matches the states
  gpu_on                share of time powered (powered is not busy)
  gpu_w                 GPU power
  gpu_boost             state the boost controller asked for
  gpu_cltm, gpu_droop   share of time a thermal / voltage-droop limit applied
  role, thermal, low_power
What changed since the first version Why
Own switch and own file, no more frame-row columns Opt-in separate from DM_NVN_TSV
Each reading left out on its own when missing, logged once The M6 had no frequency table and showed 0 MHz
gpu_mhz only when the table has one frequency per GPU state; gpu_pstate always My M5 Pro lists 13 frequencies for 15 states, so the old clock was biased low here too
Each IOReport channel fetched on its own, then merged into one subscription A missing one no longer drops the others
Submission-queue counters, perf_report.py and its verdicts removed Out of scope for this revision
@late_ms fix removed Already landed as 3984f5aa

Evidence

  • Before (M6): gpu_mhz 0 while the GPU was powered.
    After (expected from the code, not run on an M6 here): no gpu_mhz row. The log names the missing table and lists pmgr's voltage-states* properties; gpu_pstate, gpu_on and power still come through. A short M6 run would confirm it.

  • M5 Pro trace (Breath of the Wild 1.9.0, MacBook Pro M5 Pro, macOS 27.2, 4 m 46 s with both DM_SYSPROF and DM_NVN_TSV: 2,862 samples, 16,260 frames):

    Check Result
    Sample spacing median 100.0 ms, p99 104.7 ms
    gpu_on against the frames' GPU busy share in the same window correlation 0.97 at zero offset, 0.93 / 0.94 one sample either way, 0.87 at five
    Clock steps up by 2+ states 25; the frames' GPU time drops in the same 100 ms sample (P 1.0 → 4.8: 5.6 → 2.3 ms; P 1.2 → 3.5: 10.1 → 5.0 ms)
    gpu_mhz left out, as intended: GPUPH has 15 powered states, voltage-states9 13 frequencies (logged once)
    Thermal / droop limits 0% throughout
  • Mac host builds; clang-tidy (LLVM 23.1.4, as in CI) clean on the changed files; test_docs passes.

Merge Danger

Door: two-way. Nothing runs unless DM_SYSPROF is set, and no graphics code changes.

Blast Radius: diagnostics.

The sampler thread starts only with the switch set; on iOS the file compiles to an empty stub. regress.py check --games was not run: with the switch unset no new code executes in any game.

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts) docs Documentation labels Nov 3, 2026
@moretti
moretti force-pushed the host-profiler branch 2 times, most recently from 3833223 to 8dbdd41 Compare November 8, 2026 07:32
seedds added a commit that referenced this pull request Nov 18, 2026
A display-link wake can precede the texture's slot. Subtracting the
slot as unsigned nanoseconds wrapped and wrote a spurious 18.4
trillion ms in the NVN timing trace. Compare the timestamps first
and preserve the measured delay for late wakes.

The real acquire fixture checks the emitted TSV for a wake 1 ms
early and another 1.25 ms late. The early case fails on main.
Acquire and snapshot checks, Mac host build, docs and clang-tidy pass.

Co-authored-by: Paolo Moretti <1186409+moretti@users.noreply.github.com>
@seedds

seedds commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The @late_ms correction landed separately in 3984f5aa, with Paolo credited as co-author. The acquire fixture checks the actual TSV rows. A wake 1 ms before the slot logs 0.000, and a wake 1.25 ms after the slot logs 1.250.

The profiler proposal remains open here.

@seedds

seedds commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks, Paolo. The @late_ms fix has landed separately. Could you narrow this PR to the Mac sampler, with an explicit opt-in separate from DM_NVN_TSV? Timestamped samples would let us line up GPU clock, power, and limit readings with the existing frame trace.

On the M6, the sampler collected GPU power and powered time, but the frequency table was unavailable and the trace reported 0 MHz while the GPU was powered. Could you omit each unavailable counter individually so the other readings still come through?

Please keep the submission-queue counters and automatic drop verdicts out of this revision. A short trace on the original M5 Pro would confirm that the clock samples still line up with frame timing.

@moretti moretti changed the title Host profiler: the GPU clock, its limits and the process role in each frame's timing rows, and a report of one session host/sysprof: the Mac's GPU clock, power and limits in their own trace (DM_SYSPROF) Nov 21, 2026
@github-actions github-actions Bot added the game: 01007EF00011E000 The Legend of Zelda: Breath of the Wild label Nov 21, 2026
DM_SYSPROF=<tsv> (Mac, off by default) starts a sampler with the other diagnostic samplers at the host's start: every 100 ms it writes the GPU's mean performance state and, where pmgr's frequency table matches its states, its clock (gpu_pstate, gpu_mhz), its powered share (gpu_on), power (gpu_w), the boost controller's state (gpu_boost), thermal and voltage droop limits (gpu_cltm, gpu_droop), the process role, thermal state and Low Power Mode, read through IOReport without root.

Each row is t_s, metric, value: t_s is when the counters were read, in seconds since the host's start, the clock of DM_NVN_TSV's @t_s rows, so the samples line up with the frame rows by time; dt_ms is the interval each sample covers. The sampler waits on a fixed 100 ms grid at user-initiated QoS (at utility QoS macOS coalesced its timer: wakes 20-75 ms late on an M5 Pro).

A reading the system does not give is left out on its own and logged once. gpu_mhz is written only when the frequency table has one entry per powered GPU state: an M5 Pro's lists 13 frequencies for its 15 states (P1-P15), so the old mean was biased low there, and an M6 has no table (it wrote 0 MHz). The log then lists pmgr's voltage-states* properties. Each IOReport channel is subscribed on its own (its subgroup, or GPU Energy by name), so a missing one no longer drops the others.

Narrowed from the first form of the pull request: no columns in DM_NVN_TSV, no submission-queue counters, no perf_report.py; the @late_ms fix landed as 3984f5a.
@moretti

moretti commented Nov 21, 2026

Copy link
Copy Markdown
Contributor Author

@seedds Thanks for the review. I've narrowed this to the Mac sampler and force-pushed, so the PR is now one commit on current main.

  • Opt-in: DM_SYSPROF=<file>, separate from DM_NVN_TSV. The sampler writes its own TSV, one sample every 100 ms, stamped on the same clock as the frame trace's @t_s.
  • Missing readings: each one is left out on its own, and the log says once which are missing. On your M6, gpu_mhz should now be absent instead of 0, and the log lists pmgr's voltage-states* properties, so we can see where the frequency table lives on that chip. gpu_pstate, gpu_on and power still come through. I haven't run it on an M6, so a short run there would confirm it.
  • Removed: the submission-queue counters, perf_report.py and the drop verdicts.

One thing I found along the way: my M5 Pro has the same kind of problem. GPUPH has 15 powered states, but voltage-states9 only lists 13 frequencies, so the old MHz figures were biased low here too. The sampler now writes gpu_mhz only when the table has one frequency per state, and otherwise writes the mean performance state (gpu_pstate). So on both chips the clock shows up as a state number rather than MHz for now.

The M5 Pro trace is in the description: about 5 minutes of Breath of the Wild with both traces on. gpu_on follows the frames' GPU busy share with a correlation of 0.97 at zero offset, lower on either side. In the 25 times the GPU state jumped up, the frames' GPU time dropped in the same 100 ms sample.

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

Labels

docs Documentation game: 01007EF00011E000 The Legend of Zelda: Breath of the Wild host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants