Brain Dump

Scheduler

Tags
comp-arch

Is a component of the kernel that oversees timesharing.

The scheduler tracks information about all the other (non-kernel) processes on your machine. Every 1/\nth{60} of a second a timer goes off triggering a clock interrupt which causes the scheduler to stop whatever process is currently running, suspend it in place and hand control to another process. In practice 1/\nth{60} of a second on modern hardware allows for tens of thousands of instructions to be run by each process. Except in extraordinary circumstances (such as sound or 3D-graphics generation) the cause for delays is often waiting on data from some disk or network connection.

Any program can function as a scheduler. You can use the SIGSTOP and SIGCONT signals to schedule any other process through the kill system call.

The series of states a process goes through when first being scheduled is:

  1. New: A process has been requested to be scheduled either through fork or clone. At this point the OS creates a new process for it
  2. Ready: The process has had any structs the kernel needs for it allocated.

    Note: The OS data-structure referencing ready-processes is the ready queue. A process is placed on it when it can use the CPU. This can happen for example when:

    • A process was blocked waiting for a read that is now available.
    • A new process has been created and is ready to start.
    • A process thread was blocked on a synchronisation primitive (condition-variable, semaphore, Mutex) and is now able to continue.
    • A process was blocked waiting for a system call but its been interrupted by a signal that needs to be handled.
  3. Running: The process is working on the CPU. Note the process could from this state be blocked, terminated or willingly give up control of the CPU (I.E. preemption) by for example waiting on a Mutex lock (or calling sleep).

  4. Blocked: The process is suspended in the background, the OS may put it back on the ready state when it wants to.

See measures of efficiency.