From: Graeme Harker <graeme.harker@gmail.com>
To: geert@linux-m68k.org
Cc: Finn Thain <fthain@linux-m68k.org>,
linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] m68k: delay: Fix rounding of short udelay() and ndelay()
Date: Sat, 5 Dec 2026 08:28:07 +0000 [thread overview]
Message-ID: <20261205082807.1348564-1-graeme.harker@gmail.com> (raw)
In-Reply-To: <31cf41a9-a2c2-6ae6-b12e-50e54875d0d1@linux-m68k.org>
Hi Geert,
Finn has measured the patch on his LC 630 (thanks again, Finn) and has
left the remaining choice to you, so here is what I would like to send
as v2, if you are happy with it.
His numbers bear out the udelay() half: every udelay() is longer than
before and close to what was asked, the remaining 2% shortfall with
interrupts off being calibrate_delay(), which this patch does not touch.
For ndelay(), the patch is faster than the old code from 100 ns to 4 us
(1.17 against 2.49 us at 100 ns, 5.63 against 6.07 us at 4 us), and
never short, but it has one real flaw: the constant 5 that I copied from
x86 is 16.4% more than 2^32 / 10^9, so long ndelay()s run about 16% long
(46.9 against 39.2 us at 40 us). With his loops_per_jiffy of 107776 the
patch's formula predicts 46.6 us there.
For v2 I would keep udelay() as it is and change only the ndelay()
constant, using shifts so that it adds no multiply:
static inline void ndelay(unsigned long nsec)
{
/* 4 + 1/4 + 1/32 + 1/64 = 4.296875, close to 2^32 / 10^9 */
__xdelay(nsec * 4 + (nsec >> 2) + (nsec >> 5) + (nsec >> 6));
}
That is 0.044% over 2^32 / 10^9 rather than 16.4%. The shifts truncate,
so a very short ndelay() can ask for a fraction of a loop less than the
exact figure, under a nanosecond; __delay()'s extra loop covers that.
I have checked the loop counts on the host against the exact figure for
loops_per_jiffy of 17792 (my 68030), 107776 (Finn's LC040) and
170000000. As before, ndelay() is good up to about 250 ms, where
xloops * 4 overflows.
Short ndelay()s still pay for the 64-bit multiply in __xdelay(): on the
LC040 ndelay(20) went from 0.40 to 0.61 us. If you would rather avoid
that, the other choice is to drop the ndelay() change altogether and
send v2 as a udelay() fix only.
Would you like v2 with the shift form, or udelay() only? I'll wait for
your answer before sending either.
Graeme
prev parent reply other threads:[~2026-12-05 8:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 14:38 Graeme Harker
2026-11-18 9:52 ` Finn Thain
2026-11-18 21:00 ` Graeme Harker
2026-11-20 4:34 ` Finn Thain
2026-11-20 16:43 ` Graeme Harker
2026-11-21 9:56 ` Finn Thain
2026-12-05 8:28 ` Graeme Harker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205082807.1348564-1-graeme.harker@gmail.com \
--to=graeme.harker@gmail.com \
--cc=fthain@linux-m68k.org \
--cc=geert@linux-m68k.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®