Re: [PATCH v2 07/35] sched: define *_tsk_need_resched_lazy() helpers

Ankur Arora
2024-05-30T09:08:50Z

Peter Zijlstra <peterz@infradead.org> writes:

> On Mon, May 27, 2024 at 05:34:53PM -0700, Ankur Arora wrote:
>
>> static inline void clear_tsk_need_resched(struct task_struct *tsk)
>> {
>> - clear_tsk_thread_flag(tsk,TIF_NEED_RESCHED);
>> + clear_tsk_thread_flag(tsk, tif_resched(RESCHED_NOW));
>> +
>> + if (IS_ENABLED(CONFIG_PREEMPT_AUTO))
>> + clear_tsk_thread_flag(tsk, tif_resched(RESCHED_LAZY));
>> +}
>
> (using tif_resched() here is really uncalled for)
>
> So this will generate rather sub-optimal code, namely 2 atomics that
> really should be one.
>
> Ideally we'd write this something like:
>
> unsigned long mask = _TIF_NEED_RESCHED;
> if (IS_ENABLED(CONFIG_PREEMPT_AUTO))
> mask |= _TIF_NEED_RESCHED_LAZY;
>
> atomic_long_andnot(mask, (atomic_long_t *)task_thread_info(tsk)->flags);
>
> Which will clear both bits with a single atomic.

Much better. Will fix.

--
ankur