git: 961f48142868 - main - sched_ule: Fix off by one in preempt_thresh definition
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 26 Jun 2026 01:45:56 UTC
The branch main has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=961f4814286820f242d8d5407b9fd7238e896936
commit 961f4814286820f242d8d5407b9fd7238e896936
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2026-06-19 01:51:32 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2026-06-26 01:43:46 +0000
sched_ule: Fix off by one in preempt_thresh definition
Since 'preempt_thresh' is set to PRI_MIN_KERN by default, and comparison
of the considered thread's priority with that threshold is done with
'<=', PRI_MIN_KERN threads actually can preempt other threads, contrary
to other non-interrupt kernel ones (between PRI_MIN_KERN + 1 and
PRI_MAX_KERN).
So, replace the comparison operator '<=' by '<'. The alternative would
be to change the default value, but changing the comparison instead has
the benefit to be consistent with the 0 setting (which forbids
preemption entirely), since allowing only threads with priority 0 to
preempt becomes possible.
Consequently, we also change the default value for the FULL_PREEMPTION
option by adding 1 to PRI_MAX_IDLE (in practice, that does not make any
difference in the current setting, since no preemption will happen if
the new priority value is not strictly lower than the current one, and
PRI_MAX_IDLE is PRI_MAX, the highest possible priority).
Reviewed by: markj
Fixes: ae7a6b38d53f ("ULE 3.0: Fine grain scheduler locking and affinity improvements. (...)")
MFC after: 2 weeks
Event: Halifax Hackathon 202606
Location: jrm@'s dining room
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D57828
---
sys/kern/sched_ule.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
index c8d2712b89ef..eb00072b5012 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -236,7 +236,7 @@ static int __read_mostly sched_slice = 10; /* reset during boot. */
static int __read_mostly sched_slice_min = 1; /* reset during boot. */
#ifdef PREEMPTION
#ifdef FULL_PREEMPTION
-static int __read_mostly preempt_thresh = PRI_MAX_IDLE;
+static int __read_mostly preempt_thresh = PRI_MAX_IDLE + 1;
#else
static int __read_mostly preempt_thresh = PRI_MIN_KERN;
#endif
@@ -473,7 +473,7 @@ sched_shouldpreempt(int pri, int cpri, int remote)
/*
* Preempt if we exceed the threshold.
*/
- if (pri <= preempt_thresh)
+ if (pri < preempt_thresh)
return (1);
/*
* If we're interactive or better and there is non-interactive