The branch main has been updated by mchoo: URL: https://cgit.FreeBSD.org/src/commit/?id=e90be6fdf08526624f407923d003b66efa23d304
commit e90be6fdf08526624f407923d003b66efa23d304 Author: Minsoo Choo <[email protected]> AuthorDate: 2026-08-24 02:25:32 +0000 Commit: Minsoo Choo <[email protected]> CommitDate: 2026-09-18 14:14:12 +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 --- 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 - \
