x86: separate powernow/hwp/acpi cpufreq code
v2 cover x86: separate powernow/hwp/acpi cpufreq code
This short series aims to make platform-specific parts of cpufreq optional and dependant on INTEL & AMD config options. This is to allow for tuning the build for either AMD or Intel platform exclusively and hence to drop the code that would be left unused.
The initial v1 patch has been extended to not only cover HWP & Powernow drivers, but additionally ACPI driver is moved outside of cpufreq generic code and as Intel-dependant piece is put under CONFIG_INTEL option.
Patch v1 & related discussion are here:
https://lore.kernel.org/xen-devel/[email protected]/
Sergiy Kibrik (2):
x86/cpufreq: move ACPI cpufreq driver into separate file x86/cpufreq: separate powernow/hwp/acpi cpufreq code
xen/arch/x86/acpi/cpufreq/Makefile | 5 +- xen/arch/x86/acpi/cpufreq/acpi.c | 622 ++++++++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 598 +------------------------- xen/drivers/acpi/pmstat.c | 2 +- xen/drivers/cpufreq/cpufreq.c | 3 +- xen/drivers/cpufreq/utility.c | 2 +- xen/include/acpi/cpufreq/cpufreq.h | 10 + 7 files changed, 644 insertions(+), 598 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/acpi.c
Signature · 1 line
2.25.1
PATCH v2 1/2 x86/cpufreq: move ACPI cpufreq driver into separate file
Separate ACPI driver from generic initialization cpufreq code. This way acpi-cpufreq can become optional in the future and be disabled from non-Intel builds.
Other than acpi_register_driver() helper added and clean up a list of included headers no changes to code were introduced.
--- xen/arch/x86/acpi/cpufreq/Makefile | 1 + xen/arch/x86/acpi/cpufreq/acpi.c | 622 ++++++++++++++++++++++++++++ xen/arch/x86/acpi/cpufreq/cpufreq.c | 592 +------------------------- xen/include/acpi/cpufreq/cpufreq.h | 1 + 4 files changed, 625 insertions(+), 591 deletions(-) create mode 100644 xen/arch/x86/acpi/cpufreq/acpi.c
xen/arch/x86/acpi/cpufreq/Makefile +1 -0
@@ -1,3 +1,4 @@ +obj-y += acpi.o obj-y += cpufreq.o obj-y += hwp.o obj-y += powernow.o
xen/arch/x86/acpi/cpufreq/acpi.c new file +622 -0
622 lines not on this page · raw message
xen/arch/x86/acpi/cpufreq/cpufreq.c +1 -591
612 lines not on this page · raw message
xen/include/acpi/cpufreq/cpufreq.h +1 -0
@@ -260,4 +260,5 @@ int get_hwp_para(unsigned int cpu,int set_hwp_para (struct cpufreq_policy *policy,struct xen_set_cppc_para *set_cppc); +int acpi_register_driver (void );#endif /* __XEN_CPUFREQ_PM_H__ */
Signature · 1 line
2.25.1
Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file
Quoted 6 lines · Sergiy Kibrik
Separate ACPI driver from generic initialization cpufreq code. This way acpi-cpufreq can become optional in the future and be disabled from non-Intel builds.
Other than
acpi_register_driver()helper added and clean up a list of included headers no changes to code were introduced.
And perhaps that's okay despite the many style violations that you move around. However, acpi_register_driver() is too generic a name. How about acpi_cpufreq_register() (not not have it grow overly long)? Plus
Quoted 21 lines
xen/arch/x86/acpi/cpufreq/acpi.c new file +18
-0@@ -0,0 +1,622 @@ +/* +* cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $) +* +* Copyright (C) 2001, 2002 Andy Grover <[email protected]> +* Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]> +* Copyright (C) 2002 - 2004 Dominik Brodowski <[email protected]> +* Copyright (C) 2006 Denis Sadykov <[email protected]> +* +* Feb 2008 - Liu Jinsong <[email protected]> +* porting acpi-cpufreq.c from Linux 2.6.23 to Xen hypervisor +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +*
xen/arch/x86/acpi/cpufreq/acpi.c line 28
Quoted 10 lines
xen/arch/x86/acpi/cpufreq/acpi.c new file +10
-0+* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; If not, see <http://www.gnu.org/licenses/>. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/
... I expect this should be transformed into an SPDX line. I expect the one in cpufreq.c wasn't picked up when the conversion was done because it doesn't fully match whatever pattern was looked for at the time.
Jan
Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file
03.07.24 18:07, Jan Beulich:
Quoted 11 lines · Sergiy Kibrik
Quoted 6 lines
Separate ACPI driver from generic initialization cpufreq code. This way acpi-cpufreq can become optional in the future and be disabled from non-Intel builds.
Other than
acpi_register_driver()helper added and clean up a list of included headers no changes to code were introduced.And perhaps that's okay despite the many style violations that you move around. However,
acpi_register_driver()is too generic a name. How aboutacpi_cpufreq_register()(not not have it grow overly long)? Plus
yes, sure
Quoted 22 lines
Quoted 22 lines
xen/arch/x86/acpi/cpufreq/acpi.c new file +18
-0@@ -0,0 +1,622 @@ +/* +* cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $) +* +* Copyright (C) 2001, 2002 Andy Grover <[email protected]> +* Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]> +* Copyright (C) 2002 - 2004 Dominik Brodowski <[email protected]> +* Copyright (C) 2006 Denis Sadykov <[email protected]> +* +* Feb 2008 - Liu Jinsong <[email protected]> +* porting acpi-cpufreq.c from Linux 2.6.23 to Xen hypervisor +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +*
[..]
Quoted 8 lines
Quoted 3 lines
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */... I expect this should be transformed into an SPDX line. I expect the one in
cpufreq.cwasn't picked up when the conversion was done because it doesn't fully match whatever pattern was looked for at the time.
would the line
/* SPDX-License-Identifier: GPL-2.0-or-later */
be correct here?
-Sergiy
Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file
Quoted 33 lines · Sergiy Kibrik
03.07.24 18:07, Jan Beulich:
Quoted 22 lines · Sergiy Kibrik
Quoted 21 lines
xen/arch/x86/acpi/cpufreq/acpi.c new file +18
-0@@ -0,0 +1,622 @@ +/* +* cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $) +* +* Copyright (C) 2001, 2002 Andy Grover <[email protected]> +* Copyright (C) 2001, 2002 Paul Diefenbaugh <[email protected]> +* Copyright (C) 2002 - 2004 Dominik Brodowski <[email protected]> +* Copyright (C) 2006 Denis Sadykov <[email protected]> +* +* Feb 2008 - Liu Jinsong <[email protected]> +* porting acpi-cpufreq.c from Linux 2.6.23 to Xen hypervisor +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or (at +* your option) any later version. +* [..]
Quoted 8 lines
Quoted 3 lines
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */... I expect this should be transformed into an SPDX line. I expect the one in
cpufreq.cwasn't picked up when the conversion was done because it doesn't fully match whatever pattern was looked for at the time.
Quoted 5 lines
would the line
/* SPDX-License-Identifier: GPL-2.0-or-later */
be correct here?
I think so, yes.
Jan
PATCH v2 2/2 x86/cpufreq: separate powernow/hwp/acpi cpufreq code
In reply to Sergiy KibrikBuild AMD Architectural P-state driver when CONFIG_AMD is on, and Intel Hardware P-States driver together with ACPI Processor P-States driver when CONFIG_INTEL is on respectively, allowing for a platform-specific build.
---
changes in v2:
- disable acpi-cpufreq driver as well when !INTEL
- leave a stub for hwp_active() only when !INTEL
- updated patch description
--- xen/arch/x86/acpi/cpufreq/Makefile | 6 +++--- xen/arch/x86/acpi/cpufreq/cpufreq.c | 8 +++++--- xen/drivers/acpi/pmstat.c | 2 +- xen/drivers/cpufreq/cpufreq.c | 3 ++- xen/drivers/cpufreq/utility.c | 2 +- xen/include/acpi/cpufreq/cpufreq.h | 9 +++++++++ 6 files changed, 21 insertions(+), 9 deletions(-)
xen/arch/x86/acpi/cpufreq/Makefile +3 -3
@@ -1,4 +1,4 @@ -obj-y += acpi.o +obj-$(CONFIG_INTEL) += acpi.o obj-y += cpufreq.o -obj-y += hwp.o -obj-y += powernow.o +obj-$(CONFIG_INTEL) += hwp.o +obj-$(CONFIG_AMD) += powernow.o
xen/arch/x86/acpi/cpufreq/cpufreq.c +5 -3
@@ -50,10 +50,12 @@ static int __init cf_check cpufreq_driver_init(void)switch ( cpufreq_xen_opts[i] ) {case CPUFREQ_xen: - ret =acpi_register_driver (); + ret =IS_ENABLED (CONFIG_INTEL ) ? +acpi_register_driver () : -ENODEV ;break ;case CPUFREQ_hwp: - ret =hwp_register_driver (); + ret =IS_ENABLED (CONFIG_INTEL ) ? +hwp_register_driver () : -ENODEV ;break ;case CPUFREQ_none: ret =0 ;
@@ -67,7 +69,7 @@ static int __init cf_check cpufreq_driver_init(void)case X86_VENDOR_AMD :case X86_VENDOR_HYGON : - ret =powernow_register_driver (); + ret =IS_ENABLED (CONFIG_AMD ) ?powernow_register_driver () : -ENODEV ;break ; } }
xen/drivers/acpi/pmstat.c +1 -1
@@ -255,7 +255,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN );if ( !strncmp (op->u.get_para.scaling_driver,XEN_HWP_DRIVER_NAME , -CPUFREQ_NAME_LEN ) ) +CPUFREQ_NAME_LEN ) &&IS_ENABLED (CONFIG_INTEL ) ) ret =get_hwp_para (policy->cpu, &op->u.get_para.u.cppc_para);else {
xen/drivers/cpufreq/cpufreq.c +2 -1
@@ -120,7 +120,8 @@ static int __init cf_check setup_cpufreq_option(const char *str)if ( arg[0 ] && arg[1 ] ) ret =cpufreq_cmdline_parse (arg +1 , end); } -else if ( choice <0 && !cmdline_strcmp (str,"hwp" ) ) +else if ( choice <0 && !cmdline_strcmp (str,"hwp" ) && +IS_ENABLED (CONFIG_INTEL ) ) { xen_processor_pmbits |=XEN_PROCESSOR_PM_PX ; cpufreq_controller = FREQCTL_xen;
xen/drivers/cpufreq/utility.c +1 -1
@@ -379,7 +379,7 @@ int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag)if (!cpu_online (cpu) || !(policy =per_cpu (cpufreq_cpu_policy, cpu)))return 0 ; - freq_avg =get_measured_perf (cpu, flag); + freq_avg =IS_ENABLED (CONFIG_INTEL ) ?get_measured_perf (cpu, flag) :0 ;if ( freq_avg >0 )return freq_avg;
xen/include/acpi/cpufreq/cpufreq.h +9 -0
@@ -254,11 +254,20 @@ 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 bool hwp_active (void ); +#else +static inline bool hwp_active (void ) +{ +return false; +} +#endif +int get_hwp_para (unsigned int cpu,struct xen_cppc_para *cppc_para);int set_hwp_para (struct cpufreq_policy *policy,struct xen_set_cppc_para *set_cppc);int acpi_register_driver (void ); +#endif /* __XEN_CPUFREQ_PM_H__ */
Signature · 1 line
2.25.1
Re: [XEN PATCH v2 2/2] x86/cpufreq: separate powernow/hwp/acpi cpufreq code
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 258
Quoted 8 lines · Sergiy Kibrik
xen/drivers/acpi/pmstat.c +1
-1@@ -255,7 +255,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN );if ( !strncmp (op->u.get_para.scaling_driver,XEN_HWP_DRIVER_NAME , -CPUFREQ_NAME_LEN ) ) +CPUFREQ_NAME_LEN ) &&IS_ENABLED (CONFIG_INTEL ) )
Wrapping like this is confusing, not just because of the flawed indentation. Please can this be
if ( !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME,
CPUFREQ_NAME_LEN) &&
IS_ENABLED(CONFIG_INTEL) )? Perhaps the IS_ENABLED() would also better be first (not just here).
xen/drivers/cpufreq/utility.c int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag) · line 384
Quoted 10 lines
xen/drivers/cpufreq/utility.c +1
-1@@ -379,7 +379,7 @@ int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag)if (!cpu_online (cpu) || !(policy =per_cpu (cpufreq_cpu_policy, cpu)))return 0 ; - freq_avg =get_measured_perf (cpu, flag); + freq_avg =IS_ENABLED (CONFIG_INTEL ) ?get_measured_perf (cpu, flag) :0 ;if ( freq_avg >0 )return freq_avg;
Why is this? APERF/MPERF aren't Intel-only MSRs.
Quoted 13 lines
xen/include/acpi/cpufreq/cpufreq.h +6
-0@@ -254,11 +254,20 @@ 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 bool hwp_active (void ); +#else +static inline bool hwp_active (void ) +{ +return false; +}
xen/include/acpi/cpufreq/cpufreq.h void intel_feature_detect(struct cpufreq_policy *policy); · line 273
Quoted 10 lines
xen/include/acpi/cpufreq/cpufreq.h +3
-0+#endif +int get_hwp_para (unsigned int cpu,struct xen_cppc_para *cppc_para);int set_hwp_para (struct cpufreq_policy *policy,struct xen_set_cppc_para *set_cppc);int acpi_register_driver (void ); +#endif /* __XEN_CPUFREQ_PM_H__ */
Nit: This adding of a blank line should be part of the earlier patch.
Jan
Re: [XEN PATCH v2 2/2] x86/cpufreq: separate powernow/hwp/acpi cpufreq code
03.07.24 18:14, Jan Beulich:
Quoted 12 lines · Sergiy Kibrik
xen/drivers/acpi/pmstat.c static int get_cpufreq_para(struct xen_sysctl_pm_op *op) · line 258
Quoted 8 lines
xen/drivers/acpi/pmstat.c +1
-1@@ -255,7 +255,7 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)strlcpy (op->u.get_para.scaling_driver,"Unknown" ,CPUFREQ_NAME_LEN );if ( !strncmp (op->u.get_para.scaling_driver,XEN_HWP_DRIVER_NAME , -CPUFREQ_NAME_LEN ) ) +CPUFREQ_NAME_LEN ) &&IS_ENABLED (CONFIG_INTEL ) )Wrapping like this is confusing, not just because of the flawed indentation. Please can this be
Quoted 5 lines
if ( !strncmp(op->u.get_para.scaling_driver, XEN_HWP_DRIVER_NAME, CPUFREQ_NAME_LEN) && IS_ENABLED(CONFIG_INTEL) )? Perhaps the
IS_ENABLED()would also better be first (not just here).
sure, will fix that
Quoted 7 lines
Quoted 7 lines
xen/drivers/cpufreq/utility.c +0
-0@@ -379,7 +379,7 @@ int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag)if (!cpu_online (cpu) || !(policy =per_cpu (cpufreq_cpu_policy, cpu)))return 0 ;
Quoted 5 lines
xen/drivers/cpufreq/utility.c int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag) · line 384
Quoted 4 lines
xen/drivers/cpufreq/utility.c +1
-1- freq_avg =get_measured_perf (cpu, flag); + freq_avg =IS_ENABLED (CONFIG_INTEL ) ?get_measured_perf (cpu, flag) :0 ;if ( freq_avg >0 )return freq_avg;Why is this? APERF/MPERF aren't Intel-only MSRs.
yes, it seems to be a mistake..
-Sergiy