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


Groups > linux.kernel > #1370447 > unrolled thread

Re: [RFC][PATCH v8 1/2] printk: Make printk() completely async

Started byJan Kara <jack@suse.cz>
First post2016-04-04 10:40 +0200
Last post2016-04-04 18:10 +0200
Articles 3 — 3 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][PATCH v8 1/2] printk: Make printk() completely async Jan Kara <jack@suse.cz> - 2016-04-04 10:40 +0200
    Re: [RFC][PATCH v8 1/2] printk: Make printk() completely async Petr Mladek <pmladek@suse.com> - 2016-04-04 11:50 +0200
      Re: [RFC][PATCH v8 1/2] printk: Make printk() completely async Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2016-04-04 18:10 +0200

#1370447 — Re: [RFC][PATCH v8 1/2] printk: Make printk() completely async

FromJan Kara <jack@suse.cz>
Date2016-04-04 10:40 +0200
SubjectRe: [RFC][PATCH v8 1/2] printk: Make printk() completely async
Message-ID<rk8db-mW-5@gated-at.bofh.it>
On Thu 31-03-16 13:12:29, Petr Mladek wrote:
> >  #if defined CONFIG_PRINTK
> > +static int printk_kthread_func(void *data)
> > +{
> > +	while (1) {
> > +		set_current_state(TASK_INTERRUPTIBLE);
> > +		if (!need_flush_console)
> > +			schedule();
> > +
> > +		__set_current_state(TASK_RUNNING);
> 
> 
> We still must do here:
> 
> 		need_flush_console = false;
> 
> Othrerwise, we might start "busy" cycling. cosole_unlock()
> sometimes returns earlly, e.g. when console_suspended is set
> or !can_use_console() returns true.
> 
> Sigh, the handling of "need_flush_console" is a bit strange.
> Part of the logic depends on logbuf_lock and the other part
> must be lockless.

Frankly, I think we are overcomplicating this. What we really need to detect
in printk_kthread_func() is whether someone appended something to the console
since we woken up. Sure, console_unlock() may have already printed that
and we would unnecessarily make one more loop over console_lock() and
console_unlock() but who cares...

So what about having printk_kthread_func() like:

	while (1) {
		set_current_state(TASK_INTERRUPTIBLE);
		if (!need_flush_console)
			schedule();
		__set_current_state(TASK_RUNNING);
		need_flush_console = false;
		console_lock();
		console_unlock();
	}

In vprintk_emit() we do:

	if (!in_panic && printk_kthread) {
		/* Offload printing to a schedulable context. */
		need_flush_console = true;
		wake_up_process(printk_kthread);
	} else {
		...

This guarantees that after message was appended to the buffer in
vprintk_emit(), the message got either printed by console_unlock() or
printk_kthread is in TASK_RUNNING state and will call console_unlock() once
scheduled. It also guarantees that printk_kthread_func() won't loop forever
when there's nothing to print. And that is all we need...

I think the simplicity of this is worth the possible extra loops in
printk_kthread_func().

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

[toc] | [next] | [standalone]


#1370511

FromPetr Mladek <pmladek@suse.com>
Date2016-04-04 11:50 +0200
Message-ID<rk9iV-155-11@gated-at.bofh.it>
In reply to#1370447
On Thu 2016-03-31 13:52:50, Jan Kara wrote:
> On Thu 31-03-16 13:12:29, Petr Mladek wrote:
> > >  #if defined CONFIG_PRINTK
> > > +static int printk_kthread_func(void *data)
> > > +{
> > > +	while (1) {
> > > +		set_current_state(TASK_INTERRUPTIBLE);
> > > +		if (!need_flush_console)
> > > +			schedule();
> > > +
> > > +		__set_current_state(TASK_RUNNING);
> > 
> > 
> > We still must do here:
> > 
> > 		need_flush_console = false;
> > 
> > Othrerwise, we might start "busy" cycling. cosole_unlock()
> > sometimes returns earlly, e.g. when console_suspended is set
> > or !can_use_console() returns true.
> > 
> > Sigh, the handling of "need_flush_console" is a bit strange.
> > Part of the logic depends on logbuf_lock and the other part
> > must be lockless.
> 
> Frankly, I think we are overcomplicating this. What we really need to detect
> in printk_kthread_func() is whether someone appended something to the console
> since we woken up. Sure, console_unlock() may have already printed that
> and we would unnecessarily make one more loop over console_lock() and
> console_unlock() but who cares...
> 
> So what about having printk_kthread_func() like:
> 
> 	while (1) {
> 		set_current_state(TASK_INTERRUPTIBLE);
> 		if (!need_flush_console)
> 			schedule();
> 		__set_current_state(TASK_RUNNING);
> 		need_flush_console = false;
> 		console_lock();
> 		console_unlock();
> 	}
> 
> In vprintk_emit() we do:
> 
> 	if (!in_panic && printk_kthread) {
> 		/* Offload printing to a schedulable context. */
> 		need_flush_console = true;
> 		wake_up_process(printk_kthread);
> 	} else {
> 		...
> 
> This guarantees that after message was appended to the buffer in
> vprintk_emit(), the message got either printed by console_unlock() or
> printk_kthread is in TASK_RUNNING state and will call console_unlock() once
> scheduled. It also guarantees that printk_kthread_func() won't loop forever
> when there's nothing to print. And that is all we need...
> 
> I think the simplicity of this is worth the possible extra loops in
> printk_kthread_func().

I do not have strong opinion about this. I agree that the simplicity
of your proposal is nice. You are much more experienced kernel
developer. If you say that the potential extra loop is fine, I am
fine with it as well :-)

Best Regards,
Petr

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


#1370722

FromSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Date2016-04-04 18:10 +0200
Message-ID<rkfeG-5Fz-11@gated-at.bofh.it>
In reply to#1370511
Hello,

On (04/04/16 11:41), Petr Mladek wrote:
[..]
> > So what about having printk_kthread_func() like:
> > 
> > 	while (1) {
> > 		set_current_state(TASK_INTERRUPTIBLE);
> > 		if (!need_flush_console)
> > 			schedule();
> > 		__set_current_state(TASK_RUNNING);
> > 		need_flush_console = false;
> > 		console_lock();
> > 		console_unlock();
> > 	}
> > 
> > In vprintk_emit() we do:
> > 
> > 	if (!in_panic && printk_kthread) {
> > 		/* Offload printing to a schedulable context. */
> > 		need_flush_console = true;
> > 		wake_up_process(printk_kthread);
> > 	} else {
> > 		...
> > 
> > This guarantees that after message was appended to the buffer in
> > vprintk_emit(), the message got either printed by console_unlock() or
> > printk_kthread is in TASK_RUNNING state and will call console_unlock() once
> > scheduled. It also guarantees that printk_kthread_func() won't loop forever
> > when there's nothing to print. And that is all we need...
> > 
> > I think the simplicity of this is worth the possible extra loops in
> > printk_kthread_func().
> 
> I do not have strong opinion about this. I agree that the simplicity
> of your proposal is nice. You are much more experienced kernel
> developer. If you say that the potential extra loop is fine, I am
> fine with it as well :-)
> 

works for me, re-sent.
the patch is even smaller now, and we almost have nothing else to
cut off from it :)

	-ss

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web