Re: [PATCH] refperf: work around 64-bit division

From: Arnd Bergmann
Date: Sat May 30 2020 - 04:13:03 EST


On Sat, May 30, 2020 at 5:52 AM Nathan Chancellor
<natechancellor@xxxxxxxxx> wrote:
> On Fri, May 29, 2020 at 10:15:51PM +0200, Arnd Bergmann wrote:
> > strcat(buf, "Threads\tTime(ns)\n");
> >
> > for (exp = 0; exp < nruns; exp++) {
> > + u64 avg;
> > + u32 rem;
> > +
> > if (errexit)
> > break;
> > - sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, result_avg[exp] / 1000, (int)(result_avg[exp] % 1000));
> > +
> > + avg = div_s64_rem(result_avg[exp], 1000, &rem);
>
> Shouldn't this be div_u64_rem? result_avg is u64.

Yes, you are right. Actually that would be an important optimization
since div_u64_rem() optimizes for constant divisors while div_s64_rem
uses the slow path.

> > + sprintf(buf1, "%d\t%llu.%03d\n", exp + 1, avg, rem);
>
> Would %03u be the better specifier since rem is u32?

Yes, though this makes no difference in practice.

Paul, should I send a fixup for these two, or do you prefer to just
edit it in place?

Arnd