From b7b7769e947a139f7ab610561b4d427bc2b9e035 Mon Sep 17 00:00:00 2001 From: markj Date: Mon, 3 Feb 2020 22:49:05 +0000 Subject: [PATCH] Fix the !SMP case in sched_add() after r355779. If the thread's lock is already that of the runqueue, don't recurse on the queue lock. Reviewed by: jeff, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D23492 --- sys/kern/sched_ule.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index e2adf98ec6fd..62e19678c8f7 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -2605,15 +2605,17 @@ sched_add(struct thread *td, int flags) sched_setpreempt(td); #else tdq = TDQ_SELF(); - TDQ_LOCK(tdq); /* * Now that the thread is moving to the run-queue, set the lock * to the scheduler's lock. */ - if ((flags & SRQ_HOLD) != 0) - td->td_lock = TDQ_LOCKPTR(tdq); - else - thread_lock_set(td, TDQ_LOCKPTR(tdq)); + if (td->td_lock != TDQ_LOCKPTR(tdq)) { + TDQ_LOCK(tdq); + if ((flags & SRQ_HOLD) != 0) + td->td_lock = TDQ_LOCKPTR(tdq); + else + thread_lock_set(td, TDQ_LOCKPTR(tdq)); + } tdq_add(tdq, td, flags); if (!(flags & SRQ_YIELDING)) sched_setpreempt(td);