Repository navigation
iio: aop_motion: fix the M1/M2 accelerometer and gyroscope, and idle-window aop_devmotion (stacked on #2910) - #2927
RyanTheTide wants to merge 5 commits into
Conversation
Commit 9538a1d ("iio: aop_motion: run the reports only while someone reads them") stopped the AOP accelerometer and gyroscope reports when nobody reads them, saving ~100 AP wakeups/s on an idle desktop. However, its direct-read path calls Control::start() and Control::stop() around every individual sysfs axis read, and start() unconditionally resends all three calibration packets (properties 75, 76 and 77) before setting the report interval. On T6041 (M4 Max, J616C), Chromium polling the raw X/Y/Z sysfs channels at 25-60 Hz drives ~73 start/stop cycles/s (~365 EPIC RPCs/s). On every start, properties 75 and 76 return kIOReturnUnsupported (0xe00002c7) while property 77 is re-accepted, logging "2 of 3 calibration packets kept from an earlier start" over 1,200 times in 17 seconds until the AOP firmware crashes on endpoint 0x24, wedging ALS and audio for the rest of the boot. Keep the 0 Hz idle behaviour while eliminating both the calibration rewrite storm and per-axis start/stop thrashing: - Track calibration state in Stream so the three calibration packets are sent once at probe, and subsequent starts for buffers, direct reads and s2idle resume only write PROP_INTERVAL. On s2idle (!pm_suspend_via_firmware()), the AOP core does nothing so calibration stays valid. Across firmware suspend (pm_suspend_via_firmware()), hibernation and restore (PM_POST_HIBERNATION / PM_POST_RESTORE), clear calibrated and active conservatively so calibration is sent once on the next start (on firmwares that kept it, packets 75/76 return STATUS_UNSUPPORTED benignly once). Downgrade the kept-packets log message from dev_info! to dev_dbg!. - Hold direct-read reports active for a 2 s idle window via a DelayedWork item on system_dfl_wq. Back-to-back X/Y/Z reads and polling callers share the running 50 Hz stream and extend the deadline with no extra EPIC calls, while quiet periods return the AOP to interval 0. - Back off direct reads for DIRECT_IDLE_MS after a failed start so a polling client cannot hammer a failing service or spam refused() logs; buffer enable, sleep transitions and shutdown clear the backoff. - Only clear active after stop_reports() succeeds, and park on PM_RESTORE_PREPARE alongside suspend/hibernation prepare. Cancel and join the idle work synchronously with the stream mutex dropped on sleep prepare (cancel_delayed_work_sync) and permanently disable it on unbind or a failed iio.register() in probe (disable_delayed_work_sync), reclaiming any pending Arc reference cleanly. - Extend the host selftest in tools/testing/selftests/drivers/apple/aop-motion.py to cover the production Stream state machine (including failed-start backoff and failed-stop / reset_cal handling) and update Documentation/iio/aop-sensors.rst. Fixes: 9538a1d ("iio: aop_motion: run the reports only while someone reads them") Suggested-by: Ryan Murray <[email protected]> Signed-off-by: AxxzyWasTaken <[email protected]>
On the M1 Pro (T6000) the accelerometer and gyroscope read 0 0 0.
The AOP firmware there takes every calibration packet it is sent with
status 0 and applies it on top of the calibration it already holds,
instead of replacing it or answering that it holds one, as newer
firmware does. A second set of packets rotates the mount matrix again
and multiplies in the per-count scale (about 0.244 for the
accelerometer) once more. With calibration sent on every start, as
before the parent commit, the matrix shrinks towards zero within a few
reads. Calibrating once per AOP boot fixes direct reads, but a rebind of
the driver sends the packets again: on the M1 Pro, Z at rest went from
-65352 to 15960 and then -3897 counts over two rebinds.
The service's calibration state (property 61) keeps the value a host
writes until the AOP restarts; on the M1 Pro it reads 0 before that.
After sending the packets, set it to 2 ("calibration loaded"), the value
aop_temp writes after its own packets, and read it before calibrating:
when it already reads 2, skip the packets. Any other value, or a failed
read, sends them as before. Firmware that answers the write with
unsupported is left as before. The state check also makes the
conservative recalibration after firmware suspend safe on such firmware
when the AOP kept its state.
The host selftest covers the state decision.
Signed-off-by: Ryan Murray <[email protected]>
With no buffer enabled, every direct read of in_rot_quaternion_raw opens the fast-path client, writes the report interval, waits up to 500 ms for the first sample, writes interval 0 and closes the client again. That is 4 EPIC calls per read, two of them a ClientOpen/ClientClose that hand the shared DMA ring to the firmware and take it back, and the attribute is world-readable, so any polling reader drives them as fast as the firmware answers. An open or close that times out also keeps the ring mapped for the rest of the boot. Follow the design of "iio: aop_motion: calibrate once per boot and idle-stop direct reads" for the direct-read path: - The first direct read opens the client and starts the reports. The client then stays open for a 2 s idle window that every further direct read extends, so polling readers share one running client and get the latest polled sample with no EPIC call. A DelayedWork item on system_dfl_wq stops the reports and closes the client once reads have been quiet for the window. - The stream lock is held across the wait for the first sample and the idle work closes the client under the same lock, so the client is never closed while a read waits on it. - Enabling the buffer takes over a client that direct reads opened, without reopening it, and drops the direct hold. Disabling the buffer closes the client at once, as before. - Suspend parks the stream, then cancels and joins the idle work with the stream mutex dropped (cancel_delayed_work_sync). Unbind disables it for good (disable_delayed_work_sync) before the polling work is disabled. Both reclaim the Arc reference of a cancelled pending work. - The consumer state moves from separate atomics into a Stream state machine under the stream mutex, which the new host selftest tools/testing/selftests/drivers/apple/aop-devmotion.py runs. Update Documentation/iio/aop-sensors.rst. The calibration-state write is already sent once at probe and does not change. Fixes: 091f105 ("iio: apple: devmotion: pace the fast path on the host, open it on demand") Signed-off-by: Ryan Murray <[email protected]>
When opening the report client for a direct read fails, read_now() forgets the request and returns the error, so the next sysfs read tries again at once. A client polling the quaternion at 25-60 Hz then repeats the failing ClientOpen, or the open, the refused report interval and the close that undoes it, at its own rate, with a line in the log for each. That is the traffic the idle window removed from the working case, in the case where the firmware is already unhappy. Remember a failed open for DIRECT_IDLE_MS, as aop_motion does. Direct reads in that time return its error without calling the service, and the first read after it tries again. This bounds the failing case as the working one is bounded: one attempt per idle window, and with it one set of error messages per window, so they need no rate limit of their own. The backoff is for polling readers only. Enabling a buffer is a new request and tries at once, and system sleep drops the backoff in both directions, so the first read after resume is not answered with an error from before the sleep. The stream selftest covers a poller on a failing service, the retry after the window and the two ways out of the backoff. Signed-off-by: Ryan Murray <[email protected]>
|
Review at dd8d3fe. Reviewed 64413d1..dd8d3fe against #2910's head 65ddaa0. The fix is keyed on the service's own calibration state (property 61), not on a chip, and the calibration still comes from the ADT packets, so that part looks right. Findings:
|
There was a problem hiding this comment.
Formal §1–§6 pre-PR checklist review at dd8d3fe893f5ab366fc983c8606a8fdbbec849df (auditing 64413d18..dd8d3fe8 stacked on #2910 65ddaa0a).
Checklist Summary
- §1 No model gating: Pass — keys on the service's own calibration state (property 61), not on chip/SoC/firmware version, and calibration data continues to come from ADT packets.
- §2 Production-ready: Pass (non-blocking:
DIRECT_IDLE_MS+Streamstate machine/backoff are duplicated across both drivers; runtime-PM autosuspend or a shared helper inaop_sensorswould be a good follow-up). - §3 Safety: Blockers in property-61 error handling and
aop_devmotionPM restore (see below). Note:stop_idle_sync()+Arc::from_rawrefcount handling was audited againstrust/kernel/workqueue.rsenqueue_delayed()and is sound. - §4 Clean-room & attribution: Pass — #2910 commit
65ddaa0ais carried unchanged (AxxzyWasTaken), commits 2–4 carry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:, zero AI trailers in commits. - §5 Evidence: Partial — M2 (J413) and J616s are covered at final code, but M1 Pro row used an earlier
!= 0check (needs re-run at final== 2code), and J713 / M3 (J615) / J616C rows are still owed since GET/SET of property 61 runs on every firmware generation. - §6 Naming: Pass.
- CI (at review time):
host-testsFAILED.
Blocking Findings
- CI
host-testsfailure:tools/asahi/run-host-tests.pyexits with code 2:Registernot registered in run-host-tests.py: tools/testing/selftests/drivers/apple/aop-devmotion.pyaop-devmotion.pyintools/asahi/run-host-tests.py. - Prop-61 write failure leaves
s.calibrated = false(drivers/iio/common/aop_sensors/aop_motion.rs:394-397): Once all three calibration packets have been sent and accepted,self.write(PROP_CALIBRATION_STATE, ...)?returnsErron a transport error or any status other than0 | STATUS_UNSUPPORTED. That abortscalibrate()befores.calibrated = true(lines 413/425), causing the nextstartto resend all three calibration packets (re-triggering the compounding scale/rotation corruption on v240 firmware) and turning an unexpected prop-61 status on newer firmware into a probe failure. Once the three calibration packets succeed, log a warning on prop-61 write failure/refusal and still returnOk(())sos.calibratedis set. - Prop-61 read transport error treated as uncalibrated (
drivers/iio/common/aop_sensors/aop_motion.rs:357):holds_calibration()mapsErr(_)(timeout /-EIO/-ENOMEM) tofalse, causingcalibrate()to resend all three packets blindly (again risking compounding calibration on v240, e.g. on conservative post-firmware-suspend recalibration). ReturnResult<bool>fromholds_calibration(), propagate transport errors sostartfails and backs off, and only decide to send packets on anOk((status, value))response. - Missing hibernation restore handling in
aop_devmotion(drivers/iio/common/aop_sensors/aop_devmotion.rs:1046-1049): Because the fast-path client (and its DMA ring) can now stay open for up toDIRECT_IDLE_MS(2 s) after a direct read,pm_event()must also park onPM_RESTORE_PREPAREand unpark onPM_POST_RESTORE, matchingaop_motion.rs:967-978. - Stacking & §5 rows: Rebase onto
integration/auroraonce #2910 lands, and add the M1 Pro (at final== 2code), J713, M3 (J615), and J616C rows.
Verdict
REQUEST_CHANGES — fix the run-host-tests.py registration, the three concrete driver bugs above, rebase off #2910, and complete the §5 hardware rows.
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at dd8d3fe893f5. The new read of calibration state still conflates a failed transport read with a definite unset state. The reported fix depends on avoiding a second calibration on firmware that already holds it. Please preserve that distinction, cover transient property-read failure, and add the missing restore handling for the now longer-lived devmotion stream. Re-run the J413 orientation and idle-rate measurements with both fixes.
Propagate failures reading the service calibration state. Once the calibration packets have completed, keep the current bind calibrated even when the firmware state marker update fails. Park device-motion clients on restore prepare and restart them after restore. Register the device-motion host test alongside the motion and light sensor suites. Signed-off-by: Ryan Murray <[email protected]>
|
The follow-up at The AOP host runner passed all three suites. Motion passed 11/11 tests and device motion passed 5/5. Both driver objects compiled for arm64 against the fleet configuration. The head merges cleanly into integration with the first calibration change present. Still to run on this head, using the default command line: boot, rebind, buffer reads and short suspend on J413, M1 Pro and the available newer AOP firmware families. The earlier hardware rows above apply to the preceding revision. |
RyanTheTide
left a comment
There was a problem hiding this comment.
Independent source review at 75c3683e81a9. The updated head now propagates calibration-state transport errors, keeps this bind calibrated after successful packets even if marker publication fails, and pairs the devmotion restore callbacks. Both fixtures passed here, 11/11 motion and 5/5 devmotion. Before merge, qualify J413 orientation and the idle rate after suspend on the assembled current stack. Include repeated probe or rebind after a marker write refusal so the locally retained state does not mask a repeated calibration across binds.
There was a problem hiding this comment.
Formal §1–§6 pre-PR re-review at 75c3683e81a9773c2e5048a58180629b7df32ba8 (CI: host-tests green; mergeable=true, clean against integration/aurora).
Prior Blocker Verification (from dd8d3fe893f5)
- Resolved:
aop-devmotion.pyregistered intools/asahi/run-host-tests.py(host-testsnow green). - Resolved:
Control::holds_calibration()returnsResult<bool>and propagates transport/allocation errors before sending any calibration packets (drivers/iio/common/aop_sensors/aop_motion.rs:343-351). - Resolved:
Control::calibrate()warns and returnsOk(())if the post-calibration property-61 marker write fails or is refused, preservings.calibrated = truefor the current bind (aop_motion.rs:386-395). - Resolved:
aop_devmotionpm_event()now parks onPM_RESTORE_PREPAREand resumes onPM_POST_RESTORE(drivers/iio/common/aop_sensors/aop_devmotion.rs:1046-1050). - Note on
#2910:#2910(65ddaa0adccc) is already merged intointegration/aurora(5129ba79bc09). Because commit 1 in this branch is the exact same SHA, the diff againstintegration/auroracleanly contains only the four follow-up commits (64413d18..75c3683e); dropping(stacked on #2910)from the PR title is a clean non-blocking tidy-up.
Pre-PR Checklist (§1–§6)
- §1 No model gating: Pass — keyed on the service's own property-61 calibration state, with calibration data from ADT packets.
- §2 Production-ready: Pass — default command line, no hacks.
- §3 Safety: Pass on the calibration-state and idle-window paths; see the non-blocking
aop_devmotionprobe()unwind hardening note below. - §4 Clean-room & attribution: Pass —
#2910commit65ddaa0adccccarried unchanged (AxxzyWasTaken); commits64413d18,7b9d4f9c,dd8d3fe8, and75c3683ecarry human author/committer (Ryan Murray <[email protected]>) and humanSigned-off-by:only, zero AI trailers in commits;Assisted-by:disclosed in PR body. - §5 Evidence: Incomplete (blocking) — zero hardware runs at current head
75c3683e81a9. - §6 Naming: Pass.
Blocking Findings
- Missing §5 hardware evidence at current head
75c3683e81a9: All posted hardware rows are from the earlier revision (and the M1 Pro row predates the final== 2check). Please run default-command-line boot, buffered reads, 3x driver rebind, and short s2idle at75c3683e81a9on M1 Pro (J316s), M2 (J413), and available newer AOP firmware families (J616s and ideally J713 / M3 J615), including the §5 regression counts (0 SELinux denials, 0 failed units, 0 new kernel errors). - Contradictory duplicate sleep sentence in
Documentation/iio/aop-sensors.rst:107-111: Commit7b9d4f9c7ad2added "Around system sleep the client is closed, and it is reopened on wake only if a buffer is still enabled." but left the old sentence immediately below it ("Around system sleep an open client is closed and reopened after resume."). Please remove the stale duplicate sentence.
Non-blocking Note
aop_devmotionprobe()error-unwind order (drivers/iio/common/aop_sensors/aop_devmotion.rs:977-978):iio.register()?runs beforePmHook::new(state.clone())?. Now that a direct read can leaveidle_workandpoll_workqueued, ifPmHook::new()fails afteriio.register()succeeds,MotionIio::drop()unregisters and freesiio_devwithout callingstate.shutdown()orstate.disable_poll(). RegisteringPmHookbeforeiio.register()and unwinding withpm.unregister(); state.shutdown(); state.disable_poll();(matchingaop_motion.rs:1116-1126) closes that race cleanly.
Verdict
REQUEST_CHANGES — all four code/CI blockers from the prior review are fixed, but §5 hardware rows at 75c3683e81a9 and the stale sentence in Documentation/iio/aop-sensors.rst remain before merge.
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge at 75c3683e81a9: the code is ready; it needs only a row at this head.
Blockers: none in the code. Missing row: the rows are from an earlier revision. Needed at this head on an M1 Pro (J316s) or M2 (J413): a boot, buffered reads, three driver rebinds and a short s2idle.
Checked: no Apple material, no gates. The earlier points are fixed (the test is registered, holds_calibration). Host tests green. Nit: Documentation/iio/aop-sensors.rst:107-111 keeps the old sleep sentence beside the new one.
Superseded by the review at 75c3683
The merge-base changed after approval.
There was a problem hiding this comment.
Verdict: Changes requested at 75c3683e81a9.
The calibration packets can already be applied when the state-marker write is refused, unsupported or times out. Keeping the current bind calibrated helps direct reads, but a subsequent rebind with the same AOP boot sees an unset marker and can compound calibration again. Please show how the driver fails safely in the uncertain state, including an interrupted packet sequence and a marker-write failure followed by rebind. Also remove AI attribution from the PR body and attach current-head rebind and suspend evidence on the affected firmware families.
|
I exercised the exact
This was a host failure-injection test, so no live calibration was changed. The next revision needs to retain the completed or uncertain transaction state across a child rebind. The AOP core already retains ambiguous source-ring binding state across child teardown and is a candidate place to keep the calibration state as well. A new packet sequence should require evidence of a fresh firmware boot. I also checked the current-main merge at |
#2910 is merged. This PR adds the calibration-state and device-motion follow-up.
Problem
aop_devmotionhas the same start/stop-per-read pattern that iio: aop_motion: calibrate once per boot and idle-stop direct reads #2910 removes fromaop_motion: every direct quaternion read starts and stops the service.Change
aop_tempalready writes after its packets. Before calibrating, read the state and skip the packets when it reads 2. A successful read reporting any other state, or a firmware refusal, falls back to the packet statuses. A transport or allocation error aborts before any packet is sent. After the packets complete, a failed marker update preserves the current bind's calibration. This also makes iio: aop_motion: calibrate once per boot and idle-stop direct reads #2910's conservative recalibration after firmware suspend safe when the AOP kept its state. Host selftest case and docs added.DelayedWorkidle-window design as iio: aop_motion: calibrate once per boot and idle-stop direct reads #2910: a direct read keeps the fast-path client open for 2 s, and back-to-back reads reuse it.aop_motion. The PM notifier parks the fast-path client before restore and resumes it afterward.Testing
At
75c3683e81a9773c2e5048a58180629b7df32ba8, all three AOP host suites pass and both driver objects compile for arm64 with the fleet configuration. The hardware rows below used the earlier revision.devmotion6reads a unit quaternion; no AOP errors.aop-motion.pyselftest 11/11,aop-devmotion.py5/5,rustfmt --checkclean,checkpatch --strictclean.Still to run
How the root cause was found (M1 Pro)
Debug-only builds (not part of this PR) dumped raw reports and read the service properties back:
aop_motionblacklisted for one boot), no calibration sentEvidence: our own measurements (traces/kernel/20261123-aop-motion3-t6000 in the lab store); no Apple binaries involved.