Module Name:    src
Committed By:   cherry
Date:           Sun Sep 18 18:46:41 UTC 2011

Modified Files:
        src/sys/arch/xen/include [cherry-xenmp]: hypervisor.h intrdefs.h
        src/sys/arch/xen/x86 [cherry-xenmp]: hypervisor_machdep.c xen_ipi.c
        src/sys/arch/xen/xen [cherry-xenmp]: evtchn.c

Log Message:
Use an IPI to re-route events to the cpu where the handler has been registered


To generate a diff of this commit:
cvs rdiff -u -r1.31.10.2 -r1.31.10.3 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.9.34.2 -r1.9.34.3 src/sys/arch/xen/include/intrdefs.h
cvs rdiff -u -r1.14.2.4 -r1.14.2.5 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/sys/arch/xen/x86/xen_ipi.c
cvs rdiff -u -r1.47.6.4 -r1.47.6.5 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/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.31.10.2 src/sys/arch/xen/include/hypervisor.h:1.31.10.3
--- src/sys/arch/xen/include/hypervisor.h:1.31.10.2	Sat Aug 20 19:22:47 2011
+++ src/sys/arch/xen/include/hypervisor.h	Sun Sep 18 18:46:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.31.10.2 2011/08/20 19:22:47 cherry Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.31.10.3 2011/09/18 18:46:40 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -134,12 +134,12 @@
 void hypervisor_enable_event(unsigned int);
 
 /* hypervisor_machdep.c */
+void hypervisor_send_event(struct cpu_info *, unsigned int);
 void hypervisor_unmask_event(unsigned int);
 void hypervisor_mask_event(unsigned int);
 void hypervisor_clear_event(unsigned int);
 void hypervisor_enable_ipl(unsigned int);
-void hypervisor_set_ipending(struct cpu_info *, 
-			     uint32_t, int, int);
+void hypervisor_set_ipending(struct cpu_info *, uint32_t, int, int);
 void hypervisor_machdep_attach(void);
 
 /* 

Index: src/sys/arch/xen/include/intrdefs.h
diff -u src/sys/arch/xen/include/intrdefs.h:1.9.34.2 src/sys/arch/xen/include/intrdefs.h:1.9.34.3
--- src/sys/arch/xen/include/intrdefs.h:1.9.34.2	Fri Jun  3 13:27:40 2011
+++ src/sys/arch/xen/include/intrdefs.h	Sun Sep 18 18:46:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: intrdefs.h,v 1.9.34.2 2011/06/03 13:27:40 cherry Exp $ */
+/* $NetBSD: intrdefs.h,v 1.9.34.3 2011/09/18 18:46:40 cherry Exp $ */
 
 /* This file co-exists, and is included via machine/intrdefs.h */
 
@@ -11,7 +11,8 @@
 #define XEN_IPI_SYNCH_FPU	0x00000002
 #define XEN_IPI_DDB		0x00000004
 #define XEN_IPI_XCALL		0x00000008
+#define XEN_IPI_HVCB		0x00000010
 
-#define XEN_NIPIS 4 /* IPI_KICK doesn't have a handler */
+#define XEN_NIPIS 5 /* IPI_KICK doesn't have a handler */
 
 #endif /* _XEN_INTRDEFS_H_ */

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.4 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.5
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.4	Mon Aug 22 16:48:03 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Sun Sep 18 18:46:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.5 2011/09/18 18:46:40 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hypervisor_machdep.c,v 1.14.2.5 2011/09/18 18:46:40 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -281,6 +281,36 @@
 }
 
 void
+hypervisor_send_event(struct cpu_info *ci, unsigned int ev)
+{
+	KASSERT(ci != NULL);
+
+	volatile shared_info_t *s = HYPERVISOR_shared_info;
+	volatile struct vcpu_info *vci = ci->ci_vcpu;
+
+#ifdef PORT_DEBUG
+	if (ev == PORT_DEBUG)
+		printf("hypervisor_send_event %d\n", ev);
+#endif
+
+	xen_atomic_set_bit(&s->evtchn_pending[0], ev);
+	xen_atomic_set_bit(&vci->evtchn_pending_sel,
+			   ev >> LONG_SHIFT);
+
+	xen_atomic_set_bit(&vci->evtchn_upcall_pending, 0);
+
+	xen_atomic_clear_bit(&s->evtchn_mask[0], ev);
+
+	if (__predict_true(ci == curcpu())) {
+		hypervisor_force_callback();
+	} else {
+		if (xen_send_ipi(ci, XEN_IPI_HVCB)) {
+			panic("xen_send_ipi(cpu%d, XEN_IPI_HVCB) failed\n", (int) ci->ci_cpuid);
+		}
+	}
+}
+
+void
 hypervisor_unmask_event(unsigned int ev)
 {
 	volatile shared_info_t *s = HYPERVISOR_shared_info;

Index: src/sys/arch/xen/x86/xen_ipi.c
diff -u src/sys/arch/xen/x86/xen_ipi.c:1.1.2.3 src/sys/arch/xen/x86/xen_ipi.c:1.1.2.4
--- src/sys/arch/xen/x86/xen_ipi.c:1.1.2.3	Wed Aug 17 09:40:40 2011
+++ src/sys/arch/xen/x86/xen_ipi.c	Sun Sep 18 18:46:40 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $ */
+/* $NetBSD: xen_ipi.c,v 1.1.2.4 2011/09/18 18:46:40 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -33,10 +33,10 @@
 
 /* 
  * Based on: x86/ipi.c
- * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $"); 
+ * __KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.4 2011/09/18 18:46:40 cherry Exp $"); 
  */
 
-__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.3 2011/08/17 09:40:40 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xen_ipi.c,v 1.1.2.4 2011/09/18 18:46:40 cherry Exp $");
 
 #include <sys/types.h>
 
@@ -72,13 +72,15 @@
 static void xen_ipi_synch_fpu(struct cpu_info *, struct intrframe *);
 static void xen_ipi_ddb(struct cpu_info *, struct intrframe *);
 static void xen_ipi_xcall(struct cpu_info *, struct intrframe *);
+static void xen_ipi_hvcb(struct cpu_info *, struct intrframe *);
 
 static void (*ipifunc[XEN_NIPIS])(struct cpu_info *, struct intrframe *) =
 {	/* In order of priority (see: xen/include/intrdefs.h */
 	xen_ipi_halt,
 	xen_ipi_synch_fpu,
 	xen_ipi_ddb,
-	xen_ipi_xcall
+	xen_ipi_xcall,
+	xen_ipi_hvcb
 };
 
 static void
@@ -139,9 +141,9 @@
 static inline bool /* helper */
 valid_ipimask(uint32_t ipimask)
 {
-	uint32_t masks =  XEN_IPI_XCALL | XEN_IPI_DDB | 
-		XEN_IPI_SYNCH_FPU | XEN_IPI_HALT | 
-		XEN_IPI_KICK;
+	uint32_t masks =  XEN_IPI_HVCB | XEN_IPI_XCALL |
+		 XEN_IPI_DDB | XEN_IPI_SYNCH_FPU |
+		 XEN_IPI_HALT | XEN_IPI_KICK;
 
 	if (ipimask & ~masks) {
 		return false;
@@ -296,3 +298,16 @@
 		xen_broadcast_ipi(XEN_IPI_XCALL);
 	}
 }
+
+static void
+xen_ipi_hvcb(struct cpu_info *ci, struct intrframe *intrf)
+{
+	KASSERT(ci != NULL);
+	KASSERT(intrf != NULL);
+
+	volatile struct vcpu_info *vci = ci->ci_vcpu;
+
+	KASSERT(ci == curcpu());
+	KASSERT(!vci->evtchn_upcall_mask);
+	hypervisor_force_callback();
+}

Index: src/sys/arch/xen/xen/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.47.6.4 src/sys/arch/xen/xen/evtchn.c:1.47.6.5
--- src/sys/arch/xen/xen/evtchn.c:1.47.6.4	Wed Aug 17 09:40:40 2011
+++ src/sys/arch/xen/xen/evtchn.c	Sun Sep 18 18:46:40 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.47.6.4 2011/08/17 09:40:40 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.47.6.5 2011/09/18 18:46:40 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -54,7 +54,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.47.6.4 2011/08/17 09:40:40 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: evtchn.c,v 1.47.6.5 2011/09/18 18:46:40 cherry Exp $");
 
 #include "opt_xen.h"
 #include "isa.h"
@@ -237,8 +237,13 @@
 	ci->ci_data.cpu_nintr++;
 	evtsource[evtch]->ev_evcnt.ev_count++;
 	ilevel = ci->ci_ilevel;
-	if (evtsource[evtch]->ev_maxlevel <= ilevel ||
-	    evtsource[evtch]->ev_cpu != ci /* XXX: get stats */) {
+
+	if (evtsource[evtch]->ev_cpu != ci /* XXX: get stats */) {
+		hypervisor_send_event(evtsource[evtch]->ev_cpu, evtch);
+		return 0;
+	}
+
+	if (evtsource[evtch]->ev_maxlevel <= ilevel) {
 #ifdef IRQ_DEBUG
 		if (evtch == IRQ_DEBUG)
 		    printf("evtsource[%d]->ev_maxlevel %d <= ilevel %d\n",
@@ -249,14 +254,6 @@
 					evtch >> LONG_SHIFT,
 					evtch & LONG_MASK);
 
-		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) {
-				panic("xen_send_ipi(%s, XEN_IPI_KICK) failed\n", cpu_name(rci));
-			}
-		}
-
 		/* leave masked */				     
 		return 0;
 	}

Reply via email to