Re: [PATCH 03/11] preempt: Introduce __preempt_count_{sub, add}_return()
From: Heiko Carstens
Date: Sat May 09 2026 - 14:15:23 EST
On Thu, May 07, 2026 at 09:21:03PM -0700, Boqun Feng wrote:
> From: Boqun Feng <boqun.feng@xxxxxxxxx>
>
> 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 <boqun.feng@xxxxxxxxx>
> Signed-off-by: Boqun Feng <boqun@xxxxxxxxxx>
> Link: https://patch.msgid.link/20260121223933.1568682-4-lyude@xxxxxxxxxx
> ---
> 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 <hca@xxxxxxxxxxxxx> # s390