Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

printk, vt, fbcon: Remove console_conditional_schedule()

do_con_write(), fbcon_redraw.*() invoke console_conditional_schedule()
which is a conditional scheduling point based on printk's internal
variables console_may_schedule. It may only be used if the console lock
is acquired for instance via console_lock() or console_trylock().

Prinkt sets the internal variable to 1 (and allows to schedule)
if the console lock has been acquired via console_lock(). The trylock
does not allow it.

The console_conditional_schedule() invocation in do_con_write() is
invoked shortly before console_unlock().
The console_conditional_schedule() invocation in fbcon_redraw.*()
original from fbcon_scroll() / vt's con_scroll() which originate from a
line feed.

In console_unlock() the variable is set to 0 (forbids to schedule) and
it tries to schedule while making progress printing. This is brand new
compared to when console_conditional_schedule() was added in v2.4.9.11.

In v2.6.38-rc3, console_unlock() (started its existence) iterated over
all consoles and flushed them with disabled interrupts. A scheduling
attempt here was not possible, it relied that a long print scheduled
before console_unlock().

Since commit 8d91f8b15361d ("printk: do cond_resched() between lines
while outputting to consoles"), which appeared in v4.5-rc1,
console_unlock() attempts to schedule if it was allowed to schedule
while during console_lock(). Each record is idealy one line so after
every line feed.

This console_conditional_schedule() is also only relevant on
PREEMPT_NONE and PREEMPT_VOLUNTARY builds. In other configurations
cond_resched() becomes a nop and has no impact.

I'm bringing this all up just proof that it is not required anymore. It
becomes a problem on a PREEMPT_RT build with debug code enabled because
that might_sleep() in cond_resched() remains and triggers a warnings.
This is due to

legacy_kthread_func-> console_flush_one_record -> vt_console_print-> lf
-> con_scroll -> fbcon_scroll

and vt_console_print() acquires a spinlock_t which does not allow a
voluntary schedule. There is no need to fb_scroll() to schedule since
console_flush_one_record() attempts to schedule after each line.
!PREEMPT_RT is not affected because the legacy printing thread is only
enabled on PREEMPT_RT builds.

Therefore I suggest to remove console_conditional_schedule().

Cc: Simona Vetter <simona@ffwll.ch>
Cc: Helge Deller <deller@gmx.de>
Cc: linux-fbdev@vger.kernel.org
Cc: dri-devel@lists.freedesktop.org
Fixes: 5f53ca3ff83b4 ("printk: Implement legacy printer kthread for PREEMPT_RT")
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Petr Mladek <pmladek@suse.com> # from printk() POV
Signed-off-by: Helge Deller <deller@gmx.de>

authored by

Sebastian Andrzej Siewior and committed by
Helge Deller
8e9bf8b9 4a16b380

-24
-1
drivers/tty/vt/vt.c
··· 3230 3230 goto rescan_last_byte; 3231 3231 } 3232 3232 con_flush(vc, &draw); 3233 - console_conditional_schedule(); 3234 3233 notify_update(vc); 3235 3234 3236 3235 return n;
-6
drivers/video/fbdev/core/fbcon.c
··· 1608 1608 start = s; 1609 1609 } 1610 1610 } 1611 - console_conditional_schedule(); 1612 1611 s++; 1613 1612 } while (s < le); 1614 1613 if (s > start) 1615 1614 fbcon_putcs(vc, start, s - start, dy, x); 1616 - console_conditional_schedule(); 1617 1615 dy++; 1618 1616 } 1619 1617 } ··· 1647 1649 } 1648 1650 1649 1651 scr_writew(c, d); 1650 - console_conditional_schedule(); 1651 1652 s++; 1652 1653 d++; 1653 1654 } while (s < le); 1654 1655 if (s > start) 1655 1656 par->bitops->bmove(vc, info, line + ycount, x, line, x, 1, 1656 1657 s - start); 1657 - console_conditional_schedule(); 1658 1658 if (ycount > 0) 1659 1659 line++; 1660 1660 else { ··· 1700 1704 } 1701 1705 } 1702 1706 scr_writew(c, d); 1703 - console_conditional_schedule(); 1704 1707 s++; 1705 1708 d++; 1706 1709 } while (s < le); 1707 1710 if (s > start) 1708 1711 fbcon_putcs(vc, start, s - start, line, x); 1709 - console_conditional_schedule(); 1710 1712 if (offset > 0) 1711 1713 line++; 1712 1714 else {
-1
include/linux/console.h
··· 697 697 extern void console_lock(void); 698 698 extern int console_trylock(void); 699 699 extern void console_unlock(void); 700 - extern void console_conditional_schedule(void); 701 700 extern void console_unblank(void); 702 701 extern void console_flush_on_panic(enum con_flush_mode mode); 703 702 extern struct tty_driver *console_device(int *);
-16
kernel/printk/printk.c
··· 3416 3416 } 3417 3417 EXPORT_SYMBOL(console_unlock); 3418 3418 3419 - /** 3420 - * console_conditional_schedule - yield the CPU if required 3421 - * 3422 - * If the console code is currently allowed to sleep, and 3423 - * if this CPU should yield the CPU to another task, do 3424 - * so here. 3425 - * 3426 - * Must be called within console_lock();. 3427 - */ 3428 - void __sched console_conditional_schedule(void) 3429 - { 3430 - if (console_may_schedule) 3431 - cond_resched(); 3432 - } 3433 - EXPORT_SYMBOL(console_conditional_schedule); 3434 - 3435 3419 void console_unblank(void) 3436 3420 { 3437 3421 bool found_unblank = false;