[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

add n arg to thrwakeup



thrwakeup should have an extra arg to tell us how many threads to wake up.  
so when there's 200 threads on a mutex, they don't all come to life to go 
back to sleep.  need to make this change before we get too far down the 
road.

works for me.

Index: sys/kern/init_sysent.c
===================================================================
RCS file: /cvs/src/sys/kern/init_sysent.c,v
retrieving revision 1.91
diff -u -r1.91 init_sysent.c
--- sys/kern/init_sysent.c	13 Dec 2005 06:04:14 -0000	1.91
+++ sys/kern/init_sysent.c	25 Dec 2005 00:47:09 -0000
@@ -1,4 +1,4 @@
-/*	$OpenBSD: init_sysent.c,v 1.91 2005/12/13 06:04:14 tedu Exp $	*/
+/*	$OpenBSD$	*/
 
 /*
  * System call switch table.
@@ -800,7 +800,7 @@
 	    sys_getthrid },			/* 299 = getthrid */
 	{ 3, s(struct sys_thrsleep_args),
 	    sys_thrsleep },			/* 300 = thrsleep */
-	{ 1, s(struct sys_thrwakeup_args),
+	{ 2, s(struct sys_thrwakeup_args),
 	    sys_thrwakeup },			/* 301 = thrwakeup */
 	{ 1, s(struct sys_threxit_args),
 	    sys_threxit },			/* 302 = threxit */
Index: sys/kern/kern_synch.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_synch.c,v
retrieving revision 1.72
diff -u -r1.72 kern_synch.c
--- sys/kern/kern_synch.c	22 Dec 2005 06:55:03 -0000	1.72
+++ sys/kern/kern_synch.c	25 Dec 2005 00:47:09 -0000
@@ -409,19 +409,23 @@
 {
 	struct sys_thrwakeup_args *uap = v;
 	long ident = (long)SCARG(uap, ident);
+	int n = SCARG(uap, n);
 	struct proc *q;
 	int found = 0;
 	
 	/* have to check the parent, it's not in the thread list */
 	if (p->p_thrparent->p_thrslpid == ident) {
 		wakeup(&p->p_thrparent->p_thrslpid);
-		found = 1;
+		p->p_thrparent->p_thrslpid = 0;
+		if (++found == n)
+			return (0);
 	}
 	LIST_FOREACH(q, &p->p_thrparent->p_thrchildren, p_thrsib) {
 		if (q->p_thrslpid == ident) {
 			wakeup(&q->p_thrslpid);
 			q->p_thrslpid = 0;
-			found = 1;
+			if (++found == n)
+				return (0);
 		}
 	}
 	if (!found)
Index: sys/kern/kern_time.c
===================================================================
RCS file: /cvs/src/sys/kern/kern_time.c,v
retrieving revision 1.52
diff -u -r1.52 kern_time.c
--- sys/kern/kern_time.c	28 Nov 2005 00:14:29 -0000	1.52
+++ sys/kern/kern_time.c	25 Dec 2005 00:47:10 -0000
@@ -381,9 +381,11 @@
 
 	return (0);
 #else
+	static int increase_skew;
 	struct timeval atv;
-	long ndelta, ntickdelta, odelta;
+	long secdelta, ndelta, ntickdelta, odelta;
 	int s, error;
+	int largeadj = 0;
 
 	if ((error = suser(p, 0)))
 		return (error);
@@ -398,12 +400,21 @@
 	 * hardclock(), tickdelta will become zero, lest the correction
 	 * overshoot and start taking us away from the desired final time.
 	 */
-	if (atv.tv_sec > LONG_MAX / 1000000L)
+	secdelta = atv.tv_sec;
+
+	/* if this is going to take more than 4 hours, speed it up */
+	if (secdelta / 1000000L > 4 * 3600L) {
+		largeadj = 1;
+		ndelta = LONG_MAX;
+	} else if (secdelta / 1000000L < -4 * 3600L) {
+		largeadj = 1;
+		ndelta = LONG_MIN;
+	} else if (secdelta > LONG_MAX / 1000000L) {
 		ndelta = LONG_MAX;
-	else if (atv.tv_sec < LONG_MIN / 1000000L)
+	} else if (secdelta < LONG_MIN / 1000000L) {
 		ndelta = LONG_MIN;
-	else {
-		ndelta = atv.tv_sec * 1000000L;
+	} else {
+		ndelta = secdelta * 1000000L;
 		odelta = ndelta;
 		ndelta += atv.tv_usec;
 		if (atv.tv_usec > 0 && ndelta <= odelta)
@@ -412,20 +423,41 @@
 			ndelta = LONG_MIN;
 	}
 
-	if (ndelta > bigadj || ndelta < -bigadj)
+	if (largeadj)
+		ntickdelta = 100 * tickadj;
+	else if (ndelta > bigadj || ndelta < -bigadj)
 		ntickdelta = 10 * tickadj;
 	else
 		ntickdelta = tickadj;
+	/* check to see if we are losing the race */
+	if (increase_skew > 5)
+		ntickdelta += increase_skew / 5 * ntickdelta / 2;
+	else if (increase_skew < -5)
+		ntickdelta += -increase_skew / 5 * ntickdelta / 2;
+	if (ntickdelta > tick / 2)
+		ntickdelta = tick / 2;
 	if (ndelta % ntickdelta)
 		ndelta = ndelta / ntickdelta * ntickdelta;
 
 	/*
 	 * To make hardclock()'s job easier, make the per-tick delta negative
 	 * if we want time to run slower; then hardclock can simply compute
-	 * tick + tickdelta, and subtract tickdelta from timedelta.
+	 * tick + tickdelta, and subtract tickdelta from timedelta.  If
+	 * we notice we are sliding away from where we want to be,
+	 * take notice so next time we can increase the adjustment.
 	 */
-	if (ndelta < 0)
+	if (ndelta < 0) {
 		ntickdelta = -ntickdelta;
+		if (ndelta < timedelta && increase_skew < 0)
+			increase_skew--;
+		else if (increase_skew > 0)
+			increase_skew--;
+	} else {
+		if (ndelta > timedelta && increase_skew > 0)
+			increase_skew++;
+		else if (increase_skew < 0)
+			increase_skew++;
+	}
 	s = splclock();
 	odelta = timedelta;
 	timedelta = ndelta;
Index: sys/kern/syscalls.c
===================================================================
RCS file: /cvs/src/sys/kern/syscalls.c,v
retrieving revision 1.92
diff -u -r1.92 syscalls.c
--- sys/kern/syscalls.c	13 Dec 2005 06:04:14 -0000	1.92
+++ sys/kern/syscalls.c	25 Dec 2005 00:47:10 -0000
@@ -1,4 +1,4 @@
-/*	$OpenBSD: syscalls.c,v 1.92 2005/12/13 06:04:14 tedu Exp $	*/
+/*	$OpenBSD$	*/
 
 /*
  * System call names.
Index: sys/kern/syscalls.master
===================================================================
RCS file: /cvs/src/sys/kern/syscalls.master,v
retrieving revision 1.80
diff -u -r1.80 syscalls.master
--- sys/kern/syscalls.master	13 Dec 2005 06:02:03 -0000	1.80
+++ sys/kern/syscalls.master	25 Dec 2005 00:47:11 -0000
@@ -598,7 +598,7 @@
 #ifdef RTHREADS
 299	STD		{ pid_t sys_getthrid(void); }
 300	STD		{ int sys_thrsleep(void *ident, int timeout, void *lock); }
-301	STD		{ int sys_thrwakeup(void *ident); }
+301	STD		{ int sys_thrwakeup(void *ident, int n); }
 302	STD		{ int sys_threxit(int rval); }
 303	STD		{ int sys_thrsigdivert(sigset_t sigmask); }
 #else
Index: sys/sys/syscall.h
===================================================================
RCS file: /cvs/src/sys/sys/syscall.h,v
retrieving revision 1.90
diff -u -r1.90 syscall.h
--- sys/sys/syscall.h	13 Dec 2005 06:04:15 -0000	1.90
+++ sys/sys/syscall.h	25 Dec 2005 00:47:11 -0000
@@ -1,4 +1,4 @@
-/*	$OpenBSD: syscall.h,v 1.90 2005/12/13 06:04:15 tedu Exp $	*/
+/*	$OpenBSD$	*/
 
 /*
  * System call numbers.
@@ -679,7 +679,7 @@
 /* syscall: "thrsleep" ret: "int" args: "void *" "int" "void *" */
 #define	SYS_thrsleep	300
 
-/* syscall: "thrwakeup" ret: "int" args: "void *" */
+/* syscall: "thrwakeup" ret: "int" args: "void *" "int" */
 #define	SYS_thrwakeup	301
 
 /* syscall: "threxit" ret: "int" args: "int" */
Index: sys/sys/syscallargs.h
===================================================================
RCS file: /cvs/src/sys/sys/syscallargs.h,v
retrieving revision 1.92
diff -u -r1.92 syscallargs.h
--- sys/sys/syscallargs.h	13 Dec 2005 06:04:15 -0000	1.92
+++ sys/sys/syscallargs.h	25 Dec 2005 00:47:12 -0000
@@ -1,4 +1,4 @@
-/*	$OpenBSD: syscallargs.h,v 1.92 2005/12/13 06:04:15 tedu Exp $	*/
+/*	$OpenBSD$	*/
 
 /*
  * System call argument lists.
@@ -1225,6 +1225,7 @@
 
 struct sys_thrwakeup_args {
 	syscallarg(void *) ident;
+	syscallarg(int) n;
 };
 
 struct sys_threxit_args {
Index: lib/librthread/rthread.c
===================================================================
RCS file: /cvs/src/lib/librthread/rthread.c,v
retrieving revision 1.18
diff -u -r1.18 rthread.c
--- lib/librthread/rthread.c	23 Dec 2005 03:27:06 -0000	1.18
+++ lib/librthread/rthread.c	25 Dec 2005 00:47:12 -0000
@@ -45,8 +45,6 @@
 
 static struct pthread initial_thread __attribute__((__aligned__(16)));
 
-int getthrid(void);
-void threxit(int);
 int rfork_thread(int, void *, void (*)(void *), void *);
 
 /*
Index: lib/librthread/rthread.h
===================================================================
RCS file: /cvs/src/lib/librthread/rthread.h,v
retrieving revision 1.10
diff -u -r1.10 rthread.h
--- lib/librthread/rthread.h	22 Dec 2005 06:49:48 -0000	1.10
+++ lib/librthread/rthread.h	25 Dec 2005 00:47:12 -0000
@@ -128,3 +128,11 @@
 void	_rthread_tls_destructors(pthread_t);
 
 int	_atomic_lock(register volatile _spinlock_lock_t *);
+
+/* syscalls */
+int getthrid(void);
+void threxit(int);
+int thrsleep(void *, int, void *);
+int thrwakeup(void *, int n);
+int sched_yield(void);
+int thrsigdivert(const sigset_t *);
Index: lib/librthread/rthread_sched.c
===================================================================
RCS file: /cvs/src/lib/librthread/rthread_sched.c,v
retrieving revision 1.3
diff -u -r1.3 rthread_sched.c
--- lib/librthread/rthread_sched.c	19 Dec 2005 06:47:40 -0000	1.3
+++ lib/librthread/rthread_sched.c	25 Dec 2005 00:47:12 -0000
@@ -36,8 +36,6 @@
 
 #include "rthread.h"
 
-int sched_yield(void);
-
 int
 pthread_getschedparam(pthread_t thread, int *policy,
     struct sched_param *param)
Index: lib/librthread/rthread_sig.c
===================================================================
RCS file: /cvs/src/lib/librthread/rthread_sig.c,v
retrieving revision 1.3
diff -u -r1.3 rthread_sig.c
--- lib/librthread/rthread_sig.c	19 Dec 2005 06:50:13 -0000	1.3
+++ lib/librthread/rthread_sig.c	25 Dec 2005 00:47:12 -0000
@@ -36,10 +36,6 @@
 
 #include "rthread.h"
 
-int thrwakeup(void *);
-int thrsleep(void *, int, void *);
-int thrsigdivert(const sigset_t *);
-
 int
 pthread_sigmask(int how, const sigset_t *set, sigset_t *oset)
 {
@@ -60,7 +56,7 @@
 {
 	pthread_t self = pthread_self();
 	self->sigpend = sig;
-	thrwakeup(&self->sigpend);
+	thrwakeup(&self->sigpend, 0);
 }
 
 typedef void (*sigfn)(int);
Index: lib/librthread/rthread_sync.c
===================================================================
RCS file: /cvs/src/lib/librthread/rthread_sync.c,v
retrieving revision 1.12
diff -u -r1.12 rthread_sync.c
--- lib/librthread/rthread_sync.c	22 Dec 2005 06:49:48 -0000	1.12
+++ lib/librthread/rthread_sync.c	25 Dec 2005 00:47:12 -0000
@@ -38,9 +38,6 @@
 #include "rthread.h"
 
 
-int thrsleep(void *, int, void *);
-int thrwakeup(void *);
-
 /*
  * Internal implementation of semaphores
  */
@@ -91,7 +88,7 @@
 	_spinlock(&sem->lock);
 	sem->value++;
 	if (sem->waitcount) {
-		thrwakeup(sem);
+		thrwakeup(sem, 1);
 		rv = 1;
 	}
 	_spinunlock(&sem->lock);
@@ -107,7 +104,7 @@
 	_spinlock(&sem->lock);
 	if (sem->waitcount) {
 		sem->value++;
-		thrwakeup(sem);
+		thrwakeup(sem, 1);
 		rv = 1;
 	}
 	_spinunlock(&sem->lock);
@@ -123,7 +120,7 @@
 	_spinlock(&sem->lock);
 	rv = sem->waitcount;
 	sem->value += rv;
-	thrwakeup(sem);
+	thrwakeup(sem, 0);
 	_spinunlock(&sem->lock);
 
 	return (rv);

-- 
die energie aus fleisch und blut        deine sprache und die ganze wut
deine gefuehle die du lebst             und dein herz fuehl wie es bebt
zeitbombe! sie tickt in dir    zeitbombe! sie explodiert in deinem kopf
                                                    - girls under glass



Visit your host, monkey.org