On Wed 2016-03-23 09:37:25, Sergey Senozhatsky wrote:
> Hello Petr,
> 
> On (03/22/16 14:11), Petr Mladek wrote:
> > > +  * Set printing_func() sleep condition early, under the @logbuf_lock.
> > > +  * So printing kthread (if RUNNING) will go to console_lock() and spin
> > > +  * on @logbuf_lock.
> > > +  */
> > > + if (!printk_sync)
> > > +         need_flush_console = true;
> > 
> > We set this variable for each call and also when printk_kthread is
> > NULL or when sync_printk is false.
> 
> hm, yes. (printk_kthread && !need_flush_console) makes more sense.
> so we it doesn't get re-dirty if already set.

This does not solve the problem mentioned below. There still might be
extra cycle if the kthread is inside console_unclock().

> > We migth want to clear it also from console_unlock(). I think that
> > a good place would be in the check:
> > 
> >     raw_spin_lock(&logbuf_lock);
> >     retry = console_seq != log_next_seq;
> >     raw_spin_unlock_irqrestore(&logbuf_lock, flags);
> 
> hm, what's wrong with clearing it in printk_kthread  printing function?

I though about the following scenario:

CPU0                                    CPU1

vprintk_emit()
  need_flush_console = true;

  wake_up_process(printk_thread)

                                        printing_func()

                                          need_flush_console = false;

                                          console_lock()
                                          console_unlock()

vprintk_emit()

  need_flush_console = true;

                                            # flush 1st message
                                            # flush 2nd message

                                            if (!need_flush_console)
                                              # fails and continues

                                            console_lock()
                                            console_unlock()

                                            # nope because 2nd
                                            # message already flushed

                                          if (!need_flush_console)
                                             schedule()

                                             # did one unnecessary
                                             # cycle to get asleep


Best Regards,
Petr

PS: If you touch the code, please rename printing_func() to
printk_kthread_func() to make it more clear what it does.
I am sorry for nitpicking.

Reply via email to