[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20170905105454.29160c5e@gandalf.local.home>
Date: Tue, 5 Sep 2017 10:54:54 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Sergey Senozhatsky <sergey.senozhatsky.work@...il.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Joe Perches <joe@...ches.com>,
Sergey Senozhatsky <sergey.senozhatsky@...il.com>,
Pavel Machek <pavel@....cz>, Petr Mladek <pmladek@...e.com>,
Jan Kara <jack@...e.cz>,
Andrew Morton <akpm@...ux-foundation.org>,
Jiri Slaby <jslaby@...e.com>, Andreas Mohr <andi@...as.de>,
Tetsuo Handa <penguin-kernel@...ove.sakura.ne.jp>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: Re: printk: what is going on with additional newlines?
On Mon, 4 Sep 2017 14:22:46 +0900
Sergey Senozhatsky <sergey.senozhatsky.work@...il.com> wrote:
> like I said in another email, printk-safe buffer
> is per-CPU and is also used for actual printk-safe, hence it must be
> used with local IRQs disabled when we "borrow" the buffer for pr_line
> (disabled preemption is not enough due to possible IRQ printk-safe
> print out). this can be a bit annoying.
You can do what I did with trace_printk(). I have a buffer per context.
Then you only need to use preempt_disable() to do the print. That is,
trace_printk() has 4 buffers:
1. Normal context
2. softirq context
3. irq context
4. NMI context
It determines which context it is in, disables preemption, and uses the
corresponding buffer. This way I don't need to worry about being
preempted by an interrupt or NMI.
Grant it, it does make the memory needed 4x bigger.
I have an array of 4 buffers, and the following code:
static char *get_trace_buf(void)
{
struct trace_buffer_struct *buffer = this_cpu_ptr(trace_percpu_buffer);
if (!buffer || buffer->nesting >= 4)
return NULL;
return &buffer->buffer[buffer->nesting++][0];
}
Hmm, I probably need to add a "barrier()" before the return, or use a
this_cpu_inc() on nesting. As long as the nesting variable is updated
before the return of the buffer being used, then everything is fine.
Because we have:
static void put_trace_buf(void)
{
this_cpu_dec(trace_percpu_buffer->nesting);
}
And anything that preempts this call will have returned it back to its
original state before returning.
-- Steve
Powered by blists - more mailing lists