Skip to contentSkip to conversation

cpufreq, xenpm: fix cpufreq and xenpm mismatch

PATCH In review Jacob Shin 3 participants 4 messages Jun 20, 2013 – Jun 21, 2013

lore
Share & tools
lore

Jacob Shin

author
#0 lore raw

PATCH v2 1/2 cpufreq, xenpm: fix cpufreq and xenpm mismatch

Currently cpufreq and xenpm are out of sync. Fix cpufreq reporting of if turbo mode is enabled or not. Fix xenpm to not decode for tristate, but a boolean.

---
 tools/misc/xenpm.c            |   14 +++-----------
 xen/drivers/cpufreq/utility.c |    2 +-
 2 files changed, 4 insertions(+), 12 deletions(-)
tools/misc/xenpm.c +3 -11
index b5f1383..2e57f1f 100644
@@ -31,10 +31,6 @@
 
 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
 
-#define CPUFREQ_TURBO_DISABLED      -1
-#define CPUFREQ_TURBO_UNSUPPORTED   0
-#define CPUFREQ_TURBO_ENABLED       1
-
 static xc_interface *xc_handle;
 static unsigned int max_cpu_nr;
 
@@ -699,13 +695,9 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
            p_cpufreq->scaling_max_freq,
            p_cpufreq->scaling_min_freq,
            p_cpufreq->scaling_cur_freq);
-    if (p_cpufreq->turbo_enabled != CPUFREQ_TURBO_UNSUPPORTED) {
-           printf("turbo mode           : ");
-           if (p_cpufreq->turbo_enabled == CPUFREQ_TURBO_ENABLED)
-               printf("enabled\n");
-           else
-               printf("disabled\n");
-    }
+
+    printf("turbo mode           : %s\n",
+           p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a");
     printf("\n");
 }
 
xen/drivers/cpufreq/utility.c +1 -1
index 3dd70e2..519f862 100644
@@ -428,7 +428,7 @@ int cpufreq_get_turbo_status(int cpuid)
     struct cpufreq_policy *policy;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    return policy && policy->turbo;
+    return policy && policy->turbo == CPUFREQ_TURBO_ENABLED;
 }
 
 /*********************************************************************
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 2/2 cpufreq, powernow: enable/disable core performance boost for all CPUs in the Node

Since disabling turbo mode on one CPU also affect all other sibling CPUs in the same Node, we need to call update_cpb on all CPUs in the same node.

---
 xen/arch/x86/acpi/cpufreq/powernow.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
xen/arch/x86/acpi/cpufreq/powernow.c +15 -4
index 2c9fea2..3b5507a 100644
@@ -29,6 +29,7 @@
 #include <xen/cpumask.h>
 #include <xen/timer.h>
 #include <xen/xmalloc.h>
+#include <xen/numa.h>
 #include <asm/bug.h>
 #include <asm/msr.h>
 #include <asm/io.h>
@@ -82,10 +83,20 @@ static void update_cpb(void *data)
 static int powernow_cpufreq_update (int cpuid,
 				     struct cpufreq_policy *policy)
 {
-    if (!cpumask_test_cpu(cpuid, &cpu_online_map))
-        return -EINVAL;
-
-    on_selected_cpus(cpumask_of(cpuid), update_cpb, policy, 1);
+    unsigned int cpu;
+    cpumask_t cpus;
+
+    cpumask_and(&cpus, &cpu_online_map, &node_to_cpumask[cpu_to_node[cpuid]]);
+    on_selected_cpus(&cpus, update_cpb, policy, 1);
+
+    if (!cpumask_equal(policy->cpus, &cpus)) {
+        ASSERT(cpumask_subset(policy->cpus, &cpus));
+        for_each_cpu(cpu, &cpus) {
+            struct cpufreq_policy *p;
+            p = per_cpu(cpufreq_cpu_policy, cpu);
+            p->turbo = policy->turbo;
+        }
+    }
 
     return 0;
 }
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH V2 2/2] cpufreq, powernow: enable/disable core performance boost for all CPUs in the Node

Quoted 35 lines · Jacob Shin

Since disabling turbo mode on one CPU also affect all other sibling CPUs in the same Node, we need to call update_cpb on all CPUs in the same node.

---
 xen/arch/x86/acpi/cpufreq/powernow.c |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/xen/arch/x86/acpi/cpufreq/powernow.c index 2c9fea2..3b5507a 100644

xen/arch/x86/acpi/cpufreq/powernow.c +5 -4
@@ -29,6 +29,7 @@
 #include <xen/cpumask.h>
 #include <xen/timer.h>
 #include <xen/xmalloc.h>
+#include <xen/numa.h>
 #include <asm/bug.h>
 #include <asm/msr.h>
 #include <asm/io.h>
@@ -82,10 +83,20 @@ static void update_cpb(void *data)
 static int powernow_cpufreq_update (int cpuid,
 				     struct cpufreq_policy *policy)
 {
-    if (!cpumask_test_cpu(cpuid, &cpu_online_map))
-        return -EINVAL;
-
-    on_selected_cpus(cpumask_of(cpuid), update_cpb, policy, 1);
+    unsigned int cpu;
+    cpumask_t cpus;
+
+    cpumask_and(&cpus, &cpu_online_map,
 &node_to_cpumask[cpu_to_node[cpuid]]); +    on_selected_cpus(&cpus,

update_cpb, policy, 1); +

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 93

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/powernow.c +2 -0
+    if (!cpumask_equal(policy->cpus, &cpus)) {
+        ASSERT(cpumask_subset(policy->cpus, &cpus));

ASSERT here seems overkilled, considering buggy bios (i.e. buggy node affinity or buggy cpufreq dom) may crash system. Simply abort w/ warning and err return may be better.

Thanks,
Jinsong

Quoted 9 lines
xen/arch/x86/acpi/cpufreq/powernow.c +6 -0
+        for_each_cpu(cpu, &cpus) {
+            struct cpufreq_policy *p;
+            p = per_cpu(cpufreq_cpu_policy, cpu);
+            p->turbo = policy->turbo;
+        }
+    }
 
     return 0;
 }
#3 lore raw

Re: [PATCH V2 2/2] cpufreq, powernow: enable/disable core performance boost for all CPUs in the Node

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

Since disabling turbo mode on one CPU also affect all other sibling CPUs in the same Node, we need to call update_cpb on all CPUs in the same node.

Same node? Hardly - if anything, than same package.

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 86

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/powernow.c +0 -2
@@ -82,10 +83,20 @@ static void update_cpb(void *data)
 static int powernow_cpufreq_update (int cpuid,
 				     struct cpufreq_policy *policy)
 {
-    if (!cpumask_test_cpu(cpuid, &cpu_online_map))
-        return -EINVAL;

You're entirely losing that check.

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 87

Quoted 4 lines
xen/arch/x86/acpi/cpufreq/powernow.c +2 -2
-
-    on_selected_cpus(cpumask_of(cpuid), update_cpb, policy, 1);
+    unsigned int cpu;
+    cpumask_t cpus;

Please avoid on stack cpumask_t variables is at all possible. It shouldn't be too difficult to use cpumask_var_t here.

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 89

Quoted 2 lines
xen/arch/x86/acpi/cpufreq/powernow.c +2 -0
+
+    cpumask_and(&cpus, &cpu_online_map, &node_to_cpumask[cpu_to_node[cpuid]]);

While per the above I expect this to go away anyway, if nevertheless this needs to stay, then please use the macros, not the raw arrays.

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 92

Quoted 3 lines
xen/arch/x86/acpi/cpufreq/powernow.c +3 -0
+    on_selected_cpus(&cpus, update_cpb, policy, 1);
+
+    if (!cpumask_equal(policy->cpus, &cpus)) {

This is wrong - the left side ought to be cpumask_of(cpuid), or else you may again fail to update some of the policy structures.

xen/arch/x86/acpi/cpufreq/powernow.c static void update_cpb(void *data) · line 98

Quoted 6 lines
xen/arch/x86/acpi/cpufreq/powernow.c +6 -0
+        ASSERT(cpumask_subset(policy->cpus, &cpus));
+        for_each_cpu(cpu, &cpus) {
+            struct cpufreq_policy *p;
+            p = per_cpu(cpufreq_cpu_policy, cpu);
+            p->turbo = policy->turbo;
+        }

Couldn't this be done in update_cpb() instead?

And with update_cpb() being a no-op when policy->turbo == CPUFREQ_TURBO_UNSUPPORTED, and since you're re-writing this function anyway - the better change then would be to not even call on_selected_cpus() in that case (and of course the loop here wouldn't need to be gone through in that case either, as long as we're permitted to assume that CPUs in a package as well as CPUs covered by the same policy have the same turbo mode availability).

Jan