From: Petr Mladek <pmladek@suse.com>
To: Breno Leitao <leitao@debian.org>
Cc: John Ogness <john.ogness@linutronix.de>,
osandov@osandov.com, mpdesouza@suse.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, asantostc@gmail.com, efault@gmx.de,
gustavold@gmail.com, calvin@wbinvd.org, jv@jvosburgh.net,
kernel-team@meta.com, Simon Horman <horms@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
rostedt@goodmis.org
Subject: Re: [PATCH net-next 0/2] net: netconsole: convert to NBCON console infrastructure
Date: Fri, 16 Jan 2026 16:53:48 +0100 [thread overview]
Message-ID: <aWpfDKd64DLX32Hl@pathway.suse.cz> (raw)
In-Reply-To: <aWpekVlhRpD4CaDI@pathway.suse.cz>
On Fri 2026-01-16 16:51:49, Petr Mladek wrote:
> On Mon 2026-01-12 04:44:42, Breno Leitao wrote:
> > On Mon, Jan 12, 2026 at 02:55:06AM -0800, Breno Leitao wrote:
> >
> > printk: Add execution context (task name/CPU) to printk_info
> >
> >
> > --- a/kernel/printk/printk_ringbuffer.h
> > +++ b/kernel/printk/printk_ringbuffer.h
> > @@ -23,6 +24,10 @@ struct printk_info {
> > u8 flags:5; /* internal record flags */
> > u8 level:3; /* syslog level */
> > u32 caller_id; /* thread id or processor id */
> > +#ifdef CONFIG_PRINTK_EXECUTION_CTX
> > + char msg_comm[TASK_COMM_LEN]; /* name of the task that generated the message */
> > + int msg_cpu; /* CPU where the message was generated */
>
> I would allow to store the caller_id complement so that we
> always store both cpu and pid.
>
> Also I would remove the "msg_" prefix. It is not bad. But it is
> inconsistent with the existing "caller_" prefix. And the meaning
> should be obvious because it is stored in struct printk_info...
>
> Otherwise, it looks good to me.
>
> I tried to update your patch with the above proposal to see how
> it looks and I got:
The change seems to work. I have tested it with the following patch:
From 1966dc35bb19eb3fc13ca41257203819c36cd21b Mon Sep 17 00:00:00 2001
From: Petr Mladek <pmladek@suse.com>
Date: Fri, 16 Jan 2026 16:38:16 +0100
Subject: [PATCH 2/2] printk: Test extended execution context
Compile with
CONFIG_NETCONSOLE=y
CONFIG_NETCONSOLE_EXTENDED_LOG=y
CONFIG_CONSOLE_HAS_EXECUTION_CTX=y
CONFIG_PRINTK_EXECUTION_CTX=y
Then the extended console format should show also:
,cpu=XXX,pid=YYY,comm=ZZZ
For example:
[...]
6,776,2595848,-,caller=T167,cpu=3,pid=167,comm=scsi_eh_4;ata5: SATA link down (SStatus 0 SControl 300)
6,777,2623478,-,caller=T1,cpu=11,pid=1,comm=swapper/0;sched_clock: Marking stable (2420002924, 202869031)->(2789319400, -166447445)
6,778,2626663,-,caller=T159,cpu=2,pid=159,comm=scsi_eh_0;ata1: SATA link down (SStatus 0 SControl 300)
6,779,2671763,-,caller=T1,cpu=7,pid=1,comm=swapper/0;registered taskstats version 1
6,780,2672803,-,caller=T163,cpu=3,pid=163,comm=scsi_eh_2;ata3: SATA link down (SStatus 0 SControl 300)
[...]
4,1210,238099642,-,caller=C11,cpu=11,pid=0,comm=swapper/11; common_startup_64+0x13e/0x141
4,1211,238099651,-,caller=C11,cpu=11,pid=0,comm=swapper/11; </TASK>
4,1212,238099652,-,caller=C7,cpu=7,pid=0,comm=swapper/7;NMI backtrace for cpu 7
4,1213,238099655,-,caller=C7,cpu=7,pid=0,comm=swapper/7;CPU: 7 UID: 0 PID: 0 Comm: swapper/7 Not tainted 6.19.0-rc5-default+ #475 PREEMPT(full) 9097c5ae70fd66490486e279e5273a94d14cd453
[...]
Signed-off-by: Petr Mladek <pmladek@suse.com>
---
kernel/printk/printk.c | 84 ++++++++++++++++++++++++------------------
1 file changed, 48 insertions(+), 36 deletions(-)
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index bc09fb6e33d1..ac8eccb1d2fc 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -630,6 +630,40 @@ static int check_syslog_permissions(int type, int source)
return security_syslog(type);
}
+#define caller_id_mask 0x80000000
+
+static inline u32 printk_caller_id(void)
+{
+ return in_task() ? task_pid_nr(current) :
+ caller_id_mask + smp_processor_id();
+}
+
+
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+/* Store the opposite info than caller_id. */
+static inline u32 printk_caller_id2(void)
+{
+ return !in_task() ? task_pid_nr(current) :
+ caller_id_mask + smp_processor_id();
+}
+
+static inline pid_t printk_info_get_pid(const struct printk_info *info)
+{
+ u32 caller_id = info->caller_id;
+ u32 caller_id2 = info->caller_id2;
+
+ return caller_id & caller_id_mask ? caller_id2 : caller_id;
+}
+
+static inline int printk_info_get_cpu(const struct printk_info *info)
+{
+ u32 caller_id = info->caller_id;
+ u32 caller_id2 = info->caller_id2;
+
+ return (caller_id & caller_id_mask ? caller_id : caller_id2) & ~caller_id_mask;
+}
+#endif
+
static void append_char(char **pp, char *e, char c)
{
if (*pp < e)
@@ -641,6 +675,7 @@ static ssize_t info_print_ext_header(char *buf, size_t size,
{
u64 ts_usec = info->ts_nsec;
char caller[20];
+ char ext_caller[100];
#ifdef CONFIG_PRINTK_CALLER
u32 id = info->caller_id;
@@ -650,11 +685,22 @@ static ssize_t info_print_ext_header(char *buf, size_t size,
caller[0] = '\0';
#endif
+#ifdef CONFIG_PRINTK_EXECUTION_CTX
+ snprintf(ext_caller, sizeof(ext_caller),
+ ",cpu=%u,pid=%u,comm=%s",
+ printk_info_get_cpu(info),
+ printk_info_get_pid(info),
+ info->comm);
+#else
+ ext_caller[0] = '\0';
+#endif
+
do_div(ts_usec, 1000);
- return scnprintf(buf, size, "%u,%llu,%llu,%c%s;",
+ return scnprintf(buf, size, "%u,%llu,%llu,%c%s%s;",
(info->facility << 3) | info->level, info->seq,
- ts_usec, info->flags & LOG_CONT ? 'c' : '-', caller);
+ ts_usec, info->flags & LOG_CONT ? 'c' : '-',
+ caller, ext_caller);
}
static ssize_t msg_add_ext_text(char *buf, size_t size,
@@ -2131,40 +2177,6 @@ static inline void printk_delay(int level)
}
}
-#define caller_id_mask 0x80000000
-
-static inline u32 printk_caller_id(void)
-{
- return in_task() ? task_pid_nr(current) :
- caller_id_mask + smp_processor_id();
-}
-
-
-#ifdef CONFIG_PRINTK_EXECUTION_CTX
-/* Store the opposite info than caller_id. */
-static inline u32 printk_caller_id2(void)
-{
- return !in_task() ? task_pid_nr(current) :
- caller_id_mask + smp_processor_id();
-}
-
-static inline pid_t printk_info_get_pid(const struct printk_info *info)
-{
- u32 caller_id = info->caller_id;
- u32 caller_id2 = info->caller_id2;
-
- return caller_id & caller_id_mask ? caller_id2 : caller_id;
-}
-
-static inline int printk_info_get_cpu(const struct printk_info *info)
-{
- u32 caller_id = info->caller_id;
- u32 caller_id2 = info->caller_id2;
-
- return (caller_id & caller_id_mask ? caller_id : caller_id2) & ~caller_id_mask;
-}
-#endif
-
/**
* printk_parse_prefix - Parse level and control flags.
*
--
2.52.0
next prev parent reply other threads:[~2026-01-16 15:53 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 14:52 [PATCH net-next 0/2] net: netconsole: convert to NBCON console infrastructure Breno Leitao
2025-12-22 14:52 ` [PATCH net-next 1/2] netconsole: extract message fragmentation into send_msg_udp() Breno Leitao
2025-12-22 14:52 ` [PATCH net-next 2/2] netconsole: convert to NBCON console infrastructure Breno Leitao
2026-01-02 3:54 ` Marcos Paulo de Souza
2026-01-06 15:43 ` Breno Leitao
2026-01-07 15:04 ` Marcos Paulo de Souza
2025-12-23 7:12 ` [PATCH net-next 0/2] net: " Paolo Abeni
2025-12-23 9:44 ` Breno Leitao
2026-01-07 14:49 ` Breno Leitao
2026-01-07 15:50 ` John Ogness
2026-01-07 16:58 ` Breno Leitao
2026-01-08 11:08 ` Breno Leitao
2026-01-08 16:50 ` John Ogness
2026-01-09 10:48 ` Breno Leitao
2026-01-09 13:29 ` Petr Mladek
2026-01-09 14:03 ` Petr Mladek
2026-01-09 15:13 ` John Ogness
2026-01-12 10:55 ` Breno Leitao
2026-01-12 12:44 ` Breno Leitao
2026-01-16 15:51 ` Petr Mladek
2026-01-16 15:53 ` Petr Mladek [this message]
2026-01-16 18:07 ` Breno Leitao
2026-01-19 14:00 ` Petr Mladek
2026-01-19 16:34 ` Breno Leitao
2026-01-20 8:59 ` Petr Mladek
2026-01-20 9:17 ` Breno Leitao
2026-01-20 10:10 ` John Ogness
2026-01-12 14:17 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aWpfDKd64DLX32Hl@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=andrew+netdev@lunn.ch \
--cc=asantostc@gmail.com \
--cc=calvin@wbinvd.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=efault@gmx.de \
--cc=gustavold@gmail.com \
--cc=horms@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=jv@jvosburgh.net \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mpdesouza@suse.com \
--cc=netdev@vger.kernel.org \
--cc=osandov@osandov.com \
--cc=pabeni@redhat.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.