[BACK]Return to kern_mutex.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/kern/kern_mutex.c between version 1.6 and 1.28

version 1.6, 2007/02/26 19:11:28 version 1.28, 2008/01/04 21:18:09
Line 44 
Line 44 
  *          Richard McDougall.   *          Richard McDougall.
  */   */
   
 #include "opt_multiprocessor.h"  
   
 #define __MUTEX_PRIVATE  #define __MUTEX_PRIVATE
   
 #include <sys/cdefs.h>  #include <sys/cdefs.h>
 __KERNEL_RCSID(0, "$NetBSD$");  __KERNEL_RCSID(0, "$NetBSD$");
   
   #include "opt_multiprocessor.h"
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/proc.h>  #include <sys/proc.h>
 #include <sys/mutex.h>  #include <sys/mutex.h>
Line 59  __KERNEL_RCSID(0, "$NetBSD$");
Line 59  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/systm.h>  #include <sys/systm.h>
 #include <sys/lockdebug.h>  #include <sys/lockdebug.h>
 #include <sys/kernel.h>  #include <sys/kernel.h>
   #include <sys/atomic.h>
   #include <sys/intr.h>
   
 #include <dev/lockstat.h>  #include <dev/lockstat.h>
   
 #include <machine/intr.h>  #include <machine/lock.h>
   
 /*  /*
  * When not running a debug kernel, spin mutexes are not much   * When not running a debug kernel, spin mutexes are not much
Line 78  __KERNEL_RCSID(0, "$NetBSD$");
Line 80  __KERNEL_RCSID(0, "$NetBSD$");
  */   */
   
 #define MUTEX_WANTLOCK(mtx)                                     \  #define MUTEX_WANTLOCK(mtx)                                     \
     LOCKDEBUG_WANTLOCK(MUTEX_GETID(mtx),                        \      LOCKDEBUG_WANTLOCK(MUTEX_DEBUG_P(mtx), (mtx),               \
         (uintptr_t)__builtin_return_address(0), 0)          (uintptr_t)__builtin_return_address(0), 0)
 #define MUTEX_LOCKED(mtx)                                       \  #define MUTEX_LOCKED(mtx)                                       \
     LOCKDEBUG_LOCKED(MUTEX_GETID(mtx),                          \      LOCKDEBUG_LOCKED(MUTEX_DEBUG_P(mtx), (mtx),                 \
         (uintptr_t)__builtin_return_address(0), 0)          (uintptr_t)__builtin_return_address(0), 0)
 #define MUTEX_UNLOCKED(mtx)                                     \  #define MUTEX_UNLOCKED(mtx)                                     \
     LOCKDEBUG_UNLOCKED(MUTEX_GETID(mtx),                        \      LOCKDEBUG_UNLOCKED(MUTEX_DEBUG_P(mtx), (mtx),               \
         (uintptr_t)__builtin_return_address(0), 0)          (uintptr_t)__builtin_return_address(0), 0)
 #define MUTEX_ABORT(mtx, msg)                                   \  #define MUTEX_ABORT(mtx, msg)                                   \
     mutex_abort(mtx, __FUNCTION__, msg)      mutex_abort(mtx, __func__, msg)
   
 #if defined(LOCKDEBUG)  #if defined(LOCKDEBUG)
   
Line 120  do {        \
Line 122  do {        \
 /*  /*
  * Spin mutex SPL save / restore.   * Spin mutex SPL save / restore.
  */   */
   #ifndef MUTEX_COUNT_BIAS
   #define MUTEX_COUNT_BIAS        0
   #endif
   
 #define MUTEX_SPIN_SPLRAISE(mtx)                                        \  #define MUTEX_SPIN_SPLRAISE(mtx)                                        \
 do {                                                                    \  do {                                                                    \
Line 127  do {         \
Line 132  do {         \
         int x__cnt, s;                                                  \          int x__cnt, s;                                                  \
         x__cnt = x__ci->ci_mtx_count--;                                 \          x__cnt = x__ci->ci_mtx_count--;                                 \
         s = splraiseipl(mtx->mtx_ipl);                                  \          s = splraiseipl(mtx->mtx_ipl);                                  \
         if (x__cnt == 0)                                                \          if (x__cnt == MUTEX_COUNT_BIAS)                                 \
                 x__ci->ci_mtx_oldspl = (s);                             \                  x__ci->ci_mtx_oldspl = (s);                             \
 } while (/* CONSTCOND */ 0)  } while (/* CONSTCOND */ 0)
   
Line 136  do {         \
Line 141  do {         \
         struct cpu_info *x__ci = curcpu();                              \          struct cpu_info *x__ci = curcpu();                              \
         int s = x__ci->ci_mtx_oldspl;                                   \          int s = x__ci->ci_mtx_oldspl;                                   \
         __insn_barrier();                                               \          __insn_barrier();                                               \
         if (++(x__ci->ci_mtx_count) == 0)                               \          if (++(x__ci->ci_mtx_count) == MUTEX_COUNT_BIAS)                \
                 splx(s);                                                \                  splx(s);                                                \
 } while (/* CONSTCOND */ 0)  } while (/* CONSTCOND */ 0)
   
Line 151  do {         \
Line 156  do {         \
   
 #define MUTEX_OWNER(owner)                                              \  #define MUTEX_OWNER(owner)                                              \
         (owner & MUTEX_THREAD)          (owner & MUTEX_THREAD)
 #define MUTEX_OWNED(owner)                                              \  
         (owner != 0)  
 #define MUTEX_HAS_WAITERS(mtx)                                          \  #define MUTEX_HAS_WAITERS(mtx)                                          \
         (((int)(mtx)->mtx_owner & MUTEX_BIT_WAITERS) != 0)          (((int)(mtx)->mtx_owner & MUTEX_BIT_WAITERS) != 0)
   
 #define MUTEX_INITIALIZE_ADAPTIVE(mtx, id)                              \  #define MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug)                         \
 do {                                                                    \  do {                                                                    \
         (mtx)->mtx_id = (id);                                           \          if (dodebug)                                                    \
                   (mtx)->mtx_owner |= MUTEX_BIT_DEBUG;                    \
 } while (/* CONSTCOND */ 0);  } while (/* CONSTCOND */ 0);
   
 #define MUTEX_INITIALIZE_SPIN(mtx, id, ipl)                             \  #define MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl)                        \
 do {                                                                    \  do {                                                                    \
         (mtx)->mtx_owner = MUTEX_BIT_SPIN;                              \          (mtx)->mtx_owner = MUTEX_BIT_SPIN;                              \
           if (dodebug)                                                    \
                   (mtx)->mtx_owner |= MUTEX_BIT_DEBUG;                    \
         (mtx)->mtx_ipl = makeiplcookie((ipl));                          \          (mtx)->mtx_ipl = makeiplcookie((ipl));                          \
         (mtx)->mtx_id = (id);                                           \  
         __cpu_simple_lock_init(&(mtx)->mtx_lock);                       \          __cpu_simple_lock_init(&(mtx)->mtx_lock);                       \
 } while (/* CONSTCOND */ 0)  } while (/* CONSTCOND */ 0)
   
 #define MUTEX_DESTROY(mtx)                                              \  #define MUTEX_DESTROY(mtx)                                              \
 do {                                                                    \  do {                                                                    \
         (mtx)->mtx_owner = MUTEX_THREAD;                                \          (mtx)->mtx_owner = MUTEX_THREAD;                                \
         (mtx)->mtx_id = -1;                                             \  
 } while (/* CONSTCOND */ 0);  } while (/* CONSTCOND */ 0);
   
 #define MUTEX_SPIN_P(mtx)               \  #define MUTEX_SPIN_P(mtx)               \
Line 180  do {         \
Line 184  do {         \
 #define MUTEX_ADAPTIVE_P(mtx)           \  #define MUTEX_ADAPTIVE_P(mtx)           \
     (((mtx)->mtx_owner & MUTEX_BIT_SPIN) == 0)      (((mtx)->mtx_owner & MUTEX_BIT_SPIN) == 0)
   
 #define MUTEX_GETID(mtx)                ((mtx)->mtx_id)  #define MUTEX_DEBUG_P(mtx)      (((mtx)->mtx_owner & MUTEX_BIT_DEBUG) != 0)
   #if defined(LOCKDEBUG)
   #define MUTEX_OWNED(owner)              (((owner) & ~MUTEX_BIT_DEBUG) != 0)
   #define MUTEX_INHERITDEBUG(new, old)    (new) |= (old) & MUTEX_BIT_DEBUG
   #else /* defined(LOCKDEBUG) */
   #define MUTEX_OWNED(owner)              ((owner) != 0)
   #define MUTEX_INHERITDEBUG(new, old)    /* nothing */
   #endif /* defined(LOCKDEBUG) */
   
 static inline int  static inline int
 MUTEX_ACQUIRE(kmutex_t *mtx, uintptr_t curthread)  MUTEX_ACQUIRE(kmutex_t *mtx, uintptr_t curthread)
 {  {
         int rv;          int rv;
         rv = MUTEX_CAS(&mtx->mtx_owner, 0UL, curthread);          uintptr_t old = 0;
         MUTEX_RECEIVE();          uintptr_t new = curthread;
   
           MUTEX_INHERITDEBUG(old, mtx->mtx_owner);
           MUTEX_INHERITDEBUG(new, old);
           rv = MUTEX_CAS(&mtx->mtx_owner, old, new);
           MUTEX_RECEIVE(mtx);
         return rv;          return rv;
 }  }
   
Line 196  MUTEX_SET_WAITERS(kmutex_t *mtx, uintptr
Line 212  MUTEX_SET_WAITERS(kmutex_t *mtx, uintptr
 {  {
         int rv;          int rv;
         rv = MUTEX_CAS(&mtx->mtx_owner, owner, owner | MUTEX_BIT_WAITERS);          rv = MUTEX_CAS(&mtx->mtx_owner, owner, owner | MUTEX_BIT_WAITERS);
         MUTEX_RECEIVE();          MUTEX_RECEIVE(mtx);
         return rv;          return rv;
 }  }
   
 static inline void  static inline void
 MUTEX_RELEASE(kmutex_t *mtx)  MUTEX_RELEASE(kmutex_t *mtx)
 {  {
         MUTEX_GIVE();          uintptr_t new;
         mtx->mtx_owner = 0;  
           MUTEX_GIVE(mtx);
           new = 0;
           MUTEX_INHERITDEBUG(new, mtx->mtx_owner);
           mtx->mtx_owner = new;
 }  }
   
 static inline void  static inline void
Line 224  MUTEX_CLEAR_WAITERS(kmutex_t *mtx)
Line 244  MUTEX_CLEAR_WAITERS(kmutex_t *mtx)
 #endif  #endif
   
 #ifndef __HAVE_MUTEX_STUBS  #ifndef __HAVE_MUTEX_STUBS
 __strong_alias(mutex_enter, mutex_vector_enter);  __strong_alias(mutex_enter,mutex_vector_enter);
 __strong_alias(mutex_exit, mutex_vector_exit);  __strong_alias(mutex_exit,mutex_vector_exit);
 #endif  #endif
   
 #ifndef __HAVE_SPIN_MUTEX_STUBS  #ifndef __HAVE_SPIN_MUTEX_STUBS
 __strong_alias(mutex_spin_enter, mutex_vector_enter);  __strong_alias(mutex_spin_enter,mutex_vector_enter);
 __strong_alias(mutex_spin_exit, mutex_vector_exit);  __strong_alias(mutex_spin_exit,mutex_vector_exit);
 #endif  #endif
   
 void    mutex_abort(kmutex_t *, const char *, const char *);  void    mutex_abort(kmutex_t *, const char *, const char *);
 void    mutex_dump(volatile void *);  void    mutex_dump(volatile void *);
 int     mutex_onproc(uintptr_t, struct cpu_info **);  int     mutex_onproc(uintptr_t, struct cpu_info **);
 static struct lwp *mutex_owner(wchan_t);  
   
 lockops_t mutex_spin_lockops = {  lockops_t mutex_spin_lockops = {
         "Mutex",          "Mutex",
Line 255  syncobj_t mutex_syncobj = {
Line 274  syncobj_t mutex_syncobj = {
         turnstile_unsleep,          turnstile_unsleep,
         turnstile_changepri,          turnstile_changepri,
         sleepq_lendpri,          sleepq_lendpri,
         mutex_owner,          (void *)mutex_owner,
 };  };
   
 /*  /*
Line 280  mutex_dump(volatile void *cookie)
Line 299  mutex_dump(volatile void *cookie)
  *      generates a lot of machine code in the DIAGNOSTIC case, so   *      generates a lot of machine code in the DIAGNOSTIC case, so
  *      we ask the compiler to not inline it.   *      we ask the compiler to not inline it.
  */   */
 __attribute ((noinline)) __attribute ((noreturn)) void  
   #if __GNUC_PREREQ__(3, 0)
   __attribute ((noinline)) __attribute ((noreturn))
   #endif
   void
 mutex_abort(kmutex_t *mtx, const char *func, const char *msg)  mutex_abort(kmutex_t *mtx, const char *func, const char *msg)
 {  {
   
         LOCKDEBUG_ABORT(MUTEX_GETID(mtx), mtx, (MUTEX_SPIN_P(mtx) ?          LOCKDEBUG_ABORT(mtx, (MUTEX_SPIN_P(mtx) ?
             &mutex_spin_lockops : &mutex_adaptive_lockops), func, msg);              &mutex_spin_lockops : &mutex_adaptive_lockops), func, msg);
         /* NOTREACHED */          /* NOTREACHED */
 }  }
Line 301  mutex_abort(kmutex_t *mtx, const char *f
Line 324  mutex_abort(kmutex_t *mtx, const char *f
 void  void
 mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)  mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
 {  {
         u_int id;          bool dodebug;
   
         memset(mtx, 0, sizeof(*mtx));          memset(mtx, 0, sizeof(*mtx));
   
         if (type == MUTEX_DRIVER)  
                 type = (ipl == IPL_NONE ? MUTEX_ADAPTIVE : MUTEX_SPIN);  
   
         switch (type) {          switch (type) {
         case MUTEX_ADAPTIVE:          case MUTEX_ADAPTIVE:
         case MUTEX_DEFAULT:  
                 KASSERT(ipl == IPL_NONE);                  KASSERT(ipl == IPL_NONE);
                 id = LOCKDEBUG_ALLOC(mtx, &mutex_adaptive_lockops);                  break;
                 MUTEX_INITIALIZE_ADAPTIVE(mtx, id);          case MUTEX_DEFAULT:
           case MUTEX_DRIVER:
                   if (ipl == IPL_NONE || ipl == IPL_SOFTCLOCK ||
                       ipl == IPL_SOFTBIO || ipl == IPL_SOFTNET ||
                       ipl == IPL_SOFTSERIAL) {
                           type = MUTEX_ADAPTIVE;
                   } else {
                           type = MUTEX_SPIN;
                   }
                   break;
           default:
                   break;
           }
   
           switch (type) {
           case MUTEX_NODEBUG:
                   dodebug = LOCKDEBUG_ALLOC(mtx, NULL,
                       (uintptr_t)__builtin_return_address(0));
                   MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
                   break;
           case MUTEX_ADAPTIVE:
                   dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_adaptive_lockops,
                       (uintptr_t)__builtin_return_address(0));
                   MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug);
                 break;                  break;
         case MUTEX_SPIN:          case MUTEX_SPIN:
                 id = LOCKDEBUG_ALLOC(mtx, &mutex_spin_lockops);                  dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_spin_lockops,
                 MUTEX_INITIALIZE_SPIN(mtx, id, ipl);                      (uintptr_t)__builtin_return_address(0));
                   MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
                 break;                  break;
         default:          default:
                 panic("mutex_init: impossible type");                  panic("mutex_init: impossible type");
Line 338  mutex_destroy(kmutex_t *mtx)
Line 381  mutex_destroy(kmutex_t *mtx)
                 MUTEX_ASSERT(mtx, !MUTEX_OWNED(mtx->mtx_owner) &&                  MUTEX_ASSERT(mtx, !MUTEX_OWNED(mtx->mtx_owner) &&
                     !MUTEX_HAS_WAITERS(mtx));                      !MUTEX_HAS_WAITERS(mtx));
         } else {          } else {
                 MUTEX_ASSERT(mtx, mtx->mtx_lock != __SIMPLELOCK_LOCKED);                  MUTEX_ASSERT(mtx, !__SIMPLELOCK_LOCKED_P(&mtx->mtx_lock));
         }          }
   
         LOCKDEBUG_FREE(mtx, MUTEX_GETID(mtx));          LOCKDEBUG_FREE(MUTEX_DEBUG_P(mtx), mtx);
         MUTEX_DESTROY(mtx);          MUTEX_DESTROY(mtx);
 }  }
   
Line 350  mutex_destroy(kmutex_t *mtx)
Line 393  mutex_destroy(kmutex_t *mtx)
  *   *
  *      Return true if an adaptive mutex owner is running on a CPU in the   *      Return true if an adaptive mutex owner is running on a CPU in the
  *      system.  If the target is waiting on the kernel big lock, then we   *      system.  If the target is waiting on the kernel big lock, then we
  *      return false immediately.  This is necessary to avoid deadlock   *      must release it.  This is necessary to avoid deadlock.
  *      against the big lock.  
  *   *
  *      Note that we can't use the mutex owner field as an LWP pointer.  We   *      Note that we can't use the mutex owner field as an LWP pointer.  We
  *      don't have full control over the timing of our execution, and so the   *      don't have full control over the timing of our execution, and so the
  *      pointer could be completely invalid by the time we dereference it.   *      pointer could be completely invalid by the time we dereference it.
  *  
  *      XXX This should be optimised further to reduce potential cache line  
  *      ping-ponging and skewing of the spin time while busy waiting.  
  */   */
 #ifdef MULTIPROCESSOR  #ifdef MULTIPROCESSOR
 int  int
Line 372  mutex_onproc(uintptr_t owner, struct cpu
Line 411  mutex_onproc(uintptr_t owner, struct cpu
                 return 0;                  return 0;
         l = (struct lwp *)MUTEX_OWNER(owner);          l = (struct lwp *)MUTEX_OWNER(owner);
   
         if ((ci = *cip) != NULL && ci->ci_curlwp == l) {          /* See if the target is running on a CPU somewhere. */
                 mb_read(); /* XXXSMP Very expensive, necessary? */          if ((ci = *cip) != NULL && ci->ci_curlwp == l)
                 return ci->ci_biglock_wanted != l;                  goto run;
         }          for (CPU_INFO_FOREACH(cii, ci))
                   if (ci->ci_curlwp == l)
         for (CPU_INFO_FOREACH(cii, ci)) {                          goto run;
                 if (ci->ci_curlwp == l) {  
                         *cip = ci;  
                         mb_read(); /* XXXSMP Very expensive, necessary? */  
                         return ci->ci_biglock_wanted != l;  
                 }  
         }  
   
           /* No: it may be safe to block now. */
         *cip = NULL;          *cip = NULL;
         return 0;          return 0;
   
    run:
           /* Target is running; do we need to block? */
           *cip = ci;
           return ci->ci_biglock_wanted != l;
 }  }
 #endif  #endif  /* MULTIPROCESSOR */
   
 /*  /*
  * mutex_vector_enter:   * mutex_vector_enter:
Line 442  mutex_vector_enter(kmutex_t *mtx)
Line 481  mutex_vector_enter(kmutex_t *mtx)
                 do {                  do {
                         if (panicstr != NULL)                          if (panicstr != NULL)
                                 break;                                  break;
                         while (mtx->mtx_lock == __SIMPLELOCK_LOCKED) {                          while (__SIMPLELOCK_LOCKED_P(&mtx->mtx_lock)) {
                                 SPINLOCK_BACKOFF(count);                                  SPINLOCK_BACKOFF(count);
 #ifdef LOCKDEBUG  #ifdef LOCKDEBUG
                                 if (SPINLOCK_SPINOUT(spins))                                  if (SPINLOCK_SPINOUT(spins))
Line 577  mutex_vector_enter(kmutex_t *mtx)
Line 616  mutex_vector_enter(kmutex_t *mtx)
                  *   or preempted).                   *   or preempted).
                  *                   *
                  * o At any given time, MUTEX_SET_WAITERS() can only ever                   * o At any given time, MUTEX_SET_WAITERS() can only ever
                  *   be in progress on one CPU in the system - guarenteed                   *   be in progress on one CPU in the system - guaranteed
                  *   by the turnstile chain lock.                   *   by the turnstile chain lock.
                  *                   *
                  * o No other operations other than MUTEX_SET_WAITERS()                   * o No other operations other than MUTEX_SET_WAITERS()
Line 594  mutex_vector_enter(kmutex_t *mtx)
Line 633  mutex_vector_enter(kmutex_t *mtx)
                  *   completes before the modification of curlwp becomes                   *   completes before the modification of curlwp becomes
                  *   visible to this CPU.                   *   visible to this CPU.
                  *                   *
                  * o cpu_switch() posts a store fence before setting curlwp                   * o mi_switch() posts a store fence before setting curlwp
                  *   and before resuming execution of an LWP.                   *   and before resuming execution of an LWP.
                  *                   *
                  * o _kernel_lock() posts a store fence before setting                   * o _kernel_lock() posts a store fence before setting
Line 637  mutex_vector_enter(kmutex_t *mtx)
Line 676  mutex_vector_enter(kmutex_t *mtx)
                  * If the waiters bit is not set it's unsafe to go asleep,                   * If the waiters bit is not set it's unsafe to go asleep,
                  * as we might never be awoken.                   * as we might never be awoken.
                  */                   */
                 mb_read();                  if ((membar_consumer(), mutex_onproc(owner, &ci)) ||
                 if (mutex_onproc(owner, &ci) || !MUTEX_HAS_WAITERS(mtx)) {                      (membar_consumer(), !MUTEX_HAS_WAITERS(mtx))) {
                         turnstile_exit(mtx);                          turnstile_exit(mtx);
                         continue;                          continue;
                 }                  }
Line 650  mutex_vector_enter(kmutex_t *mtx)
Line 689  mutex_vector_enter(kmutex_t *mtx)
   
                 LOCKSTAT_STOP_TIMER(lsflag, slptime);                  LOCKSTAT_STOP_TIMER(lsflag, slptime);
                 LOCKSTAT_COUNT(slpcnt, 1);                  LOCKSTAT_COUNT(slpcnt, 1);
   
                 turnstile_unblock();  
         }          }
   
         LOCKSTAT_EVENT(lsflag, mtx, LB_ADAPTIVE_MUTEX | LB_SLEEP1,          LOCKSTAT_EVENT(lsflag, mtx, LB_ADAPTIVE_MUTEX | LB_SLEEP1,
Line 677  mutex_vector_exit(kmutex_t *mtx)
Line 714  mutex_vector_exit(kmutex_t *mtx)
   
         if (MUTEX_SPIN_P(mtx)) {          if (MUTEX_SPIN_P(mtx)) {
 #ifdef FULL  #ifdef FULL
                 if (mtx->mtx_lock != __SIMPLELOCK_LOCKED)                  if (!__SIMPLELOCK_LOCKED_P(&mtx->mtx_lock))
                         MUTEX_ABORT(mtx, "exiting unheld spin mutex");                          MUTEX_ABORT(mtx, "exiting unheld spin mutex");
                 MUTEX_UNLOCKED(mtx);                  MUTEX_UNLOCKED(mtx);
                 __cpu_simple_unlock(&mtx->mtx_lock);                  __cpu_simple_unlock(&mtx->mtx_lock);
Line 686  mutex_vector_exit(kmutex_t *mtx)
Line 723  mutex_vector_exit(kmutex_t *mtx)
                 return;                  return;
         }          }
   
         if (__predict_false(panicstr != NULL) || __predict_false(cold)) {          if (__predict_false((uintptr_t)panicstr | cold)) {
                 MUTEX_UNLOCKED(mtx);                  MUTEX_UNLOCKED(mtx);
                 MUTEX_RELEASE(mtx);                  MUTEX_RELEASE(mtx);
                 return;                  return;
Line 697  mutex_vector_exit(kmutex_t *mtx)
Line 734  mutex_vector_exit(kmutex_t *mtx)
         MUTEX_ASSERT(mtx, MUTEX_OWNER(mtx->mtx_owner) == curthread);          MUTEX_ASSERT(mtx, MUTEX_OWNER(mtx->mtx_owner) == curthread);
         MUTEX_UNLOCKED(mtx);          MUTEX_UNLOCKED(mtx);
   
   #ifdef LOCKDEBUG
           /*
            * Avoid having to take the turnstile chain lock every time
            * around.  Raise the priority level to splhigh() in order
            * to disable preemption and so make the following atomic.
            */
           {
                   int s = splhigh();
                   if (!MUTEX_HAS_WAITERS(mtx)) {
                           MUTEX_RELEASE(mtx);
                           splx(s);
                           return;
                   }
                   splx(s);
           }
   #endif
   
         /*          /*
          * Get this lock's turnstile.  This gets the interlock on           * Get this lock's turnstile.  This gets the interlock on
          * the sleep queue.  Once we have that, we can clear the           * the sleep queue.  Once we have that, we can clear the
Line 751  mutex_owned(kmutex_t *mtx)
Line 805  mutex_owned(kmutex_t *mtx)
         if (MUTEX_ADAPTIVE_P(mtx))          if (MUTEX_ADAPTIVE_P(mtx))
                 return MUTEX_OWNER(mtx->mtx_owner) == (uintptr_t)curlwp;                  return MUTEX_OWNER(mtx->mtx_owner) == (uintptr_t)curlwp;
 #ifdef FULL  #ifdef FULL
         return mtx->mtx_lock == __SIMPLELOCK_LOCKED;          return __SIMPLELOCK_LOCKED_P(&mtx->mtx_lock);
 #else  #else
         return 1;          return 1;
 #endif  #endif
Line 763  mutex_owned(kmutex_t *mtx)
Line 817  mutex_owned(kmutex_t *mtx)
  *      Return the current owner of an adaptive mutex.  Used for   *      Return the current owner of an adaptive mutex.  Used for
  *      priority inheritance.   *      priority inheritance.
  */   */
 static struct lwp *  lwp_t *
 mutex_owner(wchan_t obj)  mutex_owner(kmutex_t *mtx)
 {  {
         kmutex_t *mtx = (void *)(uintptr_t)obj; /* discard qualifiers */  
   
         MUTEX_ASSERT(mtx, MUTEX_ADAPTIVE_P(mtx));          MUTEX_ASSERT(mtx, MUTEX_ADAPTIVE_P(mtx));
         return (struct lwp *)MUTEX_OWNER(mtx->mtx_owner);          return (struct lwp *)MUTEX_OWNER(mtx->mtx_owner);
Line 845  mutex_spin_retry(kmutex_t *mtx)
Line 898  mutex_spin_retry(kmutex_t *mtx)
         do {          do {
                 if (panicstr != NULL)                  if (panicstr != NULL)
                         break;                          break;
                 while (mtx->mtx_lock == __SIMPLELOCK_LOCKED) {                  while (__SIMPLELOCK_LOCKED_P(&mtx->mtx_lock)) {
                         SPINLOCK_BACKOFF(count);                          SPINLOCK_BACKOFF(count);
 #ifdef LOCKDEBUG  #ifdef LOCKDEBUG
                         if (SPINLOCK_SPINOUT(spins))                          if (SPINLOCK_SPINOUT(spins))
Line 864  mutex_spin_retry(kmutex_t *mtx)
Line 917  mutex_spin_retry(kmutex_t *mtx)
 #endif  /* MULTIPROCESSOR */  #endif  /* MULTIPROCESSOR */
 }  }
 #endif  /* defined(__HAVE_SPIN_MUTEX_STUBS) || defined(FULL) */  #endif  /* defined(__HAVE_SPIN_MUTEX_STUBS) || defined(FULL) */
   
 /*  
  * sched_lock_idle:  
  *  
  *      XXX Ugly hack for cpu_switch().  
  */  
 void  
 sched_lock_idle(void)  
 {  
 #ifdef FULL  
         kmutex_t *mtx = &sched_mutex;  
   
         curcpu()->ci_mtx_count--;  
   
         if (!__cpu_simple_lock_try(&mtx->mtx_lock)) {  
                 mutex_spin_retry(mtx);  
                 return;  
         }  
   
         MUTEX_LOCKED(mtx);  
 #else  
         curcpu()->ci_mtx_count--;  
 #endif  /* FULL */  
 }  
   
 /*  
  * sched_unlock_idle:  
  *  
  *      XXX Ugly hack for cpu_switch().  
  */  
 void  
 sched_unlock_idle(void)  
 {  
 #ifdef FULL  
         kmutex_t *mtx = &sched_mutex;  
   
         if (mtx->mtx_lock != __SIMPLELOCK_LOCKED)  
                 MUTEX_ABORT(mtx, "sched_unlock_idle");  
   
         MUTEX_UNLOCKED(mtx);  
         __cpu_simple_unlock(&mtx->mtx_lock);  
 #endif  /* FULL */  
         curcpu()->ci_mtx_count++;  
 }  

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.28

CVSweb <webmaster@jp.NetBSD.org>