Skip to contentSkip to conversation

x86/platform/uv: make const pointer dots a static const array

PATCH In review Colin Ian King 5 participants 6 messages Nov 27, 2021 – Dec 2, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/platform/uv: make const pointer dots a static const array

Don't populate the const array dots on the stack but make it static const and make the pointer an array to remove a dereference. Shrinks object code a few bytes too.

---
 arch/x86/platform/uv/uv_nmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/platform/uv/uv_nmi.c +1 -1
index 1e9ff28bc2e0..2c69a0c30632 100644
@@ -725,7 +725,7 @@ static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
  */
 static void uv_nmi_dump_state_cpu(int cpu, struct pt_regs *regs)
 {
-	const char *dots = " ................................. ";
+	static const char dots[] = " ................................. ";
 
 	if (cpu == 0)
 		uv_nmi_dump_cpu_ip_hdr();
Signature · 1 line
2.33.1
maintainer
#1 lore raw
Quoted 1 line · Colin Ian King

Don't populate the const array dots on the stack

That is a misunderstanding of what the original code does. The original code has a constant char array (string constant) that is placed in an initialized data section of memory, the address off which would be assigned to the pointer "dots" on the stack -- to be clear, stack contents would not be a full array, but a pointer to it. Then that pointer would be passed to the pr_info function (which boils down to a call to printk).

Examination of the disassembly shows that the compiler actually eliminates the creation of the pointer "dots" on the stack and just passes the address of the string constant to the printk function.

So this change should not have any actual effect (I don't know where you got the "shrinks object code" from), and in my humble opinion makes the code less clear.

As such, unless there's something here I don't understand, I vote to reject this patch.

--> Steve Wahl <[email protected]>

Quoted 25 lines

but make it static
const and make the pointer an array to remove a dereference. Shrinks object code a few bytes too.

---
 arch/x86/platform/uv/uv_nmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/platform/uv/uv_nmi.c +1 -1
index 1e9ff28bc2e0..2c69a0c30632 100644
@@ -725,7 +725,7 @@ static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
  */
 static void uv_nmi_dump_state_cpu(int cpu, struct pt_regs *regs)
 {
-	const char *dots = " ................................. ";
+	static const char dots[] = " ................................. ";
 
 	if (cpu == 0)
 		uv_nmi_dump_cpu_ip_hdr();
Signature · 1 line
2.33.1
Signature · 1 line
Steve Wahl, Hewlett Packard Enterprise
#2 lore raw
Quoted 2 lines · Steve Wahl
Quoted 1 line · Colin Ian King

Don't populate the const array dots on the stack

[]

Quoted 7 lines

Examination of the disassembly shows that the compiler actually eliminates the creation of the pointer "dots" on the stack and just passes the address of the string constant to the printk function.

So this change should not have any actual effect (I don't know where you got the "shrinks object code" from), and in my humble opinion makes the code less clear.

Probably shrinks an allmodconfig where the symbols are referenced. It probably doesn't do anything to a defconfig.

Quoted 2 lines

As such, unless there's something here I don't understand, I vote to reject this patch.

[]

Quoted 3 lines
Quoted 3 lines

but make it static
const and make the pointer an array to remove a dereference. Shrinks object code a few bytes too.

[]

Quoted 1 line

arch/x86/platform/uv/uv_nmi.c

Quoted 1 line
arch/x86/platform/uv/uv_nmi.c +0 -0

[]

Quoted 6 lines
Quoted 6 lines
arch/x86/platform/uv/uv_nmi.c +1 -1
@@ -725,7 +725,7 @@ static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
  */
 static void uv_nmi_dump_state_cpu(int cpu, struct pt_regs *regs)
 {
-	const char *dots = " ................................. ";
+	static const char dots[] = " ................................. ";
maintainer
#3 lore raw
Quoted 8 lines · Joe Perches
Quoted 2 lines · Steve Wahl
Quoted 1 line · Colin Ian King

Don't populate the const array dots on the stack

[]

Quoted 4 lines

Examination of the disassembly shows that the compiler actually eliminates the creation of the pointer "dots" on the stack and just passes the address of the string constant to the printk function.

Quoted 6 lines
Quoted 3 lines

So this change should not have any actual effect (I don't know where you got the "shrinks object code" from), and in my humble opinion makes the code less clear.

Probably shrinks an allmodconfig where the symbols are referenced. It probably doesn't do anything to a defconfig.

OK, I looked. Under allmodconfig, the new code is one byte smaller.

Defconfig doesn't include CONFIG_X86_UV and this file doesn't get compiled.

Using defconfig plus CONFIG_X86_UV and prerequisites, the new code is 24 bytes larger, probably because of alignment added.

allmodconfig:

text data bss dec hex filename

  30827	  18358	   1472	  50657	   c5e1	uv_nmi.o
  30828	  18358	   1472	  50658	   c5e2	uv_nmi.orig.o

default config + CONFIG_X86_UV:

   text	   data	    bss	    dec	    hex	filename
   9918	    216	    160	  10294	   2836	uv_nmi.o
   9894	    216	    160	  10270	   281e	uv_nmi.orig.o

So I still don't think this patch makes sense.

--> Steve Wahl

Quoted 17 lines
Quoted 2 lines

As such, unless there's something here I don't understand, I vote to reject this patch.

[]

Quoted 3 lines
Quoted 3 lines

but make it static
const and make the pointer an array to remove a dereference. Shrinks object code a few bytes too.

[]

Quoted 1 line

arch/x86/platform/uv/uv_nmi.c

Quoted 1 line
arch/x86/platform/uv/uv_nmi.c +0 -0

[]

Quoted 6 lines
Quoted 6 lines
arch/x86/platform/uv/uv_nmi.c +1 -1
@@ -725,7 +725,7 @@ static void uv_nmi_dump_cpu_ip(int cpu, struct pt_regs *regs)
  */
 static void uv_nmi_dump_state_cpu(int cpu, struct pt_regs *regs)
 {
-	const char *dots = " ................................. ";
+	static const char dots[] = " ................................. ";
Signature · 1 line
Steve Wahl, Hewlett Packard Enterprise
#4 lore raw

Hi,

Quoted 30 lines · Steve Wahl
Quoted 8 lines · Joe Perches
Quoted 2 lines · Steve Wahl
Quoted 1 line · Colin Ian King

Don't populate the const array dots on the stack

[]

Quoted 4 lines

Examination of the disassembly shows that the compiler actually eliminates the creation of the pointer "dots" on the stack and just passes the address of the string constant to the printk function.

Quoted 6 lines
Quoted 3 lines

So this change should not have any actual effect (I don't know where you got the "shrinks object code" from), and in my humble opinion makes the code less clear.

Probably shrinks an allmodconfig where the symbols are referenced. It probably doesn't do anything to a defconfig.

OK, I looked. Under allmodconfig, the new code is one byte smaller.

Defconfig doesn't include CONFIG_X86_UV and this file doesn't get compiled.

Using defconfig plus CONFIG_X86_UV and prerequisites, the new code is 24 bytes larger, probably because of alignment added.

allmodconfig:

text data bss dec hex filename

  30827	  18358	   1472	  50657	   c5e1	uv_nmi.o
  30828	  18358	   1472	  50658	   c5e2	uv_nmi.orig.o
Quoted 7 lines

default config + CONFIG_X86_UV:

   text	   data	    bss	    dec	    hex	filename
   9918	    216	    160	  10294	   2836	uv_nmi.o
   9894	    216	    160	  10270	   281e	uv_nmi.orig.o

So I still don't think this patch makes sense.

I agree, so I've dropped this patch from the queue.

Regards,

Hans

#5 lore raw
Quoted 39 lines · Hans de Goede

Hi,

Quoted 36 lines · Steve Wahl
Quoted 8 lines · Joe Perches
Quoted 2 lines · Steve Wahl
Quoted 1 line · Colin Ian King

Don't populate the const array dots on the stack

[]

Quoted 4 lines

Examination of the disassembly shows that the compiler actually eliminates the creation of the pointer "dots" on the stack and just passes the address of the string constant to the printk function.

Quoted 6 lines
Quoted 3 lines

So this change should not have any actual effect (I don't know where you got the "shrinks object code" from), and in my humble opinion makes the code less clear.

Probably shrinks an allmodconfig where the symbols are referenced. It probably doesn't do anything to a defconfig.

OK, I looked. Under allmodconfig, the new code is one byte smaller.

Defconfig doesn't include CONFIG_X86_UV and this file doesn't get compiled.

Using defconfig plus CONFIG_X86_UV and prerequisites, the new code is 24 bytes larger, probably because of alignment added.

allmodconfig:

text data bss dec hex filename

   30827	  18358	   1472	  50657	   c5e1	uv_nmi.o
   30828	  18358	   1472	  50658	   c5e2	uv_nmi.orig.o

default config + CONFIG_X86_UV:

    text	   data	    bss	    dec	    hex	filename
    9918	    216	    160	  10294	   2836	uv_nmi.o
    9894	    216	    160	  10270	   281e	uv_nmi.orig.o
Quoted 8 lines
Quoted 1 line

So I still don't think this patch makes sense.

I agree, so I've dropped this patch from the queue.

Regards,

Hans

+1. Apologies for wasting your valuable time. I appreciate the detailed review.

Colin