Watchdog timers for domains
PATCH 1/1 Watchdog timers for domains
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed.
Patch from Christian Limpach <[email protected]>
# HG changeset patch
# User Tim Deegan <[email protected]> # Date 1275473726 -3600
# Node ID f192bc28870d1789cb5865f8e795e1a47a56200c # Parent ba22297b00514325fef3673f3184eca466bd6990 Watchdog timers for domains.
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed.
Patch from Christian Limpach <[email protected]>
.hgignore +1 -0
@@ -237,6 +237,7 @@ ^tools/xcutils/xc_restore$ ^tools/xcutils/xc_save$ ^tools/xcutils/readnotes$ +^tools/misc/xenwatchdogd$ ^tools/xenfb/sdlfb$ ^tools/xenfb/vncfb$ ^tools/xenmon/xentrace_setmask$
tools/libxc/xc_domain.c +28 -0
@@ -364,6 +364,34 @@unlock_pages (ctxt, sz);return rc; +} + +int xc_watchdog (xc_interface *xch, +uint32_t id, +uint32_t timeout) +{ +int ret =-1 ; +sched_watchdog_t arg; +DECLARE_HYPERCALL ; + + hypercall.op = __HYPERVISOR_sched_op; + hypercall.arg[0 ] = (unsigned long )SCHEDOP_watchdog; + hypercall.arg[1 ] = (unsigned long )&arg; + arg.id = id; + arg.timeout = timeout; + +if (lock_pages (&arg,sizeof (arg)) !=0 ) + { +PERROR ("Could not lock memory for Xen hypercall" ); + goto out1; + } + + ret =do_xen_hypercall (xch, &hypercall); + +unlock_pages (&arg,sizeof (arg)); + + out1: +return ret; }
tools/libxc/xenctrl.h +4 -0
@@ -341,6 +341,10 @@int xc_domain_shutdown (xc_interface *xch,uint32_t domid,int reason); + +int xc_watchdog (xc_interface *xch, +uint32_t id, +uint32_t timeout); int xc_vcpu_setaffinity(xc_interface *xch, uint32_t domid,
tools/misc/Makefile +5 -3
@@ -10,7 +10,7 @@ HDRS = $(wildcard *.h) -TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool +TARGETS-y := xenperf xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool xenwatchdogd TARGETS-$(CONFIG_X86) += xen-detect xen-hvmctx TARGETS := $(TARGETS-y)
@@ -22,7 +22,7 @@ INSTALL_BIN-$(CONFIG_X86) += xen-detect INSTALL_BIN := $(INSTALL_BIN-y) -INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool +INSTALL_SBIN-y := xm xen-bugtool xen-python-path xend xenperf xsview xenpm xen-tmem-list-parse gtraceview gtracestat xenlockprof xen-hptool xenwatchdogd INSTALL_SBIN-$(CONFIG_X86) += xen-hvmctx INSTALL_SBIN := $(INSTALL_SBIN-y)
@@ -37,8 +37,10 @@ install: build $(INSTALL_DIR) $(DESTDIR)$(BINDIR) $(INSTALL_DIR) $(DESTDIR)$(SBINDIR) + $(INSTALL_DIR) $(DESTDIR)$(CONFIG_DIR)/init.d $(INSTALL_PYTHON_PROG) $(INSTALL_BIN) $(DESTDIR)$(BINDIR) $(INSTALL_PYTHON_PROG) $(INSTALL_SBIN) $(DESTDIR)$(SBINDIR) + $(INSTALL_PROG) xen-watchdog $(DESTDIR)$(CONFIG_DIR)/init.d set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d install-recurse; done .PHONY: clean
@@ -49,7 +51,7 @@ %.o: %.c $(HDRS) Makefile $(CC) -c $(CFLAGS) -o $@ $< -xen-hvmctx xenperf xenpm gtracestat xenlockprof xen-hptool: %: %.o Makefile +xen-hvmctx xenperf xenpm gtracestat xenlockprof xen-hptool xenwatchdogd: %: %.o Makefile $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) gtraceview: %: %.o Makefile
tools/misc/xen-watchdog new file +59 -0
59 lines not on this page · raw message
tools/misc/xenwatchdogd.c new file +96 -0
96 lines not on this page · raw message
xen/common/domain.c +3 -0
@@ -229,6 +229,7 @@spin_lock_init_prof (d, domain_lock);spin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->shutdown_lock); +spin_lock_init (&d->watchdog_lock);spin_lock_init (&d->hypercall_deadlock_mutex);INIT_PAGE_LIST_HEAD (&d->page_list);INIT_PAGE_LIST_HEAD (&d->xenpage_list);
@@ -608,6 +609,8 @@grant_table_destroy (d);arch_domain_destroy (d); + +watchdog_domain_destroy (d);rangeset_domain_destroy (d);
xen/common/keyhandler.c +7 -0
@@ -241,6 +241,7 @@for_each_domain ( d ) { +unsigned int i;printk ("General information for domain %u:\n" , d->domain_id);cpuset_print (tmpstr,sizeof (tmpstr), d->domain_dirty_cpumask); printk(" refcnt=%d dying=%d nr_pages=%d xenheap_pages=%d "
@@ -254,6 +255,12 @@ d->handle[8 ], d->handle[9 ], d->handle[10 ], d->handle[11 ], d->handle[12 ], d->handle[13 ], d->handle[14 ], d->handle[15 ], d->vm_assist); +for (i =0 ; i <NR_WATCHDOG_TIMERS ; i++) + { +if (active_timer (&d->watchdog_timer[i]) ) +printk (" watchdog %d expires in %d seconds\n" , + i, (u32)((d->watchdog_timer[i].expires -NOW ()) >>30 )); + }arch_dump_domain_info (d);
xen/common/schedule.c +65 -0
77 lines not on this page · raw message
xen/common/shutdown.c +10 -0
@@ -5,6 +5,7 @@#include <xen/domain.h> #include <xen/delay.h> #include <xen/shutdown.h> +#include <xen/console.h> #include <asm/debugger.h> #include <public/sched.h>
@@ -53,6 +54,15 @@break ;/* not reached */ } +case SHUTDOWN_watchdog: + { +console_force_unlock (); +printk ("Domain 0 shutdown: watchdog rebooting machine.\n" ); +kexec_crash (); +machine_restart (0 ); +break ;/* not reached */ + } +default : {printk ("Domain 0 shutdown (unknown reason %u): " , reason);
xen/include/public/sched.h +17 -0
@@ -106,6 +106,22 @@#define SCHEDOP_shutdown_code 5/* +* Setup, poke and destroy a domain watchdog timer. +* @arg == pointer to sched_watchdog structure. +* With id == 0, setup a domain watchdog timer to cause domain shutdown +* after timeout, returns watchdog id. +* With id != 0 and timeout == 0, destroy domain watchdog timer. +* With id != 0 and timeout != 0, poke watchdog timer and set new timeout. +*/ +#define SCHEDOP_watchdog 6 +struct sched_watchdog { +uint32_t id;/* watchdog ID */ +uint32_t timeout;/* timeout */ +}; +typedef struct sched_watchdog sched_watchdog_t ; +DEFINE_XEN_GUEST_HANDLE (sched_watchdog_t); + +/* * Reason codes for SCHEDOP_shutdown. These may be interpreted by control * software to determine the appropriate action. For the most part, Xen does * not care about the shutdown code.
@@ -114,6 +130,7 @@#define SHUTDOWN_reboot 1/* Clean up, kill, and then restart. */ #define SHUTDOWN_suspend 2/* Clean up, save suspend info, kill. */ #define SHUTDOWN_crash 3/* Tell controller we've crashed. */ +#define SHUTDOWN_watchdog 4/* Restart because watchdog time expired. */ #endif /* __XEN_PUBLIC_SCHED_H__ */
xen/include/xen/sched.h +10 -1
@@ -193,7 +193,10 @@/* tasklet */ struct tasklet tasklet; }; - + +/* Number of supported watchdog timers per domain */ +#define NR_WATCHDOG_TIMERS 2 +struct domain {domid_t domain_id;
@@ -297,6 +300,10 @@/* OProfile support. */ struct xenoprof *xenoprof;int32_t time_offset_seconds; + +/* Domain watchdog. */ +spinlock_t watchdog_lock; +struct timer watchdog_timer[NR_WATCHDOG_TIMERS ];struct rcu_head rcu;
@@ -601,6 +608,8 @@ cpu_online(cpu) && \ !per_cpu(tasklet_work_to_do, cpu)) +void watchdog_domain_destroy (struct domain *d); +#define IS_PRIV (_d) ((_d)->is_privileged)#define IS_PRIV_FOR (_d, _t) (IS_PRIV(_d) || ((_d)->target && (_d)->target == (_t)))
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Why multiple watchdogs per domain? In fact, precisely two? I would have thought one would be plenty.
-- Keir
Quoted 7 lines · Tim Deegan
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed.
Patch from Christian Limpach <[email protected]>
Signed-off-by Tim Deegan <[email protected]>
Quoted 2 lines · Keir Fraser
Why multiple watchdogs per domain? In fact, precisely two? I would have thought one would be plenty.
Two are used by one of the high-availability addons for XenServer. I don't know why exactly; possibly one is used by xapi and one by third-party code.
I could rework it to make it indefinitely extensible but TBH I figured two watchdog timers should be enough for anyone[tm].
Cheers,
Tim.
Quoted 11 lines · Tim Deegan
Quoted 8 lines
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed.
Patch from Christian Limpach <[email protected]>
Signed-off-by Tim Deegan <[email protected]>
Signature · 3 lines
Tim Deegan <[email protected]> Principal Software Engineer, XenServer Engineering Citrix Systems UK Ltd. (Company #02937203, SL9 0BG)
Quoted 2 lines · Tim Deegan
Each domain is allowed to set, reset and disable its timers; when any timer runs out the domain is killed.
Fixed up for xen-unstable tip and applied as c/s 21529. In future it would be a good idea to submit interface-changing patches early, or at least reserve command numbers. If someone else had taken the SCHEDOP numbers for shutdown_code and watchdog, you'd be in a spot.
-- Keir
Quoted 4 lines
Patch from Christian Limpach <[email protected]>
Signed-off-by Tim Deegan <[email protected]>