Skip to contentSkip to conversation

x86: combine printk()s in show_regs_common()

PATCH In review Jan Beulich 3 participants 7 messages Feb 17, 2011 – Feb 18, 2011 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: combine printk()s in show_regs_common()

Printing a single character alone when there's an immediately following printk() is pretty pointless (and wasteful).

---
 arch/x86/kernel/process.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/process.c +3 -6
@@ -110,12 +110,9 @@ void show_regs_common(void)
 		init_utsname()->release,
 		(int)strcspn(init_utsname()->version, " "),
 		init_utsname()->version);
-	printk(KERN_CONT " ");
-	printk(KERN_CONT "%s %s", vendor, product);
-	if (board) {
-		printk(KERN_CONT "/");
-		printk(KERN_CONT "%s", board);
-	}
+	printk(KERN_CONT " %s %s", vendor, product);
+	if (board)
+		printk(KERN_CONT "/%s", board);
 	printk(KERN_CONT "\n");
 }
 
#1 lore raw
Quoted 4 lines · Jan Beulich

Printing a single character alone when there's an immediately following printk() is pretty pointless (and wasteful).

Perhaps better still to use just one printk.

---
 arch/x86/kernel/process.c |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)
arch/x86/kernel/process.c +10 -12
index ff45541..0f43771 100644
@@ -103,20 +103,18 @@ void show_regs_common(void)
 
 	/* Board Name is optional */
 	board = dmi_get_system_info(DMI_BOARD_NAME);
+	if (!board)
+		board = "";
 
 	printk(KERN_CONT "\n");
-	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
-		current->pid, current->comm, print_tainted(),
-		init_utsname()->release,
-		(int)strcspn(init_utsname()->version, " "),
-		init_utsname()->version);
-	printk(KERN_CONT " ");
-	printk(KERN_CONT "%s %s", vendor, product);
-	if (board) {
-		printk(KERN_CONT "/");
-		printk(KERN_CONT "%s", board);
-	}
-	printk(KERN_CONT "\n");
+	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
+	       current->pid, current->comm, print_tainted(),
+	       init_utsname()->release,
+	       (int)strcspn(init_utsname()->version, " "),
+	       init_utsname()->version,
+	       vendor, product,
+	       strlen(board) ? "/" : "",
+	       board);
 }
 
 void flush_thread(void)
#2 lore raw

[tip:x86/debug] x86: Combine printk()s in show_regs_common()

In reply to Jan Beulich
Commit-ID:  fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Gitweb:     http://git.kernel.org/tip/fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Author:     Jan Beulich <[email protected]>
AuthorDate: Thu, 17 Feb 2011 15:56:58 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 18 Feb 2011 08:52:30 +0100

x86: Combine printk()s in show_regs_common()

Printing a single character alone when there's an immediately following printk() is pretty pointless (and wasteful).

LKML-Reference: <[email protected]>

---
 arch/x86/kernel/process.c |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/process.c +3 -6
index ff45541..99fa3ad 100644
@@ -110,12 +110,9 @@ void show_regs_common(void)
 		init_utsname()->release,
 		(int)strcspn(init_utsname()->version, " "),
 		init_utsname()->version);
-	printk(KERN_CONT " ");
-	printk(KERN_CONT "%s %s", vendor, product);
-	if (board) {
-		printk(KERN_CONT "/");
-		printk(KERN_CONT "%s", board);
-	}
+	printk(KERN_CONT " %s %s", vendor, product);
+	if (board)
+		printk(KERN_CONT "/%s", board);
 	printk(KERN_CONT "\n");
 }
 
#3 lore raw

Re: [tip:x86/debug] x86: Combine printk()s in show_regs_common()

Quoted 11 lines · tip-bot for Jan Beulich
Commit-ID:  fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Gitweb:     http://git.kernel.org/tip/fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Author:     Jan Beulich <[email protected]>
AuthorDate: Thu, 17 Feb 2011 15:56:58 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 18 Feb 2011 08:52:30 +0100

x86: Combine printk()s in show_regs_common()

Printing a single character alone when there's an immediately following printk() is pretty pointless (and wasteful).

Ingo, why did you choose to apply this patch instead of the alternative one I posted on the same thread?

https://patchwork.kernel.org/patch/571641/

#4 lore raw

Re: [tip:x86/debug] x86: Combine printk()s in show_regs_common()

Quoted 8 lines · Joe Perches
Quoted 7 lines · tip-bot for Jan Beulich
Commit-ID:  fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Gitweb:     http://git.kernel.org/tip/fd8fa4d3ddc4cc04ec8097e632b995d535c52beb
Author:     Jan Beulich <[email protected]>
AuthorDate: Thu, 17 Feb 2011 15:56:58 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 18 Feb 2011 08:52:30 +0100
Quoted 7 lines
Quoted 4 lines

x86: Combine printk()s in show_regs_common()

Printing a single character alone when there's an immediately following printk() is pretty pointless (and wasteful).

Ingo, why did you choose to apply this patch instead of the alternative one I posted on the same thread?

Your version:

	/* Board Name is optional */
	board = dmi_get_system_info(DMI_BOARD_NAME);
	if (!board)
		board = "";

	printk(KERN_CONT "\n");

	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
	       current->pid, current->comm, print_tainted(),
	       init_utsname()->release,
	       (int)strcspn(init_utsname()->version, " "),
	       init_utsname()->version,
	       vendor, product,
	       strlen(board) ? "/" : "",
	       board);

The 'board' fiddling and the strlen(board) check complicates things unnecessarily and makes the code hard to read. Jan's version was at least simple.

Something like this:

	/* Board Name is optional */
	board = dmi_get_system_info(DMI_BOARD_NAME);

	printk(KERN_CONT "\n");

	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s %s %s\n",
	       current->pid, current->comm, print_tainted(),
	       init_utsname()->release,
	       (int)strcspn(init_utsname()->version, " "),
	       init_utsname()->version,
	       vendor, product, board ? : "");

Would be easier to read and gives similarly useful output.

Thanks,

Ingo

#5 lore raw

Re: [tip:x86/debug] x86: Combine printk()s in show_regs_common()

Quoted 21 lines · Ingo Molnar
Quoted 2 lines · Joe Perches

Ingo, why did you choose to apply this patch instead of the alternative one I posted on the same thread?

Your version:

	/* Board Name is optional */
	board = dmi_get_system_info(DMI_BOARD_NAME);
	if (!board)
		board = "";

	printk(KERN_CONT "\n");

	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
	       current->pid, current->comm, print_tainted(),
	       init_utsname()->release,
	       (int)strcspn(init_utsname()->version, " "),
	       init_utsname()->version,
	       vendor, product,
	       strlen(board) ? "/" : "",
	       board);
Quoted 2 lines

The 'board' fiddling and the strlen(board) check complicates things unnecessarily and makes the code hard to read. Jan's version was at least simple.

Perhaps you should look at the surrounding code.
It's uses the same style as I chose for "board".

void show_regs_common(void)

{
	const char *vendor, *product, *board;

	vendor = dmi_get_system_info(DMI_SYS_VENDOR);
	if (!vendor)
		vendor = "";
	product = dmi_get_system_info(DMI_PRODUCT_NAME);
	if (!product)
		product = "";

...

Quoted 14 lines

Something like this:

	/* Board Name is optional */
	board = dmi_get_system_info(DMI_BOARD_NAME);

	printk(KERN_CONT "\n");

	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s %s %s\n",
	       current->pid, current->comm, print_tainted(),
	       init_utsname()->release,
	       (int)strcspn(init_utsname()->version, " "),
	       init_utsname()->version,
	       vendor, product, board ? : "");
Quoted 1 line

Would be easier to read and gives similarly useful output.

It's a question of using identical output or
merely similar output.

cheers, Joe

#6 lore raw

Re: [tip:x86/debug] x86: Combine printk()s in show_regs_common()

Quoted 22 lines · Joe Perches
Quoted 21 lines · Ingo Molnar
Quoted 2 lines · Joe Perches

Ingo, why did you choose to apply this patch instead of the alternative one I posted on the same thread?

Your version:

	/* Board Name is optional */
	board = dmi_get_system_info(DMI_BOARD_NAME);
	if (!board)
		board = "";

	printk(KERN_CONT "\n");

	printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
	       current->pid, current->comm, print_tainted(),
	       init_utsname()->release,
	       (int)strcspn(init_utsname()->version, " "),
	       init_utsname()->version,
	       vendor, product,
	       strlen(board) ? "/" : "",
	       board);
Quoted 5 lines
Quoted 2 lines

The 'board' fiddling and the strlen(board) check complicates things unnecessarily and makes the code hard to read. Jan's version was at least simple.

Perhaps you should look at the surrounding code.
It's uses the same style as I chose for "board".

Yes, i realize that, but the strlen() trick really looks weird.

And 'weird' is not something i like seeing in essential bug reporting code.

Thanks,

Ingo