[RFC PATCH 02/13] arm64: preempt: Treat should_resched() as unlikely
Jinjie Ruan
ruanjinjie at huawei.com
Tue Jul 28 21:00:38 PDT 2026
在 2026/7/28 20:38, Mark Rutland 写道:
> The arm64 implementation of should_resched() doesn't treat the need to
> resched as unlikely, while all other implementations do, e.g.
>
> * asm-generic since:
> bdb43806589096ac ("sched: Extract the basic add/sub preempt_count modifiers")
>
> * x86 since:
> c2daa3bed53a8117 ("sched, x86: Provide a per-cpu preempt_count implementation")
>
> * s390 since:
> c360192bf4a8dc72 ("s390/preempt: move preempt_count to the lowcore")
>
> Do the same for arm64.
>
> Signed-off-by: Mark Rutland <mark.rutland at arm.com>
> Cc: Ada Couprie Diaz <ada.coupriediaz at arm.com>
> Cc: Ard Biesheuvel <ardb at kernel.org>
> Cc: Catalin Marinas <catalin.marinas at arm.com>
> Cc: Jinjie Ruan <ruanjinjie at huawei.com>
> Cc: Marc Zyngier <maz at kernel.org>
> Cc: Peter Zijlstra <peterz at infradead.org>
> Cc: Vladimir Murzin <vladimir.murzin at arm.com>
> Cc: Will Deacon <will at kernel.org>
> Cc: Yang Shi <yang at os.amperecomputing.com>
> ---
> arch/arm64/include/asm/preempt.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/preempt.h b/arch/arm64/include/asm/preempt.h
> index ca2ad1a8db095..3ef24ab8f3399 100644
> --- a/arch/arm64/include/asm/preempt.h
> +++ b/arch/arm64/include/asm/preempt.h
> @@ -58,7 +58,7 @@ static inline void __preempt_count_sub(int val)
> static inline bool should_resched(int preempt_offset)
> {
> u64 pc = READ_ONCE(current_thread_info()->preempt_count);
> - return pc == preempt_offset;
> + return unlikely(pc == preempt_offset);
It is rare that preempt_count is 0 or a specific value. Therefore, it is
reasonable to use unlikely.
Reviewed-by: Jinjie Ruan <ruanjinjie at huawei.com>
> }
>
> static inline bool __preempt_count_dec_and_test(void)
More information about the linux-arm-kernel
mailing list