linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ruifeng Zhang <ruifeng.zhang0110@gmail.com>
To: pmladek@suse.com, senozhatsky@chromium.org, rostedt@goodmis.org,
	john.ogness@linutronix.de
Cc: linux-kernel@vger.kernel.org, ruifeng.zhang1@unisoc.com,
	nianfu.bai@unisoc.com, orson.zhai@unisoc.com
Subject: [PATCH v1 1/1] printk: always output coreid in caller information
Date: Wed, 19 May 2021 14:33:55 +0800	[thread overview]
Message-ID: <20210519063355.5147-1-ruifeng.zhang0110@gmail.com> (raw)

From: Ruifeng Zhang <ruifeng.zhang1@unisoc.com>

Sometimes we want to know which cpu the process is running
on when the log output, rather than the thread id.  So add
the processor id output always in the caller information.

caller_id bitmap:
[63:32] thread_id
[31]    flags of in thread context
[30:0]  processor id

About the output format, reserve 5 bits for thread id and
2 bits for processor id.

e.g.
Before:
[    0.000000][    T0] Booting Linux on physical CPU 0x0
[    0.109338][    T1] smp: Bringing up secondary CPUs ...
[    0.115831][    T0] CPU1: thread 0, cpu 1, socket 0, mpidr 81000100
[    0.117051][    T0] CPU2: thread 0, cpu 2, socket 0, mpidr 81000200
[    0.118207][    T0] CPU3: thread 0, cpu 3, socket 0, mpidr 81000300
[  114.112319][T25122] binder:

After:
[    0.000000][     T0:C0] Booting Linux on physical CPU 0x0
[    0.114549][     T1:C0] smp: Bringing up secondary CPUs ...
[    0.121377][     T0:C1] CPU1: thread 0, cpu 1, socket 0, mpidr 81000100
[    0.122606][     T0:C2] CPU2: thread 0, cpu 2, socket 0, mpidr 81000200
[    0.123758][     T0:C3] CPU3: thread 0, cpu 3, socket 0, mpidr 81000300
[   43.260158][        C1] Irq_monitor:Irq
[  112.862589][ T21442:C5] binder:

Signed-off-by: Ruifeng Zhang <ruifeng.zhang1@unisoc.com>
---
 kernel/printk/printk.c            | 36 +++++++++++++++++++++----------
 kernel/printk/printk_ringbuffer.h |  2 +-
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 421c35571797..8ef4acefce19 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -331,7 +331,7 @@ static int console_msg_format = MSG_FORMAT_DEFAULT;
  *   record.info.facility           = 0 (LOG_KERN)
  *   record.info.flags              = 0
  *   record.info.level              = 3 (LOG_ERR)
- *   record.info.caller_id          = 299 (task 299)
+ *   record.info.caller_id          = 1286342705152 ([63:32]=299 [31]=1 [30:0]=0)
  *   record.info.dev_info.subsystem = "pci" (terminated)
  *   record.info.dev_info.device    = "+pci:0000:00:01.0" (terminated)
  *
@@ -559,10 +559,15 @@ static ssize_t info_print_ext_header(char *buf, size_t size,
 	u64 ts_usec = info->ts_nsec;
 	char caller[20];
 #ifdef CONFIG_PRINTK_CALLER
-	u32 id = info->caller_id;
+	u64 id = info->caller_id;
 
-	snprintf(caller, sizeof(caller), ",caller=%c%u",
-		 id & 0x80000000 ? 'C' : 'T', id & ~0x80000000);
+	if (id & 0x80000000)
+		snprintf(caller, sizeof(caller), ",caller=T%u:C%u",
+			 (u32)(id >> 32),
+			 (u32)(id & ~0x80000000));
+	else
+		snprintf(caller, sizeof(caller), ",caller=C%u",
+			 (u32)(id & ~0x80000000));
 #else
 	caller[0] = '\0';
 #endif
@@ -1273,9 +1278,15 @@ static size_t print_caller(u32 id, char *buf)
 {
 	char caller[12];
 
-	snprintf(caller, sizeof(caller), "%c%u",
-		 id & 0x80000000 ? 'C' : 'T', id & ~0x80000000);
-	return sprintf(buf, "[%6s]", caller);
+	if (id & 0x80000000)
+		snprintf(caller, sizeof(caller), "T%u:C%u",
+			 (u32)(id >> 32),
+			 (u32)(id & ~0x80000000));
+	else
+		snprintf(caller, sizeof(caller), "C%u",
+			 (u32)(id & ~0x80000000));
+
+	return sprintf(buf, "[%10s]", caller);
 }
 #else
 #define print_caller(id, buf) 0
@@ -1954,10 +1965,13 @@ static inline void printk_delay(void)
 	}
 }
 
-static inline u32 printk_caller_id(void)
+static inline u64 printk_caller_id(void)
 {
-	return in_task() ? task_pid_nr(current) :
-		0x80000000 + raw_smp_processor_id();
+	if (in_task())
+		return (u64)task_pid_nr(current) << 32 |
+			0x80000000 + raw_smp_processor_id();
+	else
+		return raw_smp_processor_id();
 }
 
 /**
@@ -2036,7 +2050,7 @@ int vprintk_store(int facility, int level,
 		  const struct dev_printk_info *dev_info,
 		  const char *fmt, va_list args)
 {
-	const u32 caller_id = printk_caller_id();
+	const u64 caller_id = printk_caller_id();
 	struct prb_reserved_entry e;
 	enum log_flags lflags = 0;
 	struct printk_record r;
diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h
index 73cc80e01cef..c0a3146c7ac2 100644
--- a/kernel/printk/printk_ringbuffer.h
+++ b/kernel/printk/printk_ringbuffer.h
@@ -19,7 +19,7 @@ struct printk_info {
 	u8	facility;	/* syslog facility */
 	u8	flags:5;	/* internal record flags */
 	u8	level:3;	/* syslog level */
-	u32	caller_id;	/* thread id or processor id */
+	u64	caller_id;      /* thread id or processor id */
 
 	struct dev_printk_info	dev_info;
 };
-- 
2.17.1


             reply	other threads:[~2021-05-19  6:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-19  6:33 Ruifeng Zhang [this message]
2021-05-19  8:25 ` [PATCH v1 1/1] printk: always output coreid in caller information John Ogness
2021-05-19  9:24   ` Ruifeng Zhang

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=20210519063355.5147-1-ruifeng.zhang0110@gmail.com \
    --to=ruifeng.zhang0110@gmail.com \
    --cc=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nianfu.bai@unisoc.com \
    --cc=orson.zhai@unisoc.com \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=ruifeng.zhang1@unisoc.com \
    --cc=senozhatsky@chromium.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).