[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Date: Fri, 6 Feb 2026 15:30:05 -0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6ZmR/VYUbsIrA583I6+recTTPOLRPVLSgfhbcINoDhs=; b=sOaoIKvKqzctSq2bwHvBz3I6YEjiBoSBnrSdvQHk0eM15hAlnXnRE5KljjmNgdFRLlSkXaI5LL7wjKSb9bFWE3q3+IB7As7Kck7bbwcvWq65gutAN3RFZ3nWk7WwM722B8ma+Ge6nBfg64Cdv+BR/27Kxmu8pAREXuUOcZ6K7UrJLYAPhs0SOh/S2HE11JJQnI7VVb3i78iiQCtVOZUfapSzyxeTTN6D0bnx5a8FNNUa0GgsNZXY6j1ag/V7jLdTaUA4g7zA3klJ/n7fEXBb7Jt8YQQNmfXayn32JulTO97mDeRXG5UDfj0OABlAWOD11bM5aWJlM57JdHkOaTeJIw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AdAZsrjptcoaV9g61fEmjozNwviYhCE2HOZymQm1IZnyqgtni8sSiaXiCo9c2svWR9OgIoYRI7/OpmOEPm2jrmtzBu3CnsiIR01btz21oQiEU1hpF/eyplGT2PyqoIQJFZfva9qzR4m2gG30qo2S+QnJ2wsWEBrM0PShUH3fUyk3DStXa4LKHfLMy2icizcSlD8hyRRe/N/Iu9J02Bj3UyU9H1Q05KrZmELoyQx1lsNVj5y9G9Y9rdmwaKpeisjEgS59QU8L3zscykuAjUG70wMW+rAQ1qdld8FYEHswe1XeVq6iNqjILHxfIJ+fYyHvXUq7YnwGyb+0ZOEiWO9xdA==
  • Cc: <jbeulich@xxxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <roger.pau@xxxxxxxxxx>, <jason.andryuk@xxxxxxx>, <stefano.stabellini@xxxxxxx>, <alejandro.garciavallejo@xxxxxxx>
  • Delivery-date: Fri, 06 Feb 2026 23:30:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
---
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(-)

diff --git a/xen/arch/x86/acpi/Makefile b/xen/arch/x86/acpi/Makefile
index 041377e2bb..aa476f65d5 100644
--- a/xen/arch/x86/acpi/Makefile
+++ b/xen/arch/x86/acpi/Makefile
@@ -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
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index d7e79e752a..cddd7337bb 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -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
diff --git a/xen/drivers/Makefile b/xen/drivers/Makefile
index 2a1ae8ad13..3d81b8dde4 100644
--- a/xen/drivers/Makefile
+++ b/xen/drivers/Makefile
@@ -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/
diff --git a/xen/drivers/cpufreq/Kconfig b/xen/drivers/cpufreq/Kconfig
index cce80f4aec..49631f92de 100644
--- a/xen/drivers/cpufreq/Kconfig
+++ b/xen/drivers/cpufreq/Kconfig
@@ -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.
diff --git a/xen/include/acpi/cpufreq/cpufreq.h 
b/xen/include/acpi/cpufreq/cpufreq.h
index 0171ccf0ba..9529730d9c 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -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; }
diff --git a/xen/include/acpi/cpufreq/processor_perf.h 
b/xen/include/acpi/cpufreq/processor_perf.h
index 0a87bc0384..bad9d94865 100644
--- a/xen/include/acpi/cpufreq/processor_perf.h
+++ b/xen/include/acpi/cpufreq/processor_perf.h
@@ -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;
diff --git a/xen/include/xen/acpi.h b/xen/include/xen/acpi.h
index 90635ba0f3..7077c27150 100644
--- a/xen/include/xen/acpi.h
+++ b/xen/include/xen/acpi.h
@@ -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);
 
diff --git a/xen/include/xen/pmstat.h b/xen/include/xen/pmstat.h
index 6096560d3c..4efddad438 100644
--- a/xen/include/xen/pmstat.h
+++ b/xen/include/xen/pmstat.h
@@ -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;
diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h
index 1268632344..1b431fc726 100644
--- a/xen/include/xen/sched.h
+++ b/xen/include/xen/sched.h
@@ -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)
 {
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.