Print this page
11909 THREAD_KPRI_RELEASE does nothing of the sort
Reviewed by: Bryan Cantrill <bryan@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

@@ -22,11 +22,11 @@
  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*
- * Copyright (c) 2013, Joyent, Inc.  All rights reserved.
+ * Copyright 2019 Joyent, Inc.
  */
 
 #include <sys/param.h>
 #include <sys/thread.h>
 #include <sys/cmn_err.h>

@@ -267,13 +267,10 @@
 void (*rw_lock_delay)(uint_t) = NULL;
 
 /*
  * Full-service implementation of rw_enter() to handle all the hard cases.
  * Called from the assembly version if anything complicated is going on.
- * The only semantic difference between calling rw_enter() and calling
- * rw_enter_sleep() directly is that we assume the caller has already done
- * a THREAD_KPRI_REQUEST() in the RW_READER cases.
  */
 void
 rw_enter_sleep(rwlock_impl_t *lp, krw_t rw)
 {
         uintptr_t old, new, lock_value, lock_busy, lock_wait;

@@ -340,19 +337,17 @@
                         turnstile_exit(lp);
                         continue;
                 }
 
                 /*
-                 * We really are going to block.  Bump the stats, and drop
-                 * kpri if we're a reader.
+                 * We really are going to block, so bump the stats.
                  */
                 ASSERT(lp->rw_wwwh & lock_wait);
                 ASSERT(lp->rw_wwwh & RW_LOCKED);
 
                 sleep_time = -gethrtime();
                 if (rw != RW_WRITER) {
-                        THREAD_KPRI_RELEASE();
                         CPU_STATS_ADDQ(CPU, sys, rw_rdfails, 1);
                         (void) turnstile_block(ts, TS_READER_Q, lp,
                             &rw_sobj_ops, NULL, NULL);
                 } else {
                         CPU_STATS_ADDQ(CPU, sys, rw_wrfails, 1);

@@ -364,12 +359,12 @@
                 LOCKSTAT_RECORD4(LS_RW_ENTER_BLOCK, lp, sleep_time, rw,
                     (old & RW_WRITE_LOCKED) ? 1 : 0,
                     old >> RW_HOLD_COUNT_SHIFT);
 
                 /*
-                 * We wake up holding the lock (and having kpri if we're
-                 * a reader) via direct handoff from the previous owner.
+                 * We wake up holding the lock via direct handoff from the
+                 * previous owner.
                  */
                 break;
         }
 
         ASSERT(rw_locked(lp, rw));

@@ -392,11 +387,10 @@
         int count = 0;
 
         while (next_reader != NULL) {
                 if (DISP_PRIO(next_reader) < wpri)
                         break;
-                next_reader->t_kpri_req++;
                 next_reader = next_reader->t_link;
                 count++;
         }
         return (count);
 }

@@ -521,11 +515,10 @@
                 }
                 break;
         }
 
         if (lock_value == RW_READ_LOCK) {
-                THREAD_KPRI_RELEASE();
                 LOCKSTAT_RECORD(LS_RW_EXIT_RELEASE, lp, RW_READER);
         } else {
                 LOCKSTAT_RECORD(LS_RW_EXIT_RELEASE, lp, RW_WRITER);
         }
 }

@@ -537,15 +530,13 @@
         uintptr_t old;
 
         if (rw != RW_WRITER) {
                 uint_t backoff = 0;
                 int loop_count = 0;
-                THREAD_KPRI_REQUEST();
                 for (;;) {
                         if ((old = lp->rw_wwwh) & (rw == RW_READER ?
                             RW_WRITE_CLAIMED : RW_WRITE_LOCKED)) {
-                                THREAD_KPRI_RELEASE();
                                 return (0);
                         }
                         if (casip(&lp->rw_wwwh, old, old + RW_READ_LOCK) == old)
                                 break;
                         if (rw_lock_delay != NULL) {

@@ -571,11 +562,10 @@
 void
 rw_downgrade(krwlock_t *rwlp)
 {
         rwlock_impl_t *lp = (rwlock_impl_t *)rwlp;
 
-        THREAD_KPRI_REQUEST();
         membar_exit();
 
         if ((lp->rw_wwwh & RW_OWNER) != (uintptr_t)curthread) {
                 rw_panic("rw_downgrade: not owner", lp);
                 return;

@@ -610,11 +600,10 @@
                         return (0);
                 new = old + RW_WRITE_LOCK(curthread) - RW_READ_LOCK;
         } while (casip(&lp->rw_wwwh, old, new) != old);
 
         membar_enter();
-        THREAD_KPRI_RELEASE();
         LOCKSTAT_RECORD0(LS_RW_TRYUPGRADE_UPGRADE, lp);
         ASSERT(rw_locked(lp, RW_WRITER));
         return (1);
 }