initial suspend support
cover initial suspend support
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(-)
RFC PATCH 1/5 suspend: add infrastructure
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.
--- sysemu.h | 2 ++ vl.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 0 deletions(-)
sysemu.h +2 -0
@@ -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 );
vl.c +21 -0
@@ -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;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure
Quoted 9 lines · Gerd Hoffmann
vl.c +9
-0+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; +}
vl.c void qemu_system_reset_request(void) · line 1419
Quoted 10 lines
vl.c +10
-0+ +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
Re: [Qemu-devel] [RFC PATCH 1/5] suspend: add infrastructure
Quoted 24 lines · Paolo Bonzini
Quoted 9 lines · Gerd Hoffmann
vl.c +9
-0+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; +}vl.c void qemu_system_reset_request(void) · line 1419
Quoted 10 lines
vl.c +10
-0+ +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.cis confusing, but it seems to me that IRQ is raised when the system _enters_ S3. See especiallyxen-all.c.
Quoted 3 lines
Overall, it seems to me that with your new infrastructure a global Notifier would be a better fit than a
qemu_irqthat 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 ...
Quoted 2 lines
A notifier would also remove the ugly Xen special
casing.
Yes.
Quoted 1 line
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
RFC PATCH 2/5 suspend: add wakeup monitor command
In reply to Gerd HoffmannThis patch adds a wakeup monitor command which will simply wake up suspended guests.
--- 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(-)
hmp-commands.hx +14 -0
@@ -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]",
hmp.c +5 -0
@@ -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 ;
hmp.h +1 -0
@@ -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);
qapi-schema.json +11 -0
@@ -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.
qmp-commands.hx +21 -0
@@ -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,
qmp.c +5 -0
@@ -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;
Signature · 1 line
1.7.1
RFC PATCH 3/5 suspend: switch acpi s3 to new infrastructure.
In reply to Gerd HoffmannPut 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.
--- hw/acpi.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/acpi.c +1 -2
@@ -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 ; }
Signature · 1 line
1.7.1
RFC PATCH 4/5 suspend: make ps/2 devices wakeup the guest
In reply to Gerd HoffmannThis 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.
--- hw/ps2.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/ps2.c +6 -0
@@ -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 (;;) {
Signature · 1 line
1.7.1
RFC PATCH 5/5 suspend: make serial ports wakeup the guest.
In reply to Gerd HoffmannAdd 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.
--- hw/serial.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/serial.c +6 -0
@@ -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(), }, };
Signature · 1 line
1.7.1