platform/chrome: cros_ec_sensorhub: Timestamp wrap and drift filter fixes
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v6 Latest7 patches 1 replyIn review
- v56 patches 2 repliesSuperseded
- v11 patch 0 repliesSuperseded
Changes in v6 from the cover letter
- Patch 1: rework "Fix AP/EC TS wrap". v5 compensated for missed overflows on resume and only detected forward wraps, but the sample and interrupt timestamps were still unwrapped separately and could end up a period apart, which the forward-only rule never corrected. Derive the sample timestamp from the interrupt timestamp instead, which also covers samples that stayed in the FIFO during a long suspend.
- Patch 2: new. Reset the filter when the EC and AP elapsed times disagree.
- Patch 3: describe the off-by-one precisely and add a Fixes: tag.
- Patch 4: fix the unit mismatch in MAX_M pointed out by Tzung-Bi: the slope is in ns per us, so it is 1000 times the unitless drift. With the fix, a MAX_DRIFT_PPM of 5000 is really 5000 PPM (v5 clamped at 5 PPM), which covers the drift measured above.
- Patch 5: drop the unnecessary "m = 0" and use -dx instead of abs(dx) so that backward timestamps are not treated as valid intervals.
- Patch 7: reset batch_state[].last_len when dropping a sample, so the next batch does not compute its sample period across the gap.
- Rebase on chrome-platform for-next.
Patches in v6 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/7 | platform/chrome: cros_ec_sensorhub: Unwrap sample TS relative to FIFO TSdrivers/ include/ | +18 | 0 replies | |
| 2/7 | platform/chrome: cros_ec_sensorhub: Reset TS filter on EC/AP time mismatchdrivers/ | +8 | 0 replies | |
| 3/7 | platform/chrome: cros_ec_sensorhub: Fix TS filter history shift indexdrivers/ | +4 | 0 replies | |
| 4/7 | platform/chrome: cros_ec_sensorhub: Clamp clock drift slope to MAX_DRIFT_PPMdrivers/ | +14 | 0 replies | |
| 5/7 | platform/chrome: cros_ec_sensorhub: Reset TS filter on ODR or mode changesdrivers/ | +14 | 0 replies | |
| 6/7 | platform/chrome: cros_ec_sensorhub: Increase TS_HISTORY_BORED_US to 2sdrivers/ | +6 | 0 replies | |
| 7/7 | platform/chrome: cros_ec_sensorhub: Drop sensor samples with past timestampsdrivers/ | +29 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.
Cover letter [PATCH v6 0/7] platform/chrome: cros_ec_sensorhub: Timestamp wrap and drift filter fixes
This series fixes how the 32-bit EC timestamps are unwrapped, and several issues in the filter that converts them to the AP timebase. They caused sensor timestamps to be off by a whole overflow period (about 71.6 minutes) after long gaps such as suspend, Out Of Order (OOO) timestamps, and large gaps between sensor samples during batching.
Patches 1 and 2 handle the EC timestamp wrap across long gaps. Patch 3 fixes an off-by-one in the filter history shift. Patches 4 to 6 make the drift estimate robust to interrupt jitter and to switches between streaming and batching. Patch 7 drops samples whose timestamp goes backward instead of re-timing them.
Drift between the AP and the sensor hub, measured from the cros_ec_sensorhub_timestamp trace event over 10 to 20 minutes:
- Intel ISH (Panther Lake device): about 16 to 21 PPM
- standalone EC (MediaTek-based device): about 2900 PPM
Tested on both devices with the Android CTS sensor tests (CtsSensorTestCases, 440 tests, all pass), and across a natural wrap of the 32-bit EC timestamp with sensors running. On the MediaTek-based device, also tested two 40 minute gaps without FIFO interrupt, longer than half the wrap period, after streaming the accelerometer at 100 Hz:
with the FIFO interrupt disabled as is done on suspend, and with the sensors also stopped, as the EC does in suspend, so that samples stayed in the FIFO across the gap. In both cases the FIFO interrupt timestamp was unwrapped one period off, patch 2 reset the filter, and the samples read after the gap got timestamps matching their age, including the 40 minute old ones. Replaying the same traces through the current code gives timestamps off by up to 71.5 minutes.
Changes in v6:
- Patch 1: rework "Fix AP/EC TS wrap". v5 compensated for missed overflows on resume and only detected forward wraps, but the sample and interrupt timestamps were still unwrapped separately and could end up a period apart, which the forward-only rule never corrected. Derive the sample timestamp from the interrupt timestamp instead, which also covers samples that stayed in the FIFO during a long suspend.
- Patch 2: new. Reset the filter when the EC and AP elapsed times disagree.
- Patch 3: describe the off-by-one precisely and add a Fixes: tag.
- Patch 4: fix the unit mismatch in MAX_M pointed out by Tzung-Bi: the slope is in ns per us, so it is 1000 times the unitless drift. With the fix, a MAX_DRIFT_PPM of 5000 is really 5000 PPM (v5 clamped at 5 PPM), which covers the drift measured above.
- Patch 5: drop the unnecessary "m = 0" and use -dx instead of abs(dx) so that backward timestamps are not treated as valid intervals.
- Patch 7: reset batch_state[].last_len when dropping a sample, so the next batch does not compute its sample period across the gap.
- Rebase on chrome-platform for-next.
v5: https://lore.kernel.org/all/[email protected]/
v4: https://lore.kernel.org/all/[email protected]/
Satyam Gupta (2):
platform/chrome: cros_ec_sensorhub: Unwrap sample TS relative to FIFO
TS
platform/chrome: cros_ec_sensorhub: Reset TS filter on EC/AP time
mismatch
Scott Collyer (5):
platform/chrome: cros_ec_sensorhub: Fix TS filter history shift index platform/chrome: cros_ec_sensorhub: Clamp clock drift slope to
MAX_DRIFT_PPM
platform/chrome: cros_ec_sensorhub: Reset TS filter on ODR or mode
changes
platform/chrome: cros_ec_sensorhub: Increase TS_HISTORY_BORED_US to 2s platform/chrome: cros_ec_sensorhub: Drop sensor samples with past
timestamps
.../platform/chrome/cros_ec_sensorhub_ring.c | 114 ++++++++++++++---- .../linux/platform_data/cros_ec_sensorhub.h | 2 - 2 files changed, 93 insertions(+), 23 deletions(-)
Signature · 1 line
2.56.0.307.g5fe7bd680c-goog