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

[Xen-devel] [PATCH] linux/acpi: adjust extcntl's changes to (mostly) common code, mostly for readability



While I realize that it may have been upon my request that all these
#ifdef-s were introduced, I think this went too far here: With the
abstraction in include/acpi/processor.h in place, the code still
guarantees even without all these #ifdef-s that in native kernels built
from the same source the logic will not change.

The one thing that appears a little weak still is the NR_ACPI_CPUS
construct - nothing guarantees that the ACPI IDs are constrained to 8
bits, and hence using an array here doesn't seem either safe or
scalable looking forward. To make the issue explict, the patch adds a
respective BUG_ON().

Also remove a stray export.

As usual, written and tested on 2.6.26 and made apply to the 2.6.18
tree without further testing.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: head-2008-07-21/arch/i386/kernel/acpi/processor_extcntl_xen.c
===================================================================
--- head-2008-07-21.orig/arch/i386/kernel/acpi/processor_extcntl_xen.c  
2008-07-22 15:58:45.000000000 +0200
+++ head-2008-07-21/arch/i386/kernel/acpi/processor_extcntl_xen.c       
2008-07-22 17:23:07.000000000 +0200
@@ -40,7 +40,6 @@ static int __init set_xen_processor_pmbi
        return 1;
 }
 __setup("xen_processor_pmbits=", set_xen_processor_pmbits);
-EXPORT_SYMBOL(xen_processor_pmbits);
 
 static int xen_cx_notifier(struct acpi_processor *pr, int action)
 {
Index: head-2008-07-21/drivers/acpi/processor_core.c
===================================================================
--- head-2008-07-21.orig/drivers/acpi/processor_core.c  2008-07-22 
17:19:17.000000000 +0200
+++ head-2008-07-21/drivers/acpi/processor_core.c       2008-07-22 
17:16:50.000000000 +0200
@@ -474,14 +474,9 @@ static int acpi_processor_get_info(struc
         *  they are physically not present.
         */
        if (cpu_index == -1) {
-#ifdef CONFIG_XEN
                if (ACPI_FAILURE
                    (acpi_processor_hotadd_init(pr->handle, &pr->id)) &&
                    !processor_cntl_external()) {
-#else
-               if (ACPI_FAILURE
-                   (acpi_processor_hotadd_init(pr->handle, &pr->id))) {
-#endif /* CONFIG_XEN */
                        printk(KERN_ERR PREFIX
                                    "Getting cpuindex for acpiid 0x%x\n",
                                    pr->acpi_id);
@@ -523,11 +518,7 @@ static int acpi_processor_get_info(struc
        return 0;
 }
 
-#ifdef CONFIG_XEN
 static void *processor_device_array[NR_ACPI_CPUS];
-#else
-static void *processor_device_array[NR_CPUS];
-#endif /* CONFIG_XEN */
 
 static int acpi_processor_start(struct acpi_device *device)
 {
@@ -539,22 +530,14 @@ static int __cpuinit acpi_processor_star
        pr = acpi_driver_data(device);
 
        result = acpi_processor_get_info(pr);
-#ifdef CONFIG_XEN
        if (result || 
            ((pr->id == -1) && !processor_cntl_external())) {
-#else
-       if (result) {
-#endif /* CONFIG_XEN */
                /* Processor is physically not present */
                return 0;
        }
 
-#ifdef CONFIG_XEN
        BUG_ON(!processor_cntl_external() &&
               ((pr->id >= NR_CPUS) || (pr->id < 0)));
-#else
-       BUG_ON((pr->id >= NR_CPUS) || (pr->id < 0));
-#endif /* CONFIG_XEN */
 
        /*
         * Buggy BIOS check
@@ -562,6 +545,7 @@ static int __cpuinit acpi_processor_star
         * Don't trust it blindly
         */
 #ifdef CONFIG_XEN
+       BUG_ON(pr->acpi_id >= NR_ACPI_CPUS);
        if (processor_device_array[pr->acpi_id] != NULL &&
            processor_device_array[pr->acpi_id] != (void *)device) {
 #else
@@ -595,9 +579,9 @@ static int __cpuinit acpi_processor_star
 
        acpi_processor_power_init(pr, device);
 
-#ifdef CONFIG_PROCESSOR_EXTERNAL_CONTROL
-       processor_extcntl_init(pr);
-#endif
+       result = processor_extcntl_init(pr);
+       if (result)
+               goto end;
 
        if (pr->flags.throttling) {
                printk(KERN_INFO PREFIX "%s [%s] (supports",
@@ -751,11 +735,9 @@ int acpi_processor_device_add(acpi_handl
        if (!pr)
                return -ENODEV;
 
-#ifdef CONFIG_XEN
        if (processor_cntl_external())
                processor_notify_external(pr,
                        PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD);
-#endif /* CONFIG_XEN */
 
        if ((pr->id >= 0) && (pr->id < NR_CPUS)) {
                kobject_uevent(&(*device)->kobj, KOBJ_ONLINE);
@@ -795,11 +777,9 @@ static void __ref acpi_processor_hotplug
                        break;
                }
 
-#ifdef CONFIG_XEN
                if (processor_cntl_external())
                        processor_notify_external(pr,
                                        PROCESSOR_HOTPLUG, HOTPLUG_TYPE_ADD);
-#endif /* CONFIG_XEN */
 
                if (pr->id >= 0 && (pr->id < NR_CPUS)) {
                        kobject_uevent(&device->kobj, KOBJ_OFFLINE);
@@ -838,11 +818,9 @@ static void __ref acpi_processor_hotplug
 #endif /* CONFIG_XEN */
                        kobject_uevent(&device->kobj, KOBJ_OFFLINE);
 
-#ifdef CONFIG_XEN
                if (processor_cntl_external())
                        processor_notify_external(pr, PROCESSOR_HOTPLUG,
                                                        HOTPLUG_TYPE_REMOVE);
-#endif /* CONFIG_XEN */
 
                break;
        default:
Index: head-2008-07-21/drivers/acpi/processor_idle.c
===================================================================
--- head-2008-07-21.orig/drivers/acpi/processor_idle.c  2008-05-19 
11:00:05.000000000 +0200
+++ head-2008-07-21/drivers/acpi/processor_idle.c       2008-07-22 
17:29:00.000000000 +0200
@@ -714,17 +714,12 @@ static int acpi_processor_get_power_info
                    (reg->space_id != ACPI_ADR_SPACE_FIXED_HARDWARE))
                        continue;
 
-#ifdef CONFIG_XEN
                if (!processor_pm_external())
                        cx.address = (reg->space_id ==
                                      ACPI_ADR_SPACE_FIXED_HARDWARE) ?
                                      0 : reg->address;
                else
                        cx.address = reg->address;
-#else
-               cx.address = (reg->space_id == ACPI_ADR_SPACE_FIXED_HARDWARE) ?
-                   0 : reg->address;
-#endif /* CONFIG_XEN */
 
                /* There should be an easy way to extract an integer... */
                obj = (union acpi_object *)&(element->package.elements[1]);
@@ -733,17 +728,11 @@ static int acpi_processor_get_power_info
 
                cx.type = obj->integer.value;
 
-#ifdef CONFIG_XEN
                /* Following check doesn't apply to external control case */
-               if (!processor_pm_external())
-                       if ((cx.type != ACPI_STATE_C1) &&
-                           (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO))
-                               continue;
-#else
-               if ((cx.type != ACPI_STATE_C1) &&
+               if (!processor_pm_external() &&
+                   (cx.type != ACPI_STATE_C1) &&
                    (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO))
                        continue;
-#endif /* CONFIG_XEN */
 
                if ((cx.type < ACPI_STATE_C2) || (cx.type > ACPI_STATE_C3))
                        continue;
@@ -1008,24 +997,16 @@ int acpi_processor_cst_has_changed(struc
                return -ENODEV;
 
        /* Fall back to the default idle loop */
-#ifdef CONFIG_XEN
        if (!processor_pm_external())
                pm_idle = pm_idle_save;
-#else
-       pm_idle = pm_idle_save;
-#endif /* CONFIG_XEN */
        synchronize_sched();    /* Relies on interrupts forcing exit from idle. 
*/
 
        pr->flags.power = 0;
        result = acpi_processor_get_power_info(pr);
-#ifdef CONFIG_XEN
        if (processor_pm_external())
                processor_notify_external(pr,
                        PROCESSOR_PM_CHANGE, PM_TYPE_IDLE);
        else if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
-#else
-       if ((pr->flags.power == 1) && (pr->flags.power_setup_done))
-#endif /* CONFIG_XEN */
                pm_idle = acpi_processor_idle;
 
        return result;
@@ -1157,11 +1138,7 @@ int __cpuinit acpi_processor_power_init(
                                       pr->power.states[i].type);
                printk(")\n");
 
-#ifdef CONFIG_XEN
                if (!processor_pm_external() && (pr->id == 0)) {
-#else
-               if (pr->id == 0) {
-#endif /* CONFIG_XEN */
                        pm_idle_save = pm_idle;
                        pm_idle = acpi_processor_idle;
                }
@@ -1180,11 +1157,9 @@ int __cpuinit acpi_processor_power_init(
 
        pr->flags.power_setup_done = 1;
 
-#ifdef CONFIG_XEN
        if (processor_pm_external())
                processor_notify_external(pr,
                        PROCESSOR_PM_INIT, PM_TYPE_IDLE);
-#endif /* CONFIG_XEN */
        return 0;
 }
 
Index: head-2008-07-21/drivers/acpi/processor_perflib.c
===================================================================
--- head-2008-07-21.orig/drivers/acpi/processor_perflib.c       2008-07-22 
17:19:17.000000000 +0200
+++ head-2008-07-21/drivers/acpi/processor_perflib.c    2008-07-22 
17:09:48.000000000 +0200
@@ -136,11 +136,9 @@ int acpi_processor_ppc_has_changed(struc
        int ret = acpi_processor_get_platform_limit(pr);
        if (ret < 0)
                return (ret);
-#ifdef CONFIG_XEN
        else if (processor_pmperf_external())
                return processor_notify_external(pr,
                                PROCESSOR_PM_CHANGE, PM_TYPE_PERF);
-#endif /* CONFIG_XEN */
        else
                return cpufreq_update_policy(pr->id);
 }
@@ -305,10 +303,9 @@ static int acpi_processor_get_performanc
 }
 
 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
-static int acpi_processor_get_performance_info(struct acpi_processor *pr)
-#else
-int acpi_processor_get_performance_info(struct acpi_processor *pr)
+static
 #endif
+int acpi_processor_get_performance_info(struct acpi_processor *pr)
 {
        int result = 0;
        acpi_status status = AE_OK;
@@ -548,10 +545,9 @@ static void acpi_cpufreq_remove_file(str
 #endif                         /* CONFIG_X86_ACPI_CPUFREQ_PROC_INTF */
 
 #ifndef CONFIG_PROCESSOR_EXTERNAL_CONTROL
-static int acpi_processor_get_psd(struct acpi_processor        *pr)
-#else
-int acpi_processor_get_psd(struct acpi_processor *pr)
+static
 #endif
+int acpi_processor_get_psd(struct acpi_processor *pr)
 {
        int result = 0;
        acpi_status status = AE_OK;
Index: head-2008-07-21/include/acpi/processor.h
===================================================================
--- head-2008-07-21.orig/include/acpi/processor.h       2008-07-22 
16:01:43.000000000 +0200
+++ head-2008-07-21/include/acpi/processor.h    2008-07-22 17:25:48.000000000 
+0200
@@ -22,7 +22,9 @@
 #define ACPI_PSD_REV0_ENTRIES          5
 
 #ifdef CONFIG_XEN
-#define NR_ACPI_CPUS                   256
+#define NR_ACPI_CPUS                   (NR_CPUS < 256 ? 256 : NR_CPUS)
+#else
+#define NR_ACPI_CPUS                   NR_CPUS
 #endif /* CONFIG_XEN */
 
 /*
@@ -296,7 +298,6 @@ static inline void acpi_thermal_cpufreq_
 }
 #endif
 
-#ifdef CONFIG_XEN
 /* 
  * Following are interfaces geared to external processor PM control
  * logic like a VMM
@@ -306,7 +307,7 @@ static inline void acpi_thermal_cpufreq_
 #define PROCESSOR_PM_CHANGE    2
 #define PROCESSOR_HOTPLUG      3
 
-/* Objects for the PM envents */
+/* Objects for the PM events */
 #define PM_TYPE_IDLE           0
 #define PM_TYPE_PERF           1
 #define PM_TYPE_THR            2
@@ -363,13 +364,12 @@ static inline int processor_pmthr_extern
 static inline int processor_notify_external(struct acpi_processor *pr,
                        int event, int type)
 {
-       return -EINVAL;
+       return 0;
 }
 static inline int processor_extcntl_init(struct acpi_processor *pr)
 {
-       return -EINVAL;
+       return 0;
 }
 #endif /* CONFIG_PROCESSOR_EXTERNAL_CONTROL */
-#endif /* CONFIG_XEN */
 
 #endif



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

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