Chapter 5 -- Scheduling

Basic Concepts

  1. CPU-IO Burst
    1. Processes cycle between requiring CPU and requiring I/O.
    2. Can be lots of variation depending on task (editor different from math package).
    3. Tends to follow curve as shown in fig 5-2.  Mode is just 3ms!!!
  2. Preemptive Scheduling
    1. Normally, scheuling occurs at four places
      1. Process switches from running to wait (I/O)
      2. Process switches from running to ready (timer interrupt)
      3. Process switches from wait to ready (I/O completes (interrupt))
      4. Process terminates
    2. Must switch on #1 and #4.
    3. If switch on #2 or #3, then you are preemptive.
    4. Means processes can be taken away from you without your permission.
    5. Can be a problem for thread programming with shared data structures. Locks might be required on these data structures.

Scheduling Criteria

  1. Important Measures
    1. CPU Utilization -- always do something if you have free CPU. (BTW, 40% is NOT a light load for a workstation).
    2. Throughput -- number of tasks per unit time.
    3. Turnaround time -- how long the average process must wait. (Not the inverse of throughput!)
    4. Wait time -- Time spend in the wait queue -- (Turnaround - CPU - I/O).
    5. Variance in responce -- said to be important for human interaction.
    6. Note:  Sometimes the goal is not to optimize the averae, but to minimize the worst case (RTOS are that way).
  2. Subjective Measures
    1. Fairness -- Does each process get his/her share of the CPU?
    2. Priority -- Does the boss get more than his share?
    3. Starvation -- is each process guarenteed to finish?

Short Term Scheduling Algorithms

  1. FCFS -- First come first serve (The McDonalds algorithm)
    1. Choose the first process -- run till it finishes -- move on.
    2. Can be used with or without preemption.
    3. GOOD, it's fair.
    4. BAD, no priorities.
    5. GOOD, starvation is avoided.
    6. GOOD, CPU always busy.
    7. BAD, wait times not minimized.
    8. BAD, high variation.
    9. GOOD, it's simple.
    10. BAD, there can sometimes be a convoy effect, which reduces I/O and throughput.
    11. Question:  What happens if there is more than one entry of the same process in the queues?
  2. Shortest Job Next -- just run the shortest job
    1. Somtimes has preemption, then called shortest job remaining next.
    2. BAD, no priorities
    3. BAD, starvation is possible.
    4. GOOD, wait times optimal
    5. BAD, high variation.
    6. Question:  How do you predict run time?
      1. Ask the prorgram (and punish liers, or everyone will lie).
      2. Use past data to predict the future.
  3. Round Robin
    1. Do each process for one time slice. Then move to the next.  Always preemptive.
    2. GOOD, no starving.
    3. GOOD, fair.
    4. GOOD, low variation.
    5. MEDIUM, wait times average.
    6. Question:  What should the time slice be set at.
    7. Question:  Should long running programs get a larger or smaller time slice, and more or less of them?
  4. Priority Scheduling
    1. Assign each job a priority. Run in priority order.
    2. If a job has been waiting a long time, then age it to temporarily increase it's priority.
    3. Useful for real time systems.
    4. Can be preemptive or non-preemptive. Normally preemptive.
    5. GOOD, has priorities.
    6. BAD, starvartion possible.
    7. BAD, wait times not minimized. Can be worse than FCFS.
    8. BAD, high variation.
  5. Priority Scheduling with Aging (The Standard scheduler)
    1. All processes get a fixed and a current priority.
    2. When computing current priority, add a minor amount to the current process, and to all processes that last ran on THIS CPU.
    3. Run the process with the highest current prioity.
      1. When done, reduce it's current priority to the fixed priority,
      2. (Some OS's) If it uses it's whole time slice, reduce the current priority somewhat.
    4. Every once in a while, raise the current priority of all processes that have not run for a while.
    5. GOOD, has priorities.
    6. GOOD, starvation not possible.
    7. BAD, wait times not minimized.
    8. MEDIUM variation.  (Better that straight priority, but not as good as round robin.)
  6. RTOS Scheduling
    1. Generally consists of events and deadlines.
    2. It can be proved that if a schedule is possible, that scheduling the closest deadline first will find it.
    3. This translates to priority scheduling, with no aging, and priorities set by deadline.

Long Term Scheduling

  1. Goal -- Avoid overload by delaying jobs
  2. Criterea
    1. Memory Usage
    2. I/O usage
    3. CPU usage
    4. Prioity
    5. Length of time already run