Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power.
PATCH 1/1 Add ACPI sleep button for HVM guests and a libxl method for 'pressing' sleep or power.
The first patch in this series adds a static ACPI sleep button to HVM guests (akin to the power button that was added some time ago). The second patch adds support into libxenlight for pressing either the power or sleep buttons.
Paul
PATCH 1/1 Add ACPI fixed sleep button for HVM
# HG changeset patch
# User Paul Durrant <[email protected]> # Date 1263377694 0
# Node ID cdf348c11aba31171bdc838ffe3a457acab0f7de # Parent 13d4e78ede977ee92c4a4adf78a92b31ec52c00e Add ACPI fixed sleep button for HVM.
tools/firmware/hvmloader/acpi/static_tables.c +1 -1
@@ -68,7 +68,7 @@ .p_lvl2_lat = 0x0fff, /* >100, means we do not support C2 state */ .p_lvl3_lat = 0x0fff, /* >1000, means we do not support C3 state */ .iapc_boot_arch = ACPI_8042, - .flags = (ACPI_PROC_C1 |ACPI_SLP_BUTTON | + .flags = (ACPI_PROC_C1 |ACPI_WBINVD | ACPI_FIX_RTC | ACPI_TMR_VAL_EXT),
xen/arch/x86/domctl.c +13 -0
@@ -723,6 +723,19 @@ { ret =0 ;hvm_acpi_power_button (d); + } + } +break ; + +case XEN_DOMCTL_SENDTRIGGER_SLEEP : + { +extern void hvm_acpi_sleep_button (struct domain *d); + + ret = -EINVAL ; +if (is_hvm_domain (d) ) + { + ret =0 ; +hvm_acpi_sleep_button (d); } }break ;
xen/arch/x86/hvm/pmtimer.c +12 -1
@@ -32,14 +32,16 @@#define TMR_STS (1 << 0)#define GBL_STS (1 << 5)#define PWRBTN_STS (1 << 8) +#define SLPBTN_STS (1 << 9)/* The same in PM1a_EN */ #define TMR_EN (1 << 0)#define GBL_EN (1 << 5)#define PWRBTN_EN (1 << 8) +#define SLPBTN_EN (1 << 9)/* Mask of bits in PM1a_STS that can generate an SCI. */ -#define SCI_MASK (TMR_STS|PWRBTN_STS|GBL_STS) +#define SCI_MASK (TMR_STS|PWRBTN_STS|SLPBTN_STS|GBL_STS)/* SCI IRQ number (must match SCI_INT number in ACPI FADT in hvmloader) */ #define SCI_IRQ 9
@@ -64,6 +66,15 @@PMTState *s = &d->arch.hvm_domain.pl_time.vpmt;spin_lock (&s->lock); s->pm.pm1a_sts |=PWRBTN_STS ; +pmt_update_sci (s); +spin_unlock (&s->lock); +} + +void hvm_acpi_sleep_button (struct domain *d) +{ +PMTState *s = &d->arch.hvm_domain.pl_time.vpmt; +spin_lock (&s->lock); + s->pm.pm1a_sts |=SLPBTN_STS ;pmt_update_sci (s);spin_unlock (&s->lock); }
xen/include/public/domctl.h +1 -0
@@ -439,6 +439,7 @@#define XEN_DOMCTL_SENDTRIGGER_RESET 1#define XEN_DOMCTL_SENDTRIGGER_INIT 2#define XEN_DOMCTL_SENDTRIGGER_POWER 3 +#define XEN_DOMCTL_SENDTRIGGER_SLEEP 4struct xen_domctl_sendtrigger {uint32_t trigger;/* IN */ uint32_t vcpu;/* IN */
PATCH 1/1 Add support to libxl to trigger power or sleep button pushes
In reply to Paul Durrant# HG changeset patch
# User Paul Durrant <[email protected]>
# Date 1263377694 0
# Node ID 679f0a189c7280053cc172d1ed80b6312702f4d8 # Parent cdf348c11aba31171bdc838ffe3a457acab0f7de Add support to libxl to trigger power or sleep button pushes in HVM guests.
tools/libxl/libxl.c +18 -0
@@ -2153,3 +2153,21 @@ rc =xc_domain_memory_set_pod_target (ctx->xch, domid, (target_memkb - videoram) /4 ,NULL ,NULL ,NULL );return rc; } + +int libxl_button_press (struct libxl_ctx *ctx,uint32_t domid,libxl_button button) +{ +int rc =-1 ; + +switch (button) { +case POWER_BUTTON : + rc =xc_domain_send_trigger (ctx->xch, domid,XEN_DOMCTL_SENDTRIGGER_POWER ,0 ); +break ; +case SLEEP_BUTTON : + rc =xc_domain_send_trigger (ctx->xch, domid,XEN_DOMCTL_SENDTRIGGER_SLEEP ,0 ); +break ; +default : +break ; + } + +return rc; +}
tools/libxl/libxl.h +9 -1
@@ -343,4 +343,12 @@ unsigned int bus, unsigned int dev, unsigned int func, unsigned int vdevfn); -#endif +typedef enum { +POWER_BUTTON , +SLEEP_BUTTON +}libxl_button ; + +int libxl_button_press (struct libxl_ctx *ctx,uint32_t domid,libxl_button button); + +#endif /* LIBXL_H */ +
tools/libxl/xl.c +61 -0
85 lines not on this page · raw message
Quoted 4 lines · Paul Durrant
The first patch in this series adds a static ACPI sleep button to HVM guests (akin to the power button that was added some time ago). The second patch adds support into libxenlight for pressing either the power or sleep buttons.
So HVM guests without PV drivers can now be shutdown using ACPI.. Is there 'xm' command for this aswell?
-- Pasi
Quoted 6 lines · Pasi Kärkkäinen
Quoted 4 lines · Paul Durrant
The first patch in this series adds a static ACPI sleep button to HVM guests (akin to the power button that was added some time ago). The second patch adds support into libxenlight for pressing either the power or sleep buttons.
So HVM guests without PV drivers can now be shutdown using ACPI..
Yep :-)
Quoted 2 lines
Is there 'xm' command for this aswell?
No, I didn't have time to do an xm command for it. You can obviously use the xl command even on a domain started with xm though.
Paul
Signature · 10 lines
=============================== Paul Durrant, Software Engineer Citrix Systems (R&D) Ltd. First Floor, Building 101 Cambridge Science Park Milton Road Cambridge CB4 0FY United Kingdom ===============================
Re: [PATCH 2 of 2] Add support to libxl to trigger power or sleep button pushes
In reply to Paul DurrantQuoted 7 lines · Paul Durrant
# HG changeset patch
# User Paul Durrant <[email protected]>
# Date 1263377694 0
# Node ID679f0a189c7280053cc172d1ed80b6312702f4d8# Parentcdf348c11aba31171bdc838ffe3a457acab0f7deAdd support to libxl to trigger power or sleep button pushes in HVM guests.
Thanks !
minor comment inline (but can be applied nonetheless):
tools/libxl/xl.c line 1682
Quoted 7 lines
tools/libxl/xl.c +7
-0+void button_press (char *p,char *b) +{ +struct libxl_ctx ctx; +uint32_t domid; +libxl_button button; + +libxl_ctx_init (&ctx,LIBXL_VERSION );
ctx_init can fails in bad situation; it is always better to check the return value just in case.
Quoted 9 lines
tools/libxl/xl.c +9
-0+libxl_ctx_set_log (&ctx, log_callback,NULL ); + +if (domain_qualifier_to_domid (&ctx, p, &domid) <0 ) { +fprintf (stderr,"%s is an invalid domain identifier\n" , p); +exit (2 ); + } + +if (!strcmp (b,"power" )) { + button =POWER_BUTTON ;
tools/libxl/xl.c line 1701
Quoted 10 lines
tools/libxl/xl.c +10
-0+ }else if (!strcmp (b,"sleep" )) { + button =SLEEP_BUTTON ; + }else { +fprintf (stderr,"%s is an invalid button identifier\n" , b); +exit (2 ); + } + +libxl_button_press (&ctx, domid, button); +} +
and while it doesn't matter because the program is short lived, you're suppose to call libxl_ctx_free when you're done with libxl.
Signature · 1 line
Vincent Hanquez
Re: [PATCH 1 of 2] Add ACPI fixed sleep button for HVM
In reply to Paul Durrantxen/arch/x86/domctl.c line 732
Quoted 3 lines · Paul Durrant
xen/arch/x86/domctl.c +3
-0+case XEN_DOMCTL_SENDTRIGGER_SLEEP : + { +extern void hvm_acpi_sleep_button (struct domain *d);
I think this belongs in xen/include/asm-x86/acpi.h
Ian.
Quoted 2 lines
So HVM guests without PV drivers can now be shutdown using ACPI.. Is there 'xm' command for this aswell?
Well, they'll do whatever the guest is internally configured to do when the power button is pressed e.g. nothing/shutdown/sleep/hibernate/crash
It is possible to send an ACPI "fatal" event that will likely result in the system shutting down. However, the shutdown certainly isn't as graceful as a user initiated one -- I know windows doesn't prompt you to save files or close programs; I don't know if it even notifies user space applications.
We could add ACPI support for 'Fatal' events, though someone would need to volunteer to do some more testing to understand the effects on different OSes.
Ian
"xm trigger <Domain> power" has worked since xen-3.4.0. It's quite easy to add support "xm trigger <Domain> sleep".
-- Kouya
Quoted 34 lines · Paul Durrant
Quoted 6 lines · Pasi Kärkkäinen
Quoted 4 lines · Paul Durrant
The first patch in this series adds a static ACPI sleep button to HVM guests (akin to the power button that was added some time ago). The second patch adds support into libxenlight for pressing either the power or sleep buttons.
So HVM guests without PV drivers can now be shutdown using ACPI..
Yep :-)
Quoted 2 lines
Is there 'xm' command for this aswell?
No, I didn't have time to do an xm command for it. You can obviously use the xl command even on a domain started with xm though.
Paul
Signature · 15 lines
=============================== Paul Durrant, Software Engineer Citrix Systems (R&D) Ltd. First Floor, Building 101 Cambridge Science Park Milton Road Cambridge CB4 0FY United Kingdom =============================== _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel