git: 8c308a22e759 - stable/13 - sched: Simplify sched_lend_user_prio_cond()

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Thu, 09 May 2024 13:30:21 UTC
The branch stable/13 has been updated by olce:

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

commit 8c308a22e759a666704f2b6d730568a83fb271b1
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-02-09 18:03:22 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2024-05-09 13:29:32 +0000

    sched: Simplify sched_lend_user_prio_cond()
    
    If 'td_lend_user_pri' has the expected value, there is no need to check
    the fields that sched_lend_user_prio() modifies, they either are already
    good or soon will be ('td->td_lend_user_pri' has just been changed by
    a concurrent update).
    
    Reviewed by:            kib
    Approved by:            emaste (mentor)
    MFC after:              2 weeks
    Sponsored by:           The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D44050
    
    (cherry picked from commit aeff15b392e68f5f193fff3bb01728b965cacc3a)
    
    Approved by:            emaste (mentor)
---
 sys/kern/sched_4bsd.c | 12 +++---------
 sys/kern/sched_ule.c  | 10 ++--------
 2 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index 700f0dca93aa..ca615098c1df 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -953,15 +953,9 @@ void
 sched_lend_user_prio_cond(struct thread *td, u_char prio)
 {
 
-	if (td->td_lend_user_pri != prio)
-		goto lend;
-	if (td->td_user_pri != min(prio, td->td_base_user_pri))
-		goto lend;
-	if (td->td_priority != td->td_user_pri)
-		goto lend;
-	return;
-
-lend:
+	if (td->td_lend_user_pri == prio)
+		return;
+
 	thread_lock(td);
 	sched_lend_user_prio(td, prio);
 	thread_unlock(td);
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index 9220b4700af7..b53c2f57c908 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -1996,15 +1996,9 @@ void
 sched_lend_user_prio_cond(struct thread *td, u_char prio)
 {
 
-	if (td->td_lend_user_pri != prio)
-		goto lend;
-	if (td->td_user_pri != min(prio, td->td_base_user_pri))
-		goto lend;
-	if (td->td_priority != td->td_user_pri)
-		goto lend;
-	return;
+	if (td->td_lend_user_pri == prio)
+		return;
 
-lend:
 	thread_lock(td);
 	sched_lend_user_prio(td, prio);
 	thread_unlock(td);