PERFORCE change 31364 for review

Marcel Moolenaar marcel at FreeBSD.org
Fri May 16 18:51:25 PDT 2003


http://perforce.freebsd.org/chv.cgi?CH=31364

Change 31364 by marcel at marcel_nfs on 2003/05/16 18:50:42

	IFC @31361

Affected files ...

.. //depot/projects/ia64/bin/chflags/chflags.1#3 integrate
.. //depot/projects/ia64/bin/pwd/pwd.1#7 integrate
.. //depot/projects/ia64/bin/sh/sh.1#22 integrate
.. //depot/projects/ia64/games/caesar/caesar.6#3 integrate
.. //depot/projects/ia64/games/grdc/grdc.6#4 integrate
.. //depot/projects/ia64/lib/libc/ia64/sys/brk.S#5 integrate
.. //depot/projects/ia64/lib/libc/ia64/sys/pipe.S#3 integrate
.. //depot/projects/ia64/lib/libc/ia64/sys/sbrk.S#6 integrate
.. //depot/projects/ia64/lib/libkvm/kvm_ia64.c#3 integrate
.. //depot/projects/ia64/lib/libpthread/sys/lock.c#3 integrate
.. //depot/projects/ia64/lib/libpthread/sys/lock.h#3 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_cond.c#7 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_exit.c#4 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_init.c#9 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_join.c#4 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_kern.c#15 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_mutex.c#4 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_nanosleep.c#4 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_private.h#12 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_sig.c#8 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_sigsuspend.c#4 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_sigwait.c#5 integrate
.. //depot/projects/ia64/lib/libpthread/thread/thr_yield.c#4 integrate
.. //depot/projects/ia64/libexec/ftpd/ftpd.8#12 integrate
.. //depot/projects/ia64/libexec/rtld-elf/rtld.1#7 integrate
.. //depot/projects/ia64/release/scripts/doFS.sh#16 integrate
.. //depot/projects/ia64/sbin/sysctl/sysctl.8#8 integrate
.. //depot/projects/ia64/share/man/man9/CTASSERT.9#1 branch
.. //depot/projects/ia64/share/man/man9/KASSERT.9#3 integrate
.. //depot/projects/ia64/share/man/man9/Makefile#22 integrate
.. //depot/projects/ia64/share/man/man9/VFS_SET.9#4 integrate
.. //depot/projects/ia64/share/man/man9/byteorder.9#4 integrate
.. //depot/projects/ia64/share/man/man9/mbuf.9#9 integrate
.. //depot/projects/ia64/share/man/man9/rman.9#1 branch
.. //depot/projects/ia64/share/man/man9/sleep.9#7 integrate
.. //depot/projects/ia64/sys/boot/i386/libi386/amd64_tramp.S#2 integrate
.. //depot/projects/ia64/sys/conf/Makefile.ia64#18 integrate
.. //depot/projects/ia64/sys/conf/files.ia64#40 integrate
.. //depot/projects/ia64/sys/conf/options.ia64#13 integrate
.. //depot/projects/ia64/sys/dev/md/md.c#28 integrate
.. //depot/projects/ia64/sys/ia64/ia32/ia32_sysvec.c#6 integrate
.. //depot/projects/ia64/sys/ia64/ia32/ia32_util.h#5 integrate
.. //depot/projects/ia64/sys/ia64/ia64/db_interface.c#10 integrate
.. //depot/projects/ia64/sys/ia64/ia64/db_trace.c#10 integrate
.. //depot/projects/ia64/sys/ia64/ia64/elf_machdep.c#10 integrate
.. //depot/projects/ia64/sys/ia64/ia64/exception.s#21 integrate
.. //depot/projects/ia64/sys/ia64/ia64/genassym.c#12 integrate
.. //depot/projects/ia64/sys/ia64/ia64/interrupt.c#28 integrate
.. //depot/projects/ia64/sys/ia64/ia64/locore.s#15 integrate
.. //depot/projects/ia64/sys/ia64/ia64/machdep.c#68 integrate
.. //depot/projects/ia64/sys/ia64/ia64/mp_machdep.c#32 integrate
.. //depot/projects/ia64/sys/ia64/ia64/pmap.c#61 integrate
.. //depot/projects/ia64/sys/ia64/ia64/support.s#7 integrate
.. //depot/projects/ia64/sys/ia64/ia64/trap.c#50 integrate
.. //depot/projects/ia64/sys/ia64/ia64/unaligned.c#2 integrate
.. //depot/projects/ia64/sys/ia64/ia64/unwind.c#6 integrate
.. //depot/projects/ia64/sys/ia64/ia64/vm_machdep.c#23 integrate
.. //depot/projects/ia64/sys/ia64/include/asm.h#9 integrate
.. //depot/projects/ia64/sys/ia64/include/cpu.h#12 integrate
.. //depot/projects/ia64/sys/ia64/include/db_machdep.h#6 integrate
.. //depot/projects/ia64/sys/ia64/include/frame.h#4 integrate
.. //depot/projects/ia64/sys/ia64/include/pcb.h#8 integrate
.. //depot/projects/ia64/sys/ia64/include/proc.h#5 integrate
.. //depot/projects/ia64/sys/ia64/include/reg.h#9 integrate
.. //depot/projects/ia64/sys/ia64/include/signal.h#7 integrate
.. //depot/projects/ia64/sys/ia64/include/smp.h#4 integrate
.. //depot/projects/ia64/sys/ia64/include/ucontext.h#2 integrate
.. //depot/projects/ia64/sys/ia64/include/unwind.h#3 integrate
.. //depot/projects/ia64/sys/ia64/include/vmparam.h#8 integrate
.. //depot/projects/ia64/sys/kern/kern_synch.c#36 integrate
.. //depot/projects/ia64/sys/kern/kern_thr.c#6 integrate
.. //depot/projects/ia64/sys/kern/kern_thread.c#45 integrate
.. //depot/projects/ia64/sys/kern/vfs_subr.c#48 integrate
.. //depot/projects/ia64/sys/sys/proc.h#65 integrate
.. //depot/projects/ia64/tools/tools/tinderbox/Makefile#4 integrate
.. //depot/projects/ia64/tools/tools/tinderbox/tbmaster.1#1 branch
.. //depot/projects/ia64/tools/tools/tinderbox/tbmaster.pl#9 integrate
.. //depot/projects/ia64/tools/tools/tinderbox/tinderbox.1#1 branch
.. //depot/projects/ia64/tools/tools/tinderbox/tinderbox.pl#8 integrate
.. //depot/projects/ia64/usr.bin/truss/ia64-fbsd.c#3 integrate

Differences ...

==== //depot/projects/ia64/bin/chflags/chflags.1#3 (text+ko) ====

@@ -33,9 +33,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)chflags.1	8.4 (Berkeley) 5/2/95
-.\" $FreeBSD: src/bin/chflags/chflags.1,v 1.16 2003/03/24 20:15:58 johan Exp $
+.\" $FreeBSD: src/bin/chflags/chflags.1,v 1.17 2003/05/16 21:18:01 ru Exp $
 .\"
-.Dd Mar 24, 2003
+.Dd March 24, 2003
 .Dt CHFLAGS 1
 .Os
 .Sh NAME

==== //depot/projects/ia64/bin/pwd/pwd.1#7 (text+ko) ====

@@ -33,7 +33,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)pwd.1	8.2 (Berkeley) 4/28/95
-.\" $FreeBSD: src/bin/pwd/pwd.1,v 1.21 2003/04/12 03:22:54 tjr Exp $
+.\" $FreeBSD: src/bin/pwd/pwd.1,v 1.22 2003/05/16 21:19:32 ru Exp $
 .\"
 .Dd April 12, 2003
 .Dt PWD 1
@@ -43,7 +43,7 @@
 .Nd return working directory name
 .Sh SYNOPSIS
 .Nm
-.Oo Fl L | Fl P Oc
+.Op Fl L | P
 .Sh DESCRIPTION
 The
 .Nm

==== //depot/projects/ia64/bin/sh/sh.1#22 (text+ko) ====

@@ -33,7 +33,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	from: @(#)sh.1	8.6 (Berkeley) 5/4/95
-.\" $FreeBSD: src/bin/sh/sh.1,v 1.86 2003/04/30 19:18:50 schweikh Exp $
+.\" $FreeBSD: src/bin/sh/sh.1,v 1.87 2003/05/16 21:19:32 ru Exp $
 .\"
 .Dd April 12, 2003
 .Dt SH 1
@@ -1295,7 +1295,7 @@
 List or alter key bindings for the line editor.
 This command is documented in
 .Xr editrc 5 .
-.It Ic cd Oo Fl L | Fl P Oc Op Ar directory
+.It Ic cd Oo Fl L | P Oc Op Ar directory
 Switch to the specified
 .Ar directory ,
 or to the directory specified in the
@@ -1626,7 +1626,7 @@
 If the
 .Fl s
 option is specified, only the PIDs of the jobs are printed, one per line.
-.It Ic pwd Oo Fl L | Fl P Oc
+.It Ic pwd Op Fl L | P
 Print the path of the current directory.  The built-in command may
 differ from the program of the same name because the
 built-in command remembers what the current directory

==== //depot/projects/ia64/games/caesar/caesar.6#3 (text+ko) ====

@@ -30,13 +30,13 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)caesar.6	8.2 (Berkeley) 11/16/93
-.\" $FreeBSD: src/games/caesar/caesar.6,v 1.8 2003/03/24 11:18:30 tjr Exp $
+.\" $FreeBSD: src/games/caesar/caesar.6,v 1.9 2003/05/16 21:26:39 ru Exp $
 .\"
 .Dd November 16, 1993
 .Dt CAESAR 6
 .Os
 .Sh NAME
-.Nm caesar
+.Nm caesar , rot13
 .Nd decrypt caesar ciphers
 .Sh SYNOPSIS
 .Nm

==== //depot/projects/ia64/games/grdc/grdc.6#4 (text+ko) ====

@@ -1,4 +1,4 @@
-.\" $FreeBSD: src/games/grdc/grdc.6,v 1.5 2003/03/28 16:37:45 mux Exp $
+.\" $FreeBSD: src/games/grdc/grdc.6,v 1.6 2003/05/16 21:27:23 ru Exp $
 .Dd September 25, 2001
 .Dt GRDC 6
 .Os
@@ -7,8 +7,7 @@
 .Nd grand digital clock (curses)
 .Sh SYNOPSIS
 .Nm
-.Op Fl s
-.Op Fl t
+.Op Fl st
 .Op Ar n
 .Sh DESCRIPTION
 .Nm

==== //depot/projects/ia64/lib/libc/ia64/sys/brk.S#5 (text+ko) ====

@@ -28,7 +28,7 @@
  */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/brk.S,v 1.3 2003/03/03 01:09:46 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/brk.S,v 1.4 2003/05/16 21:26:39 marcel Exp $");
 
 #include "SYS.h"
 
@@ -44,12 +44,14 @@
 	add	r14=@ltoff(minbrk),gp ;;
 	ld8	r14=[r14] ;;
 	ld8	r14=[r14] ;;
-	cmp.ltu	p6,p0=in0,r14 ;;
-(p6)	mov	in0=r14
+	cmp.ltu	p6,p0=r32,r14 ;;
+(p6)	mov	r32=r14 ;;
+	st8	[sp]=r32
 	CALLSYS_ERROR(break)
+	ld8	r15=[sp]
 	add	r14=@ltoff(curbrk),gp ;;
 	ld8	r14=[r14] ;;
-	st8	[r14]=in0
+	st8	[r14]=r15
 	mov	ret0=0
 	br.ret.sptk.few rp
 END(brk)

==== //depot/projects/ia64/lib/libc/ia64/sys/pipe.S#3 (text+ko) ====

@@ -28,14 +28,20 @@
  */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/pipe.S,v 1.3 2003/03/03 01:09:46 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/pipe.S,v 1.4 2003/05/16 21:26:39 marcel Exp $");
 
 #include "SYS.h"
 
-SYSCALL(pipe)
-	.regstk	1,0,0,0
-	st4	[in0]=ret0,4 ;;
-	st4	[in0]=ret1
-	mov	ret0=0
+ENTRY(__sys_pipe, 1)
+	WEAK_ALIAS(pipe, __sys_pipe)
+	WEAK_ALIAS(_pipe, __sys_pipe)
+	st8		[sp]=r32
+	CALLSYS_ERROR(pipe)
+	ld8		r14=[sp]
+	;;
+	st4		[r14]=ret0,4
+	;;
+	st4		[r14]=ret1
+	mov		ret0=0
 	br.ret.sptk.few rp
-END(pipe)
+END(__sys_pipe)

==== //depot/projects/ia64/lib/libc/ia64/sys/sbrk.S#6 (text+ko) ====

@@ -28,7 +28,7 @@
  */
 
 #include <machine/asm.h>
-__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/sbrk.S,v 1.4 2003/03/03 01:09:46 obrien Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/ia64/sys/sbrk.S,v 1.5 2003/05/16 21:26:39 marcel Exp $");
 
 #include "SYS.h"
 
@@ -43,18 +43,21 @@
 	add	r14 = @ltoff(curbrk), gp
 	;;
 	ld8	r14 = [r14]
-	cmp.eq	p6, p0 = in0, r0
+	cmp.eq	p6, p0 = r32, r0
 	;;
 	ld8	ret0 = [r14]
 (p6)	br.ret.sptk.few	rp
 	;;
-	add	in0 = ret0, in0
+	add	r32 = ret0, r32
+	;;
+	st8	[sp] = r32
 	CALLSYS_ERROR(break)
+	ld8	r15 = [sp]
 	add	r14 = @ltoff(curbrk), gp
 	;;
 	ld8	r14 = [r14]
 	;;
 	ld8	ret0 = [r14]
-	st8	[r14] = in0
+	st8	[r14] = r15
 	br.ret.sptk.few	rp
 END(sbrk)

==== //depot/projects/ia64/lib/libkvm/kvm_ia64.c#3 (text+ko) ====

@@ -1,4 +1,4 @@
-/* $FreeBSD: src/lib/libkvm/kvm_ia64.c,v 1.3 2002/10/21 04:21:12 marcel Exp $ */
+/* $FreeBSD: src/lib/libkvm/kvm_ia64.c,v 1.4 2003/05/16 21:26:40 marcel Exp $ */
 /*	$NetBSD: kvm_alpha.c,v 1.7.2.1 1997/11/02 20:34:26 mellon Exp $	*/
 
 /*
@@ -148,7 +148,7 @@
 	 * addresses/values.
 	 */
 
-	nlist[0].n_name = "kptdir";
+	nlist[0].n_name = "ia64_kptdir";
 	nlist[1].n_name = 0;
 
 	if (kvm_nlist(kd, nlist) != 0) {

==== //depot/projects/ia64/lib/libpthread/sys/lock.c#3 (text+ko) ====

@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/sys/lock.c,v 1.3 2003/05/04 22:29:09 deischen Exp $
+ * $FreeBSD: src/lib/libpthread/sys/lock.c,v 1.4 2003/05/16 19:58:29 deischen Exp $
  */
 
 #include <sys/types.h>
@@ -65,7 +65,7 @@
 		lck->l_head->lr_watcher = NULL;
 		lck->l_head->lr_owner = NULL;
 		lck->l_head->lr_waiting = 0;
-		lck->l_head->lr_handshake = 0;
+		lck->l_head->lr_active = 1;
 		lck->l_tail = lck->l_head;
 	}
 	return (0);
@@ -85,7 +85,7 @@
 		lu->lu_myreq->lr_watcher = NULL;
 		lu->lu_myreq->lr_owner = lu;
 		lu->lu_myreq->lr_waiting = 0;
-		lu->lu_myreq->lr_handshake = 0;
+		lu->lu_myreq->lr_active = 0;
 		lu->lu_watchreq = NULL;
 		lu->lu_priority = 0;
 		lu->lu_private = priv;
@@ -166,19 +166,16 @@
 			for (i = 0; i < MAX_SPINS; i++) {
 				if (lu->lu_watchreq->lr_locked == 0)
 					return;
+				if (lu->lu_watchreq->lr_active == 0)
+					break;
 			}
 			atomic_store_rel_long(&lu->lu_watchreq->lr_waiting, 1);
 			while (lu->lu_watchreq->lr_locked != 0)
 				lck->l_wait(lck, lu);
 			atomic_store_rel_long(&lu->lu_watchreq->lr_waiting, 0);
-			/*
-			 * Wait for original owner to stop accessing the
-			 * lockreq object.
-			 */
-			while (lu->lu_watchreq->lr_handshake)
-				;
 		}
 	}
+	lu->lu_myreq->lr_active = 1;
 }
 
 /*
@@ -240,24 +237,21 @@
 			}
 		}
 		if (lu_h != NULL) {
-			lu_h->lu_watchreq->lr_handshake = 1;
 			/* Give the lock to the highest priority user. */
-			atomic_store_rel_long(&lu_h->lu_watchreq->lr_locked, 0);
 			if ((lu_h->lu_watchreq->lr_waiting != 0) &&
 			    (lck->l_wakeup != NULL))
 				/* Notify the sleeper */
 				lck->l_wakeup(lck, lu_h->lu_myreq->lr_watcher);
-			atomic_store_rel_long(&lu_h->lu_watchreq->lr_handshake,
-				 0);
+			else
+				atomic_store_rel_long(&lu_h->lu_watchreq->lr_locked, 0);
 		} else {
-			myreq->lr_handshake = 1;
-			/* Give the lock to the previous request. */
-			atomic_store_rel_long(&myreq->lr_locked, 0);
 			if ((myreq->lr_waiting != 0) &&
 			    (lck->l_wakeup != NULL))
 				/* Notify the sleeper */
 				lck->l_wakeup(lck, myreq->lr_watcher);
-			atomic_store_rel_long(&myreq->lr_handshake, 0);
+			else
+				/* Give the lock to the previous request. */
+				atomic_store_rel_long(&myreq->lr_locked, 0);
 		}
 	} else {
 		/*
@@ -270,19 +264,25 @@
 		lu->lu_watchreq = NULL;
 		lu->lu_myreq->lr_locked = 1;
 		lu->lu_myreq->lr_waiting = 0;
-		if (lck->l_wakeup) {
-			/* Start wakeup */
-			myreq->lr_handshake = 1;
+		if (myreq->lr_waiting != 0 && lck->l_wakeup) 
+			/* Notify the sleeper */
+			lck->l_wakeup(lck, myreq->lr_watcher);
+		else
 			/* Give the lock to the previous request. */
 			atomic_store_rel_long(&myreq->lr_locked, 0);
-			if (myreq->lr_waiting != 0) {
-				/* Notify the sleeper */
-				lck->l_wakeup(lck, myreq->lr_watcher);
-			}
-			/* Stop wakeup */
-			atomic_store_rel_long(&myreq->lr_handshake, 0);
-		} else {
-			atomic_store_rel_long(&myreq->lr_locked, 0);
-		}
 	}
+	lu->lu_myreq->lr_active = 0;
+}
+
+void
+_lock_grant(struct lock *lck /* unused */, struct lockuser *lu)
+{
+	atomic_store_rel_long(&lu->lu_watchreq->lr_locked, 0);
 }
+
+void
+_lockuser_setactive(struct lockuser *lu, int active)
+{
+	lu->lu_myreq->lr_active = active;
+}
+

==== //depot/projects/ia64/lib/libpthread/sys/lock.h#3 (text+ko) ====

@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/sys/lock.h,v 1.3 2003/05/04 22:29:09 deischen Exp $
+ * $FreeBSD: src/lib/libpthread/sys/lock.h,v 1.4 2003/05/16 19:58:29 deischen Exp $
  */
 
 #ifndef _LOCK_H_
@@ -55,7 +55,7 @@
 	struct lockuser	*lr_watcher;	/* only used for priority locks */
 	struct lockuser	*lr_owner;	/* only used for priority locks */
 	long		lr_waiting;	/* non-zero when wakeup needed */
-	volatile long	lr_handshake;	/* non-zero when wakeup in progress */
+	volatile int	lr_active;	/* non-zero if the lock is last lock for thread */
 };
 
 struct lockuser {
@@ -72,6 +72,7 @@
 #define	_LCK_REQUEST_INITIALIZER	{ 0, NULL, NULL, 0 }
 
 #define	_LCK_BUSY(lu)			((lu)->lu_watchreq->lr_locked != 0)
+#define	_LCK_ACTIVE(lu)			((lu)->lu_watchreq->lr_active != 0)
 #define	_LCK_GRANTED(lu)		((lu)->lu_watchreq->lr_locked == 0)
 
 #define	_LCK_SET_PRIVATE(lu, p)		(lu)->lu_private = (void *)(p)
@@ -84,7 +85,9 @@
 	    lock_handler_t *, lock_handler_t *);
 int	_lockuser_init(struct lockuser *lu, void *priv);
 void	_lockuser_destroy(struct lockuser *lu);
+void	_lockuser_setactive(struct lockuser *lu, int active);
 void	_lock_acquire(struct lock *, struct lockuser *, int);
 void	_lock_release(struct lock *, struct lockuser *);
+void	_lock_grant(struct lock *, struct lockuser *);
 
 #endif

==== //depot/projects/ia64/lib/libpthread/thread/thr_cond.c#7 (text+ko) ====

@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/thread/thr_cond.c,v 1.39 2003/05/02 11:39:00 davidxu Exp $
+ * $FreeBSD: src/lib/libpthread/thread/thr_cond.c,v 1.40 2003/05/16 19:58:29 deischen Exp $
  */
 #include <stdlib.h>
 #include <errno.h>
@@ -267,11 +267,12 @@
 					 * lock); we should be able to safely
 					 * set the state.
 					 */
-					THR_LOCK_SWITCH(curthread);
+					THR_SCHED_LOCK(curthread, curthread);
 					THR_SET_STATE(curthread, PS_COND_WAIT);
 
 					/* Remember the CV: */
 					curthread->data.cond = *cond;
+					THR_SCHED_UNLOCK(curthread, curthread);
 
 					/* Unlock the CV structure: */
 					THR_LOCK_RELEASE(curthread,
@@ -281,7 +282,6 @@
 					_thr_sched_switch(curthread);
 
 					curthread->data.cond = NULL;
-					THR_UNLOCK_SWITCH(curthread);
 
 					/*
 					 * XXX - This really isn't a good check
@@ -479,11 +479,12 @@
 					 * lock); we should be able to safely
 					 * set the state.
 					 */
-					THR_LOCK_SWITCH(curthread);
+					THR_SCHED_LOCK(curthread, curthread);
 					THR_SET_STATE(curthread, PS_COND_WAIT);
 
 					/* Remember the CV: */
 					curthread->data.cond = *cond;
+					THR_SCHED_UNLOCK(curthread, curthread);
 
 					/* Unlock the CV structure: */
 					THR_LOCK_RELEASE(curthread,
@@ -493,7 +494,6 @@
 					_thr_sched_switch(curthread);
 
 					curthread->data.cond = NULL;
-					THR_UNLOCK_SWITCH(curthread);
 
 					/*
 					 * XXX - This really isn't a good check

==== //depot/projects/ia64/lib/libpthread/thread/thr_exit.c#4 (text+ko) ====

@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.31 2003/04/28 23:56:11 deischen Exp $
+ * $FreeBSD: src/lib/libpthread/thread/thr_exit.c,v 1.32 2003/05/16 19:58:29 deischen Exp $
  */
 #include <errno.h>
 #include <unistd.h>
@@ -125,9 +125,8 @@
 	/* This thread will never be re-scheduled. */
 	THR_LOCK_SWITCH(curthread);
 	THR_SET_STATE(curthread, PS_DEAD);
-	_thr_sched_switch(curthread);
+	_thr_sched_switch_unlocked(curthread);
 	/* Never reach! */
-	THR_UNLOCK_SWITCH(curthread);
 
 	/* This point should not be reached. */
 	PANIC("Dead thread has resumed");

==== //depot/projects/ia64/lib/libpthread/thread/thr_init.c#9 (text+ko) ====

@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.51 2003/04/30 15:05:17 deischen Exp $
+ * $FreeBSD: src/lib/libpthread/thread/thr_init.c,v 1.52 2003/05/16 19:58:29 deischen Exp $
  */
 
 /* Allocate space for global thread variables here: */
@@ -72,6 +72,7 @@
 int	__pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
 int	__pthread_mutex_lock(pthread_mutex_t *);
 int	__pthread_mutex_trylock(pthread_mutex_t *);
+void	_thread_init_hack(void);
 
 static void init_private(void);
 static void init_main_thread(struct pthread *thread);
@@ -131,6 +132,7 @@
 	&_sigsuspend,
 	&_socket,
 	&_socketpair,
+	&_thread_init_hack,
 	&_wait4,
 	&_write,
 	&_writev

==== //depot/projects/ia64/lib/libpthread/thread/thr_join.c#4 (text+ko) ====

@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libpthread/thread/thr_join.c,v 1.24 2003/04/28 23:56:11 deischen Exp $
+ * $FreeBSD: src/lib/libpthread/thread/thr_join.c,v 1.25 2003/05/16 19:58:29 deischen Exp $
  */
 #include <errno.h>
 #include <pthread.h>
@@ -123,13 +123,15 @@
 			THR_SCHED_UNLOCK(curthread, pthread);
 			_thr_ref_delete(curthread, pthread);
 
-			THR_LOCK_SWITCH(curthread);
+			THR_SCHED_LOCK(curthread, curthread);
 			while (curthread->join_status.thread == pthread) {
 				THR_SET_STATE(curthread, PS_JOIN);
+				THR_SCHED_UNLOCK(curthread, curthread);
 				/* Schedule the next thread: */
 				_thr_sched_switch(curthread);
+				THR_SCHED_LOCK(curthread, curthread);
 			}
-			THR_UNLOCK_SWITCH(curthread);
+			THR_SCHED_UNLOCK(curthread, curthread);
 
 			/*
 			 * The thread return value and error are set by the

==== //depot/projects/ia64/lib/libpthread/thread/thr_kern.c#15 (text+ko) ====

@@ -33,7 +33,7 @@
  *
  */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libpthread/thread/thr_kern.c,v 1.64 2003/05/05 05:01:19 davidxu Exp $");
+__FBSDID("$FreeBSD: src/lib/libpthread/thread/thr_kern.c,v 1.65 2003/05/16 19:58:29 deischen Exp $");
 
 #include <sys/types.h>
 #include <sys/kse.h>
@@ -398,7 +398,6 @@
 	 */
 	ts.tv_sec = 0;
 	ts.tv_nsec = 1000000;  /* 1 sec */
-	KSE_SET_WAIT(curkse);
 	while (_LCK_BUSY(lu)) {
 		/*
 		 * Yield the kse and wait to be notified when the lock
@@ -408,14 +407,7 @@
 		curkse->k_mbx.km_flags |= KMF_NOUPCALL | KMF_NOCOMPLETED;
 		kse_release(&ts);
 		curkse->k_mbx.km_flags = saved_flags;
-
-		/*
-		 * Make sure that the wait flag is set again in case
-		 * we wokeup without the lock being granted.
-		 */
-		KSE_SET_WAIT(curkse);
 	}
-	KSE_CLEAR_WAIT(curkse);
 }
 
 void
@@ -423,17 +415,23 @@
 {
 	struct kse *curkse;
 	struct kse *kse;
+	struct kse_mailbox *mbx;
 
 	curkse = _get_curkse();
 	kse = (struct kse *)_LCK_GET_PRIVATE(lu);
 
 	if (kse == curkse)
 		PANIC("KSE trying to wake itself up in lock");
-	else if (KSE_WAITING(kse)) {
+	else {
+		mbx = &kse->k_mbx;
+		_lock_grant(lock, lu);
 		/*
 		 * Notify the owning kse that it has the lock.
+		 * It is safe to pass invalid address to kse_wakeup
+		 * even if the mailbox is not in kernel at all,
+		 * and waking up a wrong kse is also harmless.
 		 */
-		KSE_WAKEUP(kse);
+		kse_wakeup(mbx);
 	}
 }
 
@@ -446,30 +444,13 @@
 _thr_lock_wait(struct lock *lock, struct lockuser *lu)
 {
 	struct pthread *curthread = (struct pthread *)lu->lu_private;
-	int count;
 
-	/*
-	 * Spin for a bit.
-	 *
-	 * XXX - We probably want to make this a bit smarter.  It
-	 *       doesn't make sense to spin unless there is more
-	 *       than 1 CPU.  A thread that is holding one of these
-	 *       locks is prevented from being swapped out for another
-	 *       thread within the same scheduling entity.
-	 */
-	count = 0;
-	while (_LCK_BUSY(lu) && count < 300)
-		count++;
-	while (_LCK_BUSY(lu)) {
-		THR_LOCK_SWITCH(curthread);
-		if (_LCK_BUSY(lu)) {
-			/* Wait for the lock: */
-			atomic_store_rel_int(&curthread->need_wakeup, 1);
-			THR_SET_STATE(curthread, PS_LOCKWAIT);
-			_thr_sched_switch(curthread);
-		}
-		THR_UNLOCK_SWITCH(curthread);
-	}
+	do {
+		THR_SCHED_LOCK(curthread, curthread);
+		THR_SET_STATE(curthread, PS_LOCKWAIT);
+		THR_SCHED_UNLOCK(curthread, curthread);
+		_thr_sched_switch(curthread);
+	} while _LCK_BUSY(lu);
 }
 
 void
@@ -477,26 +458,14 @@
 {
 	struct pthread *thread;
 	struct pthread *curthread;
-	int unlock;
 
 	curthread = _get_curthread();
 	thread = (struct pthread *)_LCK_GET_PRIVATE(lu);
 
-	unlock = 0;
-	if (curthread->kseg == thread->kseg) {
-		/* Not already locked */
-		if (curthread->lock_switch == 0) {
-			THR_SCHED_LOCK(curthread, thread);
-			unlock = 1;
-		}
-	} else {
-		THR_SCHED_LOCK(curthread, thread);
-		unlock = 1;
-	}
+	THR_SCHED_LOCK(curthread, thread);
+	_lock_grant(lock, lu);
 	_thr_setrunnable_unlocked(thread);
-	atomic_store_rel_int(&thread->need_wakeup, 0);
-	if (unlock)
-		THR_SCHED_UNLOCK(curthread, thread);
+	THR_SCHED_UNLOCK(curthread, thread);
 }
 
 kse_critical_t
@@ -537,27 +506,42 @@
 	THR_YIELD_CHECK(thread);
 }
 
+void
+_thr_sched_switch(struct pthread *curthread)
+{
+	struct kse *curkse;
+
+	(void)_kse_critical_enter();
+	curkse = _get_curkse();
+	KSE_SCHED_LOCK(curkse, curkse->k_kseg);
+	_thr_sched_switch_unlocked(curthread);
+}
+
 /*
  * XXX - We may need to take the scheduling lock before calling
  *       this, or perhaps take the lock within here before
  *       doing anything else.
  */
 void
-_thr_sched_switch(struct pthread *curthread)
+_thr_sched_switch_unlocked(struct pthread *curthread)
 {
+	struct pthread *td;
 	struct pthread_sigframe psf;
 	struct kse *curkse;
-	volatile int once = 0;
+	int ret;
+	volatile int uts_once;
+	volatile int resume_once = 0;
 
 	/* We're in the scheduler, 5 by 5: */
-	THR_ASSERT(curthread->lock_switch, "lock_switch");
-	THR_ASSERT(_kse_in_critical(), "not in critical region");
 	curkse = _get_curkse();
 
 	curthread->need_switchout = 1;	/* The thread yielded on its own. */
 	curthread->critical_yield = 0;	/* No need to yield anymore. */
 	curthread->slice_usec = -1;	/* Restart the time slice. */
 
+	/* Thread can unlock the scheduler lock. */
+	curthread->lock_switch = 1;
+
 	/*
 	 * The signal frame is allocated off the stack because
 	 * a thread can be interrupted by other signals while
@@ -566,19 +550,95 @@
 	sigemptyset(&psf.psf_sigset);
 	curthread->curframe = &psf;
 
-	_thread_enter_uts(&curthread->tmbx, &curkse->k_mbx);
+	/*
+	 * Enter the scheduler if any one of the following is true:
+	 *
+	 *   o The current thread is dead; it's stack needs to be
+	 *     cleaned up and it can't be done while operating on
+	 *     it.
+	 *   o There are no runnable threads.
+	 *   o The next thread to run won't unlock the scheduler
+	 *     lock.  A side note: the current thread may be run
+	 *     instead of the next thread in the run queue, but
+	 *     we don't bother checking for that.
+	 */
+	if ((curthread->state == PS_DEAD) ||
+	    (((td = KSE_RUNQ_FIRST(curkse)) == NULL) &&
+	    (curthread->state != PS_RUNNING)) ||
+	    ((td != NULL) && (td->lock_switch == 0)))
+		_thread_enter_uts(&curthread->tmbx, &curkse->k_mbx);
+	else {
+		uts_once = 0;
+		THR_GETCONTEXT(&curthread->tmbx.tm_context);
+		if (uts_once == 0) {
+			uts_once = 1;
+
+			/* Switchout the current thread. */
+			kse_switchout_thread(curkse, curthread);
+
+		 	/* Choose another thread to run. */
+			td = KSE_RUNQ_FIRST(curkse);
+			KSE_RUNQ_REMOVE(curkse, td);
+			curkse->k_curthread = td;
+
+			/*
+			 * Make sure the current thread's kse points to
+			 * this kse.
+			 */
+			td->kse = curkse;
+
+			/*
+			 * Reset accounting.
+			 */
+			td->tmbx.tm_uticks = 0;
+			td->tmbx.tm_sticks = 0;
+
+			/*
+			 * Reset the time slice if this thread is running
+			 * for the first time or running again after using
+			 * its full time slice allocation.
+			 */
+			if (td->slice_usec == -1)
+				td->slice_usec = 0;
+
+			/* Mark the thread active. */
+			td->active = 1;
+
+			/* Remove the frame reference. */
+			td->curframe = NULL;
+
+			/*
+			 * Continue the thread at its current frame:
+			 */
+			ret = _thread_switch(&td->tmbx, NULL);
+			/* This point should not be reached. */
+			if (ret != 0)
+				PANIC("Bad return from _thread_switch");
+			PANIC("Thread has returned from _thread_switch");
+		}
+	}
+
+	if (curthread->lock_switch != 0) {
+		/*
+		 * Unlock the scheduling queue and leave the
+		 * critical region.
+		 */
+		/* Don't trust this after a switch! */
+		curkse = _get_curkse();
 
+		curthread->lock_switch = 0;
+		KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
+		_kse_critical_leave(&curthread->tmbx);
+	}
 	/*
 	 * This thread is being resumed; check for cancellations.
 	 */
-	if ((once == 0) && (!THR_IN_CRITICAL(curthread))) {
-		once = 1;
-		curthread->critical_count++;
-		THR_UNLOCK_SWITCH(curthread);
-		curthread->critical_count--;
+	if ((resume_once == 0) && (!THR_IN_CRITICAL(curthread))) {
+		resume_once = 1;
 		thr_resume_check(curthread, &curthread->tmbx.tm_context, &psf);
-		THR_LOCK_SWITCH(curthread);
 	}
+
+	THR_ACTIVATE_LAST_LOCK(curthread);
 }
 
 /*
@@ -743,12 +803,10 @@
 		KSE_CLEAR_WAIT(curkse);
 	}
 
+	/* Lock the scheduling lock. */
 	curthread = curkse->k_curthread;
-	if (curthread == NULL || curthread->lock_switch == 0) {
-		/*
-		 * curthread was preempted by upcall, it is not a volunteer
-		 * context switch. Lock the scheduling lock.
-		 */
+	if ((curthread == NULL) || (curthread->need_switchout == 0)) {
+		/* This is an upcall; take the scheduler lock. */
 		KSE_SCHED_LOCK(curkse, curkse->k_kseg);
 	}
 
@@ -798,14 +856,9 @@
 		DBG_MSG("Continuing thread %p in critical region\n",
 		    curthread);
 		kse_wakeup_multi(curkse);
-		if (curthread->lock_switch) {
-			KSE_SCHED_LOCK(curkse, curkse->k_kseg);
-			ret = _thread_switch(&curthread->tmbx, 0);
-		} else {
-			KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
-			ret = _thread_switch(&curthread->tmbx,
-		    		&curkse->k_mbx.km_curthread);
-		}
+		KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
+		ret = _thread_switch(&curthread->tmbx,
+		    &curkse->k_mbx.km_curthread);
 		if (ret != 0)
 			PANIC("Can't resume thread in critical region\n");
 	}
@@ -895,9 +948,6 @@
 
 	kse_wakeup_multi(curkse);
 
-	/* Unlock the scheduling queue: */
-	KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
-
 	/*
 	 * The thread's current signal frame will only be NULL if it
 	 * is being resumed after being blocked in the kernel.  In
@@ -906,25 +956,30 @@
 	 * signal frame to the thread's context.
 	 */
 #ifdef NOT_YET
-	if ((curframe == NULL) && ((curthread->check_pending != 0) ||
+	if ((curframe == NULL) && ((curthread->have_signals != 0) ||
 	    (((curthread->cancelflags & THR_AT_CANCEL_POINT) == 0) &&
 	    ((curthread->cancelflags & PTHREAD_CANCEL_ASYNCHRONOUS) != 0))))
 		signalcontext(&curthread->tmbx.tm_context, 0,
 		    (__sighandler_t *)thr_resume_wrapper);
 #else
-	if ((curframe == NULL) && (curthread->check_pending != 0))
+	if ((curframe == NULL) && (curthread->have_signals != 0))
 		signalcontext(&curthread->tmbx.tm_context, 0,
 		    (__sighandler_t *)thr_resume_wrapper);
 #endif
 	/*
 	 * Continue the thread at its current frame:
 	 */
-	if (curthread->lock_switch) {
-		KSE_SCHED_LOCK(curkse, curkse->k_kseg);
-		ret = _thread_switch(&curthread->tmbx, 0);
+	if (curthread->lock_switch != 0) {
+		/*
+		 * This thread came from a scheduler switch; it will
+		 * unlock the scheduler lock and set the mailbox.
+		 */
+		ret = _thread_switch(&curthread->tmbx, NULL);
 	} else {
+		/* This thread won't unlock the scheduler lock. */
+		KSE_SCHED_UNLOCK(curkse, curkse->k_kseg);
 		ret = _thread_switch(&curthread->tmbx,
-		 	&curkse->k_mbx.km_curthread);
+		    &curkse->k_mbx.km_curthread);
 	}
 	if (ret != 0)
 		PANIC("Thread has returned from _thread_switch");
@@ -977,9 +1032,9 @@
     struct pthread_sigframe *psf)
 {
 	/* Check signals before cancellations. */
-	while (curthread->check_pending != 0) {
+	while (curthread->have_signals != 0) {
 		/* Clear the pending flag. */
-		curthread->check_pending = 0;
+		curthread->have_signals = 0;
 
 		/*
 		 * It's perfectly valid, though not portable, for
@@ -1262,6 +1317,11 @@
 					THR_SET_STATE(thread, PS_SUSPENDED);
 				else
 					KSE_RUNQ_INSERT_TAIL(kse, thread);
+				if ((thread->kse != kse) &&
+				    (thread->kse->k_curthread == thread)) {
+					thread->kse->k_curthread = NULL;
+					thread->active = 0;
+				}
 			}
 			completed = completed->tm_next;
 		}
@@ -1360,12 +1420,15 @@
 kse_switchout_thread(struct kse *kse, struct pthread *thread)
 {
 	int level;
+	int i;
 
 	/*
 	 * Place the currently running thread into the
 	 * appropriate queue(s).
 	 */
 	DBG_MSG("Switching out thread %p, state %d\n", thread, thread->state);
+

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list