+ All Categories
Home > Education > Processor / CPU Scheduling

Processor / CPU Scheduling

Date post: 06-May-2015
Category:
Upload: izaz-roghani
View: 319 times
Download: 1 times
Share this document with a friend
Description:
The CPU scheduling PPT slides
31
[email protected] 1 PROCESSOR/CPU SCHEDULING BY: Izaz Khan Roghani
Transcript
Page 1: Processor / CPU Scheduling

[email protected] 1

•PROCESSOR/CPU SCHEDULING

BY:

Izaz Khan Roghani

Page 2: Processor / CPU Scheduling

2

• Scheduling CPU is the brain of the computer system __ performs all the

processing inside the computer. Programs enter to systems ___becomes process __ handled by

OS. In a Multi-programming/Multi-user systems ___ many processes __

each process wait for its turn to utilize the CPU and to perform some useful task.

That’s why CPU requires some type of mechanism ___ to serve all the processes uniformly.

“This mechanism is handled by the OS and this management of the CPU is called CPU/processor scheduling”.

EXPLANATION: more than one processes in the Ready state __ OS decision __ which one to run first __ which one to wait.

The part of OS which makes this decision is called “Scheduler”, the algorithm it uses is called the scheduling algorithm.

[email protected]

Page 3: Processor / CPU Scheduling

3

• Scheduling Scheduling affects the performance of the system because it

determines which process will wait and which will progress. Simply we can say that the problem of determining, when processor

should be assigned to which process (currently in memory) is called scheduling.

Scheduling is a fundamental OS function. Since the CPU is such an important resource, it is very important to

develop good scheduling algorithms.

[email protected]

Page 4: Processor / CPU Scheduling

4

• Scheduling Objectives Scheduling typically attempts to achieve some combination of the

following goals, and the overall scheduling effort is intended to meet system’s performance and behavior.

THROUGHPUT: Maximize the number of jobs processed/completed per unit time.

UTILIZATION OF RESOURCES: Maximize utilization of other resources (disks, printers etc).

RESPONSE TIME: Minimize the response time for interactive users (on-line users/time sharing) i.e. provide tolerable response time.

TURNAROUND TIME: Minimize the time user wait for the output (batch users) = waiting time + computation time + I/O time

FAIRNESS: To make sure that each process gets its share of the CPU i.e. treated equally.

EFFICIENCY: To keep the CPU busy 100% of the time.

[email protected]

Page 5: Processor / CPU Scheduling

5

• Scheduling Objectives GRACEFUL DEGRADATION: If the system becomes overloaded, it

should not ‘collapse’, but avoid further loading and temporarily reduce the level of service (response time).

[email protected]

Page 6: Processor / CPU Scheduling

6

• CPU I/O Burst Cycle The execution of a process consist of an alternation of CPU Bursts

and I/O Bursts. A process begins and ends with a CPU burst. In between, CPU

activity is suspended whenever an I/O operation is needed. I/O BOUND: If the CPU bursts are relatively short compared to the

I/O bursts, then the process is said to be I/O bound. For example, if the processor is capable of making rapid changes to

a large database stored on a disk faster than the drive mechanism can perform the read and write operations, the computer is input/output-bound.

CPU Bound: If the CPU bursts are relatively long compared to the I/O bursts, then the process is said to be CPU bound.

For example, if a processor is involved in a long arithmetic computations, then the process is CPU bound.

[email protected]

Page 7: Processor / CPU Scheduling

7

•SCHEDULING LEVEL

HIGH LEVEL SCHEDULING INTERMEDIATE LEVE SCHEDULING LOW LEVEL SCEDULING

[email protected]

Page 8: Processor / CPU Scheduling

8

• SCHEDULING LEVELS In a process life cycle, scheduling can be used at THREE

levels/points. The scheduling levels discuss the level/point at which scheduling mechanism can be used.

• High level Scheduling Also called Job/Admission/long term scheduling. When a job is entered into a system and become a process it is high

level scheduling. Often admission, a process start competing actively for the

resources of the system. HLS controls the admission of jobs into the system, i.e. it decides

which newly jobs are to be converted into processes and be put into the READY queue to compete for the CPU.

This activity is only really applicable to Batch systems.

[email protected]

Page 9: Processor / CPU Scheduling

9

• Intermediate level Scheduling (ILS) Also called Medium level scheduling (MLS). MLS is applicable to systems where a process within the system

(but not currently running i.e. in the Ready Queue) can be swapped out of memory on to disk (Virtual Memory) in order to reduce the system load.

MLS determines that which process shall be allowed to compete for the CPU and which shall be suspended/blocked in response to Virtual memory.

MLS acts as a buffer between the admission of jobs to the system, and the assigning of the CPU to these jobs.

[email protected]

Page 10: Processor / CPU Scheduling

10

• Low level Scheduling (LLS) The LLS is the most complex and significant of the scheduling levels LLS determines that which Ready process will be assigned to the

CPU, when it is next available, and actually assign the CPU to this process.

LLS is performed by the Dispatcher, i.e. it dispatches a process to the CPU, which operates many times per second.

The dispatcher must therefore resides all the time in main memory The LLS will be invoked whenever the current process relinquishes

(leave/remove) control ( because of any I/O call or interrupt arises). A number of policies have been devised for use in LLS, each of

which has its own advantages and disadvantages.

HOME WORK: Pages # 287….291 from H.M. Deitel.

[email protected]

Page 11: Processor / CPU Scheduling

11

• Scheduling Levels Job waiting for

Entry

Job waiting forinitiation

SuspendedProcess waiting

For initiation

Active processes

Running Processes

Completed

[email protected]

Page 12: Processor / CPU Scheduling

12

•SCHEDULING TYPES PREEMPTIVE SCHEDULING NON-PREEMPTIVE SCHEDULING

[email protected]

Page 13: Processor / CPU Scheduling

13

• SCHEDULING TYPES Scheduling types determines how the processes use the CPU after

dispatching or at LLS. Either the process remain in the CPU until its completion or it

remains there for a short time (quantum or time slice).

• Preemptive Scheduling Preemption basically means that a process may be forcibly removed

from the CPU even if does not want to release the CPU i.e. it is still executing but a higher priority process needs the CPU.

In preemptive scheme, the LLS may remove a process from the RUNNING state in order to allow another process to run.

In a preemptive scheme, a running process may be forced to yield the CPU ( thus returning to the ready list) by an external rather than by its own action. Such external events can be:

A higher priority process enters the systems. A waited process becomes ready (because of I/O interrupt).

[email protected]

Page 14: Processor / CPU Scheduling

14

• Non-Preemptive Scheduling In Non-Preemptive scheme, a process once given to the processor,

will be allowed to run until its completion or until it terminates or incurs an I/O wait.

OR we can say that when a process can not “forcibly” lose the processor.

Non-Preemptive scheduling is also known as “Run-to-Completion”, which is slightly inaccurate, since the process will lose the processor if it incurs an I/O wait.

ASSIGNMENT:Q1: Compare Preemptive with Non-preemptive scheduling?

[email protected]

Page 15: Processor / CPU Scheduling

15

• Preemptive VS Non-Preemptive Scheduling Preemptive scheduling is useful, where high priority process

required rapid attention. In a real time system and in a interactive timesharing system,

preemptive scheduling is important. In Preemptive scheduling, interrupts disturbs the efficiency of the

CPU. In a Non-preemptive scheduling systems, short job are made to wait

by long jobs. Non-preemptive scheduling is easy to implement, they are simple. In Non-preemptive scheme, high-priority jobs can not displace

waiting jobs.

[email protected]

Page 16: Processor / CPU Scheduling

16

• Scheduling Criteria There are many scheduling algorithms, and various criteria to judge

their performance. Different algorithms may favor different types of processes. A few criteria are: Max CPU utilization – try to keep the CPU as busy as possible Max Throughput – Number of processes completed in a unit

time. Min Turnaround time – Time needed to execute a process. Min Response time & waiting time.

The CPU scheduling algorithm should try to maximize the above points.

[email protected]

Page 17: Processor / CPU Scheduling

17

•SCHEDULING ALGORITHMS/POLICIES

[email protected]

Page 18: Processor / CPU Scheduling

18

• FIFO or FCFS (First-come-first-served) The simplest scheduling algorithm/policy. As the name implies, the FCFS policy simply assigns the processor to the

process which is first in the READY queue. This is the Non-preemptive scheme. (Run-to-completion) FAIR in a sense: Run the jobs till completion UNFAIR in a sense: Long job make short job to wait for a long time and un-

important jobs make important job wait. Its response time is predictable. ( By Gantt Chart) FIFO/FCFS is rarely used as a master scheme in today’s system, but it is

often embedded with other schemes.

------- P4 P3 P2 P1 P 1

[email protected]

Page 19: Processor / CPU Scheduling

19

• Illustration of FCFS policy We assume the arrival in the READY queue for processes in the

numbered sequence, we can calculate how long each process has to wait.

(a) (b)

Job Est. Burst/Run Time waiting

1 2 (unit time) 0

2 60 2 3 1 62

4 3 63

5 50 66

The average waiting time= (0+2+62+63+66)/5= ?

[email protected]

Page 20: Processor / CPU Scheduling

20

• SJF (Shortest Job First – Non-Preemptive) It is a Non-preemptive scheduling policy. In this policy waiting jobs with shortest (shortest) estimated run-time is run

or dispatch next. It is a priority scheme, in which SJF favors short job at the expense of

longer jobs. If we use this scheme on the jobs in Table 1, above, we get a rather

different picture as shown in Table 2.

(a) (b)Job Est. Burst/Run Time waiting

3 1 0 1 2 (unit time) 1 4 3 3 5 50 6 2 60 56

[email protected]

Page 21: Processor / CPU Scheduling

21

• SJF (preemptive version) We also have a Preemptive version of SJF. In the preemptive version of SJF, a long job in the queue may be

delayed by a succession of smaller jobs arriving in the queue. In the example of Table 2, it is assumed that the job list is constant,

but, in practice, before Time 3 is when job 5 is due to start, another job of length, say, 10 minutes could arrive and be placed ahead of job5.

This queue jumping effect could recur (occur again) many times, effectively preventing job 5 from starting at all; this situation is known as Starvation.

(a) (b) Job Est. Burst/Run Time waiting 3 1 0 1 2 (unit time) 1 4 3 3 x 10 5 50 6 2 60 56

[email protected]

Page 22: Processor / CPU Scheduling

22

• SRT ( Shortest Remaining Time) SRT is a preemptive version of SJF, and is useful in timesharing

environment. In SRT, suppose a process “A” is dispatched to the CPU and started

processing, however, during of this process, another process say “B” arrives who’s Run-time is shorter than Job “A’s” remaining run time, then job “A” will be preempted and job “B” will be allow to execute.

SRT favors short jobs even more than SJF, since a currently running long job could be ousted (removed) by a new shorter one.

DANGER OF STARVATION: The danger of starvation of longer jobs also exists in this scheme. Longer jobs --- waits for shorter jobs.

Implementation of SRT requires an estimate of Total-run-time and measurement of Elapsed run-time.

So SRT has a higher over head than SJF

[email protected]

Page 23: Processor / CPU Scheduling

23

• HRN (Highest Response Ratio Next) To correct some of the weaknesses (Danger of starvation) of the

SJF policy, Brinch Hansen developed the HRN strategy. HRN is a Non-preemptive scheduling, (Run-to-completion). In HRN, a job with the highest priority value will be selected for

running. The priority of job is a function of its Service time and its waited

time Dynamic priorities are calculated in HRN according to the formula

Priority, P = time waiting + runt time / burst timerun time

Longer and shorter job’s are both given a favorable treatment. Time waiting and run-time is the system response time.

[email protected]

Page 24: Processor / CPU Scheduling

24

• HRN When processes first appear in the READY queue, the “time

waiting” will be zero and hence P will be equal to 1 for all processes. Consider two jobs ‘A’ and ‘B, with run-time of 10 and 50 minutes

respectively. After each has waited 5 minutes, their respective priorities are:

A : P = (5+10) = 1.5 B: P = (5 + 50) = 1.1

10 50 On this basis, the shorter job A will be selected. However, that if ‘A’ has just started (wait time=0), then according to

the formula the priority of process ‘A’ will be P = 1, and since the priority for process ‘B’ is p= 1.1, then in this situation process “B” will be chosen in preference to ‘A’.

This technique that a job can’t be starved.

[email protected]

Page 25: Processor / CPU Scheduling

25

• ASSIGNMENT Q1: GIVE AN EXAMPLE OF HRN POLICY WITH THE HELP OF

GANTT CHART? WHAT IS ONE OF THE MAJOR PROBLEM WITH PRIORITY

BASED SCHEDULING AND WHAT IS THEIR SOLUTION?

BOOK: CHAPTER # 6, BY SILBERSCHATZ

[email protected]

Page 26: Processor / CPU Scheduling

26

• ROUND ROBIN SCHEDULING (RRS) The oldest, simplest, fairest and most widely used scheduling policy. In the RR scheme, a process is selected for running from the READY queue in

FIFO (First in First out) sequence. Each process which enters in the CPU, is given limited amount of CPU time,

called a “time slice / quantum”. However, if the process runs beyond the time slice, then it is interrupted and

returned to the end of the READY queue. In other words, each active process is given a “time slice” in rotation. Time slice is usually 10 – 100 millisecond.

------- P4 P3 P2 P1 P 1PA

[email protected]

Page 27: Processor / CPU Scheduling

27

• RR Scheduling RR is effective in timesharing environment in which the system

needs to guarantee reasonable response time for interactive users. The RR scheme is preemptive, but preemption occurs only by

expiry of the time quantum.

[email protected]

Page 28: Processor / CPU Scheduling

28

• Multi-level Feedback Queues (MFQ) The MFQ scheme is an attempt to provide a more adaptive policy

which will treat processes in the basis of their past behavior. Figure shows a typical set up for a MFQ system. It consists of a

number of separate queues of entries which represent active processes.

Each queue represents a different priority, with the top queue being highest priority and lower queues successively lower priorities.

Within each queue, the queued processes are treated in a FIFO/FCFS fashion, with a time quantum being allotted to each process in the queue.

A new process enters the system at the end of the top queue, and will be execute for a time slice allotted to it.

Upon expiry of quantum, it will moves to the end of next lower queue.

At last it will move to the Lowest level queue, where a RR scheme is applied and then it execute their till the completion of the process.

[email protected]

Page 29: Processor / CPU Scheduling

29

•Multilevel Feedback Queues

[email protected]

Page 30: Processor / CPU Scheduling

30

•Example of Multilevel Feedback Queue

Three queues: Q0 – RR with time quantum 8 milliseconds

Q1 – RR time quantum 16 milliseconds

Q2 – FCFS Scheduling

A new job enters queue Q0 which is served FCFS. 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.

[email protected]

Page 31: Processor / CPU Scheduling

31

ASSIGNMENT

Q1: WHAT IS DISPATCHER, AND WHAT IS MEANT BY

DISPATCH LATENCY?

Q2: WHAT ARE THE ADVANTAGES AND DIS-ADVANTAGES OF

PEEMPTIVE AND NON-PREEMPTIVE SCHEDULING ALGORITHMS?

Q3: WHAT IS STATIC AND DYNAMIC PRIORITIES ?

Q4: WHAT IS CONVOY EFFECT IN FCFS SCHEDULING

ALGORITHM?

[email protected]


Recommended