I knwow that “The need_resched flag is a message to the kernel that the scheduler should be invoked as soon as possible because another process deserves to run”, but I’m missing some points:
who is in charge of checking this flag? There is a kernel process ad hoc? In the end, probably, the only question I’d like to make is: what does the kernel do to call schedule() as soon as possible after the flag is set?
I hope I’ve been clear,
Stefano
Typically this flag will be checked in the interrupt and syscall return paths – if it’s set when returning from an interrupt or syscall, and (in the interrupt case) the kernel is preemptible, then the kernel will invoke one of the rescheduling functions prior to returning.
For example, in arch/x86/kernel/entry_32.S:
Note that need_resched is a bit flag in TI_flags, and
_TIF_WORK_MASKincludes most TI_flags bits, including the one for need_resched. There are a number of other similar checks, and the return-to-kernel path also has an explicit check as well.