I spent a lot of time figuring out the function in the code level and I really got confused now.
First in the core.c, the function __schedule() or schedule() seem to be the most promising ones. Typically in __schedule(), I have found the code hrtick_clear(rq) which seems to be a timer. Then also in __schedule(), the function next = pick_next_task(rq) will be called which will try to find the next task to schedule. For the normal task, the CFS algorithm is used. So then I went into the fair.c file to check the pick_next_task_fair function. By tracking that function, I have seen the hrtick_start(rq, delta) has been called.
So obviously it seems that there is a timer based on hrtick is used to periodically activate the scheduling algorithm. But the strange thing is that in the core.c file, I really can not find how the timer is configured to call the __schedule() or schedule() periodically. I didn’t see that timer is configured to call this function.
Is there other function used? Can linux task scheduler expert give me a hint:>
Nothing special is needed. The timer just triggers an interrupt, and the interrupt logic already has to handle figuring out which task to run when you return from an interrupt. See, for example this code from entry_32.S which handles returning from an interrupt: