Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1733396

Re: printk: what is going on with additional newlines?

Path csiph.com!news.redatomik.org!aioe.org!bofh.it!news.nic.it!robomod
From Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Newsgroups linux.kernel
Subject Re: printk: what is going on with additional newlines?
Date Sun, 17 Sep 2017 08:40:02 +0200
Message-ID <uqBpg-4m9-11@gated-at.bofh.it> (permalink)
References <ujZPH-1HW-7@gated-at.bofh.it> <uk0sp-1Us-1@gated-at.bofh.it> <uk0Vr-2px-1@gated-at.bofh.it> <uk157-2sK-7@gated-at.bofh.it> <uk1eN-2wZ-3@gated-at.bofh.it> <umiEx-106-3@gated-at.bofh.it> <umiXU-1lB-13@gated-at.bofh.it> <uml9o-2zD-7@gated-at.bofh.it> <ummoN-3iq-1@gated-at.bofh.it> <umDpE-6TS-15@gated-at.bofh.it>
X-Original-To Petr Mladek <pmladek@suse.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1Xd1OBlLj1wZJ7s/DkhwUIZJlsKsbNp9G6TYFVDCaNI=; b=JStovxXESj1QgdytpvcK4O00gLaItCL0AD8bD+aFRluzmFmoZTfAoebtpA4bV38w3C JE5GKzO0ExqJ9A5lZstIeAKrRrStxzNGRdDY6YM8AeHQOBya6FEmHave2oTPNusKTaRd SlqOuuoDaE795eezFbPnFFMuCnPrL52fS9Khx01npl3UWZQnx4yRUKvTi9RD2QRGLAmO 0uORq8SyDb+cdeEz1S5NlxXdHpbnHDZSjXYMnOGzvj/+VNGI/W6mamUYsPHifjWk1XNz 9M2zjWnl7ajqjJ/CUCULLVVrwWQlip4J2ciD5tDqWPJP5+EILdJdd0+BNdELVmeEB6f+ bxUg==
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1Xd1OBlLj1wZJ7s/DkhwUIZJlsKsbNp9G6TYFVDCaNI=; b=Q28Rs2T9lKDt+ibXF8nqZwDZn9NGqQx0Lkf+JQcXzrDniNJicBhiA3Hp0JUsRzXdDb lZkXebHiQL2lu3Uh6EvFhEaMle61t1Hw4Z5w8CttzjOVyqAaSM6PDOY3v9MZW8nYeEOD r0pD80c39AW5LHwdSlCWxtT9CDMheqPRChBec43e4gPq6pROYA6famz3wc7xXkGibW1Q 26zTJmePeXPQq9BRIOQNTjaW5PfG9I1H/ImD6pIHdP1/NdiR6YffOAJcfoqT5ThRIWwK PoXiBP5FCXS6Hb12Zz4nQiRabs/T/00C0dDoMrMnGPKut7L0i7bBFtNBelkKYv/FvWJ6 Dqmw==
X-Gm-Message-State AHPjjUhSdUM2BjMLW8Vbaw2+G4W2EHr6MBiNuvKpnAPXmr3QRHaCUAea WJKdhGQjRHPG2Q==
X-Google-SMTP-Source ADKCNb7MhL2SvxZr3cVwXVasJkRCguhQ21xdtOnRzLdAjQ0HU0eLrIYZiW1M7u3UpRK0yg4gYI2fAg==
X-Received by 10.98.19.203 with SMTP id 72mr29231680pft.124.1505629856918; Sat, 16 Sep 2017 23:30:56 -0700 (PDT)
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
User-Agent Mutt/1.9.0 (2017-09-02)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 116
Organization linux.* mail to news gateway
X-Original-Cc Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Joe Perches <joe@perches.com>, Steven Rostedt <rostedt@goodmis.org>, Linus Torvalds <torvalds@linux-foundation.org>, Pavel Machek <pavel@ucw.cz>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Jan Kara <jack@suse.cz>, Andrew Morton <akpm@linux-foundation.org>, Jiri Slaby <jslaby@suse.com>, Andreas Mohr <andi@lisas.de>, Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
X-Original-Date Sun, 17 Sep 2017 15:26:08 +0900
X-Original-Message-ID <20170917062608.GA512@tigerII.localdomain>
X-Original-References <20170829211046.74644c8a@gandalf.local.home> <1504057959.2786.4.camel@perches.com> <20170830022528.GA17968@jagdpanzerIV.localdomain> <1504060296.2786.8.camel@perches.com> <20170830024703.GA17175@jagdpanzerIV.localdomain> <20170905094452.GE8741@pathway.suse.cz> <20170905095900.GC2066@jagdpanzerIV.localdomain> <20170905122154.GG8741@pathway.suse.cz> <20170905134228.GE521@jagdpanzerIV.localdomain> <20170906075554.GI8741@pathway.suse.cz>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1733396

Show key headers only | View raw


On (09/06/17 09:55), Petr Mladek wrote:
[..]
> > but I'm not super eager to have printk-safe based buffering.
> > that's why I never posted a patch set. this approach has its
> > limitations.
> 
> Ah, I am happy to read this. From the previous mails,
> I got the feeling that you were eager to go this way.

naaah, not really :)

[..]
> > I prepend every line with the CPU number that has printk()-ed it.
> > and that's helpful because one can grep and filter out messages
> > from other CPUs. it's quite OK thing to have given that messages
> > can be really mixed sometimes.
> > 
> > so adding extra information to `struct printk_log' could be helpful.
> > I think we had this discussion before and you didn't want to change
> > the size of `struct printk_log' because that might break gdb/crash/etc
> > user space tools. has it changed?
> 
> Yup, there should be a serious reason to change 'struct printk_log'.
> I am not sure if this is the case. But I am sure that there will
> be need to change the structure sooner or later.
> 
> Anyway, it seems that we will need to update all the tools
> for the different time stamps, see
> https://lkml.kernel.org/r/1504613201-23868-1-git-send-email-prarit@redhat.com
> Then we will be more clever how painful it is.
> 
> 
> > may be we can #ifdef CONFIG_PRINTK_ABC them.

so... I think we don't have to update 'struct printk_log'. we can store
that "extended data" at the beginning of every message, right after the
prefix.

NOTE:

below is a very-very quick hack. so quick, that it has known problems.
- the code does not handle !PREFIX messages (like printk("foo")).
  but I guess we can come up with a solution here.
- and printk_vscnprintf() should have that CONFIG_PRINTK_ABC,
  which is missing in the code below.


dmesg looks like this

[    3.338129] [ext: kworker/3:2/3] input: ETPS/2 Elantech Touchpad as /devices/platform/i8042/serio1/input/input7
[    3.340653] [ext: systemd-udevd/0] mousedev: PS/2 mouse device common for all mice
[    5.554184] [ext: swapper/0/0] random: crng init done
[   33.410639] [ext: wpa_supplicant/6] IPv6: ADDRCONF(NETDEV_UP): wlp2s0: link is not ready
[   36.812187] [ext: kworker/u16:5/1] wlp2s0: associated
[   36.812231] [ext: kworker/1:1/1] IPv6: ADDRCONF(NETDEV_CHANGE): wlp2s0: link becomes ready



if we will ever decide to add any sort of "extended data" to every
message, then may be we can do it this way?

---

 kernel/printk/printk.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index a64c52c19b03..d7380cb70fb5 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1936,6 +1936,35 @@ static size_t log_output(int facility, int level, enum log_flags lflags, const c
 	return log_store(facility, level, lflags, 0, dict, dictlen, text, text_len);
 }
 
+static size_t printk_vscnprintf(char *text, size_t text_sz,
+				const char *fmt, va_list args)
+{
+	size_t printed = 0;
+	bool do_prefix = false;
+
+	if (fmt[0] == KERN_SOH_ASCII) {
+		text[0] = fmt[0];
+		text[1] = fmt[1];
+
+		if (fmt[1] != 'c')
+			do_prefix = true;
+
+		fmt += 2;
+		printed = 2;
+	}
+
+	if (do_prefix) {
+		printed += snprintf(text + printed,
+				    text_sz - printed,
+				    "[ext: %s/%d] ",
+				    current->comm,
+				    smp_processor_id());
+	}
+
+	printed += vscnprintf(text + printed, text_sz - printed, fmt, args);
+	return printed;
+}
+
 asmlinkage int vprintk_emit(int facility, int level,
 			    const char *dict, size_t dictlen,
 			    const char *fmt, va_list args)
@@ -1962,7 +1991,7 @@ asmlinkage int vprintk_emit(int facility, int level,
 	 * The printf needs to come first; we need the syslog
 	 * prefix which might be passed-in as a parameter.
 	 */
-	text_len = vscnprintf(text, sizeof(textbuf), fmt, args);
+	text_len = printk_vscnprintf(text, sizeof(textbuf), fmt, args);
 
 	/* mark and strip a trailing newline */
 	if (text_len && text[text_len-1] == '\n') {
 

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-09-17 08:40 +0200
  Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky@gmail.com> - 2017-09-17 11:40 +0200
  Re: printk: what is going on with additional newlines? Linus Torvalds <torvalds@linux-foundation.org> - 2017-09-17 17:40 +0200
    Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-09-18 02:50 +0200
      Re: printk: what is going on with additional newlines? Joe Perches <joe@perches.com> - 2017-09-18 04:30 +0200
        Re: printk: what is going on with additional newlines? Joe Perches <joe@perches.com> - 2017-09-18 04:50 +0200
          Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-09-18 05:00 +0200
            Re: printk: what is going on with additional newlines? Joe Perches <joe@perches.com> - 2017-09-18 05:10 +0200
              Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-09-18 06:50 +0200
        Re: printk: what is going on with additional newlines? Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> - 2017-09-18 04:50 +0200

csiph-web