Skip to content

cpuidle: apple: Measured CPU PD residency and exit latency for J514S - #497

Open
ilyasakin wants to merge 1 commit into
omacom:integration/aurorafrom
ilyasakin:cpuidle-apple-j514s-residency
Open

ilyasakin wants to merge 1 commit into
omacom:integration/aurorafrom
ilyasakin:cpuidle-apple-j514s-residency

Conversation

@ilyasakin

Copy link
Copy Markdown

What this changes and why

cpuidle-apple gives CPU PD a 10 ms target residency and a 10 us exit latency on every Apple SoC it binds to. On the J514S (MacBook Pro 14", M3 Pro, T6030), a running desktop rarely predicts 10 ms of idle:

  • menu keeps the cores in WFI for 24-38% of their idle time, and counts about two thirds of its CPU PD entries as "too deep" (above).
  • Those short periods still save power. teo, which avoids them, kept the cores in CPU PD 9% of the time and drew 0.9 W more than menu.

This sets CPU PD's target residency to 500 us and its exit latency to 20 us on the J514S only. Every other Apple SoC keeps the defaults.

Why 500 us (balanced), and what 100 us did

I swept 10 ms / 2 ms / 500 us / 100 us / 20 us and then compared 10 ms, 500 us and 100 us under real workloads. 100 us saved slightly more power, but costs more where a wakeup from CPU PD sits on the critical path:

Averages of two rounds 10 ms (today) 500 us (this PR) 100 us
1080p60 software-decoded video, mean power 13.85 W 12.72 W (−1.13 W) 12.35 W (−1.50 W)
Dropped frames in that playback 0 0 0
fio 4k random read, QD1, O_DIRECT 10344 IOPS 9709 (−6%) 9018 (−13%)
pgbench TPC-B, 1 client (fsync) 1341 tps 1369 (+2%, noise) 1256 (−6%)
pgbench select-only, 1 client 16525 tps 16875 (+2%, noise) 15927 (−4%)

500 us keeps about 75% of the saving, at half the QD1 cost and with no measurable cost to single-client database throughput. If someone wants the extra power, a power-saver profile could lower it further, but that's a separate change.

What was tested

  • Mac model and chip: J514S, MacBook Pro 14" M3 Pro (T6030), 11-core.
  • Method: a kernel with this commit plus a local, not-submitted knob to switch the two values at runtime. Old and new values alternate, two rounds each. Power is the SMC's total system power (macsmc_hwmon "Total System Power"), on AC at 100%.
  • Idle power (display off, the usual applications open, an audio stream active, 90 one-second samples per phase, medians):
Round 1 Round 2 CPU PD share of idle time
10 ms / 10 us 4.78 W 4.77 W 62-63%
500 us / 20 us 3.88 W 3.86 W 94%

A quieter desktop saved less: about 0.1-0.2 W at 500 us and 0.24 W at 100 us. The more short idle periods the system has, the larger the saving.

  • Unchanged within run-to-run noise:

    • pgbench select-only with 8 clients;
    • redis-benchmark with one client;
    • a three-pass kernel subdirectory build (22.7-23.1 s);
    • perf bench sched messaging (hackbench, 0.25 s);
    • Wi-Fi ping to the router (p50 2.99 → 3.09 ms);
    • a PipeWire stream forced to a 64-frame quantum (1.3 ms), 30 s: 0-1 xruns in every run, with any setting.
  • Wakeup latency (a 1 ms clock_nanosleep loop and a pipe ping-pong between two cores, 3000 iterations, p50):

    • the timer woke 57 → 68 us late;
    • a round trip to an idle core took 10-20 us longer.

    The p99 and maximum varied as much between two runs of one setting as between the settings. That 10-20 us is why the exit latency is now 20 us: a PM QoS request below 20 us keeps the cores in WFI.

  • Host test: tools/testing/selftests/drivers/gpu/apple-dcp/run.sh compiles this driver into its cpuidle-s2idle replay. Its results match the base's. Locally that stage fails at the base too, on a newer clang's -Wunused-but-set-global in the harness. With only that warning off, the replay passes at the base and at this head.

  • Build: make W=1 drivers/cpuidle/cpuidle-apple.o (clang) is clean. checkpatch is clean apart from the trailers.

What was NOT tested

  • Other machines: the J516S and the other T603x boards, and M1/M2/M4. They are not matched, so nothing changes for them.
  • Battery runtime: I didn't run a full discharge. The power figures are on AC.
  • suspend-to-idle: it picks the deepest state whatever these values are, so it isn't affected. I didn't run a suspend cycle on this commit.

Risk

  • Latency-sensitive work on the J514S: QD1 storage reads lose about 6%, and a wakeup from CPU PD takes 10-20 us longer. Anything that needs less can hold a PM QoS request below 20 us.
  • Everything else: unchanged.

AI assistance

  • I used an AI tool or agent to write or draft part of this change: Claude (claude-opus-5-5), via Claude Code. It found the residency problem, ran the sweeps and workload comparisons, wrote the patch and this text, with me running the machine and reviewing.
  • A human has read the whole diff and takes responsibility for it.

🤖 Generated with Claude Code

CPU PD's target residency is 10 ms and its exit latency 10 us, on every
Apple SoC this driver binds to. On a J514S (MacBook Pro 14", M3 Pro), a
running desktop rarely predicts 10 ms of idle: with the usual applications
open and the display off, the cores spent only 62-76% of their idle time
in CPU PD under menu, and menu counted two thirds of its CPU PD entries
"too deep". Those short CPU PD periods save power all the same: teo, which
avoids them, kept the cores in CPU PD 9% of the time and drew 0.9 W more.

On the J514S, set the target residency to 500 us and the exit latency to
20 us. The values were switched at runtime on this commit, alternating
with the old ones, two rounds each; power is the SMC's total system power:

  display off, usual applications open, an audio stream active (medians):
    10 ms / 10 us   4.78, 4.77 W   (CPU PD 62-63% of idle time)
    500 us / 20 us  3.88, 3.86 W   (CPU PD 94%)
  1080p60 software-decoded video, 55 s (mean), no dropped frames in any:
    10 ms 14.09, 13.61 W; 500 us 12.71, 12.73 W; 100 us 12.39, 12.31 W

A quiet desktop with the display off saved less: about 0.1-0.2 W at
500 us (with a 10 us exit latency) and 0.24 W at 100 us.

100 us was evaluated as well and saved slightly more power, but costs
more where a wakeup from CPU PD sits on the critical path. Averages of
two rounds, 10 ms / 500 us / 100 us:

  fio 4k random read, QD1, O_DIRECT   10344 / 9709 / 9018 IOPS
  pgbench TPC-B, 1 client (fsync)      1341 / 1369 / 1256 tps
  pgbench select-only, 1 client       16525 / 16875 / 15927 tps

500 us is the balanced choice: about 75% of the saving at half the QD1
cost and none to single-client database throughput. With 8 pgbench
clients, redis-benchmark at one client, a three-pass kernel build,
hackbench and Wi-Fi ping, results matched within run-to-run noise, and
a PipeWire stream with a 64-frame quantum saw 0-1 xruns in 30 s either
way.

A 1 ms timer woke 57 -> 68 us late (p50) and a pipe round trip to an
idle core took 10-20 us longer once CPU PD was used; the p99 and maximum
varied as much between runs of one setting as between settings. A PM
QoS request below 20 us keeps the cores in WFI. suspend-to-idle picks
the deepest state regardless of these values. Other Apple SoCs keep the
defaults: only this machine was measured.

Assisted-by: Claude:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Ilyas Akin <ashnwor@gmail.com>
@c4software

Copy link
Copy Markdown

Tested on a second J514S. CPU PD residency=500us latency=20us, WFI 1/1, governor menu. No issues in a desktop session, including mpv test-pattern playback and three suspend/resume cycles.

Not tested: power on its own, and battery runtime.

Test setup

Testing and write-up assisted by Claude Code.

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