time: Update mdelay() to delay in one large chunk
authorSimon Glass <sjg@chromium.org>
Sat, 24 Nov 2018 04:29:40 +0000 (21:29 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 5 Dec 2018 13:01:35 +0000 (06:01 -0700)
The current function delays in one millisecond at a time. This does not
work well on sandbox since it results in lots of calls to usleep(1000) in
a tight loop. This makes the sleep duration quite variable since each call
results in a sleep of *at least* 1000us, but possibly more. Depending on
how busy the machine is, the sleep time can change quite a bit.

We cannot fix this in general, but we can reduce the effect by doing a
single sleep. The multiplication works fine with an unsigned long argument
up until a sleep time of about 4m milliseconds. This is over an hour and
we can be sure that delays of that length are not useful.

Update the mdelay() function to call udelay() only once with the
calculated delay value.

Signed-off-by: Simon Glass <sjg@chromium.org>
include/linux/delay.h

index 193603451a765b146d3c092095eea3d23415c48e..71a38e15fbd3232992a775d1ede31635b7059f78 100644 (file)
@@ -10,8 +10,7 @@ void udelay(unsigned long usec);
 
 static inline void mdelay(unsigned long msec)
 {
-       while (msec--)
-               udelay(1000);
+       udelay(1000 * msec);
 }
 
 static inline void ndelay(unsigned long nsec)