All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v1 (WIP) 00/16] [Timer]API Rewrite
Date: Fri, 15 Jul 2011 09:17:34 +0200	[thread overview]
Message-ID: <20110715071734.4364916F76F1@gemini.denx.de> (raw)
In-Reply-To: <4E1F8127.8030008@comcast.net>

Dear "J. William Campbell",

In message <4E1F8127.8030008@comcast.net> you wrote:
>
> I am pretty sure that is long enough for someone to notice. . I would be 
> interested in seeing an example of such code as you refer to. Could you 
> point me to one, because it seems to me that the only reason to code 
> such a delay is that for some reason the user didn't want to keep 
> looking at the termination condition so often. I think that that 

arch/powerpc/cpu/mpc512x/i2c.c:

 80         while (timeout-- && (status & I2C_BB)) {
 ...
 88                 udelay (1000);
 89                 status = mpc_reg_in (&regs->msr);
 90         }

103         while (timeout-- && !(*status & I2C_IF)) {
104                 udelay (1000);
105                 *status = mpc_reg_in (&regs->msr);
106         }

arch/powerpc/cpu/mpc512x/pci.c:

 87         /* We need to wait at least a 1sec based on PCI specs */
 88         for (i = 0; i < 1000; i++)
 89                 udelay(1000);

arch/powerpc/cpu/mpc5xx/spi.c:

258         for (i = 0; i < 1000; i++) {
...
265                 udelay(1000);
266         }

390         for (tm=0; tm<1000; ++tm) {
...
394                 udelay (1000);
395         }

arch/powerpc/cpu/mpc5xxx/i2c.c:

102         while (timeout-- && (status & I2C_BB)) {
...
111                 udelay(15);
112                 status = mpc_reg_in(&regs->msr);
113         }

125         while (timeout-- && !(*status & I2C_IF)) {
126                 udelay(15);
127                 *status = mpc_reg_in(&regs->msr);
128         }

And just that you don't think this is in a single CPU only:

arch/powerpc/cpu/mpc8260/pci.c:

343                 for (i = 0; i < 1000; ++i)
...
345                         udelay (1000);

Or in board code:

board/altera/common/cfide.c:

 29         /* wait 500 ms for power to stabilize */
 30         for (i = 0; i < 500; i++)
 31                 udelay(1000);

board/amcc/bamboo/bamboo.c:

1019         for (i=0; i<500; i++)
1020                 udelay(1000);

or common code:

common/cmd_fdc.c:

213         while((read_fdc_reg(FDC_SRA)&0x80)==0) {
214                 timeout--;
215                 udelay(10);
216                 if(timeout==0) /* timeout occured */
217                         return FALSE;
218         }

228         while((read_fdc_reg(FDC_MSR)&0xC0)!=0xC0) {
229                 /* direction out and ready */
230                 udelay(10);
231                 timeout--;
232                 if(timeout==0) /* timeout occured */
233                         return -1;
234         }
etc.etc.

375                 for(val=0;val<255;val++)
376                         udelay(500); /* wait some time to start motor */

418         for(i=0;i<100;i++)
419                 udelay(500); /* wait 500usec for fifo overrun */

600         for(i=0; i<255; i++) /* then we wait some time */
601                 udelay(500);


common/usb.c:

  93 inline void wait_ms(unsigned long ms)
  94 {
  95         while (ms-- > 0)
  96                 udelay(1000);
  97 }

etc. etc.  Note this last example which "spreads" the effect in a not
so nice way.

Note that there are even places where udelay() is part of the protocol
timing implementation - like in the soft-I2C and soft-SPI drivers.


> equivalent  operation can be produced by a pretty simple re-coding of 
> the loop. In any case, NIOS does not have the problem at present, so the 
> suggested new work-around would be no worse than the present situation.

I think it is not correct to state that "NIOS does not have the
problem at present" - it does, only this is not a blatant problem at
the moment.  Which in turn might result from the fact that all
presently supported NIOS boards has any support enabled for I2C or
SPI or USB or MMC or watchdogs or ... you name it.

The first user who adds any of the currently unused (and thus
untested) standard features that work just fine on all other
architectures might run into issue...

>           It is also true that the hardware timer cannot be used in a 
> reasonable version of udelay, as most of the desired delays may be very 
> short relative to the timebase. A calibrated timing loop would be the 
> best approach to the udelay problem.

Just try using Soft-I2C on a NIOS board and you will immediately
realize how crucial a working version of udelay() is.

> In general, that is true. There may be a few cases where a delay of less 
> than the resolution is essential to make something work. There are 

These are not just "a few cases".  There are tons of it, all over the
place - from protocol implementations like soft-I2C or soft-I2C to
timing requirements for RAM initializations etc. etc.  And there are
enough places that mandate that the timing is at least in the
requested oder, and not off by factors of tens or hundrets or worse.

> probably lots of other cases where we can easily remove the restriction 
> on the resolution. We cannot fix the first kind, no matter what we do, 
> to work on a lower resolution timer. The second kind we can and probably 
> should fix, because they are coded in an overly-restrictive manner. In 
> any case, we don't absolutely have to fix them until somebody decides to 
> use the code on a CPU with a low resolution timer. Practically speaking, 
> the suggested solution will therefore work on all extant cases.

It will work by chance, at best.  See above - any attempt to enable
one of the currently not yet used standard features in U-Boot may
break your system.  I don't consider this a sound base - to me it
feels like building on qicksand.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Do not simplify the design of a program if a way can be found to make
it complex and wonderful.

  reply	other threads:[~2011-07-15  7:17 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-28 11:40 [U-Boot] [PATCH v1 (WIP) 00/16] [Timer]API Rewrite Graeme Russ
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 01/16] [Timer]Fix misuse of ARM *timer_masked() functions outside arch/arm Graeme Russ
2011-06-28 12:35   ` Andreas Bießmann
2011-07-11 21:57   ` Wolfgang Denk
2011-07-14 17:01     ` Albert ARIBAUD
2011-07-14 19:50       ` Wolfgang Denk
2011-07-14 23:24         ` Graeme Russ
2011-07-15  6:31           ` Wolfgang Denk
2011-07-15  7:00             ` Graeme Russ
2011-07-15 12:16   ` [U-Boot] [PATCH v2 1/7]Timer: Fix " Graeme Russ
2011-07-16  8:40     ` Albert ARIBAUD
2011-07-16  8:59       ` Graeme Russ
2011-07-16  9:12         ` Albert ARIBAUD
2011-07-16  9:31     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-16  9:58       ` Albert ARIBAUD
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 02/16] [Timer]Remove calls to set_timer outside arch/ Graeme Russ
2011-07-11 21:58   ` Wolfgang Denk
2011-07-15 12:17   ` [U-Boot] [PATCH v2 2/7]Timer: Remove " Graeme Russ
2011-07-16  9:33     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:52       ` Wolfgang Denk
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 03/16] [Timer]Remove calls to set_timer in arch/ Graeme Russ
2011-07-11 21:59   ` Wolfgang Denk
2011-07-15 12:18   ` [U-Boot] [PATCH v2 3/7]Timer: Remove set_timer completely Graeme Russ
2011-07-16  9:34     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:52       ` Wolfgang Denk
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 04/16] [Timer]Allow reset_timer() only for Nios2 Graeme Russ
2011-07-11 22:01   ` Wolfgang Denk
2011-07-15 12:18   ` [U-Boot] [PATCH v2 4/7]Timer: Allow reset_timer() only for systems with low resolution timers Graeme Russ
2011-07-16  9:35     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:53       ` Wolfgang Denk
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 05/16] [Timer]Remove reset_timer() for non-Nios2 arches Graeme Russ
2011-07-11 22:02   ` Wolfgang Denk
2011-07-15  0:01     ` Graeme Russ
2011-07-15 12:19   ` [U-Boot] [PATCH v2 5/7]Timer: Remove " Graeme Russ
2011-07-16  9:36     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:53       ` Wolfgang Denk
2011-08-19 21:24         ` Mike Frysinger
2011-08-19 22:55           ` Graeme Russ
2011-08-19 23:12             ` Mike Frysinger
2011-09-28 19:24           ` Wolfgang Denk
2011-06-28 11:40 ` [U-Boot] [PATCH v1 (WIP) 06/16] [Timer]Fix at91rm9200/spi.c timer usage Graeme Russ
2011-06-28 12:30   ` Andreas Bießmann
2011-07-15 12:20   ` [U-Boot] [PATCH v2 6/7]Timer: Fix " Graeme Russ
2011-07-16  9:37     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:54       ` Wolfgang Denk
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 07/16] [Timer]Remove reset_timer_masked() Graeme Russ
2011-07-11 22:04   ` Wolfgang Denk
2011-07-15 12:21   ` [U-Boot] [PATCH v2 7/7]Timer: Remove reset_timer_masked() Graeme Russ
2011-07-16  9:38     ` [U-Boot] [PATCH v3 " Graeme Russ
2011-07-26 12:54       ` Wolfgang Denk
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 08/16] [Timer]Create new userland timer API Graeme Russ
2011-06-29  4:31   ` Simon Glass
2011-06-29  4:36     ` Graeme Russ
2011-06-29  4:48       ` Simon Glass
2011-07-11 22:05   ` Wolfgang Denk
2011-07-11 22:32     ` Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 09/16] [Timer]Replace get_timer() usage in drivers/block/ Graeme Russ
2011-06-29  4:40   ` Simon Glass
2011-06-29  5:06     ` Reinhard Meyer
2011-06-29  5:19       ` Graeme Russ
2011-06-29  5:30         ` Simon Glass
2011-06-29  5:38           ` Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 10/16] [Timer]Replace get_timer() usage in driver/mtd and driver/block Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 11/16] [Timer]Remove reset_timer() completely Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 12/16] [Timer]Replace get_timer() usage in drivers/ Graeme Russ
2011-06-28 12:36   ` Vitaly Kuzmichev
2011-06-28 23:03     ` Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 13/16] [Timer]Replace get_timer() usage in net/ Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 14/16] [Timer]Replace get_timer() usage in common/ Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 15/16] [Timer]Replace get_timer() usage in board/ Graeme Russ
2011-06-28 11:41 ` [U-Boot] [PATCH v1 (WIP) 16/16] [Timer]Replace get_timer() usage in arch/ Graeme Russ
2011-06-29  4:45   ` Simon Glass
2011-06-29  4:51     ` Graeme Russ
2011-06-29  5:15       ` Mike Frysinger
2011-06-29  5:26         ` Mike Frysinger
2011-06-29  5:29           ` Graeme Russ
2011-06-29  4:54 ` [U-Boot] [PATCH v1 (WIP) 00/16] [Timer]API Rewrite Graeme Russ
2011-06-29  5:08 ` Mike Frysinger
2011-06-29  5:20   ` Graeme Russ
2011-07-08  0:25 ` Graeme Russ
2011-07-09  6:01   ` Albert ARIBAUD
2011-07-11 21:56 ` Wolfgang Denk
2011-07-11 22:49   ` Graeme Russ
2011-07-11 23:36   ` Graeme Russ
2011-07-12  2:17     ` Graeme Russ
2011-07-12  8:49       ` Wolfgang Denk
2011-07-12 10:36         ` Graeme Russ
2011-07-12 13:10           ` Wolfgang Denk
2011-07-12 15:23             ` Scott McNutt
2011-07-12 17:27               ` J. William Campbell
2011-07-13  0:29             ` Graeme Russ
2011-07-14 19:30               ` Wolfgang Denk
2011-07-17  1:51           ` Graeme Russ
2011-07-12 14:30       ` J. William Campbell
2011-07-12 16:08         ` Reinhard Meyer
2011-07-13  0:33           ` Graeme Russ
2011-07-13  1:20             ` J. William Campbell
2011-07-14 19:41               ` Wolfgang Denk
2011-07-14 23:52                 ` J. William Campbell
2011-07-15  7:17                   ` Wolfgang Denk [this message]
2011-07-15 18:08                     ` J. William Campbell
2011-07-15 18:34                       ` Wolfgang Denk
2011-07-15 21:03                         ` J. William Campbell
2011-07-16 14:11                           ` Graeme Russ
2011-07-15 12:15 ` [U-Boot] [PATCH v2 0/7]Timer: Simplify API Graeme Russ
2011-07-15 13:08   ` Graeme Russ
2011-07-16  8:36     ` Albert ARIBAUD
2011-07-16  9:01       ` Graeme Russ
2011-07-16  9:13         ` Albert ARIBAUD
2011-07-16  9:32         ` Wolfgang Denk

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=20110715071734.4364916F76F1@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.