Messages in this thread Patch in this message | | | From | John Ogness <> | Subject | Re: [patch RFC 28/29] printk: Provide functions for atomic write enforcement | Date | Tue, 27 Sep 2022 17:07:01 +0206 |
| |
Below is a fix that was used for the LPC2022 demo to avoid unnecessarily performing the console_lock/console_unlock dance.
Add a new global boolean @have_bkl_console to be able to quickly identify if any legacy (bkl) consoles are registered. If there are none, the console_lock/console_unlock stuff can be skipped. The following patch does this and can be applied on top.
--- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1830,6 +1830,7 @@ static struct lockdep_map console_owner_dep_map = { static DEFINE_RAW_SPINLOCK(console_owner_lock); static struct task_struct *console_owner; static bool console_waiter; +static bool have_bkl_console; /** * console_lock_spinning_enable - mark beginning of code where another @@ -2285,7 +2286,7 @@ asmlinkage int vprintk_emit(int facility, int level, cons_atomic_flush(); /* If called from the scheduler, we can not call up(). */ - if (!in_sched) { + if (!in_sched && have_bkl_console) { /* * Try to acquire and then immediately release the console * semaphore. The release will print out buffers. With the @@ -2575,7 +2576,7 @@ void resume_console(void) */ static int console_cpu_notify(unsigned int cpu) { - if (!cpuhp_tasks_frozen) { + if (!cpuhp_tasks_frozen && have_bkl_console) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); @@ -3023,6 +3024,9 @@ void console_unblank(void) { struct console *c; + if (!have_bkl_console) + return; + /* * console_unblank can no longer be called in interrupt context unless * oops_in_progress is set to 1.. @@ -3052,6 +3056,9 @@ void console_unblank(void) */ void console_flush_on_panic(enum con_flush_mode mode) { + if (!have_bkl_console) + return; + /* * If someone else is holding the console lock, trylock will fail * and may_schedule may be set. Ignore and proceed to unlock so @@ -3311,6 +3318,10 @@ void register_console(struct console *newcon) /* Initialize the nobkl data in @newcon */ cons_nobkl_init(newcon); + /* Has a legacy (BKL) console registered? */ + if (!(newcon->flags & CON_NO_BKL)) + have_bkl_console = true; + /* * Put this console in the list and keep the referred driver at the * head of the list. @@ -3603,7 +3613,7 @@ static void wake_up_klogd_work_func(struct irq_work *irq_work) { int pending = this_cpu_xchg(printk_pending, 0); - if (pending & PRINTK_PENDING_OUTPUT) { + if (have_bkl_console && (pending & PRINTK_PENDING_OUTPUT)) { /* If trylock fails, someone else is doing the printing */ if (console_trylock()) console_unlock(); John Ogness
| |