Skip to contentSkip to conversation

staging: wfx: make a const array static, makes object smaller

PATCH In review Colin King 5 participants 5 messages Oct 16, 2020 – Oct 19, 2020

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 staging: wfx: make a const array static, makes object smaller

From: Colin Ian King <[email protected]>

Don't populate const array filter_ies on the stack but instead make it static. Makes the object code smaller by 261 bytes.

Before:

   text	   data	    bss	    dec	    hex	filename
  21674	   3166	    448	  25288	   62c8	drivers/staging/wfx/sta.o

After:

   text	   data	    bss	    dec	    hex	filename
  21349	   3230	    448	  25027	   61c3	drivers/staging/wfx/sta.o

(gcc version 10.2.0)

---
 drivers/staging/wfx/sta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wfx/sta.c +1 -1
index 2320a81eae0b..196779a1b89a 100644
@@ -63,7 +63,7 @@ void wfx_suspend_hot_dev(struct wfx_dev *wdev, enum sta_notify_cmd cmd)
 
 static void wfx_filter_beacon(struct wfx_vif *wvif, bool filter_beacon)
 {
-	const struct hif_ie_table_entry filter_ies[] = {
+	static const struct hif_ie_table_entry filter_ies[] = {
 		{
 			.ie_id        = WLAN_EID_VENDOR_SPECIFIC,
 			.has_changed  = 1,
Signature · 1 line
2.27.0
#1 lore raw
Quoted 5 lines · Colin King

From: Colin Ian King <[email protected]>

Don't populate const array filter_ies on the stack but instead make it static. Makes the object code smaller by 261 bytes.

Quoted 7 lines

Before:

   text	   data	    bss	    dec	    hex	filename
  21674	   3166	    448	  25288	   62c8	drivers/staging/wfx/sta.o

After:

   text	   data	    bss	    dec	    hex	filename
  21349	   3230	    448	  25027	   61c3	drivers/staging/wfx/sta.o

Thanks.

It's odd to me it's so large a change as it's only 24 bytes of initialization. (3 entries, each 8 bytes)

This line in the same function:

		hif_set_beacon_filter_table(wvif, 3, filter_ies);

might as well use ARRAY_SIZE(filter_ies) instead of 3

#2 lore raw

From: Joe Perches

Quoted 12 lines

Sent: 17 October 2020 01:12

Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Don't populate const array filter_ies on the stack but instead make it static. Makes the object code smaller by 261 bytes.

Before:

   text	   data	    bss	    dec	    hex	filename
  21674	   3166	    448	  25288	   62c8	drivers/staging/wfx/sta.o
Quoted 8 lines
Quoted 3 lines

After:

   text	   data	    bss	    dec	    hex	filename
  21349	   3230	    448	  25027	   61c3	drivers/staging/wfx/sta.o

Thanks.

It's odd to me it's so large a change as it's only 24 bytes of initialization. (3 entries, each 8 bytes)

Perhaps the 'stack protector' crap?

Interestingly, loading the data from the 'readonly' section is probably a data cache miss.
Which might end up being slower than the extra code to update the on-stack data.
The extra code might get prefetched...

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)

Reviewed-by
#3 lore raw
Quoted 22 lines · On Monday 19 October 2020 10:09:19 CEST David Laight wrote:

From: Joe Perches

Quoted 12 lines

Sent: 17 October 2020 01:12

Quoted 9 lines · Colin King

From: Colin Ian King <[email protected]>

Don't populate const array filter_ies on the stack but instead make it static. Makes the object code smaller by 261 bytes.

Before:

   text        data     bss     dec     hex filename
  21674        3166     448   25288    62c8 drivers/staging/wfx/sta.o
Quoted 8 lines
Quoted 3 lines

After:

   text        data     bss     dec     hex filename
  21349        3230     448   25027    61c3 drivers/staging/wfx/sta.o

Thanks.

It's odd to me it's so large a change as it's only 24 bytes of initialization. (3 entries, each 8 bytes)

Quoted 7 lines

Perhaps the 'stack protector' crap?

Interestingly, loading the data from the 'readonly' section is probably a data cache miss.
Which might end up being slower than the extra code to update the on-stack data.
The extra code might get prefetched...

I had never realized the difference between "const" and "static const" in this case.

With my gcc fro arm, the output of "objdump -h sta.o" gives:

Before:
0 .text 000019fc 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
[...]
7 .rodata 00000015 00000000 00000000 00001e78 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA

After:
0 .text 00001974 00000000 00000000 00000034 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
[...]
7 .rodata 0000002d 00000000 00000000 00001dd4 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA

The difference of .rodata is exactly what is expected (24 bytes) and we save 115 bytes of code.

Signature · 1 line
Jérôme Pouiller
#4 lore raw
In reply to Joe Perches

Le 17/10/2020 à 02:11, Joe Perches a écrit :

Quoted 10 lines · Colin King
Quoted 9 lines

From: Colin Ian King <[email protected]>

Don't populate const array filter_ies on the stack but instead make it static. Makes the object code smaller by 261 bytes.

Before:

    text	   data	    bss	    dec	    hex	filename
   21674	   3166	    448	  25288	   62c8	drivers/staging/wfx/sta.o
Quoted 9 lines
Quoted 3 lines

After:

    text	   data	    bss	    dec	    hex	filename
   21349	   3230	    448	  25027	   61c3	drivers/staging/wfx/sta.o

Thanks.

It's odd to me it's so large a change as it's only 24 bytes of initialization. (3 entries, each 8 bytes)

The function looks small.
Maybe it is inlined by gcc in each of the 3 callers?

CJ

Quoted 8 lines

This line in the same function:

		hif_set_beacon_filter_table(wvif, 3, filter_ies);

might as well use ARRAY_SIZE(filter_ies) instead of 3