Skip to contentSkip to conversation

1/3 Refactor Xen support for Intel Turbo boost

PATCH In review Mark Langsdorf 2 participants 4 messages Mar 31, 2010 – Apr 1, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 1/3 Refactor Xen support for Intel Turbo boost

# HG changeset patch
# User [email protected]
# Date 1270010993 18000
# Node ID 9da598418e6da7758a799e116dc8bf3c3ed2f473
# Parent ebd84be3420a4453b3024d3378d8d84b81f44118 Refactor the existing code that supports the Intel Turbo feature to move all the driver specific bits in the cpufreq driver. Create a tri-state interface for the Turbo feature that can distinguish amongst enabled Turbo, disabled Turbo, and processors that don't support Turbo at all.

tools/libxc/xc_pm.c +1 -0
diff -r ebd84be3420a -r 9da598418e6d tools/libxc/xc_pm.c
@@ -247,6 +247,7 @@
         user_para->scaling_cur_freq = sys_para->scaling_cur_freq;
         user_para->scaling_max_freq = sys_para->scaling_max_freq;
         user_para->scaling_min_freq = sys_para->scaling_min_freq;
+        user_para->turbo_enabled    = sys_para->turbo_enabled;
 
         memcpy(user_para->scaling_driver, 
                 sys_para->scaling_driver, CPUFREQ_NAME_LEN);
tools/libxc/xenctrl.h +1 -0
diff -r ebd84be3420a -r 9da598418e6d tools/libxc/xenctrl.h
@@ -1276,6 +1276,7 @@
     char scaling_governor[CPUFREQ_NAME_LEN];
     uint32_t scaling_max_freq;
     uint32_t scaling_min_freq;
+    int32_t turbo_enabled;
 
     /* for specific governor */
     union {
tools/misc/xenpm.c +4 -0
diff -r ebd84be3420a -r 9da598418e6d tools/misc/xenpm.c
@@ -30,6 +30,10 @@
 
 #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 int xc_fd;
 static int max_cpu_nr;
 
@@ -62,8 +66,8 @@
             " set-max-cstate        <num>         set the C-State limitation 

(<num> >= 0)\n"
" start [seconds] start collect Cx/Px
statistics,\n"
" output after CTRL-C or
SIGINT or several seconds.\n"
- " enable-turbo-mode [cpuid] enable Turbo Mode in DBS
governor.\n"
- " disable-turbo-mode [cpuid] disable Turbo Mode in DBS
governor.\n"
+ " enable-turbo-mode [cpuid] enable Turbo Mode for
processors that support it.\n"
+ " disable-turbo-mode [cpuid] disable Turbo Mode for
processors that support it.\n"

             );
 }
 /* wrapper function */
@@ -529,8 +533,6 @@
                p_cpufreq->u.ondemand.sampling_rate);
         printf("    up_threshold     : %u\n",
                p_cpufreq->u.ondemand.up_threshold);
-        printf("    turbo mode       : %s\n",
-               p_cpufreq->u.ondemand.turbo_enabled ? "enabled" : "disabled");
     }
 
     printf("scaling_avail_freq   :");
@@ -546,6 +548,13 @@
            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("\n");

}

@@ -561,6 +570,7 @@

     p_cpufreq->affected_cpus = NULL;
     p_cpufreq->scaling_available_frequencies = NULL;
     p_cpufreq->scaling_available_governors = NULL;

+ p_cpufreq->turbo_enabled = 0;

     do
     {
xen/arch/x86/acpi/cpufreq/cpufreq.c +12 -1
diff -r ebd84be3420a -r 9da598418e6d xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -410,6 +410,10 @@
         return -ENODEV;
     }
 
+    if (policy->turbo == -1)
+        if (target_freq > policy->cpuinfo.second_max_freq)
+            target_freq = policy->cpuinfo.second_max_freq;
+
     perf = data->acpi_data;
     result = cpufreq_frequency_table_target(policy,
                                             data->freq_table,
@@ -610,12 +614,19 @@
         break;
     }
 
-    /* Check for APERF/MPERF support in hardware */
+    /* Check for APERF/MPERF support in hardware
+     * also check for boost support */
     if (c->x86_vendor == X86_VENDOR_INTEL && c->cpuid_level >= 6) {
         unsigned int ecx;
+        unsigned int eax;
         ecx = cpuid_ecx(6);
         if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)
             acpi_cpufreq_driver.getavg = get_measured_perf;
+        eax = cpuid_eax(6);
+        if ( eax & 0x2 ) {
+            policy->turbo = 1;
+            printk(XENLOG_INFO "Turbo Mode detected and enabled!\n");
+        }
     }
 
     /*
xen/drivers/acpi/pmstat.c +3 -4
diff -r ebd84be3420a -r 9da598418e6d xen/drivers/acpi/pmstat.c
@@ -299,9 +299,8 @@
             &op->u.get_para.u.ondemand.sampling_rate_min,
             &op->u.get_para.u.ondemand.sampling_rate,
             &op->u.get_para.u.ondemand.up_threshold);
-        op->u.get_para.u.ondemand.turbo_enabled =
-            cpufreq_dbs_get_turbo_status(op->cpuid);
     }
+    op->u.get_para.turbo_enabled = cpufreq_get_turbo_status(op->cpuid);
 
     return ret;
 }
@@ -553,13 +552,13 @@
 
     case XEN_SYSCTL_pm_op_enable_turbo:
     {
-        cpufreq_dbs_enable_turbo(op->cpuid);
+        cpufreq_enable_turbo(op->cpuid);
         break;
     }
 
     case XEN_SYSCTL_pm_op_disable_turbo:
     {
-        cpufreq_dbs_disable_turbo(op->cpuid);
+        cpufreq_disable_turbo(op->cpuid);
         break;
     }
 
xen/drivers/cpufreq/cpufreq_ondemand.c +0 -31
diff -r ebd84be3420a -r 9da598418e6d xen/drivers/cpufreq/cpufreq_ondemand.c
@@ -58,9 +58,6 @@
 
 static struct timer dbs_timer[NR_CPUS];
 
-/* Turbo Mode */
-static int turbo_detected = 0;
-
 int write_ondemand_sampling_rate(unsigned int sampling_rate)
 {
     if ( (sampling_rate > MAX_SAMPLING_RATE / MICROSECS(1)) ||
@@ -111,10 +108,6 @@
 
     policy = this_dbs_info->cur_policy;
     max = policy->max;
-    if (turbo_detected && !this_dbs_info->turbo_enabled) {
-        if (max > policy->cpuinfo.second_max_freq)
-            max = policy->cpuinfo.second_max_freq;
-    }
 
     if (unlikely(policy->resume)) {
         __cpufreq_driver_target(policy, max,CPUFREQ_RELATION_H);
@@ -276,7 +269,6 @@
             } else
                 dbs_tuners_ins.sampling_rate = usr_sampling_rate;
         }
-        this_dbs_info->turbo_enabled = 1;
         dbs_timer_init(this_dbs_info);
 
         break;
@@ -353,13 +345,6 @@
 
 static int __init cpufreq_gov_dbs_init(void)
 {
-#ifdef CONFIG_X86
-    unsigned int eax = cpuid_eax(6);
-    if ( eax & 0x2 ) {
-        turbo_detected = 1;
-        printk(XENLOG_INFO "Turbo Mode detected!\n");
-    }
-#endif
     return cpufreq_register_governor(&cpufreq_gov_dbs);
 }
 __initcall(cpufreq_gov_dbs_init);
@@ -404,19 +389,3 @@
         }
     }
 }
-
-void cpufreq_dbs_enable_turbo(int cpuid)
-{
-    per_cpu(cpu_dbs_info, cpuid).turbo_enabled = 1;
-}
-
-void cpufreq_dbs_disable_turbo(int cpuid)
-{
-    per_cpu(cpu_dbs_info, cpuid).turbo_enabled = 0;
-}
-
-unsigned int cpufreq_dbs_get_turbo_status(int cpuid)
-{
-    return turbo_detected && per_cpu(cpu_dbs_info, cpuid).turbo_enabled;
-}
-
xen/drivers/cpufreq/utility.c +25 -0
diff -r ebd84be3420a -r 9da598418e6d xen/drivers/cpufreq/utility.c
@@ -394,6 +394,31 @@
     return policy->cur;
 }
 
+void cpufreq_enable_turbo(int cpuid)
+{
+    struct cpufreq_policy *policy;
+
+    policy = cpufreq_cpu_policy[cpuid];
+    if (policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
+        policy->turbo = CPUFREQ_TURBO_ENABLED;
+}
+
+void cpufreq_disable_turbo(int cpuid)
+{
+    struct cpufreq_policy *policy;
+
+    policy = cpufreq_cpu_policy[cpuid];
+    if (policy->turbo != CPUFREQ_TURBO_UNSUPPORTED)
+        policy->turbo = CPUFREQ_TURBO_DISABLED;
+}
+
+int cpufreq_get_turbo_status(int cpuid)
+{
+    struct cpufreq_policy *policy;
+
+    policy = cpufreq_cpu_policy[cpuid];
+    return policy->turbo;
+}
 
 /*********************************************************************
  *                 POLICY                                            *
xen/include/acpi/cpufreq/cpufreq.h +12 -3
diff -r ebd84be3420a -r 9da598418e6d xen/include/acpi/cpufreq/cpufreq.h
@@ -55,6 +55,9 @@
 
     unsigned int        resume; /* flag for cpufreq 1st run
                                  * S3 wakeup, hotplug cpu, etc */
+    int                 turbo;  /* tristate flag: 0 for unsupported
+                                 * -1 for disable, 1 for enabled 
+                                 * See CPUFREQ_TURBO_* below for defines */
 };
 extern struct cpufreq_policy *cpufreq_cpu_policy[NR_CPUS];
 
@@ -114,6 +117,15 @@
 #define USR_GETAVG     2
 extern int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag);
 
+#define CPUFREQ_TURBO_DISABLED      -1
+#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_get_turbo_status(int cpuid);
+
+
 static __inline__ int 
 __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
 {
@@ -241,7 +253,4 @@
 void cpufreq_dbs_timer_suspend(void);
 void cpufreq_dbs_timer_resume(void);
 
-void cpufreq_dbs_enable_turbo(int cpuid);
-void cpufreq_dbs_disable_turbo(int cpuid);
-unsigned int cpufreq_dbs_get_turbo_status(int cpuid);
 #endif /* __XEN_CPUFREQ_PM_H__ */
xen/include/acpi/cpufreq/processor_perf.h +1 -0
diff -r ebd84be3420a -r 9da598418e6d xen/include/acpi/cpufreq/processor_perf.h
@@ -9,6 +9,7 @@
 int get_cpu_id(u8);
 int powernow_cpufreq_init(void);
 unsigned int powernow_register_driver(void);
+unsigned int get_measured_perf(unsigned int cpu, unsigned int flag);
 
 void cpufreq_residency_update(unsigned int, uint8_t);
 void cpufreq_statistic_update(unsigned int, uint8_t, uint8_t);
xen/include/public/sysctl.h +1 -1
diff -r ebd84be3420a -r 9da598418e6d xen/include/public/sysctl.h
@@ -298,7 +298,6 @@
 
     uint32_t sampling_rate;
     uint32_t up_threshold;
-    uint32_t turbo_enabled;
 };
 typedef struct xen_ondemand xen_ondemand_t;
 
@@ -328,6 +327,7 @@
     char scaling_governor[CPUFREQ_NAME_LEN];
     uint32_t scaling_max_freq;
     uint32_t scaling_min_freq;
+    int32_t turbo_enabled;
 
     /* for specific governor */
     union {
#1 lore raw

Overall It looks fine. Still some small comments.

Quoted 15 lines

-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Mark Langsdorf
Sent: Wednesday, March 31, 2010 8:25 AM
To: [email protected]
Subject: [Xen-devel] [PATCH] [retry 1] 1/3 Refactor Xen support for Intel Turbo boost

diff -r ebd84be3420a -r 9da598418e6d
xen/arch/x86/acpi/cpufreq/cpufreq.c
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c Tue Mar 30 18:31:39 2010
+0100
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c Tue Mar 30 23:49:53
2010 -0500

Review line 416

Quoted 7 lines
(quoted diff) +4 -0
@@ -410,6 +410,10 @@
         return -ENODEV;
     }
 
+    if (policy->turbo == -1)
+        if (target_freq > policy->cpuinfo.second_max_freq)
+            target_freq = policy->cpuinfo.second_max_freq;
+

use CPUFREQ_TURBO_DISABLED for better readability.

Quoted 12 lines
(quoted diff) +2 -1
     perf = data->acpi_data;
     result = cpufreq_frequency_table_target(policy,
                                             data->freq_table,
@@ -610,12 +614,19 @@
         break;
     }
 
-    /* Check for APERF/MPERF support in hardware */
+    /* Check for APERF/MPERF support in hardware
+     * also check for boost support */
     if (c->x86_vendor == X86_VENDOR_INTEL && c->cpuid_level >= 6) {
         unsigned int ecx;

Review line 630

Quoted 10 lines
(quoted diff) +6 -0
+        unsigned int eax;
         ecx = cpuid_ecx(6);
         if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)
             acpi_cpufreq_driver.getavg = get_measured_perf;
+        eax = cpuid_eax(6);
+        if ( eax & 0x2 ) {
+            policy->turbo = 1;
+            printk(XENLOG_INFO "Turbo Mode detected and enabled!\n");
+        }
     }

Use CPUFREQ_TURBO_ENABLED

Quoted 27 lines

diff -r ebd84be3420a -r 9da598418e6d
xen/include/acpi/cpufreq/processor_perf.h
--- a/xen/include/acpi/cpufreq/processor_perf.h Tue Mar 30 18:31:39
2010 +0100
+++ b/xen/include/acpi/cpufreq/processor_perf.h Tue Mar 30 23:49:53
2010 -0500

(quoted diff) +1 -0
@@ -9,6 +9,7 @@
 int get_cpu_id(u8);
 int powernow_cpufreq_init(void);
 unsigned int powernow_register_driver(void);
+unsigned int get_measured_perf(unsigned int cpu, unsigned int flag);
 
 void cpufreq_residency_update(unsigned int, uint8_t);
 void cpufreq_statistic_update(unsigned int, uint8_t, uint8_t);

diff -r ebd84be3420a -r 9da598418e6d xen/include/public/sysctl.h

xen/include/public/sysctl.h +0 -1
@@ -298,7 +298,6 @@
 
     uint32_t sampling_rate;
     uint32_t up_threshold;
-    uint32_t turbo_enabled;
 };
 typedef struct xen_ondemand xen_ondemand_t;
 

xen/include/public/sysctl.h line 333

Quoted 7 lines
xen/include/public/sysctl.h +1 -0
@@ -328,6 +327,7 @@
     char scaling_governor[CPUFREQ_NAME_LEN];
     uint32_t scaling_max_freq;
     uint32_t scaling_min_freq;
+    int32_t turbo_enabled;
 
     /* for specific governor */
     union {

I would like to change this as following, to keep hypercall interface backward compatible. And adding padding allows future extension.

xen/include/public/sysctl.h Wed Mar 31 15:58:48 2010 +0800 renamed from xen/include/public/sysctl.h Tue Mar 30 08:36:41 2010 +0100 +3 -0
diff -r 91232efdcfdc xen/include/public/sysctl.h
@@ -333,7 +333,10 @@ struct xen_get_cpufreq_para {
     union {
         struct  xen_userspace userspace;
         struct  xen_ondemand ondemand;
+        uint8_t pad[32];
     } u;
+
+    int32_t turbo_enabled;
 };
 

And you may want to change "struct xc_get_cpufreq_para" as well.

Best Regards
Ke

#2 lore raw
Quoted 27 lines

Review line 333

Quoted 9 lines
(quoted diff) +1 -0
@@ -328,6 +327,7 @@
     char scaling_governor[CPUFREQ_NAME_LEN];
     uint32_t scaling_max_freq;
     uint32_t scaling_min_freq;
+    int32_t turbo_enabled;
 
     /* for specific governor */
     union {

I would like to change this as following, to keep hypercall interface backward compatible. And adding padding allows future extension.

diff -r 91232efdcfdc xen/include/public/sysctl.h

xen/include/public/sysctl.h Wed Mar 31 15:58:48 2010 +0800 renamed from xen/include/public/sysctl.h Tue Mar 30 08:36:41 2010 +0100 +3 -0
@@ -333,7 +333,10 @@ struct xen_get_cpufreq_para {
     union {
         struct  xen_userspace userspace;
         struct  xen_ondemand ondemand;
+        uint8_t pad[32];
     } u;
+
+    int32_t turbo_enabled;
 };
 
Quoted 1 line

And you may want to change "struct xc_get_cpufreq_para" as well.

I don't think you need to pad it that way. struct xen_sysctl already has a 128 byte pad defined for it.

Also, doing so triggers a build error macro in
arch/x86/setup.c line 915.

-Mark Langsdorf
Operating System Research Center
AMD

#3 lore raw
Quoted 17 lines
Quoted 17 lines

I would like to change this as following, to keep hypercall interface backward compatible. And adding padding allows future extension.

diff -r 91232efdcfdc xen/include/public/sysctl.h

xen/include/public/sysctl.h Wed Mar 31 15:58:48 2010 +0800 renamed from xen/include/public/sysctl.h Tue Mar 30 08:36:41 2010 +0100 +3 -0
@@ -333,7 +333,10 @@ struct xen_get_cpufreq_para {
     union {
         struct  xen_userspace userspace;
         struct  xen_ondemand ondemand;
+        uint8_t pad[32];
     } u;
+
+    int32_t turbo_enabled;
 };
 
Quoted 7 lines
Quoted 1 line

And you may want to change "struct xc_get_cpufreq_para" as well.

I don't think you need to pad it that way. struct xen_sysctl already has a 128 byte pad defined for it.

Also, doing so triggers a build error macro in
arch/x86/setup.c line 915.

Oh, the build error shows the length is reaching the limit of 128 bytes, in this case, padding is not necessary since there is few room for future extension.

Best Regards
Ke