x86/intel_pstate: the main boby of the intel_pstate driver
PATCH v3 6/11 x86/intel_pstate: the main boby of the intel_pstate driver
The intel_pstate driver is ported following its kernel code logic (commit: 93f0822d).In order to port the Linux source file with minimal modifications, some of the variable types are kept intact (e.g. "int current_pstae", would otherwise be changed to "unsigned int").
In the kernel, a user can adjust the limits via sysfs (limits.min_sysfs_pct/max_sysfs_pct). In Xen, the policy->limits.min_perf_pct/max_perf_pct acts as the transit station. A user interacts with it via xenpm.
--- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/intel_pstate.c | 818 +++++++++++++++++++++++++++++++ xen/arch/x86/cpu/common.c | 3 + xen/include/acpi/cpufreq/cpufreq.h | 14 + xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/msr-index.h | 3 + 6 files changed, 840 insertions(+) create mode 100644 xen/arch/x86/acpi/cpufreq/intel_pstate.c
xen/arch/x86/acpi/cpufreq/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-y += cpufreq.o +obj-y += intel_pstate.o obj-y += powernow.o
xen/arch/x86/acpi/cpufreq/intel_pstate.c new file +818 -0
818 lines not on this page · raw message
xen/arch/x86/cpu/common.c +3 -0
@@ -238,6 +238,9 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)if (cpu_has (c,X86_FEATURE_CLFLSH ) ) c->x86_clflush_size = ((ebx >>8 ) &0xff ) *8 ; +if (cpuid_ecx (6 ) &0x1 ) +set_bit (X86_FEATURE_APERFMPERF , c->x86_capability); +/* AMD-defined flags: level 0x80000001 */ c->extended_cpuid_level =cpuid_eax (0x80000000 );if ( (c->extended_cpuid_level &0xffff0000 ) ==0x80000000 ) {
xen/include/acpi/cpufreq/cpufreq.h +14 -0
@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */
@@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy); +extern int intel_pstate_init (void ); +extern int __cpufreq_set_policy (struct cpufreq_policy *data,struct cpufreq_policy *policy);
@@ -101,6 +109,12 @@ struct cpufreq_freqs {* CPUFREQ GOVERNORS * *********************************************************************/ +/* The four internal governors used in intel_pstate */ +#define CPUFREQ_POLICY_POWERSAVE (1) +#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_USERSPACE (3) +#define CPUFREQ_POLICY_ONDEMAND (4) +#define CPUFREQ_GOV_START 1#define CPUFREQ_GOV_STOP 2#define CPUFREQ_GOV_LIMITS 3
xen/include/asm-x86/cpufeature.h +1 -0
@@ -69,6 +69,7 @@#define X86_FEATURE_XTOPOLOGY (3*32+13)/* cpu topology enum extensions */ #define X86_FEATURE_CPUID_FAULTING (3*32+14)/* cpuid faulting */ #define X86_FEATURE_CLFLUSH_MONITOR (3*32+15)/* clflush reqd with monitor */ +#define X86_FEATURE_APERFMPERF (3*32+28)/* APERFMPERF */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
xen/include/asm-x86/msr-index.h +3 -0
@@ -52,6 +52,8 @@#define MSR_IA32_MCG_STATUS 0x0000017a#define MSR_IA32_MCG_CTL 0x0000017b +#define MSR_NHM_TURBO_RATIO_LIMIT 0x000001ad +#define MSR_IA32_PEBS_ENABLE 0x000003f1#define MSR_IA32_DS_AREA 0x00000600#define MSR_IA32_PERF_CAPABILITIES 0x00000345
@@ -319,6 +321,7 @@#define MSR_IA32_MISC_ENABLE_MONITOR_ENABLE (1<<18)#define MSR_IA32_MISC_ENABLE_LIMIT_CPUID (1<<22)#define MSR_IA32_MISC_ENABLE_XTPR_DISABLE (1<<23) +#define MSR_IA32_MISC_ENABLE_TURBO_DISABLE (1ULL<<38)#define MSR_IA32_TSC_DEADLINE 0x000006E0#define MSR_IA32_ENERGY_PERF_BIAS 0x000001b0
Signature · 1 line
1.9.1
Hi Wei,
Quoted 18 lines · Wei Wang
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 87
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +2
-0@@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy); +extern int intel_pstate_init (void ); +
As said on a previous version [1], intel_pstate_init is x86 specific. Although xen/include/acpi contains common headers.
Please move everything x86 specific in asm-x86.
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 117
Quoted 13 lines
xen/include/acpi/cpufreq/cpufreq.h +6
-0extern int __cpufreq_set_policy (struct cpufreq_policy *data,struct cpufreq_policy *policy);@@ -101,6 +109,12 @@ struct cpufreq_freqs {* CPUFREQ GOVERNORS * *********************************************************************/ +/* The four internal governors used in intel_pstate */ +#define CPUFREQ_POLICY_POWERSAVE (1) +#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_USERSPACE (3) +#define CPUFREQ_POLICY_ONDEMAND (4) +
From the comment, this looks like x86 specific. Maybe even intel_pstate?
Quoted 8 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0#define CPUFREQ_GOV_START 1#define CPUFREQ_GOV_STOP 2#define CPUFREQ_GOV_LIMITS 3xen/include/asm-x86/cpufeature.h +0
-0
xen/include/asm-x86/cpufeature.h line 75
Quoted 7 lines
xen/include/asm-x86/cpufeature.h +1
-0@@ -69,6 +69,7 @@#define X86_FEATURE_XTOPOLOGY (3*32+13)/* cpu topology enum extensions */ #define X86_FEATURE_CPUID_FAULTING (3*32+14)/* cpuid faulting */ #define X86_FEATURE_CLFLUSH_MONITOR (3*32+15)/* clflush reqd with monitor */ +#define X86_FEATURE_APERFMPERF (3*32+28)/* APERFMPERF */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
Regards,
[1] http://lists.xen.org/archives/html/xen-devel/2015-04/msg02904.html
Signature · 1 line
Julien Grall
Hi Julien,
Quoted 23 lines · Julien Grall
Review
Quoted 1 line · Wei Wang
(quoted diff) +0
-0
b/xen/include/acpi/cpufreq/cpufreq.hQuoted 20 lines
index d10e4c7..71bb45c 100644
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */ @@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 87
Quoted 2 lines
xen/include/acpi/cpufreq/cpufreq.h +2
-0+extern int intel_pstate_init (void ); +As said on a previous version [1],
intel_pstate_initis x86 specific. Although xen/include/acpi contains common headers.
Please see our latest discussion here (the bottom of the link): http://lists.xen.org/archives/html/xen-devel/2015-06/msg00047.html
Quoted 11 lines
Please move everything x86 specific in asm-x86.
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 110
Quoted 6 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0extern int __cpufreq_set_policy (struct cpufreq_policy *data,struct cpufreq_policy *policy);@@ -101,6 +109,12 @@ struct cpufreq_freqs {* CPUFREQ GOVERNORS * **********************************************************
***********/Quoted 1 line
Quoted 8 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 117
Quoted 6 lines
xen/include/acpi/cpufreq/cpufreq.h +6
-0+/* The four internal governors used in intel_pstate */ +#define CPUFREQ_POLICY_POWERSAVE (1) +#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_USERSPACE (3) +#define CPUFREQ_POLICY_ONDEMAND (4) +From the comment, this looks like x86 specific. Maybe even
intel_pstate?
Yes. It's currently only used by the intel_pstate driver.
Quoted 11 lines
xen/include/asm-
Quoted 4 lines
#define CPUFREQ_GOV_START 1 #define CPUFREQ_GOV_STOP 2 #define CPUFREQ_GOV_LIMITS 3xen/include/asm- renamed from xen/include/asm-x86/cpufeature.h +0
-0
x86/cpufeature.hxen/include/asm-x86/cpufeature.h line 69
Quoted 5 lines
index 7963a3a..efc9711 100644
xen/include/asm-x86/cpufeature.h +0
-0@@ -69,6 +69,7 @@#define X86_FEATURE_XTOPOLOGY (3*32+13)/* cpu topology enum extensions */
Quoted 9 lines
xen/include/asm-x86/cpufeature.h line 71
Quoted 2 lines
xen/include/asm-x86/cpufeature.h +0
-0#define X86_FEATURE_CPUID_FAULTING (3*32+14)/* cpuid faulting */ #define X86_FEATURE_CLFLUSH_MONITOR (3*32+15)/* clflush reqd with monitor */
xen/include/asm-x86/cpufeature.h
Quoted 4 lines
xen/include/asm-x86/cpufeature.h +1
-0+#define X86_FEATURE_APERFMPERF (3*32+28)/* APERFMPERF */ /* Intel-defined CPU features, CPUID level 0x00000001 (ecx), word 4 */ #define X86_FEATURE_XMM3 (4*32+ 0)/* Streaming SIMD Extensions-3 */
Best,
Wei
Quoted 24 lines · Wei W
Quoted 23 lines · Julien Grall
Review
Quoted 1 line · Wei Wang
(quoted diff) +0
-0
b/xen/include/acpi/cpufreq/cpufreq.hQuoted 20 lines
index d10e4c7..71bb45c 100644
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */ @@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);
Quoted 7 lines
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 87
Quoted 2 lines
xen/include/acpi/cpufreq/cpufreq.h +2
-0+extern int intel_pstate_init (void ); +As said on a previous version [1],
intel_pstate_initis x86 specific. Although xen/include/acpi contains common headers.Please see our latest discussion here (the bottom of the link): http://lists.xen.org/archives/html/xen-devel/2015-06/msg00047.html
Well we are planning to move cpufreq.h out of acpi in order to use for device tree based platform. Most of these declaration is common.
Although any x86 specific function would have to go out in a separate header.
Please avoid to add new one when it's possible. I don't see why a new asm-x86/cpufreq.h can't be added...
Quoted 19 lines
Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 110
Quoted 6 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0extern int __cpufreq_set_policy (struct cpufreq_policy *data,struct cpufreq_policy *policy);@@ -101,6 +109,12 @@ struct cpufreq_freqs {* CPUFREQ GOVERNORS * **********************************************************
***********/Quoted 1 line
Quoted 8 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 117
Quoted 6 lines
xen/include/acpi/cpufreq/cpufreq.h +6
-0+/* The four internal governors used in intel_pstate */ +#define CPUFREQ_POLICY_POWERSAVE (1) +#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_USERSPACE (3) +#define CPUFREQ_POLICY_ONDEMAND (4) +From the comment, this looks like x86 specific. Maybe even
intel_pstate?
Quoted 1 line
Yes. It's currently only used by the
intel_pstatedriver.
After looking to this series, this statement looks wrong to me... You are using all these defines in the common cpufreq code (parameters, pmstat,...).
The cpufreq framework should be agnostic to any cpufreq driver implementation.
So it looks like to me that we want CPUFREQ_* to be exposed for anyone. And specifying the behavior when policy = 0 would be great too rather than relying on a future developer to not define 0.
Regards,
Signature · 1 line
Julien Grall
Quoted 34 lines · Julien Grall
Quoted 24 lines · Wei W
Quoted 23 lines · Julien Grall
Review
Quoted 1 line · Wei Wang
(quoted diff) +0
-0
b/xen/include/acpi/cpufreq/cpufreq.hQuoted 20 lines
index d10e4c7..71bb45c 100644
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */ @@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy);Quoted 8 lines
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 87
Quoted 2 lines
xen/include/acpi/cpufreq/cpufreq.h +2
-0+extern int intel_pstate_init (void ); +As said on a previous version [1],
intel_pstate_initis x86 specific. Although xen/include/acpi contains common headers.Please see our latest discussion here (the bottom of the link):
http://lists.xen.org/archives/html/xen-devel/2015-06/msg00047.html
Quoted 7 lines
Well we are planning to move
cpufreq.hout of acpi in order to use for device tree based platform. Most of these declaration is common.Although any x86 specific function would have to go out in a separate header.
Please avoid to add new one when it's possible. I don't see why a new asm-
x86/cpufreq.hcan't be added...
I don't have an objection to creating a new header like that. Jan, what's your opinion?
Quoted 25 lines
Quoted 7 lines
Quoted 7 lines
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 110
Quoted 6 lines
xen/include/acpi/cpufreq/cpufreq.h +0
-0extern int __cpufreq_set_policy (struct cpufreq_policy *data,struct cpufreq_policy *policy);@@ -101,6 +109,12 @@ struct cpufreq_freqs {* CPUFREQ GOVERNORS * **********************************************************
Quoted 12 lines
Quoted 10 lines
***********/
xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_freqs { · line 117
Quoted 7 lines
xen/include/acpi/cpufreq/cpufreq.h +6
-0+/* The four internal governors used in intel_pstate */ +#define CPUFREQ_POLICY_POWERSAVE (1) +#define CPUFREQ_POLICY_PERFORMANCE (2) +#define CPUFREQ_POLICY_USERSPACE (3) +#define CPUFREQ_POLICY_ONDEMAND (4) +From the comment, this looks like x86 specific. Maybe even
intel_pstate?Quoted 1 line
Yes. It's currently only used by the
intel_pstatedriver.After looking to this series, this statement looks wrong to me... You are using all these defines in the common cpufreq code (parameters, pmstat,...).
Quoted 6 lines
The cpufreq framework should be agnostic to any cpufreq driver implementation.
So it looks like to me that we want CPUFREQ_* to be exposed for anyone. And specifying the behavior when policy = 0 would be great too rather than relying on a future developer to not define 0.
How about renaming them to "INTEL_PSTATE_POLICY_XXXX" ?
Best,
Wei
Quoted 40 lines
Quoted 1 line
Quoted 1 line · On 15.06.15 at 02:30, <[email protected]> wrote:
Quoted 31 lines · Julien Grall
Quoted 30 lines · Wei W
Quoted 28 lines · Julien Grall
Review
Quoted 1 line · Wei Wang
(quoted diff) +0
-0
b/xen/include/acpi/cpufreq/cpufreq.hQuoted 17 lines
index d10e4c7..71bb45c 100644
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -34,6 +34,12 @@ struct acpi_cpufreq_data {extern struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS ]; +/* +* Maximum transition latency is in nanoseconds - if it's unknown, +* CPUFREQ_ETERNAL shall be used. +*/ +#define CPUFREQ_ETERNAL (-1) +struct cpufreq_cpuinfo {unsigned int max_freq;unsigned int second_max_freq;/* P1 if Turbo Mode is on */ xen/include/acpi/cpufreq/cpufreq.h struct cpufreq_policy { · line 87
Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +2
-0@@ -77,6 +83,8 @@ struct cpufreq_policy { }; DECLARE_PER_CPU(struct cpufreq_policy *, cpufreq_cpu_policy); +extern int intel_pstate_init (void ); +As said on a previous version [1],
intel_pstate_initis x86 specific. Although xen/include/acpi contains common headers.Quoted 4 lines
Quoted 2 lines
Please see our latest discussion here (the bottom of the link):
http://lists.xen.org/archives/html/xen-devel/2015-06/msg00047.htmlWell we are planning to move
cpufreq.hout of acpi in order to use fordevice
Quoted 2 lines
tree based platform. Most of these declaration is common.
Quoted 8 lines
Quoted 1 line
Although any x86 specific function would have to go out in a separate
header.
Quoted 3 lines
Please avoid to add new one when it's possible. I don't see why a new asm-
x86/cpufreq.hcan't be added...I don't have an objection to creating a new header like that. Jan, what's your opinion?
If there's no suitable header to put what you need, creating one like Julien suggested seems okay to me.
Jan
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 11.06.15 at 10:27, <[email protected]> wrote:
The
intel_pstatedriver is ported following its kernel code logic (commit: 93f0822d).In order to port the Linux source file with minimal modifications, some of the variable types are kept intact (e.g. "intcurrent_pstae", would otherwise be changed to "unsigned int").
Minimal modifications implies no whitespace changes either (and even less so indentation corruption, like I just spotted in ceiling_fp() and pid_calc(); I didn't look further). I.e. if you aim at that, a diff between the original and the Xen clone should be reasonably small (and that's what I'd likely look at in the end, as I then don't really want to review all code which already made it into upstream Linux).
xen/arch/x86/cpu/common.c static void __cpuinit generic_identify(struct cpuinfo_x86 *c) · line 242
Quoted 8 lines
xen/arch/x86/cpu/common.c +2
-0@@ -238,6 +238,9 @@ static void __cpuinit generic_identify(struct cpuinfo_x86 *c)if (cpu_has (c,X86_FEATURE_CLFLSH ) ) c->x86_clflush_size = ((ebx >>8 ) &0xff ) *8 ; +if (cpuid_ecx (6 ) &0x1 ) +set_bit (X86_FEATURE_APERFMPERF , c->x86_capability);
With that the kind of misplaced identical code pieces in cpufreq.c and powernow.c should go away. The three changes together would probably best be broken out to a separate patch, to keep the focus on this one on the introduction of intel_pstate.c.
Jan