04 processor management - university of...

35
13/03/2019 1 PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS Program: is an inactive unit. A unit of work submitted by the user. Process: an active entity that requires a set of resources, including a processor and special registers, to perform its functions. Also called a task. Thread: created by a process. Can be scheduled and executed independently of its parent process. WIA2004 (4) 2

Upload: others

Post on 15-Aug-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

1

PROCESSOR MANAGEMENT

WIA2004   (4) 1

DEFINITION OF TERMS

• Program: is an inactive unit. A unit of work submitted by the user.

• Process: an active entity that requires a set of resources, including a processor and special registers, to perform its functions.  Also called a task.

• Thread: created by a process.  Can be scheduled and executed independently of its parent process. 

WIA2004   (4) 2

Page 2: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

2

EXAMPLE OF MULTI‐THREADING

• You want to see a set of pictures at a website.

• If your one‐CPU system allows a process to have only one thread of control, you can instruct your browser to establish one connection with the website and download one picture at a time.

WIA2004   (4) 3

EXAMPLE OF MULTI‐THREADING

• If your system allows processes to have multiple threads of control, you can request more than one picture at a time – the browser sets up multiple connections and download several pictures at once.

WIA2004   (4) 4

Page 3: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

3

ANALOGY 

• You buy a book shelf and want to put it together yourself.

• Once you get home, you take out the instruction manual and start to read the instructions on how to assemble the book shelf.

• The first step is to join part A to part B with a 5 cm screw, and you achieve it successfully.

• You move on to step 2.

WIA2004   (4) 5

ANALOGY 

• As you are about to execute step 3, you hear your little brother crying.  You quickly mark step 3 to indicate where you stop and go to check on your brother.

• You find that your brother fell down and injured his knee.

• You take out the first aid kit and start to bandage your brother’s knee.

• Once your brother has been taken care of, you go back to assembling your book shelf.

WIA2004   (4) 6

Page 4: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

4

ANALOGY 

• Compare that to the OS.

• You are acting as the processor.

• There are 2 programs: assembling a book shelf (Job A) and bandaging your brother’s injury (Job B).

• When you are following the instructions to assemble the book shelf, each step you perform is a process.

• Your brother’s cry was an interrupt.

WIA2004   (4) 7

ANALOGY 

• When you left your book shelf to treat your brother, you left for a higher priority program.

• When you are interrupted, you perform a context switchby marking step 3 on the instruction so that you know where to continue later on.

• When you are treating your brother, each step you execute is a process.

• When a job is completed, it is finished or terminated.

WIA2004   (4) 8

Page 5: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

5

INTRODUCTION 

• In a multiprogramming environment where there are many users and many jobs on the system, the processor must be allocated to each job fairly and efficiently.

• Multiprogramming requires that the processor be allocated to each job/process for a period of time and deallocated when the period expires.

WIA2004   (4) 9

INTRODUCTION 

• One processor can be shared by several jobs/ processes if and only if the OS has a scheduling policy and scheduling algorithm to determine when to stop working on one job and proceed to another.

• In the analogy, you work on Job A until a higher priority job (Job B) came along.

WIA2004   (4) 10

Page 6: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

6

JOB SCHEDULING VS. PROCESS SCHEDULING 

• The Processor Mgr is composed of 2 sub‐managers:

• Job scheduler is in charge of job scheduling,

• Process scheduler is in charge of process scheduling.

• The scheduling of the two jobs (assemble a book shelf and bandage an injury) was on a first‐come, first‐served (FCFS) basis.

WIA2004   (4) 11

JOB SCHEDULING VS. PROCESS SCHEDULING 

• Each job is initiated by the Job Scheduler based on certain criteria.

• Once a job is selected for execution, the Job Scheduler determines when each step (or set of steps) is executed (also based on certain criteria).

WIA2004   (4) 12

Page 7: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

7

JOB SCHEDULING VS. PROCESS SCHEDULING 

• When you started assembling the book shelf, each step in the assembly instructions is selected for execution by the Process Scheduler.

• Each job passes through a hierarchy of managers.

• First, it encounters the Job Scheduler (high level scheduler).

WIA2004   (4) 13

JOB SCHEDULING VS. PROCESS SCHEDULING 

• The Job Scheduler is only concerned with selecting jobs from a queue of incoming jobs and placing them in the process queue.

• Goal: put jobs in a sequence that will use all of the system’s resources as fully as possible.

WIA2004   (4) 14

Page 8: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

8

PROCESS SCHEDULER 

• The Process Scheduler takes over after a job has been placed in the READY queue by the Job Scheduler.

• It is the low‐level scheduler that assigns the CPU to execute the jobs placed in the queue.

• Determines which jobs get the CPU, when, and for how long.

WIA2004   (4) 15

PROCESS SCHEDULER 

• Other responsibilities:

• Decides when a job should be interrupted;

• Determines which queue a job should be moved to during its execution;

• Determines a job has concluded and should be terminated.

• To schedule the CPU, the Process Scheduler takes advantage of a common trait among most programs – they alternate between CPU and I/O cycles.

WIA2004   (4) 16

Page 9: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

9

PROCESS SCHEDULER 

WIA2004   (4) 17

PROCESS SCHEDULER 

• The duration and frequency of CPU cycles vary between programs, but there are general tendencies that can be exploited when selecting a scheduling algorithm.

• I/O bound jobs (e.g. printing a series of documents) have many brief CPU cycles and long I/O cycles.

• CPU bound jobs (e.g. finding the first 300 prime numbers) have long CPU cycles and shorter I/O cycles.

WIA2004   (4) 18

Page 10: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

10

PROCESS SCHEDULER 

• In a highly interactive environment, there is a third layer of Processor Mgr called the middle‐level scheduler.

• When the system is overloaded, the middle‐level scheduler removes active jobs from memory to reduce the degree of multi‐programming and allows jobs to be completed faster.

• Handles swapping out jobs and later swaps them back in.

WIA2004   (4) 19

PROCESS SCHEDULER: JOB AND PROCESS STATES 

• Job and Process Status: a job is in one of five states: HOLD → READY → RUNNING → WAITING → FINISHED.

WIA2004   (4) 20

Page 11: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

11

PROCESS SCHEDULER 

WIA2004   (4) 21

PROCESS SCHEDULER 

Transition Initiated by…HOLD to READY Job Scheduler – checks

availability of main memory and any requested devices.

READY to RUNNING

Process Scheduler – according to predefined algorithm, e.g. FCFS.

RUNNING to READY

Process Scheduler – according to predefined time limit or criterion, e.g. priority interrupt.

WIA2004   (4) 22

Page 12: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

12

PROCESS SCHEDULER 

Transition Initiated by…RUNNING to WAITING

Process Scheduler – initiated by an instruction in the job, such as READ, WRITE, or other I/O rqt.

WAITING to READY Process Scheduler – initiated by a signal from the I/O Device Mgr that the I/O rqt has been satisfied.

RUNNING to FINISHED

Process / Job Scheduler when:(1) job has successfully completed, or (2) OS indicates an error has occurred and the job is terminated prematurely.

WIA2004   (4) 23

PROCESS SCHEDULER: THREAD STATES

WIA2004   (4) 24

Page 13: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

13

PROCESS SCHEDULER

• Each process is represented by a data structure called a Process Control Block (PCB).

• PCB contains the basic info about the job – what it is, where it’s going, how much processing has been completed, where it is stored and how much it has spent in using resources.

• Each thread is represented by a data structure called a Thread Control Block (TCB).

WIA2004   (4) 25

PROCESS SCHEDULER

WIA2004   (4) 26

Page 14: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

14

PROCESS SCHEDULER 

• A job’s PCB is created when the Job Scheduler accepts the job and is updated as the job progresses from beginning to termination.

• PCB contains all info required by the OS to manage the processing of the job.

• The progress of job execution is noted in PCB.

WIA2004   (4) 27

PROCESS SCHEDULER

WIA2004   (4) 28

Page 15: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

15

SCHEDULING POLICIES & ALGORITHMS

• In a multiprogramming environment, there are usually more jobs that can be run at one time.

• In order to schedule jobs, the OS need to resolve 3 limitations:

• There are a finite number of resources (e.g. disk drive, printers),

• Certain resources, once allocated, cannot be shared (e.g. printer),

• Certain resources require operator intervention, i.e., can’t be reassigned automatically.

WIA2004   (4) 29

SCHEDULING POLICIES & ALGORITHMS

• What is a good process scheduling policy?

• Maximize throughput.

• Minimize response time.

• Minimize turnaround time.

• Minimize waiting time.

• Maximize CPU efficiency.

• Ensure fairness for all jobs.

WIA2004   (4) 30

Page 16: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

16

SCHEDULING POLICIES & ALGORITHMS

• One criteria may contradict another.

• How do we choose a good scheduling policy?

• System designer must determine which criteria are most important for the specific system.

• Example: the objective is to maximize CPU utilization while minimizing response time and balancing the use of all system components through a mix of I/O‐bound and CPU‐bound jobs. 

WIA2004   (4) 31

SCHEDULING ALGORITHMS

• The process scheduler relies on a process scheduling algorithm to allocate the CPU and move jobs through the system.

• 6 algorithms:• First‐Come, First Served (FCFS)

• Shortest Job Next (SJN)

• Priority Scheduling

• Shortest Remaining Time (SRT)

• Round Robin

• Multi‐Level Queues

WIA2004   (4) 32

Page 17: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

17

FCFS 

• Is a non‐preemptive scheduling algorithm that handles jobs according to their arrival time.

• Very simple; implemented using FIFO queue.

• Good for batch systems, but unacceptable for interactive systems because users expect a quick response time.

• When a job enters the system, its PCB is lined to the end of the READY queue and is removed when the processor becomes available.

WIA2004   (4) 33

FCFS 

WIA2004   (4) 34

Timeline for job sequence A, B C using FCFS algorithm.

If A, B and C arrive almost simultaneously, the turnaround time for Job A is 15, for Job B is 17 and for Job C is 18. The average turnaround time is: 15 + 17 + 18 = 16.67

3

Page 18: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

18

FCFS 

WIA2004   (4) 35

If the jobs arrive in a different order, say, C, B and A, the turnaround time for Job A is 18, for Job B is 3 and for Job C is 1. The average turnaround time is: 18 + 3 + 1 = 7.3

3

FCFS 

• Disadvantage of FCFS: the average turnaround time vary widely and are seldom minimized.

WIA2004   (4) 36

Page 19: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

19

SHORTEST JOB NEXT 

• Is a non‐preemptive scheduling algorithm.

• Also known as Shortest Job First (SJF).

• Handles jobs based on the length of their CPU cycle time.

• Easiest to implement in batch environments, where the estimated CPU time required is stated by the user at the start of a job.

WIA2004   (4) 37

SHORTEST JOB NEXT 

WIA2004   (4) 38

Job: A B C DCPU cycle: 5 2 6 4

The average turnaround time = 2 + 6 + 11 + 17 = 9.04

Page 20: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

20

SHORTEST JOB NEXT 

The average is actually:

(2) + (4+2) + (5+4+2) + (6+5+4+2)

4

= 4*2 + 3*4 + 2*5 + 1*6 = 9.0

4

The formula:

t1(n) + t2(n‐1) + t3(n‐2) + … + tn(1)

n

WIA2004   (4) 39

SHORTEST JOB NEXT 

• SJN is optimal only when all jobs are available at the same time and CPU estimates are available and accurate.

WIA2004   (4) 40

Page 21: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

21

PRIORITY SCHEDULING 

• Is a non‐preemptive algorithm.

• It gives preferential treatment to important jobs.

• Allows programs with the highest priority to be processed first, and they are not interrupted until their CPU cycles are completed or a natural wait occurs.

WIA2004   (4) 41

PRIORITY SCHEDULING 

• Priorities are assigned by a system administrator using characteristics extrinsic to the jobs.

• Example: assigned based on the position of the user (lecturers first, then research assistants, then students).

• In a commercial environment, users can purchase higher priority to guarantee their jobs are processed the fastest.

WIA2004   (4) 42

Page 22: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

22

PRIORITY SCHEDULING 

• Priorities can also be determined by the Process Mgr based on intrinsic characteristics, such as:

• Memory requirements,

• Number and type of peripheral devices,

• Total CPU time,

• Amount of time already spent in the system.

WIA2004   (4) 43

SHORTEST REMAINING TIME 

• Is a preemptive version of SJN.

• The processor is allocated to the job closest to completion.

• An executing job can be preempted if a newer job in the READY queue has a shorter completion time.

• Cannot be implemented in an interactive system because it requires advance knowledge of CPU time required.

WIA2004   (4) 44

Page 23: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

23

SHORTEST REMAINING TIME 

• Incurs more overhead than SJN because the OS has to monitor the CPU time for all jobs in the READY queue and must perform context switching for the jobs being swapped at preemption time.

WIA2004   (4) 45

SHORTEST REMAINING TIME 

Arrival time: 0    1     2   3  

Job: A    B    C   D

CPU cycle: 6     3    1   4

Turnaround: 14    4    1   6

Average turnaround time = 14 + 4 + 1 + 6 = 6.25

4

WIA2004   (4) 46

Page 24: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

24

SHORTEST REMAINING TIME 

WIA2004   (4) 47

SHORTEST REMAINING TIME 

WIA2004   (4) 48

Compare the same job problem using SJN policy.

Job: A B C DTurnaround: 6 9 5 11Average turnaround time = 6 + 9 + 5 + 11 = 7.75

4

Page 25: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

25

SHORTEST REMAINING TIME 

• SRT is faster than SJN – neglecting context switching that is required for preemptive algorithms.

• When Job A is preempted, all of its processing info must be saved in its PCB for later when its execution is continued.

• The content of Job B’s PCB are loaded into the registers so it can start running again.

• Context switching still takes CPU time and may diminish the advantages of SRT.

WIA2004   (4) 49

ROUND ROBIN 

• Is a pre‐emptive process scheduling algorithm that is used extensively in interactive systems.

• Is not based on job characteristics.

• A pre‐determined slice of time is given to each job to ensure that the CPU is shared among all active processes and no job monopolizes the CPU.

WIA2004   (4) 50

Page 26: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

26

ROUND ROBIN 

• A time slice is called a time quantum that varies between 100 ms to 1 or 2 second.

• Jobs are placed in the READY queue using a FCFS scheme. 

• The Process Scheduler:

• selects the first job from the front of the queue, 

• sets the timer to the time quantum, and

• allocates the CPU to this job.

WIA2004   (4) 51

ROUND ROBIN 

• If the job has not finished executing when the time expires, the job is pre‐empted and put at the end of the READY queue and its info is saved in its PCB.

WIA2004   (4) 52

Page 27: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

27

ROUND ROBIN 

• If the job’s CPU cycles is shorter than the time quantum, either:

• if this is the job’s last CPU cycle and it is finished, all resources allocated to it are released and the completed job is returned to the user; or

• if the CPU cycle has been interrupted by an I/O request, the info about the job is saved in its PCB and it is linked at the end of the appropriate I/O queue.  Later, it is returned to the READY queue.

WIA2004   (4) 53

ROUND ROBIN 

WIA2004   (4) 54

Arrival time: 0 1 2 3Job: A B C DCPU cycle: 8 4 9 5Turnaround: 20 7 24 22

Average turnaround time = 20 + 7 + 24 + 22 = 18.254

Page 28: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

28

ROUND ROBIN 

• Its efficiency depends on the size of the time quantum in relation to the average CPU time.

• If the quantum is too large, it becomes the FCFS scheme.

• If it is too small, the amount of context switching slows down job execution and increases the overhead dramatically.

WIA2004   (4) 55

ROUND ROBIN 

WIA2004   (4) 56

Page 29: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

29

ROUND ROBIN 

• What is the best quantum size?

• It depends on the system.

• Rules of thumb:

• It should be long enough to allow 80% of the CPU cycles to run to completion.

• It should be at least 100 times longer than the time required to perform one context switch.

WIA2004   (4) 57

MULTIPLE‐LEVEL QUEUES 

• Is not a separate scheduling algorithm.

• It works in conjunction with other schemes.

• Examples of multi‐level queues:

• A priority‐based system with different queues for each priority level.

• A system with one queue for CPU‐bound jobs and another for I/O‐bound jobs.  The Process Scheduler alternate btwn the two queues.

WIA2004   (4) 58

Page 30: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

30

MULTIPLE‐LEVEL QUEUES 

• Examples (cont.)

• In an environment that supports batch and interactive jobs, the batch jobs are put in one queue called the background queue while interactive jobs are put in a foreground queue and given priority over the background queue.

WIA2004   (4) 59

MULTIPLE‐LEVEL QUEUES 

• Issues:

• Is the processor allocated to jobs in the first queue until it is empty before moving to the next queue or does it travel from queue to queue?

• Is this fair to those who have earned or paid for a higher priority?

• Is it fair to a low priority queue?

• Can jobs in a lower priority queue move to a higher priority queue?

WIA2004   (4) 60

Page 31: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

31

MULTIPLE‐LEVEL QUEUES 

Case 1: No movement between queues

• A very simple policy.

• The CPU is allocated to jobs in the high‐priority queue using FCFS and is allocated to jobs in lower priority queues only when higher‐priority queues are empty.

WIA2004   (4) 61

MULTIPLE‐LEVEL QUEUES 

Case 2: Movement between queues

• The policy adjusts the priorities assigned to each job.

• High‐priority jobs are treated like all other once they are in the system.

• When a time quantum expires, the job is pre‐empted and moved to the end of the next lower queue.

• A job’s priority may also be increased, e.g. when it issues an I/O request before its time quantum expires.

WIA2004   (4) 62

Page 32: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

32

MULTIPLE‐LEVEL QUEUES 

Case 3: Variable time quantum per queue

• Is a variation of the movement btwn queues policy.

• Allows for faster turnaround of CPU‐bound jobs.

• Each queue is given a time quantum twice as long as the previous queue.

• The highest queue may have a time quantum of 100 ms, the second‐highest queue has a time quantum of 200 ms and so on.

WIA2004   (4) 63

MULTIPLE‐LEVEL QUEUES 

Case 4: Aging

• Ensures that jobs in the lower‐level queues will eventually complete their execution.

• The OS keeps track of each job’s waiting time and when a job gets too old (reaches a certain time limit), it is moved to the next highest queue and so on until it reaches the top queue.

• Guards against indefinite postponement that leads to starvation.

WIA2004   (4) 64

Page 33: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

33

EARLIEST DEADLINE FIRST (EDF)

• EDF is a preemptive scheduling algorithm built to address critical processing requirements of real‐time systems and their pressing deadlines.

• Known as a dynamic priority algorithm.

• E.g. of real‐time systems – driverless car navigation, mechanisms in steel‐making plant and robotics system in a hospital’s operating room.

WIA2004   (4) 65

EDF

• With EDF, the priority can be adjusted as the jobs moves through execution from START to FINISHED.

• Goal  of EDF – process all jobs in the order that is most likely to allow each to run to completion before reaching their respective deadlines.

WIA2004   (4) 66

Page 34: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

34

EDF

• The priority assigned to each job is based on the amount of time remaining until the job’s deadline. The closer the deadline, the higher the priority.

• A job’s deadline is dynamic and is allowed to change ─ the algorithm can change its priority accordingly.

WIA2004   (4) 67

EDF

WIA2004   (4) 68

Job: A B C D E FArrival Time: 0 1 2 3 3 5Execution Time: 3 1 5 2 2 5Deadline: 6 2 10 8 8 15Time-Before-Deadline 6 1 8 5 5 10(at Arrival Time)

A B A E C FD

0 1 2 3 4 6 8 10 13 15 18

Job B Job A Jobs D, E Job C Job FDeadlines

Page 35: 04 Processor Management - University of Malayaweb.fsktm.um.edu.my/~mazliza/kuliah/OS/04-processor-mgmt.pdf · PROCESSOR MANAGEMENT WIA2004 (4) 1 DEFINITION OF TERMS •Program:is

13/03/2019

35

EDF

• Drawbacks:

• Impossible to predict job throughput because job priority rises or falls depending on the mix of jobs in the systems.

• A job with a closer deadline causes other waiting jobs to be delayed.

• High overhead because it constantly evaluates the deadlines of all jobs awaiting execution.

• No guarantee that all jobs will meet their deadlines.

WIA2004   (4) 69