Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Jul 2021 00:58:04 GMT
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 63ca9ea4f34d - main - Use sleepq_signal(SLEEPQ_DROP) in cv_signal().
Message-ID:  <202107100058.16A0w42M085354@gitrepo.freebsd.org>

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

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

commit 63ca9ea4f34d887b66c7b9f1710f5e4be543ebed
Author:     Alexander Motin <mav@FreeBSD.org>
AuthorDate: 2021-07-10 00:52:40 +0000
Commit:     Alexander Motin <mav@FreeBSD.org>
CommitDate: 2021-07-10 00:57:58 +0000

    Use sleepq_signal(SLEEPQ_DROP) in cv_signal().
    
    Same as wakeup_one()/wakeup_any() commit before it reduces the lock
    hold time and so contention.
    
    MFC after:      1 week
---
 sys/kern/kern_condvar.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/sys/kern/kern_condvar.c b/sys/kern/kern_condvar.c
index e26b689b4e11..ffceee44a5c0 100644
--- a/sys/kern/kern_condvar.c
+++ b/sys/kern/kern_condvar.c
@@ -397,26 +397,23 @@ _cv_timedwait_sig_sbt(struct cv *cvp, struct lock_object *lock,
 void
 cv_signal(struct cv *cvp)
 {
-	int wakeup_swapper;
 
 	if (cvp->cv_waiters == 0)
 		return;
-	wakeup_swapper = 0;
 	sleepq_lock(cvp);
-	if (cvp->cv_waiters > 0) {
-		if (cvp->cv_waiters == CV_WAITERS_BOUND &&
-		    sleepq_lookup(cvp) == NULL) {
-			cvp->cv_waiters = 0;
-		} else {
-			if (cvp->cv_waiters < CV_WAITERS_BOUND)
-				cvp->cv_waiters--;
-			wakeup_swapper = sleepq_signal(cvp, SLEEPQ_CONDVAR, 0,
-			    0);
-		}
+	if (cvp->cv_waiters == 0) {
+		sleepq_release(cvp);
+		return;
+	}
+	if (cvp->cv_waiters == CV_WAITERS_BOUND && sleepq_lookup(cvp) == NULL) {
+		cvp->cv_waiters = 0;
+		sleepq_release(cvp);
+	} else {
+		if (cvp->cv_waiters < CV_WAITERS_BOUND)
+			cvp->cv_waiters--;
+		if (sleepq_signal(cvp, SLEEPQ_CONDVAR | SLEEPQ_DROP, 0, 0))
+			kick_proc0();
 	}
-	sleepq_release(cvp);
-	if (wakeup_swapper)
-		kick_proc0();
 }
 
 /*



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