diff mbox

[V6,8/8] acpi/cpu-hotplug: introduce helper function to keep bit setting in one place

Message ID 1413948272-7765-9-git-send-email-guz.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

Gu Zheng Oct. 22, 2014, 3:24 a.m. UTC
Introduce helper function acpi_set_cpu_present_bit() to simplify acpi_cpu_plug_cb
and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.

Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
---
v6:
 -using error_abort instead of local_err, so that we can gain the error report
  before abort (suggested by Igor).
v5:
 -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.

 hw/acpi/cpu_hotplug.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

Comments

Igor Mammedov Oct. 22, 2014, 9 a.m. UTC | #1
On Wed, 22 Oct 2014 11:24:32 +0800
Gu Zheng <guz.fnst@cn.fujitsu.com> wrote:

> Introduce helper function acpi_set_cpu_present_bit() to simplify acpi_cpu_plug_cb
> and acpi_cpu_hotplug_init, so that we can keep bit setting in one place.
> 
> Signed-off-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

> ---
> v6:
>  -using error_abort instead of local_err, so that we can gain the error report
>   before abort (suggested by Igor).
> v5:
>  -rename acpi_set_local_sts to acpi_set_cpu_present_bit for better readability.
> 
>  hw/acpi/cpu_hotplug.c |   22 +++++++++++++---------
>  1 files changed, 13 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index ae48b63..b8ebfad 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -36,10 +36,9 @@ static const MemoryRegionOps AcpiCpuHotplug_ops = {
>      },
>  };
>  
> -void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
> -                      AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
> +static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
> +                                     Error **errp)
>  {
> -    CPUState *cpu = CPU(dev);
>      CPUClass *k = CPU_GET_CLASS(cpu);
>      int64_t cpu_id;
>  
> @@ -49,9 +48,18 @@ void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
>          return;
>      }
>  
> -    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
>      g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
> +}
> +
> +void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
> +                      AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
> +{
> +    acpi_set_cpu_present_bit(g, CPU(dev), errp);
> +    if (*errp != NULL) {
> +        return;
> +    }
>  
> +    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
>      acpi_update_sci(ar, irq);
>  }
>  
> @@ -61,11 +69,7 @@ void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
>      CPUState *cpu;
>  
>      CPU_FOREACH(cpu) {
> -        CPUClass *cc = CPU_GET_CLASS(cpu);
> -        int64_t id = cc->get_arch_id(cpu);
> -
> -        g_assert((id / 8) < ACPI_GPE_PROC_LEN);
> -        gpe_cpu->sts[id / 8] |= (1 << (id % 8));
> +        acpi_set_cpu_present_bit(gpe_cpu, cpu, &error_abort);
>      }
>      memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
>                            gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);
diff mbox

Patch

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index ae48b63..b8ebfad 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -36,10 +36,9 @@  static const MemoryRegionOps AcpiCpuHotplug_ops = {
     },
 };
 
-void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
-                      AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+static void acpi_set_cpu_present_bit(AcpiCpuHotplug *g, CPUState *cpu,
+                                     Error **errp)
 {
-    CPUState *cpu = CPU(dev);
     CPUClass *k = CPU_GET_CLASS(cpu);
     int64_t cpu_id;
 
@@ -49,9 +48,18 @@  void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
         return;
     }
 
-    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
     g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
+}
+
+void acpi_cpu_plug_cb(ACPIREGS *ar, qemu_irq irq,
+                      AcpiCpuHotplug *g, DeviceState *dev, Error **errp)
+{
+    acpi_set_cpu_present_bit(g, CPU(dev), errp);
+    if (*errp != NULL) {
+        return;
+    }
 
+    ar->gpe.sts[0] |= ACPI_CPU_HOTPLUG_STATUS;
     acpi_update_sci(ar, irq);
 }
 
@@ -61,11 +69,7 @@  void acpi_cpu_hotplug_init(MemoryRegion *parent, Object *owner,
     CPUState *cpu;
 
     CPU_FOREACH(cpu) {
-        CPUClass *cc = CPU_GET_CLASS(cpu);
-        int64_t id = cc->get_arch_id(cpu);
-
-        g_assert((id / 8) < ACPI_GPE_PROC_LEN);
-        gpe_cpu->sts[id / 8] |= (1 << (id % 8));
+        acpi_set_cpu_present_bit(gpe_cpu, cpu, &error_abort);
     }
     memory_region_init_io(&gpe_cpu->io, owner, &AcpiCpuHotplug_ops,
                           gpe_cpu, "acpi-cpu-hotplug", ACPI_GPE_PROC_LEN);