Skip to contentSkip to conversation

x86/cpufreq: Add Kconfig option for CPU frequency scaling

PATCH Superseded Stefano Stabellini 3 participants 4 messages Feb 6 – Feb 10

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 x86/cpufreq: Add Kconfig option for CPU frequency scaling

Add CONFIG_CPUFREQ to allow CPU frequency scaling support to be disabled at build time. When disabled, this removes cpufreq code from the build.

Add stubs where necessary.

---
Changes in v2:
- add stubs for cpufreq_add/del_cpu
- also gate hwp_active

---
 xen/arch/x86/acpi/Makefile                |  2 +-
 xen/common/Kconfig                        |  4 ++--
 xen/drivers/Makefile                      |  2 +-
 xen/drivers/cpufreq/Kconfig               | 16 +++++++++++++++-
 xen/include/acpi/cpufreq/cpufreq.h        | 13 ++++++++++++-
 xen/include/acpi/cpufreq/processor_perf.h |  3 ---
 xen/include/xen/acpi.h                    |  8 +++++++-
 xen/include/xen/pmstat.h                  | 15 ++++++++++++++-
 xen/include/xen/sched.h                   |  9 +++++++--
 9 files changed, 59 insertions(+), 13 deletions(-)
xen/arch/x86/acpi/Makefile +1 -1
index 041377e2bb..aa476f65d5 100644
@@ -1,4 +1,4 @@
-obj-y += cpufreq/
+obj-$(CONFIG_CPUFREQ) += cpufreq/
 
 obj-y += lib.o power.o cpu_idle.o cpuidle_menu.o
 obj-bin-y += boot.init.o wakeup_prot.o
xen/common/Kconfig +2 -2
index d7e79e752a..cddd7337bb 100644
@@ -652,7 +652,7 @@ endmenu
 
 config PM_OP
 	bool "Enable Performance Management Operation"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  This option shall enable userspace performance management control
@@ -660,7 +660,7 @@ config PM_OP
 
 config PM_STATS
 	bool "Enable Performance Management Statistics"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  Enable collection of performance management statistics to aid in
xen/drivers/Makefile +1 -1
index 2a1ae8ad13..3d81b8dde4 100644
@@ -1,5 +1,5 @@
 obj-y += char/
-obj-$(CONFIG_HAS_CPUFREQ) += cpufreq/
+obj-$(CONFIG_CPUFREQ) += cpufreq/
 obj-$(CONFIG_HAS_PCI) += pci/
 obj-$(CONFIG_HAS_VPCI) += vpci/
 obj-$(CONFIG_HAS_PASSTHROUGH) += passthrough/
xen/drivers/cpufreq/Kconfig +15 -1
index cce80f4aec..49631f92de 100644
@@ -1,3 +1,17 @@
-
 config HAS_CPUFREQ
 	bool
+
+config CPUFREQ
+	bool "CPU Frequency scaling"
+	default y
+	depends on HAS_CPUFREQ
+	help
+	  Enable CPU frequency scaling and power management governors.
+	  This allows Xen to dynamically adjust CPU P-states (performance
+	  states) based on system load.
+
+	  Disabling this option removes all cpufreq governors and power
+	  management interfaces. This is useful for real-time systems or
+	  minimal hypervisor builds.
+
+	  If unsure, say Y.
xen/include/acpi/cpufreq/cpufreq.h +12 -1
index 0171ccf0ba..9529730d9c 100644
@@ -381,8 +381,19 @@ int write_ondemand_up_threshold(unsigned int up_threshold);
 
 int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq);
 
+#ifdef CONFIG_CPUFREQ
+int  cpufreq_add_cpu(unsigned int cpu);
+int  cpufreq_del_cpu(unsigned int cpu);
+
 void cpufreq_dbs_timer_suspend(void);
 void cpufreq_dbs_timer_resume(void);
+#else
+static inline int  cpufreq_add_cpu(unsigned int cpu) { return -ENOSYS; }
+static inline int  cpufreq_del_cpu(unsigned int cpu) { return -ENOSYS; }
+
+static inline void cpufreq_dbs_timer_suspend(void) {}
+static inline void cpufreq_dbs_timer_resume(void) {}
+#endif
 
 void intel_feature_detect(struct cpufreq_policy *policy);
 
@@ -398,7 +409,7 @@ void intel_feature_detect(struct cpufreq_policy *policy);
 
 int hwp_cmdline_parse(const char *s, const char *e);
 int hwp_register_driver(void);
-#ifdef CONFIG_INTEL
+#if defined(CONFIG_INTEL) && defined(CONFIG_CPUFREQ)
 bool hwp_active(void);
 #else
 static inline bool hwp_active(void) { return false; }
xen/include/acpi/cpufreq/processor_perf.h +0 -3
index 0a87bc0384..bad9d94865 100644
@@ -36,9 +36,6 @@ static inline void cpufreq_statistic_exit(unsigned int cpu) {}
 
 int  cpufreq_limit_change(unsigned int cpu);
 
-int  cpufreq_add_cpu(unsigned int cpu);
-int  cpufreq_del_cpu(unsigned int cpu);
-
 struct processor_performance {
     uint32_t state;
     uint32_t platform_limit;
xen/include/xen/acpi.h +7 -1
index 90635ba0f3..7077c27150 100644
@@ -185,8 +185,14 @@ static inline unsigned int acpi_get_csubstate_limit(void) { return 0; }
 static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }
 #endif
 
-#ifdef XEN_GUEST_HANDLE
+#if defined(XEN_GUEST_HANDLE) && defined(CONFIG_CPUFREQ)
 int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32));
+#elif defined(XEN_GUEST_HANDLE)
+static inline int acpi_set_pdc_bits(unsigned int acpi_id,
+                                    XEN_GUEST_HANDLE(uint32) pdc)
+{
+    return -ENOSYS;
+}
 #endif
 int arch_acpi_set_pdc_bits(u32 acpi_id, u32 *, u32 mask);
 
xen/include/xen/pmstat.h +14 -1
index 6096560d3c..4efddad438 100644
@@ -5,10 +5,23 @@
 #include <public/platform.h> /* for struct xen_processor_power */
 #include <public/sysctl.h>   /* for struct pm_cx_stat */
 
+#ifdef CONFIG_CPUFREQ
 int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf);
-long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power);
 int set_cppc_pminfo(unsigned int acpi_id,
                     const struct xen_processor_cppc *cppc_data);
+#else
+static inline int set_px_pminfo(uint32_t acpi_id,
+                                struct xen_processor_performance *perf)
+{
+    return -ENOSYS;
+}
+static inline int set_cppc_pminfo(unsigned int acpi_id,
+                                  const struct xen_processor_cppc *cppc_data)
+{
+    return -ENOSYS;
+}
+#endif
+long set_cx_pminfo(uint32_t acpi_id, struct xen_processor_power *power);
 
 #ifdef CONFIG_COMPAT
 struct compat_processor_performance;
xen/include/xen/sched.h +7 -2
index 1268632344..1b431fc726 100644
@@ -1255,9 +1255,14 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
-extern enum cpufreq_controller {
+enum cpufreq_controller {
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
-} cpufreq_controller;
+};
+#ifdef CONFIG_CPUFREQ
+extern enum cpufreq_controller cpufreq_controller;
+#else
+#define cpufreq_controller FREQCTL_none
+#endif
 
 static always_inline bool is_cpufreq_controller(const struct domain *d)
 {
Signature · 1 line
2.25.1
#1 lore raw

On 07.02.2026 00:30, Stefano Stabellini wrote:> --- a/xen/common/Kconfig

Quoted 11 lines

+++ b/xen/common/Kconfig

xen/common/Kconfig +1 -1
@@ -652,7 +652,7 @@ endmenu
 
 config PM_OP
 	bool "Enable Performance Management Operation"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  This option shall enable userspace performance management control

xen/common/Kconfig config PM_OP · line 666

Quoted 8 lines
xen/common/Kconfig +1 -1
@@ -660,7 +660,7 @@ config PM_OP
 
 config PM_STATS
 	bool "Enable Performance Management Statistics"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  Enable collection of performance management statistics to aid in

Is the original HAS_CPUFREQ misleading here? do_pm_op() (in pm-op.c) is also doing some C-state related work. You may not compile that out just because of CPUFREQ=n. Same for pmstat.c.

Quoted 11 lines
xen/drivers/cpufreq/Kconfig +5 -1
@@ -1,3 +1,17 @@
-
 config HAS_CPUFREQ
 	bool
+
+config CPUFREQ
+	bool "CPU Frequency scaling"
+	default y
+	depends on HAS_CPUFREQ

xen/drivers/cpufreq/Kconfig line 17

Quoted 10 lines
xen/drivers/cpufreq/Kconfig +10 -0
+	help
+	  Enable CPU frequency scaling and power management governors.
+	  This allows Xen to dynamically adjust CPU P-states (performance
+	  states) based on system load.
+
+	  Disabling this option removes all cpufreq governors and power
+	  management interfaces. This is useful for real-time systems or
+	  minimal hypervisor builds.
+
+	  If unsure, say Y.

Looks like we're trying to get rid of such re-stating of what the default is.

xen/include/acpi/cpufreq/cpufreq.h int write_ondemand_up_threshold(unsigned int up_threshold); · line 386

Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
@@ -381,8 +381,19 @@ int write_ondemand_up_threshold(unsigned int up_threshold);
 
 int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq);
 
+#ifdef CONFIG_CPUFREQ
+int  cpufreq_add_cpu(unsigned int cpu);
+int  cpufreq_del_cpu(unsigned int cpu);

If already you move these, please also get rid of the double blanks.

xen/include/acpi/cpufreq/cpufreq.h int write_ondemand_up_threshold(unsigned int up_threshold); · line 392

Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
 void cpufreq_dbs_timer_suspend(void);
 void cpufreq_dbs_timer_resume(void);
+#else
+static inline int  cpufreq_add_cpu(unsigned int cpu) { return -ENOSYS; }
+static inline int  cpufreq_del_cpu(unsigned int cpu) { return -ENOSYS; }

Here and below - no use of ENOSYS, please. EOPNOTSUPP it is everywhere else (unless dating back very far).

xen/include/xen/acpi.h static inline unsigned int acpi_get_csubstate_limit(void) { return 0; } · line 188

Quoted 7 lines
xen/include/xen/acpi.h +0 -1
@@ -185,8 +185,14 @@ static inline unsigned int acpi_get_csubstate_limit(void) { return 0; }
 static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }
 #endif
 
-#ifdef XEN_GUEST_HANDLE

If you leave this as-is, ...

xen/include/xen/acpi.h static inline unsigned int acpi_get_csubstate_limit(void) { return 0; } · line 196

Quoted 9 lines
xen/include/xen/acpi.h +7 -0
+#if defined(XEN_GUEST_HANDLE) && defined(CONFIG_CPUFREQ)
 int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32));
+#elif defined(XEN_GUEST_HANDLE)
+static inline int acpi_set_pdc_bits(unsigned int acpi_id,
+                                    XEN_GUEST_HANDLE(uint32) pdc)
+{
+    return -ENOSYS;
+}
 #endif

... the overall result may be a tiny bit tidier.

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1260

Quoted 10 lines
xen/include/xen/sched.h +1 -2
@@ -1255,9 +1255,14 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
-extern enum cpufreq_controller {
+enum cpufreq_controller {
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
-} cpufreq_controller;

This enum would better ...

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1262

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+};
+#ifdef CONFIG_CPUFREQ
+extern enum cpufreq_controller cpufreq_controller;

... stay inside here, then also making the split of type and var decl unnecessary. The two affected platform-ops likely want compiling out, too.

Jan

#2 lore raw
Quoted 13 lines · Jan Beulich

On 07.02.2026 00:30, Stefano Stabellini wrote:> --- a/xen/common/Kconfig

Quoted 12 lines

+++ b/xen/common/Kconfig

(quoted diff) +1 -1
@@ -652,7 +652,7 @@ endmenu
 
 config PM_OP
 	bool "Enable Performance Management Operation"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  This option shall enable userspace performance management control
@@ -660,7 +660,7 @@ config PM_OP
 
Quoted 11 lines

Review config PM_OP · line 666

Quoted 7 lines
(quoted diff) +1 -1
 config PM_STATS
 	bool "Enable Performance Management Statistics"
-	depends on ACPI && HAS_CPUFREQ && SYSCTL
+	depends on ACPI && CPUFREQ && SYSCTL
 	default y
 	help
 	  Enable collection of performance management statistics to aid in

Is the original HAS_CPUFREQ misleading here? do_pm_op() (in pm-op.c) is also doing some C-state related work. You may not compile that out just because of CPUFREQ=n. Same for pmstat.c.

I managed to resolve this with little changes thanks to DCE

Quoted 16 lines
Quoted 16 lines
xen/drivers/cpufreq/Kconfig +10 -1
@@ -1,3 +1,17 @@
-
 config HAS_CPUFREQ
 	bool
+
+config CPUFREQ
+	bool "CPU Frequency scaling"
+	default y
+	depends on HAS_CPUFREQ
+	help
+	  Enable CPU frequency scaling and power management governors.
+	  This allows Xen to dynamically adjust CPU P-states (performance
+	  states) based on system load.
+
Quoted 8 lines

xen/drivers/cpufreq/Kconfig line 17

Quoted 5 lines
xen/drivers/cpufreq/Kconfig +5 -0
+	  Disabling this option removes all cpufreq governors and power
+	  management interfaces. This is useful for real-time systems or
+	  minimal hypervisor builds.
+
+	  If unsure, say Y.

Looks like we're trying to get rid of such re-stating of what the default is.

OK

Quoted 11 lines

xen/include/acpi/cpufreq/cpufreq.h int write_ondemand_up_threshold(unsigned int up_threshold); · line 386

Quoted 9 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
@@ -381,8 +381,19 @@ int write_ondemand_up_threshold(unsigned int up_threshold);
 
 int write_userspace_scaling_setspeed(unsigned int cpu, unsigned int freq);
 
+#ifdef CONFIG_CPUFREQ
+int  cpufreq_add_cpu(unsigned int cpu);
+int  cpufreq_del_cpu(unsigned int cpu);

If already you move these, please also get rid of the double blanks.

OK

Quoted 8 lines

xen/include/acpi/cpufreq/cpufreq.h int write_ondemand_up_threshold(unsigned int up_threshold); · line 391

Quoted 5 lines
xen/include/acpi/cpufreq/cpufreq.h +3 -0
 void cpufreq_dbs_timer_suspend(void);
 void cpufreq_dbs_timer_resume(void);
+#else
+static inline int  cpufreq_add_cpu(unsigned int cpu) { return -ENOSYS; }
+static inline int  cpufreq_del_cpu(unsigned int cpu) { return -ENOSYS; }

Here and below - no use of ENOSYS, please. EOPNOTSUPP it is everywhere else (unless dating back very far).

OK

Quoted 10 lines

xen/include/xen/acpi.h static inline unsigned int acpi_get_csubstate_limit(void) { return 0; } · line 188

Quoted 7 lines
xen/include/xen/acpi.h +0 -1
@@ -185,8 +185,14 @@ static inline unsigned int acpi_get_csubstate_limit(void) { return 0; }
 static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }
 #endif
 
-#ifdef XEN_GUEST_HANDLE

If you leave this as-is, ...

Quoted 11 lines

xen/include/xen/acpi.h static inline unsigned int acpi_get_csubstate_limit(void) { return 0; } · line 196

Quoted 9 lines
xen/include/xen/acpi.h +7 -0
+#if defined(XEN_GUEST_HANDLE) && defined(CONFIG_CPUFREQ)
 int acpi_set_pdc_bits(unsigned int acpi_id, XEN_GUEST_HANDLE(uint32));
+#elif defined(XEN_GUEST_HANDLE)
+static inline int acpi_set_pdc_bits(unsigned int acpi_id,
+                                    XEN_GUEST_HANDLE(uint32) pdc)
+{
+    return -ENOSYS;
+}
 #endif

... the overall result may be a tiny bit tidier.

OK

Quoted 13 lines

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1260

Quoted 10 lines
xen/include/xen/sched.h +1 -2
@@ -1255,9 +1255,14 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
-extern enum cpufreq_controller {
+enum cpufreq_controller {
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
-} cpufreq_controller;

This enum would better ...

Quoted 7 lines

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1262

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+};
+#ifdef CONFIG_CPUFREQ
+extern enum cpufreq_controller cpufreq_controller;

... stay inside here, then also making the split of type and var decl unnecessary.

The two affected platform-ops likely want compiling out, too.

I am not sure I understood your suggestion. If this is what you are thinking about, it doesn't seem like an improvement.

xen/include/xen/sched.h +4 -2
index 1b431fc726..e8f5dfd473 100644
@@ -1255,13 +1255,15 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
+#ifdef CONFIG_CPUFREQ
 enum cpufreq_controller {
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
 };
-#ifdef CONFIG_CPUFREQ
 extern enum cpufreq_controller cpufreq_controller;
 #else
-#define cpufreq_controller FREQCTL_none
+#define FREQCTL_none        0
+#define FREQCTL_dom0_kernel 1
+#define cpufreq_controller  FREQCTL_none
 #endif
 
 
#3 lore raw
Quoted 34 lines · Stefano Stabellini
Quoted 14 lines · Jan Beulich

On 07.02.2026 00:30, Stefano Stabellini wrote:> --- a/xen/common/Kconfig

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1260

Quoted 10 lines
xen/include/xen/sched.h +1 -2
@@ -1255,9 +1255,14 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
-extern enum cpufreq_controller {
+enum cpufreq_controller {
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
-} cpufreq_controller;

This enum would better ...

Quoted 7 lines

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1262

Quoted 3 lines
xen/include/xen/sched.h +3 -0
+};
+#ifdef CONFIG_CPUFREQ
+extern enum cpufreq_controller cpufreq_controller;

... stay inside here, then also making the split of type and var decl unnecessary.

The two affected platform-ops likely want compiling out, too.

I am not sure I understood your suggestion. If this is what you are thinking about, it doesn't seem like an improvement.

xen/include/xen/sched.h +1 -0
@@ -1255,13 +1255,15 @@ static always_inline bool is_iommu_enabled(const struct domain *d)
 extern bool sched_smt_power_savings;
 extern bool sched_disable_smt_switching;
 
+#ifdef CONFIG_CPUFREQ
 enum cpufreq_controller {

xen/include/xen/sched.h static always_inline bool is_iommu_enabled(const struct domain *d) · line 1267

Quoted 10 lines
xen/include/xen/sched.h +3 -2
     FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen
 };
-#ifdef CONFIG_CPUFREQ
 extern enum cpufreq_controller cpufreq_controller;
 #else
-#define cpufreq_controller FREQCTL_none
+#define FREQCTL_none        0
+#define FREQCTL_dom0_kernel 1
+#define cpufreq_controller  FREQCTL_none
 #endif

No. FREQCTL_* shouldn't need to be visible at all when CPUFREQ=n. Hence the reference to the two platform-ops, where one (and cpufreq_controller) is used. If those uses are also suitably compiled out, the #define-s above shouldn't be necessary. That said, use of IS_ENABLED() there would of course require the arrangement to stay as you had it originally.

Jan