CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Sun Aug 28 22:34:26 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: clock.c evtchn.c Log Message: Put some assertions to check values of the VIRQ event channels mappings. Fix the VIRQ_TIMER per-cpu translations, so that save/restore does not choke on event channel being -1 anymore (ends badly 99,9% of the time when used as an index...) Some KNF and white space fixes. To generate a diff of this commit: cvs rdiff -u -r1.49.2.6 -r1.49.2.7 src/sys/arch/xen/xen/clock.c cvs rdiff -u -r1.42.2.8 -r1.42.2.9 src/sys/arch/xen/xen/evtchn.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/clock.c diff -u src/sys/arch/xen/xen/clock.c:1.49.2.6 src/sys/arch/xen/xen/clock.c:1.49.2.7 --- src/sys/arch/xen/xen/clock.c:1.49.2.6 Sat Aug 27 15:37:32 2011 +++ src/sys/arch/xen/xen/clock.c Sun Aug 28 22:34:25 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: clock.c,v 1.49.2.6 2011/08/27 15:37:32 jym Exp $ */ +/* $NetBSD: clock.c,v 1.49.2.7 2011/08/28 22:34:25 jym Exp $ */ /* * @@ -29,7 +29,7 @@ #include opt_xen.h #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.49.2.6 2011/08/27 15:37:32 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.49.2.7 2011/08/28 22:34:25 jym Exp $); #include sys/param.h #include sys/systm.h @@ -433,11 +433,13 @@ } void -xen_suspendclocks(void) { - +xen_suspendclocks(void) +{ int evtch; evtch = unbind_virq_from_evtch(VIRQ_TIMER); + KASSERT(evtch != -1); + hypervisor_mask_event(evtch); event_remove_handler(evtch, (int (*)(void *))xen_timer_handler, NULL); @@ -445,11 +447,13 @@ } void -xen_resumeclocks(void) { - +xen_resumeclocks(void) +{ int evtch; - + evtch = bind_virq_to_evtch(VIRQ_TIMER); + KASSERT(evtch != -1); + event_set_handler(evtch, (int (*)(void *))xen_timer_handler, NULL, IPL_CLOCK, clock); hypervisor_enable_event(evtch); Index: src/sys/arch/xen/xen/evtchn.c diff -u src/sys/arch/xen/xen/evtchn.c:1.42.2.8 src/sys/arch/xen/xen/evtchn.c:1.42.2.9 --- src/sys/arch/xen/xen/evtchn.c:1.42.2.8 Sat Aug 27 15:37:32 2011 +++ src/sys/arch/xen/xen/evtchn.c Sun Aug 28 22:34:26 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: evtchn.c,v 1.42.2.8 2011/08/27 15:37:32 jym Exp $ */ +/* $NetBSD: evtchn.c,v 1.42.2.9 2011/08/28 22:34:26 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -54,7 +54,7 @@ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.42.2.8 2011/08/27 15:37:32 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.42.2.9 2011/08/28 22:34:26 jym Exp $); #include opt_xen.h #include isa.h @@ -197,7 +197,7 @@ } bool -events_suspend (void) +events_suspend(void) { int evtch; @@ -205,6 +205,9 @@ /* VIRQ_DEBUG is the last interrupt to remove */ evtch = unbind_virq_from_evtch(VIRQ_DEBUG); + + KASSERT(evtch != -1); + hypervisor_mask_event(evtch); /* Remove the non-NULL value set in events_init() */ evtsource[evtch] = NULL; @@ -277,7 +280,7 @@ evtch LONG_SHIFT, evtch LONG_MASK); - if (evtsource[evtch]-ev_cpu != ci) { + if (evtsource[evtch]-ev_cpu != ci) { /* facilitate spllower() on remote cpu */ struct cpu_info *rci = evtsource[evtch]-ev_cpu; if (xen_send_ipi(rci, XEN_IPI_KICK) != 0) { @@ -285,7 +288,7 @@ } } - /* leave masked */ + /* leave masked */ return 0; } ci-ci_ilevel = evtsource[evtch]-ev_maxlevel; @@ -381,7 +384,7 @@ evtch_bindcount[evtchn]++; mutex_spin_exit(evtchn_lock); - + return evtchn; } @@ -393,9 +396,9 @@ mutex_spin_enter(evtchn_lock); - /* - * XXX: The only per-cpu VIRQ we currently use is VIRQ_TIMER. - * Please re-visit this implementation when others are used. + /* + * XXX: The only per-cpu VIRQ we currently use is VIRQ_TIMER. + * Please re-visit this implementation when others are used. * Note: VIRQ_DEBUG is special-cased, and not used or bound on APs. * XXX: event-virq/ipi can be unified in a linked-list * implementation. @@ -407,12 +410,14 @@ return -1; } + /* Get event channel from VIRQ */ if (virq == VIRQ_TIMER) { evtchn = virq_timer_to_evtch[ci-ci_cpuid]; - } - else { + } else { evtchn = virq_to_evtch[virq]; } + + /* Allocate a channel if there is none already allocated */ if (evtchn == -1) { op.cmd = EVTCHNOP_bind_virq; op.u.bind_virq.virq = virq; @@ -420,14 +425,20 @@ if (HYPERVISOR_event_channel_op(op) != 0) panic(Failed to bind virtual IRQ %d\n, virq); evtchn = op.u.bind_virq.port; + } + /* Set event channel */ + if (virq == VIRQ_TIMER) { + virq_timer_to_evtch[ci-ci_cpuid] = evtchn; + } else { virq_to_evtch[virq] = evtchn; } + /* Increase ref counter */ evtch_bindcount[evtchn]++; mutex_spin_exit(evtchn_lock); - + return evtchn; } @@ -498,7 +509,7 @@ evtch_bindcount[evtchn]++; mutex_spin_exit(evtchn_lock); - + return evtchn; } @@ -658,13
CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Wed Aug 24 21:37:05 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: xen_machdep.c Log Message: Now that Xen sysctl(7) moved under machdep, create a machdep.xen.suspend node to command suspension. To generate a diff of this commit: cvs rdiff -u -r1.4.12.8 -r1.4.12.9 src/sys/arch/xen/xen/xen_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xen_machdep.c diff -u src/sys/arch/xen/xen/xen_machdep.c:1.4.12.8 src/sys/arch/xen/xen/xen_machdep.c:1.4.12.9 --- src/sys/arch/xen/xen/xen_machdep.c:1.4.12.8 Thu May 26 22:32:39 2011 +++ src/sys/arch/xen/xen/xen_machdep.c Wed Aug 24 21:37:05 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_machdep.c,v 1.4.12.8 2011/05/26 22:32:39 jym Exp $ */ +/* $NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -53,7 +53,7 @@ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: xen_machdep.c,v 1.4.12.8 2011/05/26 22:32:39 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: xen_machdep.c,v 1.4.12.9 2011/08/24 21:37:05 jym Exp $); #include opt_xen.h @@ -218,29 +218,39 @@ } /* - * this function sets up the machdep.sleep_state sysctl equivalent - * for guest domains with no ACPI support - * This sysctl mimics the ACPI one, except it should be used only for - * Xen's save/restore functionalities of guest domains + * this function sets up the machdep.xen.suspend sysctl(7) that + * controls domain suspend/save. */ void -sysctl_xen_sleepstate_setup(void) { - - int ret; +sysctl_xen_sleepstate_setup(void) +{ + const struct sysctlnode *node = NULL; /* - * dom0 implements sleep_state support through ACPI - * it should not call this function to register - * machdep.sleep_state sysctl + * dom0 implements sleep support through ACPI. It should not call this + * this function to register a suspend interface. */ KASSERT(!(xendomain_is_dom0())); - ret = sysctl_createv(NULL, 0, NULL, NULL, CTLFLAG_READWRITE, - CTLTYPE_INT, sleep_state, NULL, sysctl_xen_sleepstate, 0, - NULL, 0, CTL_MACHDEP, CTL_CREATE, CTL_EOL); - - if (ret) - aprint_error(sysctl_createv failed: %d\n, ret); + sysctl_createv(clog, 0, NULL, node, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, machdep, NULL, + NULL, 0, NULL, 0, + CTL_MACHDEP, CTL_EOL); + + sysctl_createv(clog, 0, node, node, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, xen, + SYSCTL_DESCR(Xen top level node), + NULL, 0, NULL, 0, + CTL_CREATE, CTL_EOL); + + sysctl_createv(clog, 0, node, node, + CTLFLAG_PERMANENT | CTLFLAG_READWRITE, + CTLTYPE_INT, suspend, + SYSCTL_DESCR(Suspend/save control of current Xen domain), + NULL, sysctl_xen_sleepstate, 0, NULL, 0, + CTL_CREATE, CTL_EOL); } static int
CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Thu May 26 22:30:32 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: if_xennet_xenbus.c xbd_xenbus.c Log Message: Split allocation and initialization of ring I/O for xbd(4) and xennet(4): - allocation belongs to _attach() - init to _resume(), so that it can be used by suspend/resume code too. To generate a diff of this commit: cvs rdiff -u -r1.33.2.10 -r1.33.2.11 src/sys/arch/xen/xen/if_xennet_xenbus.c cvs rdiff -u -r1.38.2.9 -r1.38.2.10 src/sys/arch/xen/xen/xbd_xenbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/if_xennet_xenbus.c diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.10 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.11 --- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.10 Sat May 7 17:42:09 2011 +++ src/sys/arch/xen/xen/if_xennet_xenbus.c Thu May 26 22:30:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: if_xennet_xenbus.c,v 1.33.2.10 2011/05/07 17:42:09 jym Exp $ */ +/* $NetBSD: if_xennet_xenbus.c,v 1.33.2.11 2011/05/26 22:30:31 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -85,7 +85,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.33.2.10 2011/05/07 17:42:09 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.33.2.11 2011/05/26 22:30:31 jym Exp $); #include opt_xen.h #include opt_nfs_boot.h @@ -375,9 +375,9 @@ /* alloc shared rings */ tx_ring = (void *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0, - UVM_KMF_WIRED | UVM_KMF_ZERO); + UVM_KMF_WIRED); rx_ring = (void *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0, - UVM_KMF_WIRED | UVM_KMF_ZERO); + UVM_KMF_WIRED); if (tx_ring == NULL || rx_ring == NULL) panic(%s: can't alloc rings, device_xname(self)); @@ -481,8 +481,12 @@ tx_ring = sc-sc_tx_ring.sring; rx_ring = sc-sc_rx_ring.sring; + /* Initialize rings */ + memset(tx_ring, 0, PAGE_SIZE); SHARED_RING_INIT(tx_ring); FRONT_RING_INIT(sc-sc_tx_ring, tx_ring, PAGE_SIZE); + + memset(rx_ring, 0, PAGE_SIZE); SHARED_RING_INIT(rx_ring); FRONT_RING_INIT(sc-sc_rx_ring, rx_ring, PAGE_SIZE); Index: src/sys/arch/xen/xen/xbd_xenbus.c diff -u src/sys/arch/xen/xen/xbd_xenbus.c:1.38.2.9 src/sys/arch/xen/xen/xbd_xenbus.c:1.38.2.10 --- src/sys/arch/xen/xen/xbd_xenbus.c:1.38.2.9 Mon May 2 22:49:59 2011 +++ src/sys/arch/xen/xen/xbd_xenbus.c Thu May 26 22:30:31 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: xbd_xenbus.c,v 1.38.2.9 2011/05/02 22:49:59 jym Exp $ */ +/* $NetBSD: xbd_xenbus.c,v 1.38.2.10 2011/05/26 22:30:31 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: xbd_xenbus.c,v 1.38.2.9 2011/05/02 22:49:59 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: xbd_xenbus.c,v 1.38.2.10 2011/05/26 22:30:31 jym Exp $); #include opt_xen.h #include rnd.h @@ -268,8 +268,7 @@ sc-sc_backend_status = BLKIF_STATE_DISCONNECTED; sc-sc_shutdown = BLKIF_SHUTDOWN_REMOTE; - ring = (void *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0, - UVM_KMF_ZERO | UVM_KMF_WIRED); + ring = (void *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED); if (ring == NULL) panic(%s: can't alloc ring, device_xname(self)); sc-sc_ring.sring = ring; @@ -372,8 +371,8 @@ s = splbio(); /* wait for requests to complete, then suspend device */ while (sc-sc_backend_status == BLKIF_STATE_CONNECTED - sc-sc_dksc.sc_dkdev.dk_stats-io_busy 0) - tsleep(xbd_xenbus_suspend, PRIBIO, xbdsuspend, hz/2); + sc-sc_dksc.sc_dkdev.dk_stats-io_busy 0) + tsleep(xbd_xenbus_suspend, PRIBIO, xbdsuspend, hz/2); hypervisor_mask_event(sc-sc_evtchn); sc-sc_backend_status = BLKIF_STATE_SUSPENDED; @@ -407,8 +406,10 @@ xengnt_revoke_access(sc-sc_ring_gntref); } sc-sc_ring_gntref = GRANT_INVALID_REF; - ring = sc-sc_ring.sring; + /* Initialize ring */ + ring = sc-sc_ring.sring; + memset(ring, 0, PAGE_SIZE); SHARED_RING_INIT(ring); FRONT_RING_INIT(sc-sc_ring, ring, PAGE_SIZE); @@ -698,9 +699,11 @@ done: xen_rmb(); sc-sc_ring.rsp_cons = i; + RING_FINAL_CHECK_FOR_RESPONSES(sc-sc_ring, more_to_do); if (more_to_do) goto again; + dk_iodone(sc-sc_di, sc-sc_dksc); if (sc-sc_xbdreq_wait) wakeup(sc-sc_xbdreq_wait);
CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Thu May 26 22:32:39 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: xen_machdep.c Log Message: balloon is now supported, update comment. To generate a diff of this commit: cvs rdiff -u -r1.4.12.7 -r1.4.12.8 src/sys/arch/xen/xen/xen_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/xen_machdep.c diff -u src/sys/arch/xen/xen/xen_machdep.c:1.4.12.7 src/sys/arch/xen/xen/xen_machdep.c:1.4.12.8 --- src/sys/arch/xen/xen/xen_machdep.c:1.4.12.7 Mon Jan 10 00:37:39 2011 +++ src/sys/arch/xen/xen/xen_machdep.c Thu May 26 22:32:39 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_machdep.c,v 1.4.12.7 2011/01/10 00:37:39 jym Exp $ */ +/* $NetBSD: xen_machdep.c,v 1.4.12.8 2011/05/26 22:32:39 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -53,7 +53,7 @@ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: xen_machdep.c,v 1.4.12.7 2011/01/10 00:37:39 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: xen_machdep.c,v 1.4.12.8 2011/05/26 22:32:39 jym Exp $); #include opt_xen.h @@ -321,8 +321,8 @@ if (xen_start_info.nr_pages != physmem) { /* - * XXX JYM for now, we crash - fix it with balloon when - * supported + * XXX JYM for now, we crash - fix it with memory + * hotplug when supported */ DPRINTK((xen_start_info.nr_pages != physmem)); HYPERVISOR_crash();
CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Sat May 7 17:38:35 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: balloon.c Log Message: Implement pmf(9) suspend/resume routines for balloon(4). Trivial, heh. To generate a diff of this commit: cvs rdiff -u -r1.5.6.4 -r1.5.6.5 src/sys/arch/xen/xen/balloon.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/balloon.c diff -u src/sys/arch/xen/xen/balloon.c:1.5.6.4 src/sys/arch/xen/xen/balloon.c:1.5.6.5 --- src/sys/arch/xen/xen/balloon.c:1.5.6.4 Mon May 2 22:49:59 2011 +++ src/sys/arch/xen/xen/balloon.c Sat May 7 17:38:35 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: balloon.c,v 1.5.6.4 2011/05/02 22:49:59 jym Exp $ */ +/* $NetBSD: balloon.c,v 1.5.6.5 2011/05/07 17:38:35 jym Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ #define BALLOONDEBUG 0 #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.5.6.4 2011/05/02 22:49:59 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: balloon.c,v 1.5.6.5 2011/05/07 17:38:35 jym Exp $); #include sys/inttypes.h #include sys/device.h @@ -246,6 +246,9 @@ goto error; } + if (!pmf_device_register(self, NULL, NULL)) + aprint_error_dev(self, couldn't establish power handler\n); + return; error:
CVS commit: [jym-xensuspend] src/sys/arch/xen/xen
Module Name:src Committed By: jym Date: Sat May 7 17:42:09 UTC 2011 Modified Files: src/sys/arch/xen/xen [jym-xensuspend]: if_xennet_xenbus.c Log Message: When it successfully resume a device, return true instead of 0 aka false. To generate a diff of this commit: cvs rdiff -u -r1.33.2.9 -r1.33.2.10 src/sys/arch/xen/xen/if_xennet_xenbus.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/sys/arch/xen/xen/if_xennet_xenbus.c diff -u src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.9 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.10 --- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.33.2.9 Mon May 2 22:49:59 2011 +++ src/sys/arch/xen/xen/if_xennet_xenbus.c Sat May 7 17:42:09 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: if_xennet_xenbus.c,v 1.33.2.9 2011/05/02 22:49:59 jym Exp $ */ +/* $NetBSD: if_xennet_xenbus.c,v 1.33.2.10 2011/05/07 17:42:09 jym Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -85,7 +85,7 @@ */ #include sys/cdefs.h -__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.33.2.9 2011/05/02 22:49:59 jym Exp $); +__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.33.2.10 2011/05/07 17:42:09 jym Exp $); #include opt_xen.h #include opt_nfs_boot.h @@ -392,9 +392,8 @@ RND_TYPE_NET, 0); #endif - if (!pmf_device_register(self, - xennet_xenbus_suspend, - xennet_xenbus_resume)) + if (!pmf_device_register(self, xennet_xenbus_suspend, + xennet_xenbus_resume)) aprint_error_dev(self, couldn't establish power handler\n); else pmf_class_network_register(self, ifp); @@ -460,7 +459,7 @@ static bool xennet_xenbus_resume(device_t dev, const pmf_qual_t *qual) { - struct xennet_xenbus_softc *sc = p; + struct xennet_xenbus_softc *sc = device_private(dev); int error; netif_tx_sring_t *tx_ring; netif_rx_sring_t *rx_ring; @@ -503,7 +502,7 @@ event_set_handler(sc-sc_evtchn, xennet_handler, sc, IPL_NET, device_xname(dev)); - return 0; + return true; } static int