x86: CPUID leaf 6 consolidation
v2 cover x86: CPUID leaf 6 consolidation
Integrate this leaf with CPU policy handling, to leverage the host policy when feature bits need evaluating.
1: cpu-policy: define bits of leaf 6
2: replace APERRMPERF synthetic feature bit 3: rename ARAT feature flag
4: Intel: use host CPU policy for ARAT checking 5: cpufreq: use host CPU policy for Turbo checking 6: cpufreq: use host CPU policy in HWP driver
Jan
PATCH v2 1/6 x86/cpu-policy: define bits of leaf 6
... as far as we presently use them in the codebase.
---
Or should we make both parts proper featureset elements? At least APERFMPERF could likely be made visible to guests (in principle).
---
v2: Use bool and unions.
xen/include/xen/lib/x86/cpu-policy.h +40 -1
@@ -121,7 +121,46 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x3 - PSN. */ uint64_t :64, :64; /* Leaf 0x4 - Structured Cache. */ uint64_t :64, :64; /* Leaf 0x5 - MONITOR. */ - uint64_t :64, :64; /* Leaf 0x6 - Therm/Perf. */ + +/* Leaf 0x6 - Therm/Perf. */ +union { +uint32_t _6a; +struct { + bool :1, + turbo:1 , + arat:1, + :1, + :1, + :1, + :1 , + hwp:1 , + hwp_notification:1 , + hwp_activity_window:1 , + hwp_epp:1 , + hwp_plr:1, + :1 , + hdc:1, + :1, + :1 , + hwp_peci:1, + :1, + :1 , + hw_feedback:1 ; + }; + }; +union { +uint32_t _6b; + }; +union { +uint32_t _6c; +struct { +bool aperfmperf:1 ; + }; + }; +union { +uint32_t _6d; + }; + uint64_t :64, :64; /* Leaf 0x7 - Structured Features. */ uint64_t :64, :64; /* Leaf 0x8 - rsvd */ uint64_t :64, :64; /* Leaf 0x9 - DCA */
Re: [PATCH v2 1/6] x86/cpu-policy: define bits of leaf 6
Quoted 3 lines · Jan Beulich
... as far as we presently use them in the codebase.
Signed-off-by Jan Beulich <[email protected]>
Re: [PATCH v2 1/6] x86/cpu-policy: define bits of leaf 6
In reply to Jan BeulichQuoted 45 lines · Jan Beulich
... as far as we presently use them in the codebase.
Signed-off-by Jan Beulich <[email protected]>---
Or should we make both parts proper featureset elements? At least APERFMPERF could likely be made visible to guests (in principle).
---
v2: Use bool and unions.xen/include/xen/lib/x86/cpu-policy.h +29
-1@@ -121,7 +121,46 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x3 - PSN. */ uint64_t :64, :64; /* Leaf 0x4 - Structured Cache. */ uint64_t :64, :64; /* Leaf 0x5 - MONITOR. */ - uint64_t :64, :64; /* Leaf 0x6 - Therm/Perf. */ + +/* Leaf 0x6 - Therm/Perf. */ +union { +uint32_t _6a; +struct { + bool :1, + turbo:1 , + arat:1, + :1, + :1, + :1, + :1 , + hwp:1 , + hwp_notification:1 , + hwp_activity_window:1 , + hwp_epp:1 , + hwp_plr:1, + :1 , + hdc:1, + :1, + :1 , + hwp_peci:1, + :1, + :1 , + hw_feedback:1 ; + }; + }; +union { +uint32_t _6b;
xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 162
Quoted 10 lines
xen/include/xen/lib/x86/cpu-policy.h +10
-0+ }; +union { +uint32_t _6c; +struct { +bool aperfmperf:1 ; + }; + }; +union { +uint32_t _6d; + };
The _6[a-d] variables are only needed for the featureset <-> policy conversion which isn't the case here (notice how you don't need it the series), and we're unlikely to want in the future.
This wants to read:
/* Leaf 0x6 - Therm/Perf. */
bool :1,
turbo:1,
arat:1,
:1,
:1,
:1,
:1,
hwp:1,
hwp_notification:1,
hwp_activity_window:1,
hwp_epp:1,
hwp_plr:1,
:1,
hdc:1,
:1,
:1,
hwp_peci:1,
:1,
:1,
hw_feedback:1;
uint32_t :32; /* b */
bool aperfmperf:1;
uint32_t :32; /* d */
and with that, Reviewed-by: Andrew Cooper <[email protected]>
Re: [PATCH v2 1/6] x86/cpu-policy: define bits of leaf 6
Quoted 88 lines · Andrew Cooper
Quoted 45 lines · Jan Beulich
... as far as we presently use them in the codebase.
Signed-off-by Jan Beulich <[email protected]>---
Or should we make both parts proper featureset elements? At least APERFMPERF could likely be made visible to guests (in principle).
---
v2: Use bool and unions.xen/include/xen/lib/x86/cpu-policy.h +29
-1@@ -121,7 +121,46 @@ struct cpu_policy uint64_t :64, :64; /* Leaf 0x3 - PSN. */ uint64_t :64, :64; /* Leaf 0x4 - Structured Cache. */ uint64_t :64, :64; /* Leaf 0x5 - MONITOR. */ - uint64_t :64, :64; /* Leaf 0x6 - Therm/Perf. */ + +/* Leaf 0x6 - Therm/Perf. */ +union { +uint32_t _6a; +struct { + bool :1, + turbo:1 , + arat:1, + :1, + :1, + :1, + :1 , + hwp:1 , + hwp_notification:1 , + hwp_activity_window:1 , + hwp_epp:1 , + hwp_plr:1, + :1 , + hdc:1, + :1, + :1 , + hwp_peci:1, + :1, + :1 , + hw_feedback:1 ; + }; + }; +union { +uint32_t _6b;xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 162
Quoted 10 lines
xen/include/xen/lib/x86/cpu-policy.h +10
-0+ }; +union { +uint32_t _6c; +struct { +bool aperfmperf:1 ; + }; + }; +union { +uint32_t _6d; + };The _6[a-d] variables are only needed for the featureset <-> policy conversion which isn't the case here (notice how you don't need it the series), and we're unlikely to want in the future.
This wants to read:
/* Leaf
0x6- Therm/Perf. */
bool :1,
turbo:1,
arat:1,
:1,
:1,
:1,
:1,
hwp:1,
hwp_notification:1,
hwp_activity_window:1,
hwp_epp:1,
hwp_plr:1,
:1,
hdc:1,
:1,
:1,
hwp_peci:1,
:1,
:1,
hw_feedback:1;
uint32_t:32; /* b */
bool aperfmperf:1;
uint32_t:32; /* d */
Quoted 1 line
and with that, Reviewed-by: Andrew Cooper <[email protected]>
Thanks, but: If then someone doesn't pay close attention when breaking up the "b" field (perhaps also into booleans), things may go wrong. I deliberately added the "raw" fields, despite not (presently) being used.
And to be frank: I said I would even before I sent the new version, without you indicating I shouldn't go this route. Now what is pretty much a mechanical patch will face yet more of a delay going in. I think requests like this should either be made in a timely manner, or simply be omitted (in particular if otherwise a patch is ready to go in). Had Jason not reviewed the series, and had I not indicated that on this basis I would commit it today, how much longer would I have had to wait? How's the backlog ever going to reduce this way?
Now that this is going to take yet longer anyway, we can as well deal with your naming request in reply to patch 6 (which really would apply here first, imo). I picked names largely based on what was used in the HWP driver, as that was the in-tree status quo. I can certainly move closer to what the SDM has, but your reply to patch 6 ended up being non-conclusive to me. I'll reply in more detail there.
Jan
PATCH v2 2/6 x86: replace APERFMPERF synthetic feature bit
In reply to Jan BeulichUse the respective host CPU policy bit instead. This has the (tolerable, as we generally assume symmetry anyway) effect of using the BSP's (unleveled) setting, rather than the result of leveling (as is done by identify_cpu() on boot_cpu_data, rendering the variable name somewhat misleading).
---
The leveling of boot_cpu_data is problematic anyway, as that way features can in principle disappear post-boot (as CPUs are being brought online; just that we don't think anymore that we really support physical CPU hotplug).
---
v2: Extend description.
xen/arch/x86/cpu/common.c +0 -4
@@ -523,10 +523,6 @@ static void generic_identify(struct cpuiif (cpu_has (c,X86_FEATURE_CLFLUSH ) ) c->x86_clflush_size = ((ebx >>8 ) &0xff ) *8 ; -if ( (c->cpuid_level >=CPUID_PM_LEAF ) && - (cpuid_ecx (CPUID_PM_LEAF ) &CPUID6_ECX_APERFMPERF_CAPABILITY ) ) -__set_bit (X86_FEATURE_APERFMPERF , c->x86_capability); -/* AMD-defined flags: level 0x80000001 */ if (c->extended_cpuid_level >=0x80000001 ) cpuid(0x80000001, &tmp, &tmp,
xen/arch/x86/include/asm/cpufeature.h +5 -2
@@ -11,7 +11,9 @@#include <xen/macros.h> #ifndef __ASSEMBLY__ +#include <asm/cpu-policy.h> #include <asm/cpuid.h> +#include <xen/lib/x86/cpu-policy.h> #else #include <asm/cpufeatureset.h> #endif
@@ -121,7 +123,6 @@ static inline bool boot_cpu_has(unsigned#define CPUID6_EAX_HDC BIT(13, U)#define CPUID6_EAX_HWP_PECI BIT(16, U)#define CPUID6_EAX_HW_FEEDBACK BIT(19, U) -#define CPUID6_ECX_APERFMPERF_CAPABILITY BIT(0, U)/* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1
@@ -175,6 +176,9 @@ static inline bool boot_cpu_has(unsigned#define cpu_has_fma4 boot_cpu_has(X86_FEATURE_FMA4)#define cpu_has_tbm boot_cpu_has(X86_FEATURE_TBM) +/* CPUID level 0x00000006.ecx */ +#define cpu_has_aperfmperf host_cpu_policy.basic.aperfmperf +/* CPUID level 0x0000000D:1.eax */ #define cpu_has_xsaveopt boot_cpu_has(X86_FEATURE_XSAVEOPT)#define cpu_has_xsavec boot_cpu_has(X86_FEATURE_XSAVEC)
@@ -292,7 +296,6 @@ static inline bool boot_cpu_has(unsigned/* Synthesized. */ #define cpu_has_arch_perfmon boot_cpu_has(X86_FEATURE_ARCH_PERFMON)#define cpu_has_cpuid_faulting boot_cpu_has(X86_FEATURE_CPUID_FAULTING) -#define cpu_has_aperfmperf boot_cpu_has(X86_FEATURE_APERFMPERF)#define cpu_has_xen_lbr boot_cpu_has(X86_FEATURE_XEN_LBR)#define cpu_has_xen_shstk (IS_ENABLED(CONFIG_XEN_SHSTK) && \ boot_cpu_has(X86_FEATURE_XEN_SHSTK))
xen/arch/x86/include/asm/cpufeatures.h +1 -1
@@ -19,7 +19,7 @@ XEN_CPUFEATURE(TSC_RELIABLE, X86_SY XEN_CPUFEATURE(XTOPOLOGY, X86_SYNTH( 5)) /* cpu topology enum extensions */ XEN_CPUFEATURE(CPUID_FAULTING, X86_SYNTH( 6)) /* cpuid faulting */XEN_CPUFEATURE (XEN_FRED ,X86_SYNTH (7 ))/* Xen uses FRED */ -XEN_CPUFEATURE(APERFMPERF, X86_SYNTH( 8)) /* APERFMPERF */ +/* Bit 8 unused */ XEN_CPUFEATURE(MFENCE_RDTSC, X86_SYNTH( 9)) /* MFENCE synchronizes RDTSC */ XEN_CPUFEATURE(XEN_SMEP, X86_SYNTH(10)) /* SMEP gets used by Xen itself */XEN_CPUFEATURE (XEN_SMAP ,X86_SYNTH (11 ))/* SMAP gets used by Xen itself */
Re: [PATCH v2 2/6] x86: replace APERFMPERF synthetic feature bit
Quoted 7 lines · Jan Beulich
Use the respective host CPU policy bit instead. This has the (tolerable, as we generally assume symmetry anyway) effect of using the BSP's (unleveled) setting, rather than the result of leveling (as is done by
identify_cpu()onboot_cpu_data, rendering the variable name somewhat misleading).Signed-off-by Jan Beulich <[email protected]>
PATCH v2 3/6 x86: rename ARAT feature flag
In reply to Jan BeulichAdd a XEN infix, to properly distinguish it from the CPUID feature flag (leaf 6 EAX bit 2).
---
Question is whether we still need opt_arat (and the command line option), or whether we could go directly from the CPUID bit (overriding it to 1 for older AMD [and Hygon?] CPUs). Or whether to have opt_arat affect the (host) CPU policy directly.
xen/arch/x86/acpi/cpu_idle.c +2 -2
@@ -109,7 +109,7 @@ void (*__read_mostly lapic_timer_on)(voibool lapic_timer_init (void ) { -if (boot_cpu_has (X86_FEATURE_ARAT ) ) +if (boot_cpu_has (X86_FEATURE_XEN_ARAT ) ) { lapic_timer_off = lapic_timer_nop; lapic_timer_on = lapic_timer_nop;
@@ -1463,7 +1463,7 @@ static void amd_cpuidle_init(struct acpiif ( !vendor_override ) { -if ( !boot_cpu_has (X86_FEATURE_ARAT ) ) +if ( !boot_cpu_has (X86_FEATURE_XEN_ARAT ) )hpet_broadcast_init ();if ( !lapic_timer_init () )
xen/arch/x86/cpu/amd.c +1 -1
@@ -1355,7 +1355,7 @@ static void cf_check init_amd(struct cpu* running in deep C states. */ if ( opt_arat && c->x86 >0x11 ) -__set_bit (X86_FEATURE_ARAT , c->x86_capability); +__set_bit (X86_FEATURE_XEN_ARAT , c->x86_capability);/* * Prior to Family 0x14, perf counters are not reset during warm reboot.
xen/arch/x86/cpu/hygon.c +1 -1
@@ -76,7 +76,7 @@ static void cf_check init_hygon(struct c/* Hygon processors have APIC timer running in deep C states. */ if (opt_arat) -__set_bit (X86_FEATURE_ARAT , c->x86_capability); +__set_bit (X86_FEATURE_XEN_ARAT , c->x86_capability);if (cpu_has (c,X86_FEATURE_EFRO )) {rdmsrl (MSR_K8_HWCR , value);
xen/arch/x86/cpu/intel.c +1 -1
@@ -668,7 +668,7 @@ static void cf_check init_intel(struct cif ( opt_arat && ( c->cpuid_level >=0x00000006 ) && (cpuid_eax (0x00000006 ) & (1u <<2 ) ) ) -__set_bit (X86_FEATURE_ARAT , c->x86_capability); +__set_bit (X86_FEATURE_XEN_ARAT , c->x86_capability);if ((opt_cpu_info && !(c->apicid & (c->x86_num_siblings -1 ))) || c == &boot_cpu_data )
xen/arch/x86/cpu/mwait-idle.c +2 -2
@@ -1633,7 +1633,7 @@ static int __init mwait_idle_probe(void) icpu = id->driver_data; cpuidle_state_table = icpu->state_table; -if (boot_cpu_has (X86_FEATURE_ARAT )) +if (boot_cpu_has (X86_FEATURE_XEN_ARAT )) lapic_timer_reliable_states =LAPIC_TIMER_ALWAYS_RELIABLE ; pr_debug(PREFIX "v" MWAIT_IDLE_VERSION " model %#x\n",
@@ -1792,7 +1792,7 @@ int __init mwait_idle_init(struct notifireturn -ENODEV ; err =mwait_idle_probe (); -if (!err && !boot_cpu_has (X86_FEATURE_ARAT )) { +if (!err && !boot_cpu_has (X86_FEATURE_XEN_ARAT )) {hpet_broadcast_init ();if (xen_cpuidle <0 && !hpet_broadcast_is_available ()) err = -ENODEV ;
xen/arch/x86/include/asm/cpufeatures.h +1 -1
@@ -13,7 +13,7 @@/* Synthetic features */ XEN_CPUFEATURE(CONSTANT_TSC, X86_SYNTH( 0)) /* TSC ticks at a constant rate */ XEN_CPUFEATURE(NONSTOP_TSC, X86_SYNTH( 1)) /* TSC does not stop in C states */ -XEN_CPUFEATURE(ARAT, X86_SYNTH( 2)) /* Always running APIC timer */ +XEN_CPUFEATURE(XEN_ARAT, X86_SYNTH( 2)) /* Xen may utilize always running APIC timer */ XEN_CPUFEATURE(ARCH_PERFMON, X86_SYNTH( 3)) /* Intel Architectural PerfMon */ XEN_CPUFEATURE(TSC_RELIABLE, X86_SYNTH( 4)) /* TSC is known to be reliable */XEN_CPUFEATURE (XTOPOLOGY ,X86_SYNTH (5 ))/* cpu topology enum extensions */
xen/arch/x86/time.c +1 -1
@@ -2642,7 +2642,7 @@ static int _disable_pit_irq(bool init)* XXX dom0 may rely on RTC interrupt delivery, so only enable * hpet_broadcast if FSB mode available or if force_hpet_broadcast. */ -if (cpuidle_using_deep_cstate () && !boot_cpu_has (X86_FEATURE_ARAT ) ) +if (cpuidle_using_deep_cstate () && !boot_cpu_has (X86_FEATURE_XEN_ARAT ) ) { init ?hpet_broadcast_init () :hpet_broadcast_resume ();if ( !hpet_broadcast_is_available () )
Re: [PATCH v2 3/6] x86: rename ARAT feature flag
Quoted 4 lines · Jan Beulich
Add a XEN infix, to properly distinguish it from the CPUID feature flag (leaf 6 EAX bit 2).
Signed-off-by Jan Beulich <[email protected]>
PATCH v2 4/6 x86/Intel: use host CPU policy for ARAT checking
In reply to Jan BeulichThere's no need to invoke CPUID yet another time. However, as the host CPU policy is set up only shortly after init_intel() ran on the BSP, defer the logic to a pre-SMP initcall. This can't be (a new) one in cpu/intel.c though, as that's linked after acpi/cpu_idle.c (which is where we already need the feature set). Since opt_arat is local to the cpu/ subtree, introduce a new Intel-specific helper to hold the code needed.
Further, as we assume symmetry anyway, use setup_force_cpu_cap() and hence limit the checking to the boot CPU.
---
The need to move where cpu_has_arat is checked would go away if we did away with opt_arat (as mentioned in the previous patch), and hence could use cpu_has_arat directly where right now XEN_ARAT is checked.
xen/arch/x86/acpi/cpu_idle.c +3 -0
@@ -1666,6 +1666,9 @@ static int __init cf_check cpuidle_presm {void *cpu = (void *)(long )smp_processor_id (); +if ( boot_cpu_data.vendor ==X86_VENDOR_INTEL ) +intel_init_arat (); +if ( !xen_cpuidle )return 0 ;
xen/arch/x86/cpu/intel.c +6 -4
@@ -665,10 +665,6 @@ static void cf_check init_intel(struct c__set_bit (X86_FEATURE_NONSTOP_TSC , c->x86_capability);__set_bit (X86_FEATURE_TSC_RELIABLE , c->x86_capability); } -if ( opt_arat && - ( c->cpuid_level >=0x00000006 ) && - (cpuid_eax (0x00000006 ) & (1u <<2 ) ) ) -__set_bit (X86_FEATURE_XEN_ARAT , c->x86_capability);if ((opt_cpu_info && !(c->apicid & (c->x86_num_siblings -1 ))) || c == &boot_cpu_data )
@@ -690,3 +686,9 @@ const struct cpu_dev __initconst_cf_clob .c_early_init = early_init_intel, .c_init = init_intel, }; + +void __init intel_init_arat (void ) +{ +if ( opt_arat && cpu_has_arat ) +setup_force_cpu_cap (X86_FEATURE_XEN_ARAT ); +}
xen/arch/x86/include/asm/cpufeature.h +3 -0
@@ -176,6 +176,9 @@ static inline bool boot_cpu_has(unsigned#define cpu_has_fma4 boot_cpu_has(X86_FEATURE_FMA4)#define cpu_has_tbm boot_cpu_has(X86_FEATURE_TBM) +/* CPUID level 0x00000006.eax */ +#define cpu_has_arat host_cpu_policy.basic.arat +/* CPUID level 0x00000006.ecx */ #define cpu_has_aperfmperf host_cpu_policy.basic.aperfmperf
xen/arch/x86/include/asm/processor.h +1 -0
@@ -102,6 +102,7 @@ extern void setup_force_cpu_cap(unsignedextern bool is_forced_cpu_cap (unsigned int cap);extern void print_cpu_info (unsigned int cpu);extern void init_intel_cacheinfo (struct cpuinfo_x86 *c); +extern void intel_init_arat (void );#define cpu_to_core (_cpu) (cpu_data[_cpu].cpu_core_id)#define cpu_to_socket (_cpu) (cpu_data[_cpu].phys_proc_id)
Re: [PATCH v2 4/6] x86/Intel: use host CPU policy for ARAT checking
Quoted 11 lines · Jan Beulich
There's no need to invoke CPUID yet another time. However, as the host CPU policy is set up only shortly after
init_intel()ran on the BSP, defer the logic to a pre-SMP initcall. This can't be (a new) one incpu/intel.cthough, as that's linked afteracpi/cpu_idle.c(which is where we already need the feature set). Sinceopt_aratis local to the cpu/ subtree, introduce a new Intel-specific helper to hold the code needed.Further, as we assume symmetry anyway, use
setup_force_cpu_cap()and hence limit the checking to the boot CPU.Signed-off-by Jan Beulich <[email protected]>
PATCH v2 5/6 x86/cpufreq: use host CPU policy for Turbo checking
In reply to Jan BeulichThere's no need to invoke CPUID yet another time - we assume symmetry anyway. With symmetry assumed, logging per-CPU also isn't very useful.
xen/arch/x86/acpi/cpufreq/acpi.c +4 -7
@@ -220,14 +220,11 @@ static unsigned int cf_check get_cur_frevoid intel_feature_detect (struct cpufreq_policy *policy) { -unsigned int eax; - - eax =cpuid_eax (6 ); -if (eax &0x2 ) { +if ( cpu_has_turbo ) + { policy->turbo =CPUFREQ_TURBO_ENABLED ; -if (cpufreq_verbose) -printk (XENLOG_INFO "CPU%u: Turbo Mode detected and enabled\n" , -smp_processor_id ()); +if ( cpufreq_verbose ) +printk_once (XENLOG_INFO "Turbo Mode detected and enabled\n" ); } }
xen/arch/x86/include/asm/cpufeature.h +1 -0
@@ -177,6 +177,7 @@ static inline bool boot_cpu_has(unsigned#define cpu_has_tbm boot_cpu_has(X86_FEATURE_TBM)/* CPUID level 0x00000006.eax */ +#define cpu_has_turbo host_cpu_policy.basic.turbo#define cpu_has_arat host_cpu_policy.basic.arat/* CPUID level 0x00000006.ecx */
Re: [PATCH v2 5/6] x86/cpufreq: use host CPU policy for Turbo checking
Quoted 5 lines · Jan Beulich
There's no need to invoke CPUID yet another time - we assume symmetry anyway. With symmetry assumed, logging per-CPU also isn't very useful.
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Andrew Cooper <[email protected]>
PATCH v2 6/6 x86/cpufreq: use host CPU policy in HWP driver
In reply to Jan BeulichThere's no need to invoke CPUID yet another time. This way two of the static booleans can also go away.
---
v2: Introduce cpu_has_*.
xen/arch/x86/acpi/cpufreq/hwp.c +14 -24
@@ -18,9 +18,6 @@static bool __ro_after_init hwp_in_use; -static bool __ro_after_init feature_hwp_notification; -static bool __ro_after_init feature_hwp_activity_window; -static bool __read_mostly feature_hdc;static bool __ro_after_init opt_cpufreq_hdc = true;
@@ -165,8 +162,6 @@ bool hwp_active(void)static bool __init hwp_available (void ) { -unsigned int eax; -if ( boot_cpu_data.cpuid_level <CPUID_PM_LEAF ) { hwp_verbose("cpuid_level (%#x) lacks HWP support\n",
@@ -183,29 +178,22 @@ static bool __init hwp_available(void)return false; } - eax =cpuid_eax (CPUID_PM_LEAF ); -hwp_verbose ("%d notify: %d act-window: %d energy-perf: %d pkg-level: %d peci: %d\n" , - !!(eax &CPUID6_EAX_HWP ), - !!(eax &CPUID6_EAX_HWP_NOTIFICATION ), - !!(eax &CPUID6_EAX_HWP_ACTIVITY_WINDOW ), - !!(eax &CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE ), - !!(eax &CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST ), - !!(eax &CPUID6_EAX_HWP_PECI )); + cpu_has_hwp, cpu_has_hwp_notification, + cpu_has_hwp_activity_window, cpu_has_hwp_epp, + cpu_has_hwp_plr, cpu_has_hwp_peci); -if ( !(eax &CPUID6_EAX_HWP ) ) +if ( !cpu_has_hwp )return false; -if ( !(eax &CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE ) ) +if ( !cpu_has_hwp_epp ) {hwp_verbose ("disabled: No energy/performance preference available" );return false; } - feature_hwp_notification = eax &CPUID6_EAX_HWP_NOTIFICATION ; - feature_hwp_activity_window = eax &CPUID6_EAX_HWP_ACTIVITY_WINDOW ; - feature_hdc = eax &CPUID6_EAX_HDC ; + feature_hdc = cpu_has_hdc; hwp_verbose("Hardware Duty Cycling (HDC) %ssupported%s\n", feature_hdc ? "" : "not ",
@@ -213,7 +201,7 @@ static bool __init hwp_available(void) : "");hwp_verbose ("HW_FEEDBACK %ssupported\n" , - (eax &CPUID6_EAX_HW_FEEDBACK ) ?"" :"not " ); + cpu_has_hw_feedback ?"" :"not " ); hwp_in_use = true;
@@ -226,7 +214,8 @@ static int cf_check hwp_cpufreq_verify(s {struct hwp_drv_data *data =per_cpu (hwp_drv_data, policy->cpu); -if ( !feature_hwp_activity_window && data->activity_window ) +if ( !cpu_has_hwp_activity_window && + data->activity_window ) {hwp_verbose ("HWP activity window not supported\n" );
@@ -268,7 +257,7 @@ static int cf_check hwp_cpufreq_target(s hwp_req.max_perf = data->maximum; hwp_req.desired = data->desired; hwp_req.energy_perf = data->energy_perf; -if ( feature_hwp_activity_window ) +if ( cpu_has_hwp_activity_window ) hwp_req.activity_window = data->activity_window;if ( hwp_req.raw == data->curr_req.raw )
@@ -365,7 +354,7 @@ static void cf_check hwp_init_msrs(void }/* Ensure we don't generate interrupts */ -if ( feature_hwp_notification ) +if ( cpu_has_hwp_notification )wrmsr_safe (MSR_HWP_INTERRUPT ,0 );if ( !(val &PM_ENABLE_HWP_ENABLE ) )
@@ -537,7 +526,8 @@ int get_hwp_para(unsigned int cpu,return -ENODATA ; cppc_para->features = - (feature_hwp_activity_window ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); + (cpu_has_hwp_activity_window + ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); cppc_para->lowest = data->hw.lowest; cppc_para->lowest_nonlinear = data->hw.most_efficient; cppc_para->nominal = data->hw.guaranteed;
@@ -585,7 +575,7 @@ int set_hwp_para(struct cpufreq_policy */* Clear out activity window if lacking HW supported. */ if ( (set_cppc->set_params &XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) && - !feature_hwp_activity_window ) + !cpu_has_hwp_activity_window ) { set_cppc->set_params &= ~XEN_SYSCTL_CPPC_SET_ACT_WINDOW ; cleared_act_window = true;
xen/arch/x86/include/asm/cpufeature.h +8 -8
@@ -115,14 +115,6 @@ static inline bool boot_cpu_has(unsigned }#define CPUID_PM_LEAF 6 -#define CPUID6_EAX_HWP BIT(7, U) -#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) -#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) -#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) -#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) -#define CPUID6_EAX_HDC BIT(13, U) -#define CPUID6_EAX_HWP_PECI BIT(16, U) -#define CPUID6_EAX_HW_FEEDBACK BIT(19, U)/* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1
@@ -179,6 +171,14 @@ static inline bool boot_cpu_has(unsigned/* CPUID level 0x00000006.eax */ #define cpu_has_turbo host_cpu_policy.basic.turbo#define cpu_has_arat host_cpu_policy.basic.arat +#define cpu_has_hwp host_cpu_policy.basic.hwp +#define cpu_has_hwp_notification host_cpu_policy.basic.hwp_notification +#define cpu_has_hwp_activity_window host_cpu_policy.basic.hwp_activity_window +#define cpu_has_hwp_epp host_cpu_policy.basic.hwp_epp +#define cpu_has_hwp_plr host_cpu_policy.basic.hwp_plr +#define cpu_has_hdc host_cpu_policy.basic.hdc +#define cpu_has_hwp_peci host_cpu_policy.basic.hwp_peci +#define cpu_has_hw_feedback host_cpu_policy.basic.hw_feedback/* CPUID level 0x00000006.ecx */ #define cpu_has_aperfmperf host_cpu_policy.basic.aperfmperf
Re: [PATCH v2 6/6] x86/cpufreq: use host CPU policy in HWP driver
Quoted 11 lines · Jan Beulich
There's no need to invoke CPUID yet another time. This way two of the static booleans can also go away.
Signed-off-by Jan Beulich <[email protected]>---
v2: Introduce cpu_has_*.
xen/arch/x86/acpi/cpufreq/hwp.c static int cf_check hwp_cpufreq_verify(s · line 218
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/hwp.c +2
-1@@ -226,7 +214,8 @@ static int cf_check hwp_cpufreq_verify(s {struct hwp_drv_data *data =per_cpu (hwp_drv_data, policy->cpu); -if ( !feature_hwp_activity_window && data->activity_window ) +if ( !cpu_has_hwp_activity_window && + data->activity_window )
This ...
xen/arch/x86/acpi/cpufreq/hwp.c int get_hwp_para(unsigned int cpu, · line 530
Quoted 11 lines
xen/arch/x86/acpi/cpufreq/hwp.c +2
-1{hwp_verbose ("HWP activity window not supported\n" );@@ -537,7 +526,8 @@ int get_hwp_para(unsigned int cpu,return -ENODATA ; cppc_para->features = - (feature_hwp_activity_window ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); + (cpu_has_hwp_activity_window + ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 );
...and this can still be on one line.
Preferably with that fixed:
Thanks,
Jason
Quoted 3 lines
xen/arch/x86/acpi/cpufreq/hwp.c +0
-0cppc_para->lowest = data->hw.lowest; cppc_para->lowest_nonlinear = data->hw.most_efficient; cppc_para->nominal = data->hw.guaranteed;
Re: [PATCH v2 6/6] x86/cpufreq: use host CPU policy in HWP driver
Quoted 20 lines · Jason Andryuk
xen/arch/x86/acpi/cpufreq/hwp.c static int cf_check hwp_cpufreq_verify(s · line 218
Quoted 10 lines · Jan Beulich
xen/arch/x86/acpi/cpufreq/hwp.c +2
-1@@ -226,7 +214,8 @@ static int cf_check hwp_cpufreq_verify(s {struct hwp_drv_data *data =per_cpu (hwp_drv_data, policy->cpu); -if ( !feature_hwp_activity_window && data->activity_window ) +if ( !cpu_has_hwp_activity_window && + data->activity_window )This ...
Quoted 7 lines
xen/arch/x86/acpi/cpufreq/hwp.c +0
-0{hwp_verbose ("HWP activity window not supported\n" );@@ -537,7 +526,8 @@ int get_hwp_para(unsigned int cpu,return -ENODATA ;
Quoted 6 lines
xen/arch/x86/acpi/cpufreq/hwp.c int get_hwp_para(unsigned int cpu, · line 530
Quoted 4 lines
xen/arch/x86/acpi/cpufreq/hwp.c +2
-1cppc_para->features = - (feature_hwp_activity_window ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); + (cpu_has_hwp_activity_window + ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 );...and this can still be on one line.
Oh, yes, the lines now became shorter again.
Quoted 3 lines
Preferably with that fixed:
Reviewed-by Jason Andryuk <[email protected]>
Thanks.
Jan
Re: [PATCH v2 6/6] x86/cpufreq: use host CPU policy in HWP driver
In reply to Jan BeulichQuoted 140 lines · Jan Beulich
There's no need to invoke CPUID yet another time. This way two of the static booleans can also go away.
Signed-off-by Jan Beulich <[email protected]>---
v2: Introduce cpu_has_*.xen/arch/x86/acpi/cpufreq/hwp.c +14
-24@@ -18,9 +18,6 @@static bool __ro_after_init hwp_in_use; -static bool __ro_after_init feature_hwp_notification; -static bool __ro_after_init feature_hwp_activity_window; -static bool __read_mostly feature_hdc;static bool __ro_after_init opt_cpufreq_hdc = true;@@ -165,8 +162,6 @@ bool hwp_active(void)static bool __init hwp_available (void ) { -unsigned int eax; -if ( boot_cpu_data.cpuid_level <CPUID_PM_LEAF ) { hwp_verbose("cpuid_level (%#x) lacks HWP support\n",@@ -183,29 +178,22 @@ static bool __init hwp_available(void)return false; } - eax =cpuid_eax (CPUID_PM_LEAF ); -hwp_verbose ("%d notify: %d act-window: %d energy-perf: %d pkg-level: %d peci: %d\n" , - !!(eax &CPUID6_EAX_HWP ), - !!(eax &CPUID6_EAX_HWP_NOTIFICATION ), - !!(eax &CPUID6_EAX_HWP_ACTIVITY_WINDOW ), - !!(eax &CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE ), - !!(eax &CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST ), - !!(eax &CPUID6_EAX_HWP_PECI )); + cpu_has_hwp, cpu_has_hwp_notification, + cpu_has_hwp_activity_window, cpu_has_hwp_epp, + cpu_has_hwp_plr, cpu_has_hwp_peci); -if ( !(eax &CPUID6_EAX_HWP ) ) +if ( !cpu_has_hwp )return false; -if ( !(eax &CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE ) ) +if ( !cpu_has_hwp_epp ) {hwp_verbose ("disabled: No energy/performance preference available" );return false; } - feature_hwp_notification = eax &CPUID6_EAX_HWP_NOTIFICATION ; - feature_hwp_activity_window = eax &CPUID6_EAX_HWP_ACTIVITY_WINDOW ; - feature_hdc = eax &CPUID6_EAX_HDC ; + feature_hdc = cpu_has_hdc; hwp_verbose("Hardware Duty Cycling (HDC) %ssupported%s\n", feature_hdc ? "" : "not ",@@ -213,7 +201,7 @@ static bool __init hwp_available(void) : "");hwp_verbose ("HW_FEEDBACK %ssupported\n" , - (eax &CPUID6_EAX_HW_FEEDBACK ) ?"" :"not " ); + cpu_has_hw_feedback ?"" :"not " ); hwp_in_use = true;@@ -226,7 +214,8 @@ static int cf_check hwp_cpufreq_verify(s {struct hwp_drv_data *data =per_cpu (hwp_drv_data, policy->cpu); -if ( !feature_hwp_activity_window && data->activity_window ) +if ( !cpu_has_hwp_activity_window && + data->activity_window ) {hwp_verbose ("HWP activity window not supported\n" );@@ -268,7 +257,7 @@ static int cf_check hwp_cpufreq_target(s hwp_req.max_perf = data->maximum; hwp_req.desired = data->desired; hwp_req.energy_perf = data->energy_perf; -if ( feature_hwp_activity_window ) +if ( cpu_has_hwp_activity_window ) hwp_req.activity_window = data->activity_window;if ( hwp_req.raw == data->curr_req.raw )@@ -365,7 +354,7 @@ static void cf_check hwp_init_msrs(void }/* Ensure we don't generate interrupts */ -if ( feature_hwp_notification ) +if ( cpu_has_hwp_notification )wrmsr_safe (MSR_HWP_INTERRUPT ,0 );if ( !(val &PM_ENABLE_HWP_ENABLE ) )@@ -537,7 +526,8 @@ int get_hwp_para(unsigned int cpu,return -ENODATA ; cppc_para->features = - (feature_hwp_activity_window ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); + (cpu_has_hwp_activity_window + ?XEN_SYSCTL_CPPC_FEAT_ACT_WINDOW :0 ); cppc_para->lowest = data->hw.lowest; cppc_para->lowest_nonlinear = data->hw.most_efficient; cppc_para->nominal = data->hw.guaranteed;@@ -585,7 +575,7 @@ int set_hwp_para(struct cpufreq_policy */* Clear out activity window if lacking HW supported. */ if ( (set_cppc->set_params &XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) && - !feature_hwp_activity_window ) + !cpu_has_hwp_activity_window ) { set_cppc->set_params &= ~XEN_SYSCTL_CPPC_SET_ACT_WINDOW ; cleared_act_window = true;xen/arch/x86/include/asm/cpufeature.h +0
-8@@ -115,14 +115,6 @@ static inline bool boot_cpu_has(unsigned }#define CPUID_PM_LEAF 6 -#define CPUID6_EAX_HWP BIT(7, U) -#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) -#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) -#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) -#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) -#define CPUID6_EAX_HDC BIT(13, U) -#define CPUID6_EAX_HWP_PECI BIT(16, U) -#define CPUID6_EAX_HW_FEEDBACK BIT(19, U)/* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1@@ -179,6 +171,14 @@ static inline bool boot_cpu_has(unsigned/* CPUID level 0x00000006.eax */ #define cpu_has_turbo host_cpu_policy.basic.turbo
xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned · line 182
Quoted 10 lines
xen/arch/x86/include/asm/cpufeature.h +8
-0#define cpu_has_arat host_cpu_policy.basic.arat +#define cpu_has_hwp host_cpu_policy.basic.hwp +#define cpu_has_hwp_notification host_cpu_policy.basic.hwp_notification +#define cpu_has_hwp_activity_window host_cpu_policy.basic.hwp_activity_window +#define cpu_has_hwp_epp host_cpu_policy.basic.hwp_epp +#define cpu_has_hwp_plr host_cpu_policy.basic.hwp_plr +#define cpu_has_hdc host_cpu_policy.basic.hdc +#define cpu_has_hwp_peci host_cpu_policy.basic.hwp_peci +#define cpu_has_hw_feedback host_cpu_policy.basic.hw_feedback
The indentation of these final 5 is one-too-few spaces.
I can't help but feel that notification could be shortened to notify. Except upon looking in the SDM, it's named HWP_INTERRUPT because it enumerates MSR_HWP_INTERRUPT.
Similarly, HWP_PLR is really HWP_REQUEST_PKG because it enumerates MSR_HWP_REQUEST_PKG.
ACTIVITY_WINDOW and EPP are wonky because they're out of order WRT PLR/REQUEST_PKG. It clearly means they all came in together, but have SKU controls.
But I digress. ACTIVITY_WINDOW can probably be shortened to just WINDOW, and that fixes the two egregiously long ones.
~Andrew
Re: [PATCH v2 6/6] x86/cpufreq: use host CPU policy in HWP driver
Quoted 39 lines · Andrew Cooper
Quoted 19 lines
xen/arch/x86/include/asm/cpufeature.h +0
-8@@ -115,14 +115,6 @@ static inline bool boot_cpu_has(unsigned }#define CPUID_PM_LEAF 6 -#define CPUID6_EAX_HWP BIT(7, U) -#define CPUID6_EAX_HWP_NOTIFICATION BIT(8, U) -#define CPUID6_EAX_HWP_ACTIVITY_WINDOW BIT(9, U) -#define CPUID6_EAX_HWP_ENERGY_PERFORMANCE_PREFERENCE BIT(10, U) -#define CPUID6_EAX_HWP_PACKAGE_LEVEL_REQUEST BIT(11, U) -#define CPUID6_EAX_HDC BIT(13, U) -#define CPUID6_EAX_HWP_PECI BIT(16, U) -#define CPUID6_EAX_HW_FEEDBACK BIT(19, U)/* CPUID level 0x00000001.edx */ #define cpu_has_fpu 1@@ -179,6 +171,14 @@ static inline bool boot_cpu_has(unsigned/* CPUID level 0x00000006.eax */ xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned · line 181
Quoted 10 lines
xen/arch/x86/include/asm/cpufeature.h +8
-0#define cpu_has_turbo host_cpu_policy.basic.turbo#define cpu_has_arat host_cpu_policy.basic.arat +#define cpu_has_hwp host_cpu_policy.basic.hwp +#define cpu_has_hwp_notification host_cpu_policy.basic.hwp_notification +#define cpu_has_hwp_activity_window host_cpu_policy.basic.hwp_activity_window +#define cpu_has_hwp_epp host_cpu_policy.basic.hwp_epp +#define cpu_has_hwp_plr host_cpu_policy.basic.hwp_plr +#define cpu_has_hdc host_cpu_policy.basic.hdc +#define cpu_has_hwp_peci host_cpu_policy.basic.hwp_peci +#define cpu_has_hw_feedback host_cpu_policy.basic.hw_feedbackThe indentation of these final 5 is one-too-few spaces.
I can't help but feel that notification could be shortened to notify. Except upon looking in the SDM, it's named
HWP_INTERRUPTbecause it enumeratesMSR_HWP_INTERRUPT.Similarly,
HWP_PLRis reallyHWP_REQUEST_PKGbecause it enumeratesMSR_HWP_REQUEST_PKG.
Quoted 6 lines
ACTIVITY_WINDOWand EPP are wonky because they're out of order WRT PLR/REQUEST_PKG. It clearly means they all came in together, but have SKU controls.But I digress.
ACTIVITY_WINDOWcan probably be shortened to just WINDOW, and that fixes the two egregiously long ones.
To be honest, I see only one of two options: Either we stick to what we had settled on when the HWP driver went in (switching to acronyms where helpful), or we strictly follow the SDM. In the latter case I think I will need to split this patch, for every of the renames to be separate (to be easier to verify). And the naming decisions then want applying in patch 1 as well.
Unless I hear otherwise (soon), I'll go the "strictly per SDM" route. Still, the union-or-not question in patch 1 also needs sorting, so I'm dependent anyway upon you replying in a somewhat timely manner.
Jan