linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Kay Sievers <kay@vrfy.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	Wu Fengguang <fengguang.wu@intel.com>,
	"Paul E. McKenney" <paulmck@us.ibm.com>
Subject: Re: [PATCH v3] printk: Have printk() never buffer its data
Date: Wed, 27 Jun 2012 22:00:14 -0700	[thread overview]
Message-ID: <1340859614.16533.66.camel@joe2Laptop> (raw)
In-Reply-To: <1340869133.876.10.camel@mop>

On Thu, 2012-06-28 at 09:38 +0200, Kay Sievers wrote:
> Here we share the continuation buffer with the console copy logic,
> and partial lines are always immediately flushed to the available
> consoles. They are still buffered internally to improve the
> readability and integrity of the messages and minimize the amount
> of needed record headers to store.

trivia:

> diff --git a/kernel/printk.c b/kernel/printk.c

> @@ -329,8 +337,13 @@ static void log_store(int facility, int level,
>  	msg->text_len = text_len;
>  	memcpy(log_dict(msg), dict, dict_len);
>  	msg->dict_len = dict_len;
> -	msg->level = (facility << 3) | (level & 7);
> -	msg->ts_nsec = local_clock();
> +	msg->facility = facility;
> +	msg->level = level & 7;

Doesn't need & 7

> +	msg->flags = flags & 0x1f;
> +	if (ts_nsec > 0)
> +		msg->ts_nsec = ts_nsec;
> +	else
> +		msg->ts_nsec = local_clock();

Why local_clock?  ts_nsec really can be 0.
[]

> @@ -1294,15 +1311,92 @@ static inline void printk_delay(void)
>  	}
>  }
>  
> +/*
> + * Continuation lines are buffered, and not committed to the record buffer
> + * until the line is complete, or a race forces it. The line fragments
> + * though, are printed immediately to the consoles to ensure everything has
> + * reached the console in case of a kernel crash.
> + */
> +static struct cont {
> +	char buf[LOG_LINE_MAX];
> +	size_t len;			/* length == 0 means unused buffer */
> +	size_t cons;			/* bytes written to console */
> +	struct task_struct *owner;	/* task of first print*/
> +	u64 ts_nsec;			/* time of first print */
> +	u8 level;			/* log level of first message */
> +	u8 facility;			/* log level of first message */
> +	bool flushed:1;			/* buffer sealed and committed */

bool flushed:1 seems unnecessary.
bool flushed seems more appropriate.

> +} cont;
> +
> +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);

Looks like you can still overrun cont.buf.



  parent reply	other threads:[~2012-06-28  5:00 UTC|newest]

Thread overview: 51+ 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
2012-06-29 11:18                             ` Steven Rostedt
2012-06-29 15:40                               ` Greg Kroah-Hartman
2012-06-28  5:00                         ` Joe Perches [this message]
2012-07-05  7:03                 ` Michael Neuling
2012-07-05  8:39                   ` Kay Sievers
2012-07-05  8:53                     ` Kay Sievers
2012-07-05 10:20                       ` Michael Neuling
2012-07-05 11:47                         ` Kay Sievers
2012-07-05 12:50                           ` Kay Sievers
2012-07-06  0:41                             ` Michael Neuling
2012-07-06  0:56                               ` Kay Sievers
2012-07-06  3:39                                 ` Michael Neuling
2012-07-06  3:47                                   ` Michael Neuling
2012-07-06 10:46                                     ` Kay Sievers
2012-07-06 15:12                                       ` Kay Sievers
2012-07-06 21:04                                         ` Michael Neuling
2012-07-08 17:55                                           ` Kay Sievers
2012-07-09 17:09                                             ` Greg Kroah-Hartman
2012-07-09 17:15                                               ` Joe Perches
2012-07-09 22:36                                               ` Michael Neuling
2012-07-09 21:42                                             ` Joe Perches
2012-07-09 22:10                                               ` Kay Sievers
2012-07-09 22:29                                                 ` Joe Perches
2012-07-09 22:40                                                   ` Kay Sievers
2012-07-09 23:32                                                     ` 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=1340859614.16533.66.camel@joe2Laptop \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=fengguang.wu@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).