mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dominik Brodowski <linux@dominikbrodowski.de>
To: 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: Re: Too much error in __const_udelay() ?
Date: Sat, 5 Jun 2004 17:23:26 +0200	[thread overview]
Message-ID: <20040605152326.GA11239@dominikbrodowski.de> (raw)
In-Reply-To: <1086419565.2234.133.camel@cog.beaverton.ibm.com>

Hi,

> However I've started to see some problems w/ 2.6 and USB on x440/x445s,
> both of which use the 100Mhz cyclone time source. Further digging has
> pointed to the fact that certain important udelay()s in the USB
> subsystem aren't actually waiting long enough. 

Certain? AFAICS _no_ call to a delay routine actually passed a big enough
argument. Or am I missing something? Also, __ndelay seems to be affected 
as well: it returns zero for 550 nsec even for the TSC variant in your 
test.c.

> So I'm no math wiz. What's the proper fix here? 

Below are three changes I'd like to discuss. I'll build a fresh kernel with
all three changes enabled + PM_TIMER soon.

Change 1:

Move the multiplication with HZ up into the mull instruction:

unsigned long  __const_udelay(unsigned long xloops)
{
	int d0;
	__asm__("mull %0"
		:"=d" (xloops), "=&a" (d0)
		:"1" (xloops),"0" (LPJ * HZ));
        return __delay(xloops);
}

  1 usec: LPJ:  100000 __udelay:     0 vs my_udelay:    99
  1 usec: LPJ: 1500000 __udelay:  1000 vs my_udelay:  1499

  2 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   199
  2 usec: LPJ: 1500000 __udelay:  2000 vs my_udelay:  2999

  5 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   499
  5 usec: LPJ: 1500000 __udelay:  7000 vs my_udelay:  7498

 10 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   999
 10 usec: LPJ: 1500000 __udelay: 14000 vs my_udelay: 14996

 20 usec: LPJ:  100000 __udelay:  1000 vs my_udelay:  1999
 20 usec: LPJ: 1500000 __udelay: 29000 vs my_udelay: 29993

 50 usec: LPJ:  100000 __udelay:  4000 vs my_udelay:  4998
 50 usec: LPJ: 1500000 __udelay: 74000 vs my_udelay: 74983

100 usec: LPJ:  100000 __udelay:  9000 vs my_udelay:  9997
100 usec: LPJ: 1500000 __udelay: 149000 vs my_udelay: 149966

20000 usec: LPJ:  100000 __udelay: 1999000 vs my_udelay: 1999549
20000 usec: LPJ: 1500000 __udelay: 29993000 vs my_udelay: 29993243


Change 2:

Round up in __udelay. While it can be argued that some time is also
spent in the delay functions, it's better to spend _at least_ the specified
time sleeping, in my humble opinion. 


-	return __const_udelay2(usecs * 0x000010c6);  /* 2**32 / 1000000 */
+	return __const_udelay2(usecs * 0x000010c7);  /* 2**32 / 1000000 (rounded up)*/

  1 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   100
  1 usec: LPJ: 1500000 __udelay:  1000 vs my_udelay:  1500

  2 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   200
  2 usec: LPJ: 1500000 __udelay:  2000 vs my_udelay:  3000

  5 usec: LPJ:  100000 __udelay:     0 vs my_udelay:   500
  5 usec: LPJ: 1500000 __udelay:  7000 vs my_udelay:  7500

 10 usec: LPJ:  100000 __udelay:     0 vs my_udelay:  1000
 10 usec: LPJ: 1500000 __udelay: 14000 vs my_udelay: 15000

 20 usec: LPJ:  100000 __udelay:  1000 vs my_udelay:  2000
 20 usec: LPJ: 1500000 __udelay: 29000 vs my_udelay: 30000

 50 usec: LPJ:  100000 __udelay:  4000 vs my_udelay:  5000
 50 usec: LPJ: 1500000 __udelay: 74000 vs my_udelay: 75000

100 usec: LPJ:  100000 __udelay:  9000 vs my_udelay: 10000
100 usec: LPJ: 1500000 __udelay: 149000 vs my_udelay: 150001

20000 usec: LPJ:  100000 __udelay: 1999000 vs my_udelay: 2000015
20000 usec: LPJ: 1500000 __udelay: 29993000 vs my_udelay: 30000228


Change 3:

Asserting at least 1 loop is spent: in really small ndelay() calls to
low-mhz timers, this might be better.

        return __delay(xloops ? xloops : 1);

Before:
  1 nsec: LPJ:  100000 __ndelay:     0 vs my_udelay:     0
  2 nsec: LPJ:  100000 __ndelay:     0 vs my_udelay:     0
  5 nsec: LPJ:  100000 __ndelay:     0 vs my_udelay:     0
 10 nsec: LPJ:  100000 __ndelay:     0 vs my_udelay:     1
 20 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     2
 50 nsec: LPJ:  100000 __ndelay:     0 vs my_udelay:     5

After:
  1 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     1
  2 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     1
  5 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     1
 10 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     1
 20 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     2
 50 nsec: LPJ:  100000 __udelay:     0 vs my_udelay:     5



	Dominik

  reply	other threads:[~2004-06-05 15:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-05  7:12 john stultz
2004-06-05 15:23 ` Dominik Brodowski [this message]
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
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=20040605152326.GA11239@dominikbrodowski.de \
    --to=linux@dominikbrodowski.de \
    --cc=george@mvista.com \
    --cc=greg@kroah.com \
    --cc=johnstul@us.ibm.com \
    --cc=lcm@us.ibm.com \
    --cc=linux-kernel@vger.kernel.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®