Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What context does the scheduler code run in?

There are two cases where the scheduler code schedule() is invoked-

  1. When a process voluntarily calls schedule()

  2. Timer interrupt calls schedule()

In case 2, I think schedule() runs in interrupt context, but what about the first case? Does it run in the context of the process which invoked it?

Also are there any more scenarios which invoke schedule()?

like image 881
Pavan Manjunath Avatar asked Aug 18 '11 10:08

Pavan Manjunath


People also ask

Where does the scheduler run?

The kernel's process / thread scheduler runs on the core that needs to figure out what to do next. It's a distributed algorithm with no single decision-making thread. Scheduling doesn't work by figuring out what task should run on which other CPU.

Who invokes scheduler?

In operating system the scheduler is invoked after the system call api or after a hardware interrupt processing.

Is kernel a scheduler?

The task scheduler, sometimes called process scheduler, is the part of the kernel that decides which task to run next. It is responsible for best using system resources to guarantee that multiple tasks are being executed simultaneously. This makes it a core component of any multitasking operating system.

Can a kernel schedule a process?

O(1) Scheduler was introduced in LINUX Kernel 2.6. O(1) scheduler is also called as Big O of 1 scheduler or constant time scheduler. As the name suggests, it can schedule the processes within a constant amount of time, regardless of the number of processes running on the system. O(1) scheduler uses two queues.


1 Answers

schedule() always runs in process context. In the second case, when it is initiated by a timer interrupt, it is in the return path back from the kernel to the interrupted process where schedule() is called.

like image 65
caf Avatar answered Oct 13 '22 18:10

caf