Re: [PATCH 03/11] preempt: Introduce __preempt_count_{sub, add}_return()

Heiko Carstens <[email protected]> Sat, 9 May 2026 20:09:59 +0200
Newsgroups org.kernel.vger.linux-openrisc,org.kernel.vger.linux-arch,org.kernel.vger.linux-kernel,org.kernel.vger.linux-s390,org.kernel.vger.rust-for-linux
Message-ID <[email protected]>
On Thu, May 07, 2026 at 09:21:03PM -0700, Boqun Feng wrote:
> From: Boqun Feng <[email protected]>
> 
> In order to use preempt_count() to tracking the interrupt disable
> nesting level, __preempt_count_{add,sub}_return() are introduced, as
> their name suggest, these primitives return the new value of the
> preempt_count() after changing it. The following example shows the usage
> of it in local_interrupt_disable():
> 
> 	// increase the HARDIRQ_DISABLE bit
> 	new_count = __preempt_count_add_return(HARDIRQ_DISABLE_OFFSET);
> 
> 	// if it's the first-time increment, then disable the interrupt
> 	// at hardware level.
> 	if (new_count & HARDIRQ_DISABLE_MASK == HARDIRQ_DISABLE_OFFSET) {
> 		local_irq_save(flags);
> 		raw_cpu_write(local_interrupt_disable_state.flags, flags);
> 	}
> 
> Having these primitives will avoid a read of preempt_count() after
> changing preempt_count() on certain architectures.
> 
> Signed-off-by: Boqun Feng <[email protected]>
> Signed-off-by: Boqun Feng <[email protected]>
> Link: https://patch.msgid.link/[email protected]
> ---
>  arch/arm64/include/asm/preempt.h | 18 ++++++++++++++++++
>  arch/s390/include/asm/preempt.h  | 10 ++++++++++
>  arch/x86/include/asm/preempt.h   | 10 ++++++++++
>  include/asm-generic/preempt.h    | 14 ++++++++++++++
>  4 files changed, 52 insertions(+)

fwiw:
Acked-by: Heiko Carstens <[email protected]> # s390