diff options
| author | Mateusz Guzik <mjg@FreeBSD.org> | 2025-10-05 15:38:06 +0000 |
|---|---|---|
| committer | Mateusz Guzik <mjg@FreeBSD.org> | 2025-10-05 15:39:04 +0000 |
| commit | ccb600906f152df310794f146eac54372e6b2665 (patch) | |
| tree | e3f561dc64149f535e0fc5ffe1bc358b7aa5dd17 | |
| parent | d0a35ec01c31b498bd9996b50641a8629757b65f (diff) | |
mtx: retire _mtx_release_lock_quick
The macro is misleading and of questionable value to begin with.
For starters, it is used for both spinlocks and regular mutexes (the
latter only the in the slow path), which have fundamentally different
requirements on unlock -- spinlocks are guaranteed to not have blocked
waiters and can blindly do a store.
The commentary above the it is also head-scratching:
> Release mtx_lock quickly, assuming we own it.
You can't *just* release a sleepable mutex "quickly". The only legal use
right now is when the turnstile lock is held.
Note that unlock of a sleepable mutex without using RMW atomics is very
much possible and may show up soon (tm).
Sponsored by: Rubicon Communications, LLC ("Netgate")
| -rw-r--r-- | sys/kern/kern_mutex.c | 6 | ||||
| -rw-r--r-- | sys/sys/mutex.h | 6 |
2 files changed, 4 insertions, 8 deletions
diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 8b5908f5219a..b7316ea5f387 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -869,7 +869,7 @@ _thread_lock(struct thread *td) WITNESS_LOCK(&m->lock_object, LOP_EXCLUSIVE, file, line); return; } - _mtx_release_lock_quick(m); + atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED); slowpath_unlocked: spinlock_exit(); slowpath_noirq: @@ -959,7 +959,7 @@ retry: } if (m == td->td_lock) break; - _mtx_release_lock_quick(m); + atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED); } LOCK_LOG_LOCK("LOCK", &m->lock_object, opts, m->mtx_recurse, file, line); @@ -1071,7 +1071,7 @@ __mtx_unlock_sleep(volatile uintptr_t *c, uintptr_t v) * can be removed from the hash list if it is empty. */ turnstile_chain_lock(&m->lock_object); - _mtx_release_lock_quick(m); + atomic_store_rel_ptr(&m->mtx_lock, MTX_UNOWNED); ts = turnstile_lookup(&m->lock_object); MPASS(ts != NULL); if (LOCK_LOG_TEST(&m->lock_object, opts)) diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h index b534a74626bc..83300d4eb593 100644 --- a/sys/sys/mutex.h +++ b/sys/sys/mutex.h @@ -221,10 +221,6 @@ void _thread_lock(struct thread *); #define _mtx_release_lock(mp, tid) \ atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED) -/* Release mtx_lock quickly, assuming we own it. */ -#define _mtx_release_lock_quick(mp) \ - atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED) - #define _mtx_release_lock_fetch(mp, vp) \ atomic_fcmpset_rel_ptr(&(mp)->mtx_lock, (vp), MTX_UNOWNED) @@ -332,7 +328,7 @@ void _thread_lock(struct thread *); (mp)->mtx_recurse--; \ else { \ LOCKSTAT_PROFILE_RELEASE_SPIN_LOCK(spin__release, mp); \ - _mtx_release_lock_quick((mp)); \ + atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED); \ } \ spinlock_exit(); \ }) |
