x86: make delay work in earlier stages
PATCH 1/1 x86: make delay work in earlier stages
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.
--- arch/x86/lib/delay.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/lib/delay.c +3 -2
@@ -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); }
Signature · 1 line
2.11.0
arch/x86/lib/delay.c EXPORT_SYMBOL(__delay); · line 160
Quoted 2 lines
arch/x86/lib/delay.c +2
-0+unsigned long lpf =this_cpu_read (cpu_info.loops_per_jiffy) ? : + loops_per_jiffy;
Perhaps lpj ?
In any case FWIW:
Signature · 2 lines
With Best Regards, Andy Shevchenko
tip-bot for Jiri Slaby
merge bot[tip:timers/core] x86/timer: Make delay() during early bootup
In reply to Jiri Slabyx86/timer: Make delay() during early bootup
Commit-ID: bf3304d996fbb993bad6be09cafde39cc2db72bb Gitweb: http://git.kernel.org/tip/bf3304d996fbb993bad6be09cafde39cc2db72bb Author: Jiri Slaby <[email protected]> AuthorDate: Thu, 19 Jan 2017 12:47:30 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 20 Jan 2017 09:45:22 +0100
x86/timer: Make delay() 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 is does not work 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 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.
--- arch/x86/lib/delay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/lib/delay.c +2 -2
@@ -156,13 +156,13 @@ EXPORT_SYMBOL(__delay);inline void __const_udelay (unsigned long xloops) { +unsigned long lpj =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" (lpj * (HZ /4 )));__delay (++xloops); }
Re: [tip:timers/core] x86/timer: Make delay() during early bootup
Quoted 7 lines · tip-bot for Jiri Slaby
Commit-ID: bf3304d996fbb993bad6be09cafde39cc2db72bb Gitweb: http://git.kernel.org/tip/bf3304d996fbb993bad6be09cafde39cc2db72bb Author: Jiri Slaby <[email protected]> AuthorDate: Thu, 19 Jan 2017 12:47:30 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Fri, 20 Jan 2017 09:45:22 +0100
Quoted 6 lines
x86/timer: Make
delay()during early bootupWhen a panic happens during bootup, "Rebooting in X seconds.." is shown, but reboot happens immediatelly. It is because
panic()usesmdelay()andmdelay()calls__const_udelay()immediately, which is does not work while booting.
The 'is' is superfluous after your edit now. But I guess, you cannot change it given it is in the tree.
arch/x86/lib/delay.c EXPORT_SYMBOL(__delay); · line 159
Quoted 7 lines
arch/x86/lib/delay.c +1
-0@@ -156,13 +156,13 @@ EXPORT_SYMBOL(__delay);inline void __const_udelay (unsigned long xloops) { +unsigned long lpj =this_cpu_read (cpu_info.loops_per_jiffy) ? : loops_per_jiffy;
And thanks for fixing the 'lpf' brain damage :).
Signature · 2 lines
js suse labs
tip-bot for Jiri Slaby
merge bot[tip:timers/core] x86/timer: Make delay() work during early bootup
In reply to Jiri Slabyx86/timer: Make delay() work during early bootup
Commit-ID: 4c45c5167c9563b1a2eee3e2fe954621355e4ca8 Gitweb: http://git.kernel.org/tip/4c45c5167c9563b1a2eee3e2fe954621355e4ca8 Author: Jiri Slaby <[email protected]> AuthorDate: Thu, 19 Jan 2017 12:47:30 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Sun, 22 Jan 2017 10:03:12 +0100
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.
--- arch/x86/lib/delay.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/lib/delay.c +2 -2
@@ -156,13 +156,13 @@ EXPORT_SYMBOL(__delay);inline void __const_udelay (unsigned long xloops) { +unsigned long lpj =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" (lpj * (HZ /4 )));__delay (++xloops); }