Docsity

CPU Scheduling: Concepts, Algorithms, and Evaluation, Slides of Operating Systems

Partial preview of the text

Download CPU Scheduling: Concepts, Algorithms, and Evaluation and more Slides Operating Systems in PDF only on Docsity!

CPU SCHEDULING

Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling 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.
  • CPU burst distribution

Histogram of CPU-burst Times

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:
    • Switches from running to waiting state.
    • Switches from running to ready state.
    • Switches from waiting to ready.
    • Terminates.
  • Scheduling under 1 and 4 is nonpreemptive.
  • All other scheduling is preemptive.

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

Scheduling Criteria

  • 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, not output (for time- sharing environment)

First-Come, First-Served (FCFS)

Process Burst Time P1 24 P2 3 P3 3

  • Suppose that the processes arrive in the order: P1 , P2 , P. The Gantt Chart for the schedule is:
  • Waiting time for P1 = 0; P2 = 24; P3 = 27
  • Average waiting time: (0 + 24 + 27)/3 = 17

P 1 P 2 P 3 0 24 27 30

FCFS Scheduling (Cont.)

  • Suppose that the processes arrive in the order P2 , P3 , P
  • The Gantt chart for the schedule is:
  • Waiting time for P1 = 6; P2 = 0; P3 = 3
  • Average waiting time: (6 + 0 + 3)/3 = 3
  • Much better than previous case.

P 2 P 3 P 1 0 3 6 30

Shortest-Job-First (SJF) Scheduling

  • Preemptive Version (SRTF)
    • if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest- Remaining-Time-First (SRTF).
  • SJF is optimal – gives minimum average waiting time for a given set of processes.

Example of Non-Preemptive SJF

Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4

  • SJF (non-preemptive)
  • Average waiting time = (0 + 6 + 3 + 7)/4 = 4

P 1 P 3 P 2 0 3 7 16

P 4 8 12

Docsity.com

Predicting Next CPU Burst

  • The exponential average formula 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. predicted value for the next CPUburst
  4. actual lenght of CPUburst

 

   

 (^) n 1

th tn n

 n  1  tn   1   n.

actual length

Next CPU Burst

Exponential Averaging

  • If we expand the formula, we get: n+1 =  tn+(1 - ) n n+1 =  tn+(1 - )[  tn-1 +(1 - ) n-1 ] + … +(1 -  )j  tn-j + … +(1 -  )n+1  0
  • Since both  and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor.

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