Re: [PATCH v2 06/35] thread_info: define __tif_need_resched(resched_t)

From: Peter Zijlstra
Date: Tue May 28 2024 - 12:03:41 EST


On Mon, May 27, 2024 at 05:34:52PM -0700, Ankur Arora wrote:

> diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
> index 65e5beedc915..e246b01553a5 100644
> --- a/include/linux/thread_info.h
> +++ b/include/linux/thread_info.h
> @@ -216,22 +216,44 @@ static __always_inline unsigned long read_ti_thread_flags(struct thread_info *ti
>
> #ifdef _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H
>
> -static __always_inline bool tif_need_resched(void)
> +static __always_inline bool __tif_need_resched_bitop(int nr_flag)
> {
> - return arch_test_bit(TIF_NEED_RESCHED,
> - (unsigned long *)(&current_thread_info()->flags));
> + return arch_test_bit(nr_flag,
> + (unsigned long *)(&current_thread_info()->flags));
> }
>
> #else
>
> -static __always_inline bool tif_need_resched(void)
> +static __always_inline bool __tif_need_resched_bitop(int nr_flag)
> {
> - return test_bit(TIF_NEED_RESCHED,
> - (unsigned long *)(&current_thread_info()->flags));
> + return test_bit(nr_flag,
> + (unsigned long *)(&current_thread_info()->flags));
> }

:se cino=(0:0

That is, you're wrecking the indentation here.

>
> #endif /* _ASM_GENERIC_BITOPS_INSTRUMENTED_NON_ATOMIC_H */
>
> +static __always_inline bool __tif_need_resched(resched_t rs)
> +{
> + /*
> + * With !PREEMPT_AUTO, this check is only meaningful if we
> + * are checking if tif_resched(RESCHED_NOW) is set.
> + */
> + if (IS_ENABLED(CONFIG_PREEMPT_AUTO) || rs == RESCHED_NOW)
> + return __tif_need_resched_bitop(tif_resched(rs));
> + else
> + return false;
> +}

if (!IS_ENABLED(CONFIG_PREEMPT_AUTO) && rs == RESCHED_LAZY)
return false;

return __tif_need_resched_bitop(tif_resched(rs));


> +
> +static __always_inline bool tif_need_resched(void)
> +{
> + return __tif_need_resched(RESCHED_NOW);
> +}
> +
> +static __always_inline bool tif_need_resched_lazy(void)
> +{
> + return __tif_need_resched(RESCHED_LAZY);
> +}
> +
> #ifndef CONFIG_HAVE_ARCH_WITHIN_STACK_FRAMES
> static inline int arch_within_stack_frames(const void * const stack,
> const void * const stackend,
> diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
> index 233d1af39fff..ed229527be05 100644
> --- a/kernel/trace/trace.c
> +++ b/kernel/trace/trace.c
> @@ -2511,7 +2511,7 @@ unsigned int tracing_gen_ctx_irq_test(unsigned int irqs_status)
> if (softirq_count() >> (SOFTIRQ_SHIFT + 1))
> trace_flags |= TRACE_FLAG_BH_OFF;
>
> - if (tif_need_resched())
> + if (__tif_need_resched(RESCHED_NOW))
> trace_flags |= TRACE_FLAG_NEED_RESCHED;

Per the above this is a NO-OP.