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

From: Byungchul Park
Date: Mon Mar 21 2016 - 04:47:59 EST


On Mon, Mar 21, 2016 at 05:07:51PM +0900, Byungchul Park wrote:
> On Mon, Mar 21, 2016 at 04:35:07PM +0900, Sergey Senozhatsky wrote:
> > On (03/21/16 09:56), Byungchul Park wrote:
> > > > > > + if (!sync_print) {
> > > > > > + if (in_sched) {
> > > > > > + /*
> > > > > > + * @in_sched messages may come too early, when we don't
> > > > > > + * yet have @printk_kthread. We can't print deferred
> > > > > > + * messages directly, because this may deadlock, route
> > > > > > + * them via IRQ context.
> > > > > > + */
> > > > > > + __this_cpu_or(printk_pending,
> > > > > > + PRINTK_PENDING_OUTPUT);
> > > > > > + irq_work_queue(this_cpu_ptr(&wake_up_klogd_work));
> > > > > > + } else if (printk_kthread && !in_panic) {
> > > > > > + /* Offload printing to a schedulable context. */
> > > > > > + wake_up_process(printk_kthread);
> > > > >
> > > > > It will not print the "lockup suspected" message at all, for e.g. rq->lock,
> > > > > p->pi_lock and any locks which are used within wake_up_process().
> > > >
> > > > this will switch to old SYNC printk() mode should such a lockup ever
> > > > happen, which is a giant advantage over any other implementation; doing
> > > > wake_up_process() within the 'we can detect recursive printk() here'
> > > > gives us better control.
> > > >
> > > > why
> > > > printk()->IRQ->wake_up_process()->spin_dump()->printk()->IRQ->wake_up_process()->spin_dump()->printk()->IRQ...
> > > > is better?
> > >
> > > What is IRQ?
> >
> > this is how printk() can print the messages in async mode apart from
> > direct and wake_up_process() in vprintk_emit().
>
> Do you mean IRQ work?
>
> Is there any reason why you don't put the wake_up_process() out of the
> critical section with my suggestion, even though it can solve the infinite
> recuresion you worried about?

Just to be sure, whether you take my suggestion or not is not important.
I just suggested it in this thread since it can solve what you worried
about. That's all. I can post it in another thread though. Why don't you
consider it so that yours don't miss any printk message? Do you think there
are any problems in my suggestion?

>
> >
> > -ss
> >
> > > > > Furtheremore, any printk() within wake_up_process() cannot work at all, as
> > > > > well.
> > > >
> > > > there is printk_deferred() which has LOGLEVEL_SCHED and which must be used
> > > > in sched functions.
> > >
> > > It would be good for all scheduler code to use the printk_deferred() as you
> > > said, but it's not true yet.
> > >
> > > >
> > > > -ss
> > >