From owner-p4-projects@FreeBSD.ORG Tue Apr 22 08:16:51 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C2F711065672; Tue, 22 Apr 2008 08:16:51 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 85095106564A for ; Tue, 22 Apr 2008 08:16:51 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 6F1FF8FC17 for ; Tue, 22 Apr 2008 08:16:51 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m3M8GpI3007779 for ; Tue, 22 Apr 2008 08:16:51 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m3M8Gpkp007777 for perforce@freebsd.org; Tue, 22 Apr 2008 08:16:51 GMT (envelope-from jb@freebsd.org) Date: Tue, 22 Apr 2008 08:16:51 GMT Message-Id: <200804220816.m3M8Gpkp007777@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 140391 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Apr 2008 08:16:52 -0000 http://perforce.freebsd.org/chv.cgi?CH=140391 Change 140391 by jb@freebsd3 on 2008/04/22 08:16:45 IFC FreeBSD ID loopback Affected files ... .. //depot/projects/dtrace/src/lib/libthr/thread/thr_rtld.c#6 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/kern/opensolaris_string.c#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/rpc/xdr.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/acl.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/bitmap.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/byteorder.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/callb.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/cpupart.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/cpuvar.h#3 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/dkio.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/mntent.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/objfs.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/sysmacros.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/taskq.h#2 integrate .. //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/taskq_impl.h#2 integrate Differences ... ==== //depot/projects/dtrace/src/lib/libthr/thread/thr_rtld.c#6 (text) ==== @@ -23,7 +23,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $FreeBSD: src/lib/libthr/thread/thr_rtld.c,v 1.7 2008/04/02 07:41:24 davidxu Exp $ + * $FreeBSD: src/lib/libthr/thread/thr_rtld.c,v 1.8 2008/04/22 06:44:11 davidxu Exp $ * */ @@ -40,8 +40,6 @@ extern int errno; #define CACHE_LINE_SIZE 64 -#define WAFLAG 0x1 -#define RC_INCR 0x2 static int _thr_rtld_clr_flag(int); static void *_thr_rtld_lock_create(void); @@ -52,11 +50,7 @@ static void _thr_rtld_wlock_acquire(void *); struct rtld_lock { - volatile int lock; - volatile int rd_waiters; - volatile int wr_waiters; - volatile long rd_cv; - volatile long wr_cv; + struct urwlock lock; void *base; }; @@ -67,19 +61,22 @@ char *p; uintptr_t r; struct rtld_lock *l; + size_t size; - THR_ASSERT(sizeof(struct rtld_lock) <= CACHE_LINE_SIZE, - "rtld_lock too large"); - base = calloc(1, CACHE_LINE_SIZE); + size = CACHE_LINE_SIZE; + while (size < sizeof(struct rtld_lock)) + size <<= 1; + base = calloc(1, size); p = (char *)base; if ((uintptr_t)p % CACHE_LINE_SIZE != 0) { free(base); - base = calloc(1, 2 * CACHE_LINE_SIZE); + base = calloc(1, size + CACHE_LINE_SIZE); p = (char *)base; if ((r = (uintptr_t)p % CACHE_LINE_SIZE) != 0) p += CACHE_LINE_SIZE - r; } l = (struct rtld_lock *)p; + l->lock.rw_flags = URWLOCK_PREFER_READER; l->base = base; return (l); } @@ -110,7 +107,6 @@ { struct pthread *curthread; struct rtld_lock *l; - long v; int errsave; curthread = _get_curthread(); @@ -118,18 +114,8 @@ l = (struct rtld_lock *)lock; THR_CRITICAL_ENTER(curthread); - atomic_add_acq_int(&l->lock, RC_INCR); - if (!(l->lock & WAFLAG)) { - RESTORE_ERRNO(); - return; - } - v = l->rd_cv; - atomic_add_int(&l->rd_waiters, 1); - while (l->lock & WAFLAG) { - _thr_umtx_wait(&l->rd_cv, v, NULL); - v = l->rd_cv; - } - atomic_add_int(&l->rd_waiters, -1); + while (_thr_rwlock_rdlock(&l->lock, 0, NULL) != 0) + ; RESTORE_ERRNO(); } @@ -138,7 +124,6 @@ { struct pthread *curthread; struct rtld_lock *l; - long v; int errsave; curthread = _get_curthread(); @@ -146,19 +131,9 @@ l = (struct rtld_lock *)lock; _thr_signal_block(curthread); - for (;;) { - if (atomic_cmpset_acq_int(&l->lock, 0, WAFLAG)) { - RESTORE_ERRNO(); - return; - } - v = l->wr_cv; - atomic_add_int(&l->wr_waiters, 1); - while (l->lock != 0) { - _thr_umtx_wait(&l->wr_cv, v, NULL); - v = l->wr_cv; - } - atomic_add_int(&l->wr_waiters, -1); - } + while (_thr_rwlock_wrlock(&l->lock, NULL) != 0) + ; + RESTORE_ERRNO(); } static void @@ -166,29 +141,20 @@ { struct pthread *curthread; struct rtld_lock *l; + int32_t state; int errsave; curthread = _get_curthread(); SAVE_ERRNO(); l = (struct rtld_lock *)lock; - if ((l->lock & WAFLAG) == 0) { - atomic_add_rel_int(&l->lock, -RC_INCR); - if (l->lock == 0 && l->wr_waiters) { - atomic_add_long(&l->wr_cv, 1); - _thr_umtx_wake(&l->wr_cv, l->wr_waiters); + state = l->lock.rw_state; + if (_thr_rwlock_unlock(&l->lock) == 0) { + if ((state & URWLOCK_WRITE_OWNER) == 0) { + THR_CRITICAL_LEAVE(curthread); + } else { + _thr_signal_unblock(curthread); } - THR_CRITICAL_LEAVE(curthread); - } else { - atomic_add_rel_int(&l->lock, -WAFLAG); - if (l->lock == 0 && l->wr_waiters) { - atomic_add_long(&l->wr_cv, 1); - _thr_umtx_wake(&l->wr_cv, l->wr_waiters); - } else if (l->rd_waiters) { - atomic_add_long(&l->rd_cv, 1); - _thr_umtx_wake(&l->rd_cv, l->rd_waiters); - } - _thr_signal_unblock(curthread); } RESTORE_ERRNO(); } ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/kern/opensolaris_string.c#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/kern/opensolaris_string.c,v 1.4 2008/04/22 07:42:59 jb Exp $ */ /* * Copyright 2007 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/rpc/xdr.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/rpc/xdr.h,v 1.4 2008/04/22 07:42:59 jb Exp $ */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/acl.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/acl.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/bitmap.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/bitmap.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/byteorder.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/byteorder.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/callb.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/callb.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/cpupart.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/cpupart.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/cpuvar.h#3 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/cpuvar.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/dkio.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/dkio.h,v 1.3 2008/04/22 07:42:59 jb Exp $ */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/mntent.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/mntent.h,v 1.3 2008/04/22 07:43:00 jb Exp $ */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/objfs.h#2 (text+ko) ==== @@ -17,6 +17,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/objfs.h,v 1.3 2008/04/22 07:43:00 jb Exp $ */ #ifndef _COMPAT_OPENSOLARIS_SYS_OBJFS_H ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/sysmacros.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/sysmacros.h,v 1.3 2008/04/22 07:43:00 jb Exp $ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/taskq.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/taskq.h,v 1.3 2008/04/22 07:43:00 jb Exp $ */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. ==== //depot/projects/dtrace/src/sys/cddl/compat/opensolaris/sys/taskq_impl.h#2 (text+ko) ==== @@ -18,6 +18,8 @@ * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END + * + * $FreeBSD: src/sys/cddl/compat/opensolaris/sys/taskq_impl.h,v 1.3 2008/04/22 07:43:00 jb Exp $ */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved.