Lecture 3 - CPU Scheduling


Agenda

Announcements

  • CS Colloquium Friday 2:35. Hear 4 of your classmates talk about their summer work experience. Refreshments will be served.
  • Those of you who didn't already have an account on applecore, the Mac OS X server in the department, should now have one. At this time, it's a completely separate account from your unix account - different password, different home directory. If you didn't have an account from some other course, see me for your initial password. This account lets you log in remotely to applecore and to log into the Mac OS X clients in the 217a and 312.
  • The class mailing list is up. If you didn't get a subscription notice, then you weren't registered when the list was set up. Contact me to get on the list.
  • Process Creation from Lecture 2

    CPU Scheduling

    CPU scheduling can be done at three different levels:

    1. Long-term Scheduling - also known as batch scheduling. Decide which jobs/processes are allowed into the system.
    2. Short-term Scheduling - or interactive scheduling. Decide from a collection of ready processes which gets the CPU next.
    3. Medium-term Scheduling - or memory scheduling. Decide if/when a process should be "swapped out" or back in based on memory available.

    We will discuss primarily short-term scheduling here, though we will discuss all of the algorithms that Tanenbaum splits between batch and interactive scheduling.

    A typical process alternates between the need for CPU and the need for I/O service throughout its lifespan. This is called the CPU-I/O burst cycle.

    It is this fact that makes multiprogramming essential. When a process needs I/O, it's good to have another process ready to move in and take advantage of the available CPU resource.

    The amount of time that it can make use of the CPU is known as its CPU burst time.

    A typical distribution of CPU burst times looks like this:

    Processes may be categorized as:

  • CPU-bound - process does not need much I/O service, almost always want the CPU
  • I/O-bound - short CPU burst times, needs lots of I/O service
  • Interactive - short CPU burst times, lots of time waiting for user input (keyboard, mouse)
  • The type of processes in the system will affect the performance of scheduling algorithms.

    A short-term CPU scheduling decision is needed when a process:

    1. switches from a running to a waiting state (non-preemptive)
    2. switches from a running to a ready state (preemptive)
    3. switches from a waiting to a ready state (preemptive)
    4. terminates (non-preemptive)

    Goals of a CPU scheduler. (In parens is whether this is a goal of the owners of the system or the users of the system)

  • maximize CPU Utilization - keep the CPU busy doing useful work (owner)
  • maximize Throughput - rate of process completion (owner)
  • minimize Turnaround Time - amount of time to execute a particular process (user)
  • minimize Waiting Time - amount of time that a process is waiting in the ready queue (user)
  • minimize Response Time - amount of time it takes from a process' arrival until its first turn on the CPU (user)
  • Response Time's Relationship to Throughput

    First-Come, First-Served (FCFS) Scheduling

    As its name suggests, the first process to arrive gets to go first. It is a non-preemptive FIFO system.

    Example:

    Consider 4 processes P1, P2, and P3 that have burst times of 24, 3, and 3, respectively.

    If the processes arrive in the order P1, P2, P3, FCFS will service them in that order. We visualize this with a Gantt Chart:

    |---------P1----------|-P2-|-P3-|
    0                    24   27   30
    

    Waiting times: P1 = 0; P2 = 24; P3 = 27, Avg: (0+24+27)/(3)=17.

    But what if the processes arrive P2, P3, P1?

    |-P2-|-P3-|---------P1-----------|
    0    3    6                     30
    

    Waiting times: P1 = 6; P2 = 0; P3 = 3, Avg: (6+0+3)/(3)=3.

    FCFS characteristics:

  • Penalizes short jobs
  • Rewards long jobs
  • Large variance in throughput
  • Sensitive to arrival order
  • Is starvation free - every job gets its turn
  • Easy to implement
  • Remainder moved to Lecture 4 notes.

    Project 1 - Discrete Event Simulation