Add an escape hatch for "NMI-safer" printing When debugging, I often want print a backtrace in NMI context. That's not particularly safe, and for the watchdog, hanging the machine is a bad idea. These dirty bools will let us skip the two locks *that I know about* from the printing code paths. Super brittle. Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
diff --git a/kern/arch/x86/console.c b/kern/arch/x86/console.c index 9c4bd5c..89099bf 100644 --- a/kern/arch/x86/console.c +++ b/kern/arch/x86/console.c
@@ -252,6 +252,7 @@ #define SCROLLING_CRT_SIZE (MAX_SCROLL_LENGTH * CRT_SIZE) static spinlock_t console_lock = SPINLOCK_INITIALIZER_IRQSAVE; +bool panic_skip_console_lock; static unsigned addr_6845; static uint16_t *crt_buf; @@ -655,7 +656,8 @@ { void logbuf(int c); - spin_lock_irqsave(&console_lock); + if (!panic_skip_console_lock) + spin_lock_irqsave(&console_lock); #ifndef CONFIG_SERIAL_IO serial_spam_char(c); @@ -664,7 +666,8 @@ cga_putc(c); logbuf(c); - spin_unlock_irqsave(&console_lock); + if (!panic_skip_console_lock) + spin_unlock_irqsave(&console_lock); } // `High'-level console I/O. Used by readline and cprintf.
diff --git a/kern/arch/x86/console.h b/kern/arch/x86/console.h index e2660f8..6cc5737 100644 --- a/kern/arch/x86/console.h +++ b/kern/arch/x86/console.h
@@ -26,6 +26,9 @@ SLIST_HEAD(cons_dev_slist, cons_dev); extern struct cons_dev_slist cdev_list; +/* Set this to turn off console locking. (debugging/panic/NMI) */ +extern bool panic_skip_console_lock; + void cons_init(void); /* Returns 0 on success, with the char in *data */ int cons_get_char(struct cons_dev *cdev, uint8_t *data);
diff --git a/kern/include/stdio.h b/kern/include/stdio.h index fd9cbaf..fc89b39 100644 --- a/kern/include/stdio.h +++ b/kern/include/stdio.h
@@ -35,6 +35,7 @@ void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_list); // lib/printf.c +extern bool panic_skip_print_lock; void print_lock(void); void print_unlock(void); void print_unlock_force(void);
diff --git a/kern/src/printf.c b/kern/src/printf.c index 7b415d9..3fd7ddb 100644 --- a/kern/src/printf.c +++ b/kern/src/printf.c
@@ -15,9 +15,13 @@ static spinlock_t output_lock = SPINLOCK_INITIALIZER_IRQSAVE; static int output_lock_holder = -1; /* core_id. */ static int output_lock_count; +bool panic_skip_print_lock; void print_lock(void) { + if (panic_skip_print_lock) + return; + if (output_lock_holder == core_id_early()) { output_lock_count++; return; @@ -30,6 +34,9 @@ void print_unlock(void) { + if (panic_skip_print_lock) + return; + output_lock_count--; if (output_lock_count) return;