From: "Jan Beulich" Subject: [PATCH, v2] x86/cpufreq: fix turbo mode detection Date: Fri, 07 May 2010 09:39:11 +0100 Message-ID: <4BE3EDCF0200007800001BF4@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartAE840BBF.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartAE840BBF.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline {acpi,powernow}_cpufreq_cpu_init() generally don't run on the CPU the policy they deal with is related to, hence using cpuid() directly works only as long as all CPUs in the system are identical (which admittedly is commonly the case). Further add a per-policy flag indicating the availability of APERF/MPERF MSRs, so that globally setting the .getavg accessor won't be a problem on heterogeneous configurations. Signed-off-by: Jan Beulich --- 2010-05-04.orig/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-05-06 = 14:52:45.000000000 +0200 +++ 2010-05-04/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-05-07 = 10:30:33.000000000 +0200 @@ -280,7 +280,7 @@ unsigned int get_measured_perf(unsigned=20 return 0; =20 policy =3D cpufreq_cpu_policy[cpu]; - if (!policy) + if (!policy || !policy->aperf_mperf) return 0; =20 switch (flag) @@ -377,6 +377,26 @@ static unsigned int get_cur_freq_on_cpu( return freq; } =20 +static void feature_detect(void *info) +{ + struct cpufreq_policy *policy =3D info; + unsigned int eax, ecx; + + ecx =3D cpuid_ecx(6); + if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY) { + policy->aperf_mperf =3D 1; + acpi_cpufreq_driver.getavg =3D get_measured_perf; + } + + eax =3D cpuid_eax(6); + if (eax & 0x2) { + policy->turbo =3D CPUFREQ_TURBO_ENABLED; + if (cpufreq_verbose) + printk(XENLOG_INFO "CPU%u: Turbo Mode detected and enabled\n",= + smp_processor_id()); + } +} + static unsigned int check_freqs(cpumask_t mask, unsigned int freq, struct acpi_cpufreq_data *data) { @@ -615,18 +635,8 @@ acpi_cpufreq_cpu_init(struct cpufreq_pol =20 /* Check for APERF/MPERF support in hardware * also check for boost support */ - if (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_level >=3D 6) { - unsigned int ecx; - unsigned int eax; - ecx =3D cpuid_ecx(6); - if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY) - acpi_cpufreq_driver.getavg =3D get_measured_perf; - eax =3D cpuid_eax(6); - if ( eax & 0x2 ) { - policy->turbo =3D CPUFREQ_TURBO_ENABLED; - printk(XENLOG_INFO "Turbo Mode detected and enabled!\n"); - } - } + if (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_level >=3D 6) + on_selected_cpus(cpumask_of(cpu), feature_detect, policy, 1); =20 /* * the first call to ->target() should result in us actually --- 2010-05-04.orig/xen/arch/x86/acpi/cpufreq/powernow.c 2010-04-12 = 11:28:20.000000000 +0200 +++ 2010-05-04/xen/arch/x86/acpi/cpufreq/powernow.c 2010-05-07 = 10:30:26.000000000 +0200 @@ -165,6 +165,27 @@ static int powernow_cpufreq_verify(struc return cpufreq_frequency_table_verify(policy, data->freq_table); } =20 +static void feature_detect(void *info) +{ + struct cpufreq_policy *policy =3D info; + unsigned int ecx, edx; + + ecx =3D cpuid_ecx(6); + if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY) { + policy->aperf_mperf =3D 1; + powernow_cpufreq_driver.getavg =3D get_measured_perf; + } + + edx =3D cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES); + if ((edx & CPB_CAPABLE) =3D=3D CPB_CAPABLE) { + policy->turbo =3D CPUFREQ_TURBO_ENABLED; + if (cpufreq_verbose) + printk(XENLOG_INFO + "CPU%u: Core Boost/Turbo detected and enabled\n", + smp_processor_id()); + } +} + static int powernow_cpufreq_cpu_init(struct cpufreq_policy *policy) { unsigned int i; @@ -250,18 +271,8 @@ static int powernow_cpufreq_cpu_init(str if (result) goto err_freqfree; =20 - if (c->cpuid_level >=3D 6) { - unsigned int edx; - unsigned int ecx; - ecx =3D cpuid_ecx(6); - if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY) - powernow_cpufreq_driver.getavg =3D get_measured_perf; - edx =3D cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES); - if ((edx & CPB_CAPABLE) =3D=3D CPB_CAPABLE) { - policy->turbo =3D CPUFREQ_TURBO_ENABLED; - printk(XENLOG_INFO "Core Boost/Turbo detected and enabled\n");= - } - } + if (c->cpuid_level >=3D 6) + on_selected_cpus(cpumask_of(cpu), feature_detect, policy, 1); =20 /* * the first call to ->target() should result in us actually --- 2010-05-04.orig/xen/include/acpi/cpufreq/cpufreq.h 2010-04-12 = 11:28:20.000000000 +0200 +++ 2010-05-04/xen/include/acpi/cpufreq/cpufreq.h 2010-05-07 = 10:22:20.000000000 +0200 @@ -52,11 +52,12 @@ struct cpufreq_policy { * governors are used */ struct cpufreq_governor *governor; =20 - unsigned int resume; /* flag for cpufreq 1st run + bool_t resume; /* flag for cpufreq 1st run * S3 wakeup, hotplug cpu, etc */ - int turbo; /* tristate flag: 0 for unsupported + s8 turbo; /* tristate flag: 0 for unsupported * -1 for disable, 1 for enabled * See CPUFREQ_TURBO_* below for defines = */ + bool_t aperf_mperf; /* CPU has APERF/MPERF MSRs */ }; extern struct cpufreq_policy *cpufreq_cpu_policy[NR_CPUS]; =20 --=__PartAE840BBF.0__= Content-Type: text/plain; name="cpufreq-turbo-detect.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cpufreq-turbo-detect.patch" {acpi,powernow}_cpufreq_cpu_init() generally don't run on the CPU = the=0Apolicy they deal with is related to, hence using cpuid() directly=0Aw= orks only as long as all CPUs in the system are identical (which=0Aadmitted= ly is commonly the case).=0A=0AFurther add a per-policy flag indicating = the availability of=0AAPERF/MPERF MSRs, so that globally setting the = .getavg accessor won't=0Abe a problem on heterogeneous configurations.=0A= =0ASigned-off-by: Jan Beulich =0A=0A--- 2010-05-04.ori= g/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-05-06 14:52:45.000000000 = +0200=0A+++ 2010-05-04/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-05-07 = 10:30:33.000000000 +0200=0A@@ -280,7 +280,7 @@ unsigned int get_measured_pe= rf(unsigned =0A return 0;=0A =0A policy =3D cpufreq_cpu_policy[= cpu];=0A- if (!policy)=0A+ if (!policy || !policy->aperf_mperf)=0A = return 0;=0A =0A switch (flag)=0A@@ -377,6 +377,26 @@ static = unsigned int get_cur_freq_on_cpu(=0A return freq;=0A }=0A =0A+static = void feature_detect(void *info)=0A+{=0A+ struct cpufreq_policy *policy = =3D info;=0A+ unsigned int eax, ecx;=0A+=0A+ ecx =3D cpuid_ecx(6);=0A= + if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY) {=0A+ policy->aper= f_mperf =3D 1;=0A+ acpi_cpufreq_driver.getavg =3D get_measured_perf;= =0A+ }=0A+=0A+ eax =3D cpuid_eax(6);=0A+ if (eax & 0x2) {=0A+ = policy->turbo =3D CPUFREQ_TURBO_ENABLED;=0A+ if (cpufreq_verbose)= =0A+ printk(XENLOG_INFO "CPU%u: Turbo Mode detected and = enabled\n",=0A+ smp_processor_id());=0A+ }=0A+}=0A+=0A= static unsigned int check_freqs(cpumask_t mask, unsigned int freq,=0A = struct acpi_cpufreq_data *data)=0A {=0A@@ = -615,18 +635,8 @@ acpi_cpufreq_cpu_init(struct cpufreq_pol=0A =0A /* = Check for APERF/MPERF support in hardware=0A * also check for boost = support */=0A- if (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_lev= el >=3D 6) {=0A- unsigned int ecx;=0A- unsigned int eax;=0A- = ecx =3D cpuid_ecx(6);=0A- if (ecx & CPUID_6_ECX_APERFMPERF_CA= PABILITY)=0A- acpi_cpufreq_driver.getavg =3D get_measured_perf;= =0A- eax =3D cpuid_eax(6);=0A- if ( eax & 0x2 ) {=0A- = policy->turbo =3D CPUFREQ_TURBO_ENABLED;=0A- printk(XENLOG_I= NFO "Turbo Mode detected and enabled!\n");=0A- }=0A- }=0A+ if = (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_level >=3D 6)=0A+ = on_selected_cpus(cpumask_of(cpu), feature_detect, policy, 1);=0A =0A = /*=0A * the first call to ->target() should result in us actually=0A--= - 2010-05-04.orig/xen/arch/x86/acpi/cpufreq/powernow.c 2010-04-12 = 11:28:20.000000000 +0200=0A+++ 2010-05-04/xen/arch/x86/acpi/cpufreq/powerno= w.c 2010-05-07 10:30:26.000000000 +0200=0A@@ -165,6 +165,27 @@ static = int powernow_cpufreq_verify(struc=0A return cpufreq_frequency_table_ver= ify(policy, data->freq_table);=0A }=0A =0A+static void feature_detect(void = *info)=0A+{=0A+ struct cpufreq_policy *policy =3D info;=0A+ unsigned = int ecx, edx;=0A+=0A+ ecx =3D cpuid_ecx(6);=0A+ if (ecx & CPUID_6_ECX= _APERFMPERF_CAPABILITY) {=0A+ policy->aperf_mperf =3D 1;=0A+ = powernow_cpufreq_driver.getavg =3D get_measured_perf;=0A+ }=0A+=0A+ = edx =3D cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES);=0A+ if ((edx & = CPB_CAPABLE) =3D=3D CPB_CAPABLE) {=0A+ policy->turbo =3D CPUFREQ_TUR= BO_ENABLED;=0A+ if (cpufreq_verbose)=0A+ printk(XENLOG_IN= FO=0A+ "CPU%u: Core Boost/Turbo detected and enabled\n",= =0A+ smp_processor_id());=0A+ }=0A+}=0A+=0A static = int powernow_cpufreq_cpu_init(struct cpufreq_policy *policy)=0A {=0A = unsigned int i;=0A@@ -250,18 +271,8 @@ static int powernow_cpufreq_cpu_init= (str=0A if (result)=0A goto err_freqfree;=0A =0A- if = (c->cpuid_level >=3D 6) {=0A- unsigned int edx;=0A- unsigned = int ecx;=0A- ecx =3D cpuid_ecx(6);=0A- if (ecx & CPUID_6_ECX_= APERFMPERF_CAPABILITY)=0A- powernow_cpufreq_driver.getavg =3D = get_measured_perf;=0A- edx =3D cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIE= S);=0A- if ((edx & CPB_CAPABLE) =3D=3D CPB_CAPABLE) {=0A- = policy->turbo =3D CPUFREQ_TURBO_ENABLED;=0A- printk(XENLOG_INFO= "Core Boost/Turbo detected and enabled\n");=0A- }=0A- }=0A+ = if (c->cpuid_level >=3D 6)=0A+ on_selected_cpus(cpumask_of(cpu), = feature_detect, policy, 1);=0A =0A /*=0A * the first call = to ->target() should result in us actually=0A--- 2010-05-04.orig/xen/includ= e/acpi/cpufreq/cpufreq.h 2010-04-12 11:28:20.000000000 +0200=0A+++ = 2010-05-04/xen/include/acpi/cpufreq/cpufreq.h 2010-05-07 10:22:20.0000000= 00 +0200=0A@@ -52,11 +52,12 @@ struct cpufreq_policy {=0A = * governors are used */=0A struct cpufreq_governor = *governor;=0A =0A- unsigned int resume; /* flag for cpufreq 1st = run=0A+ bool_t resume; /* flag for cpufreq 1st run=0A = * S3 wakeup, hotplug cpu, etc */=0A- int = turbo; /* tristate flag: 0 for unsupported=0A+ s8 = turbo; /* tristate flag: 0 for unsupported=0A = * -1 for disable, 1 for enabled=0A = * See CPUFREQ_TURBO_* below for defines */=0A+ bool_t = aperf_mperf; /* CPU has APERF/MPERF MSRs */=0A };=0A extern struct = cpufreq_policy *cpufreq_cpu_policy[NR_CPUS];=0A =0A --=__PartAE840BBF.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartAE840BBF.0__=--