CPU Scheduling - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

CPU Scheduling

Description:

CPU Scheduling Basic Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling ... – PowerPoint PPT presentation

Number of Views:263
Avg rating:3.0/5.0
Slides: 21
Provided by: stf60
Category:

less

Transcript and Presenter's Notes

Title: CPU Scheduling


1
CPU Scheduling
  • Basic Concepts

2
Chapter 5 CPU Scheduling
  • Basic Concepts
  • Scheduling Criteria
  • Scheduling Algorithms
  • Thread Scheduling
  • Multiple-Processor Scheduling
  • Operating Systems Examples
  • Algorithm Evaluation

3
Objectives
  • To introduce CPU scheduling, which is the basis
    for multiprogrammed operating systems
  • To describe various CPU-scheduling algorithms
  • To discuss evaluation criteria for selecting a
    CPU-scheduling algorithm for a particular system

4
Basic Concepts
  • Maximum CPU utilization obtained with
    multiprogramming
  • CPUI/O Burst Cycle Process execution consists
    of a cycle of CPU execution and I/O wait
  • CPU burst distribution

5
Histogram of CPU-burst Times
6
CPU-I/O Burst Cycle
  • Process execution consists of a cycle of CPU
    execution and I/O wait
  • Processes alternate between these two states
  • Each scheduling decision is about which job to
    give to the CPU for use by its next CPU burst
  • With time slicing, job may be forced to give up
    CPU before finishing current CPU burst

7
CPU Scheduler
  • Selects from among the processes in memory that
    are ready to execute, and allocates the CPU to
    one of them
  • CPU scheduling decisions may take place when a
    process
  • 1. Switches from running to waiting state
  • 2. Switches from running to ready state
  • 3. Switches from waiting to ready
  • 4. Terminates
  • Scheduling under 1 and 4 is nonpreemptive
  • All other scheduling is preemptive

8
Scheduling
  • Managing resource (e.g., CPU)
  • n processes
  • A schedule is a listing
  • Number of possible schedules if no
    interdependencies?
  • Environment
  • Number of processors involved
  • Whether preemption is allowed (priorities or time
    slicing)
  • Whether a process once active can become blocked
    (due to I/O, etc)

9
Scheduling
  • First the easy case
  • One processor, no preemption, no blocking
  • n/1 static scheduling problem
  • n processes
  • Know arrival times, processing times

10
Scheduling
  • Given the following information about process Pi
  • Arrival Time ai
  • Execution Time ei
  • Due Time di
  • We can obtain
  • Completion (finish) Time fi
  • Turn-around Time ti (fi ai)
  • Waiting Time wi (ti ei)
  • Lateness Li (fi di)
  • Tardiness Ti max(0, Li)

11
Example
Process P1 P2 P3 P4 P5 P6
pi 15 25 5 20 25 30
P4 P5 P3 P1 P6 P2
ti wi
P1 65 50
P2 120 95
P3 50 45
P4 20 0
P5 45 20
P6 95 65
0 20 45 50
65 95 120
12
Scheduling Criteria
  • CPU utilization
  • keep the CPU as busy as possible
  • Throughput
  • of processes that complete their execution per
    time unit
  • Turnaround time
  • amount of time to execute a particular process
  • Waiting time
  • amount of time a process has been waiting in the
    ready queue
  • Response time
  • amount of time it takes from when a request was
    submitted until the first response is produced

13
How good is a schedule? Performance Measures
  • Max CPU utilization
  • Max throughput
  • Min turnaround time
  • Min waiting time
  • Min response time

14
First-Come, First-Served (FCFS) Scheduling
  • First-Come, First-Served (FCFS)
  • Also First In, First Out (FIFO) or Run until
    done
  • In early systems, FCFS meant one program
    scheduled until done (including I/O)
  • Now, means keep CPU until process blocks

15
First-Come, First-Served (FCFS) Scheduling
  • Suppose that the processes arrive in the order
    P1 , P2 , P3 . Draw the Gantt Chart for the
    schedule and compute the average waiting time 3

Process P1 P2 P3
pi 24 3 3
16
First-Come, First-Served (FCFS) Scheduling
  • Suppose that the processes arrive in the order
    P2, P3, P1 . Draw the Gantt Chart for the
    schedule and compute the average waiting time 17

Process P1 P2 P3
pi 24 3 3
17
First-Come, First-Served (FCFS) Scheduling
  • There is a convoy effect as all the other
    processes wait for the one big process to get off
    the CPU
  • Average waiting time for FCFS is often quite long
  • What about average turnaround time?
  • Pros and cons
  • Simple ()
  • Short jobs get stuck behind long ones (-)
  • Analogy getting milk at a supermarket and
    waiting to pay, always stuck behind carts full of
    items. Upside get to read about space aliens!

18
Example of (Shortest Job First) SJF
  • Process Arrival Time Burst Time
  • P1 0.0 6
  • P2 2.0 8
  • P3 4.0 7
  • P4 5.0 3
  • SJF scheduling chart
  • Average waiting time (3 16 9 0) / 4 7

19
SJF Scheduling example
  • Sometimes called Shortest Processing Time (SPT)
    First
  • Draw the Gantt Chart for a SPT schedule and
    compute the average waiting time and average
    turnaround time (assume all processes arrive at
    time 0)

Process P1 P2 P3 P4 P5 P6
pi 15 25 5 20 18 30
20
Round Robin (RR)
  • Each process gets a small unit of CPU time (time
    quantum), usually 10-100 milliseconds. After
    this time has elapsed, the process is preempted
    and added to the end of the ready queue.
  • If there are n processes in the ready queue and
    the time quantum is q, then each process gets 1/n
    of the CPU time in chunks of at most q time units
    at once. No process waits more than (n-1)q time
    units.
  • Performance
  • q large ? FIFO
  • q small ? q must be large with respect to context
    switch, otherwise overhead is too high
Write a Comment
User Comments (0)
About PowerShow.com