Skip to content

Commit 8aeee85

Browse files
antonblanchardtorvalds
authored andcommitted
panic: fix panic_timeout accuracy when running on a hypervisor
I've had some complaints about panic_timeout being wildly innacurate on shared processor PowerPC partitions (a 3 minute panic_timeout taking 30 minutes). The problem is we loop on mdelay(1) and with a 1ms in 10ms hypervisor timeslice each of these will take 10ms (ie 10x) longer. I expect other platforms with shared processor hypervisors will see the same issue. This patch keeps the old behaviour if we have a panic_blink (only keyboard LEDs right now) and does 1 second mdelays if we don't. Signed-off-by: Anton Blanchard <anton@samba.org> Cc: Ingo Molnar <mingo@elte.hu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 78d7d40 commit 8aeee85

1 file changed

Lines changed: 30 additions & 16 deletions

File tree

‎kernel/panic.c‎

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,36 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
3636

3737
EXPORT_SYMBOL(panic_notifier_list);
3838

39-
static long no_blink(long time)
40-
{
41-
return 0;
42-
}
43-
4439
/* Returns how long it waited in ms */
4540
long (*panic_blink)(long time);
4641
EXPORT_SYMBOL(panic_blink);
4742

43+
static void panic_blink_one_second(void)
44+
{
45+
static long i = 0, end;
46+
47+
if (panic_blink) {
48+
end = i + MSEC_PER_SEC;
49+
50+
while (i < end) {
51+
i += panic_blink(i);
52+
mdelay(1);
53+
i++;
54+
}
55+
} else {
56+
/*
57+
* When running under a hypervisor a small mdelay may get
58+
* rounded up to the hypervisor timeslice. For example, with
59+
* a 1ms in 10ms hypervisor timeslice we might inflate a
60+
* mdelay(1) loop by 10x.
61+
*
62+
* If we have nothing to blink, spin on 1 second calls to
63+
* mdelay to avoid this.
64+
*/
65+
mdelay(MSEC_PER_SEC);
66+
}
67+
}
68+
4869
/**
4970
* panic - halt the system
5071
* @fmt: The text string to print
@@ -95,21 +116,16 @@ NORET_TYPE void panic(const char * fmt, ...)
95116

96117
bust_spinlocks(0);
97118

98-
if (!panic_blink)
99-
panic_blink = no_blink;
100-
101119
if (panic_timeout > 0) {
102120
/*
103121
* Delay timeout seconds before rebooting the machine.
104122
* We can't use the "normal" timers since we just panicked.
105123
*/
106124
printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout);
107125

108-
for (i = 0; i < panic_timeout*1000; ) {
126+
for (i = 0; i < panic_timeout; i++) {
109127
touch_nmi_watchdog();
110-
i += panic_blink(i);
111-
mdelay(1);
112-
i++;
128+
panic_blink_one_second();
113129
}
114130
/*
115131
* This will not be a clean reboot, with everything
@@ -135,11 +151,9 @@ NORET_TYPE void panic(const char * fmt, ...)
135151
}
136152
#endif
137153
local_irq_enable();
138-
for (i = 0; ; ) {
154+
while (1) {
139155
touch_softlockup_watchdog();
140-
i += panic_blink(i);
141-
mdelay(1);
142-
i++;
156+
panic_blink_one_second();
143157
}
144158
}
145159

0 commit comments

Comments
 (0)