All of lore.kernel.org
 help / color / mirror / Atom feed
From: Byungchul Park <byungchul.park@lge.com>
To: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Cc: Petr Mladek <pmladek@suse.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jan Kara <jack@suse.com>, Tejun Heo <tj@kernel.org>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	linux-kernel@vger.kernel.org, Jan Kara <jack@suse.cz>
Subject: Re: [RFC][PATCH v4 1/2] printk: Make printk() completely async
Date: Wed, 16 Mar 2016 11:10:49 +0900	[thread overview]
Message-ID: <20160316021049.GI5220@X58A-UD3R> (raw)
In-Reply-To: <20160316020115.GA3217@swordfish>

On Wed, Mar 16, 2016 at 11:01:15AM +0900, Sergey Senozhatsky wrote:
> Hello Petr,
> 
> On (03/15/16 16:58), Petr Mladek wrote:
> [..]
> > > +static bool __read_mostly printk_sync = !IS_ENABLED(CONFIG_SMP);
> > > +module_param_named(synchronous, printk_sync, bool, S_IRUGO | S_IWUSR);
> > 
> > If we make it writtable, we also need to handle the situation that
> > it gets disabled at runtime. It means to make sure that the kthread
> > will be running event printk_sync was set during the boot.
> 
> yes, I just thought this morning that may be disabling 'write' here would
> be ok.
> 
> > What about this?
> > 
> > int need_flush_console;
> > 
> > 	while(1) {
> > 		set_current_state(TASK_INTERRUPTIBLE);
> > 		if (!need_flush_console)
> > 			schedule();

                else // This shoule be here, IMHO. Hm?

> > 		__set_current_state(TASK_RUNNING);
> > 
> > 		need_flush_console =  false;
> > 
> > > +		console_lock();
> > > +		console_unlock();
> > > +	}
> 
> much better, indeed.
> I assume `need_flush_console' is primarily for avoiding schedule() cost?
> not that it closes the race window 100%, it can be false at the time we
> check it, and become true by the time we schedule(). TASK_INTERRUPTIBLE
> should prevent lost wake_up() case, AFAIK.
> 
> > Also I wonder if we need some special handling of the system freezing
> > but I do not thing so.
> 
> hm, I don't think so either.
> 
> > > +	printk_thread = kthread_run(printing_func, NULL, "printk");
> > > +	BUG_ON(IS_ERR(printk_thread));
> > 
> > I would prefer to force the synchronous mode instead.
> 
> ok, no strong opinion here, I thought that if the system can't create
> a kthread in late_initcall(), then it probably doesn't have many chances
> to survive anyway.
> 
> > > + * Delayed printk version, for scheduler-internal messages:
> > 
> > This is not longer related to sheduler only.
> 
> this has changed. KTHREAD/IRQ  split is not needed anymore, please
> see below.
> 
> > BTW: I suggest to move this whole section in a separate patch.
> > It will be more clear what has changed for the async printk
> > and what stays for the deferred printk.
> 
> hm, sounds good.
> 
> 
> > 	if (pending & PRINTK_PENDING_CONSOLE_OUTPUT) {
> > 		if (printk_sync || !printk_kthread) {
> > 			/* If trylock fails, someone else is doing the printing */
> > 			if (console_trylock())
> > 				console_unlock();
> > 		} else {
> > 			wake_up_process(printk_kthread);
> > 		}
> > 
> > 	if (pending & PRINTK_PENDING_KLOGD_WAKEUP)
> > 		wake_up_interruptible(&log_wait);
> 
> yes, agree. this is what I have here:
> http://marc.info/?l=linux-kernel&m=145805101825604
> 
> > > +	bool in_panic = console_loglevel == CONSOLE_LOGLEVEL_MOTORMOUTH;
> > > +	bool sync_print = printk_sync;
> > 
> > I would force the global printk_sync if we are in_panic
> > 
> > 	if (in_panic)
> > 		printk_sync = true;
> 
> can add, yes.
> 
> > > -	/* If called from the scheduler, we can not call up(). */
> > > -	if (!in_sched) {
> > > +	if (sync_print) {
> > >  		lockdep_off();
> > 
> > I wonder if it might be much easier with If we used only the two
> > PRINTK_PENDING flags and force global printk_sync when in panic.
> 
> two PENDING flags stuff was my bad. (I replied here
> http://marc.info/?l=linux-kernel&m=145805101825604)
> 
> in short, my intention was to move it out of that part of vprintk_emit() that
> can recurse, but cannot detect the recursion. wake_up()/wake_up_process()
> add spin_locks/etc., which add possibilities of
>         vprint_emit()->spin_lock()->spin_dump()->vprintk_emit()->...
> that will not be handled by vprintk_emit() recursion detection code. but
> I guess I simply want to move this under the logbuf lock section after all,
> so printk recursion detection will have better chances to help us out.
> 
> > Sigh, it would be great to rename also wake_up_klogd_work and
> > wake_up_klogd_work_func(). They are not only about klogd.
> > Well, this should be separate patch as well because it
> > was even before.
> 
> hm, yes, as a separate patch later I think.
> 
> > I still to thing about possible races. Especially, when checking
> > printk_kthread and printk_sync.
> 
> hm, I don't think we risk anything here. if CPU saw an 'old' (NULL) @printk_kthread
> then it just would do direct printk. once it's !NULL, we can wake it up.
> is your concern here that `pointer = VALUE' can be !atomic?
> 
> > I hope that some of the above suggestions makes sense. vprintk_emit()
> > is crazy already now. I feel motivated to do not make it worse ;-)
> 
> thanks for review.
> 
> 	-ss

  reply	other threads:[~2016-03-16  2:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 14:13 [RFC][PATCH v4 0/2] printk: Make printk() completely async Sergey Senozhatsky
2016-03-14 14:13 ` [RFC][PATCH v4 1/2] " Sergey Senozhatsky
2016-03-15 10:03   ` Jan Kara
2016-03-15 14:07     ` Sergey Senozhatsky
2016-03-16  5:39       ` Byungchul Park
2016-03-16  6:58         ` Sergey Senozhatsky
2016-03-16  7:30           ` Byungchul Park
2016-03-16  7:56             ` Sergey Senozhatsky
2016-03-16 10:34               ` Byungchul Park
2016-03-17  0:34                 ` Sergey Senozhatsky
2016-03-18  5:49                   ` Byungchul Park
2016-03-18  7:11                     ` Sergey Senozhatsky
2016-03-18  8:23                       ` byungchul.park
2016-03-16  7:00         ` Byungchul Park
2016-03-16  7:07           ` Sergey Senozhatsky
2016-03-15 15:58   ` Petr Mladek
2016-03-16  2:01     ` Sergey Senozhatsky
2016-03-16  2:10       ` Byungchul Park [this message]
2016-03-16  2:31         ` Sergey Senozhatsky
2016-03-14 14:13 ` [RFC][PATCH v4 2/2] printk: Skip messages on oops Sergey Senozhatsky
2016-03-17 10:56   ` Sergey Senozhatsky
2016-04-23 19:36 ` [RFC][PATCH v4 0/2] printk: Make printk() completely async Pavel Machek
2016-04-24  5:03   ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160316021049.GI5220@X58A-UD3R \
    --to=byungchul.park@lge.com \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.com \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=pmladek@suse.com \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.