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 1/3] mull'ify multiplication with HZ in __const_udelay() [Was: Re: Too much error in __const_udelay() ?]
Date: Tue, 15 Jun 2004 08:11:09 +0200	[thread overview]
Message-ID: <20040615061109.GA27541@dominikbrodowski.de> (raw)
In-Reply-To: <20040607212058.GA23106@dominikbrodowski.de>

John Stultz mentioned on lkml ( http://lkml.org/lkml/2004/6/5/15 ) that
calls to udelay() don't delay long enough, causing trouble e.g. in the USB
subsystem. The following patches address this issue.

Move the multiplication of (loops_per_jiffy * xloops) with HZ into
the "mull" asm operation. This increases the accuracy of the delay functions
largely:

n usec delay on a system with loops_per_jiffy = 1500000 : 

  n 	   before	  after
  1	 1000 ticks	 1499 ticks
 10	14000 ticks	14999 ticks

n usec delay on a system with loops_per_jiffy = 100000 : 

 n 	   before	  after
  1	    0 ticks	   99 ticks
 10	    0 ticks	  999 ticks
100	 9000 ticks	 9999 ticks

As noted by Kurt Garloff, it's necessary to adjust for large loops_per_jiffies,
as the multiplication of it with HZ fails for 4GHz or larger. So, John Stultz
suggested multiplying xloops with 4 first, and multiplying with (HZ/4).

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-14 18:20:27.000000000 +0200
+++ linux/arch/i386/lib/delay.c	2004-06-15 07:48:57.302279400 +0200
@@ -31,10 +31,11 @@
 inline void __const_udelay(unsigned long xloops)
 {
 	int d0;
+	xloops *= 4;
 	__asm__("mull %0"
 		:"=d" (xloops), "=&a" (d0)
-		:"1" (xloops),"0" (current_cpu_data.loops_per_jiffy));
-        __delay(xloops * HZ);
+		:"1" (xloops),"0" (current_cpu_data.loops_per_jiffy * (HZ/4)));
+        __delay(xloops);
 }
 
 void __udelay(unsigned long usecs)

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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-05  7:12 Too much error in __const_udelay() ? john stultz
2004-06-05 15:23 ` Dominik Brodowski
2004-06-06 19:46   ` Pavel Machek
2004-06-07 19:12   ` john stultz
2004-06-07 20:27     ` john stultz
2004-06-07 21:20     ` [PATCH 1/3] mull'ify multiplication with HZ in __const_udelay() [Was: Re: Too much error in __const_udelay() ?] Dominik Brodowski
2004-06-07 22:00       ` john stultz
2004-06-15  6:11       ` Dominik Brodowski [this message]
2004-06-07 21:22     ` [PATCH 2/3] round up in __udelay() " Dominik Brodowski
2004-06-07 21:23     ` [PATCH 3/3] fix for small xloops " Dominik Brodowski
2004-06-09 10:03       ` Pavel Machek
2004-06-07 21:23     ` Too much error in __const_udelay() ? Dominik Brodowski

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=20040615061109.GA27541@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®