mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v6 0/7] platform/chrome: cros_ec_sensorhub: Timestamp wrap and drift filter fixes
@ 2026-10-29  9:28 Satyam Gupta
  2026-10-29  9:28 ` [PATCH v6 1/7] platform/chrome: cros_ec_sensorhub: Unwrap sample TS relative to FIFO TS Satyam Gupta
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Satyam Gupta @ 2026-10-29  9:28 UTC (permalink / raw)
  To: Tzung-Bi Shih
  Cc: Benson Leung, Guenter Roeck, Gwendal Grignou, Scott Collyer,
	chrome-platform, linux-kernel, Satyam Gupta

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/20261014074306.2500909-1-sgsatyam@google.com/
v4: https://lore.kernel.org/all/20261013105753.1370713-1-sgsatyam@google.com/

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(-)

-- 
2.56.0.307.g5fe7bd680c-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-10-29  9:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-29  9:28 [PATCH v6 0/7] platform/chrome: cros_ec_sensorhub: Timestamp wrap and drift filter fixes Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 1/7] platform/chrome: cros_ec_sensorhub: Unwrap sample TS relative to FIFO TS Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 2/7] platform/chrome: cros_ec_sensorhub: Reset TS filter on EC/AP time mismatch Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 3/7] platform/chrome: cros_ec_sensorhub: Fix TS filter history shift index Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 4/7] platform/chrome: cros_ec_sensorhub: Clamp clock drift slope to MAX_DRIFT_PPM Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 5/7] platform/chrome: cros_ec_sensorhub: Reset TS filter on ODR or mode changes Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 6/7] platform/chrome: cros_ec_sensorhub: Increase TS_HISTORY_BORED_US to 2s Satyam Gupta
2026-10-29  9:28 ` [PATCH v6 7/7] platform/chrome: cros_ec_sensorhub: Drop sensor samples with past timestamps Satyam Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®