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 512B03A7840 for ; Tue, 24 Feb 2026 16:38:16 +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=1771951096; cv=none; b=mIEkcXrwbr2HxxrQDCQjRlIqbHs/6oO+7rhWLazgZMPAsJc6euVYkR6R4qcbGRlm7AhbILVr/Z28yXBGZBnS62jAT0ohXtAhPK7iLlMlqO7KxNkHYSgxHQvz85LMzi1yqKhosNlUpJCLh3okvk4qaVcPqhJSc00BVTVVp/e6L1U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771951096; c=relaxed/simple; bh=t4mGNYQHdhq1LJBnthcBWbTC1Z9MRWQgDUnrnUXZRUw=; h=Date:Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nQYKZZ1PGYVgJ416qFcpKA1nHq1CD6UecuWBs2YFGKVBP+yrKEJ349LPridENMTLYzYMEmr/8eGhhA3hIOjIVkU2u1U+0uUq2NtKwneKmJ9yZpSWuJNkxmNQZPbExqv0SapCKVJPnS70/D07nBA2dpDNksQvHyPswBNuxdXXywk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n79bNwuN; 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="n79bNwuN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57641C116D0; Tue, 24 Feb 2026 16:38:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771951096; bh=t4mGNYQHdhq1LJBnthcBWbTC1Z9MRWQgDUnrnUXZRUw=; h=Date:From:To:Cc:Subject:References:From; b=n79bNwuNHL4RHNbLhuIDA+RmZmz/oZonx6crd8ntKAz+8lRZyMV3Q5E7/iVydhD8f POa7RX3wRPxZhaVzS1e2RZ8+cwAKi/HEhsMjZ6UDOZaIiWeeuTj9duAdNeNdlkNv0W aiROkbewKDV9g7RYY6x4rZwxrz8ADbU6lLqtSp+IvVCyrxaCtvjLLn3fn9+CrjZqgs 5FtRzHh1VnwpV92OiMo3BaihM7rQqpLpoUV8sTJOR7tfOq4xTve5h3YEPjvFRItOif TRn+Dn19xBepSBgQDhcEiCIZ+lkAWEH5pYt97k2M5HrO0ap4XhI0cwFr5NNqBIe9MP 4ne83PUyAdxtg== Date: Tue, 24 Feb 2026 17:38:12 +0100 Message-ID: <20260224163431.208580085@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 37/48] sched/core: Prepare for deferred hrtimer rearming 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 From: Peter Zijlstra The hrtimer interrupt expires timers and at the end of the interrupt it rearms the clockevent device for the next expiring timer. That's obviously correct, but in the case that a expired timer sets NEED_RESCHED the return from interrupt ends up in schedule(). If HRTICK is enabled then schedule() will modify the hrtick timer, which causes another reprogramming of the hardware. That can be avoided by deferring the rearming to the return from interrupt path and if the return results in a immediate schedule() invocation then it can be deferred until the end of schedule(), which avoids multiple rearms and re-evaluation of the timer wheel. Add the rearm checks to the existing sched_hrtick_enter/exit() functions, which already handle the batched rearm of the hrtick timer. For now this is just placing empty stubs at the right places which are all optimized out by the compiler until the guard condition becomes true. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Thomas Gleixner --- tglx: Split out to make it simpler to review and to make cross subsystem merge logistics trivial. --- kernel/sched/core.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -876,6 +876,7 @@ enum { HRTICK_SCHED_NONE = 0, HRTICK_SCHED_DEFER = BIT(1), HRTICK_SCHED_START = BIT(2), + HRTICK_SCHED_REARM_HRTIMER = BIT(3) }; static void hrtick_clear(struct rq *rq) @@ -974,6 +975,8 @@ void hrtick_start(struct rq *rq, u64 del static inline void hrtick_schedule_enter(struct rq *rq) { rq->hrtick_sched = HRTICK_SCHED_DEFER; + if (hrtimer_test_and_clear_rearm_deferred()) + rq->hrtick_sched |= HRTICK_SCHED_REARM_HRTIMER; } static inline void hrtick_schedule_exit(struct rq *rq) @@ -991,6 +994,9 @@ static inline void hrtick_schedule_exit( hrtimer_cancel(&rq->hrtick_timer); } + if (rq->hrtick_sched & HRTICK_SCHED_REARM_HRTIMER) + __hrtimer_rearm_deferred(); + rq->hrtick_sched = HRTICK_SCHED_NONE; }