[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] x86, cpufreq: Change powernow's CPB status immediately



# HG changeset patch
# User Boris Ostrovsky <boris.ostrovsky@xxxxxxx>
# Date 1339538170 -7200
# Node ID 9477c6d78eb19422b59d235a67c3923346a3d60b
# Parent  32034d1914a607d7b6f1f060352b4cac973600f8
x86, cpufreq: Change powernow's CPB status immediately

When command to modify turbo mode (CPB on AMD processors) comes
in the actual change happens later, when P-state transition is
requested. There is no time limit on when this transition will
occur and therefore change in CPB state may take long time from
the moment when command to toggle it is issued.

This patch makes CPB mode change happen immediately when request
is made.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxx>

diff -r 32034d1914a6 -r 9477c6d78eb1 xen/arch/x86/acpi/cpufreq/powernow.c
--- a/xen/arch/x86/acpi/cpufreq/powernow.c      Thu Jun 07 19:46:57 2012 +0100
+++ b/xen/arch/x86/acpi/cpufreq/powernow.c      Tue Jun 12 23:56:10 2012 +0200
@@ -68,16 +68,42 @@ static void transition_pstate(void *drvc
     struct drv_cmd *cmd;
     cmd = (struct drv_cmd *) drvcmd;
 
-    if (cmd->turbo != CPUFREQ_TURBO_UNSUPPORTED) {
+
+    wrmsrl(MSR_PSTATE_CTRL, cmd->val);
+}
+
+static void update_cpb(void *data)
+{
+    struct cpufreq_policy *policy = (struct cpufreq_policy *)data;
+
+    if (policy->turbo != CPUFREQ_TURBO_UNSUPPORTED) {
         uint64_t msr_content;
+ 
         rdmsrl(MSR_K8_HWCR, msr_content);
-        if (cmd->turbo == CPUFREQ_TURBO_ENABLED)
+
+        if (policy->turbo == CPUFREQ_TURBO_ENABLED)
             msr_content &= ~MSR_HWCR_CPBDIS_MASK;
         else
             msr_content |= MSR_HWCR_CPBDIS_MASK; 
+
         wrmsrl(MSR_K8_HWCR, msr_content);
     }
-    wrmsrl(MSR_PSTATE_CTRL, cmd->val);
+}
+
+static int powernow_cpufreq_update (int cpuid,
+                                    struct cpufreq_policy *policy)
+{
+    cpumask_t cpumask;
+
+    if (!cpumask_test_cpu(cpuid, &cpu_online_map))
+        return -EINVAL;
+
+    cpumask_clear(&cpumask);
+    cpumask_set_cpu(cpuid, &cpumask);
+
+    on_selected_cpus(&cpumask, update_cpb, policy, 1);
+
+    return 0;
 }
 
 static int powernow_cpufreq_target(struct cpufreq_policy *policy,
@@ -300,7 +326,8 @@ static struct cpufreq_driver powernow_cp
     .verify = powernow_cpufreq_verify,
     .target = powernow_cpufreq_target,
     .init   = powernow_cpufreq_cpu_init,
-    .exit   = powernow_cpufreq_cpu_exit
+    .exit   = powernow_cpufreq_cpu_exit,
+    .update = powernow_cpufreq_update
 };
 
 unsigned int __init powernow_register_driver()
diff -r 32034d1914a6 -r 9477c6d78eb1 xen/drivers/acpi/pmstat.c
--- a/xen/drivers/acpi/pmstat.c Thu Jun 07 19:46:57 2012 +0100
+++ b/xen/drivers/acpi/pmstat.c Tue Jun 12 23:56:10 2012 +0200
@@ -494,13 +494,13 @@ int do_pm_op(struct xen_sysctl_pm_op *op
 
     case XEN_SYSCTL_pm_op_enable_turbo:
     {
-        cpufreq_enable_turbo(op->cpuid);
+        ret = cpufreq_enable_turbo(op->cpuid);
         break;
     }
 
     case XEN_SYSCTL_pm_op_disable_turbo:
     {
-        cpufreq_disable_turbo(op->cpuid);
+        ret = cpufreq_disable_turbo(op->cpuid);
         break;
     }
 
diff -r 32034d1914a6 -r 9477c6d78eb1 xen/drivers/cpufreq/utility.c
--- a/xen/drivers/cpufreq/utility.c     Thu Jun 07 19:46:57 2012 +0100
+++ b/xen/drivers/cpufreq/utility.c     Tue Jun 12 23:56:10 2012 +0200
@@ -390,22 +390,44 @@ int cpufreq_driver_getavg(unsigned int c
     return policy->cur;
 }
 
-void cpufreq_enable_turbo(int cpuid)
+int cpufreq_enable_turbo(int cpuid)
 {
     struct cpufreq_policy *policy;
+    int ret = 0;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    if (policy && policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
+    if (policy && policy->turbo == CPUFREQ_TURBO_DISABLED)
+    {
         policy->turbo = CPUFREQ_TURBO_ENABLED;
+        if (cpufreq_driver->update)
+        {
+            ret = cpufreq_driver->update(cpuid, policy);
+            if (ret)
+                policy->turbo = CPUFREQ_TURBO_DISABLED;
+        }
+    }
+
+    return ret;
 }
 
-void cpufreq_disable_turbo(int cpuid)
+int cpufreq_disable_turbo(int cpuid)
 {
     struct cpufreq_policy *policy;
+    int ret = 0;
 
     policy = per_cpu(cpufreq_cpu_policy, cpuid);
-    if (policy && policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
+    if (policy && policy->turbo == CPUFREQ_TURBO_ENABLED)
+    {
         policy->turbo = CPUFREQ_TURBO_DISABLED;
+        if (cpufreq_driver->update)
+        {
+            ret = cpufreq_driver->update(cpuid, policy);
+            if (ret)
+                policy->turbo = CPUFREQ_TURBO_ENABLED;
+        }
+    }
+
+    return ret;
 }
 
 int cpufreq_get_turbo_status(int cpuid)
diff -r 32034d1914a6 -r 9477c6d78eb1 xen/include/acpi/cpufreq/cpufreq.h
--- a/xen/include/acpi/cpufreq/cpufreq.h        Thu Jun 07 19:46:57 2012 +0100
+++ b/xen/include/acpi/cpufreq/cpufreq.h        Tue Jun 12 23:56:10 2012 +0200
@@ -124,8 +124,8 @@ extern int cpufreq_driver_getavg(unsigne
 #define CPUFREQ_TURBO_UNSUPPORTED   0
 #define CPUFREQ_TURBO_ENABLED       1
 
-extern void cpufreq_enable_turbo(int cpuid);
-extern void cpufreq_disable_turbo(int cpuid);
+extern int cpufreq_enable_turbo(int cpuid);
+extern int cpufreq_disable_turbo(int cpuid);
 extern int cpufreq_get_turbo_status(int cpuid);
 
 static __inline__ int 
@@ -146,6 +146,7 @@ struct cpufreq_driver {
     char   name[CPUFREQ_NAME_LEN];
     int    (*init)(struct cpufreq_policy *policy);
     int    (*verify)(struct cpufreq_policy *policy);
+    int    (*update)(int cpuid, struct cpufreq_policy *policy);
     int    (*target)(struct cpufreq_policy *policy,
                      unsigned int target_freq,
                      unsigned int relation);


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.