Re: [PATCH v2 2/3] iio: inv_sensors: better timestamp alignment when using watermark
From: Andy Shevchenko
Date: Mon Jul 20 2026 - 08:03:08 EST
On Mon, Jul 20, 2026 at 12:38:33PM +0200, Jean-Baptiste Maneyrol via B4 Relay wrote:
> Current interrupt timestamp alignment only changes the final timestamp.
> When the watermark is in use, we have a batch of samples for each
> interrupt. The current code doesn't manage to align the timestamp
> because the jitter is too high.
>
> Instead modify the estimated inter interrupt period and use that to
> adjust the timestamp alignment over the batch in a linear fashion.
...
> void inv_sensors_timestamp_interrupt(struct inv_sensors_timestamp *ts,
> if (sample_nb == 0)
> return;
>
> + /* no previous data, compute theoretical value from interrupt */
> + if (ts->timestamp == 0) {
> + /* elapsed time: sensor period * sensor samples number */
> + interval = (s64)ts->period * (s64)sample_nb;
The both variables are unsigned. Why do we cast them to the signed type?
> + ts->timestamp = timestamp - interval;
> + }
...
> - /* no previous data, compute theoretical value from interrupt */
> - if (ts->timestamp == 0) {
> - /* elapsed time: sensor period * sensor samples number */
> - interval = (s64)ts->period * (s64)sample_nb;
Yeah, I see this is the original code, but consider revisiting.
> - ts->timestamp = it->up - interval;
> - return;
> - }
--
With Best Regards,
Andy Shevchenko