3
votes

I know that the kernel scheduler is run periodically. This period is determined by a timer. However, I have been unable to find where the IRQ for the timer interrupt is and the entire flow from beginning to end of the scheduler code.

I understand that the schedule() function may potentially have several entry and exit points.. but could someone point me towards where to look for these?

From the kernel source, I've gathered that __schedule() is the main schedule function that seems to be called from schedule().. but what calls schedule()..and what calls the function that calls schedule.. ..

1
For your kernel source browsing needs: lxr.linux.no/linux. schedule() is called from several different places. One of which will be the APIC timer callbackJonathon Reinhart

1 Answers

2
votes

There are actually two schedulers, or rather two scheduling codes in the Linux kernel. There is a core scheduler, which you yourself mentioned called schedule() which calls __schedule(). schedule() is called from many points in the kernel:

  1. Explicit blocking, like in case of semaphores, mutexes etc.
  2. A flag TIF_NEED_RESCHED is checked on interrupts and on return to userspace, if set then schedule is called.
  3. A process wakes up.

There is another scheduler code with the name scheduler_tick()[this too resides in core.c], which is a periodic scheduler and is called by the timer code(timer.c) via interrupt with a frequency of HZ, i.e. scheduler_tick() is called HZ times in one second. HZ is hardware dependent and its value varies between 100-1024. scheduler_tick() calls the task_tick() of the scheduling class to which the current task on the processor belongs.