qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC PATCH 0/5] initial suspend support
@ 2012-01-11 15:08 Gerd Hoffmann
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure Gerd Hoffmann
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

This patch series makes suspend support in qemu alot more useful.  Right
now the guest can put itself into s3, but qemu will wakeup the guest
instantly.  With this patch series applied the guest will stay suspended
instead and there are a few events which can kick the guest out of
suspend state:  A monitor command, ps/2 input, serial input.  Not much
yet, but it's a start with the low hanging fruits ;)

Gerd Hoffmann (5):
  suspend: add infrastructure
  suspend: add wakeup monitor command
  suspend: switch acpi s3 to new infrastructure.
  suspend: make ps/2 devices wakeup the guest
  suspend: make serial ports wakeup the guest.

 hmp-commands.hx  |   14 ++++++++++++++
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 hw/acpi.c        |    3 +--
 hw/ps2.c         |    6 ++++++
 hw/serial.c      |    6 ++++++
 qapi-schema.json |   11 +++++++++++
 qmp-commands.hx  |   21 +++++++++++++++++++++
 qmp.c            |    5 +++++
 sysemu.h         |    2 ++
 vl.c             |   21 +++++++++++++++++++++
 11 files changed, 93 insertions(+), 2 deletions(-)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure
  2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
@ 2012-01-11 15:08 ` Gerd Hoffmann
  2012-01-13 15:51   ` Paolo Bonzini
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 2/5] suspend: add wakeup monitor command Gerd Hoffmann
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

This patch adds qemu_system_suspend_request() and void
qemu_system_wakeup_request() functions to qemu.

qemu_system_suspend_request is supposed to be called when the guest
asks for being be suspended, for example via ACPI.

qemu_system_wakeup_request is supposed to be called on events which
should wake up the guest.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 sysemu.h |    2 ++
 vl.c     |   21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/sysemu.h b/sysemu.h
index 3806901..d1834a0 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -39,6 +39,8 @@ void vm_stop(RunState state);
 void vm_stop_force_state(RunState state);
 
 void qemu_system_reset_request(void);
+void qemu_system_suspend_request(qemu_irq wake_irq);
+void qemu_system_wakeup_request(void);
 void qemu_system_shutdown_request(void);
 void qemu_system_powerdown_request(void);
 void qemu_system_debug_request(void);
diff --git a/vl.c b/vl.c
index ba55b35..26413e3 100644
--- a/vl.c
+++ b/vl.c
@@ -1282,6 +1282,7 @@ static int shutdown_requested, shutdown_signal = -1;
 static pid_t shutdown_pid;
 static int powerdown_requested;
 static int debug_requested;
+static qemu_irq suspend_wake_irq;
 static RunState vmstop_requested = RUN_STATE_MAX;
 
 int qemu_shutdown_requested_get(void)
@@ -1397,6 +1398,26 @@ void qemu_system_reset_request(void)
     qemu_notify_event();
 }
 
+void qemu_system_suspend_request(qemu_irq wake_irq)
+{
+    if (suspend_wake_irq != NULL) {
+        return;
+    }
+    cpu_stop_current();
+    qemu_notify_event();
+    suspend_wake_irq = wake_irq;
+}
+
+void qemu_system_wakeup_request(void)
+{
+    if (suspend_wake_irq == NULL) {
+        return;
+    }
+    reset_requested = 1;
+    qemu_irq_raise(suspend_wake_irq);
+    suspend_wake_irq = NULL;
+}
+
 void qemu_system_killed(int signal, pid_t pid)
 {
     shutdown_signal = signal;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [RFC PATCH 2/5] suspend: add wakeup monitor command
  2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure Gerd Hoffmann
@ 2012-01-11 15:08 ` Gerd Hoffmann
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 3/5] suspend: switch acpi s3 to new infrastructure Gerd Hoffmann
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

This patch adds a wakeup monitor command which will simply wake up
suspended guests.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hmp-commands.hx  |   14 ++++++++++++++
 hmp.c            |    5 +++++
 hmp.h            |    1 +
 qapi-schema.json |   11 +++++++++++
 qmp-commands.hx  |   21 +++++++++++++++++++++
 qmp.c            |    5 +++++
 6 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/hmp-commands.hx b/hmp-commands.hx
index 14838b7..a3e7486 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -313,6 +313,20 @@ Resume emulation.
 ETEXI
 
     {
+        .name       = "wakeup",
+        .args_type  = "",
+        .params     = "",
+        .help       = "wakeup guest from suspend",
+        .mhandler.cmd = hmp_wakeup,
+    },
+
+STEXI
+@item wakeup
+@findex wakeup
+Wakeup guest from suspend.
+ETEXI
+
+    {
         .name       = "gdbserver",
         .args_type  = "device:s?",
         .params     = "[device]",
diff --git a/hmp.c b/hmp.c
index e7659d5..1a14684 100644
--- a/hmp.c
+++ b/hmp.c
@@ -594,6 +594,11 @@ void hmp_cont(Monitor *mon, const QDict *qdict)
     }
 }
 
+void hmp_wakeup(Monitor *mon, const QDict *qdict)
+{
+    qmp_wakeup(NULL);
+}
+
 void hmp_inject_nmi(Monitor *mon, const QDict *qdict)
 {
     Error *errp = NULL;
diff --git a/hmp.h b/hmp.h
index 093242d..76eb3df 100644
--- a/hmp.h
+++ b/hmp.h
@@ -40,6 +40,7 @@ void hmp_cpu(Monitor *mon, const QDict *qdict);
 void hmp_memsave(Monitor *mon, const QDict *qdict);
 void hmp_pmemsave(Monitor *mon, const QDict *qdict);
 void hmp_cont(Monitor *mon, const QDict *qdict);
+void hmp_wakeup(Monitor *mon, const QDict *qdict);
 void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
 void hmp_set_link(Monitor *mon, const QDict *qdict);
 void hmp_block_passwd(Monitor *mon, const QDict *qdict);
diff --git a/qapi-schema.json b/qapi-schema.json
index 44cf764..75773d4 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -967,6 +967,17 @@
 { 'command': 'cont' }
 
 ##
+# @wakeup:
+#
+# Wakrup guest from suspend
+#
+# Since:  1.1
+#
+# Returns:  nothing.
+##
+{ 'command': 'wakeup' }
+
+##
 # @inject-nmi:
 #
 # Injects an Non-Maskable Interrupt into all guest's VCPUs.
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 7e3f4b9..2c84a7a 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -218,6 +218,27 @@ Example:
 EQMP
 
     {
+        .name       = "wakeup",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_wakeup,
+    },
+
+SQMP
+wakeup
+------
+
+Wakeup guest from suspend.
+
+Arguments: None.
+
+Example:
+
+-> { "execute": "wakeup" }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "system_reset",
         .args_type  = "",
         .mhandler.cmd_new = qmp_marshal_input_system_reset,
diff --git a/qmp.c b/qmp.c
index 5e09b41..f8b1dc7 100644
--- a/qmp.c
+++ b/qmp.c
@@ -158,6 +158,11 @@ void qmp_cont(Error **errp)
     vm_start();
 }
 
+void qmp_wakeup(Error **errp)
+{
+    qemu_system_wakeup_request();
+}
+
 DevicePropertyInfoList *qmp_qom_list(const char *path, Error **errp)
 {
     DeviceState *dev;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [RFC PATCH 3/5] suspend: switch acpi s3 to new infrastructure.
  2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure Gerd Hoffmann
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 2/5] suspend: add wakeup monitor command Gerd Hoffmann
@ 2012-01-11 15:08 ` Gerd Hoffmann
  2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 4/5] suspend: make ps/2 devices wakeup the guest Gerd Hoffmann
  2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 5/5] suspend: make serial ports " Gerd Hoffmann
  4 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Put the new bits into use by making acpi s3 suspend use them.
This patch also makes the guest actually stay suspended instead
of leaving suspend instantly, so it is useful for more than just
testing whenever the suspend/resume cycle actually works.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/acpi.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/hw/acpi.c b/hw/acpi.c
index 9c35f2d..11d535d 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -348,8 +348,7 @@ void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val)
                Pretend that resume was caused by power button */
             pm1a->sts |=
                 (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS);
-            qemu_system_reset_request();
-            qemu_irq_raise(pm1_cnt->cmos_s3);
+            qemu_system_suspend_request(pm1_cnt->cmos_s3);
         default:
             break;
         }
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [RFC PATCH 4/5] suspend: make ps/2 devices wakeup the guest
  2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 3/5] suspend: switch acpi s3 to new infrastructure Gerd Hoffmann
@ 2012-01-11 15:09 ` Gerd Hoffmann
  2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 5/5] suspend: make serial ports " Gerd Hoffmann
  4 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

This patch adds wakeup support to ps/2 emulation.  Any key press on the
ps/2 keyboard will wakeup the guest.  Likewise any mouse button press
will wakeup the guest.  Mouse moves are ignored, so the guest will not
wakeup in case your mouse crosses the vnc window of a suspended guest by
accident.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/ps2.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/ps2.c b/hw/ps2.c
index 1d9057b..d1b2505 100644
--- a/hw/ps2.c
+++ b/hw/ps2.c
@@ -24,6 +24,7 @@
 #include "hw.h"
 #include "ps2.h"
 #include "console.h"
+#include "sysemu.h"
 
 /* debug PC keyboard */
 //#define DEBUG_KBD
@@ -154,6 +155,7 @@ static void ps2_put_keycode(void *opaque, int keycode)
 {
     PS2KbdState *s = opaque;
 
+    qemu_system_wakeup_request();
     /* XXX: add support for scancode set 1 */
     if (!s->translate && keycode < 0xe0 && s->scancode_set > 1) {
         if (keycode & 0x80) {
@@ -368,6 +370,10 @@ static void ps2_mouse_event(void *opaque,
 	return;
     s->mouse_buttons = buttons_state;
 
+    if (buttons_state) {
+        qemu_system_wakeup_request();
+    }
+
     if (!(s->mouse_status & MOUSE_STATUS_REMOTE) &&
         (s->common.queue.count < (PS2_QUEUE_SIZE - 16))) {
         for(;;) {
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [RFC PATCH 5/5] suspend: make serial ports wakeup the guest.
  2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 4/5] suspend: make ps/2 devices wakeup the guest Gerd Hoffmann
@ 2012-01-11 15:09 ` Gerd Hoffmann
  4 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-11 15:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Add a 'wakeup' property to the serial port.  It is off by default.  When
enabled any incoming character on the serial line will wake up the
guest.  Useful for guests which have a serial console configured.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/serial.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index d35c7a9..96ac7c1 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -139,6 +139,7 @@ struct SerialState {
     int it_shift;
     int baudbase;
     int tsr_retry;
+    uint32_t wakeup;
 
     uint64_t last_xmit_ts;              /* Time when the last byte was successfully sent out of the tsr */
     SerialFIFO recv_fifo;
@@ -635,6 +636,10 @@ static int serial_can_receive1(void *opaque)
 static void serial_receive1(void *opaque, const uint8_t *buf, int size)
 {
     SerialState *s = opaque;
+
+    if (s->wakeup) {
+        qemu_system_wakeup_request();
+    }
     if(s->fcr & UART_FCR_FE) {
         int i;
         for (i = 0; i < size; i++) {
@@ -889,6 +894,7 @@ static ISADeviceInfo serial_isa_info = {
         DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
         DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
         DEFINE_PROP_CHR("chardev",  ISASerialState, state.chr),
+        DEFINE_PROP_UINT32("wakeup", ISASerialState, state.wakeup, 0),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure
  2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure Gerd Hoffmann
@ 2012-01-13 15:51   ` Paolo Bonzini
  2012-01-16 18:12     ` Gerd Hoffmann
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2012-01-13 15:51 UTC (permalink / raw)
  To: qemu-devel, Gerd Hoffmann

On 01/11/2012 04:08 PM, Gerd Hoffmann wrote:
> +void qemu_system_suspend_request(qemu_irq wake_irq)
> +{
> +    if (suspend_wake_irq != NULL) {
> +        return;
> +    }
> +    cpu_stop_current();
> +    qemu_notify_event();
> +    suspend_wake_irq = wake_irq;
> +}
> +
> +void qemu_system_wakeup_request(void)
> +{
> +    if (suspend_wake_irq == NULL) {
> +        return;
> +    }
> +    reset_requested = 1;
> +    qemu_irq_raise(suspend_wake_irq);
> +    suspend_wake_irq = NULL;
> +}

The code in acpi.c is confusing, but it seems to me that IRQ is raised 
when the system _enters_ S3.  See especially xen-all.c.  It would be 
lowered by acpi_pm1_cnt_reset when the reset actually happens on the 
next main loop iteration.  However, acpi_pm1_cnt_reset has never been 
called since its introduction in commit eaba51c (acpi, acpi_piix, 
vt82c686: factor out PM1_CNT logic, 2011-03-25).

Overall, it seems to me that with your new infrastructure a global 
Notifier would be a better fit than a qemu_irq that the board would have 
to pass all the way.  A notifier would also remove the ugly Xen special 
casing.  However, this can be done separately.

Paolo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure
  2012-01-13 15:51   ` Paolo Bonzini
@ 2012-01-16 18:12     ` Gerd Hoffmann
  0 siblings, 0 replies; 8+ messages in thread
From: Gerd Hoffmann @ 2012-01-16 18:12 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel

On 01/13/12 16:51, Paolo Bonzini wrote:
> On 01/11/2012 04:08 PM, Gerd Hoffmann wrote:
>> +void qemu_system_suspend_request(qemu_irq wake_irq)
>> +{
>> +    if (suspend_wake_irq != NULL) {
>> +        return;
>> +    }
>> +    cpu_stop_current();
>> +    qemu_notify_event();
>> +    suspend_wake_irq = wake_irq;
>> +}
>> +
>> +void qemu_system_wakeup_request(void)
>> +{
>> +    if (suspend_wake_irq == NULL) {
>> +        return;
>> +    }
>> +    reset_requested = 1;
>> +    qemu_irq_raise(suspend_wake_irq);
>> +    suspend_wake_irq = NULL;
>> +}
> 
> The code in acpi.c is confusing, but it seems to me that IRQ is raised
> when the system _enters_ S3.  See especially xen-all.c.

> Overall, it seems to me that with your new infrastructure a global
> Notifier would be a better fit than a qemu_irq that the board would have
> to pass all the way.

Indeed.  Especially as it isn't actually a IRQ line but just a qemu_irq
struct which is abused as notifier ...

> A notifier would also remove the ugly Xen special
> casing.

Yes.

> However, this can be done separately.

It's easier to do it all in one go.  It also gives some bonus points
because it'll remove more code than it adds ;)

v2 goes out in a minute ...

thanks for the review,
  Gerd

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-01-16 19:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-11 15:08 [Qemu-devel] [RFC PATCH 0/5] initial suspend support Gerd Hoffmann
2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure Gerd Hoffmann
2012-01-13 15:51   ` Paolo Bonzini
2012-01-16 18:12     ` Gerd Hoffmann
2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 2/5] suspend: add wakeup monitor command Gerd Hoffmann
2012-01-11 15:08 ` [Qemu-devel] [RFC PATCH 3/5] suspend: switch acpi s3 to new infrastructure Gerd Hoffmann
2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 4/5] suspend: make ps/2 devices wakeup the guest Gerd Hoffmann
2012-01-11 15:09 ` [Qemu-devel] [RFC PATCH 5/5] suspend: make serial ports " Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).