Skip to contentSkip to conversation

x86: separate powernow/hwp/acpi cpufreq code

PATCH Superseded Sergiy Kibrik 2 participants 8 messages Jul 1, 2024 – Jul 9, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index db83aa6b14..44d4c0b497 100644
@@ -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
index 443427153b..1a8ba3756c 100644
@@ -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
#5 lore raw

PATCH v2 2/2 x86/cpufreq: separate powernow/hwp/acpi cpufreq code

In reply to Sergiy Kibrik

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

CC Jason Andryuk <[email protected]>
CC Jan Beulich <[email protected]>

---
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
index 44d4c0b497..e7dbe434a8 100644
@@ -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
index c1a842e959..59ea1f41d4 100644
@@ -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
index 998d2e3c65..ff6b930794 100644
@@ -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
index 8659ad3aee..e61482e5b0 100644
@@ -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
index e690a484f1..aab0b78454 100644
@@ -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
index 1a8ba3756c..b2e7a592df 100644
@@ -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
#2 lore raw

Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file

In reply to Sergiy Kibrik
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

#6 lore raw

Re: [XEN PATCH v2 2/2] x86/cpufreq: separate powernow/hwp/acpi cpufreq code

In reply to Sergiy Kibrik

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

#3 lore raw

Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file

In reply to Jan Beulich

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 about acpi_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.c wasn'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

#7 lore raw

Re: [XEN PATCH v2 2/2] x86/cpufreq: separate powernow/hwp/acpi cpufreq code

In reply to Jan Beulich

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

#4 lore raw

Re: [XEN PATCH v2 1/2] x86/cpufreq: move ACPI cpufreq driver into separate file

In reply to Sergiy Kibrik
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.c wasn'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