From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751988AbdIEOy7 (ORCPT ); Tue, 5 Sep 2017 10:54:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:46194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751316AbdIEOy6 (ORCPT ); Tue, 5 Sep 2017 10:54:58 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 375E721BB9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=goodmis.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=rostedt@goodmis.org Date: Tue, 5 Sep 2017 10:54:54 -0400 From: Steven Rostedt To: Sergey Senozhatsky Cc: Linus Torvalds , Joe Perches , Sergey Senozhatsky , Pavel Machek , Petr Mladek , Jan Kara , Andrew Morton , Jiri Slaby , Andreas Mohr , Tetsuo Handa , Linux Kernel Mailing List Subject: Re: printk: what is going on with additional newlines? Message-ID: <20170905105454.29160c5e@gandalf.local.home> In-Reply-To: <20170904052246.GB28534@jagdpanzerIV.localdomain> References: <20170828124634.GD492@amd> <20170829134048.GA437@jagdpanzerIV.localdomain> <20170829195013.5048dc42@gandalf.local.home> <20170830010348.GB654@jagdpanzerIV.localdomain> <20170829211046.74644c8a@gandalf.local.home> <20170901131656.GA468@tigerII.localdomain> <1504287133.2361.11.camel@perches.com> <20170904052246.GB28534@jagdpanzerIV.localdomain> X-Mailer: Claws Mail 3.14.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 4 Sep 2017 14:22:46 +0900 Sergey Senozhatsky 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