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


Groups > linux.kernel > #1572135 > unrolled thread

Re: [PATCH] printk: use console_trylock() in console_cpu_notify()

Started bySergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
First post2017-02-02 05:00 +0100
Last post2017-02-02 18:00 +0100
Articles 2 — 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: [PATCH] printk: use console_trylock() in console_cpu_notify() Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-02-02 05:00 +0100
    Re: [PATCH] printk: use console_trylock() in console_cpu_notify() Petr Mladek <pmladek@suse.com> - 2017-02-02 18:00 +0100

#1572135 — Re: [PATCH] printk: use console_trylock() in console_cpu_notify()

FromSergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
Date2017-02-02 05:00 +0100
SubjectRe: [PATCH] printk: use console_trylock() in console_cpu_notify()
Message-ID<t6gIW-6QB-5@gated-at.bofh.it>
Hello,

thanks for taking a look, Petr.

On (01/25/17 16:02), Petr Mladek wrote:
[..]
> > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > ---
> >  kernel/printk/printk.c | 11 ++++++-----
> >  1 file changed, 6 insertions(+), 5 deletions(-)
> > 
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index 7180088cbb23..772eb16436ce 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -2028,15 +2028,16 @@ void resume_console(void)
> >   * @cpu: unused
> >   *
> >   * If printk() is called from a CPU that is not online yet, the messages
> > - * will be spooled but will not show up on the console.  This function is
> > - * called when a new CPU comes online (or fails to come up), and ensures
> > - * that any such output gets printed.
> > + * will be printed on the console only if there are CON_ANYTIME consoles.
> > + * This function is called when a new CPU comes online (or fails to come
> > + * up) or goes offline.
> >   */
> >  static int console_cpu_notify(unsigned int cpu)
> >  {
> >  	if (!cpuhp_tasks_frozen) {
> > -		console_lock();
> > -		console_unlock();
> > +		/* If trylock fails, someone else is doing the printing */
> > +		if (console_trylock())
> > +			console_unlock();
> >  	}
> >  	return 0;
> >  }
> 
> Rather theoretically, the other owner of console_sem might be
> on a CPU that is going online/offline and will refuse to print
> the messages.

hm, if console_sem is locked by CPU that is going offline
then console_cpu_notify() will deadlock in console_lock().
if I understood your point correctly.

> All in all. The change looks fine to me because it most likely
> improves the performance[1] and does not affect the reliability
> that much.

yeah, I think so.

> But we should revisit this notifier after adding the async printk
> patchset. It will allow to defer the console handling to
> another CPU and work even for going CPUs.

ok, may be.

> I add some people working on CPU hotplug into CC to get their
> opinion.

thanks.

> [1] https://lkml.kernel.org/r/20170119120744.GB435@tigerII.localdomain

	-ss

[toc] | [next] | [standalone]


#1572517

FromPetr Mladek <pmladek@suse.com>
Date2017-02-02 18:00 +0100
Message-ID<t6sTL-6vB-11@gated-at.bofh.it>
In reply to#1572135
On Thu 2017-02-02 12:53:47, Sergey Senozhatsky wrote:
> Hello,
> 
> thanks for taking a look, Petr.
> 
> On (01/25/17 16:02), Petr Mladek wrote:
> [..]
> > > Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> > > ---
> > >  kernel/printk/printk.c | 11 ++++++-----
> > >  1 file changed, 6 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > > index 7180088cbb23..772eb16436ce 100644
> > > --- a/kernel/printk/printk.c
> > > +++ b/kernel/printk/printk.c
> > > @@ -2028,15 +2028,16 @@ void resume_console(void)
> > >   * @cpu: unused
> > >   *
> > >   * If printk() is called from a CPU that is not online yet, the messages
> > > - * will be spooled but will not show up on the console.  This function is
> > > - * called when a new CPU comes online (or fails to come up), and ensures
> > > - * that any such output gets printed.
> > > + * will be printed on the console only if there are CON_ANYTIME consoles.
> > > + * This function is called when a new CPU comes online (or fails to come
> > > + * up) or goes offline.
> > >   */
> > >  static int console_cpu_notify(unsigned int cpu)
> > >  {
> > >  	if (!cpuhp_tasks_frozen) {
> > > -		console_lock();
> > > -		console_unlock();
> > > +		/* If trylock fails, someone else is doing the printing */
> > > +		if (console_trylock())
> > > +			console_unlock();
> > >  	}
> > >  	return 0;
> > >  }
> > 
> > Rather theoretically, the other owner of console_sem might be
> > on a CPU that is going online/offline and will refuse to print
> > the messages.
> 
> hm, if console_sem is locked by CPU that is going offline
> then console_cpu_notify() will deadlock in console_lock().
> if I understood your point correctly.

No, it will not deadlock. I guess that it will just do nothing.

console_unlock() would probably return at the beginning because
can_use_console() would return false because cpu_online()
would return false.

I am not sure about it. It is not easy for me to find
in which cpu_online() state the notifiers are called.

If the console really is not usable, we should rather
defer the console work to another CPU.

Best Regards,
Petr

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web