Skip to contentSkip to conversation

x86/intel_pstate: changes in cpufreq_del_cpu for CPU offline

PATCH Superseded Wei Wang 3 participants 11 messages Jun 11, 2015 – Jun 23, 2015

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH v3 7/11 x86/intel_pstate: changes in cpufreq_del_cpu for CPU offline

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
 xen/drivers/cpufreq/cpufreq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
xen/drivers/cpufreq/cpufreq.c +3 -3
index 6003a8c..a8772e8 100644
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
     /* for HW_ALL, stop gov for each core of the _PSD domain */
     /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain */
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all || (cpumask_weight(cpufreq_dom->map) ==
+                   perf->domain_info.num_processors)))
         __cpufreq_governor(policy, CPUFREQ_GOV_STOP);
 
     cpufreq_statistic_exit(cpu);
-    per_cpu(cpufreq_cpu_policy, cpu) = NULL;
     cpumask_clear_cpu(cpu, policy->cpus);
     cpumask_clear_cpu(cpu, cpufreq_dom->map);
 
@@ -349,6 +348,7 @@ int cpufreq_del_cpu(unsigned int cpu)
         free_cpumask_var(policy->cpus);
         xfree(policy);
     }
+    per_cpu(cpufreq_cpu_policy, cpu) = NULL;
 
     /* for the last cpu of the domain, clean room */
     /* It's safe here to free freq_table, drv_data and policy */
Signature · 1 line
1.9.1
#1 lore raw

Hi,

Quoted 15 lines · Wei Wang

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
  xen/drivers/cpufreq/cpufreq.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
xen/drivers/cpufreq/cpufreq.c +0 -0
index 6003a8c..a8772e8 100644

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu) · line 339

Quoted 7 lines
xen/drivers/cpufreq/cpufreq.c +2 -2
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
      /* for HW_ALL, stop gov for each core of the _PSD domain */
      /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain */
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all || (cpumask_weight(cpufreq_dom->map) ==
+                   perf->domain_info.num_processors)))

Based on your patch #6, the field policy contains value which is defined per-cpufreq driver (because you defined internal value). How can you be sure that a driver will never use 0 as a valid value?

Regards,

Signature · 1 line
Julien Grall
#2 lore raw
Quoted 23 lines · Julien Grall
Quoted 15 lines · Wei Wang

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
  xen/drivers/cpufreq/cpufreq.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/cpufreq/cpufreq.c index 6003a8c..a8772e8 100644

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu) · line 337

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
      /* for HW_ALL, stop gov for each core of the _PSD domain */
      /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain

*/

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu)

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +1 -2
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all || (cpumask_weight(cpufreq_dom->map)
Quoted 6 lines

==

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu) · line 339

Quoted 1 line
xen/drivers/cpufreq/cpufreq.c +1 -0
+                   perf->domain_info.num_processors)))

Based on your patch #6, the field policy contains value which is defined per- cpufreq driver (because you defined internal value). How can you be sure that a driver will never use 0 as a valid value?

Hi Julien, what do you mean by "per-cpufreq driver"?

We currently have two P-state drivers. This filed is currently only used by the intel_pstate driver, and the four usable values are:
#define CPUFREQ_POLICY_POWERSAVE (1)
#define CPUFREQ_POLICY_PERFORMANCE (2)
#define CPUFREQ_POLICY_USERSPACE (3)
#define CPUFREQ_POLICY_ONDEMAND (4)

The intel_pstate won't use 0 as a valid value, and the default value is CPUFREQ_POLICY_ONDEMAND. If it's 0, it basically means the old acpi-cpufreq driver is being used.

Best,
Wei

#3 lore raw
Quoted 33 lines · Wei W
Quoted 23 lines · Julien Grall
Quoted 15 lines · Wei Wang

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
   xen/drivers/cpufreq/cpufreq.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/cpufreq/cpufreq.c index 6003a8c..a8772e8 100644

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu) · line 337

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +0 -0
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
       /* for HW_ALL, stop gov for each core of the _PSD domain */
       /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD domain

*/

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu)

Quoted 3 lines
xen/drivers/cpufreq/cpufreq.c +1 -2
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all || (cpumask_weight(cpufreq_dom->map)
Quoted 6 lines

==

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu) · line 339

Quoted 1 line
xen/drivers/cpufreq/cpufreq.c +1 -0
+                   perf->domain_info.num_processors)))

Based on your patch #6, the field policy contains value which is defined per- cpufreq driver (because you defined internal value). How can you be sure that a driver will never use 0 as a valid value?

Hi Julien, what do you mean by "per-cpufreq driver"?

Quoted 7 lines

We currently have two P-state drivers. This filed is currently only used by the intel_pstate driver, and the four usable values are:
#define CPUFREQ_POLICY_POWERSAVE (1)
#define CPUFREQ_POLICY_PERFORMANCE (2)
#define CPUFREQ_POLICY_USERSPACE (3)
#define CPUFREQ_POLICY_ONDEMAND (4)

The intel_pstate won't use 0 as a valid value, and the default value is CPUFREQ_POLICY_ONDEMAND. If it's 0, it basically means the old acpi-cpufreq driver is being used.

You seem to rely on nobody else with use the cpufreq framework... which is wrong. intel_pstate won't be the only possible cpufreq driver. Some ARM developper are working on adding a cpufreq for ARM power management.

You said that CPUFREQ_POLICY_* is specific to the intel driver. But use them in the common code. If any cpufreq driver can use the value, then make it common. Otherwise please move this code outside of the framework.

Regards,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 47 lines · Julien Grall
Quoted 29 lines · Wei W
Quoted 28 lines · Julien Grall
Quoted 18 lines · Wei Wang

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
   xen/drivers/cpufreq/cpufreq.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/cpufreq/cpufreq.c index 6003a8c..a8772e8 100644

xen/drivers/cpufreq/cpufreq.c +0 -0
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
       /* for HW_ALL, stop gov for each core of the _PSD domain */
       /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD
Quoted 1 line

domain

*/

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu)

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +2 -2
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all ||
+ (cpumask_weight(cpufreq_dom->map)

==

Quoted 1 line

+ perf->domain_info.num_processors)))

Quoted 7 lines
Quoted 3 lines

Based on your patch #6, the field policy contains value which is defined per- cpufreq driver (because you defined internal value). How can you be sure that a driver will never use 0 as a valid value?

Hi Julien, what do you mean by "per-cpufreq driver"?

We currently have two P-state drivers. This filed is currently only used by

the intel_pstate driver, and the four usable values are:

Quoted 6 lines

#define CPUFREQ_POLICY_POWERSAVE (1)
#define CPUFREQ_POLICY_PERFORMANCE (2)
#define CPUFREQ_POLICY_USERSPACE (3)
#define CPUFREQ_POLICY_ONDEMAND (4)

The intel_pstate won't use 0 as a valid value, and the default value is

CPUFREQ_POLICY_ONDEMAND. If it's 0, it basically means the old acpi- cpufreq driver is being used.

Quoted 7 lines

You seem to rely on nobody else with use the cpufreq framework... which is wrong. intel_pstate won't be the only possible cpufreq driver. Some ARM developper are working on adding a cpufreq for ARM power management.

You said that CPUFREQ_POLICY_* is specific to the intel driver. But use them in the common code. If any cpufreq driver can use the value, then make it common. Otherwise please move this code outside of the framework.

To me, we can deal with your concerns by
1) renaming the previously mentioned things to be intel_pstate specific;
2) moving them to a new header file.

Jan, please also ACK if you agree on these changes.

Best,
Wei

#5 lore raw
Quoted 57 lines
Quoted 1 line
Quoted 1 line · On 15.06.15 at 02:31, <[email protected]> wrote:
Quoted 47 lines · Julien Grall
Quoted 29 lines · Wei W
Quoted 28 lines · Julien Grall
Quoted 18 lines · Wei Wang

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

---
   xen/drivers/cpufreq/cpufreq.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/xen/drivers/cpufreq/cpufreq.c index 6003a8c..a8772e8 100644

xen/drivers/cpufreq/cpufreq.c +0 -0
@@ -335,12 +335,11 @@ int cpufreq_del_cpu(unsigned int cpu)
 
       /* for HW_ALL, stop gov for each core of the _PSD domain */
       /* for SW_ALL & SW_ANY, stop gov for the 1st core of the _PSD
Quoted 1 line

domain

*/

xen/drivers/cpufreq/cpufreq.c int cpufreq_del_cpu(unsigned int cpu)

Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +2 -2
-    if (hw_all || (cpumask_weight(cpufreq_dom->map) ==
-                   perf->domain_info.num_processors))
+    if (!policy->policy && (hw_all ||
+ (cpumask_weight(cpufreq_dom->map)

==

Quoted 1 line

+ perf->domain_info.num_processors)))

Quoted 7 lines
Quoted 3 lines

Based on your patch #6, the field policy contains value which is defined per- cpufreq driver (because you defined internal value). How can you be sure that a driver will never use 0 as a valid value?

Hi Julien, what do you mean by "per-cpufreq driver"?

We currently have two P-state drivers. This filed is currently only used by

the intel_pstate driver, and the four usable values are:

Quoted 6 lines

#define CPUFREQ_POLICY_POWERSAVE (1)
#define CPUFREQ_POLICY_PERFORMANCE (2)
#define CPUFREQ_POLICY_USERSPACE (3)
#define CPUFREQ_POLICY_ONDEMAND (4)

The intel_pstate won't use 0 as a valid value, and the default value is

CPUFREQ_POLICY_ONDEMAND. If it's 0, it basically means the old acpi- cpufreq driver is being used.

Quoted 7 lines

You seem to rely on nobody else with use the cpufreq framework... which is wrong. intel_pstate won't be the only possible cpufreq driver. Some ARM developper are working on adding a cpufreq for ARM power management.

You said that CPUFREQ_POLICY_* is specific to the intel driver. But use them in the common code. If any cpufreq driver can use the value, then make it common. Otherwise please move this code outside of the framework.

Quoted 5 lines

To me, we can deal with your concerns by
1) renaming the previously mentioned things to be intel_pstate specific;
2) moving them to a new header file.

Jan, please also ACK if you agree on these changes.

Your proposal doesn't address the use of the constants in common code, as observed by Julien.

Jan

#6 lore raw
In reply to Wei Wang
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:28, <[email protected]> wrote:

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

Apart from what was already said on this patch, I think it is placed too late in this series (should precede patch 6) or, even better, not needed at all: ->exit() gets passed the policy being cleaned up, so I don't follow why the driver needs to consult the per-CPU field to obtain it.

Plus, if the patch is to be kept, the description suggesting this to be a problem at system shutdown only is wrong - it can equally well happen while offlining a CPU. Just saying that the pointer is still needed would be sufficient.

Jan

#7 lore raw
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:28, <[email protected]> wrote:

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

Quoted 8 lines

Apart from what was already said on this patch, I think it is placed too late in this series (should precede patch 6) or, even better, not needed at all: ->exit() gets passed the policy being cleaned up, so I don't follow why the driver needs to consult the per-CPU field to obtain it.

Plus, if the patch is to be kept, the description suggesting this to be a problem at system shutdown only is wrong - it can equally well happen while offlining a CPU. Just saying that the pointer is still needed would be sufficient.

It's needed. When unplugging a CPU, the intel_pstate driver sets it to run with the lowest P-state.

Best,
Wei

#8 lore raw
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.06.15 at 08:16, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:28, <[email protected]> wrote:

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

Apart from what was already said on this patch, I think it is placed too late in this series (should precede patch 6) or, even better, not needed at all: ->exit() gets passed the policy being cleaned up, so I don't follow why the driver needs to consult the per-CPU field to obtain it.

Quoted 6 lines
Quoted 3 lines

Plus, if the patch is to be kept, the description suggesting this to be a problem at system shutdown only is wrong - it can equally well happen while offlining a CPU. Just saying that the pointer is still needed would be sufficient.

It's needed. When unplugging a CPU, the intel_pstate driver sets it to run with the lowest P-state.

I understand the latter, but this doesn't explain why you can't do what I suggested above.

Jan

#9 lore raw
Quoted 16 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.06.15 at 08:16, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:28, <[email protected]> wrote:

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

Quoted 8 lines
Quoted 8 lines

Apart from what was already said on this patch, I think it is placed too late in this series (should precede patch 6) or, even better, not needed at all: ->exit() gets passed the policy being cleaned up, so I don't follow why the driver needs to consult the per-CPU field to obtain it.

Plus, if the patch is to be kept, the description suggesting this to be a problem at system shutdown only is wrong - it can equally well happen while offlining a CPU. Just saying that the pointer is still needed

Quoted 7 lines

would be sufficient.

Quoted 3 lines

It's needed. When unplugging a CPU, the intel_pstate driver sets it to run with the lowest P-state.

I understand the latter, but this doesn't explain why you can't do what I suggested above.

Because the "->exit()" needs to call "intel_pstate_set_pstate()" which does not receive "policy" as a parameter. "intel_pstate_set_pstate()" is also called by another function without passing "policy". So I think it is simpler to just change the order of NULLing the pointer, instead of changing more code.

Best,
Wei

#10 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 23.06.15 at 10:21, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.06.15 at 08:16, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:28, <[email protected]> wrote:

cpufreq_cpu_policy is used in intel_pstate_set_pstate(), so we change to NULL it after the call of cpufreq_driver->exit. Otherwise, a calltrace will show up on your screen due to the reference of a NULL pointer when you power down the system.

Quoted 8 lines
Quoted 8 lines

Apart from what was already said on this patch, I think it is placed too late in this series (should precede patch 6) or, even better, not needed at all: ->exit() gets passed the policy being cleaned up, so I don't follow why the driver needs to consult the per-CPU field to obtain it.

Plus, if the patch is to be kept, the description suggesting this to be a problem at system shutdown only is wrong - it can equally well happen while offlining a CPU. Just saying that the pointer is still needed

would be sufficient.

Quoted 3 lines

It's needed. When unplugging a CPU, the intel_pstate driver sets it to run with the lowest P-state.

Quoted 8 lines
Quoted 2 lines

I understand the latter, but this doesn't explain why you can't do what I suggested above.

Because the "->exit()" needs to call "intel_pstate_set_pstate()" which does not receive "policy" as a parameter. "intel_pstate_set_pstate()" is also called by another function without passing "policy". So I think it is simpler to just change the order of NULLing the pointer, instead of changing more code.

I yet have to see the amount of differences to the Linux original to be convinced that this is the better approach, so let's see how the next version of the series is going to look like.

Jan