mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86: make delay work in earlier stages
@ 2017-01-19 11:47 Jiri Slaby
  2017-01-19 18:35 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jiri Slaby @ 2017-01-19 11:47 UTC (permalink / raw)
  To: mingo
  Cc: linux-kernel, Jiri Slaby, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, x86

When a panic happens during bootup, "Rebooting in X seconds.." is
shown, but reboot happens immediatelly. It is because panic uses mdelay
and mdelay calls internally __const_udelay which is broken while booting.

The per_cpu cpu_info.loops_per_jiffy is not initialized yet, so
__const_udelay actually multiplies the number of loops by zero. This
results in __const_udelay to delay the execution only by a nanosecond or
so.

So check whether cpu_info.loops_per_jiffy is zero and use
loops_per_jiffy in that case. mdelay will not be so precise, but it
works relatively good. From the original (mdelay in rest_init):
[    0.170039] delaying 100ms
[    0.170828] done
I get:
[    0.214042] delaying 100ms
[    0.313974] done

I do not think the added check matters given we are about to spin the
processor in the next few hundred cycles.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <x86@kernel.org>
---
 arch/x86/lib/delay.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/x86/lib/delay.c b/arch/x86/lib/delay.c
index 073d1f1a620b..aca0988f0e14 100644
--- a/arch/x86/lib/delay.c
+++ b/arch/x86/lib/delay.c
@@ -156,13 +156,14 @@ EXPORT_SYMBOL(__delay);
 
 inline void __const_udelay(unsigned long xloops)
 {
+	unsigned long lpf = this_cpu_read(cpu_info.loops_per_jiffy) ? :
+		loops_per_jiffy;
 	int d0;
 
 	xloops *= 4;
 	asm("mull %%edx"
 		:"=d" (xloops), "=&a" (d0)
-		:"1" (xloops), "0"
-		(this_cpu_read(cpu_info.loops_per_jiffy) * (HZ/4)));
+		:"1" (xloops), "0" (lpf * (HZ / 4)));
 
 	__delay(++xloops);
 }
-- 
2.11.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-22  9:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-19 11:47 [PATCH] x86: make delay work in earlier stages Jiri Slaby
2017-01-19 18:35 ` Andy Shevchenko
2017-01-20 14:40 ` [tip:timers/core] x86/timer: Make delay() during early bootup tip-bot for Jiri Slaby
2017-01-21  7:35   ` Jiri Slaby
2017-01-22  9:08 ` [tip:timers/core] x86/timer: Make delay() work " tip-bot for Jiri Slaby

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome