mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.de>
To: akpm@osdl.org, torvalds@osdl.org, john stultz <johnstul@us.ibm.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
	george anzinger <george@mvista.com>, greg kh <greg@kroah.com>,
	Chris McDermott <lcm@us.ibm.com>
Subject: [PATCH 3/3] add 1 in __const_udelay() [Was: Re: Too much error in __const_udelay() ?]
Date: Tue, 15 Jun 2004 08:13:15 +0200	[thread overview]
Message-ID: <20040615061315.GD27541@dominikbrodowski.de> (raw)

The "mull" instruction in __const_udelay() cuts off the lower 32 bits -- so,
it is "rounding down". This is both an issue for small ndelay()s for _all_ 
values for loops_per_jiffy and for certain {n,u}delay()s for many loops_per_jiffy
values.

Assuming

LPJ = 1501115

udelay(87)

results in

130597 loops to be spent.

However, 1000 * 130597 / 1501115 is 86.999997 us, so we're actually
_rounding down_. 1000 * 130598 / 1501115 is 87.000662841, which would be the
technically correct thing to do. Of course, for the TSC case this won't
matter as the maths take some time, so the actual delay is

1000 * __udelay(x) / lpj + __OVERHEAD(x)


Anybody worried about both the additional overhead and the fact that the
overhead takes some time to run should add a check

        if (unlikely(xloops < OVERHEAD))
                return;
        xloops -= OVERHEAD;


to the delay() routines in arch/i386/kernel/timers/*.c and determine
what the OVERHEAD is.

Signed-off-by: Dominik Brodowski <linux@brodo.de>

diff -ruN linux-original/arch/i386/lib/delay.c linux/arch/i386/lib/delay.c
--- linux-original/arch/i386/lib/delay.c	2004-06-15 07:54:16.938687280 +0200
+++ linux/arch/i386/lib/delay.c	2004-06-15 07:54:36.275747600 +0200
@@ -35,7 +35,7 @@
 	__asm__("mull %0"
 		:"=d" (xloops), "=&a" (d0)
 		:"1" (xloops),"0" (current_cpu_data.loops_per_jiffy * (HZ/4)));
-        __delay(xloops);
+        __delay(++xloops);
 }
 
 void __udelay(unsigned long usecs)

                 reply	other threads:[~2004-06-15  6:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20040615061315.GD27541@dominikbrodowski.de \
    --to=linux@dominikbrodowski.de \
    --cc=akpm@osdl.org \
    --cc=george@mvista.com \
    --cc=greg@kroah.com \
    --cc=johnstul@us.ibm.com \
    --cc=lcm@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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®