From owner-p4-projects@FreeBSD.ORG Fri May 16 19:04:53 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2E57E37B404; Fri, 16 May 2003 19:04:53 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BF65637B401 for ; Fri, 16 May 2003 19:04:52 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id A767943F3F for ; Fri, 16 May 2003 19:04:51 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h4H24p0U006763 for ; Fri, 16 May 2003 19:04:51 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h4H24oeV006760 for perforce@freebsd.org; Fri, 16 May 2003 19:04:50 -0700 (PDT) Date: Fri, 16 May 2003 19:04:50 -0700 (PDT) Message-Id: <200305170204.h4H24oeV006760@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Subject: PERFORCE change 31369 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 May 2003 02:04:54 -0000 http://perforce.freebsd.org/chv.cgi?CH=31369 Change 31369 by marcel@marcel_nfs on 2003/05/16 19:03:59 IFia64 Affected files ... .. //depot/projects/ia64_epc/bin/chflags/chflags.1#3 integrate .. //depot/projects/ia64_epc/bin/pwd/pwd.1#3 integrate .. //depot/projects/ia64_epc/bin/sh/sh.1#4 integrate .. //depot/projects/ia64_epc/games/caesar/caesar.6#3 integrate .. //depot/projects/ia64_epc/games/grdc/grdc.6#3 integrate .. //depot/projects/ia64_epc/lib/libc/ia64/sys/brk.S#5 integrate .. //depot/projects/ia64_epc/lib/libc/ia64/sys/pipe.S#4 integrate .. //depot/projects/ia64_epc/lib/libc/ia64/sys/sbrk.S#5 integrate .. //depot/projects/ia64_epc/lib/libkvm/kvm_ia64.c#3 integrate .. //depot/projects/ia64_epc/lib/libpthread/sys/lock.c#3 integrate .. //depot/projects/ia64_epc/lib/libpthread/sys/lock.h#3 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_cond.c#7 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_exit.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_init.c#7 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_join.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_kern.c#10 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_mutex.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_nanosleep.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_private.h#10 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_sig.c#7 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_sigsuspend.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_sigwait.c#4 integrate .. //depot/projects/ia64_epc/lib/libpthread/thread/thr_yield.c#4 integrate .. //depot/projects/ia64_epc/libexec/ftpd/ftpd.8#4 integrate .. //depot/projects/ia64_epc/libexec/rtld-elf/rtld.1#4 integrate .. //depot/projects/ia64_epc/release/scripts/doFS.sh#9 integrate .. //depot/projects/ia64_epc/sbin/sysctl/sysctl.8#2 integrate .. //depot/projects/ia64_epc/share/man/man9/CTASSERT.9#1 branch .. //depot/projects/ia64_epc/share/man/man9/KASSERT.9#2 integrate .. //depot/projects/ia64_epc/share/man/man9/Makefile#6 integrate .. //depot/projects/ia64_epc/share/man/man9/VFS_SET.9#2 integrate .. //depot/projects/ia64_epc/share/man/man9/byteorder.9#3 integrate .. //depot/projects/ia64_epc/share/man/man9/mbuf.9#4 integrate .. //depot/projects/ia64_epc/share/man/man9/rman.9#1 branch .. //depot/projects/ia64_epc/share/man/man9/sleep.9#3 integrate .. //depot/projects/ia64_epc/sys/boot/i386/libi386/amd64_tramp.S#2 integrate .. //depot/projects/ia64_epc/sys/conf/Makefile.ia64#5 integrate .. //depot/projects/ia64_epc/sys/conf/files.ia64#14 integrate .. //depot/projects/ia64_epc/sys/conf/options.ia64#4 integrate .. //depot/projects/ia64_epc/sys/dev/md/md.c#9 integrate .. //depot/projects/ia64_epc/sys/ia64/ia32/ia32_sysvec.c#7 integrate .. //depot/projects/ia64_epc/sys/ia64/ia32/ia32_util.h#3 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/db_interface.c#10 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/db_trace.c#5 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/elf_machdep.c#5 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/exception.s#20 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/genassym.c#9 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/interrupt.c#3 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/locore.s#18 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/machdep.c#25 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/mp_machdep.c#11 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/pmap.c#16 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/support.s#6 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/trap.c#21 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/unaligned.c#4 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/unwind.c#5 integrate .. //depot/projects/ia64_epc/sys/ia64/ia64/vm_machdep.c#10 integrate .. //depot/projects/ia64_epc/sys/ia64/include/asm.h#6 integrate .. //depot/projects/ia64_epc/sys/ia64/include/cpu.h#9 integrate .. //depot/projects/ia64_epc/sys/ia64/include/db_machdep.h#4 integrate .. //depot/projects/ia64_epc/sys/ia64/include/frame.h#3 integrate .. //depot/projects/ia64_epc/sys/ia64/include/pcb.h#10 integrate .. //depot/projects/ia64_epc/sys/ia64/include/proc.h#3 integrate .. //depot/projects/ia64_epc/sys/ia64/include/reg.h#4 integrate .. //depot/projects/ia64_epc/sys/ia64/include/signal.h#5 integrate .. //depot/projects/ia64_epc/sys/ia64/include/smp.h#4 integrate .. //depot/projects/ia64_epc/sys/ia64/include/ucontext.h#5 integrate .. //depot/projects/ia64_epc/sys/ia64/include/unwind.h#5 integrate .. //depot/projects/ia64_epc/sys/ia64/include/vmparam.h#4 integrate .. //depot/projects/ia64_epc/sys/kern/kern_synch.c#14 integrate .. //depot/projects/ia64_epc/sys/kern/kern_thr.c#7 integrate .. //depot/projects/ia64_epc/sys/kern/kern_thread.c#18 integrate .. //depot/projects/ia64_epc/sys/kern/vfs_subr.c#15 integrate .. //depot/projects/ia64_epc/sys/sys/proc.h#17 integrate .. //depot/projects/ia64_epc/tools/tools/tinderbox/Makefile#4 integrate .. //depot/projects/ia64_epc/tools/tools/tinderbox/tbmaster.1#1 branch .. //depot/projects/ia64_epc/tools/tools/tinderbox/tbmaster.pl#8 integrate .. //depot/projects/ia64_epc/tools/tools/tinderbox/tinderbox.1#1 branch .. //depot/projects/ia64_epc/tools/tools/tinderbox/tinderbox.pl#7 integrate .. //depot/projects/ia64_epc/usr.bin/truss/ia64-fbsd.c#4 integrate Differences ... ==== //depot/projects/ia64_epc/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_epc/bin/pwd/pwd.1#3 (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_epc/bin/sh/sh.1#4 (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_epc/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_epc/games/grdc/grdc.6#3 (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_epc/lib/libc/ia64/sys/brk.S#5 (text+ko) ==== @@ -28,7 +28,7 @@ */ #include -__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" ==== //depot/projects/ia64_epc/lib/libc/ia64/sys/pipe.S#4 (text+ko) ==== @@ -28,7 +28,7 @@ */ #include -__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" ==== //depot/projects/ia64_epc/lib/libc/ia64/sys/sbrk.S#5 (text+ko) ==== @@ -28,7 +28,7 @@ */ #include -__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" ==== //depot/projects/ia64_epc/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 $ */ /* ==== //depot/projects/ia64_epc/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 @@ -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_epc/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_epc/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 #include @@ -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_epc/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 #include @@ -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_epc/lib/libpthread/thread/thr_init.c#7 (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_epc/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 #include @@ -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_epc/lib/libpthread/thread/thr_kern.c#10 (text+ko) ==== @@ -33,7 +33,7 @@ * */ #include -__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 #include @@ -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); + + THR_DEACTIVATE_LAST_LOCK(thread); if (thread->blocked != 0) { thread->active = 0; thread->need_switchout = 0; @@ -1473,6 +1536,15 @@ } thread->active = 0; thread->need_switchout = 0; + if (thread->check_pending != 0) { + /* Install pending signals into the frame. */ + thread->check_pending = 0; + for (i = 0; i < _SIG_MAXSIG; i++) { + if (sigismember(&thread->sigpend, i) && + !sigismember(&thread->tmbx.tm_context.uc_sigmask, i)) + _thr_sig_add(thread, i, &thread->siginfo[i]); + } + } } /* @@ -1584,37 +1656,6 @@ } void -_thr_sig_add(struct pthread *thread, int sig, siginfo_t *info, ucontext_t *ucp) -{ - struct kse *curkse; - - curkse = _get_curkse(); - - KSE_SCHED_LOCK(curkse, thread->kseg); - /* - * A threads assigned KSE can't change out from under us - * when we hold the scheduler lock. - */ - if (THR_IS_ACTIVE(thread)) { - /* Thread is active. Can't install the signal for it. */ - /* Make a note in the thread that it has a signal. */ - sigaddset(&thread->sigpend, sig); - thread->check_pending = 1; - } - else { - /* Make a note in the thread that it has a signal. */ - sigaddset(&thread->sigpend, sig); - thread->check_pending = 1; - - if (thread->blocked != 0) { - /* Tell the kernel to interrupt the thread. */ - kse_thr_interrupt(&thread->tmbx); - } - } - KSE_SCHED_UNLOCK(curkse, thread->kseg); -} - -void _thr_set_timeout(const struct timespec *timeout) { struct pthread *curthread = _get_curthread(); @@ -1675,14 +1716,14 @@ THR_SET_STATE(thread, PS_SUSPENDED); else THR_SET_STATE(thread, PS_RUNNING); - }else if (thread->state != PS_RUNNING) { + } else if (thread->state != PS_RUNNING) { if ((thread->flags & THR_FLAGS_IN_WAITQ) != 0) KSE_WAITQ_REMOVE(thread->kse, thread); if ((thread->flags & THR_FLAGS_SUSPENDED) != 0) THR_SET_STATE(thread, PS_SUSPENDED); else { THR_SET_STATE(thread, PS_RUNNING); - if ((thread->blocked == 0) && >>> TRUNCATED FOR MAIL (1000 lines) <<<