32
3.1 : Resource Management Part2 :Processor Management

3.1 : Resource Management Part2 :Processor Management

Embed Size (px)

Citation preview

Page 1: 3.1 : Resource Management Part2 :Processor Management

3.1 : Resource Management

Part2 :Processor Management

Page 2: 3.1 : Resource Management Part2 :Processor Management

Learning Outcomes

3.1.1 Understand Processor Management3.1.2 Various type of scheduling processes3.1.3 Scheduling Algorithms– First in first out (FIFO)– Shortest Job First (Nonpreemptive SJF)– Shortest Remaining Time (Preemptive SJF)– Round Robin Scheduling – Priority

Page 3: 3.1 : Resource Management Part2 :Processor Management

Processor Management

• To know how Processor Manager allocates a single CPU to execute the jobs / processes from those user.

• Task of Processor Manager : Decidei. How to allocate the CPUii. Monitor whether it’s executing or waiting

a process . iii.Control job entry to ensure balanced use

of resources

Page 4: 3.1 : Resource Management Part2 :Processor Management

Process

• Process is a program in execution • When process execute it changes state• State represent process’s current activity• Each process may be in one of the following state,

which are :– New : the process is being created– Running : instruction are being executed– Waiting : the process is waiting for some event to occur

(reception of signal)– Ready : the process is waiting to be assigned to a processor– Terminated : the process has finished execution

Page 5: 3.1 : Resource Management Part2 :Processor Management

Process

• Waiting queue is place for not executing process.

• Ready queue is contains all the processes that are ready to execute and waiting for the CPU.

• Each process is represent by PCB (Process Control Block)

Page 6: 3.1 : Resource Management Part2 :Processor Management

PCB (Process Control Block)

• PCB contains many pieces of information with specific process which are;– Process state : new, running, waiting, ready and terminated– Program counter : the counter indicate the address of the next

instruction to be executed– CPU Register: include accumulator, index register stack pointer and

so on .– CPU Scheduling algorithm : includes a process priority, or others

CPU scheduling algorithm – Memory – management information : may include such information

as the value of the limit and base register, the page table or segment table, depend on which memory scheme used by operating system.

• PCB can linked together to a ready queue

Page 7: 3.1 : Resource Management Part2 :Processor Management

Scheduling Concept

• The objective of Multiprogramming is to have some process running at all times, - to maximize CPU utilization

• Objective of Time-Sharing is to switch the CPU among processes – so frequently that user can interact with each program while it is running.

• A uniprocessor/ single – user system can have only one running process. If more processes exist, the rest must wait until the CPU is free and can be rescheduled.

Page 8: 3.1 : Resource Management Part2 :Processor Management

Process Scheduling

• Therefore process scheduling is need for schedule processes on your system

• Why to schedule ? To decide which process to run first if there have more than one process is run able.

• Scheduler is part of O/S which make this decision.

Page 9: 3.1 : Resource Management Part2 :Processor Management

Schematic of scheduling

Figure above is shows movement of requests in the system

All requests waiting to be executed are kept in a list of pending requests.

Whenever scheduling is to be performed, the scheduler examines the pending request and select one for executing.

Scheduler

CPU

Scheduled request

Arriving requests

Completed request

Preempted request

Pending requests

Data flow Control Flow

This request is handed over to the CPU.

A request leaves the CPU when it completes or when it is preempted by the scheduler.

In which case, it is put back into the list of pending request

In either situation, scheduler performs scheduling to select next request to be executed.

Page 10: 3.1 : Resource Management Part2 :Processor Management

Cont..

• Preemptive– Interrupts the processing of a job and transfer the CPU to

another job.– Strategy of allowing process that are logically run able to be

suspended.– It is widely used in time-sharing environments

• Nonpreemtive– Always processes a scheduled request to completion– Since only one request is under processing by the CPU at any

time, it is not necessary to maintain the distinction between long, medium and short – term scheduling

– Example of scheduling are FCFS and SJF scheduling

Page 11: 3.1 : Resource Management Part2 :Processor Management

Type of scheduling processes : Long – term Scheduling

– Also known as job scheduling– Is the selection of processes to be allowed to

compete for the CPU. – Normally Long – Term Scheduling is heavily

influenced resource – allocation consideration, especially memory management.

Page 12: 3.1 : Resource Management Part2 :Processor Management

Type of scheduling processes : Short– term Scheduling

– Also known as CPU Scheduling– Is the selection of one process from ready

queue(all the processes that are ready to execute and waiting for the CPU)

Page 13: 3.1 : Resource Management Part2 :Processor Management

Scheduling Creteria

1. CPU utilization (Penggunaan CPU) - keep the CPU as busy as possible

2. Throughput(Daya Pemprosesan) – number of processes that complete their execution per time unit

3. Turnaround time (Masa pusingan)– amount of time to execute a particular process

4. Waiting time( Masa menunggu) – amount of time a process has been waiting in the ready queue

5. Response time(Masa tindakbalas) – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

Page 14: 3.1 : Resource Management Part2 :Processor Management

Optimization Criteria

• Max; – CPU utilization– throughput

• Min; – turnaround time – waiting time – response time

Page 15: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : First Come First Serve

• Is nonpreemptive scheduling algorithm.• Handles job according to their arrival time.

The early arrive the, the sooner they’re served.• It’s very simple algorithm to implement

because it uses FIFO queue.• This algorithm is fine for most batch system,

but it unacceptable for interactive systems because interactive users expect quick response time

Page 16: 3.1 : Resource Management Part2 :Processor Management

Example : FCFS

Process Burst Time (ms)P1 24

P2 3

P3 3

The Gantt Chart for the schedule is:

• Waiting time for P1 = 0ms; P2 = 24ms; P3 = 27ms

• Average waiting time: (0 + 24 + 27)/3 = 17ms

P1 P2 P3

24 27 300

Page 17: 3.1 : Resource Management Part2 :Processor Management

Exercise 1: FCFS

• What will happened if the processes arrive in the order P2 , P3 , P1 i. Draw a gantt chart ii. Calculate average waiting time

Page 18: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : Shortest Job First (SJF)

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

• When CPU available , it is assigned to the process that has smallest next CPU burst.

• If two processes have the same length next CPU burst, FCFS scheduling is used to break the tie.

• The SJF scheduling algorithm is optimal that is gives the minimum average waiting time for a given set of processes.

Page 19: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : Shortest Job First (SJF)

• Two schemes: – nonpreemptive – once CPU given to the

process it cannot be preempted until completes its CPU burst.

– preemptive – 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).

Page 20: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : Shortest Job First (SJF) Nonpreemptive

P4

9

P3P1 P2

1 16 240

ii) Waiting time; P1= 3; P2=16; P3=9; P4=0

iii) Average waiting time; = ( 3 + 16 + 9 + 0 )/ 4= 7 ms

Process Burst Time Arrival Time

P1 6 0

P2 8 0

P3 7 0

P4 3 0

Page 21: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : Shortest Job First (SJF) Nonpreemptive

Process Burst Time Arrival Time

P1 7 0

P2 4 2

P3 1 4

P4 4 5

P1 P3 P2

7 160

P4

8 12

iii) AWT = (0 + 6 + 3 + 7)/4 4ii) Waiting Time 1. P1 = 0 2. P2 = 8 – 2 = 63. P3 = 7 – 4 = 34. P4 = 12 – 5 = 7

Page 22: 3.1 : Resource Management Part2 :Processor Management

Exercise SJF Nonepreemptive

Open your labwork book, page 11(Activity 2)

Page 23: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm : Shortest Job First (SJF) Preemptive / SRTF

Rules :Current process preempted if a new process with CPU burst time less than remaining burst time for current executing process.

Page 24: 3.1 : Resource Management Part2 :Processor Management

Example 1: SRTF

Process Burst Time Arrival Time

P1 10 0

P2 2 2

P1

420

P1

12

P2

ii) Waiting TimeP1 = 0 + (4-2) = 2P2 = 2-2 = 0

ii) AWTP1+P2 = 1ms 2

Page 25: 3.1 : Resource Management Part2 :Processor Management

Exercise 1: SRTF

Open your labwork book, page 11(Activity 2)

Page 26: 3.1 : Resource Management Part2 :Processor Management

Exercise 2 : SRTF

i) Draw a gantt chartii) Calculate are waiting time for each process iii) Calculate average waiting time

Process Burst Time Arrival Time

P1 24 0

P2 3 1

P3 3 2

P4 1 3

Page 27: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm: Round Robin Scheduling /RR

• Is a preemptive process scheduling algorithm • Each process gets a small unit of CPU time

(time quantum/time slice), usually 10-100 milliseconds.

• Time quantum = time interval• After this time has elapsed, the process is

preempted and added to the end of the ready queue.

Page 28: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm: RR Scheduling

Process Burst Time

Time Quantum = 4msP1 24

P2 3

P3 3

P10 107 18

P1P3P2 P1P1 P1P1

144 2622 30

ii) Waiting time1. P1 = (0 + (10-4)) = 6 ms2. P2 = 4 ms3. P3 = 7 ms

iii) Average waiting time= ( 6 + 4 + 7 )/ 3= 5.66 ms

Page 29: 3.1 : Resource Management Part2 :Processor Management

Exercise 1: RR Scheduling

Open your labwork book, page 14 (Activity 1)

Page 30: 3.1 : Resource Management Part2 :Processor Management

Scheduling Algorithm: 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 the predicted next CPU burst time.

• Problem Starvation ( low priority processes may never execute)

• Solution Aging ( as time progresses increase the priority of the process)

Page 31: 3.1 : Resource Management Part2 :Processor Management

Example 1: Priority Scheduling

Process Burst Time Priority

P1 10 3

P2 1 1

P3 2 4

P4 1 5

P5 5 2

P26

P3P1P5 P41 1816 190

ii) Waiting time1. P1 = 6 ms2. P2 = 0 ms3. P3 = 16 ms4. P4 = 18 ms5. P5 = 1 ms

iii) Average waiting time= ( 6 + 0 + 16 + 18 + 1 )/ 5= 8.2 ms

Page 32: 3.1 : Resource Management Part2 :Processor Management

Exercise 1: Priority Scheduling

Open your labwork book, page 15 (Activity 2)