git: 8e83ca27529c - stable/15 - sched_4bsd: add static assertion for nice weight

From: Minsoo Choo <mchoo_at_FreeBSD.org>
Date: Fri, 02 Oct 2026 15:34:59 UTC
The branch stable/15 has been updated by mchoo:

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

commit 8e83ca27529c190ab37fe4695c2aaebdc658c76c
Author:     Minsoo Choo <mchoo@FreeBSD.org>
AuthorDate: 2026-08-24 02:25:32 +0000
Commit:     Minsoo Choo <mchoo@FreeBSD.org>
CommitDate: 2026-10-02 15:34:29 +0000

    sched_4bsd: add static assertion for nice weight
    
    When NICE_WEIGHT * (PRIO_MAX - PRIO_MIN) exceeds the timeshare range,
    two CPU-bound threads with different nice values can have the same
    priority as their nice values are clamped to the timeshare range limit.
    Add static assertion on NICE_WEIGHT to ensure that there is always
    enough room for nice values in the both end of the timeshare priority
    range.
    
    Reviewed by:    olce
    Approved by:    olce (mentor)
    MFC after:      2 weeks
    Sponsored by:   FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D59396
    
    (cherry picked from commit e90be6fdf08526624f407923d003b66efa23d304)
---
 sys/kern/sched_4bsd.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index 95170c1a4e02..f5f31ff4fbfe 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -72,6 +72,10 @@
  */
 #define	INVERSE_ESTCPU_WEIGHT	8	/* 1 / (priorities per estcpu level). */
 #define	NICE_WEIGHT		1	/* Priorities per nice level. */
+_Static_assert(NICE_WEIGHT * (PRIO_MAX - PRIO_MIN)
+    <= PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE,
+    "Priority range accounting for nice values cannot exceed the including "
+    "timeshare span.");
 #define	ESTCPULIM(e)							\
 	min((e), INVERSE_ESTCPU_WEIGHT *				\
 	    (PRI_MAX_TIMESHARE - PRI_MIN_TIMESHARE -			\