Operating Systems
This presentation is the property of its rightful owner.
Sponsored Links
1 / 17

Operating Systems Lecture 17 Scheduling III PowerPoint PPT Presentation


  • 45 Views
  • Uploaded on
  • Presentation posted in: General

Operating Systems Lecture 17 Scheduling III. Recall Scheduling Criteria. CPU utilization –fraction of time the CPU is busy. CPU efficiency – fraction of time the CPU is executing user code. Throughput – # of processes completed per unit time

Download Presentation

Operating Systems Lecture 17 Scheduling III

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Operating systems lecture 17 scheduling iii

Operating SystemsLecture 17

Scheduling III

Operating System Concepts


Recall scheduling criteria

Recall Scheduling Criteria

  • CPU utilization –fraction of time the CPU is busy.

  • CPU efficiency – fraction of time the CPU is executing user code.

  • Throughput – # of processes completed per unit time

  • Average Turnaround time – average delay between job submission and job completion.

  • Normalized turnaround time – Ratio of turnaround time to service time per process. Indicates the relative delay experienced by a 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.

Operating System Concepts


Example of non preemptive sjf

Example of Non-Preemptive SJF

P1

P3

P2

P4

0

3

7

8

12

16

ProcessArrival TimeBurst Time

P10.07

P22.04

P34.01

P45.04

  • SJF (non-preemptive) Selection criterion: min(s)

  • Average waiting time = (0 + 3 + 6 + 7)/4 = 4

  • Avg service time = (7 + 4 + 1 + 4)/4 = 4

  • Throughput = 4/16 = 0.25

  • Avg turnaround = (7 + 10 + 4 + 11)/4 = 32/4 = 8

    • Check consistency. Wait = (Turnaround - Service - Dispatch)

Operating System Concepts


Example of preemptive sjf srtf shortest remaining time first

Example of Preemptive SJF (SRTF--Shortest remaining time first)

P1

P2

P3

P2

P4

P1

11

16

0

2

4

5

7

ProcessArrival TimeBurst Time

P10.07

P22.04

P34.01

P45.04

  • SJF (preemptive) Selection criterion: min(s - e)

  • Average waiting time = (9 + 1 + 0 + 2)/4 = 3

  • What statistics are different from non-preemptive SJF?

    What are the values of these stats?

Operating System Concepts


Determining length of next cpu burst

Determining Length of Next CPU Burst

  • Can be done by using the length of previous CPU bursts, using exponential averaging.

If we expand the formula, we get:

n+1 =  tn+(1 - )  tn-1+ …

+(1 -  )j  tn-j+ …

+(1 -  )n+1 0

Operating System Concepts


Priority scheduling

Priority Scheduling

  • A priority number (integer) is associated with each process.

  • The CPU is allocated to the process with the highest priority

    • Some systems have a high number represent high priority.

    • Other systems have a low number represent high priority.

    • Text uses a low number to represent high priority.

  • Priority scheduling may be preemptive or nonpreemptive.

Operating System Concepts


Assigning priorities

Assigning Priorities

  • SJF is a priority scheduling where priority is the predicted next CPU burst time.

  • Other bases for assigning priority:

    • Memory requirements

    • Number of open files

    • Avg I/O burst / Avg CPU burst

    • External requirements (amount of money paid, political factors, etc).

  • Problem: Starvation -- low priority processes may never execute.

  • Solution: Aging -- as time progresses increase the priority of the process.

Operating System Concepts


Round robin scheduling

Round Robin Scheduling

  • Each process gets a small unit of CPU time (time quantum).

    • A time quantum is usually 10-1000 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.

Operating System Concepts


Example of rr time quantum 20

Example of RR, time quantum = 20

P1

P2

P3

P4

P1

P3

P4

P1

P3

P3

0

20

37

57

77

97

117

121

134

154

162

ProcessBurst Time

P153

P2 17

P368

P4 24

  • The Gantt chart is:

  • Compute: Avg service time, Throughput, avg turnaround, avg wait:

  • Typically, higher average turnaround than SJF, but better response.

  • Suppose P1 arrives at 0, P2 at 19, P3 at 23 and P4 at 25. What changes? What are the new values?

Operating System Concepts


Rr performance

RR Performance

  • Performance varies with the size of the time slice, but not in a simple way.

  • Short time slice leads to faster interactive response.

    • Problem: Adds lots of context switches. High Overhead.

  • Longer time slice leads to better system throughput (lower overhead), but response time is worse.

    • If time slice is too long, RR becomes just like FCFS.

  • Time slice vs process switch time:

    • If time slice = 20 msec and process switch time = 5 msec, then 5/25 = 20% of CPU time spent on overhead.

    • If time slice = 500 msec, then only 1% of CPU used for overhead.

    • The time slice should be large compared to the process switch time.

    • A typical time slice is 1 sec (4.3 BSD UNIX)

  • RR makes the implicit assumption that all processes are equally important.

    • Cannot use RR is you want different processes to have different priorities.

Operating System Concepts


Multilevel queues

Multilevel Queues

  • Ready queue is partitioned into separate queues: E.g.:foreground (interactive)background (batch)

  • Each queue has its own scheduling algorithm, e.g.:foreground – RRbackground – FCFS

  • Scheduling must be done between the queues. Possible methods:

    • Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation.

    • Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes;

      • i.e., 80% to foreground in RR

      • 20% to background in FCFS

  • Works well for time sharing systems.

Operating System Concepts


Multilevel queue scheduling

Multilevel Queue scheduling

Operating System Concepts


Multilevel feedback queue

Multilevel Feedback Queue

  • A process can move between the various queues; aging can be implemented this way.

  • Multilevel-feedback-queue scheduler defined by the following parameters:

    • number of queues

    • scheduling algorithms for each queue

    • method used to determine when to upgrade a process

    • method used to determine when to demote a process

    • method used to determine which queue a process will enter when that process needs service (where to put new processes)

Operating System Concepts


Typical behavior for multilevel feedback queues

Typical behavior for multilevel feedback queues

  • New processes go to the highest priority queue for that job type.

    • Top priorities reserved for system processes.

  • If process uses full time slice, it moves down a priority.

  • If process blocks before using full time slice, it remains at the same priority.

  • Higher priority queues have smaller time slices than lower priority queues.

Operating System Concepts


Example of a multilevel feedback queue

Example of a Multilevel Feedback Queue

  • Three queues:

    • Q0 – time quantum 8 milliseconds

    • Q1 – time quantum 16 milliseconds

    • Q2 – FCFS

  • Scheduling

    • A new job enters queue Q0which is servedFCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1.

    • At Q1 job is again served FCFS and receives 16 additional milliseconds. If it still does not complete, it is preempted and moved to queue Q2.

Operating System Concepts


Multilevel feedback queues

Multilevel Feedback Queues

Operating System Concepts


Notes on multilevel feedback queues

Notes on Multilevel Feedback Queues

  • Short processes are favored.

  • Good for interactive processes with short CPU bursts.

  • Is starvation Possible?

    • Yes--Long processes may wait forever.

    • To avoid--increase the priority of a process if it has been waiting for some period of time in some queue.

Operating System Concepts


  • Login