All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Kay Sievers <kay@vrfy.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Wu Fengguang <fengguang.wu@intel.com>,
	Joe Perches <joe@perches.com>,
	"Paul E. McKenney" <paulmck@us.ibm.com>
Subject: Re: [PATCH v3] printk: Have printk() never buffer its data
Date: Fri, 29 Jun 2012 01:30:27 -0400	[thread overview]
Message-ID: <20120629053027.GA9841@kroah.com> (raw)
In-Reply-To: <1340852129.16702.73.camel@gandalf.stny.rr.com>

On Wed, Jun 27, 2012 at 10:55:29PM -0400, Steven Rostedt wrote:
> On Thu, 2012-06-28 at 09:38 +0200, Kay Sievers wrote:
> 
> > +static void cont_flush(void)
> > +{
> > +	if (cont.flushed)
> > +		return;
> > +	if (cont.len == 0)
> > +		return;
> > +
> > +	log_store(cont.facility, cont.level, LOG_NOCONS, cont.ts_nsec,
> > +		  NULL, 0, cont.buf, cont.len);
> > +
> > +	cont.flushed = true;
> > +}
> > +
> > +static bool cont_add(int facility, int level, const char *text, size_t len)
> > +{
> > +	if (cont.len && cont.flushed)
> > +		return false;
> > +
> > +	if (cont.len + len > sizeof(cont.buf)) {
> > +		cont_flush();
> > +		return false;
> > +	}
> > +
> > +	if (!cont.len) {
> > +		cont.facility = facility;
> > +		cont.level = level;
> > +		cont.owner = current;
> > +		cont.ts_nsec = local_clock();
> > +		cont.cons = 0;
> > +		cont.flushed = false;
> > +	}
> > +
> > +	memcpy(cont.buf + cont.len, text, len);
> > +	cont.len += len;
> > +	return true;
> > +}
> > +
> > +static size_t cont_print_text(char *text, size_t size)
> > +{
> > +	size_t textlen = 0;
> > +	size_t len;
> > +
> > +	if (cont.cons == 0) {
> > +		textlen += print_time(cont.ts_nsec, text);
> > +		size -= textlen;
> > +	}
> > +
> > +	len = cont.len - cont.cons;
> > +	if (len > 0) {
> > +		if (len+1 > size)
> > +			len = size-1;
> > +		memcpy(text + textlen, cont.buf + cont.cons, len);
> > +		textlen += len;
> > +		cont.cons = cont.len;
> > +	}
> > +
> > +	if (cont.flushed) {
> > +		text[textlen++] = '\n';
> > +		/* got everything, release buffer */
> > +		cont.len = 0;
> > +	}
> > +	return textlen;
> > +}
> > +
> >  asmlinkage int vprintk_emit(int facility, int level,
> >  			    const char *dict, size_t dictlen,
> >  			    const char *fmt, va_list args)
> >  {
> >  	static int recursion_bug;
> > -	static char cont_buf[LOG_LINE_MAX];
> > -	static size_t cont_len;
> > -	static int cont_level;
> > -	static struct task_struct *cont_task;
> >  	static char textbuf[LOG_LINE_MAX];
> >  	char *text = textbuf;
> >  	size_t text_len;
> > @@ -1348,7 +1442,8 @@ asmlinkage int vprintk_emit(int facility, int level,
> >  		recursion_bug = 0;
> >  		printed_len += strlen(recursion_msg);
> >  		/* emit KERN_CRIT message */
> > -		log_store(0, 2, NULL, 0, recursion_msg, printed_len);
> > +		log_store(0, 2, LOG_DEFAULT, 0,
> > +			  NULL, 0, recursion_msg, printed_len);
> >  	}
> >  
> >  	/*
> > @@ -1386,55 +1481,38 @@ asmlinkage int vprintk_emit(int facility, int level,
> >  	}
> >  
> >  	if (!newline) {
> > -		if (cont_len && (prefix || cont_task != current)) {
> > -			/*
> > -			 * Flush earlier buffer, which is either from a
> > -			 * different thread, or when we got a new prefix.
> > -			 */
> > -			log_store(facility, cont_level, NULL, 0, cont_buf, cont_len);
> > -			cont_len = 0;
> > -		}
> > -
> > -		if (!cont_len) {
> > -			cont_level = level;
> > -			cont_task = current;
> > -		}
> > +		/*
> > +		 * Flush the conflicting buffer. An earlier newline was missing,
> > +		 * or another task also prints continuation lines.
> > +		 */
> > +		if (cont.len && (prefix || cont.owner != current))
> > +			cont_flush();
> >  
> > -		/* buffer or append to earlier buffer from the same thread */
> > -		if (cont_len + text_len > sizeof(cont_buf))
> > -			text_len = sizeof(cont_buf) - cont_len;
> > -		memcpy(cont_buf + cont_len, text, text_len);
> > -		cont_len += text_len;
> > +		/* buffer line if possible, otherwise store it right away */
> > +		if (!cont_add(facility, level, text, text_len))
> > +			log_store(facility, level, LOG_DEFAULT, 0,
> > +				  dict, dictlen, text, text_len);
> >  	} else {
> > -		if (cont_len && cont_task == current) {
> > -			if (prefix) {
> > -				/*
> > -				 * New prefix from the same thread; flush. We
> > -				 * either got no earlier newline, or we race
> > -				 * with an interrupt.
> > -				 */
> > -				log_store(facility, cont_level,
> > -					  NULL, 0, cont_buf, cont_len);
> > -				cont_len = 0;
> > -			}
> > +		bool stored = false;
> >  
> > -			/* append to the earlier buffer and flush */
> > -			if (cont_len + text_len > sizeof(cont_buf))
> > -				text_len = sizeof(cont_buf) - cont_len;
> > -			memcpy(cont_buf + cont_len, text, text_len);
> > -			cont_len += text_len;
> > -			log_store(facility, cont_level,
> > -				  NULL, 0, cont_buf, cont_len);
> > -			cont_len = 0;
> > -			cont_task = NULL;
> > -			printed_len = cont_len;
> > -		} else {
> > -			/* ordinary single and terminated line */
> > -			log_store(facility, level,
> > -				  dict, dictlen, text, text_len);
> > -			printed_len = text_len;
> > +		/*
> > +		 * Flush the conflicting buffer. An earlier newline was missing,
> > +		 * or we race with a continuation line from an interrupt.
> > +		 */
> > +		if (cont.len && prefix && cont.owner == current)
> > +			cont_flush();
> > +
> > +		/* Merge with our buffer if possible; flush it in any case */
> > +		if (cont.len && cont.owner == current) {
> > +			stored = cont_add(facility, level, text, text_len);
> > +			cont_flush();
> >  		}
> 
> 
> I wonder if it would be better to do the following for the above two
> ifs:
> 
> 	if (cont.len && cont.owner == current) {
> 		if (!prefix)
> 			stored = cont_add(facility, level, text, text_len);
> 		cont_flush();
> 	}
> 
> If the prefix was true, then the cont.flush would be set when cont_add()
> is called, and the first thing that cont_add() does:
> 
> 	if (cont.len && cont.flushed)
> 		return false;
> 
> which would always be true (returning false) if prefix was set.
> 
> And the second cont_flush() is a nop due to it doing:
> 
> 	if (cont.flushed)
> 		return;

It might be "better", and this would be a nice optimization, but is it
needed right now?  In other words, I'd like to get this patch into
linux-next soon to get testing to get to Linus before 3.5-final comes
out, don't you?

thanks,

greg k-h

  reply	other threads:[~2012-06-29  5:30 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-25 19:05 [PATCH v3] printk: Have printk() never buffer its data Steven Rostedt
2012-06-25 22:07 ` Andrew Morton
2012-06-25 23:55   ` Greg Kroah-Hartman
2012-06-26  0:01     ` Linus Torvalds
2012-06-26  0:23       ` Greg Kroah-Hartman
2012-06-26  0:40         ` Linus Torvalds
2012-06-26  0:56           ` Kay Sievers
2012-06-26  1:40             ` Linus Torvalds
2012-06-26 16:07               ` Kay Sievers
2012-06-26 16:30                 ` Joe Perches
2012-06-26 16:58                 ` Greg Kroah-Hartman
2012-06-26 17:00                   ` Kay Sievers
2012-06-26 17:02                     ` Greg Kroah-Hartman
2012-06-26 18:34                     ` Greg Kroah-Hartman
2012-06-26 18:38                       ` Greg Kroah-Hartman
2012-06-26 18:48                         ` Greg Kroah-Hartman
2012-06-27 15:13                 ` Steven Rostedt
2012-06-27 15:18                   ` Steven Rostedt
2012-06-27 15:26                     ` Kay Sievers
2012-06-28  7:38                       ` Kay Sievers
2012-06-28  1:48                         ` Greg Kroah-Hartman
2012-06-28  1:54                           ` Steven Rostedt
2012-06-28  2:55                         ` Steven Rostedt
2012-06-29  5:30                           ` Greg Kroah-Hartman [this message]
2012-06-29 11:18                             ` Steven Rostedt
2012-06-29 15:40                               ` Greg Kroah-Hartman
2012-06-28  5:00                         ` Joe Perches
2012-07-05  7:03                 ` Michael Neuling
2012-07-05  7:03                   ` Michael Neuling
2012-07-05  8:39                   ` Kay Sievers
2012-07-05  8:39                     ` Kay Sievers
2012-07-05  8:53                     ` Kay Sievers
2012-07-05  8:53                       ` Kay Sievers
2012-07-05 10:20                       ` Michael Neuling
2012-07-05 10:20                         ` Michael Neuling
2012-07-05 11:47                         ` Kay Sievers
2012-07-05 11:47                           ` Kay Sievers
2012-07-05 12:50                           ` Kay Sievers
2012-07-05 12:50                             ` Kay Sievers
2012-07-06  0:41                             ` Michael Neuling
2012-07-06  0:41                               ` Michael Neuling
2012-07-06  0:56                               ` Kay Sievers
2012-07-06  0:56                                 ` Kay Sievers
2012-07-06  3:39                                 ` Michael Neuling
2012-07-06  3:39                                   ` Michael Neuling
2012-07-06  3:47                                   ` Michael Neuling
2012-07-06  3:47                                     ` Michael Neuling
2012-07-06 10:46                                     ` Kay Sievers
2012-07-06 10:46                                       ` Kay Sievers
2012-07-06 15:12                                       ` Kay Sievers
2012-07-06 15:12                                         ` Kay Sievers
2012-07-06 21:04                                         ` Michael Neuling
2012-07-06 21:04                                           ` Michael Neuling
2012-07-08 17:55                                           ` Kay Sievers
2012-07-08 17:55                                             ` Kay Sievers
2012-07-09 17:09                                             ` Greg Kroah-Hartman
2012-07-09 17:09                                               ` Greg Kroah-Hartman
2012-07-09 17:15                                               ` Joe Perches
2012-07-09 17:15                                                 ` Joe Perches
2012-07-09 22:36                                               ` Michael Neuling
2012-07-09 22:36                                                 ` Michael Neuling
2012-07-09 21:42                                             ` Joe Perches
2012-07-09 21:42                                               ` Joe Perches
2012-07-09 22:10                                               ` Kay Sievers
2012-07-09 22:10                                                 ` Kay Sievers
2012-07-09 22:29                                                 ` Joe Perches
2012-07-09 22:29                                                   ` Joe Perches
2012-07-09 22:40                                                   ` Kay Sievers
2012-07-09 22:40                                                     ` Kay Sievers
2012-07-09 23:32                                                     ` Joe Perches
2012-07-09 23:32                                                       ` Joe Perches
2012-07-09 23:41                                                       ` Joe Perches
2012-07-09 23:41                                                         ` Joe Perches
2012-06-26  0:18   ` Joe Perches

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=20120629053027.GA9841@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=joe@perches.com \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulmck@us.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.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.