Source-Changes-HG archive

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

[src/trunk]: src/sys/kern A couple more tweaks to avoid reading the lock word.



details:   https://anonhg.NetBSD.org/src/rev/66c54b342d06
branches:  trunk
changeset: 846725:66c54b342d06
user:      ad <ad%NetBSD.org@localhost>
date:      Fri Nov 29 20:50:54 2019 +0000

description:
A couple more tweaks to avoid reading the lock word.

diffstat:

 sys/kern/kern_rwlock.c |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (67 lines):

diff -r 1caa471dd8e3 -r 66c54b342d06 sys/kern/kern_rwlock.c
--- a/sys/kern/kern_rwlock.c    Fri Nov 29 20:31:35 2019 +0000
+++ b/sys/kern/kern_rwlock.c    Fri Nov 29 20:50:54 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_rwlock.c,v 1.56 2019/11/29 20:04:54 riastradh Exp $       */
+/*     $NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $      */
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.56 2019/11/29 20:04:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.57 2019/11/29 20:50:54 ad Exp $");
 
 #define        __RWLOCK_PRIVATE
 
@@ -417,10 +417,11 @@
                 * No need for a memory barrier because of context switch.
                 * If not handed the lock, then spin again.
                 */
-               if (op == RW_READER || (rw->rw_owner & RW_THREAD) == curthread)
+               if (op == RW_READER)
                        break;
-
                owner = rw->rw_owner;
+               if ((owner & RW_THREAD) == curthread)
+                       break;
        }
        KPREEMPT_ENABLE(curlwp);
 
@@ -476,14 +477,13 @@
         * lock would become unowned.
         */
        RW_MEMBAR_EXIT();
-       for (;;) {
+       for (;; owner = next) {
                newown = (owner - decr);
                if ((newown & (RW_THREAD | RW_HAS_WAITERS)) == RW_HAS_WAITERS)
                        break;
                next = rw_cas(rw, owner, newown);
                if (__predict_true(next == owner))
                        return;
-               owner = next;
        }
 
        /*
@@ -568,15 +568,15 @@
                need_wait = RW_WRITE_LOCKED | RW_THREAD;
        }
 
-       for (owner = rw->rw_owner;; owner = next) {
-               if (__predict_false((owner & need_wait) != 0))
-                       return 0;
+       for (owner = 0;; owner = next) {
                next = rw_cas(rw, owner, owner + incr);
                if (__predict_true(next == owner)) {
                        /* Got it! */
                        RW_MEMBAR_ENTER();
                        break;
                }
+               if (__predict_false((owner & need_wait) != 0))
+                       return 0;
        }
 
        RW_WANTLOCK(rw, op);



Home | Main Index | Thread Index | Old Index