Repository navigation
fix(r528s3-mibox-x1): serialise the icm20948 enable/disable transitions - #24
Conversation
Follow-up to open-vela#23, which merged the board support and the SPI adapter fix. This addresses the concurrency concern that was left open there. work_cancel() does not wait for a worker that is already executing: it can return -EBUSY, and the sleep that follows would then land between a worker's data read and its temperature read. The disable paths now use work_cancel_sync(), which retries until the running worker has returned. The three activate callbacks also had no shared state lock, so an enable could wake the chip, be preempted before setting its *_enabled flag, and race with the last disable seeing every flag clear and putting the chip back to sleep. A mutex_t statelock now serialises those state transitions: each callback is a thin wrapper that takes the lock and calls the original logic, moved unchanged into *_activate_locked(). Verified on the board with the new image: repeated enable/disable cycles across all three sensors, no deadlock, the device still sleeps when idle and wakes on the next enable. Signed-off-by: tyx <1815108523@qq.com>
❌ CLA Signature Required@tyx-crazy Some contributors need to sign the CLA:
Please:
📋 View detailed check results: Action Run #44233395011 💡 Tip: All contributors must sign the CLA before the PR can be merged. |
|
/check-cla |
✅ CLA Verification Complete@tyx-crazy All contributors have signed the CLA!
📋 View detailed check results: Action Run #44234139497 Your pull request can now proceed with the review process! 🎉 |
yanxingyu17
left a comment
There was a problem hiding this comment.
The shared state mutex addresses the cross-topic wake/sleep race, but synchronously cancelling the worker from the sensor activate callback introduces a lock inversion with the sensor upper-half.
|
R528_MIBOX-X1_xTS测试报告.docx Note: the report covers the overall board-port validation — kernel, driver BSP, |
56517e1 to
ffe4d63
Compare
yanxingyu17
left a comment
There was a problem hiding this comment.
The lock inversion from the previous revision is addressed. Please also update the PR description: it still describes the removed work_cancel_sync() design. The Testing section should include the actual passing self-test log (or a linked log artifact), including the exact commands, 80-cycle count, 120/700/1500 ms close delays, and final zero-hang/zero-failure summary rather than only a prose result.
sensor_close() holds the sensor upper-half lock while it calls activate(..., false). A worker that is already running may be inside push_event(), waiting for that same lock, so waiting for the worker from the activate callback can deadlock. Keep the cancellation non-blocking: when work_cancel() reports that the worker is still running, let that worker perform the final idle and sleep transition itself, after its push path and under the shared state lock. When the work is not running, do the transition in the activate path. Do the same transition when a worker starts, takes the lock and finds the sensor already disabled, so a close that raced with the scheduler does not leave the chip awake. Apply the same pattern to the accel, gyro and mag workers.
ffe4d63 to
84cba5b
Compare
yanxingyu17
left a comment
There was a problem hiding this comment.
The enable/disable state transitions are serialized without blocking on an in-flight worker from the sensor upper-half callback. The worker-side idle transition covers both the running and early-exit paths.
CI, checkpatch, CLA, and the 80-cycle board test pass.
Follow-up to #23, which merged the board support and the SPI adapter fix.
This addresses the concurrency concern left open there.
Summary
work_cancel() does not wait for a worker that is already executing: it can
return -EBUSY. Instead of waiting, the worker performs the final idle and
sleep transition itself after its push path, under the shared state lock.
When the work is not running, the transition is done in the activate path,
and a worker that starts and finds the sensor already disabled does the
same before returning.
The three activate callbacks also had no shared state lock, so an enable
could wake the chip, be preempted before setting its *_enabled flag, and
race with the last disable seeing every flag clear and putting the chip
back to sleep. A mutex_t statelock now serialises those state transitions:
each callback is a thin wrapper that takes the lock and calls the original
logic, moved unchanged into *_activate_locked().
Impact
One file: chips/r528/drivers/rtos-hal/hal/source/sensor/icm20948/icm20948.c.
Only the ICM20948 driver changes; the lock is per device instance, so no
other sensor or board is affected.
Testing
Built from this branch and tested on R528 MIBOX-X1 (NAND image,
20,395,008 bytes, MD5 E644A694DBCBA86C59246B60A5C1344B).
icm20948_uorb was started from nsh and stopped with Ctrl-C, so every cycle
runs activate(true) and activate(false) for accel, gyro and mag. 80 cycles
in total, with scripted close delays of 120 ms / 700 ms / 1500 ms
(30 / 30 / 20):
No hang, no assert or panic. Every run printed "Sensor icm20948 read
examples exit." and returned to the nsh prompt. Serial excerpts and the
firmware MD5 are in the test notes attached in the review thread.