thermal: intel_powerclamp: Use first online CPU as control_cpu
PATCH 1/1 thermal: intel_powerclamp: Use first online CPU as control_cpu
From: Rafael J. Wysocki <[email protected]>
Commit 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash") fixed an issue related to using smp_processor_id() in preemptible context by replacing it with a pair of get_cpu()/put_cpu(), but what is needed there really is any online CPU and not necessarily the one currently running the code. Arguably, getting the one that's running the code in there is confusing.
For this reason, simply give the control CPU role to the first online one which automatically will be CPU0 if it is online, so one check can be dropped from the code for an added benefit.
--- drivers/thermal/intel/intel_powerclamp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/thermal/intel/intel_powerclamp.c +1 -5
@@ -516,11 +516,7 @@ static int start_power_clamp(void)cpus_read_lock ();/* prefer BSP */ - control_cpu =0 ; -if (!cpu_online (control_cpu)) { - control_cpu =get_cpu (); -put_cpu (); - } + control_cpu =cpumask_first (cpu_online_mask); clamping = true;schedule_delayed_work (&poll_pkg_cstate_work,0 );
Quoted 25 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Commit
68b99e94a4a2("thermal:intel_powerclamp: Useget_cpu()instead ofsmp_processor_id()to avoid crash") fixed an issue related to usingsmp_processor_id()in preemptible context by replacing it with a pair of get_cpu()/put_cpu(), but what is needed there really is any online CPU and not necessarily the one currently running the code. Arguably, getting the one that's running the code in there is confusing.For this reason, simply give the control CPU role to the first online one which automatically will be CPU0 if it is online, so one check can be dropped from the code for an added benefit.
Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/intel/intel_powerclamp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)Index:
linux-pm/drivers/thermal/intel/intel_powerclamp.c
===================================================================
drivers/thermal/intel/intel_powerclamp.c static int start_power_clamp(void) · line 518
Quoted 3 lines
drivers/thermal/intel/intel_powerclamp.c +0
-0@@ -516,11 +516,7 @@ static int start_power_clamp(void)cpus_read_lock ();/* prefer BSP */
Above comment line is not true any more, might delete it as well?
thanks,
Chenyu
Quoted 12 lines
drivers/thermal/intel/intel_powerclamp.c +1
-5- control_cpu =0 ; -if (!cpu_online (control_cpu)) { - control_cpu =get_cpu (); -put_cpu (); - } + control_cpu =cpumask_first (cpu_online_mask); clamping = true;schedule_delayed_work (&poll_pkg_cstate_work,0 );
Rafael J. Wysocki
maintainerQuoted 29 lines · Chen Yu
Quoted 27 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Commit
68b99e94a4a2("thermal:intel_powerclamp: Useget_cpu()instead ofsmp_processor_id()to avoid crash") fixed an issue related to usingsmp_processor_id()in preemptible context by replacing it with a pair of get_cpu()/put_cpu(), but what is needed there really is any online CPU and not necessarily the one currently running the code. Arguably, getting the one that's running the code in there is confusing.For this reason, simply give the control CPU role to the first online one which automatically will be CPU0 if it is online, so one check can be dropped from the code for an added benefit.
Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/intel/intel_powerclamp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)Index:
linux-pm/drivers/thermal/intel/intel_powerclamp.c
===================================================================drivers/thermal/intel/intel_powerclamp.c +0
-0@@ -516,11 +516,7 @@ static int start_power_clamp(void)cpus_read_lock ();
Quoted 2 lines
drivers/thermal/intel/intel_powerclamp.c static int start_power_clamp(void) · line 518
Quoted 1 line
drivers/thermal/intel/intel_powerclamp.c +0
-0/* prefer BSP */ Above comment line is not true any more, might delete it as well?
Well, why not? If CPU0 is the BSP, it is still preferred as before.
Quoted 1 line
Reviewed-by Chen Yu <[email protected]>
Thanks!
Quoted 12 lines
Quoted 12 lines
drivers/thermal/intel/intel_powerclamp.c +1
-5- control_cpu =0 ; -if (!cpu_online (control_cpu)) { - control_cpu =get_cpu (); -put_cpu (); - } + control_cpu =cpumask_first (cpu_online_mask); clamping = true;schedule_delayed_work (&poll_pkg_cstate_work,0 );
Quoted 30 lines · Rafael J. Wysocki
Quoted 29 lines · Chen Yu
Quoted 27 lines · Rafael J. Wysocki
From: Rafael J. Wysocki <[email protected]>
Commit
68b99e94a4a2("thermal:intel_powerclamp: Useget_cpu()instead ofsmp_processor_id()to avoid crash") fixed an issue related to usingsmp_processor_id()in preemptible context by replacing it with a pair of get_cpu()/put_cpu(), but what is needed there really is any online CPU and not necessarily the one currently running the code. Arguably, getting the one that's running the code in there is confusing.For this reason, simply give the control CPU role to the first online one which automatically will be CPU0 if it is online, so one check can be dropped from the code for an added benefit.
Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")Signed-off-by Rafael J. Wysocki <[email protected]>--- drivers/thermal/intel/intel_powerclamp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)Index:
linux-pm/drivers/thermal/intel/intel_powerclamp.c
===================================================================drivers/thermal/intel/intel_powerclamp.c +0
-0@@ -516,11 +516,7 @@ static int start_power_clamp(void)cpus_read_lock ();
Quoted 5 lines
Quoted 2 lines
drivers/thermal/intel/intel_powerclamp.c static int start_power_clamp(void) · line 518
Quoted 1 line
drivers/thermal/intel/intel_powerclamp.c +0
-0/* prefer BSP */ Above comment line is not true any more, might delete it as well?
Well, why not? If CPU0 is the BSP, it is still preferred as before.
I see. Got it.
thanks,
Chenyu
Quoted 16 lines
Quoted 1 line
Reviewed-by Chen Yu <[email protected]>Thanks!
Quoted 12 lines
Quoted 12 lines
drivers/thermal/intel/intel_powerclamp.c +1
-5- control_cpu =0 ; -if (!cpu_online (control_cpu)) { - control_cpu =get_cpu (); -put_cpu (); - } + control_cpu =cpumask_first (cpu_online_mask); clamping = true;schedule_delayed_work (&poll_pkg_cstate_work,0 );