1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-14 10:09:48 +00:00

Don't modify curthread->td_locks unless INVARIANTS is enabled.

This field is only used in a KASSERT that verifies that no locks are held
when returning to user mode. Moreover, the td_locks accounting is only
correct when LOCK_DEBUG > 0, which is implied by INVARIANTS.

Reviewed by:	jhb
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D3205
This commit is contained in:
Mark Johnston 2015-08-02 00:03:08 +00:00
parent c3321180ec
commit ce1c953ee0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=286166
6 changed files with 29 additions and 31 deletions

View File

@ -69,12 +69,8 @@ CTASSERT(LK_UNLOCKED == (LK_UNLOCKED &
#ifndef INVARIANTS
#define _lockmgr_assert(lk, what, file, line)
#define TD_LOCKS_INC(td)
#define TD_LOCKS_DEC(td)
#else
#define TD_LOCKS_INC(td) ((td)->td_locks++)
#define TD_LOCKS_DEC(td) ((td)->td_locks--)
#endif
#define TD_SLOCKS_INC(td) ((td)->td_lk_slocks++)
#define TD_SLOCKS_DEC(td) ((td)->td_lk_slocks--)

View File

@ -224,7 +224,7 @@ __mtx_lock_flags(volatile uintptr_t *c, int opts, const char *file, int line)
line);
WITNESS_LOCK(&m->lock_object, (opts & ~MTX_RECURSE) | LOP_EXCLUSIVE,
file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
void
@ -248,7 +248,7 @@ __mtx_unlock_flags(volatile uintptr_t *c, int opts, const char *file, int line)
mtx_assert(m, MA_OWNED);
__mtx_unlock(m, curthread, opts, file, line);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
void
@ -347,7 +347,7 @@ _mtx_trylock_flags_(volatile uintptr_t *c, int opts, const char *file, int line)
if (rval) {
WITNESS_LOCK(&m->lock_object, opts | LOP_EXCLUSIVE | LOP_TRYLOCK,
file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
if (m->mtx_recurse == 0)
LOCKSTAT_PROFILE_OBTAIN_LOCK_SUCCESS(adaptive__acquire,
m, contested, waittime, file, line);
@ -958,7 +958,7 @@ _mtx_destroy(volatile uintptr_t *c)
if (LOCK_CLASS(&m->lock_object) == &lock_class_mtx_spin)
spinlock_exit();
else
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
lock_profile_release_lock(&m->lock_object);
/* Tell witness this isn't locked to make it happy. */

View File

@ -608,11 +608,8 @@ _rm_wlock_debug(struct rmlock *rm, const char *file, int line)
_rm_wlock(rm);
LOCK_LOG_LOCK("RMWLOCK", &rm->lock_object, 0, 0, file, line);
WITNESS_LOCK(&rm->lock_object, LOP_EXCLUSIVE, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
void
@ -628,7 +625,7 @@ _rm_wunlock_debug(struct rmlock *rm, const char *file, int line)
WITNESS_UNLOCK(&rm->lock_object, LOP_EXCLUSIVE, file, line);
LOCK_LOG_LOCK("RMWUNLOCK", &rm->lock_object, 0, 0, file, line);
_rm_wunlock(rm);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
int
@ -670,9 +667,7 @@ _rm_rlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
LOCK_LOG_LOCK("RMRLOCK", &rm->lock_object, 0, 0, file,
line);
WITNESS_LOCK(&rm->lock_object, 0, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
return (1);
} else if (trylock)
LOCK_LOG_TRY("RMRLOCK", &rm->lock_object, 0, 0, file, line);
@ -694,7 +689,7 @@ _rm_runlock_debug(struct rmlock *rm, struct rm_priotracker *tracker,
WITNESS_UNLOCK(&rm->lock_object, 0, file, line);
LOCK_LOG_LOCK("RMRUNLOCK", &rm->lock_object, 0, 0, file, line);
_rm_runlock(rm, tracker);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
#else

View File

@ -268,7 +268,7 @@ _rw_wlock_cookie(volatile uintptr_t *c, const char *file, int line)
__rw_wlock(rw, curthread, file, line);
LOCK_LOG_LOCK("WLOCK", &rw->lock_object, 0, rw->rw_recurse, file, line);
WITNESS_LOCK(&rw->lock_object, LOP_EXCLUSIVE, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
int
@ -303,7 +303,7 @@ __rw_try_wlock(volatile uintptr_t *c, const char *file, int line)
if (!rw_recursed(rw))
LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(rw__acquire,
rw, 0, 0, file, line, LOCKSTAT_WRITER);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
return (rval);
}
@ -325,8 +325,9 @@ _rw_wunlock_cookie(volatile uintptr_t *c, const char *file, int line)
LOCK_LOG_LOCK("WUNLOCK", &rw->lock_object, 0, rw->rw_recurse, file,
line);
__rw_wunlock(rw, curthread, file, line);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
/*
* Determines whether a new reader can acquire a lock. Succeeds if the
* reader already owns a read lock and the lock is locked for read to
@ -565,7 +566,7 @@ __rw_rlock(volatile uintptr_t *c, const char *file, int line)
waittime, file, line, LOCKSTAT_READER);
LOCK_LOG_LOCK("RLOCK", &rw->lock_object, 0, 0, file, line);
WITNESS_LOCK(&rw->lock_object, 0, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
curthread->td_rw_rlocks++;
}
@ -596,7 +597,7 @@ __rw_try_rlock(volatile uintptr_t *c, const char *file, int line)
WITNESS_LOCK(&rw->lock_object, LOP_TRYLOCK, file, line);
LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(rw__acquire,
rw, 0, 0, file, line, LOCKSTAT_READER);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
curthread->td_rw_rlocks++;
return (1);
}
@ -714,7 +715,7 @@ _rw_runlock_cookie(volatile uintptr_t *c, const char *file, int line)
break;
}
LOCKSTAT_PROFILE_RELEASE_RWLOCK(rw__release, rw, LOCKSTAT_READER);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
curthread->td_rw_rlocks--;
}

View File

@ -261,7 +261,7 @@ _sx_slock(struct sx *sx, int opts, const char *file, int line)
if (!error) {
LOCK_LOG_LOCK("SLOCK", &sx->lock_object, 0, 0, file, line);
WITNESS_LOCK(&sx->lock_object, 0, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
return (error);
@ -290,7 +290,7 @@ sx_try_slock_(struct sx *sx, const char *file, int line)
WITNESS_LOCK(&sx->lock_object, LOP_TRYLOCK, file, line);
LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(sx__acquire,
sx, 0, 0, file, line, LOCKSTAT_READER);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
return (1);
}
}
@ -318,7 +318,7 @@ _sx_xlock(struct sx *sx, int opts, const char *file, int line)
LOCK_LOG_LOCK("XLOCK", &sx->lock_object, 0, sx->sx_recurse,
file, line);
WITNESS_LOCK(&sx->lock_object, LOP_EXCLUSIVE, file, line);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
return (error);
@ -353,7 +353,7 @@ sx_try_xlock_(struct sx *sx, const char *file, int line)
if (!sx_recursed(sx))
LOCKSTAT_PROFILE_OBTAIN_RWLOCK_SUCCESS(sx__acquire,
sx, 0, 0, file, line, LOCKSTAT_WRITER);
curthread->td_locks++;
TD_LOCKS_INC(curthread);
}
return (rval);
@ -371,7 +371,7 @@ _sx_sunlock(struct sx *sx, const char *file, int line)
WITNESS_UNLOCK(&sx->lock_object, 0, file, line);
LOCK_LOG_LOCK("SUNLOCK", &sx->lock_object, 0, 0, file, line);
__sx_sunlock(sx, file, line);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
void
@ -387,7 +387,7 @@ _sx_xunlock(struct sx *sx, const char *file, int line)
LOCK_LOG_LOCK("XUNLOCK", &sx->lock_object, 0, sx->sx_recurse, file,
line);
__sx_xunlock(sx, curthread, file, line);
curthread->td_locks--;
TD_LOCKS_DEC(curthread);
}
/*

View File

@ -238,7 +238,7 @@ struct thread {
int td_oncpu; /* (t) Which cpu we are on. */
volatile u_char td_owepreempt; /* (k*) Preempt on last critical_exit */
u_char td_tsqueue; /* (t) Turnstile queue blocked on. */
short td_locks; /* (k) Count of non-spin locks. */
short td_locks; /* (k) Debug: count of non-spin locks */
short td_rw_rlocks; /* (k) Count of rwlock read locks. */
short td_lk_slocks; /* (k) Count of lockmgr shared locks. */
short td_stopsched; /* (k) Scheduler stopped. */
@ -351,8 +351,14 @@ do { \
KASSERT((__m == &blocked_lock || __m == (lock)), \
("Thread %p lock %p does not match %p", td, __m, (lock))); \
} while (0)
#define TD_LOCKS_INC(td) ((td)->td_locks++)
#define TD_LOCKS_DEC(td) ((td)->td_locks--)
#else
#define THREAD_LOCKPTR_ASSERT(td, lock)
#define TD_LOCKS_INC(td)
#define TD_LOCKS_DEC(td)
#endif
/*