CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-10-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Oct 22 19:26:16 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
Various clock fixes:
- xen_get_timecount() is CPU specific, so get the time from this
  virtual CPU and not VCPU0. Also keep xen_clock_bias per-cpu.
- The periodic timer looks buggy, we stop receiving events after a (short)
  while. Linux is using the one-shoot timer so use it too (and disable
  the periodic timer), but rearm it from the event handler, not idle_block()
  as the later may not be called if the CPU is busy, resulting it clock
  event loss.
- use  HYPERVISOR_block() in idle_block() again, now that interrupts are
  working properly.


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.4 -r1.54.6.5 src/sys/arch/xen/xen/clock.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.54.6.4 src/sys/arch/xen/xen/clock.c:1.54.6.5
--- src/sys/arch/xen/xen/clock.c:1.54.6.4	Sun Sep 18 18:54:32 2011
+++ src/sys/arch/xen/xen/clock.c	Sat Oct 22 19:26:16 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.4 2011/09/18 18:54:32 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.5 2011/10/22 19:26:16 bouyer Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.4 2011/09/18 18:54:32 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.5 2011/10/22 19:26:16 bouyer Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -94,7 +94,7 @@ static volatile uint64_t vcpu_system_tim
  * back to maintain the illusion that hardclock(9) was called when it
  * was supposed to be, not when Xen got around to scheduling us.
  */
-static volatile uint64_t xen_clock_bias;
+static volatile uint64_t xen_clock_bias[MAXCPUS];
 
 #ifdef DOM0OPS
 /* If we're dom0, send our time to Xen every minute or so. */
@@ -416,9 +416,10 @@ u_int
 xen_get_timecount(struct timecounter *tc)
 {
 	uint64_t ns;
+	struct cpu_info *ci = curcpu();
 
 	mutex_enter(tmutex);
-	ns = get_system_time() - xen_clock_bias;
+	ns = get_vcpu_time(ci) - xen_clock_bias[ci-ci_cpuid];
 	mutex_exit(tmutex);
 
 	return (u_int)ns;
@@ -439,12 +440,10 @@ xen_initclocks(void)
 	int err, evtch;
 	static bool tcdone = false;
 
-	struct vcpu_set_periodic_timer hardclock_period = { NS_PER_TICK };
-
 	struct cpu_info *ci = curcpu();
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
-	xen_clock_bias = 0;
+	xen_clock_bias[ci-ci_cpuid] = 0;
 
 	evcnt_attach_dynamic(hardclock_called[ci-ci_cpuid],
 			 EVCNT_TYPE_INTR,
@@ -468,12 +467,19 @@ xen_initclocks(void)
 	}
 	/* The splhigh requirements start here. */
 
-	/* Set hardclock() frequency */
-	err = HYPERVISOR_vcpu_op(VCPUOP_set_periodic_timer,
+	/*
+	 * The periodic timer looks buggy, we stop receiving events
+	 * after a while. Use the one-shot timer every NS_PER_TICK
+	 * and rearm it from the event handler.
+	 */
+	err = HYPERVISOR_vcpu_op(VCPUOP_stop_periodic_timer,
  ci-ci_cpuid,
- hardclock_period);
+ NULL);
 
 	KASSERT(err == 0);
+	err = HYPERVISOR_set_timer_op(
+	vcpu_system_time[ci-ci_cpuid] + NS_PER_TICK);
+	KASSERT(err == 0);
 
 	event_set_handler(evtch, (int (*)(void *))xen_timer_handler,
 	ci, IPL_CLOCK, clock);
@@ -504,25 +510,34 @@ xen_timer_handler(void *arg, struct intr
 	int64_t delta;
 	struct cpu_info *ci = curcpu();
 	KASSERT(arg == ci);
+	int err;
+again:
 	mutex_enter(tmutex);
-
 	delta = (int64_t)(get_vcpu_time(ci) - vcpu_system_time[ci-ci_cpuid]);
-
 	mutex_exit(tmutex);
 
 	/* Several ticks may have passed without our being run; catch up. */
 	while (delta = (int64_t)NS_PER_TICK) {
 		mutex_enter(tmutex);
 		vcpu_system_time[ci-ci_cpuid] += NS_PER_TICK;
-		xen_clock_bias = (delta -= NS_PER_TICK);
+		xen_clock_bias[ci-ci_cpuid] = (delta -= NS_PER_TICK);
 		mutex_exit(tmutex);
 		hardclock((struct clockframe *)regs);
 		hardclock_called[ci-ci_cpuid].ev_count++;
 	}
+
+	/*
+	 * rearm the timer. If it fails it's probably because the date
+	 * is in the past, update our local time and try again.
+	 */
+	err = HYPERVISOR_set_timer_op(
+	vcpu_system_time[ci-ci_cpuid] + NS_PER_TICK);
+	if (err)
+		goto again;
 	
-	if (xen_clock_bias) {
+	if (xen_clock_bias[ci-ci_cpuid]) {
 		mutex_enter(tmutex);
-		xen_clock_bias = 0;
+		xen_clock_bias[ci-ci_cpuid] = 0;
 		mutex_exit(tmutex);
 	}
 
@@ -537,6 +552,18 @@ setstatclockrate(int arg)
 void
 idle_block(void)
 {
+#ifdef MULTIPROCESSOR
 	HYPERVISOR_yield();
 	__sti();
+#else
+	struct cpu_info *ci = curcpu();
+	int r;
+
+	r = HYPERVISOR_set_timer_op(
+	vcpu_system_time[ci-ci_cpuid] + NS_PER_TICK);
+	if (r == 0)
+		HYPERVISOR_block();
+	else
+		__sti();
+#endif
 }



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-10-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Oct 22 21:16:59 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
Really use HYPERVISOR_block()


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.5 -r1.54.6.6 src/sys/arch/xen/xen/clock.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.54.6.5 src/sys/arch/xen/xen/clock.c:1.54.6.6
--- src/sys/arch/xen/xen/clock.c:1.54.6.5	Sat Oct 22 19:26:16 2011
+++ src/sys/arch/xen/xen/clock.c	Sat Oct 22 21:16:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.5 2011/10/22 19:26:16 bouyer Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.6 2011/10/22 21:16:59 bouyer Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.5 2011/10/22 19:26:16 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.6 2011/10/22 21:16:59 bouyer Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -552,18 +552,6 @@ setstatclockrate(int arg)
 void
 idle_block(void)
 {
-#ifdef MULTIPROCESSOR
-	HYPERVISOR_yield();
-	__sti();
-#else
-	struct cpu_info *ci = curcpu();
-	int r;
-
-	r = HYPERVISOR_set_timer_op(
-	vcpu_system_time[ci-ci_cpuid] + NS_PER_TICK);
-	if (r == 0)
-		HYPERVISOR_block();
-	else
-		__sti();
-#endif
+	KASSERT(curcpu()-ci_ipending == 0);
+	HYPERVISOR_block();
 }



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-10-22 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Sat Oct 22 22:42:21 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
More improvements:
- Precise what tmutex protects
- springle some KASSERT(mutex_owned(tmutex))
- the system time uses the CPU timecounter to get some precision;
  don't mix local CPU timecounter with VCPU0's time, it won't work well.
  Always use curcpu()'s time.


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.6 -r1.54.6.7 src/sys/arch/xen/xen/clock.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.54.6.6 src/sys/arch/xen/xen/clock.c:1.54.6.7
--- src/sys/arch/xen/xen/clock.c:1.54.6.6	Sat Oct 22 21:16:59 2011
+++ src/sys/arch/xen/xen/clock.c	Sat Oct 22 22:42:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.6 2011/10/22 21:16:59 bouyer Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.7 2011/10/22 22:42:20 bouyer Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.6 2011/10/22 21:16:59 bouyer Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.7 2011/10/22 22:42:20 bouyer Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -79,11 +79,12 @@ struct shadow {
 	struct timespec ts;
 };
 
+/* Protects volatile variables ci_shadow  xen_clock_bias */
+static kmutex_t tmutex;
+
 /* Per CPU shadow time values */
 static volatile struct shadow ci_shadow[MAXCPUS];
 
-static kmutex_t tmutex; /* Protects volatile variables, below */
-
 /* The time when the last hardclock(9) call should have taken place,
  * per cpu.
  */
@@ -116,6 +117,7 @@ get_time_values_from_xen(struct cpu_info
 	volatile struct vcpu_time_info *t = ci-ci_vcpu-time;
 	uint32_t tversion;
 
+	KASSERT(mutex_owned(tmutex));
 	do {
 		shadow-time_version = t-version;
 		xen_rmb();
@@ -142,9 +144,11 @@ static inline int
 time_values_up_to_date(struct cpu_info *ci)
 {
 	int rv;
+	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
+
 	KASSERT(ci != NULL);
+	KASSERT(mutex_owned(tmutex));
 
-	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
 	xen_rmb();
 	rv = shadow-time_version == ci-ci_vcpu-time.version;
@@ -187,6 +191,7 @@ get_tsc_offset_ns(struct cpu_info *ci)
 	uint64_t tsc_delta, offset;
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
+	KASSERT(mutex_owned(tmutex));
 	tsc_delta = cpu_counter() - shadow-tsc_stamp;
 	offset = scale_delta(tsc_delta, shadow-freq_mul,
 	shadow-freq_shift);
@@ -212,53 +217,36 @@ get_vcpu_time(struct cpu_info *ci)
 	uint64_t offset, stime;
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 	
-	for (;;) {
+	KASSERT(mutex_owned(tmutex));
+	do {
+		get_time_values_from_xen(ci);
 		offset = get_tsc_offset_ns(ci);
 		stime = shadow-system_time + offset;
 		
 		/* if the timestamp went stale before we used it, refresh */
-		if (time_values_up_to_date(ci)) {
-			/*
-			 * Work around an intermittent Xen2 bug where, for
-			 * a period of 132 ns, currently running domains
-			 * don't get their timer events as usual (and also
-			 * aren't preempted in favor of other runnable
-			 * domains).  Setting the timer into the past in
-			 * this way causes it to fire immediately.
-			 */
-			break;
-		}
-		get_time_values_from_xen(ci);
-	}
+	} while (!time_values_up_to_date(ci));
 
 	return stime;
 }
 
-/*
- * SMP note: system time always derives from Boot Processor.
- * Must be called at splhigh. See comment above on get_vcpu_time()
- */
-static uint64_t
-get_system_time(void)
-{
-	return get_vcpu_time(cpu_info_primary);
-
-}
-
 static void
 xen_wall_time(struct timespec *wt)
 {
 	uint64_t nsec;
-	struct cpu_info *ci = cpu_info_primary;
+	struct cpu_info *ci = curcpu();
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
 	mutex_enter(tmutex);
-	get_time_values_from_xen(ci);
-	*wt = shadow-ts;
-	nsec = wt-tv_nsec;
+	do {
+		/*
+		 * Under Xen3, shadow-ts is the wall time less system time
+		 * get_vcpu_time() will update shadow
+		 */
+		nsec = get_vcpu_time(curcpu());
+		*wt = shadow-ts;
+		nsec += wt-tv_nsec;
 
-	/* Under Xen3, this is the wall time less system time */
-	nsec += get_system_time();
+	} while (!time_values_up_to_date(ci));
 	mutex_exit(tmutex);
 	wt-tv_sec += nsec / 10L;
 	wt-tv_nsec = nsec % 10L;
@@ -300,7 +288,7 @@ xen_rtc_set(todr_chip_handle_t todr, str
 		op.u.settime.secs	 = tvp-tv_sec;
 		op.u.settime.nsecs	 = tvp-tv_usec * 1000;
 		mutex_enter(tmutex);
-		op.u.settime.system_time = get_system_time();
+		op.u.settime.system_time = get_vcpu_time(curcpu());
 		mutex_exit(tmutex);
 #if __XEN_INTERFACE_VERSION__  0x00030204
 		return HYPERVISOR_dom0_op(op);
@@ -363,6 +351,7 @@ xen_delay(unsigned int n)
 		when = shadow-system_time + n * 1000;
 		while (shadow-system_time  when) {
 			mutex_exit(tmutex);
+			HYPERVISOR_yield();
 			mutex_enter(tmutex);
 

CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-09-18 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 18 16:48:23 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: x86_xpmap.c

Log Message:
Make the xpq locking per-cpu


To generate a diff of this commit:
cvs rdiff -u -r1.26.2.9 -r1.26.2.10 src/sys/arch/xen/x86/x86_xpmap.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/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.10
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9	Fri Sep  9 11:53:43 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Sun Sep 18 16:48:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2.9 2011/09/09 11:53:43 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.26.2.10 2011/09/18 16:48:23 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.26.2.9 2011/09/09 11:53:43 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.26.2.10 2011/09/18 16:48:23 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -168,26 +168,26 @@
 static int xpq_idx_array[MAXCPUS];
 
 #ifdef MULTIPROCESSOR
-static struct simplelock xpq_lock = SIMPLELOCK_INITIALIZER;
+static struct simplelock xpq_lock[MAXCPUS];
 
 extern struct cpu_info * (*xpq_cpu)(void);
 
 void
 xpq_queue_lock(void)
 {
-	simple_lock(xpq_lock);
+	simple_lock(xpq_lock[xpq_cpu()-ci_cpuid]);
 }
 
 void
 xpq_queue_unlock(void)
 {
-	simple_unlock(xpq_lock);
+	simple_unlock(xpq_lock[xpq_cpu()-ci_cpuid]);
 }
 
 bool
 xpq_queue_locked(void)
 {
-	return simple_lock_held(xpq_lock);
+	return simple_lock_held(xpq_lock[xpq_cpu()-ci_cpuid]);
 }
 #endif /* MULTIPROCESSOR */
 
@@ -589,12 +589,15 @@
 vaddr_t
 xen_pmap_bootstrap(void)
 {
-	int count, oldcount;
+	int count, oldcount, i;
 	long mapsize;
 	vaddr_t bootstrap_tables, init_tables;
 
 	memset(xpq_idx_array, 0, sizeof xpq_idx_array);
-	
+	for (i = 0; i  MAXCPUS;i++) {
+		simple_lock_init(xpq_lock[i]);
+	}
+
 	xpmap_phys_to_machine_mapping =
 	(unsigned long *)xen_start_info.mfn_list;
 	init_tables = xen_start_info.pt_base;



CVS commit: [cherry-xenmp] src/sys/arch/xen

2011-09-18 Thread Cherry G. Mathew
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	0x0002
 #define XEN_IPI_DDB		0x0004
 #define XEN_IPI_XCALL		0x0008
+#define XEN_IPI_HVCB		0x0010
 
-#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 

CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-09-18 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Sep 18 18:54:32 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
Register the clock handler at the appropriate ipl (IPL_CLOCK). Cleanup the 
idle_block()


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.3 -r1.54.6.4 src/sys/arch/xen/xen/clock.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.54.6.3 src/sys/arch/xen/xen/clock.c:1.54.6.4
--- src/sys/arch/xen/xen/clock.c:1.54.6.3	Tue Aug 23 16:19:12 2011
+++ src/sys/arch/xen/xen/clock.c	Sun Sep 18 18:54:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.3 2011/08/23 16:19:12 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.4 2011/09/18 18:54:32 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.3 2011/08/23 16:19:12 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.4 2011/09/18 18:54:32 cherry Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -463,7 +463,7 @@
 	get_time_values_from_xen(ci);
 	vcpu_system_time[ci-ci_cpuid] = shadow-system_time;
 	if (!tcdone) { /* Do this only once */
-		mutex_init(tmutex, MUTEX_DEFAULT, IPL_HIGH);
+		mutex_init(tmutex, MUTEX_DEFAULT, IPL_CLOCK);
 		tc_init(xen_timecounter);
 	}
 	/* The splhigh requirements start here. */
@@ -537,19 +537,6 @@
 void
 idle_block(void)
 {
-	int r;
-
-	/*
-	 * We set the timer to when we expect the next timer
-	 * interrupt.  We could set the timer to later if we could
-	 * easily find out when we will have more work (callouts) to
-	 * process from hardclock.
-	 */
-	r = 0; //HYPERVISOR_set_timer_op(vcpu_system_time[ci-ci_cpuid] + NS_PER_TICK);
-	if (r == 0) {
-		HYPERVISOR_yield();
-		__sti();
-	}
-	else
-		__sti();
+	HYPERVISOR_yield();
+	__sti();
 }



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-09-09 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Sep  9 11:53:43 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c x86_xpmap.c

Log Message:
fix amd64 boot.


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.10 -r1.56.2.11 src/sys/arch/xen/x86/cpu.c
cvs rdiff -u -r1.26.2.8 -r1.26.2.9 src/sys/arch/xen/x86/x86_xpmap.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/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.10 src/sys/arch/xen/x86/cpu.c:1.56.2.11
--- src/sys/arch/xen/x86/cpu.c:1.56.2.10	Thu Sep  1 08:04:46 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Sep  9 11:53:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.56.2.10 2011/09/01 08:04:46 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.56.2.11 2011/09/09 11:53:43 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.10 2011/09/01 08:04:46 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.11 2011/09/09 11:53:43 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -712,6 +712,7 @@
  * work. 
  */
 extern void x86_64_tls_switch(struct lwp *);
+
 void
 cpu_hatch(void *v)
 {
@@ -918,7 +919,8 @@
 	 * Use pmap_kernel() L4 PD directly, until we setup the
 	 * per-cpu L4 PD in pmap_cpu_init_late()
 	 */
-	initctx-ctrlreg[3] = xpmap_ptom(pcb-pcb_cr3);
+
+	initctx-ctrlreg[3] = xen_pfn_to_cr3(x86_btop(xpmap_ptom(ci-ci_kpm_pdirpa)));
 	initctx-ctrlreg[4] = CR4_PAE | CR4_OSFXSR | CR4_OSXMMEXCPT;
 
 
@@ -1281,7 +1283,7 @@
 	}
 
 	if (__predict_true(pmap != pmap_kernel())) {
-		xen_set_user_pgd(ci-ci_kpm_pdirpa);
+		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
 		ci-ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
 	}
 	else {
@@ -1299,6 +1301,27 @@
 
 /*
  * pmap_cpu_init_late: perform late per-CPU initialization.
+ * Short note about percpu PDIR pages:
+ * Both the PAE and __x86_64__ architectures have per-cpu PDIR
+ * tables. This is to get around Xen's pagetable setup constraints for
+ * PAE (multiple L3[3]s cannot point to the same L2 - Xen
+ * will refuse to pin a table setup this way.) and for multiple cpus
+ * to map in different user pmaps on __x86_64__ (see: cpu_load_pmap())
+ *
+ * What this means for us is that the PDIR of the pmap_kernel() is
+ * considered to be a canonical SHADOW PDIR with the following
+ * properties: 
+ * - Its recursive mapping points to itself
+ * - per-cpu recurseive mappings point to themselves
+ * - per-cpu L4 pages' kernel entries are expected to be in sync with
+ *   the shadow
+ * - APDP_PDE_SHADOW accesses the shadow pdir
+ * - APDP_PDE accesses the per-cpu pdir
+ * - alternate mappings are considered per-cpu - however, x86 pmap
+ *   currently partially consults the shadow - this works because the
+ *   shadow PDE is updated together with the per-cpu entry (see:
+ *   xen_pmap.c: pmap_map_ptes(), and the pmap is locked while the
+ * alternate ptes are mapped in.
  */
 
 void
@@ -1315,7 +1338,7 @@
 
 	KASSERT(ci != NULL);
 
-#ifdef PAE
+#if defined(PAE)
 	ci-ci_pae_l3_pdir = (paddr_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
 	UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
 
@@ -1344,26 +1367,32 @@
 	}
 	ci-ci_kpm_pdirpa = vtophys((vaddr_t) ci-ci_kpm_pdir);
 	KASSERT(ci-ci_kpm_pdirpa != 0);
+
+#if defined(__x86_64__)
 	/*
-	 * Copy over kernel pmd entries from boot
-	 * cpu. XXX:locking/races
+	 * Copy over the pmap_kernel() shadow L4 entries 
 	 */
 
-	memcpy(ci-ci_kpm_pdir,
-	pmap_kernel()-pm_pdir[PDIR_SLOT_KERN],
-	nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
+	memcpy(ci-ci_kpm_pdir, pmap_kernel()-pm_pdir, PAGE_SIZE);
+
+	/* Recursive kernel mapping */
+	ci-ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci-ci_kpm_pdirpa) | PG_k | PG_V;
+#elif defined(PAE)
+	/* Copy over the pmap_kernel() shadow L2 entries that map the kernel */
+	memcpy(ci-ci_kpm_pdir, pmap_kernel()-pm_pdir + PDIR_SLOT_KERN, nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
+#endif /* __x86_64__ else PAE */
 
 	/* Xen wants R/O */
 	pmap_kenter_pa((vaddr_t)ci-ci_kpm_pdir, ci-ci_kpm_pdirpa,
 	VM_PROT_READ, 0);
 
-#ifdef PAE
+#if defined(PAE)
 	/* Initialise L3 entry 3. This mapping is shared across all
 	 * pmaps and is static, ie; loading a new pmap will not update
 	 * this entry.
 	 */
 	
-	ci-ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci-ci_kpm_pdirpa) | PG_V;
+	ci-ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci-ci_kpm_pdirpa) | PG_k | PG_V;
 
 	/* Mark L3 R/O (Xen wants this) */
 	pmap_kenter_pa((vaddr_t)ci-ci_pae_l3_pdir, ci-ci_pae_l3_pdirpa,

Index: src/sys/arch/xen/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.8 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.9
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.8	Tue Aug 30 12:53:46 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Fri Sep  9 11:53:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2.8 2011/08/30 12:53:46 

CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-09-03 Thread Michael L. Hitch
Module Name:src
Committed By:   mhitch
Date:   Sun Sep  4 01:15:14 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: xengnt.c

Log Message:
Use a mutex to protect updates to gnt_entries.  Fixes a KASSERT panic
with an MP kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.18.2.1 -r1.18.2.2 src/sys/arch/xen/xen/xengnt.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/xengnt.c
diff -u src/sys/arch/xen/xen/xengnt.c:1.18.2.1 src/sys/arch/xen/xen/xengnt.c:1.18.2.2
--- src/sys/arch/xen/xen/xengnt.c:1.18.2.1	Thu Jun 23 14:19:50 2011
+++ src/sys/arch/xen/xen/xengnt.c	Sun Sep  4 01:15:13 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: xengnt.c,v 1.18.2.1 2011/06/23 14:19:50 cherry Exp $  */
+/*  $NetBSD: xengnt.c,v 1.18.2.2 2011/09/04 01:15:13 mhitch Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xengnt.c,v 1.18.2.1 2011/06/23 14:19:50 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xengnt.c,v 1.18.2.2 2011/09/04 01:15:13 mhitch Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -35,6 +35,7 @@
 #include sys/queue.h
 #include sys/extent.h
 #include sys/kernel.h
+#include sys/mutex.h
 #include uvm/uvm.h
 
 #include xen/hypervisor.h
@@ -62,6 +63,8 @@
 /* empty entry in the list */
 #define XENGNT_NO_ENTRY 0x
 
+static kmutex_t	gnt_mutex;
+
 /* VM address of the grant table */
 grant_entry_t *grant_table;
 
@@ -101,6 +104,7 @@
 		gnt_entries[i] = XENGNT_NO_ENTRY;
 
 	last_gnt_entry = 0;
+	mutex_init(gnt_mutex, MUTEX_DEFAULT, IPL_VM);
 	xengnt_resume();
 
 }
@@ -192,13 +196,13 @@
 xengnt_get_entry(void)
 {
 	grant_ref_t entry;
-	int s = splvm();
 	static struct timeval xengnt_nonmemtime;
 	static const struct timeval xengnt_nonmemintvl = {5,0};
 
+	mutex_enter(gnt_mutex);
 	if (last_gnt_entry == 0) {
 		if (xengnt_more_entries()) {
-			splx(s);
+			mutex_exit(gnt_mutex);
 			if (ratecheck(xengnt_nonmemtime, xengnt_nonmemintvl))
 printf(xengnt_get_entry: out of grant 
 table entries\n);
@@ -209,7 +213,7 @@
 	last_gnt_entry--;
 	entry = gnt_entries[last_gnt_entry];
 	gnt_entries[last_gnt_entry] = XENGNT_NO_ENTRY;
-	splx(s);
+	mutex_exit(gnt_mutex);
 	KASSERT(entry != XENGNT_NO_ENTRY);
 	KASSERT(last_gnt_entry = 0);
 	KASSERT(last_gnt_entry = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
@@ -222,13 +226,13 @@
 static void
 xengnt_free_entry(grant_ref_t entry)
 {
-	int s = splvm();
+	mutex_enter(gnt_mutex);
 	KASSERT(gnt_entries[last_gnt_entry] == XENGNT_NO_ENTRY);
 	KASSERT(last_gnt_entry = 0);
 	KASSERT(last_gnt_entry = gnt_max_grant_frames * NR_GRANT_ENTRIES_PER_PAGE);
 	gnt_entries[last_gnt_entry] = entry;
 	last_gnt_entry++;
-	splx(s);
+	mutex_exit(gnt_mutex);
 }
 
 int



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Aug 26 13:33:34 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: cpu.c

Log Message:
Name the L4 per-cpu pointer appropriately.
User cr3 should point to the per-cpu L4, not the user pmap pdir


To generate a diff of this commit:
cvs rdiff -u -r1.56.2.7 -r1.56.2.8 src/sys/arch/xen/x86/cpu.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/x86/cpu.c
diff -u src/sys/arch/xen/x86/cpu.c:1.56.2.7 src/sys/arch/xen/x86/cpu.c:1.56.2.8
--- src/sys/arch/xen/x86/cpu.c:1.56.2.7	Sat Aug 20 19:22:47 2011
+++ src/sys/arch/xen/x86/cpu.c	Fri Aug 26 13:33:34 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.c,v 1.56.2.7 2011/08/20 19:22:47 cherry Exp $	*/
+/*	$NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $	*/
 /* NetBSD: cpu.c,v 1.18 2004/02/20 17:35:01 yamt Exp  */
 
 /*-
@@ -66,7 +66,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.7 2011/08/20 19:22:47 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: cpu.c,v 1.56.2.8 2011/08/26 13:33:34 cherry Exp $);
 
 #include opt_ddb.h
 #include opt_multiprocessor.h
@@ -1253,10 +1253,10 @@
 	int i, s;
 	pd_entry_t *new_pgd;
 	struct cpu_info *ci;
-	paddr_t l3_shadow_pa;
+	paddr_t l4_pd_ma;
 
 	ci = curcpu();
-	l3_shadow_pa = xpmap_ptom_masked(ci-ci_kpm_pdirpa);
+	l4_pd_ma = xpmap_ptom_masked(ci-ci_kpm_pdirpa);
 
 	/*
 	 * Map user space address in kernel space and load
@@ -1269,15 +1269,15 @@
 
 	/* Copy user pmap L4 PDEs (in user addr. range) to per-cpu L4 */
 	for (i = 0; i  PDIR_SLOT_PTE; i++) {
-		xpq_queue_pte_update(l3_shadow_pa + i * sizeof(pd_entry_t), new_pgd[i]);
+		xpq_queue_pte_update(l4_pd_ma + i * sizeof(pd_entry_t), new_pgd[i]);
 	}
 
 	if (__predict_true(pmap != pmap_kernel())) {
-		xen_set_user_pgd(pmap_pdirpa(pmap, 0));
+		xen_set_user_pgd(ci-ci_kpm_pdirpa);
 		ci-ci_xen_current_user_pgd = pmap_pdirpa(pmap, 0);
 	}
 	else {
-		xpq_queue_pt_switch(l3_shadow_pa);
+		xpq_queue_pt_switch(l4_pd_ma);
 		ci-ci_xen_current_user_pgd = 0;
 	}
 	xpq_queue_unlock();



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-08-23 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Tue Aug 23 16:19:12 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
MP-fy clock. per-cpu hardclock(). Use the periodic timer, instead of the 
one-shot reload.

idle_loop() does not block the domain anymore. Instead, it yields to the 
hypervisor(). We can thus remove the one-shot wakeup timer.


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.2 -r1.54.6.3 src/sys/arch/xen/xen/clock.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.54.6.2 src/sys/arch/xen/xen/clock.c:1.54.6.3
--- src/sys/arch/xen/xen/clock.c:1.54.6.2	Mon Jul 25 17:29:43 2011
+++ src/sys/arch/xen/xen/clock.c	Tue Aug 23 16:19:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.3 2011/08/23 16:19:12 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.3 2011/08/23 16:19:12 cherry Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -38,12 +38,14 @@
 #include sys/timetc.h
 #include sys/timevar.h
 #include sys/kernel.h
+#include sys/mutex.h
 #include sys/device.h
 #include sys/sysctl.h
 
 #include xen/xen.h
 #include xen/hypervisor.h
 #include xen/evtchn.h
+#include xen/xen3-public/vcpu.h
 #include machine/cpu_counter.h
 
 #include dev/clock_subr.h
@@ -80,6 +82,8 @@
 /* Per CPU shadow time values */
 static volatile struct shadow ci_shadow[MAXCPUS];
 
+static kmutex_t tmutex; /* Protects volatile variables, below */
+
 /* The time when the last hardclock(9) call should have taken place,
  * per cpu.
  */
@@ -90,7 +94,7 @@
  * back to maintain the illusion that hardclock(9) was called when it
  * was supposed to be, not when Xen got around to scheduling us.
  */
-static volatile uint64_t xen_clock_bias[MAXCPUS];
+static volatile uint64_t xen_clock_bias;
 
 #ifdef DOM0OPS
 /* If we're dom0, send our time to Xen every minute or so. */
@@ -245,18 +249,17 @@
 xen_wall_time(struct timespec *wt)
 {
 	uint64_t nsec;
-	int s;
 	struct cpu_info *ci = cpu_info_primary;
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
-	s = splhigh();
+	mutex_enter(tmutex);
 	get_time_values_from_xen(ci);
 	*wt = shadow-ts;
 	nsec = wt-tv_nsec;
 
 	/* Under Xen3, this is the wall time less system time */
 	nsec += get_system_time();
-	splx(s);
+	mutex_exit(tmutex);
 	wt-tv_sec += nsec / 10L;
 	wt-tv_nsec = nsec % 10L;
 }
@@ -282,8 +285,6 @@
 #else
 	xen_platform_op_t op;
 #endif
-	int s;
-
 	if (xendomain_is_privileged()) {
  		/* needs to set the RTC chip too */
  		struct clock_ymdhms dt;
@@ -298,9 +299,9 @@
 		/* XXX is rtc_offset handled correctly everywhere? */
 		op.u.settime.secs	 = tvp-tv_sec;
 		op.u.settime.nsecs	 = tvp-tv_usec * 1000;
-		s = splhigh();
+		mutex_enter(tmutex);
 		op.u.settime.system_time = get_system_time();
-		splx(s);
+		mutex_exit(tmutex);
 #if __XEN_INTERFACE_VERSION__  0x00030204
 		return HYPERVISOR_dom0_op(op);
 #else
@@ -355,18 +356,17 @@
 		return;
 	} else {
 		uint64_t when;
-		int s;
 		/* for large delays, shadow-system_time is OK */
 		
-		s = splhigh();
+		mutex_enter(tmutex);
 		get_time_values_from_xen(ci);
 		when = shadow-system_time + n * 1000;
 		while (shadow-system_time  when) {
-			splx(s);
-			s = splhigh();
+			mutex_exit(tmutex);
+			mutex_enter(tmutex);
 			get_time_values_from_xen(ci);
 		}
-		splx(s);
+		mutex_exit(tmutex);
 	}
 }
 
@@ -416,11 +416,10 @@
 xen_get_timecount(struct timecounter *tc)
 {
 	uint64_t ns;
-	int s;
 
-	s = splhigh();
-	ns = get_system_time() - xen_clock_bias[0];
-	splx(s);
+	mutex_enter(tmutex);
+	ns = get_system_time() - xen_clock_bias;
+	mutex_exit(tmutex);
 
 	return (u_int)ns;
 }
@@ -437,13 +436,15 @@
 void
 xen_initclocks(void)
 {
-	int evtch;
+	int err, evtch;
 	static bool tcdone = false;
 
+	struct vcpu_set_periodic_timer hardclock_period = { NS_PER_TICK };
+
 	struct cpu_info *ci = curcpu();
 	volatile struct shadow *shadow = ci_shadow[ci-ci_cpuid];
 
-	xen_clock_bias[ci-ci_cpuid] = 0;
+	xen_clock_bias = 0;
 
 	evcnt_attach_dynamic(hardclock_called[ci-ci_cpuid],
 			 EVCNT_TYPE_INTR,
@@ -462,10 +463,18 @@
 	get_time_values_from_xen(ci);
 	vcpu_system_time[ci-ci_cpuid] = shadow-system_time;
 	if (!tcdone) { /* Do this only once */
+		mutex_init(tmutex, MUTEX_DEFAULT, IPL_HIGH);
 		tc_init(xen_timecounter);
 	}
 	/* The splhigh requirements start here. */
 
+	/* Set hardclock() frequency */
+	err = HYPERVISOR_vcpu_op(VCPUOP_set_periodic_timer,
+ ci-ci_cpuid,
+ hardclock_period);
+
+	KASSERT(err == 0);
+
 	event_set_handler(evtch, (int (*)(void *))xen_timer_handler,
 	ci, IPL_CLOCK, clock);
 	hypervisor_enable_event(evtch);
@@ -493,43 +502,30 @@
 

CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 22 16:48:03 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: hypervisor_machdep.c

Log Message:
Do not trust the hypervisor to route events to the right cpu. Enforce this in 
stipending()


To generate a diff of this commit:
cvs rdiff -u -r1.14.2.3 -r1.14.2.4 src/sys/arch/xen/x86/hypervisor_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/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.3 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.4
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.3	Wed Aug 17 09:40:39 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Mon Aug 22 16:48:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.3 2011/08/17 09:40:39 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.4 2011/08/22 16:48:03 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -140,8 +140,8 @@
 	int *ret = args;
 
 	if (evtsource[port]) {
-		hypervisor_set_ipending(ci, evtsource[port]-ev_imask,
-		l1i, l2i);
+		hypervisor_set_ipending(evtsource[port]-ev_cpu,
+		evtsource[port]-ev_imask, l1i, l2i);
 		evtsource[port]-ev_evcnt.ev_count++;
 		if (*ret == 0  ci-ci_ilevel 
 		evtsource[port]-ev_maxlevel)



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-08-22 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Aug 22 17:39:19 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: xen_pmap.c

Log Message:
Remove spurious locks


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.3 -r1.2.2.4 src/sys/arch/xen/x86/xen_pmap.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/x86/xen_pmap.c
diff -u src/sys/arch/xen/x86/xen_pmap.c:1.2.2.3 src/sys/arch/xen/x86/xen_pmap.c:1.2.2.4
--- src/sys/arch/xen/x86/xen_pmap.c:1.2.2.3	Sat Aug 20 19:22:47 2011
+++ src/sys/arch/xen/x86/xen_pmap.c	Mon Aug 22 17:39:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xen_pmap.c,v 1.2.2.3 2011/08/20 19:22:47 cherry Exp $	*/
+/*	$NetBSD: xen_pmap.c,v 1.2.2.4 2011/08/22 17:39:19 cherry Exp $	*/
 
 /*
  * Copyright (c) 2007 Manuel Bouyer.
@@ -102,7 +102,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.2.2.3 2011/08/20 19:22:47 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xen_pmap.c,v 1.2.2.4 2011/08/22 17:39:19 cherry Exp $);
 
 #include opt_user_ldt.h
 #include opt_lockdebug.h
@@ -212,7 +212,6 @@
 
 	/* the kernel's pmap is always accessible */
 	if (pmap == pmap_kernel()) {
-		mutex_enter(pmap-pm_lock);
 		*pmap2 = NULL;
 		*ptepp = PTE_BASE;
 		*pdeppp = normal_pdes;
@@ -327,7 +326,6 @@
 {
 
 	if (pmap == pmap_kernel()) {
-		mutex_exit(pmap-pm_lock);
 		return;
 	}
 	KASSERT(kpreempt_disabled());



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-08-21 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Aug 21 11:24:11 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: if_xennet_xenbus.c
xennetback_xenbus.c

Log Message:
add locking around mmu flush xpq ops


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.51.2.1 src/sys/arch/xen/xen/if_xennet_xenbus.c
cvs rdiff -u -r1.46 -r1.46.2.1 src/sys/arch/xen/xen/xennetback_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.51 src/sys/arch/xen/xen/if_xennet_xenbus.c:1.51.2.1
--- src/sys/arch/xen/xen/if_xennet_xenbus.c:1.51	Mon May 30 13:03:56 2011
+++ src/sys/arch/xen/xen/if_xennet_xenbus.c	Sun Aug 21 11:24:10 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: if_xennet_xenbus.c,v 1.51 2011/05/30 13:03:56 joerg Exp $  */
+/*  $NetBSD: if_xennet_xenbus.c,v 1.51.2.1 2011/08/21 11:24:10 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -85,7 +85,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.51 2011/05/30 13:03:56 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_xennet_xenbus.c,v 1.51.2.1 2011/08/21 11:24:10 cherry Exp $);
 
 #include opt_xen.h
 #include opt_nfs_boot.h
@@ -663,7 +663,9 @@
 		 * those first!
 		 */
 		s2 = splvm();
+		xpq_queue_lock();
 		xpq_flush_queue();
+		xpq_queue_unlock();		
 		splx(s2);
 		/* now decrease reservation */
 		xenguest_handle(reservation.extent_start) = xennet_pages;

Index: src/sys/arch/xen/xen/xennetback_xenbus.c
diff -u src/sys/arch/xen/xen/xennetback_xenbus.c:1.46 src/sys/arch/xen/xen/xennetback_xenbus.c:1.46.2.1
--- src/sys/arch/xen/xen/xennetback_xenbus.c:1.46	Mon May 30 14:34:58 2011
+++ src/sys/arch/xen/xen/xennetback_xenbus.c	Sun Aug 21 11:24:10 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: xennetback_xenbus.c,v 1.46 2011/05/30 14:34:58 joerg Exp $  */
+/*  $NetBSD: xennetback_xenbus.c,v 1.46.2.1 2011/08/21 11:24:10 cherry Exp $  */
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -26,7 +26,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: xennetback_xenbus.c,v 1.46 2011/05/30 14:34:58 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: xennetback_xenbus.c,v 1.46.2.1 2011/08/21 11:24:10 cherry Exp $);
 
 #include opt_xen.h
 
@@ -1077,7 +1077,9 @@
 			 * we flush those first!
 			 */
 			int svm = splvm();
+			xpq_queue_lock();
 			xpq_flush_queue();
+			xpq_queue_unlock();
 			splx(svm);
 			mclp[-1].args[MULTI_UVMFLAGS_INDEX] =
 			UVMF_TLB_FLUSH|UVMF_ALL;



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-08-05 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Fri Aug  5 17:26:27 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: xentests.c

Log Message:
pmap_enter() test needs an address that work for both i386 and amd64


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.1 -r1.1.2.2 src/sys/arch/xen/xen/xentests.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/xentests.c
diff -u src/sys/arch/xen/xen/xentests.c:1.1.2.1 src/sys/arch/xen/xen/xentests.c:1.1.2.2
--- src/sys/arch/xen/xen/xentests.c:1.1.2.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/xentests.c	Fri Aug  5 17:26:27 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: xentests.c,v 1.1.2.1 2011/06/03 13:27:42 cherry Exp $ */
+/* $NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 
-__KERNEL_RCSID(0, $NetBSD: xentests.c,v 1.1.2.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: xentests.c,v 1.1.2.2 2011/08/05 17:26:27 cherry Exp $);
 
 #include sys/types.h
 
@@ -997,6 +997,7 @@
 	return result;
 }
 
+#define USEFULLUSERLANDADDRESS 0x1
 
 /* pmap enter and extract */
 
@@ -1006,7 +1007,7 @@
 	KASSERT(arg != NULL);
 	struct test_args *ta = arg;
 
-	vaddr_t va = 0xfeedface  ~PAGE_MASK; /* PAGE_SIZE aligned */
+	vaddr_t va = USEFULLUSERLANDADDRESS  ~PAGE_MASK; /* PAGE_SIZE aligned */
 	paddr_t pa;
 	struct vm_page *pg;
 



CVS commit: [cherry-xenmp] src/sys/arch/xen

2011-08-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug  4 09:07:47 UTC 2011

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

Log Message:
first cut at per-cpu event handling


To generate a diff of this commit:
cvs rdiff -u -r1.18.10.1 -r1.18.10.2 src/sys/arch/xen/include/evtchn.h
cvs rdiff -u -r1.31 -r1.31.10.1 src/sys/arch/xen/include/hypervisor.h
cvs rdiff -u -r1.31.10.2 -r1.31.10.3 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.14.2.1 -r1.14.2.2 src/sys/arch/xen/x86/hypervisor_machdep.c
cvs rdiff -u -r1.47.6.1 -r1.47.6.2 src/sys/arch/xen/xen/evtchn.c
cvs rdiff -u -r1.37 -r1.37.2.1 src/sys/arch/xen/xen/xenevt.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/evtchn.h
diff -u src/sys/arch/xen/include/evtchn.h:1.18.10.1 src/sys/arch/xen/include/evtchn.h:1.18.10.2
--- src/sys/arch/xen/include/evtchn.h:1.18.10.1	Fri Jun  3 13:27:40 2011
+++ src/sys/arch/xen/include/evtchn.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.h,v 1.18.10.1 2011/06/03 13:27:40 cherry Exp $	*/
+/*	$NetBSD: evtchn.h,v 1.18.10.2 2011/08/04 09:07:46 cherry Exp $	*/
 
 /*
  *
@@ -42,7 +42,9 @@
 int event_remove_handler(int, int (*func)(void *), void *);
 
 struct intrhand;
-void event_set_iplhandler(struct intrhand *, int);
+void event_set_iplhandler(struct cpu_info *ci,
+			  struct intrhand *, 
+			  int);
 
 extern int debug_port;
 extern int xen_debug_handler(void *);

Index: src/sys/arch/xen/include/hypervisor.h
diff -u src/sys/arch/xen/include/hypervisor.h:1.31 src/sys/arch/xen/include/hypervisor.h:1.31.10.1
--- src/sys/arch/xen/include/hypervisor.h:1.31	Mon Oct 19 18:41:10 2009
+++ src/sys/arch/xen/include/hypervisor.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor.h,v 1.31 2009/10/19 18:41:10 bouyer Exp $	*/
+/*	$NetBSD: hypervisor.h,v 1.31.10.1 2011/08/04 09:07:46 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Manuel Bouyer.
@@ -91,6 +91,7 @@
 #include xen/xen3-public/io/netif.h
 #include xen/xen3-public/io/blkif.h
 
+#include machine/cpu.h
 #include machine/hypercalls.h
 
 #undef u8
@@ -136,7 +137,8 @@
 void hypervisor_mask_event(unsigned int);
 void hypervisor_clear_event(unsigned int);
 void hypervisor_enable_ipl(unsigned int);
-void hypervisor_set_ipending(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/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31.10.2 src/sys/arch/xen/include/intr.h:1.31.10.3
--- src/sys/arch/xen/include/intr.h:1.31.10.2	Sun Jun 26 12:56:32 2011
+++ src/sys/arch/xen/include/intr.h	Thu Aug  4 09:07:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.31.10.2 2011/06/26 12:56:32 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.31.10.3 2011/08/04 09:07:46 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -58,13 +58,8 @@
 	struct intrhand *ev_handlers;	/* handler chain */
 	struct evcnt ev_evcnt;		/* interrupt counter */
 	char ev_evname[32];		/* event counter name */
+	struct cpu_info *ev_cpu;	/* cpu on which this event is bound */
 	struct simplelock ev_lock;	/* protects this structure */
-
-	/* 
-	 * XXX: The lock is quite coursegrained ( for the entire
-	 * handler list ), but contention is expected to be low. See
-	 * how this performs and revisit.
-	 */
 };
 
 /*

Index: src/sys/arch/xen/x86/hypervisor_machdep.c
diff -u src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.1 src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.2
--- src/sys/arch/xen/x86/hypervisor_machdep.c:1.14.2.1	Fri Jun  3 13:27:41 2011
+++ src/sys/arch/xen/x86/hypervisor_machdep.c	Thu Aug  4 09:07:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.1 2011/06/03 13:27:41 cherry Exp $	*/
+/*	$NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $	*/
 
 /*
  *
@@ -54,7 +54,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.1 2011/06/03 13:27:41 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor_machdep.c,v 1.14.2.2 2011/08/04 09:07:47 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -86,13 +86,101 @@
 // #define PORT_DEBUG 4
 // #define EARLY_DEBUG_EVENT
 
+static inline unsigned int
+evt_bitstr_to_port(unsigned long l1, unsigned long l2)
+{
+	unsigned int l1i, l2i, port;
+
+	l1i = xen_ffs(l1) - 1;
+	l2i = xen_ffs(l2) - 1;
+
+	port = (l1i  LONG_SHIFT) + l2i;
+	return port;
+}
+
+/* callback function type */
+typedef void (*iterate_func_t)(struct cpu_info *,
+			   unsigned int,
+			   unsigned int,
+			   unsigned int,
+			   void *);
+
+
+static inline void
+evt_iterate_pending(struct cpu_info *ci,
+		volatile unsigned long *pendingl1,
+		volatile 

CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-08-04 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Thu Aug  4 13:04:20 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: evtchn.c

Log Message:
Send an ipi at IPL_HIGH to remote cpu, in order to get it to run spllower()


To generate a diff of this commit:
cvs rdiff -u -r1.47.6.2 -r1.47.6.3 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/evtchn.c
diff -u src/sys/arch/xen/xen/evtchn.c:1.47.6.2 src/sys/arch/xen/xen/evtchn.c:1.47.6.3
--- src/sys/arch/xen/xen/evtchn.c:1.47.6.2	Thu Aug  4 09:07:47 2011
+++ src/sys/arch/xen/xen/evtchn.c	Thu Aug  4 13:04:20 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: evtchn.c,v 1.47.6.2 2011/08/04 09:07:47 cherry Exp $	*/
+/*	$NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 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.2 2011/08/04 09:07:47 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: evtchn.c,v 1.47.6.3 2011/08/04 13:04:20 cherry Exp $);
 
 #include opt_xen.h
 #include isa.h
@@ -245,7 +245,16 @@
 	evtsource[evtch]-ev_imask,
 	evtch  LONG_SHIFT,
 	evtch  LONG_MASK);
-		/* leave masked */
+
+		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)) {
+panic(xen_send_ipi(%s, XEN_IPI_KICK) failed\n, cpu_name(rci));
+			}
+		}
+
+		/* leave masked */ 
 		return 0;
 	}
 	ci-ci_ilevel = evtsource[evtch]-ev_maxlevel;



CVS commit: [cherry-xenmp] src/sys/arch/xen/xen

2011-07-25 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jul 25 17:29:43 UTC 2011

Modified Files:
src/sys/arch/xen/xen [cherry-xenmp]: clock.c

Log Message:
Do not register the same callback more than once.


To generate a diff of this commit:
cvs rdiff -u -r1.54.6.1 -r1.54.6.2 src/sys/arch/xen/xen/clock.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.54.6.1 src/sys/arch/xen/xen/clock.c:1.54.6.2
--- src/sys/arch/xen/xen/clock.c:1.54.6.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/clock.c	Mon Jul 25 17:29:43 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: clock.c,v 1.54.6.1 2011/06/03 13:27:42 cherry Exp $	*/
+/*	$NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $	*/
 
 /*
  *
@@ -29,7 +29,7 @@
 #include opt_xen.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: clock.c,v 1.54.6.2 2011/07/25 17:29:43 cherry Exp $);
 
 #include sys/param.h
 #include sys/cpu.h
@@ -452,7 +452,9 @@
 			 hardclock);
 
 #ifdef DOM0OPS
-	callout_init(xen_timepush_co, 0);
+	if (!tcdone) { /* Do this only once */
+		callout_init(xen_timepush_co, 0);
+	}
 #endif
 	evtch = bind_virq_to_evtch(VIRQ_TIMER);
 	aprint_verbose(Xen clock: using event channel %d\n, evtch);



CVS commit: [cherry-xenmp] src/sys/arch/xen/conf

2011-06-27 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jun 27 10:21:53 UTC 2011

Modified Files:
src/sys/arch/xen/conf [cherry-xenmp]: files.xen

Log Message:
Conditionally compile xen_ipi.c


To generate a diff of this commit:
cvs rdiff -u -r1.118.2.2 -r1.118.2.3 src/sys/arch/xen/conf/files.xen

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/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.118.2.2 src/sys/arch/xen/conf/files.xen:1.118.2.3
--- src/sys/arch/xen/conf/files.xen:1.118.2.2	Thu Jun 23 14:19:49 2011
+++ src/sys/arch/xen/conf/files.xen	Mon Jun 27 10:21:52 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.118.2.2 2011/06/23 14:19:49 cherry Exp $
+#	$NetBSD: files.xen,v 1.118.2.3 2011/06/27 10:21:52 cherry Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -127,7 +127,7 @@
 file	arch/xen/x86/consinit.c
 file	arch/x86/x86/identcpu.c
 file	arch/xen/x86/intr.c
-file	arch/xen/x86/xen_ipi.c
+file	arch/xen/x86/xen_ipi.c		multiprocessor
 file	arch/x86/x86/pmap.c
 file	arch/x86/x86/pmap_tlb.c
 file	arch/x86/x86/procfs_machdep.c	procfs



CVS commit: [cherry-xenmp] src/sys/arch/xen/x86

2011-06-27 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Jun 27 10:23:21 UTC 2011

Modified Files:
src/sys/arch/xen/x86 [cherry-xenmp]: x86_xpmap.c

Log Message:
Add xpq locking around xpq-QUEUE_TLB_FLUSH()


To generate a diff of this commit:
cvs rdiff -u -r1.26.2.2 -r1.26.2.3 src/sys/arch/xen/x86/x86_xpmap.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/x86/x86_xpmap.c
diff -u src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.2 src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.3
--- src/sys/arch/xen/x86/x86_xpmap.c:1.26.2.2	Thu Jun 23 14:19:50 2011
+++ src/sys/arch/xen/x86/x86_xpmap.c	Mon Jun 27 10:23:21 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: x86_xpmap.c,v 1.26.2.2 2011/06/23 14:19:50 cherry Exp $	*/
+/*	$NetBSD: x86_xpmap.c,v 1.26.2.3 2011/06/27 10:23:21 cherry Exp $	*/
 
 /*
  * Copyright (c) 2006 Mathieu Ropert m...@adviseo.fr
@@ -69,7 +69,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.26.2.2 2011/06/23 14:19:50 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: x86_xpmap.c,v 1.26.2.3 2011/06/27 10:23:21 cherry Exp $);
 
 #include opt_xen.h
 #include opt_ddb.h
@@ -658,7 +658,9 @@
 	(UPAGES + 1) * NBPG);
 
 	/* Finally, flush TLB. */
+	xpq_queue_lock();
 	xpq_queue_tlb_flush();
+	xpq_queue_unlock();
 
 	return (init_tables + ((count + l2_4_count) * PAGE_SIZE));
 }



CVS commit: [cherry-xenmp] src/sys/arch/xen

2011-06-26 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Sun Jun 26 12:56:33 UTC 2011

Modified Files:
src/sys/arch/xen/include [cherry-xenmp]: intr.h
src/sys/arch/xen/xen [cherry-xenmp]: hypervisor.c

Log Message:
Unbreak uniprocessor build


To generate a diff of this commit:
cvs rdiff -u -r1.31.10.1 -r1.31.10.2 src/sys/arch/xen/include/intr.h
cvs rdiff -u -r1.55.2.1 -r1.55.2.2 src/sys/arch/xen/xen/hypervisor.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/intr.h
diff -u src/sys/arch/xen/include/intr.h:1.31.10.1 src/sys/arch/xen/include/intr.h:1.31.10.2
--- src/sys/arch/xen/include/intr.h:1.31.10.1	Fri Jun  3 13:27:40 2011
+++ src/sys/arch/xen/include/intr.h	Sun Jun 26 12:56:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: intr.h,v 1.31.10.1 2011/06/03 13:27:40 cherry Exp $	*/
+/*	$NetBSD: intr.h,v 1.31.10.2 2011/06/26 12:56:32 cherry Exp $	*/
 /*	NetBSD intr.h,v 1.15 2004/10/31 10:39:34 yamt Exp	*/
 
 /*-
@@ -185,9 +185,15 @@
 struct pic *intr_findpic(int);
 void intr_add_pcibus(struct pcibus_attach_args *);
 
+#ifdef MULTIPROCESSOR
 void xen_ipi_init(void);
 int xen_send_ipi(struct cpu_info *, uint32_t);
 void xen_broadcast_ipi(uint32_t);
+#else
+#define xen_ipi_init(_1) do {} while(0) /* nothing */
+#define xen_send_ipi(_i1, _i2) do {} while(0) /* nothing */
+#define xen_broadcast_ipi(_i1) do {} while(0) /* nothing */
+#endif /* MULTIPROCESSOR */
 
 #endif /* !_LOCORE */
 

Index: src/sys/arch/xen/xen/hypervisor.c
diff -u src/sys/arch/xen/xen/hypervisor.c:1.55.2.1 src/sys/arch/xen/xen/hypervisor.c:1.55.2.2
--- src/sys/arch/xen/xen/hypervisor.c:1.55.2.1	Fri Jun  3 13:27:42 2011
+++ src/sys/arch/xen/xen/hypervisor.c	Sun Jun 26 12:56:33 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: hypervisor.c,v 1.55.2.1 2011/06/03 13:27:42 cherry Exp $ */
+/* $NetBSD: hypervisor.c,v 1.55.2.2 2011/06/26 12:56:33 cherry Exp $ */
 
 /*
  * Copyright (c) 2005 Manuel Bouyer.
@@ -53,7 +53,7 @@
 
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.55.2.1 2011/06/03 13:27:42 cherry Exp $);
+__KERNEL_RCSID(0, $NetBSD: hypervisor.c,v 1.55.2.2 2011/06/26 12:56:33 cherry Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -128,7 +128,6 @@
 hypervisor_match, hypervisor_attach, NULL, NULL);
 
 static int hypervisor_print(void *, const char *);
-static int hypervisor_vcpu_print(void *, const char *);
 
 union hypervisor_attach_cookie {
 	const char *hac_device;		/* first elem of all */
@@ -183,6 +182,15 @@
 	return 0;
 }
 
+#ifdef MULTIPROCESSOR
+static int
+hypervisor_vcpu_print(void *aux, const char *parent)
+{
+	/* Unconfigured cpus are ignored quietly. */
+	return (QUIET);
+}
+#endif /* MULTIPROCESSOR */
+
 /*
  * Attach the hypervisor.
  */
@@ -190,7 +198,6 @@
 hypervisor_attach(device_t parent, device_t self, void *aux)
 {
 	int xen_version;
-	cpuid_t vcpuid;
 
 #if NPCI 0
 #ifdef PCI_BUS_FIXUP
@@ -226,6 +233,7 @@
 	 * allocated vcpus (See: cpu.c:vcpu_match()) by iterating
 	 * through the maximum supported by NetBSD MP.
 	 */
+	cpuid_t vcpuid;
 
 	for (vcpuid = 1; vcpuid  maxcpus; vcpuid++) {
 		memset(hac, 0, sizeof(hac));
@@ -331,13 +339,6 @@
 	return (UNCONF);
 }
 
-static int
-hypervisor_vcpu_print(void *aux, const char *parent)
-{
-	/* Unconfigured cpus are ignored quietly. */
-	return (QUIET);
-}
-
 #if defined(DOM0OPS)
 
 #define DIR_MODE	(S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)