Index: sys/lock.h =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/sys/lock.h,v retrieving revision 1.67 diff -d -u -r1.67 lock.h --- sys/lock.h 21 Mar 2007 22:18:10 -0000 1.67 +++ sys/lock.h 3 Apr 2007 07:45:23 -0000 @@ -79,7 +79,6 @@ #define LO_ENROLLPEND 0x00800000 /* On the pending enroll list. */ #define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */ #define LO_NOPROFILE 0x10000000 /* Don't profile this lock */ -#define LO_CONTESTED 0x20000000 /* Lock was contested */ /* * Lock classes are statically assigned an index into the gobal lock_classes Index: sys/lock_profile.h =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/sys/lock_profile.h,v retrieving revision 1.10 diff -d -u -r1.10 lock_profile.h --- sys/lock_profile.h 27 Feb 2007 06:42:05 -0000 1.10 +++ sys/lock_profile.h 3 Apr 2007 06:33:16 -0000 @@ -122,7 +122,6 @@ if (lock_prof_enable && *contested == 0) { *waittime = nanoseconds(); - lo->lo_flags |= LO_CONTESTED; atomic_add_int(&l->lpo_contest_holding, 1); *contested = 1; } @@ -131,21 +130,19 @@ static inline void lock_profile_obtain_lock_success(struct lock_object *lo, int contested, uint64_t waittime, const char *file, int line) { if (lock_prof_enable) { +#ifdef LOCK_PROFILING_FAST + if (contested == 0) + return; +#endif _lock_profile_obtain_lock_success(lo, contested, waittime, file, line); } } - static inline void lock_profile_release_lock(struct lock_object *lo) { struct lock_profile_object *l = &lo->lo_profile_obj; -#ifdef LOCK_PROFILING_FAST - if((lo->lo_flags & LO_CONTESTED) == 0) - return; -#endif - if (lock_prof_enable || l->lpo_acqtime) { - lo->lo_flags &= ~LO_CONTESTED; + + if (l->lpo_acqtime) _lock_profile_release_lock(lo); - } } #else /* !LOCK_PROFILING */ Index: sys/mutex.h =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/sys/mutex.h,v retrieving revision 1.93 diff -d -u -r1.93 mutex.h --- sys/mutex.h 30 Mar 2007 18:10:08 -0000 1.93 +++ sys/mutex.h 3 Apr 2007 08:39:11 -0000 @@ -156,15 +156,11 @@ #ifndef _get_sleep_lock #define _get_sleep_lock(mp, tid, opts, file, line) do { \ uintptr_t _tid = (uintptr_t)(tid); \ - int contested = 0; \ - uint64_t waittime = 0; \ if (!_obtain_lock((mp), _tid)) { \ - lock_profile_obtain_lock_failed(&(mp)->lock_object, \ - &contested, &waittime); \ _mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \ - } \ - lock_profile_obtain_lock_success(&(mp)->lock_object, contested, \ - waittime, (file), (line)); \ + } else \ + lock_profile_obtain_lock_success(&(mp)->lock_object, 0, \ + 0, (file), (line)); \ } while (0) #endif @@ -179,20 +175,16 @@ #ifdef SMP #define _get_spin_lock(mp, tid, opts, file, line) do { \ uintptr_t _tid = (uintptr_t)(tid); \ - int contested = 0; \ - uint64_t waittime = 0; \ spinlock_enter(); \ if (!_obtain_lock((mp), _tid)) { \ if ((mp)->mtx_lock == _tid) \ (mp)->mtx_recurse++; \ else { \ - lock_profile_obtain_lock_failed(&(mp)->lock_object, \ - &contested, &waittime); \ _mtx_lock_spin((mp), _tid, (opts), (file), (line)); \ } \ - } \ - lock_profile_obtain_lock_success(&(mp)->lock_object, contested, \ - waittime, (file), (line)); \ + } else \ + lock_profile_obtain_lock_success(&(mp)->lock_object, 0, \ + 0, (file), (line)); \ } while (0) #else /* SMP */ #define _get_spin_lock(mp, tid, opts, file, line) do { \ @@ -237,9 +229,11 @@ #define _rel_spin_lock(mp) do { \ if (mtx_recursed((mp))) \ (mp)->mtx_recurse--; \ - else \ + else { \ + lock_profile_release_lock(&(mp)->lock_object); \ _release_lock_quick((mp)); \ - spinlock_exit(); \ + } \ + spinlock_exit(); \ } while (0) #else /* SMP */ #define _rel_spin_lock(mp) do { \ Index: sys/sx.h =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/sys/sx.h,v retrieving revision 1.29 diff -d -u -r1.29 sx.h --- sys/sx.h 31 Mar 2007 23:23:42 -0000 1.29 +++ sys/sx.h 3 Apr 2007 07:16:26 -0000 @@ -97,17 +97,13 @@ /* Acquire an exclusive lock. */ #define __sx_xlock(sx, tid, file, line) do { \ uintptr_t _tid = (uintptr_t)(tid); \ - int contested = 0; \ - uint64_t waitstart = 0; \ \ if (!atomic_cmpset_acq_ptr(&(sx)->sx_lock, SX_LOCK_UNLOCKED, \ _tid)) { \ - lock_profile_obtain_lock_failed(&(sx)->lock_object, \ - &contested, &waitstart); \ _sx_xlock_hard((sx), _tid, (file), (line)); \ - } \ - lock_profile_obtain_lock_success(&(sx)->lock_object, contested, \ - waitstart, (file), (line)); \ + } else \ + lock_profile_obtain_lock_success(&(sx)->lock_object, 0, \ + 0, (file), (line)); \ } while (0) /* Release an exclusive lock. */ @@ -122,18 +118,14 @@ /* Acquire a shared lock. */ #define __sx_slock(sx, file, line) do { \ uintptr_t x = (sx)->sx_lock; \ - int contested = 0; \ - uint64_t waitstart = 0; \ \ if (!(x & SX_LOCK_SHARED) || \ !atomic_cmpset_acq_ptr(&(sx)->sx_lock, x, \ x + SX_ONE_SHARER)) { \ - lock_profile_obtain_lock_failed(&(sx)->lock_object, \ - &contested, &waitstart); \ _sx_slock_hard((sx), (file), (line)); \ - } \ - lock_profile_obtain_lock_success(&(sx)->lock_object, contested, \ - waitstart, (file), (line)); \ + } else \ + lock_profile_obtain_lock_success(&(sx)->lock_object, 0, \ + 0, (file), (line)); \ } while (0) /* Index: kern/kern_mutex.c =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/kern/kern_mutex.c,v retrieving revision 1.187 diff -d -u -r1.187 kern_mutex.c --- kern/kern_mutex.c 22 Mar 2007 16:09:23 -0000 1.187 +++ kern/kern_mutex.c 3 Apr 2007 08:54:25 -0000 @@ -213,7 +213,8 @@ line); mtx_assert(m, MA_OWNED); - lock_profile_release_lock(&m->lock_object); + if (m->mtx_recurse == 0) + lock_profile_release_lock(&m->lock_object); _rel_sleep_lock(m, curthread, opts, file, line); } @@ -250,7 +251,6 @@ line); mtx_assert(m, MA_OWNED); - lock_profile_release_lock(&m->lock_object); _rel_spin_lock(m); } @@ -309,6 +309,8 @@ #ifdef KTR int cont_logged = 0; #endif + int contested = 0; + uint64_t waittime = 0; uintptr_t v; if (mtx_owned(m)) { @@ -321,7 +323,10 @@ CTR1(KTR_LOCK, "_mtx_lock_sleep: %p recursing", m); return; } - + + lock_profile_obtain_lock_failed(&m->lock_object, + &contested, &waittime); + if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR4(KTR_LOCK, "_mtx_lock_sleep: %s contested (lock=%p) at %s:%d", @@ -418,7 +423,8 @@ m->lock_object.lo_name, (void *)tid, file, line); } #endif - return; + lock_profile_obtain_lock_success(&m->lock_object, contested, + waittime, (file), (line)); } #ifdef SMP @@ -432,12 +438,15 @@ _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { - int i = 0; - struct thread *td; - + int i = 0, contested = 0; + struct thread *td; + uint64_t waittime = 0; + if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); + lock_profile_obtain_lock_failed(&m->lock_object, &contested, &waittime); + while (!_obtain_lock(m, tid)) { /* Give interrupts a chance while we spin. */ @@ -471,7 +480,9 @@ if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR1(KTR_LOCK, "_mtx_lock_spin: %p spin done", m); - return; + lock_profile_obtain_lock_success(&m->lock_object, contested, + waittime, (file), (line)); + } #endif /* SMP */ @@ -496,12 +507,13 @@ CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p unrecurse", m); return; } - + turnstile_lock(&m->lock_object); ts = turnstile_lookup(&m->lock_object); if (LOCK_LOG_TEST(&m->lock_object, opts)) CTR1(KTR_LOCK, "_mtx_unlock_sleep: %p contested", m); + #ifdef ADAPTIVE_MUTEXES if (ts == NULL) { _release_lock_quick(m); @@ -543,8 +555,9 @@ * always just set a flag and never do instant-preempts. */ td = curthread; - if (td->td_critnest > 0 || td1->td_priority >= td->td_priority) + if (td->td_critnest > 0 || td1->td_priority >= td->td_priority) return; + mtx_lock_spin(&sched_lock); if (!TD_IS_RUNNING(td1)) { #ifdef notyet @@ -572,8 +585,6 @@ } mtx_unlock_spin(&sched_lock); #endif - - return; } /* Index: kern/kern_sx.c =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/kern/kern_sx.c,v retrieving revision 1.40 diff -d -u -r1.40 kern_sx.c --- kern/kern_sx.c 31 Mar 2007 23:23:42 -0000 1.40 +++ kern/kern_sx.c 3 Apr 2007 07:53:47 -0000 @@ -273,7 +273,6 @@ curthread->td_locks--; WITNESS_UNLOCK(&sx->lock_object, 0, file, line); LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line); - lock_profile_release_lock(&sx->lock_object); __sx_sunlock(sx, file, line); } @@ -287,7 +286,8 @@ WITNESS_UNLOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line); LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file, line); - lock_profile_release_lock(&sx->lock_object); + if (!sx_recursed(sx)) + lock_profile_release_lock(&sx->lock_object); __sx_xunlock(sx, curthread, file, line); } @@ -390,6 +390,8 @@ volatile struct thread *owner; #endif uintptr_t x; + int contested = 0; + uint64_t waitstart = 0; /* If we already hold an exclusive lock, then recurse. */ if (sx_xlocked(sx)) { @@ -399,6 +401,8 @@ CTR2(KTR_LOCK, "%s: %p recursing", __func__, sx); return; } + lock_profile_obtain_lock_failed(&(sx)->lock_object, + &contested, &waitstart); if (LOCK_LOG_TEST(&sx->lock_object, 0)) CTR5(KTR_LOCK, "%s: %s contested (lock=%p) at %s:%d", __func__, @@ -517,6 +521,8 @@ __func__, sx); } + lock_profile_obtain_lock_success(&(sx)->lock_object, contested, + waitstart, (file), (line)); GIANT_RESTORE(); } @@ -585,7 +591,8 @@ volatile struct thread *owner; #endif uintptr_t x; - + uint64_t waitstart = 0; + int contested = 0; /* * As with rwlocks, we don't make any attempt to try to block * shared locks once there is an exclusive waiter. @@ -603,6 +610,10 @@ MPASS(!(x & SX_LOCK_SHARED_WAITERS)); if (atomic_cmpset_acq_ptr(&sx->sx_lock, x, x + SX_ONE_SHARER)) { + if (SX_SHARERS(x) == 0) + lock_profile_obtain_lock_success( + &sx->lock_object, contested, + waitstart, file, line); if (LOCK_LOG_TEST(&sx->lock_object, 0)) CTR4(KTR_LOCK, "%s: %p succeed %p -> %p", __func__, @@ -691,7 +702,9 @@ if (LOCK_LOG_TEST(&sx->lock_object, 0)) CTR2(KTR_LOCK, "%s: %p blocking on sleep queue", __func__, sx); - + + lock_profile_obtain_lock_failed(&sx->lock_object, &contested, + &waitstart); GIANT_SAVE(); sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name, SLEEPQ_SX, SQ_SHARED_QUEUE); @@ -765,6 +778,7 @@ */ MPASS(x == (SX_SHARERS_LOCK(1) | SX_LOCK_EXCLUSIVE_WAITERS)); + lock_profile_release_lock(&sx->lock_object); sleepq_lock(&sx->lock_object); /* Index: kern/sched_ule.c =================================================================== RCS file: /usr/home/kmacy/devel/cxgb/ncvs/src/sys/kern/sched_ule.c,v retrieving revision 1.191 diff -d -u -r1.191 sched_ule.c --- kern/sched_ule.c 17 Mar 2007 23:32:48 -0000 1.191 +++ kern/sched_ule.c 21 Mar 2007 16:49:03 -0000 @@ -1859,8 +1859,7 @@ CTR2(KTR_ULE, "ithd %d < %d", td->td_priority, PRI_MAX_ITHD); ts->ts_cpu = cpuid; - } - if (pick_pri) + } else if (pick_pri) ts->ts_cpu = tdq_pickpri(tdq, ts, flags); else ts->ts_cpu = tdq_pickidle(tdq, ts);