From: "Jan Beulich" Subject: [PATCH] x86/cpufreq: fix turbo mode detection Date: Thu, 06 May 2010 14:10:12 +0100 Message-ID: <4BE2DBD4020000780000191E@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartDAF07EA4.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. --=__PartDAF07EA4.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline acpi_cpufreq_cpu_init() does generally not run on the CPU the policy it deals 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). Also fix a minor glitch in xenpm, which I noticed while looking into the original inconsistencies on one of my systems. Signed-off-by: Jan Beulich --- 2010-05-04.orig/tools/misc/xenpm.c 2010-04-14 14:05:14.000000000 = +0200 +++ 2010-05-04/tools/misc/xenpm.c 2010-05-06 13:37:30.000000000 = +0200 @@ -499,10 +499,7 @@ static void print_cpufreq_para(int cpuid =20 printf("affected_cpus :"); for ( i =3D 0; i < p_cpufreq->cpu_num; i++ ) - if ( i =3D=3D cpuid ) - printf(" *%d", p_cpufreq->affected_cpus[i]); - else - printf(" %d", p_cpufreq->affected_cpus[i]); + printf(" %d", p_cpufreq->affected_cpus[i]); printf("\n"); =20 printf("cpuinfo frequency : max [%u] min [%u] cur [%u]\n", --- 2010-05-04.orig/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-04-12 = 11:28:20.000000000 +0200 +++ 2010-05-04/xen/arch/x86/acpi/cpufreq/cpufreq.c 2010-05-06 = 13:24:41.000000000 +0200 @@ -377,6 +377,23 @@ 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) + 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 +632,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 --=__PartDAF07EA4.0__= Content-Type: text/plain; name="cpufreq-turbo-detect.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cpufreq-turbo-detect.patch" acpi_cpufreq_cpu_init() does generally not run on the CPU the policy=0Ait = deals with is related to, hence using cpuid() directly works only=0Aas = long as all CPUs in the system are identical (which admittedly=0Ais = commonly the case).=0A=0AAlso fix a minor glitch in xenpm, which I noticed = while looking into=0Athe original inconsistencies on one of my systems.=0A= =0ASigned-off-by: Jan Beulich =0A=0A--- 2010-05-04.ori= g/tools/misc/xenpm.c 2010-04-14 14:05:14.000000000 +0200=0A+++ = 2010-05-04/tools/misc/xenpm.c 2010-05-06 13:37:30.000000000 +0200=0A@@ = -499,10 +499,7 @@ static void print_cpufreq_para(int cpuid=0A =0A = printf("affected_cpus :");=0A for ( i =3D 0; i < p_cpufreq->cpu_= num; i++ )=0A- if ( i =3D=3D cpuid )=0A- printf(" *%d", = p_cpufreq->affected_cpus[i]);=0A- else=0A- printf(" %d", = p_cpufreq->affected_cpus[i]);=0A+ printf(" %d", p_cpufreq->affected_= cpus[i]);=0A printf("\n");=0A =0A printf("cpuinfo frequency : = max [%u] min [%u] cur [%u]\n",=0A--- 2010-05-04.orig/xen/arch/x86/acpi/cpuf= req/cpufreq.c 2010-04-12 11:28:20.000000000 +0200=0A+++ 2010-05-04/xen/ar= ch/x86/acpi/cpufreq/cpufreq.c 2010-05-06 13:24:41.000000000 +0200=0A@@ = -377,6 +377,23 @@ 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_APERFMPE= RF_CAPABILITY)=0A+ acpi_cpufreq_driver.getavg =3D get_measured_perf;= =0A+ eax =3D cpuid_eax(6);=0A+ if (eax & 0x2) {=0A+ policy->tu= rbo =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 +632,8 @@ = acpi_cpufreq_cpu_init(struct cpufreq_pol=0A =0A /* Check for APERF/MPER= F support in hardware=0A * also check for boost support */=0A- if = (c->x86_vendor =3D=3D X86_VENDOR_INTEL && c->cpuid_level >=3D 6) {=0A- = unsigned int ecx;=0A- unsigned int eax;=0A- ecx =3D = cpuid_ecx(6);=0A- if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)=0A- = acpi_cpufreq_driver.getavg =3D get_measured_perf;=0A- eax = =3D cpuid_eax(6);=0A- if ( eax & 0x2 ) {=0A- policy->turb= o =3D CPUFREQ_TURBO_ENABLED;=0A- printk(XENLOG_INFO "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_cp= us(cpumask_of(cpu), feature_detect, policy, 1);=0A =0A /*=0A * = the first call to ->target() should result in us actually=0A --=__PartDAF07EA4.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 --=__PartDAF07EA4.0__=--