Skip to contentSkip to conversation

cpufreq, powernow: enable/disable core performance boost for all cpus in policy

PATCH In review Jacob Shin 3 participants 9 messages Jun 19, 2013 – Jun 20, 2013

lore
Share & tools
lore

Jacob Shin

author
#0 lore raw

PATCH 1/2 cpufreq, powernow: enable/disable core performance boost for all cpus in policy

Currently, enable/disable turbo mode on AMD is broken:

$ xenpm enable-turbo-mode 0 <-- works and proper CPU MSR bit is set
$ xenpm enable-turbo-mode 1 <-- silently broken, MSR bit not set

Since ->turbo is per policy, when user requests to enable/disable turbo mode, we need to set the bit in all of the ->cpus that this policy affects.

---
 xen/arch/x86/acpi/cpufreq/powernow.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/acpi/cpufreq/powernow.c +1 -1
index 2c9fea2..81ba17f 100644
@@ -85,7 +85,7 @@ static int powernow_cpufreq_update (int cpuid,
     if (!cpumask_test_cpu(cpuid, &cpu_online_map))
         return -EINVAL;
 
-    on_selected_cpus(cpumask_of(cpuid), update_cpb, policy, 1);
+    on_selected_cpus(policy->cpus, update_cpb, policy, 1);
 
     return 0;
 }
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH 2/2 cpufreq: fix turbo mode state reporting

Currently we report back 0 or 1, which is broken since xenpm expects CPUFREQ_TURBO_DISABLED, CPUFREQ_TURBO_UNSUPPORTED, or CPUFREQ_TURBO_ENABLED. Report back actual policy->turbo value instead.

---
 xen/drivers/cpufreq/utility.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
xen/drivers/cpufreq/utility.c +4 -1
index 3dd70e2..1ff5e29 100644
@@ -428,7 +428,10 @@ int cpufreq_get_turbo_status(int cpuid)
     struct cpufreq_policy *policy;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    return policy && policy->turbo;
+    if (!policy)
+        return CPUFREQ_TURBO_UNSUPPORTED;
+
+    return policy->turbo;
 }
 
 /*********************************************************************
Signature · 1 line
1.7.9.5
author
#5 lore raw
In reply to Jacob Shin
Quoted 8 lines · Jacob Shin

Currently, enable/disable turbo mode on AMD is broken:

$ xenpm enable-turbo-mode 0 <-- works and proper CPU MSR bit is set
$ xenpm enable-turbo-mode 1 <-- silently broken, MSR bit not set

Since ->turbo is per policy, when user requests to enable/disable turbo mode, we need to set the bit in all of the ->cpus that this policy affects.

Sorry, I'll have to re-do this [PATCH 1/2], as it does not solve the problem on platforms with a separate policy per CPU.

1. We'll have to either globally enable/disable boost for all CPUs, or
2. [if there is a easy way to do so] find all Node siblings and set their bits and policy->turbo as well.

[PATCH 2/2] is still valid.

Thanks,

Quoted 20 lines
---
 xen/arch/x86/acpi/cpufreq/powernow.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/acpi/cpufreq/powernow.c +1 -1
index 2c9fea2..81ba17f 100644
@@ -85,7 +85,7 @@ static int powernow_cpufreq_update (int cpuid,
     if (!cpumask_test_cpu(cpuid, &cpu_online_map))
         return -EINVAL;
 
-    on_selected_cpus(cpumask_of(cpuid), update_cpb, policy, 1);
+    on_selected_cpus(policy->cpus, update_cpb, policy, 1);
 
     return 0;
 }
Signature · 1 line
1.7.9.5
#6 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Jacob Shin
Quoted 5 lines · Jacob Shin

Currently, enable/disable turbo mode on AMD is broken:

$ xenpm enable-turbo-mode 0 <-- works and proper CPU MSR bit is set
$ xenpm enable-turbo-mode 1 <-- silently broken, MSR bit not set
Quoted 6 lines
Quoted 3 lines

Since ->turbo is per policy, when user requests to enable/disable turbo mode, we need to set the bit in all of the ->cpus that this policy affects.

Sorry, I'll have to re-do this [PATCH 1/2], as it does not solve the problem on platforms with a separate policy per CPU.

But isn't a separate policy per CPU meaning that indeed you want to only fiddle with the one CPU that the policy is getting changed for?

Quoted 1 line

1. We'll have to either globally enable/disable boost for all CPUs, or

That's clearly not a good path, as the interface is specifically intending to allow per-policy control.

Quoted 2 lines

2. [if there is a easy way to do so] find all Node siblings and set their bits and policy->turbo as well.

That would be the way to go, pending clarification on the above.

Jan

#2 lore raw

Re: [PATCH 2/2] cpufreq: fix turbo mode state reporting

In reply to Jacob Shin
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Jacob Shin

Currently we report back 0 or 1, which is broken since xenpm expects CPUFREQ_TURBO_DISABLED, CPUFREQ_TURBO_UNSUPPORTED, or CPUFREQ_TURBO_ENABLED. Report back actual policy->turbo value instead.

I think that it's xenpm that's wrong here - the three constants above aren't exposed in public headers, and hence aren't part of the ABI. Furthermore the structure member name that the result of this function gets stored into is "turbo_enabled", which also suggests a boolean value to me. I.e. if we want to change the value set that the hypervisor may return here, the field should also get renamed, and the value set exposed.

xen/drivers/cpufreq/utility.c int cpufreq_get_turbo_status(int cpuid) · line 434

Quoted 11 lines
xen/drivers/cpufreq/utility.c +4 -1
@@ -428,7 +428,10 @@ int cpufreq_get_turbo_status(int cpuid)
     struct cpufreq_policy *policy;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    return policy && policy->turbo;
+    if (!policy)
+        return CPUFREQ_TURBO_UNSUPPORTED;
+
+    return policy->turbo;

Nevertheless this would need adjustment even for the boolean value case:

- return policy && policy->turbo;
+ return policy && policy->turbo == CPUFREQ_TURBO_ENABLED;

Jan

author
#3 lore raw

Re: [PATCH 2/2] cpufreq: fix turbo mode state reporting

Quoted 5 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Jacob Shin

Currently we report back 0 or 1, which is broken since xenpm expects CPUFREQ_TURBO_DISABLED, CPUFREQ_TURBO_UNSUPPORTED, or CPUFREQ_TURBO_ENABLED. Report back actual policy->turbo value instead.

Quoted 7 lines

I think that it's xenpm that's wrong here - the three constants above aren't exposed in public headers, and hence aren't part of the ABI. Furthermore the structure member name that the result of this function gets stored into is "turbo_enabled", which also suggests a boolean value to me. I.e. if we want to change the value set that the hypervisor may return here, the field should also get renamed, and the value set exposed.

Okay I'll fix xenpm instead.

Quoted 16 lines

xen/drivers/cpufreq/utility.c int cpufreq_get_turbo_status(int cpuid) · line 434

Quoted 12 lines
xen/drivers/cpufreq/utility.c +4 -1
@@ -428,7 +428,10 @@ int cpufreq_get_turbo_status(int cpuid)
     struct cpufreq_policy *policy;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    return policy && policy->turbo;
+    if (!policy)
+        return CPUFREQ_TURBO_UNSUPPORTED;
+
+    return policy->turbo;

Nevertheless this would need adjustment even for the boolean value case:

Review

Quoted 2 lines
(quoted diff) +1 -1
-    return policy && policy->turbo;
+    return policy && policy->turbo == CPUFREQ_TURBO_ENABLED;

Yup that's correct.

Thanks,

author
#7 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Jacob Shin
Quoted 8 lines · Jacob Shin

Currently, enable/disable turbo mode on AMD is broken:

$ xenpm enable-turbo-mode 0 <-- works and proper CPU MSR bit is set
$ xenpm enable-turbo-mode 1 <-- silently broken, MSR bit not set

Since ->turbo is per policy, when user requests to enable/disable turbo mode, we need to set the bit in all of the ->cpus that this policy affects.

Quoted 6 lines
Quoted 2 lines

Sorry, I'll have to re-do this [PATCH 1/2], as it does not solve the problem on platforms with a separate policy per CPU.

But isn't a separate policy per CPU meaning that indeed you want to only fiddle with the one CPU that the policy is getting changed for?

Yes, this is okay if the end user realizes that on current AMD parts, disabling turbo on one core means that it affects all other sibling cores that are on the same node.

$ xenpm disable-turbo-mode 0 </-- hardware bit gets set on CPU0
$ xenpm get-cpufreq-para
...
CPU0
turbo mode: disabled
...
CPU1
turbo mode: enabled

But since CPU0 and CPU1 are in the same Node, in reality CPU1 also in affect has turbo mode disabled.

If this is okay, then I think the above patch will be fine.

Quoted 5 lines
Quoted 2 lines

1. We'll have to either globally enable/disable boost for all CPUs, or

That's clearly not a good path, as the interface is specifically intending to allow per-policy control.

Okay.

Quoted 5 lines
Quoted 3 lines

2. [if there is a easy way to do so] find all Node siblings and set their bits and policy->turbo as well.

That would be the way to go, pending clarification on the above.

Let me know what you think about my blurb above.

Thanks!

#8 lore raw
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Jacob Shin
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Jacob Shin
Quoted 8 lines · Jacob Shin

Currently, enable/disable turbo mode on AMD is broken:

$ xenpm enable-turbo-mode 0 <-- works and proper CPU MSR bit is set
$ xenpm enable-turbo-mode 1 <-- silently broken, MSR bit not set

Since ->turbo is per policy, when user requests to enable/disable turbo mode, we need to set the bit in all of the ->cpus that this policy affects.

Quoted 6 lines
Quoted 2 lines

Sorry, I'll have to re-do this [PATCH 1/2], as it does not solve the problem on platforms with a separate policy per CPU.

But isn't a separate policy per CPU meaning that indeed you want to only fiddle with the one CPU that the policy is getting changed for?

Yes, this is okay if the end user realizes that on current AMD parts, disabling turbo on one core means that it affects all other sibling cores that are on the same node.

$ xenpm disable-turbo-mode 0 </-- hardware bit gets set on CPU0
$ xenpm get-cpufreq-para
...
CPU0
turbo mode: disabled
...
CPU1
turbo mode: enabled
Quoted 4 lines

But since CPU0 and CPU1 are in the same Node, in reality CPU1 also in affect has turbo mode disabled.

If this is okay, then I think the above patch will be fine.

No, this is not okay, but it is also not okay to reflect such a setup with a per-core policy. Of course things are going to become difficult if frequency selection can be per-core, but turbo mode enabling requires that all cores have it enabled in order for it to actually be used.

Jan

#4 lore raw

Re: [PATCH 2/2] cpufreq: fix turbo mode state reporting

In reply to Jan Beulich

Sorry for late reply, just notice this thread. Some comments inline below.

Quoted 6 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Jacob Shin

Currently we report back 0 or 1, which is broken since xenpm expects CPUFREQ_TURBO_DISABLED, CPUFREQ_TURBO_UNSUPPORTED, or CPUFREQ_TURBO_ENABLED. Report back actual policy->turbo value instead.

Quoted 8 lines

I think that it's xenpm that's wrong here - the three constants above aren't exposed in public headers, and hence aren't part of the ABI. Furthermore the structure member name that the result of this function gets stored into is "turbo_enabled", which also suggests a boolean value to me. I.e. if we want to change the value set that the hypervisor may return here, the field should also get renamed, and the value set exposed.

IMHO this patch itself is OK, just need minor update at xenpm and add the 3 constants to public headers.

Tristate (cap, enable/disable) exposes more info to user than bool (enable/disable), and the original semantics of the ABI is tristate (though bug at Xen cpufreq side). As for 'turbo_enabled', rename it as 'turbo' is OK.

Thanks,
Jinsong

Quoted 19 lines

xen/drivers/cpufreq/utility.c int cpufreq_get_turbo_status(int cpuid) · line 434

Quoted 11 lines
xen/drivers/cpufreq/utility.c +4 -1
@@ -428,7 +428,10 @@ int cpufreq_get_turbo_status(int cpuid)
     struct cpufreq_policy *policy;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    return policy && policy->turbo;
+    if (!policy)
+        return CPUFREQ_TURBO_UNSUPPORTED;
+
+    return policy->turbo;

Nevertheless this would need adjustment even for the boolean value case:

(quoted diff) +1 -1
-    return policy && policy->turbo;
+    return policy && policy->turbo == CPUFREQ_TURBO_ENABLED;

Jan