public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cpufreq: longhaul: Make array speeds static const
@ 2022-11-03 13:21 Colin Ian King
  2022-11-03 14:15 ` Joe Perches
  2022-11-03 14:37 ` Viresh Kumar
  0 siblings, 2 replies; 5+ messages in thread
From: Colin Ian King @ 2022-11-03 13:21 UTC (permalink / raw)
  To: Rafael J . Wysocki, Viresh Kumar, linux-pm; +Cc: kernel-janitors, linux-kernel

Don't populate the read-only array speeds on the stack but instead
make it static. Also makes the object code a little smaller.

Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 drivers/cpufreq/longhaul.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
index 3e000e1a75c6..25f8ef7bac47 100644
--- a/drivers/cpufreq/longhaul.c
+++ b/drivers/cpufreq/longhaul.c
@@ -407,7 +407,7 @@ static int guess_fsb(int mult)
 {
 	int speed = cpu_khz / 1000;
 	int i;
-	int speeds[] = { 666, 1000, 1333, 2000 };
+	static const int speeds[] = { 666, 1000, 1333, 2000 };
 	int f_max, f_min;
 
 	for (i = 0; i < 4; i++) {
-- 
2.38.1


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

* Re: [PATCH] cpufreq: longhaul: Make array speeds static const
  2022-11-03 13:21 [PATCH] cpufreq: longhaul: Make array speeds static const Colin Ian King
@ 2022-11-03 14:15 ` Joe Perches
  2022-11-03 14:30   ` Colin King (gmail)
  2022-11-03 14:37 ` Viresh Kumar
  1 sibling, 1 reply; 5+ messages in thread
From: Joe Perches @ 2022-11-03 14:15 UTC (permalink / raw)
  To: Colin Ian King, Rafael J . Wysocki, Viresh Kumar, linux-pm
  Cc: kernel-janitors, linux-kernel

On Thu, 2022-11-03 at 13:21 +0000, Colin Ian King wrote:
> Don't populate the read-only array speeds on the stack but instead
> make it static. Also makes the object code a little smaller.
[]
> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
[]
> @@ -407,7 +407,7 @@ static int guess_fsb(int mult)
>  {
>  	int speed = cpu_khz / 1000;
>  	int i;
> -	int speeds[] = { 666, 1000, 1333, 2000 };
> +	static const int speeds[] = { 666, 1000, 1333, 2000 };
>  	int f_max, f_min;
>  
>  	for (i = 0; i < 4; i++) {

style trivia:  the loop test is probably better using ARRAY_SIZE

	for (i = 0; i < ARRAY_SIZE(speeds); i++)


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

* Re: [PATCH] cpufreq: longhaul: Make array speeds static const
  2022-11-03 14:15 ` Joe Perches
@ 2022-11-03 14:30   ` Colin King (gmail)
  0 siblings, 0 replies; 5+ messages in thread
From: Colin King (gmail) @ 2022-11-03 14:30 UTC (permalink / raw)
  To: Joe Perches, Rafael J . Wysocki, Viresh Kumar, linux-pm
  Cc: kernel-janitors, linux-kernel

On 03/11/2022 14:15, Joe Perches wrote:
> On Thu, 2022-11-03 at 13:21 +0000, Colin Ian King wrote:
>> Don't populate the read-only array speeds on the stack but instead
>> make it static. Also makes the object code a little smaller.
> []
>> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
> []
>> @@ -407,7 +407,7 @@ static int guess_fsb(int mult)
>>   {
>>   	int speed = cpu_khz / 1000;
>>   	int i;
>> -	int speeds[] = { 666, 1000, 1333, 2000 };
>> +	static const int speeds[] = { 666, 1000, 1333, 2000 };
>>   	int f_max, f_min;
>>   
>>   	for (i = 0; i < 4; i++) {
> 
> style trivia:  the loop test is probably better using ARRAY_SIZE
> 
> 	for (i = 0; i < ARRAY_SIZE(speeds); i++)
> 
I'll send a V2 for that. Good idea.

Colin

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

* Re: [PATCH] cpufreq: longhaul: Make array speeds static const
  2022-11-03 13:21 [PATCH] cpufreq: longhaul: Make array speeds static const Colin Ian King
  2022-11-03 14:15 ` Joe Perches
@ 2022-11-03 14:37 ` Viresh Kumar
  2022-11-03 14:46   ` Colin King (gmail)
  1 sibling, 1 reply; 5+ messages in thread
From: Viresh Kumar @ 2022-11-03 14:37 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Rafael J . Wysocki, linux-pm, kernel-janitors, linux-kernel

On 03-11-22, 13:21, Colin Ian King wrote:
> Don't populate the read-only array speeds on the stack but instead
> make it static. Also makes the object code a little smaller.

How will that benefit ? I am just looking for a valid answer in commit log.

> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
>  drivers/cpufreq/longhaul.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
> index 3e000e1a75c6..25f8ef7bac47 100644
> --- a/drivers/cpufreq/longhaul.c
> +++ b/drivers/cpufreq/longhaul.c
> @@ -407,7 +407,7 @@ static int guess_fsb(int mult)
>  {
>  	int speed = cpu_khz / 1000;
>  	int i;
> -	int speeds[] = { 666, 1000, 1333, 2000 };
> +	static const int speeds[] = { 666, 1000, 1333, 2000 };

Why not make it global then ?

-- 
viresh

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

* Re: [PATCH] cpufreq: longhaul: Make array speeds static const
  2022-11-03 14:37 ` Viresh Kumar
@ 2022-11-03 14:46   ` Colin King (gmail)
  0 siblings, 0 replies; 5+ messages in thread
From: Colin King (gmail) @ 2022-11-03 14:46 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: Rafael J . Wysocki, linux-pm, kernel-janitors, linux-kernel

On 03/11/2022 14:37, Viresh Kumar wrote:
> On 03-11-22, 13:21, Colin Ian King wrote:
>> Don't populate the read-only array speeds on the stack but instead
>> make it static. Also makes the object code a little smaller.
> 
> How will that benefit ? I am just looking for a valid answer in commit log.

When the array is non-static there will be some executable code to put 
these values into the array that's on the stack (e.g. at run time). When 
it is static the array is filled at compile time and there is no 
executable code required to populate the array at run time.



> 
>> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
>> ---
>>   drivers/cpufreq/longhaul.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c
>> index 3e000e1a75c6..25f8ef7bac47 100644
>> --- a/drivers/cpufreq/longhaul.c
>> +++ b/drivers/cpufreq/longhaul.c
>> @@ -407,7 +407,7 @@ static int guess_fsb(int mult)
>>   {
>>   	int speed = cpu_khz / 1000;
>>   	int i;
>> -	int speeds[] = { 666, 1000, 1333, 2000 };
>> +	static const int speeds[] = { 666, 1000, 1333, 2000 };
> 
> Why not make it global then ?

Making it static inside the function limits the scope to the function 
and so it's not globally visible. We don't like making stuff global 
unless we really need to.

Colin



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

end of thread, other threads:[~2022-11-03 14:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-03 13:21 [PATCH] cpufreq: longhaul: Make array speeds static const Colin Ian King
2022-11-03 14:15 ` Joe Perches
2022-11-03 14:30   ` Colin King (gmail)
2022-11-03 14:37 ` Viresh Kumar
2022-11-03 14:46   ` Colin King (gmail)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox