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

[xen staging] x86/cpufreq: Clean up powernow registration



commit eed4f94ddbf15e70da93a075a878c304f0a079cb
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Fri Nov 12 15:13:36 2021 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Mon Nov 29 13:53:05 2021 +0000

    x86/cpufreq: Clean up powernow registration
    
    powernow_register_driver() is currently written with a K&R type definition;
    I'm surprised that compilers don't object to a mismatch with its 
declaration,
    which is written in an ANSI-C compatible way.
    
    Furthermore, its sole caller is cpufreq_driver_init() which is a pre-smp
    initcall.  There are no other online CPUs, and even if there were, checking
    the BSP's CPUID data $N times is pointless.  Simplify registration to only
    look at the BSP.
    
    While at it, drop obviously unused includes.  Also rewrite the expression in
    cpufreq_driver_init() for clarity.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/arch/x86/acpi/cpufreq/cpufreq.c  | 21 ++++++++++++++-------
 xen/arch/x86/acpi/cpufreq/powernow.c | 27 ++++-----------------------
 2 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c 
b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index f1f3c6923f..df9747e0b6 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -640,13 +640,20 @@ static int __init cpufreq_driver_init(void)
 {
     int ret = 0;
 
-    if ((cpufreq_controller == FREQCTL_xen) &&
-        (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL))
-        ret = cpufreq_register_driver(&acpi_cpufreq_driver);
-    else if ((cpufreq_controller == FREQCTL_xen) &&
-        (boot_cpu_data.x86_vendor &
-         (X86_VENDOR_AMD | X86_VENDOR_HYGON)))
-        ret = powernow_register_driver();
+    if ( cpufreq_controller == FREQCTL_xen )
+    {
+        switch ( boot_cpu_data.x86_vendor )
+        {
+        case X86_VENDOR_INTEL:
+            ret = cpufreq_register_driver(&acpi_cpufreq_driver);
+            break;
+
+        case X86_VENDOR_AMD:
+        case X86_VENDOR_HYGON:
+            ret = powernow_register_driver();
+            break;
+        }
+    }
 
     return ret;
 }
diff --git a/xen/arch/x86/acpi/cpufreq/powernow.c 
b/xen/arch/x86/acpi/cpufreq/powernow.c
index f620bebc7e..dfd96b9216 100644
--- a/xen/arch/x86/acpi/cpufreq/powernow.c
+++ b/xen/arch/x86/acpi/cpufreq/powernow.c
@@ -24,13 +24,9 @@
 #include <xen/types.h>
 #include <xen/errno.h>
 #include <xen/init.h>
-#include <xen/delay.h>
 #include <xen/cpumask.h>
-#include <xen/timer.h>
 #include <xen/xmalloc.h>
-#include <asm/bug.h>
 #include <asm/msr.h>
-#include <asm/io.h>
 #include <asm/processor.h>
 #include <asm/cpufeature.h>
 #include <acpi/acpi.h>
@@ -353,25 +349,10 @@ static const struct cpufreq_driver __initconstrel 
powernow_cpufreq_driver = {
     .update = powernow_cpufreq_update
 };
 
-unsigned int __init powernow_register_driver()
+unsigned int __init powernow_register_driver(void)
 {
-    unsigned int i, ret = 0;
-
-    for_each_online_cpu(i) {
-        struct cpuinfo_x86 *c = &cpu_data[i];
-        if (!(c->x86_vendor & (X86_VENDOR_AMD | X86_VENDOR_HYGON)))
-            ret = -ENODEV;
-        else
-        {
-            u32 eax, ebx, ecx, edx;
-            cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx);
-            if ((edx & USE_HW_PSTATE) != USE_HW_PSTATE)
-                ret = -ENODEV;
-        }
-        if (ret)
-            return ret;
-    }
+    if ( !(cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES) & USE_HW_PSTATE) )
+        return -ENODEV;
 
-    ret = cpufreq_register_driver(&powernow_cpufreq_driver);
-    return ret;
+    return cpufreq_register_driver(&powernow_cpufreq_driver);
 }
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

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