From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752217AbdIARcW (ORCPT ); Fri, 1 Sep 2017 13:32:22 -0400 Received: from smtprelay0211.hostedemail.com ([216.40.44.211]:54077 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751863AbdIARcV (ORCPT ); Fri, 1 Sep 2017 13:32:21 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2196:2199:2200:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:4385:4605:5007:6119:7875:8603:8660:10004:10400:10450:10455:10848:11026:11232:11658:11914:12043:12296:12438:12681:12740:12760:12895:13095:13148:13230:13439:14181:14659:14721:19904:19999:21080:21088:21433:21434:21627:30029:30034:30046:30054:30056:30060:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: berry04_13cd365aab906 X-Filterd-Recvd-Size: 4489 Message-ID: <1504287133.2361.11.camel@perches.com> Subject: Re: printk: what is going on with additional newlines? From: Joe Perches To: Sergey Senozhatsky , Steven Rostedt Cc: Sergey Senozhatsky , Linus Torvalds , Pavel Machek , Petr Mladek , Jan Kara , Andrew Morton , Jiri Slaby , Andreas Mohr , Tetsuo Handa , Linux Kernel Mailing List Date: Fri, 01 Sep 2017 10:32:13 -0700 In-Reply-To: <20170901131656.GA468@tigerII.localdomain> References: <20170828090521.GA25025@amd> <20170828102830.GA403@jagdpanzerIV.localdomain> <20170828122109.GA532@jagdpanzerIV.localdomain> <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> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2017-09-01 at 22:19 +0900, Sergey Senozhatsky wrote: > On (08/29/17 21:10), Steven Rostedt wrote: > [..] > > > could do. for a single continuation line printk("%.*s", s.len, s.buffer) > > > this will work perfectly fine. for a more general case - backtraces, dumps, > > > etc. - this requires some tweaks. > > > > We could simply add a seq_buf_printk() that is implemented in the printk > > proper, to parse the seq_buf buffer properly, and add the timestamps and > > such. > > so I quickly cooked the first version. like really quickly. just to > check if this is what people might like/use. > > RFC. > > so wondering if this will suffice. the name is somewhat hideous -- prbuf(), > wanted to keep it short and somehow aligned with pr_foo(). Yes, it's a poor name. At least keep using a pr_ prefix. > the patch also defines a number of prbuf_err()/prbuf_cont() macros that > call __prbuf_write() -- I don't want people to invoke __prbuf_write() > directly, because we need KERN_FOO prefix for stored messages and people > tend to forget to provide one. > prbuf_init() function inits the seq_buf buffer. it takes size and GFP > mask, just to permit prbuf usage from different contexts. if we fail > to kmalloc() the buffer, then __prbuf_write() does direct printk(). I think there's relatively little value in multiple line output. It seems like buffering for buffering's sake. Just keep it to a single line and simple. > a usage example: > > > struct seq_buf s; > > prbuf_init(&s, 256, GFP_KERNEL); > > prbuf_err(&s, "Opps at %lu\n", _RET_IP_); > prbuf_info(&s, "Start of cont line"); > prbuf_cont(&s, " foo "); > prbuf_cont(&s, " bar "); > prbuf_cont(&s, " status: %s\n", "done"); > > ret = 0; > while (ret++ < 10) > prbuf_err(&s, "%x\n", ret); > > prbuf_flush(&s); > prbuf_free(&s); > > > this will store everything in conseq logbuf entries. if the buffer > was too small, we print overflow message. > > any comments? [] > diff --git a/include/linux/printk.h b/include/linux/printk.h [] > @@ -277,6 +288,29 @@ static inline void printk_safe_flush(void) > static inline void printk_safe_flush_on_panic(void) > { > } > + > +struct seq_buf; > + > +static inline > +int prbuf_init(struct seq_buf *s, size_t size, gfp_t flags) > +{ > + return 0; > +} > + > +static inlin __printf(2, 3) __cold uncompiled > +static int __prbuf_write(struct seq_buf *s, const char *fmt, ...) inline > +int prbuf_init(struct seq_buf *s, size_t size, gfp_t flags) > +{ > + char *b; > + > + b = kmalloc(size, flags); > + seq_buf_init(s, b, size); > + return !!b; > +} Most of the time, this buffer should be on the stack and not be malloc'd.