History

[PATCH] pause_on_oops command line option

Attempt to fix the problem wherein people's oops reports scroll off the screen due to repeated oopsing or to oopses on other CPUs. If this happens the user can reboot with the `pause_on_oops=<seconds>' option. It will allow the first oopsing CPU to print an oops record just a single time. Second oopsing attempts, or oopses on other CPUs will cause those CPUs to enter a tight loop until the specified number of seconds have elapsed. The patch implements the infrastructure generically in the expectation that architectures other than x86 will find it useful.

Andrew Morton committed 20 years ago

Commit dd287791 parent 41c28ff5 files · +130 −17Browse files

Showing the changes to kernel (1 of 5 files). Show all

Unified · Split

kernel/panic.c+96−1
@@ -20,10 +20,13 @@ · 19 unmodified lines
2020 #include <linux/nmi.h>
2121 #include <linux/kexec.h>
2222
23−int panic_timeout;
2423 int panic_on_oops;
2524 int tainted;
25+static int pause_on_oops;
26+static int pause_on_oops_flag;
27+static DEFINE_SPINLOCK(pause_on_oops_lock);
2628
29+int panic_timeout;
2730 EXPORT_SYMBOL(panic_timeout);
2831
2932 struct notifier_block *panic_notifier_list;
@@ -174,3 +177,95 @@ void add_taint(unsigned flag) · 144 unmodified lines
174177 tainted |= flag;
175178 }
176179 EXPORT_SYMBOL(add_taint);
180+
181+static int __init pause_on_oops_setup(char *str)
182+{
183+ pause_on_oops = simple_strtoul(str, NULL, 0);
184+ return 1;
185+}
186+__setup("pause_on_oops=", pause_on_oops_setup);
187+
188+static void spin_msec(int msecs)
189+{
190+ int i;
191+
192+ for (i = 0; i < msecs; i++) {
193+ touch_nmi_watchdog();
194+ mdelay(1);
195+ }
196+}
197+
198+/*
199+ * It just happens that oops_enter() and oops_exit() are identically
200+ * implemented...
201+ */
202+static void do_oops_enter_exit(void)
203+{
204+ unsigned long flags;
205+ static int spin_counter;
206+
207+ if (!pause_on_oops)
208+ return;
209+
210+ spin_lock_irqsave(&pause_on_oops_lock, flags);
211+ if (pause_on_oops_flag == 0) {
212+ /* This CPU may now print the oops message */
213+ pause_on_oops_flag = 1;
214+ } else {
215+ /* We need to stall this CPU */
216+ if (!spin_counter) {
217+ /* This CPU gets to do the counting */
218+ spin_counter = pause_on_oops;
219+ do {
220+ spin_unlock(&pause_on_oops_lock);
221+ spin_msec(MSEC_PER_SEC);
222+ spin_lock(&pause_on_oops_lock);
223+ } while (--spin_counter);
224+ pause_on_oops_flag = 0;
225+ } else {
226+ /* This CPU waits for a different one */
227+ while (spin_counter) {
228+ spin_unlock(&pause_on_oops_lock);
229+ spin_msec(1);
230+ spin_lock(&pause_on_oops_lock);
231+ }
232+ }
233+ }
234+ spin_unlock_irqrestore(&pause_on_oops_lock, flags);
235+}
236+
237+/*
238+ * Return true if the calling CPU is allowed to print oops-related info. This
239+ * is a bit racy..
240+ */
241+int oops_may_print(void)
242+{
243+ return pause_on_oops_flag == 0;
244+}
245+
246+/*
247+ * Called when the architecture enters its oops handler, before it prints
248+ * anything. If this is the first CPU to oops, and it's oopsing the first time
249+ * then let it proceed.
250+ *
251+ * This is all enabled by the pause_on_oops kernel boot option. We do all this
252+ * to ensure that oopses don't scroll off the screen. It has the side-effect
253+ * of preventing later-oopsing CPUs from mucking up the display, too.
254+ *
255+ * It turns out that the CPU which is allowed to print ends up pausing for the
256+ * right duration, whereas all the other CPUs pause for twice as long: once in
257+ * oops_enter(), once in oops_exit().
258+ */
259+void oops_enter(void)
260+{
261+ do_oops_enter_exit();
262+}
263+
264+/*
265+ * Called when the architecture exits its oops handler, after printing
266+ * everything.
267+ */
268+void oops_exit(void)
269+{
270+ do_oops_enter_exit();
271+}