Re: [PATCH] iio: imu: inv_icm42600: fix timestamping by limiting FIFO reading
From: Andy Shevchenko
Date: Tue Jun 23 2026 - 16:23:41 EST
On Tue, Jun 23, 2026 at 06:44:22PM +0200, Jean-Baptiste Maneyrol via B4 Relay wrote:
> Timestamps are made by measuring the chip clock using the watermark
> interrupts. If we read more than watermark samples as done today, we
> are reducing the period between interrupts and distort the period
> measurement. Fix that by reading only watermark samples in the
> interrupt case.
>
> Better watermark computation using gcd and store watermark value for
> FIFO reading.
...
> + /* use the shortest period and the gcd of the latencies */
> + period = min(period_gyro, period_accel);
> + latency = gcd(latency_gyro, latency_accel);
If gyro is 5 and accel is 7 the gcd() will give 1. I don't think it's what you
want.
Did you think of lcm()?
...
> + /* update effective watemarks */
> + st->fifo.watermark.value = max(latency / period, 1);
> + if (wm_gyro)
> + st->fifo.watermark.eff_gyro = max(latency / period_gyro, 1);
> + if (wm_accel)
> + st->fifo.watermark.eff_accel = max(latency / period_accel, 1);
In my example this ends up with 1 in both cases.
--
With Best Regards,
Andy Shevchenko