x86/cpufreq: Add Kconfig option for CPU frequency scaling
PATCH v3 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.
Move the cpufreq_controller enum and is_cpufreq_controller() inside #ifdef CONFIG_CPUFREQ so that FREQCTL_* values are not visible when CPUFREQ is disabled. Provide a stub is_cpufreq_controller() that returns false when CPUFREQ is not configured.
Compile out the XENPF_change_freq and XENPF_getidletime platform ops when CONFIG_CPUFREQ is disabled, as they require cpufreq_controller.
Add stubs where necessary.
---
Changes in v3:
- Move enum cpufreq_controller inside #ifdef CONFIG_CPUFREQ so FREQCTL_* values are not visible when CPUFREQ=n
- Keep enum and variable declaration combined
- Wrap XENPF_change_freq and XENPF_getidletime cases with #ifdef CONFIG_CPUFREQ
- Add __maybe_unused to the out: label since it's only used by XENPF_getidletime
- Move is_cpufreq_controller() inside #ifdef CONFIG_CPUFREQ and provide a stub returning false for the !CPUFREQ case
- use -EOPNOTSUPP instead of -ENOSYS
- code style fixes
--- xen/arch/x86/acpi/Makefile | 2 +- xen/arch/x86/platform_hypercall.c | 4 +++- xen/drivers/Makefile | 2 +- xen/drivers/acpi/pm-op.c | 3 ++- xen/drivers/acpi/pmstat.c | 8 ++++++-- xen/drivers/cpufreq/Kconfig | 14 +++++++++++++- 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 | 7 +++++++ 11 files changed, 67 insertions(+), 12 deletions(-)
xen/arch/x86/acpi/Makefile +1 -1
@@ -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/arch/x86/platform_hypercall.c +3 -1
@@ -485,6 +485,7 @@ ret_t do_platform_op( ret =acpi_enter_sleep (&op->u.enter_acpi_sleep);break ; +#ifdef CONFIG_CPUFREQ case XENPF_change_freq: ret = -ENOSYS ;if ( cpufreq_controller != FREQCTL_dom0_kernel )
@@ -544,6 +545,7 @@ ret_t do_platform_op( ret = -EFAULT ;break ; } +#endif case XENPF_set_processor_pminfo: switch ( op->u.set_pminfo.type )
@@ -936,7 +938,7 @@ ret_t do_platform_op(break ; } - out: + out:__maybe_unused ;spin_unlock (&xenpf_lock);return ret;
xen/drivers/Makefile +1 -1
@@ -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/acpi/pm-op.c +2 -1
@@ -367,7 +367,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)return ret; } -if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) ) +if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) || + !IS_ENABLED (CPUFREQ ) )return -EINVAL ; pmpt = processor_pminfo[op->cpuid];
xen/drivers/acpi/pmstat.c +6 -2
@@ -76,6 +76,9 @@ void cpufreq_statistic_update(unsigned int cpu, uint8_t from, uint8_t to)spinlock_t *cpufreq_statistic_lock = &per_cpu (cpufreq_statistic_lock, cpu); +if ( !IS_ENABLED (CPUFREQ ) ) +return ; +spin_lock (cpufreq_statistic_lock); pxpt =per_cpu (cpufreq_statistic_data, cpu);
@@ -105,7 +108,7 @@ int cpufreq_statistic_init(unsigned int cpu)spin_lock_init (cpufreq_statistic_lock); -if ( !pmpt ) +if ( !pmpt || !IS_ENABLED (CPUFREQ ) )return -EINVAL ;/* Only need to initialize in Px mode */
@@ -225,7 +228,8 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)int ret =0 ;const struct processor_pminfo *pmpt; -if ( !op || (op->cpuid >= nr_cpu_ids) || !cpu_online (op->cpuid) ) +if ( !IS_ENABLED (CPUFREQ ) || !op || (op->cpuid >= nr_cpu_ids) || + !cpu_online (op->cpuid) )return -EINVAL ; pmpt = processor_pminfo[op->cpuid];
xen/drivers/cpufreq/Kconfig +13 -1
@@ -1,3 +1,15 @@ - 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.
xen/include/acpi/cpufreq/cpufreq.h +12 -1
@@ -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 -EOPNOTSUPP ; } +static inline int cpufreq_del_cpu (unsigned int cpu) {return -EOPNOTSUPP ; } + +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
@@ -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 +8 -0
@@ -186,7 +186,15 @@ static inline void acpi_set_csubstate_limit(unsigned int new_limit) { return; }#endif #ifdef XEN_GUEST_HANDLE +#ifdef CONFIG_CPUFREQ int acpi_set_pdc_bits (unsigned int acpi_id,XEN_GUEST_HANDLE (uint32 )); +#else +static inline int acpi_set_pdc_bits (unsigned int acpi_id, +XEN_GUEST_HANDLE (uint32) pdc) +{ +return -EOPNOTSUPP ; +} +#endif #endif int arch_acpi_set_pdc_bits (u32 acpi_id,u32 *,u32 mask);
xen/include/xen/pmstat.h +14 -1
@@ -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 -EOPNOTSUPP ; +} +static inline int set_cppc_pminfo (unsigned int acpi_id, +const struct xen_processor_cppc *cppc_data) +{ +return -EOPNOTSUPP ; +} +#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 -0
@@ -1255,6 +1255,7 @@ 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 extern enum cpufreq_controller { FREQCTL_none, FREQCTL_dom0_kernel, FREQCTL_xen } cpufreq_controller;
@@ -1274,6 +1275,12 @@ static always_inline bool is_cpufreq_controller(const struct domain *d)return (is_pv_domain (d) &&is_hardware_domain (d) && cpufreq_controller == FREQCTL_dom0_kernel); } +#else +static always_inline bool is_cpufreq_controller(const struct domain *d) +{ +return false; +} +#endif int cpupool_move_domain (struct domain *d,struct cpupool *c);int cpupool_do_sysctl (struct xen_sysctl_cpupool_op *op);
Signature · 1 line
2.25.1
Quoted 13 lines · Stefano Stabellini
xen/arch/x86/platform_hypercall.c +1
-0@@ -485,6 +485,7 @@ ret_t do_platform_op( ret =acpi_enter_sleep (&op->u.enter_acpi_sleep);break ; +#ifdef CONFIG_CPUFREQ case XENPF_change_freq: ret = -ENOSYS ;if ( cpufreq_controller != FREQCTL_dom0_kernel )
xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 548
Quoted 4 lines
xen/arch/x86/platform_hypercall.c +1
-0@@ -544,6 +545,7 @@ ret_t do_platform_op( ret = -EFAULT ; break; } +#endif
You must not hide case labels like this. Instead, use:
case XENPF_change_freq:
ret = -ENOSYS;
if ( !IS_ENABLED(CONFIG_CPUFREQ) )
break;
...
which in turn ...
xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 942
Quoted 10 lines
xen/arch/x86/platform_hypercall.c +1
-1case XENPF_set_processor_pminfo: switch ( op->u.set_pminfo.type )@@ -936,7 +938,7 @@ ret_t do_platform_op(break ; } - out: + out:__maybe_unused ;spin_unlock (&xenpf_lock);
... removes the need for this hunk.
xen/drivers/acpi/pm-op.c int do_pm_op(struct xen_sysctl_pm_op *op) · line 371
Quoted 11 lines
xen/drivers/acpi/pm-op.c +2
-1@@ -367,7 +367,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)return ret; } -if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) ) +if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) || + !IS_ENABLED (CPUFREQ ) )
Everywhere else in this patch, CONFIG_CPUFREQ.
You won't get a compile error for typo-ing a name inside IF_ENABLED(), but it won't function correctly either.
~Andrew
Quoted 36 lines · Andrew Cooper
Quoted 13 lines · Stefano Stabellini
xen/arch/x86/platform_hypercall.c +1
-0@@ -485,6 +485,7 @@ ret_t do_platform_op( ret =acpi_enter_sleep (&op->u.enter_acpi_sleep);break ; +#ifdef CONFIG_CPUFREQ case XENPF_change_freq: ret = -ENOSYS ;if ( cpufreq_controller != FREQCTL_dom0_kernel )xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 548
Quoted 4 lines
xen/arch/x86/platform_hypercall.c +1
-0@@ -544,6 +545,7 @@ ret_t do_platform_op( ret = -EFAULT ; break; } +#endif You must not hide case labels like this. Instead, use:
case
XENPF_change_freq:
ret =-ENOSYS;
if ( !IS_ENABLED(CONFIG_CPUFREQ) )
break;
...which in turn ...
Quoted 7 lines
xen/arch/x86/platform_hypercall.c +0
-0case XENPF_set_processor_pminfo: switch ( op->u.set_pminfo.type )@@ -936,7 +938,7 @@ ret_t do_platform_op(break ; }
Quoted 5 lines
xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 942
Quoted 3 lines
xen/arch/x86/platform_hypercall.c +1
-1- out: + out:__maybe_unused ;spin_unlock (&xenpf_lock);... removes the need for this hunk.
I can do that
Quoted 8 lines
Quoted 8 lines
xen/drivers/acpi/pm-op.c +0
-0@@ -367,7 +367,8 @@ int do_pm_op(struct xen_sysctl_pm_op *op)return ret; }
Quoted 8 lines
xen/drivers/acpi/pm-op.c int do_pm_op(struct xen_sysctl_pm_op *op) · line 371
Quoted 3 lines
xen/drivers/acpi/pm-op.c +2
-1-if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) ) +if ( op->cpuid >= nr_cpu_ids || !cpu_online (op->cpuid) || + !IS_ENABLED (CPUFREQ ) )Everywhere else in this patch,
CONFIG_CPUFREQ.You won't get a compile error for typo-ing a name inside
IF_ENABLED(), but it won't function correctly either.
Oh man now that I have seen it I cannot unsee it. I'll respin it immediately.
Quoted 2 lines · Andrew Cooper
You won't get a compile error for typo-ing a name inside
IF_ENABLED(), but it won't function correctly either.
There's beauty in having a typo explaining the effects of a typo :)
Cheers,
Alejandro