diff mbox series

[U-Boot,17/21] time: Update mdelay() to delay in one large chunk

Message ID 20181124042944.239106-18-sjg@chromium.org
State Accepted
Commit 49c751603c5abfe32019640834bc34a0a424eb57
Delegated to: Simon Glass
Headers show
Series Various patches for verified boot support | expand

Commit Message

Simon Glass Nov. 24, 2018, 4:29 a.m. UTC
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 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Simon Glass Dec. 5, 2018, 11:10 p.m. UTC | #1
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 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied to u-boot-dm/master, thanks!
diff mbox series

Patch

diff --git a/include/linux/delay.h b/include/linux/delay.h
index 193603451a7..71a38e15fbd 100644
--- a/include/linux/delay.h
+++ b/include/linux/delay.h
@@ -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)