From f717642e336564e1ee6e240dcfe20451242a2931 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Wed, 19 Sep 2012 14:50:37 +0200 Subject: [PATCH 245/365] printk: Make rt aware X-NVConfidentiality: public Drop the lock before calling the console driver and do not disable interrupts while printing to a serial console. Change-Id: I88d565b2b1b7a631cc02d97074681f5c2e9cd9a4 Signed-off-by: Thomas Gleixner --- kernel/printk/printk.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 68b7e06..32c45a5 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1585,6 +1585,7 @@ static void call_console_drivers(int level, if (!console_drivers) return; + migrate_disable(); for_each_console(con) { if (exclusive_console && con != exclusive_console) continue; @@ -1600,6 +1601,7 @@ static void call_console_drivers(int level, else con->write(con, text, len); } + migrate_enable(); } int printk_delay_msec __read_mostly; @@ -1895,12 +1897,22 @@ asmlinkage int vprintk_emit(int facility, int level, /* If called from the scheduler, we can not call up(). */ if (!in_sched) { + int may_trylock = 1; + +#ifdef CONFIG_PREEMPT_RT_FULL + /* + * we can't take a sleeping lock with IRQs or preeption disabled + * so we can't print in these contexts + */ + if (!(preempt_count() == 0 && !irqs_disabled())) + may_trylock = 0; +#endif /* * Try to acquire and then immediately release the console * semaphore. The release will print out buffers and wake up * /dev/kmsg and syslog() users. */ - if (console_trylock()) + if (may_trylock && console_trylock()) console_unlock(); } @@ -2286,11 +2298,16 @@ static void console_cont_flush(char *text, size_t size) goto out; len = cont_print_text(text, size); +#ifdef CONFIG_PREEMPT_RT_FULL + raw_spin_unlock_irqrestore(&logbuf_lock, flags); + call_console_drivers(cont.level, NULL, 0, text, len); +#else raw_spin_unlock(&logbuf_lock); stop_critical_timings(); call_console_drivers(cont.level, NULL, 0, text, len); start_critical_timings(); local_irq_restore(flags); +#endif return; out: raw_spin_unlock_irqrestore(&logbuf_lock, flags); @@ -2415,6 +2432,10 @@ void console_unlock(void) } console_idx = log_next(console_idx); console_seq++; +#ifdef CONFIG_PREEMPT_RT_FULL + raw_spin_unlock_irqrestore(&logbuf_lock, flags); + call_console_drivers(level, ext_text, ext_len, text, len); +#else raw_spin_unlock(&logbuf_lock); stop_critical_timings(); /* don't trace print latency */ @@ -2422,6 +2443,7 @@ void console_unlock(void) start_critical_timings(); printk_safe_exit_irqrestore(flags); +#endif if (do_cond_resched) cond_resched(); } -- 2.28.0