Docsity

CPU Scheduling - Computer Operating Systems - Lecture Slides, Slides of Operating Systems

Partial preview of the text

Download CPU Scheduling - Computer Operating Systems - Lecture Slides and more Slides Operating Systems in PDF only on Docsity!

Lecture 8

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling

  • Basic Concepts
  • Scheduling Criteria
  • Scheduling Algorithms
  • Thread Scheduling
  • Multiple-Processor Scheduling
  • Operating Systems Examples
  • Algorithm Evaluation

Basic Concepts

  • Maximum CPU utilization obtained with

multiprogramming

  • CPU–I/O Burst Cycle : Process execution

consists of a cycle of CPU execution and

I/O wait

  • Alternating Sequence of CPU And I/O Bursts

Histogram of CPU-burst Times

Dispatcher

• Dispatcher module gives control of the CPU to

the process selected by the short-term

scheduler; this involves:

  • switching context
  • switching to user mode
  • jumping to the proper location in the user program
to restart that program

• Dispatch latency – time it takes for the

dispatcher to stop one process and start

another running

Scheduling Criteria

  • CPU utilization – keep the CPU as busy as possible
    • Typically between 40% to 90%
  • Throughput – # of processes that complete their execution per time unit - Depends on the length of process
  • Turnaround time – amount of time to execute a particular process - Sum of wait for memory, ready queue, execution, and I/O.
  • Waiting time – amount of time a process has been waiting in the ready queue - Sum of wait in ready queue
  • Response time – amount of time it takes from when a request was submitted until the first response is produced, not output - for time-sharing environment

First-Come, First-Served (FCFS) Scheduling

Process Burst Time

P 1 24

P 2 3

P 3 3

  • Suppose that the processes arrive in the order: P 1 ,

P 2 , P 3

The Gantt Chart for the schedule is:

  • Waiting time for P 1 = 0; P 2 = 24; P 3 = 27
  • Average waiting time: (0 + 24 + 27)/3 = 17

P 1 P2 P 3

0 24 27 30

FCFS Scheduling (Cont)

Suppose that the processes arrive in the order

P 2 , P 3 , P 1

  • The Gantt chart for the schedule is:
  • Waiting time for P 1 = 6 ; P 2 = 0 ; P 3 = 3
  • Average waiting time: (6 + 0 + 3)/3 = 3
  • Much better than previous case
  • Nonpreemtive
  • Convoy effect short process behind long process

P 2 P 3 P 1

0 3 6 30

Example of SJF

Process Arrival TimeBurst Time

P 1 0.0 6

P 2 2.0 8

P 3 4.0 7

P 4 5.0 3

• SJF scheduling chart

P 4 P 1 P 3

0 3 9 16

P 2

24

Determining Length of Next CPU

Burst

• Can only estimate the length

• Can be done by using the length of previous

CPU bursts

  • using exponential averaging
    1. Define :
    2. , 0 1
    3. predictedvaluefor thenextCPU burst
  1. actual lengthof CPU burst

≤ ≤

=

=

α α

τ (^) n 1

th tn n

τ (^) n = 1 =α tn + ( 1 −α) τ (^) n.

Prediction of the Length of the Next CPU Burst

Priority Scheduling

• A priority number (integer) is associated with

each process

• The CPU is allocated to the process with the

highest priority (smallest integer ≡ highest

priority)

  • Preemptive
  • Nonpreemptive

• SJF is a priority scheduling where priority is