Message ID | 20171206120217.11392-2-danielhb@linux.vnet.ibm.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 12/06/2017 06:02 AM, Daniel Henrique Barboza wrote: > When issuing the qmp/hmp 'system_wakeup' command, what happens in a > nutshell is: > > This patch implements a new QMP command called > 'query-wakeup-from-suspend-support' that allows the caller to query > if the guest supports wake up from suspend via system_wakeup. It > goes over the subscribers of the wake up event and, if it's empty, > it assumes that the guest does not support wake up from suspend > (and thus, pm-suspend itself). > > This is the expected output of the command when running a x86 guest: > > {"execute" : "query-wakeup-from-suspend-support"} > {"return": {"enabled": true}} Do we really need a new command, or can we add it as an additional field to an existing command (for example, in MachineInfo under query-machines, or TargetInfo under query-target)?
On 12/06/2017 12:26 PM, Eric Blake wrote: > On 12/06/2017 06:02 AM, Daniel Henrique Barboza wrote: >> When issuing the qmp/hmp 'system_wakeup' command, what happens in a >> nutshell is: >> >> This patch implements a new QMP command called >> 'query-wakeup-from-suspend-support' that allows the caller to query >> if the guest supports wake up from suspend via system_wakeup. It >> goes over the subscribers of the wake up event and, if it's empty, >> it assumes that the guest does not support wake up from suspend >> (and thus, pm-suspend itself). >> >> This is the expected output of the command when running a x86 guest: >> >> {"execute" : "query-wakeup-from-suspend-support"} >> {"return": {"enabled": true}} > Do we really need a new command, or can we add it as an additional field > to an existing command (for example, in MachineInfo under > query-machines, or TargetInfo under query-target)? A new QMP command was the first idea that crossed my mind but yeah, adding the info to an existing command is also valid IMO. Daniel >
Hi, On 12/06/2017 01:50 PM, Daniel Henrique Barboza wrote: > > > On 12/06/2017 12:26 PM, Eric Blake wrote: >> On 12/06/2017 06:02 AM, Daniel Henrique Barboza wrote: >>> When issuing the qmp/hmp 'system_wakeup' command, what happens in a >>> nutshell is: >>> >>> This patch implements a new QMP command called >>> 'query-wakeup-from-suspend-support' that allows the caller to query >>> if the guest supports wake up from suspend via system_wakeup. It >>> goes over the subscribers of the wake up event and, if it's empty, >>> it assumes that the guest does not support wake up from suspend >>> (and thus, pm-suspend itself). >>> >>> This is the expected output of the command when running a x86 guest: >>> >>> {"execute" : "query-wakeup-from-suspend-support"} >>> {"return": {"enabled": true}} >> Do we really need a new command, or can we add it as an additional field >> to an existing command (for example, in MachineInfo under >> query-machines, or TargetInfo under query-target)? > > A new QMP command was the first idea that crossed my mind but yeah, > adding > the info to an existing command is also valid IMO. After investigating, I think that it's simpler to hook the wakeup support info into TargetInfo than MachineInfo, given that the detection I'm using for this new property is based on the current runtime state. Hooking into MachineInfo would require to change the MachineClass to add a new property, then setting it up for the machines that have the wakeup support (only x86 so far). Definitely doable, but if we don't have any favorites between MachineInfo and TargetInfo I'd rather pick the simpler route. So, if no one objects, I'll rework this series by putting the logic inside query-target instead of a new API. Daniel > > > Daniel > >> > >
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index c083869fcf..70b94dcda5 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -69,6 +69,7 @@ typedef enum WakeupReason { void qemu_system_reset_request(ShutdownCause reason); void qemu_system_suspend_request(void); void qemu_register_suspend_notifier(Notifier *notifier); +bool qemu_wakeup_notifier_is_empty(void); void qemu_system_wakeup_request(WakeupReason reason); void qemu_system_wakeup_enable(WakeupReason reason, bool enabled); void qemu_register_wakeup_notifier(Notifier *notifier); diff --git a/qapi-schema.json b/qapi-schema.json index 18457954a8..cf5bf327bd 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3200,3 +3200,26 @@ # Since: 2.11 ## { 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} } + +## +# @WakeupSuspendSupportInfo: +# +# Information about the wake up from suspend support of the VM. +# +# @enabled: true if the target supports wake up from suspend +# +# Since: 2.12 +## +{ 'struct': 'WakeupSuspendSupportInfo', + 'data': { 'enabled': 'bool' } } + +## +# @query-wakeup-from-suspend-support: +# +# Return information about the wake up from suspend support of the VM. +# +# Returns: WakeupSuspendSupportInfo +# +# Since: 2.12 +## +{ 'command': 'query-wakeup-from-suspend-support', 'returns': 'WakeupSuspendSupportInfo' } diff --git a/qmp.c b/qmp.c index e8c303116a..26fefbbe88 100644 --- a/qmp.c +++ b/qmp.c @@ -722,3 +722,12 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp) return mem_info; } + +WakeupSuspendSupportInfo *qmp_query_wakeup_from_suspend_support(Error **errp) +{ + WakeupSuspendSupportInfo *info = g_malloc0(sizeof(*info)); + + info->enabled = !qemu_wakeup_notifier_is_empty(); + + return info; +} diff --git a/vl.c b/vl.c index 1ad1c04637..b07aa6f098 100644 --- a/vl.c +++ b/vl.c @@ -1889,6 +1889,11 @@ void qemu_register_wakeup_notifier(Notifier *notifier) notifier_list_add(&wakeup_notifiers, notifier); } +bool qemu_wakeup_notifier_is_empty(void) +{ + return QLIST_EMPTY(&wakeup_notifiers.notifiers); +} + void qemu_system_killed(int signal, pid_t pid) { shutdown_signal = signal;
When issuing the qmp/hmp 'system_wakeup' command, what happens in a nutshell is: - qmp_system_wakeup_request set runstate to RUNNING, sets a wakeup_reason and notify the event - in the main_loop, all vcpus are paused, a system reset is issued, all subscribers of wakeup_notifiers receives a notification, vcpus are then resumed and the wake up QAPI event is fired Note that this procedure alone doesn't ensure that the guest will awake from SUSPENDED state - the subscribers of the wake up event must take action to resume the guest, otherwise the guest will simply reboot. At this moment there are only two subscribers of the wake up event: one in hw/acpi/core.c and another one in hw/i386/xen/xen-hvm.c. This means that system_wakeup does not work as intended with other architectures. However, only the presence of 'system_wakeup' is required for QGA to support 'guest-suspend-ram' and 'guest-suspend-hybrid' at this moment. This means that the user/management will expect to suspend the guest using one of those suspend commands and then resume execution using system_wakeup, regardless of the support offered in system_wakeup in the first place. This patch implements a new QMP command called 'query-wakeup-from-suspend-support' that allows the caller to query if the guest supports wake up from suspend via system_wakeup. It goes over the subscribers of the wake up event and, if it's empty, it assumes that the guest does not support wake up from suspend (and thus, pm-suspend itself). This is the expected output of the command when running a x86 guest: {"execute" : "query-wakeup-from-suspend-support"} {"return": {"enabled": true}} This is the output when running a pseries guest: {"execute" : "query-wakeup-from-suspend-support"} {"return": {"enabled": false}} With this extra tool, management can avoid situations where a guest that does not have proper suspend/wake capabilities ends up in inconsistent state (e.g. https://github.com/open-power-host-os/qemu/issues/31). Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> --- include/sysemu/sysemu.h | 1 + qapi-schema.json | 23 +++++++++++++++++++++++ qmp.c | 9 +++++++++ vl.c | 5 +++++ 4 files changed, 38 insertions(+)