[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot
From: |
Gleb Natapov |
Subject: |
Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot |
Date: |
Wed, 8 Jul 2009 10:56:01 +0300 |
On Tue, Jul 07, 2009 at 02:26:31PM -0500, Ryan Harper wrote:
> Add a new monitor command (system_reboot) for a soft reboot which uses
> system_powerdown to trigger ACPI shutdown in the guest and once shutdown
> is complete, trigger a reset instead of exiting qemu.
>
> Depends on commit a6d6552426dcbf726e5549f08b70c9318d6be14b which enabled
> ACPI power button support.
>
> V2:
> -added reset handler to lower the reboot flag on reset.
OS is free to ignore ACPI shutdown request and in this case
reboot_requested will not be reset. On the next user initiated
guest power down qemu will reboot instead of exit.
>
> Tested with:
> - Ubuntu 9.04 64-bit guest.
> - SLES 10 SP2 32-bit guest.
> - RHEL 5.3 32 and 64 bit guests.
>
> --
> Ryan Harper
> Software Engineer; Linux Technology Center
> IBM Corp., Austin, Tx
> address@hidden
>
>
> diffstat output:
> hw/acpi.c | 15 ++++++++++++++-
> monitor.c | 5 +++++
> qemu-monitor.hx | 8 ++++++++
> sysemu.h | 2 ++
> vl.c | 22 +++++++++++++++++++++-
> 5 files changed, 50 insertions(+), 2 deletions(-)
>
> ---
> From: Ryan Harper <address@hidden>
> Subject: [PATCH] Add system_reboot monitor function
> Cc: Anthony Liguori <address@hidden>
>
> This patch adds a new monitor command to trigger a powerdown followed by
> system_reset.
>
> Signed-off-by: Ryan Harper <address@hidden>
> ---
> hw/acpi.c | 15 ++++++++++++++-
> monitor.c | 5 +++++
> qemu-monitor.hx | 8 ++++++++
> sysemu.h | 2 ++
> vl.c | 21 +++++++++++++++++++++
> 5 files changed, 50 insertions(+), 1 deletions(-)
>
> diff --git a/hw/acpi.c b/hw/acpi.c
> index 0465201..aba384c 100644
> --- a/hw/acpi.c
> +++ b/hw/acpi.c
> @@ -151,7 +151,13 @@ static void pm_ioport_writew(void *opaque, uint32_t
> addr, uint32_t val)
> sus_typ = (val >> 10) & 7;
> switch(sus_typ) {
> case 0: /* soft power off */
> - qemu_system_shutdown_request();
> + /* after powerdown, if on system_reboot path, call reset
> + instead of shutdown */
> + if (qemu_reboot_requested()) {
> + qemu_system_reset_request();
> + } else {
> + qemu_system_shutdown_request();
> + }
> break;
> case 1:
> /* RSM_STS should be set on resume. Pretend that resume
> @@ -497,6 +503,12 @@ static void piix4_reset(void *opaque)
> }
> }
>
> +static void system_reboot_reset(void *opaque)
> +{
> + /* clear reboot flag */
> + qemu_reboot_requested();
> +}
> +
> i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
> qemu_irq sci_irq)
> {
> @@ -551,6 +563,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t
> smb_io_base,
> s->smbus = i2c_init_bus(NULL, "i2c");
> s->irq = sci_irq;
> qemu_register_reset(piix4_reset, s);
> + qemu_register_reset(system_reboot_reset, s);
>
> return s->smbus;
> }
> diff --git a/monitor.c b/monitor.c
> index bad79fe..346e0db 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -1223,6 +1223,11 @@ static void do_system_powerdown(Monitor *mon)
> qemu_system_powerdown_request();
> }
>
> +static void do_system_reboot(Monitor *mon)
> +{
> + qemu_system_reboot_request();
> +}
> +
> #if defined(TARGET_I386)
> static void print_pte(Monitor *mon, uint32_t addr, uint32_t pte, uint32_t
> mask)
> {
> diff --git a/qemu-monitor.hx b/qemu-monitor.hx
> index dc10b75..91799d0 100644
> --- a/qemu-monitor.hx
> +++ b/qemu-monitor.hx
> @@ -339,6 +339,14 @@ STEXI
> Power down the system (if supported).
> ETEXI
>
> + { "system_reboot", "", do_system_reboot,
> + "", "send system power down event, and then reset" },
> +STEXI
> address@hidden system_reboot
> +
> +Power down the system (if supported), and then reset.
> +ETEXI
> +
> { "sum", "ii", do_sum,
> "addr size", "compute the checksum of a memory region" },
> STEXI
> diff --git a/sysemu.h b/sysemu.h
> index 06dc4c6..056a491 100644
> --- a/sysemu.h
> +++ b/sysemu.h
> @@ -40,10 +40,12 @@ void cpu_enable_ticks(void);
> void cpu_disable_ticks(void);
>
> void qemu_system_reset_request(void);
> +void qemu_system_reboot_request(void);
> void qemu_system_shutdown_request(void);
> void qemu_system_powerdown_request(void);
> int qemu_shutdown_requested(void);
> int qemu_reset_requested(void);
> +int qemu_reboot_requested(void);
> int qemu_powerdown_requested(void);
> #ifdef NEED_CPU_H
> #if !defined(TARGET_SPARC) && !defined(TARGET_I386)
> diff --git a/vl.c b/vl.c
> index 7b7489c..634d386 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -3618,6 +3618,7 @@ static QEMUResetEntry *first_reset_entry;
> static int reset_requested;
> static int shutdown_requested;
> static int powerdown_requested;
> +static int reboot_requested;
> static int debug_requested;
> static int vmstop_requested;
>
> @@ -3642,6 +3643,13 @@ int qemu_powerdown_requested(void)
> return r;
> }
>
> +int qemu_reboot_requested(void)
> +{
> + int r = reboot_requested;
> + reboot_requested = 0;
> + return r;
> +}
> +
> static int qemu_debug_requested(void)
> {
> int r = debug_requested;
> @@ -3712,6 +3720,17 @@ void qemu_system_powerdown_request(void)
> qemu_notify_event();
> }
>
> +void qemu_system_reboot_request(void)
> +{
> + /* Raise the powerdown request to trigger system_powerdown event.
> + * Also raise reboot flag so powerdown handler knows to request
> + * a reset instead of shutdown after the powerdown.
> + */
> + powerdown_requested = 1;
> + reboot_requested = 1;
> + qemu_notify_event();
> +}
> +
> #ifdef CONFIG_IOTHREAD
> static void qemu_system_vmstop_request(int reason)
> {
> @@ -4461,6 +4480,8 @@ static int vm_can_run(void)
> {
> if (powerdown_requested)
> return 0;
> + if (reboot_requested)
> + return 0;
> if (reset_requested)
> return 0;
> if (shutdown_requested)
> --
> 1.6.0.4
>
>
--
Gleb.
Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot,
Gleb Natapov <=
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Anthony Liguori, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Daniel P. Berrange, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Anthony Liguori, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Daniel P. Berrange, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Anthony Liguori, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Ryan Harper, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Anthony Liguori, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Ryan Harper, 2009/07/08
- Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Anthony Liguori, 2009/07/08
Re: [Qemu-devel] [PATCH][RESEND] Add monitor command for system_reboot, Avi Kivity, 2009/07/08