the functions of operating systems scheduling(multi-programming)

34
The Functions of The Functions of Operating Systems Operating Systems Scheduling Scheduling (multi-programming) (multi-programming)

Upload: jessie-stanley

Post on 21-Jan-2016

226 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: The Functions of Operating Systems Scheduling(multi-programming)

The Functions of The Functions of Operating Systems Operating Systems

SchedulingScheduling(multi-programming)(multi-programming)

Page 2: The Functions of Operating Systems Scheduling(multi-programming)

Learning ObjectivesLearning Objectives

Define and explain the purpose of scheduling, job queues, priorities and how they are used to manage job throughput.

Page 3: The Functions of Operating Systems Scheduling(multi-programming)

Multi-Programming

Predecessor to multi-tasking / multi-user, without “Round-Robin”.

See “Multi-Tasking & Multi-User / Access Presentation” from AS Computing.

Several different programs are loaded in the computer’s memory, and the first one begins to run. When the first program reaches an instruction waiting for a peripheral (e.g. a printer), the context of the program is stored away, and the second program in memory is given a chance to run. The process continues until all programs finish running.

Page 4: The Functions of Operating Systems Scheduling(multi-programming)

Appropriate order of tasksAppropriate order of tasks

One of the tasks of the OS is to arrange One of the tasks of the OS is to arrange the jobs that need to be done into an the jobs that need to be done into an appropriate order.appropriate order.

Page 5: The Functions of Operating Systems Scheduling(multi-programming)

The objectives of scheduling are to:The objectives of scheduling are to:

Maximise the use of the whole of the computer Maximise the use of the whole of the computer system.system.Be fair to all users.Be fair to all users.Provide a reasonable response time to all users, Provide a reasonable response time to all users, whether they are on-line users or a batch whether they are on-line users or a batch processing user.processing user.Prevent the system failing if it is becoming Prevent the system failing if it is becoming overloaded.overloaded.Make sure that the system is consistent by Make sure that the system is consistent by always giving similar response times to similar always giving similar response times to similar activities from day to day.activities from day to day.

Page 6: The Functions of Operating Systems Scheduling(multi-programming)

IInput / nput / OOutput (I/O) Vs Processor utput (I/O) Vs Processor Bound JobsBound Jobs

Input / Output (I/O) Bound Jobs:Input / Output (I/O) Bound Jobs: Jobs that require relatively little processing but do need to use Jobs that require relatively little processing but do need to use

the peripheral devices substantially.the peripheral devices substantially.E.g. Printing wage slips for the employees of a large company.E.g. Printing wage slips for the employees of a large company.

Processor Bound Jobs:Processor Bound Jobs: Jobs that require a large amount of processor time and very little Jobs that require a large amount of processor time and very little

use of the various peripheral devices. use of the various peripheral devices. E.g. Analysing the annual, world-wide sales of the company which E.g. Analysing the annual, world-wide sales of the company which has a turnover of many millions of pounds. has a turnover of many millions of pounds.

As this is decided before running it is a As this is decided before running it is a non pre-emptivenon pre-emptive policypolicy..

See slide See slide 16 later. later.

Page 7: The Functions of Operating Systems Scheduling(multi-programming)

Priority?Priority?If a processor bound job has priority over a I/O If a processor bound job has priority over a I/O bound job for use of the processor, it could be a bound job for use of the processor, it could be a long time before the I/O job is executed.long time before the I/O job is executed. E.g. The pay slips can be printed.E.g. The pay slips can be printed.

Page 8: The Functions of Operating Systems Scheduling(multi-programming)

Priority?Priority?

If a I/O bound job has priority over a processor If a I/O bound job has priority over a processor bound job for use of the processor, I/O bound bound job for use of the processor, I/O bound job can still run in a reasonable time and much job can still run in a reasonable time and much better throughput is achieved. better throughput is achieved.

Page 9: The Functions of Operating Systems Scheduling(multi-programming)

The three states of a job/process:The three states of a job/process:

1.1. Ready/RunnableReady/Runnable to start. to start.

2.2. RunningRunning on the system. on the system.

3.3. BlockedBlocked because it is waiting for a peripheral because it is waiting for a peripheral

Page 10: The Functions of Operating Systems Scheduling(multi-programming)

Note:Note:

Jobs / Processes are synonyms (the same).Jobs / Processes are synonyms (the same).A job can only enter the A job can only enter the runningrunning state from the state from the readyready state. state. The The ready/runnableready/runnable and and blockedblocked states are states are queues that may hold several jobs. queues that may hold several jobs. On a standard single processor computer only On a standard single processor computer only oneone job can be in the job can be in the runningrunning state. state. All jobs entering the system normally enter via All jobs entering the system normally enter via the the ready/runnableready/runnable state and (normally) only state and (normally) only leave the system from the leave the system from the runningrunning state. state.

Page 11: The Functions of Operating Systems Scheduling(multi-programming)

HHigh igh LLevel evel SScheduler (cheduler (HLSHLS) / Long Term ) / Long Term Scheduler / Admissions SchedulerScheduler / Admissions Scheduler

Deals with the Deals with the Ready/Runnable stateReady/Runnable state by deciding by deciding which process/job should be loaded next in the which process/job should be loaded next in the ready queue held in the main memory.ready queue held in the main memory.Makes sure that the system is not over loaded as it Makes sure that the system is not over loaded as it will only consider processes/jobs if space in main will only consider processes/jobs if space in main memory is or becomes available.memory is or becomes available.When deciding on which process to load next it When deciding on which process to load next it considers the following attributes or priorities:considers the following attributes or priorities: Estimated run time.Estimated run time. Time to deadline.Time to deadline. Estimated memory requirements.Estimated memory requirements. Resources required.Resources required. User priority.User priority.

Page 12: The Functions of Operating Systems Scheduling(multi-programming)

LLow ow LLevel evel SScheduler (LLS) / cheduler (LLS) / Short Term SchedulerShort Term Scheduler

Deals with Deals with Running stateRunning state by moving jobs by moving jobs between the ready and running states or between the ready and running states or removing them from the system once they removing them from the system once they are completed.are completed.

Decides the order in which jobs are to be Decides the order in which jobs are to be placed in the running state.placed in the running state.

Page 13: The Functions of Operating Systems Scheduling(multi-programming)

MMedium edium LLevel evel SScheduler (MLS) / cheduler (MLS) / Medium Term Scheduler Medium Term Scheduler

Deals with the Deals with the Blocked stateBlocked state by swapping by swapping jobs between the ready state in the main jobs between the ready state in the main memory and the backing store.memory and the backing store.

Page 14: The Functions of Operating Systems Scheduling(multi-programming)

Differences between high, low & medium level scheduling

Night club analogy: The bouncer is high level scheduling.

He determines who gets into the club, i.e., which tasks or requests are accepted by the system.

The hostess is low level scheduling. She seats each person based on priority and space.If a VIP (i.e., high priority task) enters the club (i.e., computer system), scheduling places that VIP to the front of the line, and everyone that is deemed a lower priority must wait until the VIP is seated and served.

Medium level scheduling.If someone gets into the club, but it is full, they may be asked to wait in another room until a table opens up.

http://smallbusiness.chron.com/low-level-high-level-scheduling-26299.html

Page 15: The Functions of Operating Systems Scheduling(multi-programming)

Scheduling SummaryScheduling Summary

http://www.theteacher.info/websites/ocr/WebPages/F453_Advanced/Scheduling/Scheduling.html

Page 16: The Functions of Operating Systems Scheduling(multi-programming)

Pre-Emptive & Non-Pre-EmptivePre-Emptive & Non-Pre-EmptivePre-Emptive Scheme / Policy:Pre-Emptive Scheme / Policy:

Allows the LLS to remove a job when not complete from the running Allows the LLS to remove a job when not complete from the running state so that another job can be placed in the running state.state so that another job can be placed in the running state.

So has control over what is in running state and means the interrupt So has control over what is in running state and means the interrupt queue is checked after each cycle.queue is checked after each cycle.

Non-Pre-Emptive Policy:Non-Pre-Emptive Policy: Each job runs until it no longer requires the processor. Each job runs until it no longer requires the processor. This may be because it has finished or because it needs an Input / This may be because it has finished or because it needs an Input /

Output device (see I/O Bound Jobs later).Output device (see I/O Bound Jobs later). Simply follows the queue set before a job is started and is only re-Simply follows the queue set before a job is started and is only re-

arranged (if at all – see First Come First Served later) after a job is arranged (if at all – see First Come First Served later) after a job is complete.complete.

Policy – a method of arranging the queue or stopping a job.Policy – a method of arranging the queue or stopping a job.Scheme – when the Round Robin policy Scheme – when the Round Robin policy (pre-emptive)(pre-emptive) is is combined with another.combined with another.

See later.See later.

Page 17: The Functions of Operating Systems Scheduling(multi-programming)

Importance of job / Type of job:Importance of job / Type of job:

Safety critical jobs will be given very high priority, on-Safety critical jobs will be given very high priority, on-line and real time applications will also have to have line and real time applications will also have to have high priorities.high priorities.

E.g. E.g. 1.1. A computer monitoring the temperature and pressure in a A computer monitoring the temperature and pressure in a

chemical process whilst analysing results of readings taken over a chemical process whilst analysing results of readings taken over a period of time must give the highest priority to the control program. period of time must give the highest priority to the control program. If the temperature or pressure goes out of a pre-defined range, the If the temperature or pressure goes out of a pre-defined range, the

control program must take over immediately. control program must take over immediately. 2.2. A bank's computer is printing bank statements over night and A bank's computer is printing bank statements over night and

someone wishes to use a cash point, the cash point job must take someone wishes to use a cash point, the cash point job must take priority.priority.

Also remember I/O bound jobs Also remember I/O bound jobs will also get priority as will also get priority as stated earlier.stated earlier.

Depending on if the queue is checked after each cycle or not Depending on if the queue is checked after each cycle or not this can be a this can be a Pre-EmptivePre-Emptive policypolicy or a or a NonNon Pre-Emptive Pre-Emptive policypolicy..

Page 18: The Functions of Operating Systems Scheduling(multi-programming)

FFirst irst CCome ome FFirst irst SServed (FCFS) erved (FCFS) / / FIFO / LILOFIFO / LILO

First job to enter ready queue is first to First job to enter ready queue is first to enter running state.enter running state.

Favours long jobsFavours long jobs..

There is no point in rechecking the queue There is no point in rechecking the queue during a job as the queue is FCFS so this is a during a job as the queue is FCFS so this is a non pre-emptivenon pre-emptive policypolicy..

Page 19: The Functions of Operating Systems Scheduling(multi-programming)

SShortest hortest JJob ob FFirst (SJF) / irst (SJF) / Shortest Estimated Run TimeShortest Estimated Run Time

Sorts jobs in ready queue in ascending order of Sorts jobs in ready queue in ascending order of time expected to be needed by each job. time expected to be needed by each job.

New jobs are added in such a way so as to New jobs are added in such a way so as to preserve this order.preserve this order.

As the queue is arranged before a job is started and As the queue is arranged before a job is started and only checked again once a job is finished it is a only checked again once a job is finished it is a Non-Non-Pre-EmptivePre-Emptive policypolicy..

If this was not the case and job is recalculated after each If this was not the case and job is recalculated after each cycle then it would become Shortest Remaining Time (see cycle then it would become Shortest Remaining Time (see later).later).

Make sure you describe policies when you list them, do not just name them; particularly this policy, “Shortest job first”, which should be described as “Estimated completion time” as otherwise examiners will complain that there is no indication of what is “shortest”.

Page 20: The Functions of Operating Systems Scheduling(multi-programming)

RRound ound RRobin (RR)obin (RR)Each job is given a set amount of processor/quantum time.Each job is given a set amount of processor/quantum time.At the end of the time available for a job, it is interrupted.At the end of the time available for a job, it is interrupted.The operating system inspects the queue of jobs still to be The operating system inspects the queue of jobs still to be processed.processed.

If it is not empty allocates the next amount of processor time to the If it is not empty allocates the next amount of processor time to the job first in the queue.job first in the queue.

The previous job goes to the end of the queue.The previous job goes to the end of the queue.

If a job is completed before the maximum time is up it leaves If a job is completed before the maximum time is up it leaves the system.the system.

This policy has to be used in conjunction with another policy as it does not This policy has to be used in conjunction with another policy as it does not deal with the initial arrangement of the queue. deal with the initial arrangement of the queue.

However, as it interrupts jobs whether they are finished or not, it forms a However, as it interrupts jobs whether they are finished or not, it forms a Pre-Emptive schemePre-Emptive scheme performed when combined with another policy. performed when combined with another policy.

Page 21: The Functions of Operating Systems Scheduling(multi-programming)

SShortest hortest RRemaining emaining TTime (SRT)ime (SRT)

The ready queue is sorted on the amount of The ready queue is sorted on the amount of expected time still required by a job. expected time still required by a job. FavoursFavours short jobs even more than SJF. short jobs even more than SJF. There is a danger of long jobs being prevented There is a danger of long jobs being prevented from running.from running.

To be meaningful it must be re-calculated meaning To be meaningful it must be re-calculated meaning that jobs must be interrupted without being complete that jobs must be interrupted without being complete so is a so is a pre-emptive policypre-emptive policy..

This would be done either after each cycle or This would be done either after each cycle or processor/quantum time if combined with RR processor/quantum time if combined with RR (so forming a (so forming a scheme)scheme)..

Note if SRT were not recalculated it would be affectively SJF.Note if SRT were not recalculated it would be affectively SJF.

Page 22: The Functions of Operating Systems Scheduling(multi-programming)

MMulti-level ulti-level FFeedback eedback QQueues ueues (MFQ)(MFQ)

Several queues of different priorities with Several queues of different priorities with jobs migrating downwards.jobs migrating downwards.

Multiple FCFS Multiple FCFS / FIFO / LILO/ FIFO / LILO policy schedule policy schedule queues are used and the operation is as queues are used and the operation is as follows:follows:

Page 23: The Functions of Operating Systems Scheduling(multi-programming)

Time up

Time up

Jobs circulate in round robin fashion until Jobs circulate in round robin fashion until they complete and leave the system.they complete and leave the system.

A new job is positioned at the end of the A new job is positioned at the end of the top-level FIFO queue.top-level FIFO queue.

Time up

Page 24: The Functions of Operating Systems Scheduling(multi-programming)

Multi-Level Feedback QueuesMulti-Level Feedback Queues1.1. A new job is positioned at the end of the top-level FCFS queue. A new job is positioned at the end of the top-level FCFS queue. 2.2. At some stage the job reaches the head of the queue and is At some stage the job reaches the head of the queue and is

assigned to the CPU. assigned to the CPU. 3.3. If the job is completed it leaves the system. If the job is completed it leaves the system. 4.4. If the job uses all the quantum time, it is pre-empted and If the job uses all the quantum time, it is pre-empted and

positioned at the end of the next lower level queue.positioned at the end of the next lower level queue. A job is given just one chance to complete at a given queue level A job is given just one chance to complete at a given queue level

before it is forced down to a lower level queue.before it is forced down to a lower level queue.5.5. If the job is an I/O job and is blocked, it leaves the queuing If the job is an I/O job and is blocked, it leaves the queuing

network, and when the process is unblocked it is 'promoted' one network, and when the process is unblocked it is 'promoted' one level, and placed at the end of the next-highest queue. level, and placed at the end of the next-highest queue.

This allows I/O bound processes to be favoured by the scheduler and This allows I/O bound processes to be favoured by the scheduler and allows processes to 'escape' the base level queue.allows processes to 'escape' the base level queue.

6.6. This will continue until the process completes or it reaches the This will continue until the process completes or it reaches the base level queue where jobs circulate in round robin fashion until base level queue where jobs circulate in round robin fashion until they complete and leave the system.they complete and leave the system.

Page 25: The Functions of Operating Systems Scheduling(multi-programming)

Multi-Level Feedback Queues Multi-Level Feedback Queues

1.1. Give preference to short jobs. Give preference to short jobs. 2.2. Give preference to I/O bound processes. Give preference to I/O bound processes. 3.3. Quickly establish the nature of a process and Quickly establish the nature of a process and

schedule the process accordingly. schedule the process accordingly.

As uses RR and FCFS it is a As uses RR and FCFS it is a Pre-Emptive Pre-Emptive SchemeScheme (see earlier)(see earlier)..

Page 26: The Functions of Operating Systems Scheduling(multi-programming)

NotePre-emptive policies can only be performed by the LLS as only the LLS can remove jobs from the running state (the HLS only places jobs in the ready state). Non Pre-emptive methods can be performed by both the HLS and the LLS (as both the HLS and LLS can place jobs in the ready state, the difference being that the HLS does this from outside the system – secondary storage - and the LLS from the running state).To avoid problems when answering exam questions make sure you describe policies when you list them; do not just name them. If you do not then you may not be given the marks.

Particularly the policy “Shortest job first”, which should be described as “Estimated completion time” as there must be some indication of what is “shortest” and could be confused with “Shortest remaining time” which is pre-emptive and can only be performed by the LLS.

Also “Round-Robin” is not considered to be a method of allocating priority, it is only a scheduling policy.

Page 27: The Functions of Operating Systems Scheduling(multi-programming)

Summary ListSummary ListNon Pre-emptive which can be performed by both the HLS and the LLSNon Pre-emptive which can be performed by both the HLS and the LLS::

First Come First (FCFS)First Come First (FCFS)Time to deadline.Time to deadline.Amount of peripheral time / resources required.Amount of peripheral time / resources required.

Compares I/O jobs and asks “How much of a I/O job are you?”.Compares I/O jobs and asks “How much of a I/O job are you?”.Estimated memory requirements.Estimated memory requirements.Necessary response time / Time to deadline.Necessary response time / Time to deadline.

Compares real-time / on-line jobs and asks “How much of a real-time / on-line jobs are you?” or Compares real-time / on-line jobs and asks “How much of a real-time / on-line jobs are you?” or “OK, you are a real-time / on-line job but how quickly do I need to respond to you?”“OK, you are a real-time / on-line job but how quickly do I need to respond to you?”

User PriorityUser PriorityShortest Job First (SJF) – Estimated run time.Shortest Job First (SJF) – Estimated run time.Importance / Type of job.Importance / Type of job.Amount of time already waited.Amount of time already waited.

Pre-emptive policies which can be performed by only the LLS:Pre-emptive policies which can be performed by only the LLS:Round Robin (RR).Round Robin (RR).

Not considered to be a “method of allocating priority”.Not considered to be a “method of allocating priority”.Shortest Remaining Time (SRT).Shortest Remaining Time (SRT).Amount of processor time already given.Amount of processor time already given.Multi-Level Feedback (MLF).Multi-Level Feedback (MLF).Amount of processor time already given.Amount of processor time already given.

Page 28: The Functions of Operating Systems Scheduling(multi-programming)

PlenaryPlenary

Describe the objectives of scheduling in Describe the objectives of scheduling in a multi-user operating system.a multi-user operating system.

Page 29: The Functions of Operating Systems Scheduling(multi-programming)

The objectives of scheduling are to:The objectives of scheduling are to:

Maximise the use of the whole of the computer Maximise the use of the whole of the computer system.system.Be fair to all users.Be fair to all users.Provide a reasonable response time to all users, Provide a reasonable response time to all users, whether they are on-line users or a batch whether they are on-line users or a batch processing user.processing user.Prevent the system failing if it is becoming Prevent the system failing if it is becoming overloaded.overloaded.Make sure that the system is consistent by Make sure that the system is consistent by always giving similar response times to similar always giving similar response times to similar activities from day to day.activities from day to day.

Page 30: The Functions of Operating Systems Scheduling(multi-programming)

PlenaryPlenary

Describe some common scheduling Describe some common scheduling policies.policies.

Page 31: The Functions of Operating Systems Scheduling(multi-programming)

Common Scheduling PoliciesCommon Scheduling PoliciesFFirst irst CCome ome FFirst irst SServed (FCFS)erved (FCFS) First job to enter ready queue is first to enter running state.First job to enter ready queue is first to enter running state. Favours long jobs.Favours long jobs.

SShortest hortest JJob ob FFirst (SJF)irst (SJF) Sorts jobs in ready queue in ascending order of time expected to Sorts jobs in ready queue in ascending order of time expected to

be needed by each job. be needed by each job. New jobs are added in such a way so as to preserve this order.New jobs are added in such a way so as to preserve this order.

RRound ound RRobin (RR)obin (RR) Gives each job a maximum length of processor time (called a Gives each job a maximum length of processor time (called a

time slice) after which the job is put at the back of the ready time slice) after which the job is put at the back of the ready queue and the job at the front of the queue is given use of the queue and the job at the front of the queue is given use of the processor. processor.

If a job is completed before the maximum time is up it leaves the If a job is completed before the maximum time is up it leaves the system.system.

Page 32: The Functions of Operating Systems Scheduling(multi-programming)

Common Scheduling PoliciesCommon Scheduling Policies

SShortest hortest RRemaining emaining TTime (SRT)ime (SRT) The ready queue is sorted on the amount of expected The ready queue is sorted on the amount of expected

time still required by a job. time still required by a job. Favours short jobs even more than SJF. Favours short jobs even more than SJF. There is a danger of long jobs being prevented from There is a danger of long jobs being prevented from

running.running.

MMulti-level ulti-level FFeedback eedback QQueues (MFQ)ueues (MFQ) Several queues of different priorities with jobs Several queues of different priorities with jobs

migrating downwards.migrating downwards.

Page 33: The Functions of Operating Systems Scheduling(multi-programming)

PlenaryPlenary

State methods by which the priority of a State methods by which the priority of a job may be determined.job may be determined.

Page 34: The Functions of Operating Systems Scheduling(multi-programming)

List of all methods of allocating List of all methods of allocating priorities:priorities:

1.1. First Come First (First Come First (FCFSFCFS))2.2. Amount of time already waited.Amount of time already waited.3.3. Shortest Job First (Shortest Job First (SJFSJF))4.4. Importance / Type of jobImportance / Type of job

Safety critical jobs given higher priority.Safety critical jobs given higher priority.I/O bound jobs given higher priority than Processor bound jobs.I/O bound jobs given higher priority than Processor bound jobs.Amount of peripheral time.Amount of peripheral time.On-line and real time jobs given higher priority. On-line and real time jobs given higher priority. Necessary response time.Necessary response time.

5.5. Round Robin (Round Robin (RRRR))6.6. Shortest Remaining Time (Shortest Remaining Time (SRTSRT))7.7. Amount of processor time already given.Amount of processor time already given.8.8. Multi-Level Feedback (Multi-Level Feedback (MLFMLF))