Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Feb 2025 21:35:09 GMT
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b01495caac2e - main - umtx: Add a helper for unlocked umtxq_busy() calls
Message-ID:  <202502242135.51OLZ9AS057368@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=b01495caac2eca73463f4a889936a19e4c1c5909

commit b01495caac2eca73463f4a889936a19e4c1c5909
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-24 20:36:48 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-02-24 21:34:51 +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
---
 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 f9189024d629..dc6fee1f8f38 100644
--- a/sys/kern/kern_umtx.c
+++ b/sys/kern/kern_umtx.c
@@ -441,9 +441,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);
@@ -2372,9 +2379,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
@@ -2540,9 +2545,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) {
@@ -2727,9 +2730,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
@@ -2792,9 +2794,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) {
@@ -3148,9 +3148,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
@@ -3341,9 +3339,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 *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502242135.51OLZ9AS057368>