Skip to content

Commit c7ff0d9

Browse files
tamukitorvalds
authored andcommitted
panic: keep blinking in spite of long spin timer mode
To keep panic_timeout accuracy when running under a hypervisor, the current implementation only spins on long time (1 second) calls to mdelay. That brings a good effect, but the problem is the keyboard LEDs don't blink at all on that situation. This patch changes to call to panic_blink_enter() between every mdelay and keeps blinking in spite of long spin timer mode. The time to call to mdelay is now 100ms. Even this change will keep panic_timeout accuracy enough when running under a hypervisor. Signed-off-by: TAMUKI Shoichi <tamuki@linet.gr.jp> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Russell King <linux@arm.linux.org.uk> Acked-by: Dmitry Torokhov <dtor@mail.ru> Cc: Anton Blanchard <anton@samba.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bebf8cf commit c7ff0d9

5 files changed

Lines changed: 37 additions & 68 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,6 @@ and is between 256 and 4096 characters. It is defined in the file
915915
controller
916916
i8042.nopnp [HW] Don't use ACPIPnP / PnPBIOS to discover KBD/AUX
917917
controllers
918-
i8042.panicblink=
919-
[HW] Frequency with which keyboard LEDs should blink
920-
when kernel panics (default is 0.5 sec)
921918
i8042.reset [HW] Reset the controller during init and cleanup
922919
i8042.unlock [HW] Unlock (ignore) the keylock
923920

‎arch/arm/mach-s3c2440/mach-gta02.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,17 @@
9090
static struct pcf50633 *gta02_pcf;
9191

9292
/*
93-
* This gets called every 1ms when we paniced.
93+
* This gets called frequently when we paniced.
9494
*/
9595

96-
static long gta02_panic_blink(long count)
96+
static long gta02_panic_blink(int state)
9797
{
9898
long delay = 0;
99-
static long last_blink;
100-
static char led;
99+
char led;
101100

102-
/* Fast blink: 200ms period. */
103-
if (count - last_blink < 100)
104-
return 0;
105-
106-
led ^= 1;
101+
led = (state) ? 1 : 0;
107102
gpio_direction_output(GTA02_GPIO_AUX_LED, led);
108103

109-
last_blink = count;
110-
111104
return delay;
112105
}
113106

@@ -556,7 +549,7 @@ static void gta02_poweroff(void)
556549

557550
static void __init gta02_machine_init(void)
558551
{
559-
/* Set the panic callback to make AUX LED blink at ~5Hz. */
552+
/* Set the panic callback to turn AUX LED on or off. */
560553
panic_blink = gta02_panic_blink;
561554

562555
s3c_pm_init();

‎drivers/input/serio/i8042.c‎

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ static bool i8042_noloop;
6161
module_param_named(noloop, i8042_noloop, bool, 0);
6262
MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
6363

64-
static unsigned int i8042_blink_frequency = 500;
65-
module_param_named(panicblink, i8042_blink_frequency, uint, 0600);
66-
MODULE_PARM_DESC(panicblink, "Frequency with which keyboard LEDs should blink when kernel panics");
67-
6864
#ifdef CONFIG_X86
6965
static bool i8042_dritek;
7066
module_param_named(dritek, i8042_dritek, bool, 0);
@@ -1030,8 +1026,8 @@ static void i8042_controller_reset(void)
10301026

10311027

10321028
/*
1033-
* i8042_panic_blink() will flash the keyboard LEDs and is called when
1034-
* kernel panics. Flashing LEDs is useful for users running X who may
1029+
* i8042_panic_blink() will turn the keyboard LEDs on or off and is called
1030+
* when kernel panics. Flashing LEDs is useful for users running X who may
10351031
* not see the console and will help distingushing panics from "real"
10361032
* lockups.
10371033
*
@@ -1041,22 +1037,12 @@ static void i8042_controller_reset(void)
10411037

10421038
#define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0)
10431039

1044-
static long i8042_panic_blink(long count)
1040+
static long i8042_panic_blink(int state)
10451041
{
10461042
long delay = 0;
1047-
static long last_blink;
1048-
static char led;
1049-
1050-
/*
1051-
* We expect frequency to be about 1/2s. KDB uses about 1s.
1052-
* Make sure they are different.
1053-
*/
1054-
if (!i8042_blink_frequency)
1055-
return 0;
1056-
if (count - last_blink < i8042_blink_frequency)
1057-
return 0;
1043+
char led;
10581044

1059-
led ^= 0x01 | 0x04;
1045+
led = (state) ? 0x01 | 0x04 : 0;
10601046
while (i8042_read_status() & I8042_STR_IBF)
10611047
DELAY;
10621048
dbg("%02x -> i8042 (panic blink)", 0xed);
@@ -1069,7 +1055,6 @@ static long i8042_panic_blink(long count)
10691055
dbg("%02x -> i8042 (panic blink)", led);
10701056
i8042_write_data(led);
10711057
DELAY;
1072-
last_blink = count;
10731058
return delay;
10741059
}
10751060

‎include/linux/kernel.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ struct va_format {
177177
};
178178

179179
extern struct atomic_notifier_head panic_notifier_list;
180-
extern long (*panic_blink)(long time);
180+
extern long (*panic_blink)(int state);
181181
NORET_TYPE void panic(const char * fmt, ...)
182182
__attribute__ ((NORET_AND format (printf, 1, 2))) __cold;
183183
extern void oops_enter(void);

‎kernel/panic.c‎

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#include <linux/nmi.h>
2525
#include <linux/dmi.h>
2626

27+
#define PANIC_TIMER_STEP 100
28+
#define PANIC_BLINK_SPD 18
29+
2730
int panic_on_oops;
2831
static unsigned long tainted_mask;
2932
static int pause_on_oops;
@@ -36,36 +39,15 @@ ATOMIC_NOTIFIER_HEAD(panic_notifier_list);
3639

3740
EXPORT_SYMBOL(panic_notifier_list);
3841

39-
/* Returns how long it waited in ms */
40-
long (*panic_blink)(long time);
41-
EXPORT_SYMBOL(panic_blink);
42-
43-
static void panic_blink_one_second(void)
42+
static long no_blink(int state)
4443
{
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-
}
44+
return 0;
6745
}
6846

47+
/* Returns how long it waited in ms */
48+
long (*panic_blink)(int state);
49+
EXPORT_SYMBOL(panic_blink);
50+
6951
/**
7052
* panic - halt the system
7153
* @fmt: The text string to print
@@ -78,7 +60,8 @@ NORET_TYPE void panic(const char * fmt, ...)
7860
{
7961
static char buf[1024];
8062
va_list args;
81-
long i;
63+
long i, i_next = 0;
64+
int state = 0;
8265

8366
/*
8467
* It's possible to come here directly from a panic-assertion and
@@ -117,16 +100,23 @@ NORET_TYPE void panic(const char * fmt, ...)
117100

118101
bust_spinlocks(0);
119102

103+
if (!panic_blink)
104+
panic_blink = no_blink;
105+
120106
if (panic_timeout > 0) {
121107
/*
122108
* Delay timeout seconds before rebooting the machine.
123109
* We can't use the "normal" timers since we just panicked.
124110
*/
125111
printk(KERN_EMERG "Rebooting in %d seconds..", panic_timeout);
126112

127-
for (i = 0; i < panic_timeout; i++) {
113+
for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP) {
128114
touch_nmi_watchdog();
129-
panic_blink_one_second();
115+
if (i >= i_next) {
116+
i += panic_blink(state ^= 1);
117+
i_next = i + 3600 / PANIC_BLINK_SPD;
118+
}
119+
mdelay(PANIC_TIMER_STEP);
130120
}
131121
/*
132122
* This will not be a clean reboot, with everything
@@ -152,9 +142,13 @@ NORET_TYPE void panic(const char * fmt, ...)
152142
}
153143
#endif
154144
local_irq_enable();
155-
while (1) {
145+
for (i = 0; ; i += PANIC_TIMER_STEP) {
156146
touch_softlockup_watchdog();
157-
panic_blink_one_second();
147+
if (i >= i_next) {
148+
i += panic_blink(state ^= 1);
149+
i_next = i + 3600 / PANIC_BLINK_SPD;
150+
}
151+
mdelay(PANIC_TIMER_STEP);
158152
}
159153
}
160154

0 commit comments

Comments
 (0)