All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sched/hrtick: Name the minimum slice and derive the rearm slack
@ 2026-08-18 15:18 Liang Hao
  0 siblings, 0 replies; only message in thread
From: Liang Hao @ 2026-08-18 15:18 UTC (permalink / raw)
  To: Ingo Molnar, Peter Zijlstra, Thomas Gleixner
  Cc: Juri Lelli, Vincent Guittot, Dietmar Eggemann, Steven Rostedt,
	Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
	linux-kernel, Liang Hao

hrtick_start() floors delays at 10000ns to avoid programming slices
too short to matter and to prevent timer DoS.  hrtick_needs_rearm()
separately ignores expiry adjustments below 5000ns as not worth the
reprogram.

Define the slack as half the floor so an expiry shift of one
minimum slice still crosses the rearm threshold.  Name both so
the relationship reads off the constants.

No functional change.

Signed-off-by: Liang Hao <haohlliang@gmail.com>
---
The 10us floor and 5us slack were introduced years apart. This patch
only names the existing values and encodes the slack as half the floor
so a one-slice expiry shift still rearms.

Was the 5us threshold chosen deliberately to be half of the 10us floor,
or as a separate heuristic? Any background on that choice would be helpful.

 kernel/sched/core.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b77152edafd9..c2149b7c7a9c 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -905,6 +905,9 @@ enum {
 	HRTICK_SCHED_REARM_HRTIMER	= BIT(3)
 };
 
+#define HRTICK_MIN_SLICE_NS	(10 * NSEC_PER_USEC)
+#define HRTICK_REARM_SLACK_NS	(HRTICK_MIN_SLICE_NS / 2)
+
 static void __used hrtick_clear(struct rq *rq)
 {
 	if (hrtimer_active(&rq->hrtick_timer))
@@ -938,7 +941,7 @@ static inline bool hrtick_needs_rearm(struct hrtimer *timer, ktime_t expires)
 	 * whether the expiry time actually changes substantially.
 	 */
 	return !hrtimer_is_queued(timer) ||
-		abs(expires - hrtimer_get_expires(timer)) > 5000;
+		abs(expires - hrtimer_get_expires(timer)) > HRTICK_REARM_SLACK_NS;
 }
 
 static void hrtick_cond_restart(struct rq *rq)
@@ -973,10 +976,10 @@ void hrtick_start(struct rq *rq, u64 delay)
 	s64 delta;
 
 	/*
-	 * Don't schedule slices shorter than 10000ns, that just
-	 * doesn't make sense and can cause timer DoS.
+	 * Don't schedule slices shorter than the minimum hrtick slice.
+	 * That doesn't make sense and can cause timer DoS.
 	 */
-	delta = max_t(s64, delay, 10000LL);
+	delta = max_t(s64, delay, HRTICK_MIN_SLICE_NS);
 
 	/*
 	 * If this is in the middle of schedule() only note the delay
-- 
2.50.1 (Apple Git-155)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-18 15:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 15:18 [PATCH] sched/hrtick: Name the minimum slice and derive the rearm slack Liang Hao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.