Skip to contentSkip to conversation

printk: Print cpuid along with the timestamp with CONFIG_PRINTK_TIME

PATCH In review Ravikiran G Thirumalai 3 participants 5 messages Sep 18, 2008 – Sep 19, 2008 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: Print cpuid along with the timestamp with CONFIG_PRINTK_TIME

I found it useful to have the cpuid of the printing cpu along with the timestamp -- especially while debugging hangs during bootups.

I don't know why this hasn't been implemened in the kernel yet, and cannot think of a strong reason not to have it. Yes, the cpuid prefix will take 5 more characters per line, but having the cpuid info is worth it, I think.

Thanks,
Kiran

---

Add cpuid information to printk if CONFIG_PRINTK_TIME is enabled. This information is useful to debug hangs and bootup issues.

kernel/printk.c +3 -2
Index: linux-git/kernel/printk.c
===================================================================
@@ -739,9 +739,10 @@ asmlinkage int vprintk(const char *fmt, 
 
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+				tlen = sprintf(tbuf, "[%5lu.%06lu:%d] ",
 						(unsigned long) t,
-						nanosec_rem / 1000);
+						nanosec_rem / 1000,
+						printk_cpu);
 
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);
#1 lore raw
Quoted 26 lines · On Thu, 18 Sep 2008 12:37:20 -0700 Ravikiran G Thirumalai <[email protected]>…

I found it useful to have the cpuid of the printing cpu along with the timestamp -- especially while debugging hangs during bootups.

I don't know why this hasn't been implemened in the kernel yet, and cannot think of a strong reason not to have it. Yes, the cpuid prefix will take 5 more characters per line, but having the cpuid info is worth it, I think.

Thanks,
Kiran

---

Add cpuid information to printk if CONFIG_PRINTK_TIME is enabled. This information is useful to debug hangs and bootup issues.

Index: linux-git/kernel/printk.c
===================================================================

kernel/printk.c +0 -0
@@ -739,9 +739,10 @@ asmlinkage int vprintk(const char *fmt, 
 
 				t = cpu_clock(printk_cpu);

kernel/printk.c asmlinkage int vprintk(const char *fmt, · line 748

Quoted 10 lines
kernel/printk.c +3 -2
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+				tlen = sprintf(tbuf, "[%5lu.%06lu:%d] ",
 						(unsigned long) t,
-						nanosec_rem / 1000);
+						nanosec_rem / 1000,
+						printk_cpu);
 
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);

Yes, I guess it could be useful sometimes. otoh anyone who is down at that level of detail and is using printk to debug something can add their own %d/smp_processor_id().

Your patch illogically ties the cpu-id-printing feature to the printk.time feature. I guess that's liveable with, but Documentation/kernel-parameters.txt should be updated.

Anyone who was parsing that output might get a shock, but that's liveable with too. Probably their parser will continue to work anwyay.

I don't know whether the usefulness of this feature outweighs its various costs. Input is sought.

#2 lore raw
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 18 Sep 2008 12:37:20 -0700 Ravikiran G Thirumalai <[email protected]>…

Index: linux-git/kernel/printk.c
===================================================================

kernel/printk.c +3 -2
@@ -739,9 +739,10 @@ asmlinkage int vprintk(const char *fmt, 
 
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+				tlen = sprintf(tbuf, "[%5lu.%06lu:%d] ",
 						(unsigned long) t,
-						nanosec_rem / 1000);
+						nanosec_rem / 1000,
+						printk_cpu);
 
Quoted 8 lines

kernel/printk.c asmlinkage int vprintk(const char *fmt, · line 748

Quoted 2 lines
kernel/printk.c +0 -0
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);

Your patch illogically ties the cpu-id-printing feature to the printk.time feature. I guess that's liveable with, but Documentation/kernel-parameters.txt should be updated.

Didn't realize Documentation/kernel-parameters.txt had reference and even a runtime parameter to control this! I always enabled CONFIG_PRINTK_TIME to get timestamps. Here's an updated patch.

As for the cpuid with the timestamp, the timestamp that is being is the printed the cpu's time stamp.

---

Add cpuid information to printk if CONFIG_PRINTK_TIME is enabled. This information is useful to debug hangs and boot issues.

kernel/printk.c +3 -2
Index: linux-git/kernel/printk.c
===================================================================
@@ -739,9 +739,10 @@ asmlinkage int vprintk(const char *fmt, 
 
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+				tlen = sprintf(tbuf, "[%5lu.%06lu:%d] ",
 						(unsigned long) t,
-						nanosec_rem / 1000);
+						nanosec_rem / 1000,
+						printk_cpu);
 
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);
Documentation/kernel-parameters.txt +4 -1
Index: linux-git/Documentation/kernel-parameters.txt
===================================================================
@@ -1687,7 +1687,10 @@ and is between 256 and 4096 characters. 
 			default: off.
 
 	printk.time=	Show timing data prefixed to each printk message line
-			Format: <bool>  (1/Y/y=enable, 0/N/n=disable)
+			Format: <bool>  (1/Y/y=enable, 0/N/n=disable).
+			Per-cpu timestamps are prefixed as
+			"[sssss.uuuuuu:cpuid]" on each and every line printed,
+			if this option is enabled.
 
 	profile=	[KNL] Enable kernel profiling via /proc/profile
 			Format: [schedule,]<number>
#3 lore raw
Quoted 30 lines · Ravikiran G Thirumalai
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 18 Sep 2008 12:37:20 -0700 Ravikiran G Thirumalai <[email protected]>…

Index: linux-git/kernel/printk.c
===================================================================

kernel/printk.c +3 -2
@@ -739,9 +739,10 @@ asmlinkage int vprintk(const char *fmt, 
 
 				t = cpu_clock(printk_cpu);
 				nanosec_rem = do_div(t, 1000000000);
-				tlen = sprintf(tbuf, "[%5lu.%06lu] ",
+				tlen = sprintf(tbuf, "[%5lu.%06lu:%d] ",
 						(unsigned long) t,
-						nanosec_rem / 1000);
+						nanosec_rem / 1000,
+						printk_cpu);
 
Quoted 8 lines

kernel/printk.c asmlinkage int vprintk(const char *fmt, · line 748

Quoted 2 lines
kernel/printk.c +0 -0
 				for (tp = tbuf; tp < tbuf + tlen; tp++)
 					emit_log_char(*tp);

Your patch illogically ties the cpu-id-printing feature to the printk.time feature. I guess that's liveable with, but Documentation/kernel-parameters.txt should be updated.

Quoted 6 lines

Didn't realize Documentation/kernel-parameters.txt had reference and even a runtime parameter to control this! I always enabled CONFIG_PRINTK_TIME to get timestamps. Here's an updated patch.

As for the cpuid with the timestamp, the timestamp that is being is the printed the cpu's time stamp.

Do we really need this information on UP kernels? Why don't you add another option for this feature?

Marcin

#4 lore raw
Quoted 2 lines · Marcin Slusarz

Do we really need this information on UP kernels?

I thought about it, and left it as the way it is to have a consistent format between UP and SMP. With most of the modern cpus being multicore, or headed that way, and since the entire timestamp prefix can be controlled by a boot option, is it worth having different formats for UP and SMP? Most distros ship SMP kernels anyways.