Skip to contentSkip to conversation

x86: CPUID leaf 6 consolidation

PATCH In review Jan Beulich 3 participants 13 messages Jan 14 – Jan 15

lore
Share & tools
lore
#0 lore raw

v3 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

#1 lore raw

PATCH v3 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).
---
v3: Use SDM-conforming names. (Sorry Jason, had to drop you R-b once

    again.)

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_boost:1,
+                        arat:1,
+                        :1,
+                        :1,
+                        :1,
+                        :1,
+                        hwp:1,
+                        hwp_interrupt:1,
+                        hwp_activity_window:1,
+                        hwp_epp:1,
+                        hwp_request_pkg:1,
+                        :1,
+                        hdc:1,
+                        :1,
+                        :1,
+                        hwp_peci_override:1,
+                        :1,
+                        :1,
+                        hw_feedback:1;
+                };
+            };
+            union {
+                uint32_t _6b;
+            };
+            union {
+                uint32_t _6c;
+                struct {
+                    bool hw_feedback_cap: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 */
#2 lore raw

Re: [PATCH v3 1/6] x86/cpu-policy: define bits of leaf 6

Le 14/01/2026 à 14:45, Jan Beulich a écrit :

Quoted 48 lines

... 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).
---
v3: Use SDM-conforming names. (Sorry Jason, had to drop you R-b once

     again.)

v2: Use bool and unions.

xen/include/xen/lib/x86/cpu-policy.h +30 -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_boost:1,
+                        arat:1,
+                        :1,
+                        :1,
+                        :1,
+                        :1,
+                        hwp:1,
+                        hwp_interrupt:1,
+                        hwp_activity_window:1,
+                        hwp_epp:1,
+                        hwp_request_pkg:1,
+                        :1,
+                        hdc:1,
+                        :1,
+                        :1,
+                        hwp_peci_override:1,
+                        :1,
+                        :1,
+                        hw_feedback:1;
+                };
+            };
+            union {
+                uint32_t _6b;
+            };

xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 163

Quoted 10 lines
xen/include/xen/lib/x86/cpu-policy.h +10 -0
+            union {
+                uint32_t _6c;
+                struct {
+                    bool hw_feedback_cap:1;
+                };
+            };
+            union {
+                uint32_t _6d;
+            };
+

While I'm ok for the a and c unions, I'm not convinced by the b and d ones (union with just a single uint32_t in it) as it's quite verbose and inconsistent with the rest of the cpu_policy structure.

xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 166

Quoted 5 lines
xen/include/xen/lib/x86/cpu-policy.h +0 -0
              uint64_t :64, :64; /* Leaf 0x7 - Structured Features. */
              uint64_t :64, :64; /* Leaf 0x8 - rsvd */
              uint64_t :64, :64; /* Leaf 0x9 - DCA */

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#3 lore raw

Re: [PATCH v3 1/6] x86/cpu-policy: define bits of leaf 6

Quoted 55 lines · Teddy Astie

Le 14/01/2026 à 14:45, Jan Beulich a écrit :

Quoted 54 lines

... 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).
---
v3: Use SDM-conforming names. (Sorry Jason, had to drop you R-b once

     again.)

v2: Use bool and unions.

xen/include/xen/lib/x86/cpu-policy.h +36 -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_boost:1,
+                        arat:1,
+                        :1,
+                        :1,
+                        :1,
+                        :1,
+                        hwp:1,
+                        hwp_interrupt:1,
+                        hwp_activity_window:1,
+                        hwp_epp:1,
+                        hwp_request_pkg:1,
+                        :1,
+                        hdc:1,
+                        :1,
+                        :1,
+                        hwp_peci_override:1,
+                        :1,
+                        :1,
+                        hw_feedback:1;
+                };
+            };
+            union {
+                uint32_t _6b;
+            };
+            union {
+                uint32_t _6c;
+                struct {
+                    bool hw_feedback_cap:1;
+                };
+            };
Quoted 8 lines

xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 163

Quoted 4 lines
xen/include/xen/lib/x86/cpu-policy.h +4 -0
+            union {
+                uint32_t _6d;
+            };
+

While I'm ok for the a and c unions, I'm not convinced by the b and d ones (union with just a single uint32_t in it) as it's quite verbose and inconsistent with the rest of the cpu_policy structure.

Indeed for them I wasn't quite certain. I could drop the union wrapping for now (until individual fields appear), yet then I'd again be on the
edge: Use

            uint32_t _6b;

or

            uint32_t :32;

? Both have their pros and cons. Hence why I went with consistent layout for all 4 fields. If there was a clear majority preference for either of the above, I'd be fine to switch.

Jan

Reviewed-by on v3 1/6
#4 lore raw

Re: [PATCH v3 1/6] x86/cpu-policy: define bits of leaf 6

In reply to Jan Beulich
Quoted 7 lines · Jan Beulich

... as far as we presently use them in the codebase.

xen/include/xen/lib/x86/cpu-policy.h +3 -0
+            /* Leaf 0x6 - Therm/Perf. */
+            union {
+                uint32_t _6a;

xen/include/xen/lib/x86/cpu-policy.h struct cpu_policy · line 157

Quoted 10 lines
xen/include/xen/lib/x86/cpu-policy.h +8 -0
+                struct {
+                    bool :1,
 
+                        hw_feedback:1;
+                };
 
+            union {
+                uint32_t _6c;
+                struct {
+                    bool hw_feedback_cap:1;

Maybe with an comment of "/* aperf/mperf */" since that is probably how it is better know? I was confused with hw_feedback above which is different.

Actually, looking at patch 2, I'd prefer leaving this named aperfmperf. While not the SDM name, I think it's a more common name for the feature.

Either way (but preferably with aperfmperf):

Regards,
Jason

#5 lore raw

PATCH v3 2/6 x86: replace APERFMPERF synthetic feature bit

In reply to 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() 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).
---
v3: Re-base over naming changes.
v2: Extend description.

xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -80,7 +80,7 @@ unsigned int get_measured_perf(unsigned
         return 0;
 
     policy = per_cpu(cpufreq_cpu_policy, cpu);
-    if ( !policy || !cpu_has_aperfmperf )
+    if ( !policy || !cpu_has_hw_feedback_cap )
         return 0;
 
     switch (flag)
xen/arch/x86/cpu/common.c +0 -4
@@ -523,10 +523,6 @@ static void generic_identify(struct cpui
 	if ( 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 __ASSEMBLER__
+#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_hw_feedback_cap host_cpu_policy.basic.hw_feedback_cap
+
 /* 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 */
#6 lore raw

Re: [PATCH v3 2/6] x86: replace APERFMPERF synthetic feature bit

Le 14/01/2026 à 14:45, Jan Beulich a écrit :

Quoted 6 lines

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() on boot_cpu_data, rendering the variable name somewhat misleading).

Quoted 7 lines

---
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).

I think in the vast majority of cases, hotplugged CPUs are of same model or very similar; so shouldn't diverge too much in term of features. Otherwise, it's pretty much impossible to guarantee anything unless we have per-socket cpu datas.

Quoted 71 lines

---
v3: Re-base over naming changes.
v2: Extend description.

xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -1
@@ -80,7 +80,7 @@ unsigned int get_measured_perf(unsigned
          return 0;
 
      policy = per_cpu(cpufreq_cpu_policy, cpu);
-    if ( !policy || !cpu_has_aperfmperf )
+    if ( !policy || !cpu_has_hw_feedback_cap )
          return 0;
 
      switch (flag)
xen/arch/x86/cpu/common.c +0 -4
@@ -523,10 +523,6 @@ static void generic_identify(struct cpui
  	if ( 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 __ASSEMBLER__
+#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_hw_feedback_cap host_cpu_policy.basic.hw_feedback_cap
+
  /* 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 XEN_CPUFEATURE(TSC_RELIABLE, X86_SY · line 25

Quoted 8 lines
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 */

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#7 lore raw

PATCH v3 3/6 x86: rename ARAT feature flag

In reply to Jan Beulich

Add 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)(voi
 
 bool 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 acpi
 
         if ( !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
@@ -1239,7 +1239,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
@@ -81,7 +81,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 c
 	if ( 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 notifi
 		return -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
@@ -2644,7 +2644,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() )
#8 lore raw

PATCH v3 4/6 x86/Intel: use host CPU policy for ARAT checking

In reply to 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 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.
---
v3: Re-base over naming changes.

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 )
@@ -693,3 +689,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_hw_feedback_cap host_cpu_policy.basic.hw_feedback_cap
 
xen/arch/x86/include/asm/processor.h +1 -0
@@ -102,6 +102,7 @@ extern void setup_force_cpu_cap(unsigned
 extern 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)
#9 lore raw

PATCH v3 5/6 x86/cpufreq: use host CPU policy for Turbo checking

In reply to 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.

---
v3: Re-base over naming changes.

xen/arch/x86/acpi/cpufreq/acpi.c +4 -7
@@ -220,14 +220,11 @@ static unsigned int cf_check get_cur_fre
 
 void intel_feature_detect(struct cpufreq_policy *policy)
 {
-    unsigned int eax;
-
-    eax = cpuid_eax(6);
-    if (eax & 0x2) {
+    if ( cpu_has_turbo_boost )
+    {
         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_boost     host_cpu_policy.basic.turbo_boost
 #define cpu_has_arat            host_cpu_policy.basic.arat
 
 /* CPUID level 0x00000006.ecx */
#10 lore raw

PATCH v3 6/6 x86/cpufreq: use host CPU policy in HWP driver

In reply to Jan Beulich

There's no need to invoke CPUID yet another time. This way two of the static booleans can also go away.

---
v3: Undo some line wrapping. Correct padding in asm/cpufeature.h. Re-base
over naming changes.
v2: Introduce cpu_has_*.

xen/arch/x86/acpi/cpufreq/hwp.c +12 -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_interrupt,
+                cpu_has_hwp_activity_window, cpu_has_hwp_epp,
+                cpu_has_hwp_request_pkg, cpu_has_hwp_peci_override);
 
-    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,7 @@ 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 +256,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 +353,7 @@ static void cf_check hwp_init_msrs(void
     }
 
     /* Ensure we don't generate interrupts */
-    if ( feature_hwp_notification )
+    if ( cpu_has_hwp_interrupt )
         wrmsr_safe(MSR_HWP_INTERRUPT, 0);
 
     if ( !(val & PM_ENABLE_HWP_ENABLE) )
@@ -537,7 +525,7 @@ 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 +573,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_boost     host_cpu_policy.basic.turbo_boost
 #define cpu_has_arat            host_cpu_policy.basic.arat
+#define cpu_has_hwp             host_cpu_policy.basic.hwp
+#define cpu_has_hwp_interrupt   host_cpu_policy.basic.hwp_interrupt
+#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_request_pkg host_cpu_policy.basic.hwp_request_pkg
+#define cpu_has_hdc             host_cpu_policy.basic.hdc
+#define cpu_has_hwp_peci_override host_cpu_policy.basic.hwp_peci_override
+#define cpu_has_hw_feedback     host_cpu_policy.basic.hw_feedback
 
 /* CPUID level 0x00000006.ecx */
 #define cpu_has_hw_feedback_cap host_cpu_policy.basic.hw_feedback_cap
Reviewed-by on v3 6/6
#11 lore raw

Re: [PATCH v3 6/6] x86/cpufreq: use host CPU policy in HWP driver

Le 14/01/2026 à 14:47, Jan Beulich a écrit :

Quoted 144 lines

There's no need to invoke CPUID yet another time. This way two of the static booleans can also go away.

---
v3: Undo some line wrapping. Correct padding in asm/cpufeature.h. Re-base
over naming changes.
v2: Introduce cpu_has_*.

xen/arch/x86/acpi/cpufreq/hwp.c +12 -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_interrupt,
+                cpu_has_hwp_activity_window, cpu_has_hwp_epp,
+                cpu_has_hwp_request_pkg, cpu_has_hwp_peci_override);
 
-    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,7 @@ 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 +256,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 +353,7 @@ static void cf_check hwp_init_msrs(void
      }
 
      /* Ensure we don't generate interrupts */
-    if ( feature_hwp_notification )
+    if ( cpu_has_hwp_interrupt )
          wrmsr_safe(MSR_HWP_INTERRUPT, 0);
 
      if ( !(val & PM_ENABLE_HWP_ENABLE) )
@@ -537,7 +525,7 @@ 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 +573,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 +1 -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_boost     host_cpu_policy.basic.turbo_boost
  #define cpu_has_arat            host_cpu_policy.basic.arat
+#define cpu_has_hwp             host_cpu_policy.basic.hwp

xen/arch/x86/include/asm/cpufeature.h static inline bool boot_cpu_has(unsigned · line 184

Quoted 10 lines
xen/arch/x86/include/asm/cpufeature.h +7 -0
+#define cpu_has_hwp_interrupt   host_cpu_policy.basic.hwp_interrupt
+#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_request_pkg host_cpu_policy.basic.hwp_request_pkg
+#define cpu_has_hdc             host_cpu_policy.basic.hdc
+#define cpu_has_hwp_peci_override host_cpu_policy.basic.hwp_peci_override
+#define cpu_has_hw_feedback     host_cpu_policy.basic.hw_feedback
 
  /* CPUID level 0x00000006.ecx */
  #define cpu_has_hw_feedback_cap host_cpu_policy.basic.hw_feedback_cap

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech