Re: [PATCH] m68k: delay: Fix rounding of short udelay() and ndelay()

From: Graeme Harker

Date: Wed Nov 18 2026 - 16:00:15 EST


Hi Finn,

Thanks for testing it on real hardware, and with a better method than
mine.

> Which clocksource driver are you using for jiffies?

The jiffies clocksource itself; the board has no sub-tick clocksource
yet. The tick is a periodic clock_event_device on the DUART's
counter/timer (GENERIC_CLOCKEVENTS, not LEGACY_TIMER_TICK), and my
figures were 1 s of each call timed by jiffies with interrupts on, so
they include the tick's own cost. Yours are the better numbers.

> ndelay(400) 536E-09 -> 239E-09 seconds

I think the patched ndelay() count has wrapped your 16-bit timer. The
patched ndelay(400) asks __delay() for at least 466 ns of calibrated
loops whatever loops_per_jiffy is (8000 * loops_per_jiffy * 25 / 2^32
loops, plus the one __delay() adds), and it now does a mulu.l on every
call, which the old code did not (its arithmetic is plain C, so GCC can
hoist it out of your unrolled loop). If a call takes about 1.08 us,
100000 calls take 107.6 ms, more than the 83.7 ms that T2 can count at
783360 Hz, and what is left after one wrap is 23.9 ms, or 239 ns a
call.

Could you try ndelay(400) with 40000 invocations instead of 100000? If
I'm right it should come out at about 1.08 us. That would mean it is
longer than before, not shorter. As the commit message says, ndelay()
now pays for the 64-bit multiply, so very short ndelay()s cost more.
If that cost matters on the 040, I could keep the old ndelay() and
only fix udelay().

Your udelay(1000) at 978 us is still 2 % short with interrupts off. I
believe that is calibrate_delay() running with the tick enabled, so the
tick's time is counted as loop time. That is separate from this patch,
and I have left it alone.

Graeme