git: c813157a1541 - stable/14 - umtx: Add a helper for unlocked umtxq_busy() calls
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 08 Mar 2025 08:13:57 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=c813157a154148d5488d841aa28aed50b3e13049
commit c813157a154148d5488d841aa28aed50b3e13049
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-24 20:36:48 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-03-07 22:51:48 +0000
umtx: Add a helper for unlocked umtxq_busy() calls
This seems like a natural complement to umtxq_unbusy_unlocked(). No
functional change intended.
Reviewed by: olce, kib
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D49124
(cherry picked from commit b01495caac2eca73463f4a889936a19e4c1c5909)
---
sys/compat/linux/linux_futex.c | 12 +++---------
sys/kern/kern_umtx.c | 34 +++++++++++++++-------------------
sys/sys/umtxvar.h | 1 +
3 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/sys/compat/linux/linux_futex.c b/sys/compat/linux/linux_futex.c
index ab2760859e16..37d0142bae8b 100644
--- a/sys/compat/linux/linux_futex.c
+++ b/sys/compat/linux/linux_futex.c
@@ -501,9 +501,7 @@ linux_futex_lock_pi(struct thread *td, bool try, struct linux_futex_args *args)
if (error != 0)
break;
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
/*
* Set the contested bit so that a release in user space knows
@@ -642,9 +640,7 @@ linux_futex_wakeop(struct thread *td, struct linux_futex_args *args)
umtx_key_release(&key);
return (error);
}
- umtxq_lock(&key);
- umtxq_busy(&key);
- umtxq_unlock(&key);
+ umtxq_busy_unlocked(&key);
error = futex_atomic_op(td, args->val3, args->uaddr2, &op_ret);
umtxq_lock(&key);
umtxq_unbusy(&key);
@@ -701,9 +697,7 @@ linux_futex_requeue(struct thread *td, struct linux_futex_args *args)
umtx_key_release(&key);
return (error);
}
- umtxq_lock(&key);
- umtxq_busy(&key);
- umtxq_unlock(&key);
+ umtxq_busy_unlocked(&key);
error = fueword32(args->uaddr, &uval);
if (error != 0)
error = EFAULT;
diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c
index 7cfe68730e7d..f326b9aa691a 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -440,9 +440,16 @@ umtxq_unbusy(struct umtx_key *key)
}
void
-umtxq_unbusy_unlocked(struct umtx_key *key)
+umtxq_busy_unlocked(struct umtx_key *key)
{
+ umtxq_lock(key);
+ umtxq_busy(key);
+ umtxq_unlock(key);
+}
+void
+umtxq_unbusy_unlocked(struct umtx_key *key)
+{
umtxq_lock(key);
umtxq_unbusy(key);
umtxq_unlock(key);
@@ -2371,9 +2378,7 @@ do_lock_pi(struct thread *td, struct umutex *m, uint32_t flags,
if (error != 0)
break;
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
/*
* Set the contested bit so that a release in user space
@@ -2539,9 +2544,7 @@ do_lock_pp(struct thread *td, struct umutex *m, uint32_t flags,
su = (priv_check(td, PRIV_SCHED_RTPRIO) == 0);
for (;;) {
old_inherited_pri = uq->uq_inherited_pri;
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
rv = fueword32(&m->m_ceilings[0], &ceiling);
if (rv == -1) {
@@ -2722,9 +2725,8 @@ do_unlock_pp(struct thread *td, struct umutex *m, uint32_t flags, bool rb)
TYPE_PP_ROBUST_UMUTEX : TYPE_PP_UMUTEX, GET_SHARE(flags),
&key)) != 0)
return (error);
- umtxq_lock(&key);
- umtxq_busy(&key);
- umtxq_unlock(&key);
+ umtxq_busy_unlocked(&key);
+
/*
* For priority protected mutex, always set unlocked state
* to UMUTEX_CONTESTED, so that userland always enters kernel
@@ -2787,9 +2789,7 @@ do_set_ceiling(struct thread *td, struct umutex *m, uint32_t ceiling,
&uq->uq_key)) != 0)
return (error);
for (;;) {
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
rv = fueword32(&m->m_ceilings[0], &save_ceiling);
if (rv == -1) {
@@ -3139,9 +3139,7 @@ do_rw_rdlock(struct thread *td, struct urwlock *rwlock, long fflag,
break;
/* grab monitor lock */
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
/*
* re-read the state, in case it changed between the try-lock above
@@ -3332,9 +3330,7 @@ do_rw_wrlock(struct thread *td, struct urwlock *rwlock, struct _umtx_time *timeo
}
/* grab monitor lock */
- umtxq_lock(&uq->uq_key);
- umtxq_busy(&uq->uq_key);
- umtxq_unlock(&uq->uq_key);
+ umtxq_busy_unlocked(&uq->uq_key);
/*
* Re-read the state, in case it changed between the
diff --git a/sys/sys/umtxvar.h b/sys/sys/umtxvar.h
index 647ee2a4650c..6165d37d9195 100644
--- a/sys/sys/umtxvar.h
+++ b/sys/sys/umtxvar.h
@@ -206,6 +206,7 @@ int umtx_key_get(const void *, int, int, struct umtx_key *);
void umtx_key_release(struct umtx_key *);
struct umtx_q *umtxq_alloc(void);
void umtxq_busy(struct umtx_key *);
+void umtxq_busy_unlocked(struct umtx_key *);
int umtxq_count(struct umtx_key *);
void umtxq_free(struct umtx_q *);
struct umtxq_chain *umtxq_getchain(struct umtx_key *);