Skip to content

soc: apple: show the fabric and DCS clock-generator words in debugfs - #336

Closed
joshuaswarren wants to merge 1 commit into
omacom:integration/aurorafrom
joshuaswarren:w73/pmgr-misc-debugfs
Closed

joshuaswarren wants to merge 1 commit into
omacom:integration/aurorafrom
joshuaswarren:w73/pmgr-misc-debugfs

Conversation

@joshuaswarren

Copy link
Copy Markdown

[Joshua's agent] Adds one read-only debugfs directory to apple-pmgr-misc: apple-pmgr-misc-<device>/fabric_ps and dcs_ps, mode 0400, each the whole clock-generator word of that system device (desired state in bits 3:0, actual state in bits 7:4).

Why: on the 16-inch M1 Max a PMP request bit moved the DCS word from state 7 to 9 and the fabric word from 3 to 7, and the GPU read bandwidth from 241 to 368 GB/s. Finding that took a separate probe module. With these files any measurement can record the memory-side state it ran in, next to its timing.

What it does: the show function reads the word through the same mapping the driver already uses at probe and on resume, and writes nothing. The directory is removed by a managed action when the device goes away. Without the debugfs, nothing changes.

Checked: the same change builds on the 7.1.12 lab kernel tree with its flags (object compiled, the strings present). The same two words, at the same addresses and through a non-posted mapping, were read on a 16-inch M1 Max by a throwaway module (fabric 0x333, DCS 0x777 at idle, unchanged over 20 samples a second). This patch itself has not been booted yet.

Read only: apple-pmgr-misc gets one debugfs directory with the whole clock-generator word of the fabric and DCS system devices (fabric_ps and dcs_ps, mode 0400, the desired state in bits 3:0 and the actual state in bits 7:4). It reads the words through the mapping the driver already uses and writes nothing. A performance measurement can then record the memory-side state it ran in next to its timing.

Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
@joshuaswarren

Copy link
Copy Markdown
Author

GREEN on b50e681

Reviewer identity: routed by Main to Sonnet/Claude, model id unverifiable here; implementer model unverified. Source review of the diff plus a comparison with the lab patch I reviewed separately (7851bc5b, GREEN). Not built or booted by me; the PR's ci / compile check is green (I did not check which objects it builds).

Checked at head b50e681 (base integration/aurora 2a76ae3, which is still the branch tip):

  • The added code is identical to the lab patch's pmgr-misc half, compared line by line: 36 added lines each, one difference, the comment on the show function, which here says "actual state bits 7:4". That is right for this file: it defines APPLE_CLKGEN_PSTATE_DESIRED GENMASK(3, 0) and APPLE_CLKGEN_PSTATE_ACTUAL GENMASK(7, 4).
  • Includes: linux/debugfs.h and linux/seq_file.h are added and are the headers for debugfs_create_dir/file/remove and DEFINE_SHOW_ATTRIBUTE/seq_printf; nothing else is needed.
  • Probe edit: the call sits after platform_set_drvdata and only when ret is 0 (at least one of fabric or DCS mapped), before the governor setup; nothing after it can fail the probe.
  • Read-only: the only device access is one readl_relaxed at offset 0 (APPLE_CLKGEN_PSTATE, the word the driver already reads in apple_pmgr_init_device and in its set_pstate paths). The governor's writes take misc->lock around a read-modify-write; a debugfs read does not need it, it is a single load and cannot disturb that sequence. During system sleep userspace is frozen, so no read overlaps the noirq writes.
  • pmp_owned: with PMP describing and owning the fabric and DCS p-states the register is still only read, so the patch changes nothing the PMP or the governor see. (The governor is already disabled in that case.)
  • Lifetime: misc and both ioremaps are devm resources registered before the debugfs action; the dir name and the removal action are registered after them, and the governor setup that follows registers nothing in devres (it uses INIT_*WORK and queue_delayed_work). Devres runs in reverse, so debugfs_remove runs first and drains in-flight readers before the mapping or misc go away. suppress_bind_attrs is set and there is no remove callback, so only module unload or a failed probe reach this; the existing governor-outlives-unload comment in the file already covers the first and the patch adds nothing to it.
  • Mode 0400 on both files; the directory has the default debugfs mode. If one of the two devices is not mapped its file is not created.

Not covered: what the files print on hardware (no boot), and the pre-existing if (!base) after devm_platform_ioremap_resource_byname (it returns an ERR_PTR), which this PR does not touch.

@scottjones scottjones left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We read this against b50e681 and it looks right to us. The files are only created for windows that mapped, they are 0400 under debugfs, and the devm action is registered after both ioremaps, so the directory is removed (and readers drained) before the mappings go away. The read is a single 32-bit readl_relaxed at offset 0 of a 0x400 window on both t600x and t602x, the same word the driver already reads at probe, and in the governor or suspend/resume, so we don't see a new SError risk. With CONFIG_DEBUG_FS=n, or if the directory can't be created, the calls fall through to the stubs and debugfs_remove ignores the error pointer.

On how this sits with #337: the base check in debugfs_init relies on base staying NULL when a window is absent. Today that only holds because a missing window makes the probe read an ERR_PTR before we ever get here, so #336 doesn't make anything worse on its own. With #337 in, a missing window returns early, base stays NULL from the kzalloc, and the file is skipped as intended. The two merge cleanly in either order.

Small things, not blocking:

  • checkpatch flags three lines over 100 columns (the comment on the show function, the devm_kasprintf line and the debugfs_create_file line) and the commit body is one unwrapped line.
  • The devm_kasprintf for the directory name isn't needed, since debugfs copies the name. A plain "apple-pmgr-misc" would do with one instance, or a stack buffer if we want the device name.

We built the object with clang W=1 on arm64 with debugfs on and off, and with #337 merged. We also booted it, with #337, on an M2 Max (J414c, t6021) at integration/aurora 396f2d6. The driver bound to 28e20c000.power-management, and apple-pmgr-misc-28e20c000.power-management/ has fabric_ps and dcs_ps at 0400. Reading four times a second at idle and under CPU, memory and GPU load, they always gave 0x00000555 and 0x00000999 (desired and actual equal). That's what we'd expect with idle_fabric_pstate at its default of 0, where nothing moves the fabric while awake. There was nothing in the kernel log from pmgr-misc, no "invalid resource" line, and no oops or warning.

@joshuaswarren

Copy link
Copy Markdown
Author

Note

🤖 GPT-6.1 Terra responding on behalf of Joshua Warren

The current head is b50e681fb588da49c7fcbf71bd6a7b499600a6c4. Its CI checks pass, including ci / result; attest was skipped. The current check run does not show a failure.

@joshuaswarren

Copy link
Copy Markdown
Author

Note

anthropic/claude-sonnet-5-5 responding on behalf of joshuawarren

Scott, this PR has your approval at head b50e681fb588da49c7fcbf71bd6a7b499600a6c4, and every check on that head passed. The first ci / result run on the head failed when its host test jobs were cancelled. The rerun at 10:54Z passed, including ci / result, ci / boot and ci / package. Could you merge it when you are ready?

@joshuaswarren

Copy link
Copy Markdown
Author

Note

anthropic/claude-opus-5-5 responding on behalf of joshuawarren

Scott, a short follow-up: this is still approved at head b50e681fb588, it is mergeable, and the rerun of every check on that head passed (the one failed ci / result is the earlier run whose host test jobs were cancelled). Could you merge it when you have a moment? Thank you.

@joshuaswarren

Copy link
Copy Markdown
Author

Moved to aurora-silicon/linux#2143 (same commit carried onto aurora-edge; kernel work continues on the aurora-silicon tree).

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.

2 participants