Skip to content

iio: aop_als: stop the reports for system sleep - #3404

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/aop-als-stop-for-sleep
Nov 27, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/aop-als-stop-for-sleep

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What: iio_aop_als now stops the light sensor's reports for system sleep and starts them again after it, as aop_las already does for the lid angle. In suspend-to-idle the reports kept arriving as AOP mailbox interrupts (about 2.7 a second on a J413) and woke a CPU for readings nobody takes. This is the suspend part of #2713, on top of #3393 (merged).

Tested: at 116a2c10 (rows below re-run at this head; first run at db323325), built as a module against the fleet89 tree and loaded on the running fleet89 kernel, stock module first, then this one. Counts are AOP mailbox interrupts during one 20 s rtc sleep.

  • J413 (M2 Air, VD6286, s2idle by default): 83 and 82 interrupts with the stock module, 29 and 28 with this one (db323325: 84/81 vs 28/28). A test-only build where the stop fails (ETIMEDOUT) still had reports back at 46/10 s after each wake. Reports came back after every wake (46-47 per 10 s, same as before the sleep).
  • J700 (MacBook Neo, CT817): two deep sleeps and one s2idle. Reports came back after every wake (51 per 10 s). The s2idle took 6 interrupts in 21 s, against the sensor's 5 a second when armed.
  • Both Macs were left on the stock module with the driver bound: saved fleet89, empty next entry, Enforcing, 0 failed units.

Risk: two-way · Macs with an AOP light sensor. Every part now gets a PM notifier. The CT817 wake path behaves as before (#2528); VD6286/CT720 parts gain a stop before the sleep and a restart after it.

Not yet: the power saved per hour of s2idle hasn't been measured; only the interrupt counts above. No CT720 Mac in the lab; the VD6286 takes the same code path (one interval write each way). Not yet run on a cold boot of a kernel built from this head. Lux read 0 in the dark lab rooms, so these rows don't show light-following.

Details
  • PM_SUSPEND_PREPARE: record the attempt, then write interval 0. A failure is logged and never refuses the sleep.
  • PM_POST_SUSPEND: the CT817 gets the whole arming sequence after every sleep, because its firmware stops the reports for system sleep even when the host didn't (iio: aop_als: arm the CT817 again after system sleep #2528). The other parts get ALS_INTERVAL_US back after every attempted stop, including one whose reply was lost (review item; fixed in 116a2c10).
  • The part-specific branch is chosen by the part the AOP reports, the same selection the driver already makes. No chip or board gate.
  • Found while measuring: on the current fleet89 default (which predates iio: aop_als: arm the CT817 again after system sleep #2528) the J700's light sensor stays silent after the first deep sleep of a boot (50 reports per 10 s before, 0 after). Main and Edge already carry iio: aop_als: arm the CT817 again after system sleep #2528.
Evidence

J413, 20 s rtcwake -d rtc1 -m freeze, AOP mailbox 24a408000 (also carries the other AOP sensors):

-- stock module
   awake: 46/10s
   sleep freeze rc=0 wall=21.62s success 23->24: AOP mbox during sleep 84
   after wake: 46/10s
   sleep freeze rc=0 wall=20.99s success 24->25: AOP mbox during sleep 81
   after wake: 46/10s
-- new module
   awake: 46/10s
   sleep freeze rc=0 wall=20.95s success 25->26: AOP mbox during sleep 28
   after wake: 46/10s
   sleep freeze rc=0 wall=20.99s success 26->27: AOP mbox during sleep 28
   after wake: 47/10s
-- stock restored
   awake: 46/10s

Earlier the same night, with the ALS stopped by unbind instead: 26 interrupts per 21 s sleep. With it armed: 84.

J700, 20 s rtcwake -m mem x2 + -m freeze, AOP mailbox 310608000:

-- stock module (fleet89, without #2528)
   awake: 50/10s
   sleep mem rc=0 wall=20.44s success 2->3: AOP mbox during sleep 14
   after wake: 0/10s
   sleep mem rc=0 wall=20.97s success 3->4: AOP mbox during sleep 12
   after wake: 0/10s
   sleep freeze rc=0 wall=21.06s success 4->5: AOP mbox during sleep 0
   after wake: 0/10s
-- new module
   awake: 51/10s
   sleep mem rc=0 wall=20.87s success 5->6: AOP mbox during sleep 18
   after wake: 51/10s
   sleep mem rc=0 wall=20.98s success 6->7: AOP mbox during sleep 18
   after wake: 51/10s
   sleep freeze rc=0 wall=21.08s success 7->8: AOP mbox during sleep 6
   after wake: 51/10s
-- stock restored
   awake: 51/10s

No new kernel warnings in either run.

Build: aop_als.o compiles against main 2d96d922 with no warnings (fleet config, clang/LLD 22.1.6, rustc 1.97.1, bindgen 0.73.2). The test module was built against fleet89 645f7cd3 with an identical config and symbol table. rustfmt --check is clean; checkpatch reports 0 errors and 0 warnings.

Revert: git revert -m 1 <merge>; ALS reports run through system sleep again, and the CT817 is re-armed after wake as before.

The light sensor reports on its own every 200 ms, and each report is an
AOP mailbox interrupt. Nothing stopped them for a system sleep, so in
suspend-to-idle they went on waking a CPU for readings nobody takes.

On a J413 (M2 Air, VD6286, suspend-to-idle by default) the AOP mailbox
took 84 interrupts during a 21 s rtc sleep with the light sensor armed,
and 26 with it stopped: the light sensor was about 2.7 of the 4 wakeups
a second the AOP caused while the Mac slept. The lid angle driver
already stops its reports for the sleep.

Extend the PM notifier that re-arms the CT817 to every part: at
PM_SUSPEND_PREPARE write the interval to zero, and at PM_POST_SUSPEND
start the reports again. The CT817 keeps the whole arming sequence after
every sleep, because its firmware stops the reports for system sleep
even when the host did not. The other parts get their interval back, and
only if it was stopped. A failure to stop is logged and never refuses
the sleep.

Link: #2713
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide
RyanTheTide requested review from a team as code owners November 27, 2026 15:08

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The J413 interrupt counts and J700 wake reports cover the normal path, and unbind unregisters the notifier before removing the listener. The stop failure path can leave a non-CT817 sensor permanently silent. PM_SUSPEND_PREPARE sets stopped only on a successful reply, so if the interval-zero command reaches the AOP but its reply is lost or times out, PM_POST_SUSPEND skips restoration on VD6286/CT720. This also applies when suspend aborts after the prepare callback. Please restore the driver's active interval after every attempted stop, including uncertain completion, or establish that all errors guarantee the command was never applied. Cover a failed reply followed by post-suspend. Keep the existing CT817 re-arm sequence.

PM_SUSPEND_PREPARE marked the reports as stopped only when the AOP
answered the interval-zero command. A command that reached the AOP but
whose reply was lost or timed out may still have been applied, and then
PM_POST_SUSPEND did not restore a VD6286 or CT720, which stayed silent
until the driver was bound again.

Record the attempt before the command goes out and restore the active
interval after every attempted stop, whatever the reply. Writing the
active interval to a sensor that kept reporting changes nothing; the
CT817 keeps its full arming sequence after every sleep.

Link: #3404 (review)
Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Fixed in 116a2c10 ("iio: aop_als: restore the interval after every attempted stop"), pushed as a new commit on top.

  • Lost or failed stop reply: stop_attempted is now set before the interval-zero command goes out, and PM_POST_SUSPEND restores the active interval after every attempted stop, whatever the reply. The CT817 keeps its full re-arm sequence after every sleep, unchanged.
  • Suspend aborted after prepare: the PM core calls PM_POST_SUSPEND for every notifier that got PM_SUSPEND_PREPARE, so the same restore runs.
  • Coverage for a failed stop followed by post-suspend: J413 (VD6286), two 20 s s2idle sleeps with a test-only build of this head in which the stop command never goes out and returns ETIMEDOUT. The kernel logged reports may be left on for sleep: ETIMEDOUT both times. The sensor kept reporting through the sleep (82 and 84 AOP interrupts, as with the stock module). The restore then wrote the active interval to a sensor that never stopped, and reports stayed at 46/10 s after each wake, the same as before the sleep. So restoring after an unapplied stop is harmless.
  • The real head 116a2c10:
    • J413: s2idle 29 and 28 AOP interrupts per 21 s (stock: 83 and 82), and 46-47/10 s after each wake.
    • J700: two deep sleeps and one s2idle, 51/10 s after every wake.
    • aop_als.o compiles against main without warnings, and rustfmt --check is clean.

Logs: J413 traces/ci/20261128-neo-gaps/als-sleep-row-116a2c10-j413.txt, J700 .../als-sleep-row-116a2c10-j700.txt (lab store; numbers quoted above).

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@github-actions

Copy link
Copy Markdown

Merge readiness at 116a2c10: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at 116a2c10
Conflicts ok none
PR text ok Risk: two-way · Macs with an AOP light sensor. Every part now gets a PM notifier. The CT817 wake path behaves as before (#2528); VD6286/CT720 parts gain a stop before the sleep and a restart after it.

Areas: none matched in CODEOWNERS

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

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Setting stop_attempted before the write addresses uncertain completion while preserving unconditional CT817 re-arm. I ran the exact notifier body against a mocked AOP that applies interval zero and returns ETIMEDOUT. Two consecutive prepare/post pairs restored the active interval and cleared the marker each time. The reported J413 and J700 rows exercise the normal paths on this head. Code approved. Keep held for hosted CI and record the CT720 coverage limit from the existing test report.

@RyanTheTide
RyanTheTide merged commit ad25d59 into main Nov 27, 2026
2 of 6 checks passed
@RyanTheTide
RyanTheTide deleted the fix/aop-als-stop-for-sleep branch November 27, 2026 17:01
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged as ad25d59a at head 116a2c10. Basis: host-tests and pr-text passed; the non-author review approved this head after its change request was fixed; J413 and J700 rows at this head. CT720 is still not covered (no lab Mac has one; VD6286 takes the same path). To revert: git revert -m 1 ad25d59a.

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

Labels

ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant