Skip to content

soc: apple: clpc: count I/O wait as busy - #2754

Draft
satchlj wants to merge 2 commits into
integration/aurorafrom
satchlj/clpc-io-busy-20261122
Draft

satchlj wants to merge 2 commits into
integration/aurorafrom
satchlj/clpc-io-busy-20261122

Conversation

@satchlj

@satchlj satchlj commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Claude Opus 5.5 on @satchlj's behalf.

soc: apple: clpc: count time a CPU spends waiting for I/O as busy when the CLPC decides whether a CPU cluster gets its DRAM controller (DCS) and fabric floor, as ondemand's io_is_busy does.

Why: a cluster requests a floor once its busiest CPU is busy for half of a 4 ms sampling period, for the SoC's sustain count of periods in a row. Busy time came from get_cpu_idle_time(cpu, &wall, 0), which counts I/O wait as idle. A CPU that submits I/O and waits for each completion never reaches the threshold, so its transfers run with both rails at state 0.

On J775c (Mac Studio, M5 Max), the CPU submitting 1 MiB QD32 direct NVMe writes is 18% busy and 49% in I/O wait. That is below the threshold, although schedutil's I/O-wait boost holds it at the top clock.

Change: one argument (io_busy = 1) and the comments. The threshold, sustain counts, tables and states requested are unchanged.

  • There is no SoC or board selection: the rule applies wherever the driver runs.
  • I/O wait only accrues while a task waits for I/O, so an idle machine still releases the floor (measured below).

Testing

J775c (T6050), lobata candidate stack (integration/aurora cacf3554 plus lobata's open PRs, including #2565's apple,cpu-busy-floor = <6 3>), with and without this commit (138e1d30 there, the same change as b67b0683 here). Default cmdline, one-shot trial boots.

Each row: fstrim, a 3 s pre-write of the same 2 GiB file, then two 8 s fio 1 MiB QD32 direct libaio writes. The CLPC's PMC agent floor is sampled every 0.25 s.

Kernel CLPC floor during the writes Write MB/s clat p50 / p99 µs Floor at idle afterwards
candidate, without 0 in 32/34 and 27/34 samples 11260 / 11253 2703 / 6521 0
candidate, with DCS 6 / fabric 3 in 31/34 and 30/34 12417 / 12374 2441 / 6193 0 (8/8 samples)
lobata's current default (an older stack with a local cpufreq hook) DCS 6 / fabric 3 throughout 12318 / 12322 2408 / 6259 held at DCS 6 / fabric 3
  • An earlier variant of this change, behind a T6050 table flag, gave 12411 / 12368 MB/s on another boot.
  • 7-Zip 18T with this commit: 189759 / 189485 / 188438, against 183–191k without it.
  • Regression run with this commit: 0 failed units, 0 SELinux denials. No new kernel error lines: the three present (speakers off, DCP lane count, DCP clock index) are on every candidate boot.
  • Slow I/O, random reads and a mixed load: see the cost rows in the comment below.
    • At 20 MB/s the floor is still almost never requested, at the same power.
    • 4k QD32 random reads go from 36,653 to 183,952 IOPS.
    • 7-Zip, alone and with a background writer, is unchanged.
  • Not measured:
    • other Macs: J775c is the only one I have, and owners of other machines are welcome to run the same rows;
    • USB or SD storage (none attached);
    • power over a long steady I/O load.
  • checkpatch --strict: clean.

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

A CPU cluster requests a DRAM controller and fabric floor once its
busiest CPU is busy for half of a sampling period, for the SoC's sustain
count of periods in a row. Busy time came from get_cpu_idle_time() with
I/O wait counted as idle. A CPU that drives I/O and waits for each
completion therefore stays below the threshold, and its transfers run at
the lowest memory and fabric states.

On J775c (T6050), the CPU submitting 1 MiB QD32 direct NVMe writes is 18%
busy and 49% waiting. The writes run at 11.2 GB/s with no floor, and at
12.4 GB/s with the board's busy-CPU floor (DCS 6, fabric 3) held.

Count I/O wait as busy, as ondemand's io_is_busy does. The threshold, the
sustain count and the states requested are unchanged. I/O wait accrues
only while a task waits for I/O, so an idle machine still releases the
floor.

Signed-off-by: Satya Benson <satya@benson.earth>
@RyanTheTide

Copy link
Copy Markdown
Contributor

The NVMe numbers make the case for counting I/O wait on that workload. Two problems before this can go in:

  • drivers/soc/apple/clpc.c:509: the baseline taken when a cluster is first found still calls get_cpu_idle_time(..., 0), which returns idle plus I/O wait (drivers/cpufreq/cpufreq.c:133-141), while the sample at :541 now subtracts idle only. On the first sample di is short by the whole I/O wait accrued since boot. It either underflows, and the sample is dropped, or it reads far busier than it was. With .sustain = 0 (t6041) one such sample is enough to request the floor. Please pass 1 there as well, so both reads count the same thing.
  • I/O wait is the time a CPU idles while some task sleeps on any I/O. It does not show that the transfer needs memory or fabric bandwidth. With this change, a write to a slow USB stick or SD card, a network filesystem, or a stream of journal fsyncs all hold DCS and fabric up, on every SoC in the table at :2123-2129, including the fanless M4 Air. The PR lists idle power under a steady I/O load as not measured. Could you add a power row on a battery machine (an M4 Air, for example) with a slow-device copy and an idle desktop, with and without this change? Alternatively, narrow the signal: require some real busy time alongside the I/O wait, or follow the schedutil I/O-wait boost instead of raw I/O-wait time.
  • The rows are on a stack with soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565's apple,cpu-busy-floor and other open PRs. It would help to know whether the gain also holds on the current integration/aurora.

Assisted-by: LLM (Claude:Opus 5.5)

@satchlj

satchlj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

Cost and coverage rows (iobusy-cost-row.sh): what this does to slow I/O, reads and mixed loads.

  • Setup: J775c, candidate stack as in the description, without this commit (boot 3da13385) and with it (boot 7b91d2b1). Default cmdline, one-shot boots.
  • Every 0.5 s: the CLPC's PMC floor, each cpufreq policy's frequency, and SMC DC input power (macsmc_hwmon power1_input).
Phase Floor held, without → with Mean DC input power, without → with Result, without → with
idle, 20 s 1/40 → 1/40 12.5 → 13.6 W —
fio --rate=20m, 1 MiB QD1 direct write, 20 s 4/40 → 2/40 11.2 → 11.2 W 20 → 20 MB/s
buffered dd writer, 20 s 40/40 → 40/40 28.4 → 27.7 W —
4k random read, QD32 direct, 10 s 1/20 → 20/20 17.3 → 24.6 W 36,653 → 183,952 IOPS (143 → 719 MB/s)
1 MiB write, QD32 direct, 10 s 1/20 → 20/20 22.8 → 30.9 W 9,780 → 12,425 MB/s
7-Zip 18T alone — — 190,317 / 183,364 → 186,480 / 186,671
7-Zip 18T + background QD32 writer — — 178,058 / 174,440 → 179,536 / 177,537; writer 12,354 → 12,422 MB/s

Slow I/O:

  • A CPU waiting on a 20 MB/s writer now counts as busy, but the floor is still almost never requested. Its policy sits low in its frequency range, and the floor is only requested in the top quartile.
  • Power is the same with and without the commit.
  • The idle difference (12.5 vs 13.6 W) is between two boots, with the floor equally rare in both, so I don't attribute it to this change.

The buffered writer and 7-Zip keep CPUs busy, so they hold the floor with or without the commit. With 7-Zip running, the background writer gets the floor anyway, which is why it reaches 12.4 GB/s without the commit too.

Random reads gain the most: 5× the IOPS at QD32 with the floor held.

Lapsed samples in the earlier write rows: the fio worker moves between clusters during a run (CPUs 16 → 1 → 0 here). A cluster it has just joined starts its busy streak again.

Still not measured:

  • USB or SD storage: nothing is attached to lobata;
  • other Macs;
  • power over a long steady I/O load. The SMC sensor is better than the outlet meter but still slow to update, so the power column is a coarse mean.

Regression: 0 failed units on both boots. The same 3 kernel notices appear on both, as on every candidate boot.

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

@satchlj

satchlj commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

Repeated on this PR's own base. The lobata candidate cand-13 is integration/aurora 606d37ec plus lobata's open PRs, including this commit. Default cmdline, boot 13d181f8, the same floor row as above:

  • 1 MiB QD32 direct writes: 12,252 / 12,362 MB/s, clat p50 2441 µs, p99 6193 µs.
  • CLPC floor DCS 6 / fabric 3 held in 31/34 samples during each write.
  • Floor 0 in 8/8 samples at idle afterwards.
  • 7-Zip 18T: 190,576 / 186,691 / 186,377.
  • 0 failed units, 0 SELinux denials, 3 kernel notice lines (the same as on every candidate boot).

The same kernel's switch-readiness checklist also reads 12,363 MB/s seq write, but that boot is being re-run because of unrelated load on the machine during it.

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

@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 review at b67b0683b9c2 against pre-pr-checklist.md:

Blockers

  1. §3 (Baseline/sample get_cpu_idle_time() accounting mismatch — drivers/soc/apple/clpc.c:509 vs 541):

    • apple_clpc_find_clusters() (clpc.c:509) still captures the initial per-CPU baseline with get_cpu_idle_time(cpu, &clpc->wall[cpu], 0) (which returns idle + iowait and reads *wall from get_cpu_iowait_time_us, per drivers/cpufreq/cpufreq.c:133-141).
    • apple_clpc_sample_cluster() (clpc.c:541) now reads get_cpu_idle_time(cpu, &wall, 1) (which returns idle only and reads *wall from get_cpu_idle_time_us).
    • On the first sample after cluster discovery, di = idle_1 - (idle_0 + iowait_0) is short by the cumulative I/O wait accrued since boot — either underflowing u64 (dropping the sample) or inflating busy up to 100% on an idle CPU. On the five SoCs with .sustain = 0 (t8132, t8140, t8142, t8152, t6041), one corrupted first sample immediately raises the rail floor. Line 509 must also pass 1.
  2. §3 / §5 (Cross-SoC power regression risk on all-quartile / .sustain = 0 SoCs and stock integration/aurora gap):

    • The slow-I/O cost explanation ("Its policy sits low in its frequency range, and the floor is only requested in the top quartile") relies on the out-of-tree candidate stack's #2565 (apple,cpu-busy-floor).
    • On stock integration/aurora, all four quartiles are non-zero on t6050 (DCS {2,4,5,5}, SOC {1,2,2,2}), t8132 (DCS {5,5,5,5}, SOC {3,3,3,3}, .sustain = 0), t6041 (DCS {5,5,5,5}, SOC {3,3,3,3}, .sustain = 0), t8140 (DCS {1,2,3,4}, .sustain = 0), and t8152 (DCS {2,4,6,7}, SOC {1,2,3,4}, .sustain = 0).
    • Consequently, on M4 / M4 Air (t8132, fanless battery machine) and M4 Max (t6041), any low-bandwidth I/O wait (USB/SD/NFS/fsync) even at minimum CPU frequency immediately triggers the maximum DCS 5 / SOC 3 floor on a single 4 ms sample.
    • Please: (a) verify the J775c NVMe and slow-I/O floor/power rows on stock integration/aurora (without #2565), and (b) either provide an idle + slow-I/O power row on a battery SoC with all-quartile maps / .sustain = 0 (such as t8132) or narrow the condition (e.g., requiring non-trivial CPU busy time or tying to a higher-demand signal) so slow I/O does not pin DCS/fabric floors on laptops.

Checks Passing

  • §1 / §2 / §4 / §6: No SoC/model gating, default cmdline, human author/committer and human Signed-off-by: only, Assisted-by: present in PR body, clean naming, all 7 CI checks (host-tests, source, rust-build, kunit, DWC3/ATC build matrix) green.

Assisted-by: LLM (Gemini 4 Neon)

The previous commit makes apple_clpc_sample_cluster() read
get_cpu_idle_time(cpu, &wall, 1), so I/O wait counts as busy, but
apple_clpc_find_clusters() still takes each CPU's baseline with
io_busy 0. With io_busy 0 the helper returns idle plus iowait and
reads the wall clock from the iowait counter. The first sample after
discovery then subtracts a baseline that includes all I/O wait since
boot: its idle delta is short by that amount, so the sample is either
dropped (the u64 difference wraps and fails di <= dw) or reads as
busier than the CPU was. On a SoC that raises its floor on one sample
(sustain 0), that one sample raises the floor.

Read both through one helper, so the baseline and the samples always
use the same counters.

Signed-off-by: Satya Benson <satya@benson.earth>
@RyanTheTide

Copy link
Copy Markdown
Contributor

10dcb69 fixes the baseline: apple_clpc_idle_time() (drivers/soc/apple/clpc.c:494-497) now feeds both the baseline in apple_clpc_find_clusters() (:523) and the sample (:549), so the first sample no longer wraps.

Still open:

  • The power question is unchanged. The code still raises DCS and fabric on I/O wait for every compatible in the table (clpc.c:2131-2137), and the only rows are from the J775c. The slow-I/O row there holds because of soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565's apple,cpu-busy-floor, which is still open and not in this tree. Without it, t8132 (apple_clpc_hw_t8132, sustain 0, :1576) requests the floor from a single sample at any CPU frequency. That is the fanless M4 Air. Please either show an idle and slow-device write power row on an M4 Air (or another battery T8132/T6040 machine) at this head, with and without the change, or narrow the signal so plain I/O wait at low CPU demand does not hold the floors (for example by requiring real busy time too). Stacking this on soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565 and saying so would also do.
  • The 02:32Z repeat is on cand-13, which still carries soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565, so it is not a run on integration/aurora alone.
  • Nit: the new helper sits between the comment "cpufreq policies can appear after probe; pick up new ones as they do." (:484) and apple_clpc_find_clusters(), so that comment now labels the helper.

Assisted-by: LLM (Claude:Opus 5.5)

@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.

Re-review at head 10dcb69cbbc84238c065d393cc140a5d774536df against pre-pr-checklist.md: Request changes — Blocker #1 is fixed, but Blocker #2 remains open.

Resolved

  1. Baseline/sample get_cpu_idle_time() accounting mismatch (clpc.c:494-497,523,549): Fixed in 10dcb69c by routing both apple_clpc_find_clusters() and apple_clpc_sample_cluster() through apple_clpc_idle_time() (io_busy = 1), eliminating the first-sample wrap/inflation.

Remaining Blocker

  1. §3 / §5 Cross-SoC power regression risk on stock integration/aurora (all-quartile / .sustain = 0 SoCs):
    • The slow-I/O safety premise ("Its policy sits low in its frequency range, and the floor is only requested in the top quartile") still depends on open PR #2565 (apple,cpu-busy-floor), which is not in integration/aurora. The 02:32Z repeat also ran on cand-13 (which carries #2565), so there is still no run on stock integration/aurora.
    • On stock integration/aurora, all four frequency quartiles map to non-zero floors on t8132 (DCS {5,5,5,5}, SOC {3,3,3,3}, .sustain = 0 — fanless M4 Air), t6041 (DCS {5,5,5,5}, SOC {3,3,3,3}, .sustain = 0), t8140 (.sustain = 0), t8152 (.sustain = 0), and t6050. Counting raw iowait as busy means any low-bandwidth I/O wait (USB/SD/NFS/fsync) at minimum CPU frequency immediately triggers the maximum DCS/fabric floor on a single 4 ms sample on t8132/t6041.
    • Please address this by: (a) verifying the J775c NVMe and slow-I/O rows on stock integration/aurora (without #2565), and (b) either adding an idle + slow-I/O power row on a battery all-quartile / .sustain = 0 machine (such as M4 Air t8132), narrowing the signal (e.g., requiring non-trivial CPU busy time or tying to a higher-demand condition), or stacking this PR explicitly on #2565.

Minor non-blocking nits

  • Bisectability: Please squash 10dcb69c into b67b0683 so b67b0683 does not remain in history with mismatched baseline/sample counters.
  • Misplaced comment (drivers/soc/apple/clpc.c:484): /* cpufreq policies can appear after probe; pick up new ones as they do. */ now sits above apple_clpc_idle_time() instead of apple_clpc_find_clusters().

Checks Passing

  • §1 / §2 / §4 / §6 & CI: No SoC/model gating, default cmdline, human author/committer + Signed-off-by: only on both commits, Assisted-by: present in PR body, clean naming, all 7/7 CI checks green on 10dcb69c.

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. Reply to @DjDeveloperr's review of b67b0683.

1. Baseline/sample mismatch: fixed in 10dcb69c. apple_clpc_find_clusters() and apple_clpc_sample_cluster() now read idle time through one helper, both with io_busy 1. The first sample after discovery no longer subtracts a baseline that includes all I/O wait since boot.

2. Premise on stock integration/aurora: it doesn't hold. You were right, and my slow-I/O explanation leaned on #2565.

Setup

Repeat, reversed order (tip + #2754 first):

Phase Tip + #2754 (7d8507d5) Tip (507f83a2)
Idle 11,048 mW 11,026 mW
Slow sync I/O 14,337 mW; floor 0x24/0x25/0x12 in 36 of 36 samples 12,625 mW; floor 0 in 36 of 36
NVMe 1M QD32 12,112 MB/s 12,056 MB/s

The slow-I/O cost is +1.65 W in the first order and +1.71 W in this one, so it follows the commit, not the boot order. The NVMe difference stays within 0.5 %.

Phase Tip Tip + #2754
Idle, 20 s 10,862 mW; floor 0 (38 of 40 samples) 10,863 mW; floor 0 (38 of 40)
Slow sync I/O: 4 KiB O_DSYNC writes, 20 s (12 MiB both) 12,633 mW; floor 0 (35 of 36) 14,282 mW; floor 0x25/0x24 (36 of 36)
NVMe 1M QD32 direct write, 10 s 12,107 MB/s; floor 0x24 12,104 MB/s; floor 0x24
Idle after 10,858 mW 10,880 mW
  • On stock, this PR doesn't speed up the NVMe write: 12.1 GB/s either way. The floor during the write is the same 0x24, raised there by the hold reason (reason_bits 0x10), not the CPU busy path.
  • What it does on stock: pins the DCS/fabric floor during slow synchronous I/O. That costs about +1.65 W (+13 %) for the same 12 MiB.
  • That is the laptop risk you describe. On t8132 and t6041, with all-quartile maps and sustain = 0, it would happen from one sample.
  • Where the gain came from: not isolated (corrected; an earlier version of this comment blamed soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565's busy floor). soc: apple: clpc: a board's busy-CPU floor (apple,cpu-busy-floor); J775c at 6/3 #2565 only replaces the top frequency quarter's entry (apple_clpc_cpu_state()), so it doesn't explain a difference at low frequency. The 9.44 GB/s this PR was written against was one unordered cand-12 run. Which of the candidate's other changes makes the difference, if any does, I haven't isolated.
  • What is measured: the candidate with this PR (cand-16b, Image d6dbf747) writes at 12,326 MB/s and holds 0x25/0x12 during the same slow I/O (13,601 mW). The stock tip writes at 12.1 GB/s without it.
  • Conclusion: on the stock tip this PR has a measured cost and no measured gain.

Next: I'm moving this PR to draft.

  • Before anything is folded anywhere, I'll measure the candidate without this PR, order-controlled, to see whether its NVMe write needs it at all.
  • If it doesn't need it, this PR closes.
  • Both commits stay on the branch as they are until that's decided.

0 SELinux denials on both boots. The one failed unit on both is systemd-modules-load (no i2c_dev module in that build), the same in both arms.

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

@satchlj

satchlj commented Nov 22, 2026 •

Copy link
Copy Markdown
Member Author

Claude Opus 5.5 on @satchlj's behalf.

This is the #2483 / #2754 pairing on lobata (J775c, t6050 max): two A-B-B-A palindromes of one-shot boots, run on 2026-11-22. The same text is on #2483 and #2754.

Builds

Decision rule, written before round 1

Accept the narrowed #2754 if, in both orders:

Round 1: with, narrow, without, without, narrow, with

Arm (boot) QD32 MB/s QD32 W 4 KiB O_DSYNC W O_DSYNC floor
with (1) 12323 31.71 14.22 0x24, 21 of 36 samples
narrow (2) 12114 29.46 12.62 0
without (3) 11237 23.01 12.66 0
without (4) 11109 21.80 12.58 0
narrow (5) 12226 30.05 12.73 0
with (6) 12354 31.90 13.53 0x12, 16 of 36 samples

Narrow is −1.4 % on QD32 against "with" and +0.05 W on O_DSYNC against "without", so it passes the rule. The 4 % threshold, though, was fitted to these two workloads, which is why round 2 was run.

Round 2: held-out workloads, predictions written first

Order: narrow, without, aio-revert, aio-revert, without, narrow.

Arm (boot) QD32 MB/s QD1 4 KiB random read: IOPS / W / floor-raised samples 4 concurrent 4 KiB O_DSYNC writers: W / floor-raised samples
narrow (1) 12203 14678 / 16.15 / 5 of 20 12.69 / 5 of 30
without (2) 11254 13249 / 15.53 / 0 12.55 / 0
aio-revert (3) 11626 13473 / 13.28 / 0 12.57 / 1
aio-revert (4) 11666 12264 / 13.15 / 2 12.53 / 3
without (5) 11360 13951 / 15.41 / 0 12.49 / 2
narrow (6) 12188 14109 / 16.01 / 1 12.83 / 9
  • QD1 random read. Predicted: the floor is raised. Held in part: a few samples. Narrow is +3.5 % IOPS and +0.6 W against "without".
  • Four concurrent writers. Predicted: the floor is not raised. Failed: narrow raised it in 5 and 9 of 30 samples, at +0.24 W.
  • aio-revert. Predicted: QD32 returns to the stock tip's 12.0-12.2 GB/s, measured earlier and not in this palindrome. Failed: it reached 11.63 and 11.67 GB/s, against 11.25 and 11.36 for "without".
  • Also run: a buffered-write held-out, which is invalid because it finished before its sampling window. I also logged a per-window busy distribution. Its 100 ms windows count in 10 ms ticks, too coarse to resolve a 4 % threshold.

What this shows

Raw rows are in lobata's session evidence: claude-narrow2754-* and claude-r2-*.

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