Messages in this thread Patch in this message | | | Date | Tue, 22 Jan 2002 15:42:47 -0800 | From | Andrew Morton <> | Subject | Re: Console output for debugging |
| |
Serguei Miridonov wrote: > > Q: Is there any function in the kernel which I can call > safely from a module to print debug message on the console > screen? > > I don't want to use printk for some reasons. One of them is > that I want messages to appear on the screen immediately, > even from interrupt processing routines. Another is to be > able to see messages until the system freezes completely in > case of software or hardware bug. >
printk does all this, usually. It is synchronous, so when it returns to your code, the text is on the screen.
The only exception to this is when you perform a printk from within an interrupt handler *while* printk itself is executing in non-interrupt context. When this rare situation occurs, the text is buffered, to be emitted by the non-interrupt code before it returns to its caller.
If the printk-within-printk buffering is a problem for you, (which I doubt) then you could disable interrupts while running printk. Something like this:
--- linux-2.4.18-pre6/kernel/printk.c Tue Jan 22 12:38:31 2002 +++ linux-akpm/kernel/printk.c Tue Jan 22 15:40:57 2002 @@ -412,6 +412,10 @@ asmlinkage int printk(const char *fmt, . char *p; static char printk_buf[1024]; static int log_level_unknown = 1; + static spinlock_t printk_lock = SPIN_LOCK_UNLOCKED; + unsigned long xflags; + + spin_lock_irqsave(&printk_lock, xflags); if (oops_in_progress) { /* If a crash is occurring, make sure we can't deadlock */ @@ -471,6 +475,7 @@ asmlinkage int printk(const char *fmt, . spin_unlock_irqrestore(&logbuf_lock, flags); } out: + spin_unlock_irqrestore(&printk_lock, xflags); return printed_len; } EXPORT_SYMBOL(printk); - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |