提交 4c45c516 编写于 作者: J Jiri Slaby 提交者: Ingo Molnar

x86/timer: Make delay() work during early bootup

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 __const_udelay() immediately, which does not
work while booting.

The per_cpu cpu_info.loops_per_jiffy value 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 without
proper calibration, but it works relatively well.

Before:

  [    0.170039] delaying 100ms
  [    0.170828] done

After

  [    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: NJiri Slaby <jslaby@suse.cz>
Reviewed-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Acked-by: NThomas Gleixner <tglx@linutronix.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20170119114730.2670-1-jslaby@suse.cz
[ Minor edits. ]
Signed-off-by: NIngo Molnar <mingo@kernel.org>
上级 d852d394
...@@ -156,13 +156,13 @@ EXPORT_SYMBOL(__delay); ...@@ -156,13 +156,13 @@ EXPORT_SYMBOL(__delay);
inline void __const_udelay(unsigned long xloops) inline void __const_udelay(unsigned long xloops)
{ {
unsigned long lpj = this_cpu_read(cpu_info.loops_per_jiffy) ? : loops_per_jiffy;
int d0; int d0;
xloops *= 4; xloops *= 4;
asm("mull %%edx" asm("mull %%edx"
:"=d" (xloops), "=&a" (d0) :"=d" (xloops), "=&a" (d0)
:"1" (xloops), "0" :"1" (xloops), "0" (lpj * (HZ / 4)));
(this_cpu_read(cpu_info.loops_per_jiffy) * (HZ/4)));
__delay(++xloops); __delay(++xloops);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册