From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4532F441026 for ; Fri, 27 Feb 2026 15:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772207886; cv=none; b=bvBfCmc6CQtVpjACDpN4Pm7S7RHIde3tCl5Bn4en9VRFFGFcMzmMWcYkh8DFcZKaVM1+FaNjNYf0Z69ZHo5Plgpg0qD2agiWj19HCIAyisv0ffqtv71X/+8BWCXkhxuaCvcR0HwBVGt3DcRoNtog4FFDZIkbJnu9H2duv5E+3Hw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772207886; c=relaxed/simple; bh=JdpaPZX8sDL+GgU/SuqmqfR7X/zRzbNrMNW0E20CVcM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=q0IR2emrFBCfm4/i4hqzL6GLbtfXZPo45pX90u080GR1/cRhyvjO6kkgXl2Vgw4YmAEWkfAjgfss2CAO+7STe3bbX73+7h4BC0cc7jxm1IZuN6Rm4ToXSIWjbFFBXnRKjuwmtSFB8dDZH6gLQ7uaOY7OWfhJVYDRmERV4BZfCuE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2170914BF; Fri, 27 Feb 2026 07:57:57 -0800 (PST) Received: from [192.168.0.16] (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 84C483F73B; Fri, 27 Feb 2026 07:57:58 -0800 (PST) Message-ID: <51f8535f-b98c-48e3-ba7b-f28759a92c16@arm.com> Date: Fri, 27 Feb 2026 15:57:55 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [patch 35/48] entry: Prepare for deferred hrtimer rearming To: Thomas Gleixner , LKML , Peter Zijlstra 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 References: <20260224163022.795809588@kernel.org> <20260224163431.066469985@kernel.org> Content-Language: en-US From: Christian Loehle In-Reply-To: <20260224163431.066469985@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/24/26 16:38, Thomas Gleixner wrote: > 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. > > As this is only relevant for interrupt to user return split the work masks > up and hand them in as arguments from the relevant exit to user functions, > which allows the compiler to optimize the deferred handling out for the > syscall exit to user case. > > Add the rearm checks to the approritate places in the exit to user loop and > the interrupt return to kernel path, so that the rearming is always > guaranteed. > > In the return to user space path this is handled in the same way as > TIF_RSEQ to avoid extra instructions in the fast path, which are truly > hurtful for device interrupt heavy work loads as the extra instructions and > conditionals while benign at first sight accumulate quickly into measurable > regressions. The return from syscall path is completely unaffected due to > the above mentioned split so syscall heavy workloads wont have any extra > burden. > > For now this is just placing empty stubs at the right places which are all > optimized out by the compiler until the actual functionality is in place. > > 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. > --- > include/linux/irq-entry-common.h | 25 +++++++++++++++++++------ > include/linux/rseq_entry.h | 16 +++++++++++++--- > kernel/entry/common.c | 4 +++- > 3 files changed, 35 insertions(+), 10 deletions(-) > > --- a/include/linux/irq-entry-common.h > +++ b/include/linux/irq-entry-common.h > @@ -3,6 +3,7 @@ > #define __LINUX_IRQENTRYCOMMON_H > > #include > +#include > #include > #include > #include > @@ -33,6 +34,14 @@ > _TIF_PATCH_PENDING | _TIF_NOTIFY_SIGNAL | _TIF_RSEQ | \ > ARCH_EXIT_TO_USER_MODE_WORK) > > +#ifdef CONFIG_HRTIMER_REARM_DEFERRED > +# define EXIT_TO_USER_MODE_WORK_SYSCALL (EXIT_TO_USER_MODE_WORK) > +# define EXIT_TO_USER_MODE_WORK_IRQ (EXIT_TO_USER_MODE_WORK | _TIF_HRTIMER_REARM) > +#else > +# define EXIT_TO_USER_MODE_WORK_SYSCALL (EXIT_TO_USER_MODE_WORK) > +# define EXIT_TO_USER_MODE_WORK_IRQ (EXIT_TO_USER_MODE_WORK) > +#endif > + > /** > * arch_enter_from_user_mode - Architecture specific sanity check for user mode regs > * @regs: Pointer to currents pt_regs > @@ -203,6 +212,7 @@ unsigned long exit_to_user_mode_loop(str > /** > * __exit_to_user_mode_prepare - call exit_to_user_mode_loop() if required > * @regs: Pointer to pt_regs on entry stack > + * @work_mask: Which TIF bits need to be evaluated > * > * 1) check that interrupts are disabled > * 2) call tick_nohz_user_enter_prepare() > @@ -212,7 +222,8 @@ unsigned long exit_to_user_mode_loop(str > * > * Don't invoke directly, use the syscall/irqentry_ prefixed variants below > */ > -static __always_inline void __exit_to_user_mode_prepare(struct pt_regs *regs) > +static __always_inline void __exit_to_user_mode_prepare(struct pt_regs *regs, > + const unsigned long work_mask) > { > unsigned long ti_work; > > @@ -222,8 +233,10 @@ static __always_inline void __exit_to_us > tick_nohz_user_enter_prepare(); > > ti_work = read_thread_flags(); > - if (unlikely(ti_work & EXIT_TO_USER_MODE_WORK)) > - ti_work = exit_to_user_mode_loop(regs, ti_work); > + if (unlikely(ti_work & work_mask)) { > + if (!hrtimer_rearm_deferred_user_irq(&ti_work, work_mask)) > + ti_work = exit_to_user_mode_loop(regs, ti_work); > + } > > arch_exit_to_user_mode_prepare(regs, ti_work); > } > @@ -239,7 +252,7 @@ static __always_inline void __exit_to_us > /* Temporary workaround to keep ARM64 alive */ > static __always_inline void exit_to_user_mode_prepare_legacy(struct pt_regs *regs) > { > - __exit_to_user_mode_prepare(regs); > + __exit_to_user_mode_prepare(regs, EXIT_TO_USER_MODE_WORK); Should this also be EXIT_TO_USER_MODE_WORK_IRQ? I guess it doesn't really matter for now (since arm64 doesn't have the generic entry path and generic TIF bits yet and therefore HRTIMER_REARM_DEFERRED=n), but I've been playing around with the this series, the generic entry series https://lore.kernel.org/lkml/20260203133728.848283-1-ruanjinjie@huawei.com (and using generic TIF bits) and noticed this. > rseq_exit_to_user_mode_legacy(); > __exit_to_user_mode_validate(); > } > @@ -253,7 +266,7 @@ static __always_inline void exit_to_user > */ > static __always_inline void syscall_exit_to_user_mode_prepare(struct pt_regs *regs) > { > - __exit_to_user_mode_prepare(regs); > + __exit_to_user_mode_prepare(regs, EXIT_TO_USER_MODE_WORK_SYSCALL); > rseq_syscall_exit_to_user_mode(); > __exit_to_user_mode_validate(); > } > @@ -267,7 +280,7 @@ static __always_inline void syscall_exit > */ > static __always_inline void irqentry_exit_to_user_mode_prepare(struct pt_regs *regs) > { > - __exit_to_user_mode_prepare(regs); > + __exit_to_user_mode_prepare(regs, EXIT_TO_USER_MODE_WORK_IRQ); > rseq_irqentry_exit_to_user_mode(); > __exit_to_user_mode_validate(); > [snip]