CS361: Operating System

Jian Huang — Spring 2012

EECS | University of Tennessee - Knoxville

CPU scheduler

CPU scheduler is made of 2 components:

  1. This short-term scheduler - select which task to run
  2. The dispatcher - switch context, switch to user mode, jump to the proper location in the user program to restart the program

The goal of the scheduling algorithm is to optimize the following, which are sometimes conflicting amongst themselves:

  1. CPU utilization
  2. throughput
  3. turnaround time: from submission of job till finishing the job
  4. waiting time: time spent in the ready queue
  5. response time: submission of job till first response

Scheduling algorithms

The algorithms that we have covered in class are:

  1. first-come, first-served
  2. shortest-job-first scheduling
  3. shortest-remaining-time-first shceduling
  4. priority scheduling
  5. round-robin scheduling (based on time quantum)
  6. multilevel queue scheduling (system, interactive, batch)
  7. multilevel feedback queue scheduling (allowing a process to move between queues)

Algorithm evaluations are through:

  1. algorithm evaluation
  2. deterministic modeling
  3. queueing models
  4. simulation
  5. implementation

Some intrinsic issues of multi-processor scheduling (as opposed to uniprocessor scheduling) are:

  1. processor affinity (soft vs. hard)
  2. load balancing (push vs. pull migration) - Linux implements both - push is done every 200 ms, pull is done when a processor is empty.

Linux implementation

Linux is preemptive, priority-based (multilevel feedback queue). Each processor maintains its own runqueue and schedules itself independently Each runqueue has two priority arrays - active vs. expired array

There are 0-140 numeric priority values. 0-99 are for real-time system tasks, and 100-140 are for other tasks. Different priority level gets different time slices, which range from 10ms to 100 ms per time slice. Context switching overhead is about 0.1- 1 ms. Roughly 1% overhead due to context switching.

Tasks with more interactivity (I/O related sleep time) will get higher priority (e.g. with -5 nice value). Tasks with shorter sleep time (less interactivity) receives lower priority.

A fun anecdotal information bit. Traditional Unix scheduler uses a simple formula to (re)calculate process priority on a per second interval. The priority is (recent CPU usage divided by 2) + base. Higher the number, lower the priority.

Finally, let's clarify a few key terms:

multiprocessing  - multiple CPUs/cores
multiprogramming - multiple jobs or processes
multithreading   - multiple threads per process

Jian Huang / EECS /UTK / revised 01/2012