Re: [RFC] sched,livepatch: call klp_try_switch_task in __cond_resched

From: Peter Zijlstra
Date: Sun May 08 2022 - 16:41:25 EST


On Sat, May 07, 2022 at 07:18:51PM +0000, Rik van Riel wrote:
> Huh, I just looked at that, and the x86 should_resched()
> only seems to check that we _can_ resched, not whether
> we should...
>
>
> /*
> * Returns true when we need to resched and can (barring IRQ state).
> */
> static __always_inline bool should_resched(int preempt_offset)
> {
> return unlikely(raw_cpu_read_4(__preempt_count) ==
> preempt_offset);
> }
>
> I wonder if that was intended, and why, or whether
> the x86 should_resched should also be checking for
> TIF_NEED_RESCHED?

No, it does what you think it should do, you're just getting confused by
the inverted PREEMPT_NEED_RESCHED bit :-)