Re: [PATCH] iio: imu: inv_icm42600: fix timestamping by limiting FIFO reading
From: Jean-Baptiste Maneyrol
Date: Wed Jun 24 2026 - 04:23:05 EST
>From: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
>Sent: Tuesday, June 23, 2026 22:23
>To: Jean-Baptiste Maneyrol
>Cc: Jonathan Cameron; David Lechner; Nuno Sá; Andy Shevchenko; Jean-Baptiste Maneyrol; linux-iio@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx; stable@xxxxxxxxxxxxxxx
>Subject: Re: [PATCH] iio: imu: inv_icm42600: fix timestamping by limiting FIFO reading
>
>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
>ZjQcmQRYFpfptBannerStart
>This Message Is From an External Sender
>This message came from outside your organization.
>
>ZjQcmQRYFpfptBannerEnd
>
>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()?
>
Hello Andy,
you're right, I completely messed that up.
It is in fact even more complex than just using gcd or lcm.
I will rework that, thanks for your review.
Thanks,
JB
>...
>
>> + /* 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
>