Tải bản đầy đủ (.pdf) (53 trang)

Lecture Operating systems: A concept-based approach (2/e): Chapter 4 - Dhananjay M. Dhamdhere

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1022.37 KB, 53 trang )

PROPRIETARY MATERIAL. ©  2007 The McGraw­Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide  may be displayed, reproduced or distributed 
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw­Hill 
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission. 

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 1
Copyright © 2008


Scheduling



Scheduling is the act of determining the order in which
requests should be taken up for servicing
– A request is a unit of computational work
* It could be a job, a process, or a subrequest made to a process

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 2
Copyright © 2008



Scheduling related concepts and terms



Request related concepts and terms
– Arrival time
* Request is submitted to the system

– Admission time
* Kernel starts considering the request for scheduling

– Completion time
– Deadline
* Time by which servicing of a request should be completed

– Service time
* Total of CPU time and I/O time required to service a request

– Preemption
– Priority
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 3
Copyright © 2008


A schematic of scheduling


  

•  Admission of an arrived request may be delayed for reasons seen later
•  An admitted request remains pending until it is scheduled
•  A preempted request is put back into the pool of pending requests
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 4
Copyright © 2008


Performance related concepts and terms



User service related concepts and terms
– Response time
– Turn-around time
– Weighted turn-around = Turn-around time / service time
– Deadline overrun
* Amount of time by which a deadline is missed

– Fair share
* A specified share of CPU time that should be devoted to a process
or a group of processes


– Response ratio
* Response ratio = (time since arrival + service time) / service time

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 5
Copyright © 2008


Performance related concepts and terms



We shall use the following terms
– Terms related to average service
* Mean response time
* Mean turn-around time

– Terms related to scheduling performance
* Schedule length
 The total amount of time required to service a set of requests
* Throughput
 Number of requests serviced per unit of time

Chapter 4: Scheduling

Dhamdhere: Operating Systems—

A Concept­Based Approach, 2 ed 

Slide No: 6
Copyright © 2008


Fundamental techniques of scheduling



Three fundamental techniques are used in scheduling
– Priority-based scheduling
* As seen in the context of multiprogramming

– Reordering of requests: it may be used to
* Enhance system throughput, e.g., as in multiprogramming
* Enhance user service, e.g., as in time sharing

– Variation of time slice
* Small time slice yields better response times
* Large time slice may reduce scheduling overhead

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 7
Copyright © 2008



More on priority



Features of priority-based scheduling
– Priorities may be static or dynamic
* A static priority is assigned to a request before it is admitted
* A dynamic priority is one that is varied during servicing of a request

– How to handle processes having same priority?
* Round-robin scheduling is performed within a priority level

– Starvation of a low priority request may occur
Q: How to avoid starvation?

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 8
Copyright © 2008


Kinds of Scheduling



Scheduling may be performed in two ways

– Non-preemptive scheduling
* A process runs to completion when scheduled

– Preemptive scheduling
* Kernel may preempt a process and schedule another one
* A set of processes are serviced in an overlapped manner

Q: What are the benefits of preemptive scheduling?

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 9
Copyright © 2008


Processes for scheduling



In our discussion, we will consider the following
processes for scheduling
Process

Chapter 4: Scheduling

P1


P2

P3

P4

P5

Arrival time

0

2

3

5

9

Service time

3

3

2

5


3

Deadline

4

14

6

11

12

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 10
Copyright © 2008


Non-preemptive scheduling



Principle
– Reorder the processes to improve performance
* Performance criteria
 Throughput
 Turn around times of processes


Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 11
Copyright © 2008


Non-preemptive scheduling policies



Three principal non-preemptive scheduling policies are
– First come, first served (FCFS)
– Shortest request next (SRN)
– Highest response ratio next (HRN)
Response ratio = (Time since arrival + service time) / service
time
Q: Which policy will provide better performance under what
conditions? Consider throughput, average turn-around time,
manipulation by users, starvation possibility …

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 12

Copyright © 2008


Performance of FCFS and SRN scheduling

         Arrives Service

                     Time
P1        0          3
P2        2          3
P3        3          2
P4        5          5
P5        9          3

•  Table shows sequence of decisions made by the scheduling policies
•  SRN schedules P3 ahead of P2  because it is shorter
•  Mean turn­around time is shorter by SRN than by FCFS scheduling
Qs:  Schedule lengths? Should we always use SRN?
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 13
Copyright © 2008


Highest response ratio next (HRN) policy

•  P14   has a shorter service time than P13

•  It has a higher response ratio at 8 seconds, so it is  scheduled ahead of P13
Qs:  Advantages / disadvantages over FCFS and SRN?

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 14
Copyright © 2008


Non-preemptive scheduling policies



Consider service provided to different kinds of requests
– Short requests
* SRN provides them a favoured treatment; FCFS does not
Q: Does HRN provide them a favoured treatment?

– Long requests
* May starve if SRN scheduling is used
* They do not starve if HRN scheduling is used
Q: Why?



SRN is not a feasible scheduling policy
– Service times of processes are not known

– Service time information provided by users is not reliable

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 15
Copyright © 2008


Preemptive scheduling policies



Principle
– Preempt a process to permit other processes to operate
* Aimed at improving throughput and response times



Scheduling policies
– Round-robin with time slicing (RR)
– Least completed next (LCN)
* Select the process that has received least amount of CPU time

– Shortest time to go (STG)
* Select the process with least remaining service time

Chapter 4: Scheduling


Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 16
Copyright © 2008


Scheduling using preemptive scheduling policies

     Arrives Service
                     time
P1       0           3 
P2       2           3
P3        3           2
P4       5           5
P5        9           3

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 17
Copyright © 2008


Operation of preemptive scheduling policies

Notes:

• In LCN, n  in Pi:n 

   is CPU time  
   provided to Pi
• In STG, n  in Pi:n 
  is remaining service
  time of Pi

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 18
Copyright © 2008


Performance of preemptive scheduling policies

•  Column C shows the completion time of a process
•  ta is the turn­around time and w is the weighted turn­around
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 19
Copyright © 2008



Variation of average response time with time slice

•  Response time = n x (time slice + scheduling overhead)
•  The response time is larger for time slice of 5 msec than for 10 msec
   because of the scheduling overhead
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 20
Copyright © 2008


Preemptive scheduling policies



Comparison of preemptive scheduling policies
– Performance
* Depends on characteristics of a workload

– Starvation
* The STG policy suffers from starvation

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 


Slide No: 21
Copyright © 2008


Long, medium, and short-term scheduling



A single scheduler cannot provide the desired
combination of performance and user service, so an OS
uses three schedulers
– Long-term scheduler
* Decides when to admit an arrived process
 Uses nature of a process, availability of resources to decide

– Medium-term scheduler
* Performs swapping
 Maintains a sufficient number of processes in memory

– Short-term scheduler
* Decides which ready process should operate on the CPU
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 22
Copyright © 2008



Event handling and scheduling

•  An event handler passes control to the long­ or medium­term scheduler
•  These schedulers pass control to the short­term scheduler
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 23
Copyright © 2008


Scheduling in a time sharing system

The medium term scheduler swaps blocked and ready processes and
                              changes their states accordingly
Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 24
Copyright © 2008


Scheduling mechanisms and policy modules




The scheduling policy invokes the scheduling
mechanisms when necessary; the mechanisms access
scheduling data
– Scheduling mechanisms
* Process dispatching
* Context save
* Priority computation and reordering

– Data structures
* Scheduling policy uses PCBs; mechanisms update PCBs

Chapter 4: Scheduling

Dhamdhere: Operating Systems—
A Concept­Based Approach, 2 ed 

Slide No: 25
Copyright © 2008


×