mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Graeme Harker <graeme.harker@gmail.com>
To: Finn Thain <fthain@linux-m68k.org>
Cc: geert@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: Fri, 20 Nov 2026 16:43:22 +0000	[thread overview]
Message-ID: <20261120164322.1034075-1-graeme.harker@gmail.com> (raw)
In-Reply-To: <5783b448-b34a-58a5-0bc0-98b1a806f182@linux-m68k.org>

Hi Finn,

Thanks for running it again, and with both interrupt settings.

> test_ndelay(40)	 191E-09 -> 17.0E-09

I think this one has wrapped the timer as well. 400000 calls only fit
in T2's 83.7 ms if each takes less than 209 ns, and 17 ns is less than
one clock on the LC040. With one wrap it would be 226 ns, which is
longer than before, as ndelay(400) now is. 40000 calls should show it.

> test_ndelay(40000) 38.7E-06 -> 46.5E-06
> test_ndelay(400000) 366E-06 -> 456E-06

These show a real problem with the patch: long ndelay()s now run about
15% long. The 5 I took from x86 is 2^32 / 10^9 rounded up, but
2^32 / 10^9 is 4.295, so every ndelay() asks for 16.4% more loops than
it should. Combined with your udelay(1000) of 979 us (2% short), that
predicts 453 us for ndelay(400000), and you measured 456 us. The old
code was short instead, from rounding loops_per_jiffy down to a
multiple of 2048.

I can't explain the old ndelay(4000) of 6.03 us without knowing
loops_per_jiffy. What does your machine calibrate to?

I can see three ways to go, and I'd like to know which you and Geert
would prefer:

1. Keep 5, as x86 does. Delays are never short, but up to 16% long.

2. Use a closer constant, e.g. __xdelay(nsec * 4 + ((nsec * 1209) >> 12)),
   which is 4.29517, within 0.005% of 2^32 / 10^9 and still never
   short. It costs another multiply and a shift on every call, and the
   second term overflows for delays above 3.5 ms, which ndelay() should
   not be asked for anyway.

3. Leave ndelay() as it is and fix only udelay().

Option 2 seems the most accurate, but ndelay() is mostly used for short
delays, and for those the call overhead you measured matters more than
the constant.

Graeme

      reply	other threads:[~2026-11-20 16:43 UTC|newest]

Thread overview: 5+ 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 [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=20261120164322.1034075-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®