linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
@ 2021-05-05 19:01 Colin King
  2021-05-05 19:41 ` Krzysztof Kozlowski
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Colin King @ 2021-05-05 19:01 UTC (permalink / raw)
  To: Alim Akhtar, Avri Altman, James E . J . Bottomley,
	Martin K . Petersen, Krzysztof Kozlowski, linux-scsi,
	linux-arm-kernel, linux-samsung-soc
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Don't populate the const array granularity_tbl on the stack but instead it
static. Makes the object code smaller by 190 bytes:

Before:
   text    data     bss     dec     hex filename
  25563    6908       0   32471    7ed7 ./drivers/scsi/ufs/ufs-exynos.o

After:
   text    data     bss     dec     hex filename
  25213    7068       0   32281    7e19 ./drivers/scsi/ufs/ufs-exynos.o

(gcc version 10.3.0)

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/ufs/ufs-exynos.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/ufs/ufs-exynos.c b/drivers/scsi/ufs/ufs-exynos.c
index 70647eacf195..f2f342d496c7 100644
--- a/drivers/scsi/ufs/ufs-exynos.c
+++ b/drivers/scsi/ufs/ufs-exynos.c
@@ -1048,7 +1048,7 @@ static void exynos_ufs_pre_hibern8(struct ufs_hba *hba, u8 enter)
 		exynos_ufs_ungate_clks(ufs);
 
 		if (ufs->opts & EXYNOS_UFS_OPT_USE_SW_HIBERN8_TIMER) {
-			const unsigned int granularity_tbl[] = {
+			static const unsigned int granularity_tbl[] = {
 				1, 4, 8, 16, 32, 100
 			};
 			int h8_time = attr->pa_hibern8time *
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
  2021-05-05 19:01 [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller Colin King
@ 2021-05-05 19:41 ` Krzysztof Kozlowski
  2021-05-05 19:49   ` Colin Ian King
  2021-05-22  2:50 ` Martin K. Petersen
  2021-05-26  4:07 ` Martin K. Petersen
  2 siblings, 1 reply; 5+ messages in thread
From: Krzysztof Kozlowski @ 2021-05-05 19:41 UTC (permalink / raw)
  To: Colin King, Alim Akhtar, Avri Altman, James E . J . Bottomley,
	Martin K . Petersen, linux-scsi, linux-arm-kernel,
	linux-samsung-soc
  Cc: kernel-janitors, linux-kernel

On 05/05/2021 15:01, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Don't populate the const array granularity_tbl on the stack but instead it
> static. Makes the object code smaller by 190 bytes:
> 
> Before:
>    text    data     bss     dec     hex filename
>   25563    6908       0   32471    7ed7 ./drivers/scsi/ufs/ufs-exynos.o
> 
> After:
>    text    data     bss     dec     hex filename
>   25213    7068       0   32281    7e19 ./drivers/scsi/ufs/ufs-exynos.o
> 
> (gcc version 10.3.0)

I am not sure what's the benefit here - you moved the code from text to
data. In total you decreased the size for this compilation settings
(e.g. compiler + optimizations) but that might not be always true, right?

This has effect on the code readability - line is longer and reader
would think "why this was made static since it is simple one-time const?".


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
  2021-05-05 19:41 ` Krzysztof Kozlowski
@ 2021-05-05 19:49   ` Colin Ian King
  0 siblings, 0 replies; 5+ messages in thread
From: Colin Ian King @ 2021-05-05 19:49 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Alim Akhtar, Avri Altman,
	James E . J . Bottomley, Martin K . Petersen, linux-scsi,
	linux-arm-kernel, linux-samsung-soc
  Cc: kernel-janitors, linux-kernel

On 05/05/2021 20:41, Krzysztof Kozlowski wrote:
> On 05/05/2021 15:01, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Don't populate the const array granularity_tbl on the stack but instead it
>> static. Makes the object code smaller by 190 bytes:
>>
>> Before:
>>    text    data     bss     dec     hex filename
>>   25563    6908       0   32471    7ed7 ./drivers/scsi/ufs/ufs-exynos.o
>>
>> After:
>>    text    data     bss     dec     hex filename
>>   25213    7068       0   32281    7e19 ./drivers/scsi/ufs/ufs-exynos.o
>>
>> (gcc version 10.3.0)
> 
> I am not sure what's the benefit here - you moved the code from text to
> data. In total you decreased the size for this compilation settings
> (e.g. compiler + optimizations) but that might not be always true, right?

It is a marginal saving, but for arrays this size it makes sense to not
have to populate the data into the stack before using it and then
discarding it. This change essentially replaces quite a lot of
instructions that put the data onto the stack so I think it's worth while.

> 
> This has effect on the code readability - line is longer and reader
> would think "why this was made static since it is simple one-time const?".
>

Not sure how to respond to this. If they wonder why it is static const
and don't know why then one would hope they look it up in K&R and
familiarize themselves with C.  It's not so subtle.

Colin
> 
> Best regards,
> Krzysztof
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
  2021-05-05 19:01 [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller Colin King
  2021-05-05 19:41 ` Krzysztof Kozlowski
@ 2021-05-22  2:50 ` Martin K. Petersen
  2021-05-26  4:07 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-05-22  2:50 UTC (permalink / raw)
  To: Colin King
  Cc: Alim Akhtar, Avri Altman, James E . J . Bottomley,
	Martin K . Petersen, Krzysztof Kozlowski, linux-scsi,
	linux-arm-kernel, linux-samsung-soc, kernel-janitors,
	linux-kernel


Colin,

> Don't populate the const array granularity_tbl on the stack but instead it
> static. Makes the object code smaller by 190 bytes:

Applied to 5.14/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
  2021-05-05 19:01 [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller Colin King
  2021-05-05 19:41 ` Krzysztof Kozlowski
  2021-05-22  2:50 ` Martin K. Petersen
@ 2021-05-26  4:07 ` Martin K. Petersen
  2 siblings, 0 replies; 5+ messages in thread
From: Martin K. Petersen @ 2021-05-26  4:07 UTC (permalink / raw)
  To: linux-samsung-soc, Colin King, linux-scsi,
	James E . J . Bottomley, linux-arm-kernel, Krzysztof Kozlowski,
	Avri Altman, Alim Akhtar
  Cc: Martin K . Petersen, kernel-janitors, linux-kernel

On Wed, 5 May 2021 20:01:04 +0100, Colin King wrote:

> Don't populate the const array granularity_tbl on the stack but instead it
> static. Makes the object code smaller by 190 bytes:
> 
> Before:
>    text    data     bss     dec     hex filename
>   25563    6908       0   32471    7ed7 ./drivers/scsi/ufs/ufs-exynos.o
> 
> [...]

Applied to 5.14/scsi-queue, thanks!

[1/1] scsi: ufs: ufs-exynos: make a const array static, makes object smaller
      https://git.kernel.org/mkp/scsi/c/5ac3c649f11c

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-05-26  4:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 19:01 [PATCH] scsi: ufs: ufs-exynos: make a const array static, makes object smaller Colin King
2021-05-05 19:41 ` Krzysztof Kozlowski
2021-05-05 19:49   ` Colin Ian King
2021-05-22  2:50 ` Martin K. Petersen
2021-05-26  4:07 ` Martin K. Petersen

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).