Skip to contentSkip to conversation

Series to implement suspend for ppc/spapr

PATCH In review Nicholas Piggin 3 participants 7 messages Jul 22, 2019 – Jul 23, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover Series to implement suspend for ppc/spapr

Hi, this series is rebased on top of the qmp event fix, and takes Paolo's suggestion to implement ->wakeup for i386 before adding ppc, which makes it much nicer.

If the first two patches can be agreed on initially and merged, I can take the third patch through the ppc list after that.

Thanks,
Nick

Nicholas Piggin (3):
machine: Add wakeup method to MachineClass
i386: use machine class ->wakeup method
spapr: Implement ibm,suspend-me

 hw/i386/pc.c           |  8 ++++++++
 hw/ppc/spapr.c         |  7 +++++++
 hw/ppc/spapr_rtas.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 vl.c                   | 16 +++++++++++++++-
 6 files changed, 65 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v2 1/3 machine: Add wakeup method to MachineClass

Waking from suspend is not logically a machine reset on all machines, particularly in the paravirtualized case rather than hardware emulated. The ppc spapr machine for example just invokes hypervisor to suspend, and expects that call to return with the machine in the same state (modulo some possible migration and reconfiguration details).

Implement a machine ->wakeup method and use that if it exists.

---
 include/hw/boards.h |  1 +
 vl.c                | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
include/hw/boards.h +1 -0
index a71d1a53a5..915ac3352b 100644
@@ -180,6 +180,7 @@ struct MachineClass {
 
     void (*init)(MachineState *state);
     void (*reset)(MachineState *state);
+    void (*wakeup)(MachineState *state);
     void (*hot_add_cpu)(MachineState *state, const int64_t id, Error **errp);
     int (*kvm_type)(MachineState *machine, const char *arg);
     void (*smp_parse)(MachineState *ms, QemuOpts *opts);
vl.c +17 -1
index cefe5a3968..45ea034410 100644
@@ -1556,6 +1556,22 @@ void qemu_system_reset(ShutdownCause reason)
     cpu_synchronize_all_post_reset();
 }
 
+/*
+ * Wake the VM after suspend.
+ */
+static void qemu_system_wakeup(void)
+{
+    MachineClass *mc;
+
+    mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
+
+    if (mc && mc->wakeup) {
+        mc->wakeup(current_machine);
+    } else {
+        qemu_system_reset(SHUTDOWN_CAUSE_NONE);
+    }
+}
+
 void qemu_system_guest_panicked(GuestPanicInformation *info)
 {
     qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed");
@@ -1764,7 +1780,7 @@ static bool main_loop_should_exit(void)
     }
     if (qemu_wakeup_requested()) {
         pause_all_vcpus();
-        qemu_system_reset(SHUTDOWN_CAUSE_NONE);
+        qemu_system_wakeup();
         notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
         wakeup_reason = QEMU_WAKEUP_REASON_NONE;
         resume_all_vcpus();
Signature · 1 line
2.20.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/3] machine: Add wakeup method to MachineClass

Quoted 10 lines · Nicholas Piggin

Waking from suspend is not logically a machine reset on all machines, particularly in the paravirtualized case rather than hardware emulated. The ppc spapr machine for example just invokes hypervisor to suspend, and expects that call to return with the machine in the same state (modulo some possible migration and reconfiguration details).

Implement a machine ->wakeup method and use that if it exists.

Quoted 53 lines
---
 include/hw/boards.h |  1 +
 vl.c                | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
include/hw/boards.h +1 -0
index a71d1a53a5..915ac3352b 100644
@@ -180,6 +180,7 @@ struct MachineClass {
 
     void (*init)(MachineState *state);
     void (*reset)(MachineState *state);
+    void (*wakeup)(MachineState *state);
     void (*hot_add_cpu)(MachineState *state, const int64_t id, Error **errp);
     int (*kvm_type)(MachineState *machine, const char *arg);
     void (*smp_parse)(MachineState *ms, QemuOpts *opts);
vl.c +17 -1
index cefe5a3968..45ea034410 100644
@@ -1556,6 +1556,22 @@ void qemu_system_reset(ShutdownCause reason)
     cpu_synchronize_all_post_reset();
 }
 
+/*
+ * Wake the VM after suspend.
+ */
+static void qemu_system_wakeup(void)
+{
+    MachineClass *mc;
+
+    mc = current_machine ? MACHINE_GET_CLASS(current_machine) : NULL;
+
+    if (mc && mc->wakeup) {
+        mc->wakeup(current_machine);
+    } else {
+        qemu_system_reset(SHUTDOWN_CAUSE_NONE);
+    }
+}
+
 void qemu_system_guest_panicked(GuestPanicInformation *info)
 {
     qemu_log_mask(LOG_GUEST_ERROR, "Guest crashed");
@@ -1764,7 +1780,7 @@ static bool main_loop_should_exit(void)
     }
     if (qemu_wakeup_requested()) {
         pause_all_vcpus();
-        qemu_system_reset(SHUTDOWN_CAUSE_NONE);
+        qemu_system_wakeup();
         notifier_list_notify(&wakeup_notifiers, &wakeup_reason);
         wakeup_reason = QEMU_WAKEUP_REASON_NONE;
         resume_all_vcpus();
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw
In reply to Nicholas Piggin
Quoted 6 lines · Nicholas Piggin

Hi, this series is rebased on top of the qmp event fix, and takes Paolo's suggestion to implement ->wakeup for i386 before adding ppc, which makes it much nicer.

If the first two patches can be agreed on initially and merged, I can take the third patch through the ppc list after that.

LGTM. Now, what tree(s) do we merge this through?

Quoted 17 lines

Thanks,
Nick

Nicholas Piggin (3):
machine: Add wakeup method to MachineClass
i386: use machine class ->wakeup method
spapr: Implement ibm,suspend-me

 hw/i386/pc.c           |  8 ++++++++
 hw/ppc/spapr.c         |  7 +++++++
 hw/ppc/spapr_rtas.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 vl.c                   | 16 +++++++++++++++-
 6 files changed, 65 insertions(+), 2 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
Acked-by
#4 lore raw
Quoted 9 lines · David Gibson
Quoted 6 lines · Nicholas Piggin

Hi, this series is rebased on top of the qmp event fix, and takes Paolo's suggestion to implement ->wakeup for i386 before adding ppc, which makes it much nicer.

If the first two patches can be agreed on initially and merged, I can take the third patch through the ppc list after that.

LGTM. Now, what tree(s) do we merge this through?

I have just spotted a volunteer!

Paolo

Quoted 18 lines
Quoted 17 lines

Thanks,
Nick

Nicholas Piggin (3):
machine: Add wakeup method to MachineClass
i386: use machine class ->wakeup method
spapr: Implement ibm,suspend-me

 hw/i386/pc.c           |  8 ++++++++
 hw/ppc/spapr.c         |  7 +++++++
 hw/ppc/spapr_rtas.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 vl.c                   | 16 +++++++++++++++-
 6 files changed, 65 insertions(+), 2 deletions(-)
#5 lore raw
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · David Gibson
Quoted 4 lines · Nicholas Piggin

Hi, this series is rebased on top of the qmp event fix, and takes Paolo's suggestion to implement ->wakeup for i386 before adding ppc, which makes it much nicer.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

If the first two patches can be agreed on initially and merged, I can take the third patch through the ppc list after that.

LGTM. Now, what tree(s) do we merge this through?

I have just spotted a volunteer!

Well, merging an i386 patch through the ppc tree is kinda weird, but yeah, I can do that.

Quoted 24 lines

Paolo

Quoted 18 lines
Quoted 17 lines

Thanks,
Nick

Nicholas Piggin (3):
machine: Add wakeup method to MachineClass
i386: use machine class ->wakeup method
spapr: Implement ibm,suspend-me

 hw/i386/pc.c           |  8 ++++++++
 hw/ppc/spapr.c         |  7 +++++++
 hw/ppc/spapr_rtas.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 vl.c                   | 16 +++++++++++++++-
 6 files changed, 65 insertions(+), 2 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw
In reply to Paolo Bonzini
Quoted 6 lines · Paolo Bonzini
Quoted 5 lines · David Gibson
Quoted 4 lines · Nicholas Piggin

Hi, this series is rebased on top of the qmp event fix, and takes Paolo's suggestion to implement ->wakeup for i386 before adding ppc, which makes it much nicer.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If the first two patches can be agreed on initially and merged, I can take the third patch through the ppc list after that.

LGTM. Now, what tree(s) do we merge this through?

I have just spotted a volunteer!

I've put this in the ppc-for-4.2 tree.

Quoted 22 lines

Paolo

Quoted 18 lines
Quoted 17 lines

Thanks,
Nick

Nicholas Piggin (3):
machine: Add wakeup method to MachineClass
i386: use machine class ->wakeup method
spapr: Implement ibm,suspend-me

 hw/i386/pc.c           |  8 ++++++++
 hw/ppc/spapr.c         |  7 +++++++
 hw/ppc/spapr_rtas.c    | 32 ++++++++++++++++++++++++++++++++
 include/hw/boards.h    |  1 +
 include/hw/ppc/spapr.h |  3 ++-
 vl.c                   | 16 +++++++++++++++-
 6 files changed, 65 insertions(+), 2 deletions(-)
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson