From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751376AbdH2Rwe (ORCPT ); Tue, 29 Aug 2017 13:52:34 -0400 Received: from mail-io0-f172.google.com ([209.85.223.172]:37676 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751219AbdH2Rwd (ORCPT ); Tue, 29 Aug 2017 13:52:33 -0400 MIME-Version: 1.0 In-Reply-To: <20170829173314.GA623@tigerII.localdomain> References: <20170815025625.1977-1-sergey.senozhatsky@gmail.com> <20170828090521.GA25025@amd> <20170828102830.GA403@jagdpanzerIV.localdomain> <20170828122109.GA532@jagdpanzerIV.localdomain> <20170828124634.GD492@amd> <20170829134048.GA437@jagdpanzerIV.localdomain> <20170829173314.GA623@tigerII.localdomain> From: Linus Torvalds Date: Tue, 29 Aug 2017 10:52:32 -0700 X-Google-Sender-Auth: 8nWOR3LaegExQyfaoqRj1f3eZIo Message-ID: Subject: Re: printk: what is going on with additional newlines? To: Sergey Senozhatsky Cc: Sergey Senozhatsky , Pavel Machek , Petr Mladek , Steven Rostedt , Jan Kara , Andrew Morton , Jiri Slaby , Andreas Mohr , Tetsuo Handa , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 29, 2017 at 10:33 AM, Sergey Senozhatsky wrote: > > ok. that's something several people asked for -- some sort of buffered > printk mode; but people don't want to use a buffer allocated on the stack > (or kmalloc-ed, etc.) to do sprintf() on it and then feed it to printk("%s"), > because this adds some extra cost: I don't like the notion of per-cpu buffers either, because then you suddenly get atomicity issues, and you really don't want that. My preference as a user is actually to just have a dynamically re-sizable buffer (that's pretty much what I've done in *every* single user space project I've had in the last decade), but because some users might have atomicity issues I do suspect that we should just use a stack buffer. And then perhaps say that the buffer size has to be capped at 80 characters. Because if you're printing more than 80 characters and expecting it all to fit on a line, you're doing something else wrong anyway. And hide it not as a explicit "char buffer[80]]" allocation, but as a "struct line_buffer" or similar, so that (a) people don't get the line size wrong (b) the buffering code can add a few fields for length etc in there too Introduce a few helper functions for it: init_line_buffer(&buf); print_line(&buf, fmt, args); vprint_line(&buf, fmt, vararg); finish_line(&buf); or whatever, and it sounds like it should be pretty easy to use. Linus