git: c0e358871703 - stable/14 - sched_4bsd: add static assertion for nice weight
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 02 Oct 2026 15:49:53 UTC
The branch stable/14 has been updated by mchoo:
URL: https://cgit.FreeBSD.org/src/commit/?id=c0e3588717033041e7bce8f0bdfe3212afdc6ca1
commit c0e3588717033041e7bce8f0bdfe3212afdc6ca1
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:40:08 +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 02157fdee7a8..bde47e511a63 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -79,6 +79,10 @@ dtrace_vtime_switch_func_t dtrace_vtime_switch_func;
#define INVERSE_ESTCPU_WEIGHT 8 /* 1 / (priorities per estcpu level). */
#endif
#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 * \
(NICE_WEIGHT * (PRIO_MAX - PRIO_MIN) + \