From: Liang Hao <haohlliang@gmail.com>
To: Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>
Cc: Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
Valentin Schneider <vschneid@redhat.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
linux-kernel@vger.kernel.org, Liang Hao <haohlliang@gmail.com>
Subject: [PATCH] sched/hrtick: Name the minimum slice and derive the rearm slack
Date: Tue, 18 Aug 2026 23:18:54 +0800 [thread overview]
Message-ID: <20260818151854.9193-1-haohlliang@gmail.com> (raw)
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)
reply other threads:[~2026-08-18 15:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260818151854.9193-1-haohlliang@gmail.com \
--to=haohlliang@gmail.com \
--cc=bsegall@google.com \
--cc=dietmar.eggemann@arm.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®