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 +669,13 @@
 			panic("can't allocate fixed interrupt source");
 
 		evts->ev_handlers = ih;
-		/* 
+		/*
 		 * XXX: We're assuming here that ci is the same cpu as
 		 * the one on which this event/port is bound on. The
 		 * api needs to be reshuffled so that this assumption
 		 * is more explicitly implemented.
 		 */
-		evts->ev_cpu = ci; 
+		evts->ev_cpu = ci;
 		mutex_init(&evtlock[evtch], MUTEX_DEFAULT, IPL_HIGH);
 		evtsource[evtch] = evts;
 		if (evname)

Reply via email to