From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EBAE3A8FF6 for ; Tue, 24 Feb 2026 16:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771950960; cv=none; b=M4ir3h7mw44+mK1LbJ1zVFdVQk6gGfnrsz0CsOXDMEij70MinnL49OOKQSR2CC3rt5NLRl/zZGByA7uT+6Nqd1UiKlzL7XS2djTZgyMBOj0F4nowMDGGgKcn5n6sDd0nef2KYR0uAtlyQia705L1SCFuM+9fPJPd/LJRH19AjvE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771950960; c=relaxed/simple; bh=w/08wrYAvr+mim8LiwNBkKTRYSiA2d8XE+0nv6KRdLs=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=EiYa1Gn2omKo5WBKUqEYjAzMC9U5vR6yXsmrKEiE17l6vWOTBhwToFSe73wZ/MMy3jYUBADMihCJvicvy9FVVA1nYEcmO+PUK0yjnC2asf7JpyTyuvAuVaAuDjtcSzhihAFAm3jvrCdXmIV8WQW6nPZbb00FxExcmK24ZKhhh7Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jaZRIT66; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jaZRIT66" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B193C19423; Tue, 24 Feb 2026 16:35:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771950959; bh=w/08wrYAvr+mim8LiwNBkKTRYSiA2d8XE+0nv6KRdLs=; h=Date:From:To:Cc:Subject:References:From; b=jaZRIT66+OUPx/P3HpKEjqVioAbnBmt7DIPWjPMrJO3kDGDgowTaQNZJgCJWApB2T 6r7ZAJgf03PPjgb9LZ5BztG81JyQ4SbguBxTefQQjQN7qA9jhmLdgEGAftjx4pZlmI KI14i/z4HW+/rMPRwjZdxWp3QlHl1+HfwHUYiwR3oVqsqTGmcAACj+v6LnTwpHWh8C C2jjsMbEezkA+4mxxmL3SVafntqZVgQuXnp1oK9lDhVRXOmcu2f5phI4K0QthnFse4 Byizn9qx83Utz4c5by5O1vxiGSOktRdthgb6//7lLxU/lB4wLcjnZ212uLW6zeeh2x oi+7jgno7gdLg== Date: Tue, 24 Feb 2026 17:35:56 +0100 Message-ID: <20260224163429.340593047@kernel.org> User-Agent: quilt/0.68 From: Thomas Gleixner To: LKML Cc: Anna-Maria Behnsen , John Stultz , Stephen Boyd , Daniel Lezcano , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , x86@kernel.org, Peter Zijlstra , Frederic Weisbecker , Eric Dumazet Subject: [patch 09/48] sched/hrtick: Avoid tiny hrtick rearms References: <20260224163022.795809588@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Tiny adjustments to the hrtick expiry time below 5 microseconds are just causing extra work for no real value. Filter them out when restarting the hrtick. Signed-off-by: Thomas Gleixner --- kernel/sched/core.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -903,12 +903,24 @@ static enum hrtimer_restart hrtick(struc return HRTIMER_NORESTART; } -static void __hrtick_restart(struct rq *rq) +static inline bool hrtick_needs_rearm(struct hrtimer *timer, ktime_t expires) +{ + /* + * Queued is false when the timer is not started or currently + * running the callback. In both cases, restart. If queued check + * whether the expiry time actually changes substantially. + */ + return !hrtimer_is_queued(timer) || + abs(expires - hrtimer_get_expires(timer)) > 5000; +} + +static void hrtick_cond_restart(struct rq *rq) { struct hrtimer *timer = &rq->hrtick_timer; ktime_t time = rq->hrtick_time; - hrtimer_start(timer, time, HRTIMER_MODE_ABS_PINNED_HARD); + if (hrtick_needs_rearm(timer, time)) + hrtimer_start(timer, time, HRTIMER_MODE_ABS_PINNED_HARD); } /* @@ -920,7 +932,7 @@ static void __hrtick_start(void *arg) struct rq_flags rf; rq_lock(rq, &rf); - __hrtick_restart(rq); + hrtick_cond_restart(rq); rq_unlock(rq, &rf); } @@ -950,9 +962,11 @@ void hrtick_start(struct rq *rq, u64 del } rq->hrtick_time = ktime_add_ns(ktime_get(), delta); + if (!hrtick_needs_rearm(&rq->hrtick_timer, rq->hrtick_time)) + return; if (rq == this_rq()) - __hrtick_restart(rq); + hrtimer_start(&rq->hrtick_timer, rq->hrtick_time, HRTIMER_MODE_ABS_PINNED_HARD); else smp_call_function_single_async(cpu_of(rq), &rq->hrtick_csd); } @@ -966,7 +980,7 @@ static inline void hrtick_schedule_exit( { if (rq->hrtick_sched & HRTICK_SCHED_START) { rq->hrtick_time = ktime_add_ns(ktime_get(), rq->hrtick_delay); - __hrtick_restart(rq); + hrtick_cond_restart(rq); } else if (idle_rq(rq)) { /* * No need for using hrtimer_is_active(). The timer is CPU local