Skip to content

power: supply: macsmc: report the adapter's input power as power_now - #2372

Merged
DjDeveloperr merged 1 commit into
mainfrom
powerctl/ac-power-now
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
powerctl/ac-power-now

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The macsmc AC supply reports how much the adapter may deliver (input_power_limit) but not how much the Mac takes from it. You can't see the charge rate against the adapter's headroom without turning on the driver's debug log.

Change

The SMC already has the input power: PDTR, the DC-in power in watts. It is the "In" value that the driver's log_power debug output prints. When the key exists, it is now reported as power_now on macsmc-ac. The read goes through a small helper, and a new KUnit suite, macsmc-power-ac, checks the float conversion and error handling.

Every machine gets this through key presence at probe. There is no board or SoC check.

Testing

  • J616s (16-inch MacBook Pro, M4 Pro), fleet75, on a 15 W USB-C source, log_power on for 40 s: In 12.92 W, Sys 6.2 W, Batt 6.7 W. PDTR is the sum of the system and battery legs, so it is the adapter's input.
  • M2 (J413), fleet74, signed test module swapped in at runtime: macsmc-ac/power_now read 2.32-2.35 W while log_power printed In 2.32-2.35 W (battery full, 0 W), and the property appears only with the test module. The stock module was put back afterwards.
  • J616s (T6040), fleet75, same swap: power_now 12.94 W against In 12.94-12.95 W while the battery took 6.7 W.
  • M1 Pro (J316s, T6000), fleet74, same swap: power_now 3.39-3.47 W against In 3.42-3.47 W (battery full).
  • Built against the fleet75 configuration with W=1 (clang): no warnings. The module is signed with the fleet key.
  • KUnit on arm64 (kunit.py, qemu virt, LLVM, MFD_MACSMC + MACSMC_POWER with their KUnit options): macsmc-power 1/1, macsmc-power-charge 14/14 and the new macsmc-power-ac 1/1 passed; 35 tests run in total, 34 passed, 1 skipped (a GPU test that needs CONFIG_UCLAMP_TASK).

Still to run

Nothing on our machines: rows done on T6000, T8112 and T6040. Other SoCs get the property only where the SMC has PDTR.

Reviewer detail
  • Key: PDTR, 4-byte IEEE-754 float in watts, read with the driver's existing apple_smc_read_f32_scaled() at a scale of 1e6, so the value is in µW as power_supply expects. 140 W fits in an int with room to spare.
  • The property is registered only when apple_smc_key_exists(PDTR), the same way the driver already handles ACPW and the legacy AC-n/AC-i keys.
  • KUnit vectors: 0x414eb021 (12.918 W) -> 12918000 µW, 0x430b8000 (139.5 W) -> 139500000 µW, 0 -> 0, and a read error is passed through.
  • PDTR is the value macsmc_do_dbg() already prints as "In" (Hector Martin's debug mode, dbg print added in dbfcab8).
  • macsmc-power.c is identical between fleet75 (48cac48) and this base, so the fleet75 test module is the same code as this PR.

The AC supply tells how much the adapter may deliver (input_power_limit,
from ACPW) but not how much the system takes from it now. The SMC has
that too: PDTR is the DC-in power in watts, the "In" value of the
driver's own log_power debug output.

On a 16-inch MacBook Pro (M4 Pro, J616s) on a 15 W USB-C source, PDTR
read 12.92 W while the SMC's system power read 6.2 W and the battery
took 6.7 W, so PDTR is the input that feeds both.

Report it as power_now on the AC supply when the key exists. With the
battery's own power_now this gives the adapter's headroom and the charge
rate without the debug log. Read it through a helper and test the float
conversion with KUnit.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 19, 2026 17:06
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No blockers.

power_now on macsmc-ac is registered only when PDTR exists (drivers/power/supply/macsmc-power.c:1299-1300). That makes at most 5 of the 10 MACSMC_MAX_AC_PROPS slots. The read goes through the existing apple_smc_read_f32_scaled() (:157-196), which clamps to INT_MAX, and 140 W in µW is about 1.4e8, so a real adapter never reaches that. Zero and denormal floats come back as 0. The KUnit suite stubs apple_smc_read through its existing KUNIT_STATIC_STUB_REDIRECT and covers the read error path. The three Mac rows (T6000, T8112, T6040) match the debug "In" value within 0.05 W. The commit has a human Signed-off-by and no agent trailers. host-tests pass.

  1. Nit: the PR body has several blank lines after Assisted-by: LLM (Claude:Opus 5.5); trim them so it really is the last line.

HW row: the existing rows swapped the module in at runtime. Add one boot of the fleet kernel with this commit built in on any of the three Macs, default command line: macsmc-ac/power_now present and tracking the adapter, 0 AVC, 0 failed units, 0 new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

No blockers in review; the one thing still needed is a boot of the fleet kernel with this commit built in (not a module swapped in at runtime) on a T6000, T8112 or T6040 Mac, with the default command line, showing macsmc-ac/power_now present and tracking the adapter.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review at 969abb4. The AC power supply advertises POWER_NOW only when the SMC reports the PDTR key. The existing adapter-capacity property stays separate from the live reading. The host suite covers scale, zero and read errors. Please include an unplug/replug row on J413 that maps unsupported and unplugged behavior, and a positive live adapter reading alongside battery power. These are different physical quantities.

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

Formal §1–§6 pre-PR checklist review at 969abb49d0662bd805b7152b99080c7b8287d38c:

Code and tests look clean and still apply cleanly to integration/aurora (not superseded):

  • §1 No model gating: Pass. POWER_SUPPLY_PROP_POWER_NOW is registered on macsmc-ac strictly via apple_smc_key_exists(power->smc, SMC_KEY(PDTR)) (5 of 10 MACSMC_MAX_AC_PROPS slots used).
  • §2 Production-ready, no hacks: Pass. Verified apple_smc_read_f32_scaled(..., 1000000): max 24-bit mantissa × 10⁶ is 44 bits (no u64 intermediate overflow), 0.0f/subnormals yield 0, 140 W+ fits comfortably within INT_MAX (~2147 W in µW), and read errors propagate cleanly. host-tests CI passes and the new macsmc-power-ac KUnit suite checks scaling, zero, and -EIO.
  • §3 Safety: Pass (read-only SMC telemetry).
  • §4 Clean-room and attribution: Pass. Commit 969abb49d066 has human author/committer (Ryan Murray <[email protected]>) and human Signed-off-by: only, zero AI trailers in commit; PR body includes Assisted-by:.
  • §6 Naming: Pass.

Blocker:

  • §5 Evidence (Blocker): All three reported Mac runs (J413, J616s, J316s) used a runtime-swapped macsmc-power.ko module on fleet74/fleet75 rather than booting a kernel built with this commit on the default command line, did not include the §5 regression check (0 SELinux denials / 0 AVC, 0 failed units, 0 new kernel errors), and did not record unplug/replug behavior (macsmc-ac/power_now unplugged vs plugged alongside macsmc-battery/power_now).

Please add one full-boot row on a T6000, T8112 (e.g., J413), or T6040 Mac with this commit built into the kernel on the default command line, covering plugged and unplugged macsmc-ac/power_now readings alongside macsmc-battery/power_now plus the regression check (0 AVC, 0 failed units, 0 new kernel errors).

@github-actions github-actions Bot added area:power Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Merge readiness at 969abb49: not ready yet

Check Detail
CI at head ok 1 check passed
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head no no line with the head SHA 969abb49, a Mac and a result in the PR body or a comment
Conflicts ok not computed yet
PR text adopt when you next edit add a 'Tested:' line; a 'Risk:' line (door and Macs) (guide)

Areas: area:power

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

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

Verdict: MERGE at 969abb49d066

Blockers: none.

Checked: no Apple material, no gates. PDTR is the sum of the system and battery legs, so it's the adapter's input, and the property only appears when it's read. Rows at this head's code: J616s (In 12.92 W against Sys 6.2 + Batt 6.7 W), J413 (power_now 2.32–2.35 W matching log_power) and J316s, each with the module built from this commit. A module built from the head counts as the row; a full kernel boot isn't needed for a driver module. KUnit test added, CI green. This replaces my earlier review.

Evidence

Read 969abb49 (macsmc-power.c, macsmc-power-test.c) and the three rows. A plugged/unplugged comparison of macsmc-ac/power_now is a check after the merge.

@DjDeveloperr
DjDeveloperr dismissed their stale review November 24, 2026 19:42

Superseded by the review at 969abb4

@DjDeveloperr
DjDeveloperr merged commit 69d1553 into main Nov 24, 2026
2 checks passed
@RyanTheTide
RyanTheTide deleted the powerctl/ac-power-now branch November 27, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:power Area from CODEOWNERS (bot) changes-requested A reviewer requested changes (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants