Module Name: src Committed By: snj Date: Wed May 13 00:33:32 UTC 2009
Modified Files: src/sys/kern [netbsd-5]: kern_rwlock.c Log Message: Pull up following revision(s) (requested by ad in ticket #725): sys/kern/kern_rwlock.c: revision 1.30 A workaround for a bug with some Opteron revisions where locked operations sometimes do not serve as memory barriers, allowing memory references to bleed outside of critical sections. It is possible that this is the reason for pkgbuild's longstanding crashiness. For rwlocks, always enable the explicit membars. They were disabled only on x86, and since they are not in the fast-path it's not a big deal. TODO: convert these to an atomic_membar_foo() or similar that does ordering between regular data references and atomic references. To generate a diff of this commit: cvs rdiff -u -r1.28 -r1.28.4.1 src/sys/kern/kern_rwlock.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/kern/kern_rwlock.c diff -u src/sys/kern/kern_rwlock.c:1.28 src/sys/kern/kern_rwlock.c:1.28.4.1 --- src/sys/kern/kern_rwlock.c:1.28 Tue Jul 29 16:13:39 2008 +++ src/sys/kern/kern_rwlock.c Wed May 13 00:33:32 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: kern_rwlock.c,v 1.28 2008/07/29 16:13:39 thorpej Exp $ */ +/* $NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $ */ /*- * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.28 2008/07/29 16:13:39 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.28.4.1 2009/05/13 00:33:32 snj Exp $"); #define __RWLOCK_PRIVATE @@ -329,9 +329,7 @@ ~RW_WRITE_WANTED); if (__predict_true(next == owner)) { /* Got it! */ -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_enter(); -#endif break; } @@ -453,9 +451,7 @@ * proceed to do direct handoff if there are waiters, and if the * lock would become unowned. */ -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_exit(); -#endif for (;;) { new = (owner - decr); if ((new & (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS) @@ -555,13 +551,11 @@ next = rw_cas(rw, owner, owner + incr); if (__predict_true(next == owner)) { /* Got it! */ + membar_enter(); break; } } -#ifndef __HAVE_ATOMIC_AS_MEMBAR - membar_enter(); -#endif RW_WANTLOCK(rw, op, true); RW_LOCKED(rw, op); RW_DASSERT(rw, (op != RW_READER && RW_OWNER(rw) == curthread) || @@ -588,10 +582,7 @@ RW_ASSERT(rw, RW_OWNER(rw) == curthread); RW_UNLOCKED(rw, RW_WRITER); -#ifndef __HAVE_ATOMIC_AS_MEMBAR membar_producer(); -#endif - owner = rw->rw_owner; if ((owner & RW_HAS_WAITERS) == 0) { /* @@ -685,8 +676,10 @@ } new = curthread | RW_WRITE_LOCKED | (owner & ~RW_THREAD); next = rw_cas(rw, owner, new); - if (__predict_true(next == owner)) + if (__predict_true(next == owner)) { + membar_producer(); break; + } } RW_UNLOCKED(rw, RW_READER); @@ -694,10 +687,6 @@ RW_DASSERT(rw, rw->rw_owner & RW_WRITE_LOCKED); RW_DASSERT(rw, RW_OWNER(rw) == curthread); -#ifndef __HAVE_ATOMIC_AS_MEMBAR - membar_producer(); -#endif - return 1; }