The branch stable/14 has been updated by mchoo: URL: https://cgit.FreeBSD.org/src/commit/?id=abed4cb15735d9743da4ef979ceef0ec678289d1
commit abed4cb15735d9743da4ef979ceef0ec678289d1 Author: Minsoo Choo <[email protected]> AuthorDate: 2026-09-06 22:49:02 +0000 Commit: Minsoo Choo <[email protected]> CommitDate: 2026-10-02 15:44:55 +0000 sched: factor out hogticks calculation into sched_update_hogticks() Suggested by: olce Reviewed by: olce Approved by: olce (mentor) MFC after: 2 weeks Sponsored by: FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D59471 (cherry picked from commit 5a879394ba2eac14f65b466a46dae39326df00db) --- sys/kern/sched_4bsd.c | 16 ++++++++++------ sys/kern/sched_ule.c | 17 +++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index f66c73597b67..d494f6d7ba29 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -134,6 +134,13 @@ static int realstathz = 127; /* stathz is sometimes 0 and run off of hz. */ static int sched_tdcnt; /* Total runnable threads in the system. */ static int sched_slice = 12; /* Thread run time before rescheduling. */ +static inline void +sched_update_hogticks(void) +{ + hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / + realstathz); +} + static void setup_runqs(void); static void schedcpu(void); static void schedcpu_thread(void); @@ -209,8 +216,7 @@ sysctl_kern_quantum(SYSCTL_HANDLER_ARGS) if (new_val <= 0) return (EINVAL); sched_slice = imax(1, (new_val + period / 2) / period); - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); return (0); } @@ -226,8 +232,7 @@ sysctl_kern_slice(SYSCTL_HANDLER_ARGS) if (new_val <= 0) return (EINVAL); sched_slice = new_val; - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); return (0); } @@ -664,8 +669,7 @@ sched_initticks(void *dummy) realstathz = stathz ? stathz : hz; sched_slice = realstathz / 10; /* ~100ms */ - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); } /* External interfaces start here */ diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 9a7adfed338c..30226aa31071 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -235,6 +235,14 @@ static int __read_mostly tickincr = 8 << SCHED_TICK_SHIFT; static int __read_mostly realstathz = 127; /* reset during boot. */ static int __read_mostly sched_slice = 10; /* reset during boot. */ static int __read_mostly sched_slice_min = 1; /* reset during boot. */ + +static inline void +sched_update_hogticks(void) +{ + hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / + realstathz); +} + #ifdef PREEMPTION #ifdef FULL_PREEMPTION static int __read_mostly preempt_thresh = PRI_MAX_IDLE + 1; @@ -1665,8 +1673,7 @@ sched_initticks(void *dummy) realstathz = stathz ? stathz : hz; sched_slice = realstathz / SCHED_SLICE_DEFAULT_DIVISOR; sched_slice_min = sched_slice / SCHED_SLICE_MIN_DIVISOR; - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); /* * tickincr is shifted out by 10 to avoid rounding errors due to @@ -3434,8 +3441,7 @@ sysctl_kern_quantum(SYSCTL_HANDLER_ARGS) return (EINVAL); sched_slice = imax(1, (new_val + period / 2) / period); sched_slice_min = imax(1, sched_slice / SCHED_SLICE_MIN_DIVISOR); - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); return (0); } @@ -3452,8 +3458,7 @@ sysctl_kern_slice(SYSCTL_HANDLER_ARGS) return (EINVAL); sched_slice = new_val; sched_slice_min = imax(1, sched_slice / SCHED_SLICE_MIN_DIVISOR); - hogticks = imax(1, (2 * hz * sched_slice + realstathz / 2) / - realstathz); + sched_update_hogticks(); return (0); }
