Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1680548 > unrolled thread

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

Started bySteven Rostedt <rostedt@goodmis.org>
First post2017-07-03 21:40 +0200
Last post2017-07-04 09:00 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [RFC][PATCHv3 2/5] printk: introduce printing kernel thread Steven Rostedt <rostedt@goodmis.org> - 2017-07-03 21:40 +0200
    Re: [RFC][PATCHv3 2/5] printk: introduce printing kernel thread Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-07-04 07:30 +0200
      Re: [RFC][PATCHv3 2/5] printk: introduce printing kernel thread Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-07-04 09:00 +0200

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

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-07-03 21:40 +0200
SubjectRe: [RFC][PATCHv3 2/5] printk: introduce printing kernel thread
Message-ID<tZfmq-5Q9-35@gated-at.bofh.it>
On Mon, 3 Jul 2017 20:11:30 +0900
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> 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);
>  	}
>  }
>  

[toc] | [next] | [standalone]


#1680660

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2017-07-04 07:30 +0200
Message-ID<tZozn-3Ky-3@gated-at.bofh.it>
In reply to#1680548
On (07/03/17 15:34), Steven Rostedt 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.

yes.

> And what happens if the printk caller happens to preempt the one
> doing the writes to consoles?

in short - we just burn CPU cycles. that case is broken.

that's mostly the reason behind PRINTK_FLOOD_DEFAULT_DELAY being quite
small.

one can simply do

	console_lock();
	printk();
	printk();
	....
	printk();
	console_unlock();

and trigger a useless throttling. a needed one in general case,
but useless in the given circumstances.

not sure if we can properly throttle printk in all of the cases.
we know that console_sem is locked, but we don't know what for.
is CPU that owns the console_sem is now in console_unlock() or
somewhere in fbcon, or anywhere else. we probably need not to
throttle printk() if we know that console_sem is already locked
by this_cpu and we simply call printk either from IRQ that
preempted console_unlock() on this_cpu or recursive printk from
console_unlock()... and so on.

	-ss

[toc] | [prev] | [next] | [standalone]


#1680695

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2017-07-04 09:00 +0200
Message-ID<tZpYt-4Iv-7@gated-at.bofh.it>
In reply to#1680660
On (07/04/17 14:26), Sergey Senozhatsky wrote:
[..]
> not sure if we can properly throttle printk in all of the cases.
> we know that console_sem is locked, but we don't know what for.
> is CPU that owns the console_sem is now in console_unlock() or
> somewhere in fbcon, or anywhere else. we probably need not to
> throttle printk() if we know that console_sem is already locked
> by this_cpu and we simply call printk either from IRQ that
> preempted console_unlock() on this_cpu or recursive printk from
> console_unlock()... and so on.

which is hard to do, given that console_unlock() can schedule with
console_sem locked. so CPU number won't do the trick. unless we will
forbid preemption in console_unlock()... we sort of need to do it.

	-ss

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web