Re: [RFC][PATCHv3 2/5] printk: introduce printing kernel thread

From: Steven Rostedt
Date: Mon Jul 03 2017 - 15:34:38 EST


On Mon, 3 Jul 2017 20:11:30 +0900
Sergey Senozhatsky <sergey.senozhatsky.work@xxxxxxxxx> wrote:

> +#define PRINTK_FLOOD_DEFAULT_DELAY 10
> +
> int printk_delay_msec __read_mostly;
>
> +static inline void __printk_delay(int m)
> +{
> + while (m--) {
> + mdelay(1);
> + touch_nmi_watchdog();
> + }
> +}
> +
> static inline void printk_delay(void)
> {
> - if (unlikely(printk_delay_msec)) {
> - int m = printk_delay_msec;
> + unsigned long flags;
> + u64 console_seen = 0, console_to_see;
>
> - while (m--) {
> - mdelay(1);
> - touch_nmi_watchdog();
> - }
> + if (printk_delay_msec) {
> + __printk_delay(printk_delay_msec);
> + return;
> + }
> +

This had better be an option, and not default. And what happens if the
printk caller happens to preempt the one doing the writes to consoles?

-- Steve

> + /*
> + * Check if consoles are far behind the loguf head and
> + * throttle printk() callers if so.
> + */
> + logbuf_lock_irqsave(flags);
> + if (console_seq > log_first_seq)
> + console_seen = console_seq - log_first_seq;
> + console_to_see = log_next_seq - console_seq;
> + logbuf_unlock_irqrestore(flags);
> +
> + if (console_seen < 4 * console_to_see) {
> + if (printk_delay_msec)
> + __printk_delay(printk_delay_msec);
> + else
> + __printk_delay(PRINTK_FLOOD_DEFAULT_DELAY);
> }
> }
>