Re: [PATCH v2 2/2] mul_u64_u64_div_u64: basic sanity test

From: Uwe Kleine-König
Date: Wed Jul 03 2024 - 17:36:45 EST


Hello Andrew,

On Wed, Jul 03, 2024 at 01:47:10PM -0400, Nicolas Pitre wrote:
> On Wed, 3 Jul 2024, Andrew Morton wrote:
>
> > On Tue, 2 Jul 2024 23:34:09 -0400 Nicolas Pitre <nico@xxxxxxxxxxx> wrote:
> >
> > > Verify that edge cases produce proper results, and some more.
> >
> > Awesome, thanks.
> >
> > Do you know of any situations in which the present implementation
> > causes issues?
>
> Uwe could probably elaborate further, but the example given in the
> first commit log is causing trouble for a driver he's working on.

Actually the example was a constructed one. I became aware of
mul_u64_u64_div_u64() being only an approximation while reviewing a pwm
driver by Biju Das:

https://lore.kernel.org/linux-pwm/TYCPR01MB1126992DD51F714AEDADF0A4F868DA@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

mul_u64_u64_div_u64 is used in various pwm drivers, but in practise the
periods used are small enough to not be problematic for the status quo
implementation since commit 8c86fb68ffcb ("mul_u64_u64_div_u64: increase
precision by conditionally swapping a and b"). At least I think Biju
(added to Cc:) only hit this problem during testing, and not in a real
world application.

I intend to do a performance test of Nico's code. I hope I get to that
tomorrow.

Best regards
Uwe

Attachment: signature.asc
Description: PGP signature