Repository navigation
sensors: leave a swept bus that only times out, and probe no bus twice - #295
Conversation
PR Summary by QodoStop repeated sensor probes on timed-out or duplicate I²C buses
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
|
Timed on NT98566 + IMX415 (nightly master+8a60044): --short-sensor 27.1 s → 4.15 s, real detection 27.3 s → 4.4 s, i2c2/i2c3 timeouts 13/13 → 2/2. Details: OpenIPC/firmware#1889 (comment) |
|
On the two Qodo findings, both addressed in 6b1e92f:
Thanks @DrSamjames for the timing. The results are in the description, and the merge hold is lifted. |
Symptom
On an XM IVG-N8S (NT98566, IMX415), the
ipcinfo --short-sensorthat runs at boot takes about 27 s when the sensor does not answer, withi2c transfer timed outfromf0350000.i2c2andf03a0000.i2c3(reported in OpenIPC/firmware#1889).Cause
When nothing answers on the bus the HAL nominated, the probe sweeps the others, about 13 reads each on Novatek. The kernel driver fails a transfer that never completes with
ETIMEDOUTafter a fixed 1 s, while a NACK isEREMOTEIOat once. Two such buses are about 26 s, which matches the 27 s. The report also had a 41 s run, timed from syslog. The reporter puts that down tontpdstepping the clock during detection: a later boot took 42 s by syslog and 27.4 s by uptime.Change
ETIMEDOUT, so such a bus costs about 2 s instead of 13. A NACK or a good read resets the count, so an empty bus is still probed in full. The nominated bus is untouched, and so are the buses inhal_sensor_buses./dev/i2c-0, and every number with/dev/i2c-1on some dies. The adapter is compared by the device number of the opened i2c-dev node (major 89); anything else is never treated as the same bus.The probes call
i2c_read_registerby that name, so the sweep borrows that global and gives it back, asget_sensor_id_spi()does with its own. Writes are not affected, so a register page is still put back. Other HALs benefit where their reader returns -1 witherrnoatETIMEDOUT; elsewhere the count never rises.getsensorid()takes no lock, so a second probing thread that finds the reader already borrowed does not save it as the HAL's: it would call itself until the stack overflowed. Concurrent sweeps still share the timeout count, so one thread's timeouts can end another's sweep of a bus. Sensor detection already relied on unlocked global state, and this PR does not add a lock.A bus reporting busy (
EBUSY) is not covered.Tests
sensors_testgains a mock bus set: dead, empty and intermittent buses, a number that opens another's bus, descriptors whose adapter is unknown, and a sensor behind a dead bus. Undoing any of the pieces fails it (one mutation, not giving the reader back, by overflowing the stack). All host tests pass and the sensor fingerprint is unchanged.ipctoolandipcinfocross-build for arm32 with the NT98566 firmware toolchain.Tested on a camera
DrSamjames timed this head (
6b1e92f) against its base on an XM IVG-N8S (NT98566, IMX415), in full here. I did not run it myself.ipcinfo --short-sensor, sensor not answering, two runs eachThe warm boot with this PR detected
imx415and streamed at 25 fps.Not tested: any other camera. The lab NT98566 cannot run this probe, because it wedges that board's bus.
clang-formatwas not run.