There are two cases where the scheduler code schedule()
is invoked-
When a process voluntarily calls schedule()
Timer
When a process calls schedule()
it runs in a system call context which is interrupt based. In the 2nd case a hardware interrupt triggers the schedule()
call. In both cases it runs as an interrupt. AFAIK those are the only times that schedule()
is called because most manipulation of scheduling involves modifying the kernel run queue of things to be scheduled although a process can be interrupted but that is usually done via an interrupt to tell the process to yield or the process yielding itself.