Patchwork [10/21] acpi_piix4: add infrastructure to send CPU hot-plug GPE to guest

login
register
mail settings
Submitter Juan Quintela
Date April 23, 2013, 3:25 p.m.
Message ID <87haixuv41.fsf@elfo.elfo>
Download mbox | patch
Permalink /patch/238941/
State New
Headers show

Comments

Juan Quintela - April 23, 2013, 3:25 p.m.
Igor Mammedov <imammedo@redhat.com> wrote:
> On Tue, 23 Apr 2013 13:38:10 +0200
> Juan Quintela <quintela@redhat.com> wrote:

Something like this (on top of your series) should work.

It implements an optional subsection and is sent depending if we have
used (or not) cpu hotplug.  I just compiled it,  haven't tested it,  so
it should be perfect (TM).

What do you think?

Thanks,  Juan.


From f887ce646f65a81ceff1920c7e6e2287b914b3ca Mon Sep 17 00:00:00 2001
From: Juan Quintela <quintela@trasno.org>
Date: Tue, 23 Apr 2013 17:23:29 +0200
Subject: [PATCH] vmstate subsection example


Signed-off-by: Juan Quintela <quintela@trasno.org>
---
 hw/acpi/piix4.c | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)
Igor Mammedov - April 23, 2013, 3:53 p.m.
On Tue, 23 Apr 2013 17:25:50 +0200
Juan Quintela <quintela@redhat.com> wrote:

> Igor Mammedov <imammedo@redhat.com> wrote:
> > On Tue, 23 Apr 2013 13:38:10 +0200
> > Juan Quintela <quintela@redhat.com> wrote:
> 
> Something like this (on top of your series) should work.
> 
> It implements an optional subsection and is sent depending if we have
> used (or not) cpu hotplug.  I just compiled it,  haven't tested it,  so
> it should be perfect (TM).
> 
> What do you think?
> 
> Thanks,  Juan.
> 

Just tested. it works.
I'm going to merge it in and remove unused Error* and repost patch.

> From f887ce646f65a81ceff1920c7e6e2287b914b3ca Mon Sep 17 00:00:00 2001
> From: Juan Quintela <quintela@trasno.org>
> Date: Tue, 23 Apr 2013 17:23:29 +0200
> Subject: [PATCH] vmstate subsection example
> 
> 
> Signed-off-by: Juan Quintela <quintela@trasno.org>
> ---
>  hw/acpi/piix4.c | 42 +++++++++++++++++++++++++++++-------------
>  1 file changed, 29 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index b845123..14dba76 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -60,6 +60,7 @@ struct pci_status {
>  };
> 
>  struct cpu_status {
> +    bool hotplug_happened;
>      uint8_t sts[PIIX4_PROC_LEN];
>  };
> 
> @@ -269,17 +270,23 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)
>      return ret;
>  }
> 
> -#define VMSTATE_CPU_STATUS_ARRAY(_field, _state)                             \
> - {                                                                           \
> -     .name       = (stringify(_field)),                                      \
> -     .version_id = 0,                                                        \
> -     .num        = PIIX4_PROC_LEN,                                           \
> -     .info       = &vmstate_info_uint8,                                      \
> -     .size       = sizeof(uint8_t),                                          \
> -     .flags      = VMS_ARRAY,                                                \
> -     .offset     = vmstate_offset_array(_state, _field, uint8_t,             \
> -                                        PIIX4_PROC_LEN),                     \
> - }
> +static bool vmstate_piix4_hotplug_needed(void *opaque)
> +{
> +    PIIX4PMState *s = opaque;
> +
> +    return s->gpe_cpu.hotplug_happened;
> +}
> +
> +static const VMStateDescription vmstate_piix4_hotplug_state = {
> +    .name ="piix4_pm/hotplug",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .minimum_version_id_old = 1,
> +    .fields = (VMStateField []) {
> +        VMSTATE_UINT8_ARRAY(gpe_cpu.sts, PIIX4PMState, PIIX4_PROC_LEN),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> 
>  /* qemu-kvm 1.2 uses version 3 but advertised as 2
>   * To support incoming qemu-kvm 1.2 migration, change version_id
> @@ -289,7 +296,7 @@ static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)
>   */
>  static const VMStateDescription vmstate_acpi = {
>      .name = "piix4_pm",
> -    .version_id = 4,
> +    .version_id = 3,
>      .minimum_version_id = 3,
>      .minimum_version_id_old = 1,
>      .load_state_old = acpi_load_old,
> @@ -305,8 +312,15 @@ static const VMStateDescription vmstate_acpi = {
>          VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),
>          VMSTATE_STRUCT(pci0_status, PIIX4PMState, 2, vmstate_pci_status,
>                         struct pci_status),
> -        VMSTATE_CPU_STATUS_ARRAY(gpe_cpu.sts, PIIX4PMState),
>          VMSTATE_END_OF_LIST()
> +    },
> +    .subsections = (VMStateSubsection[]) {
> +        {
> +            .vmsd = &vmstate_piix4_hotplug_state,
> +            .needed = vmstate_piix4_hotplug_needed,
> +        }, {
> +            /* empty */
> +        }
>      }
>  };
> 
> @@ -664,6 +678,7 @@ static void piix4_cpu_added_req(Notifier *n, void *opaque)
>  {
>      PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);
> 
> +    s->gpe_cpu.hotplug_happened = true;
>      piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
>  }
> 
> @@ -706,6 +721,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
>      pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);
> 
>      piix4_init_cpu_status(qdev_get_machine(), &s->gpe_cpu);
> +    s->gpe_cpu.hotplug_happened = false;
>      memory_region_init_io(&s->io_cpu, &cpu_hotplug_ops, s, "apci-cpu-hotplug",
>                            PIIX4_PROC_LEN);
>      memory_region_add_subregion(parent, PIIX4_PROC_BASE, &s->io_cpu);

Patch

diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index b845123..14dba76 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -60,6 +60,7 @@  struct pci_status {
 };

 struct cpu_status {
+    bool hotplug_happened;
     uint8_t sts[PIIX4_PROC_LEN];
 };

@@ -269,17 +270,23 @@  static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)
     return ret;
 }

-#define VMSTATE_CPU_STATUS_ARRAY(_field, _state)                             \
- {                                                                           \
-     .name       = (stringify(_field)),                                      \
-     .version_id = 0,                                                        \
-     .num        = PIIX4_PROC_LEN,                                           \
-     .info       = &vmstate_info_uint8,                                      \
-     .size       = sizeof(uint8_t),                                          \
-     .flags      = VMS_ARRAY,                                                \
-     .offset     = vmstate_offset_array(_state, _field, uint8_t,             \
-                                        PIIX4_PROC_LEN),                     \
- }
+static bool vmstate_piix4_hotplug_needed(void *opaque)
+{
+    PIIX4PMState *s = opaque;
+
+    return s->gpe_cpu.hotplug_happened;
+}
+
+static const VMStateDescription vmstate_piix4_hotplug_state = {
+    .name ="piix4_pm/hotplug",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField []) {
+        VMSTATE_UINT8_ARRAY(gpe_cpu.sts, PIIX4PMState, PIIX4_PROC_LEN),
+        VMSTATE_END_OF_LIST()
+    }
+};

 /* qemu-kvm 1.2 uses version 3 but advertised as 2
  * To support incoming qemu-kvm 1.2 migration, change version_id
@@ -289,7 +296,7 @@  static int acpi_load_old(QEMUFile *f, void *opaque, int version_id)
  */
 static const VMStateDescription vmstate_acpi = {
     .name = "piix4_pm",
-    .version_id = 4,
+    .version_id = 3,
     .minimum_version_id = 3,
     .minimum_version_id_old = 1,
     .load_state_old = acpi_load_old,
@@ -305,8 +312,15 @@  static const VMStateDescription vmstate_acpi = {
         VMSTATE_STRUCT(ar.gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),
         VMSTATE_STRUCT(pci0_status, PIIX4PMState, 2, vmstate_pci_status,
                        struct pci_status),
-        VMSTATE_CPU_STATUS_ARRAY(gpe_cpu.sts, PIIX4PMState),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (VMStateSubsection[]) {
+        {
+            .vmsd = &vmstate_piix4_hotplug_state,
+            .needed = vmstate_piix4_hotplug_needed,
+        }, {
+            /* empty */
+        }
     }
 };

@@ -664,6 +678,7 @@  static void piix4_cpu_added_req(Notifier *n, void *opaque)
 {
     PIIX4PMState *s = container_of(n, PIIX4PMState, cpu_added_notifier);

+    s->gpe_cpu.hotplug_happened = true;
     piix4_cpu_hotplug_req(s, CPU(opaque), PLUG);
 }

@@ -706,6 +721,7 @@  static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
     pci_bus_hotplug(bus, piix4_device_hotplug, &s->dev.qdev);

     piix4_init_cpu_status(qdev_get_machine(), &s->gpe_cpu);
+    s->gpe_cpu.hotplug_happened = false;
     memory_region_init_io(&s->io_cpu, &cpu_hotplug_ops, s, "apci-cpu-hotplug",
                           PIIX4_PROC_LEN);
     memory_region_add_subregion(parent, PIIX4_PROC_BASE, &s->io_cpu);