git: 5a879394ba2e - main - sched: factor out hogticks calculation into sched_update_hogticks()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 18 Sep 2026 14:15:01 UTC
The branch main has been updated by mchoo:
URL: https://cgit.FreeBSD.org/src/commit/?id=5a879394ba2eac14f65b466a46dae39326df00db
commit 5a879394ba2eac14f65b466a46dae39326df00db
Author: Minsoo Choo <mchoo@FreeBSD.org>
AuthorDate: 2026-09-06 22:49:02 +0000
Commit: Minsoo Choo <mchoo@FreeBSD.org>
CommitDate: 2026-09-18 14:14:14 +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
---
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 cd039501b609..61b8c0e68691 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -133,6 +133,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);
@@ -206,8 +213,7 @@ sysctl_kern_4bsd_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);
}
@@ -223,8 +229,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);
}
@@ -660,8 +665,7 @@ sched_4bsd_initticks(void)
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 34b376857ad9..ca55e5c1da7b 100644
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -232,6 +232,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;
@@ -1659,8 +1667,7 @@ sched_ule_initticks(void)
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
@@ -3477,8 +3484,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);
}
@@ -3495,8 +3501,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);
}