Skip to contentSkip to conversation

thermal: intel_powerclamp: Use first online CPU as control_cpu

PATCH In review Rafael J. Wysocki 3 participants 4 messages Oct 13, 2022 Thermal

lore
Share & tools
lore
#0 lore raw

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.

Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")
---
 drivers/thermal/intel/intel_powerclamp.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
drivers/thermal/intel/intel_powerclamp.c +1 -5
Index: linux-pm/drivers/thermal/intel/intel_powerclamp.c
===================================================================
@@ -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);
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Rafael J. Wysocki

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.

Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")
---
 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);
#2 lore raw
Quoted 29 lines · Chen Yu
Quoted 27 lines · Rafael J. Wysocki

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.

Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")
---
 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

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);
#3 lore raw
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: 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.

Fixes 68b99e94a4a2 ("thermal: intel_powerclamp: Use get_cpu() instead of smp_processor_id() to avoid crash")
---
 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

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