SCHEDULING ALGORITHM

SCHEDULING ALGORITHM - SIT222 Operating Systems Session 03...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: SIT222 Operating Systems Session 03. Process scheduling Outline • Introduction to scheduling • Objectives of scheduling • Scheduling algorithms SIT222 Session 3 2 Introduction to scheduling • Recall that a computer can run multiple processes at the same time by switching between them • The context switch is the operating system function that switches from one processes to another – One CPU/core can run one process at a time – The CPU/core is then shared between all processes to give the appearance they are all running simultaneously • This is done many times per second SIT222 Session 3 3 Introduction to scheduling • Previously we raised three problems to be solved for performing a context switch: – How to get to kernel mode? • The timer sends an interrupt periodically – How often to switch the CPU? • Determined by setting the time between interrupts sent by the timer – What process to switch to? • This represents the problem of scheduling SIT222 Session 3 4 Introduction to scheduling • Recall that every process in the system can be in one of three states: • The operating system maintains a list of ready processes – The scheduler selects which of these to run SIT222 Session 3 5 Introduction to scheduling • Historically, computers were batch systems – Jobs would run from start to completion without any interaction with the user – When one job completed, the next job would be loaded • Nowadays, computers are multiprogrammed – Many processes competing for the CPU/cores at the same time – CPU is switched between these processes SIT222 Session 3 6 Introduction to scheduling • We can also identify the behavior of processes as either compute-bound or I/O bound – A compute bound process spends most of its time performing computations • Examples: simulations, audio/video encoding, and so on – An I/O bound process spends most of its time waiting for input or output • Examples: word processor, Unix shell, and so on SIT222 Session 3 7 Introduction to scheduling • It is important to consider the difference between compute-bound and I/O-bound processes – I/O bound processes may be interacting with the user, who expects a fast response – I/O bound processes keep the peripheral devices of the computer working as much as possible, e.g., disk SIT222 Session 3 8 Introduction to scheduling • We have already identified that the scheduler runs whenever a timer interrupt occurs • There are also other times the scheduler may run: – When a process is created • Continue running the parent or the child? – When a process exits • The CPU has been vacated, get it working again – When a process requests I/O • Process is blocked until a response is received – When an I/O interrupt is received • I/O request completed, switch to the I/O bound process to allow it to queue its next request SIT222 Session 3 9 Introduction to scheduling • We can identify two types of scheduling – Preemptive scheduling • When the CPU is forcibly taken away from a process (on a timer interrupt) – Non-preemptive scheduling • When the process “gives up” the CPU by blocking for I/O, exiting, etc. SIT222 Session 3 10 Objectives of scheduling • Objectives of scheduling algorithms include: – Fairness • Similar jobs should get similar service (time on the CPU) – Policy enforcement • Some jobs may have unusual requirements, e.g., a safety control system should get the CPU as soon as it’s ready to run – Balance • Keep as much of the system busy as possible, e.g., allow I/O bound jobs to run to keep peripherals working in parallel with the CPU SIT222 Session 3 11 Objectives of scheduling • Objectives of scheduling algorithms include: – Throughput • The number of jobs completed per unit of time, e.g., per hour – Turnaround time • Average time it takes for a job to be completed – CPU utilization • Keep the CPU busy/working at all times, an idle CPU is wasted time – Remember a context switch is wasted time! SIT222 Session 3 12 Objectives of scheduling • Objectives of scheduling algorithms include: – Response time • The time it takes for a program to respond to input, e.g., typing in a command to the shell in Linux – Proportionality • System matches user expectations, e.g., simple jobs are quick, complex jobs take time – Meeting deadlines • Real-time systems work to deadlines, e.g., shutting down a runaway nuclear reaction SIT222 Session 3 13 Objectives of scheduling • Objectives of scheduling algorithms include: – Predictability • Missing the occasional deadline doesn’t matter, but if the processes don’t get the CPU with foreseeable/expectable regularity they cannot function properly, e.g., video/audio streaming SIT222 Session 3 14 Objectives of scheduling • No CPU scheduling algorithm can achieve all these objectives because they conflict, e.g,. – CPU utilization versus response time/balance • Favor CPU-bound processes and long timeslice for CPU utilization • Favor I/O bound processes and a short timeslice for response time/balance – Throughput vs turnaround time • Favoring short jobs increases throughput (more jobs completed) but turnaround time for long jobs will suffer badly SIT222 Session 3 15 Objectives of scheduling • Thus different algorithms are used for different different systems – Batch system • Non-interactive, e.g., calculate interest (banks) – Interactive system • Multi-user interactive systems, e.g., Linux – Real-time system • Meeting deadlines is most important, e.g., monitoring a nuclear reactor SIT222 Session 3 16 Objectives of scheduling • Thus different algorithms are used for different different systems – Batch system objectives • Throughput, turnarond time, CPU utilisation – Interactive system objectives • Response time, proportionality – Real-time system objectives • Meeting deadlines, predictability – All systems • Fairness, policy enforcement, balance SIT222 Session 3 17 Scheduling algorithms • When examining scheduling algorithms, we will consider the following process arrivals and duration: Process Arrival Duration P1 0 3 P2 2 6 P3 4 4 P4 6 5 P5 8 2 SIT222 Session 3 18 Scheduling algorithms • Assumptions: – Processes arrive and are immediately added to the queue – Context switches take no time SIT222 Session 3 19 Scheduling algorithms • Batch systems – First Come First Served (FCFS) – Processes run in the order they arrive – Processes run until completion, no preemption SIT222 Session 3 20 First Come First Served (Cont.) • Batch systems – First Come First Served (FCFS) – Advantages • Simple • Low overhead (scheduling does not take away time from processes) – Disadvantages • Favours CPU bound jobs over I/O bound jobs • Not useful for interactive systems • Disadvantages short jobs Operating System Concepts Scheduling algorithms • Batch systems – Shortest Job First (SJF) – Shortest available job is always selected – Processes run until completion, no preemption SIT222 Session 3 22 Scheduling algorithms • Batch systems – Shortest Job First (SJF) – Advantages • The smaller the execution time the better the turnaround time of the job – Disadvantages • User must estimate the execution time – how? • If enough short jobs are arriving, starvation is possible for longer jobs (may never run) SIT222 Session 3 23 Scheduling algorithms • Batch systems – Shortest Remaining Time Next (SRTN) – Job with shortest remaining time always selected – Preemption can occur when new jobs arrive SIT222 Session 3 24 Scheduling algorithms • Batch systems – Shortest Job First (SJF) – Advantages • The smaller the execution time the better the turnaround time of the job • Can prove it’s optimal for the shortest average turnaround time – Disadvantages • User must estimate the execution time – how? • If enough short jobs are arriving, starvation is possible for longer jobs (may never run) SIT222 Session 3 25 Scheduling algorithms • Interactive systems – Round Robin (RR) – Timeslice = 4 – Processes are added to a queue upon arrival – First process is dequeued and run for a timeslice – If process still ready after timeslice, it is re-enqueued SIT222 Session 3 26 Scheduling algorithms • Interactive systems – Round Robin (RR) – Timeslice = 1 – Processes are added to a queue upon arrival – First process is dequeued and run for a timeslice – If process still ready after timeslice, it is re-enqueued SIT222 Session 3 27 Scheduling algorithms • Interactive systems – Round Robin (RR) – Advantages • Usable for interactive systems • Simple – Disadvantages • If the timeslice is too long, performance approaches FIFO behaviour • If the timeslice is too short, the system thrashes because the context switch overhead dominates • Very difficult to select a perfect timeslice SIT222 Session 3 28 Scheduling algorithms • Interactive scheduling – Priority scheduling – Importantly, not all processes are created equal • Some processes are more important than others – We have already seen some priorities: • Round robin treats all processes identically, i.e., equal priority • SJF uses the predicted duration of the process for priority – The shorter the process, the higher the priority Operating System Concepts Scheduling algorithms • Interactive scheduling – Priority scheduling – Starvation can be a problem with priorities however • For SJF, if enough small/high priority processes arrive, large/low priority processes may never get the CPU • Solution is aging – process priority increases over time Operating System Concepts Scheduling algorithms • Interactive scheduling – Priority scheduling – Priorities can be either static or dynamic – Static priorities • Never change throughout the lifetime of a process • Easy to implement • Low overhead – Dynamic priorities • Priorities adapt to the observed execution of the process • Calculating priorities adds overhead • The hope is the overhead is less significant than the increased effectiveness of scheduling Operating System Concepts Scheduling algorithms • Interactive scheduling – Multiple Queues – There is also benefit to recognizing different types of processes • I/O bound processes work best when they are scheduled regularly • CPU bound processes work best when they have a longer timeslice on the CPU • These objectives conflict however – Scheduling I/O bound processes regularly requires small timeslice – Scheduling CPU bound processes for longer means I/O bound processes will get the CPU less often Operating System Concepts Scheduling algorithms • Interactive scheduling – Multiple Queues – One solution is to use multiple queues, one for each priority • Highest priority contains I/O bound processes – Scheduled regularly for short timeslices • Lowest priority contains CPU bound processes – Scheduled less-regularly for long timeslices SIT222 Session 3 33 Scheduling algorithms • Interactive scheduling – Multiple Queues – This can be extended to a more general multilevel queue… • Top priority queue gets one time quantum, i.e., timeslice = x • Next priority gets two time quantum, i.e., timeslice = 2x • Next priority gets four time quantum, i.e., timeslice = 4x • … continues doubling time quantum each time SIT222 Session 3 34 Scheduling algorithms • Interactive scheduling – Multiple Queues – We then need to get the I/O bound processes in the top queue and the CPU bound processes in the lower queues – Solution: • If a process uses up all its timeslice, it is CPU bound so move it down one queue • If a process does not use up all its timeslice, it has blocked for I/O, so move it up one queue – There are many other similar solutions SIT222 Session 3 35 Scheduling algorithms • Interactive scheduling – Multiple Queues – There is also the question of how to schedule processes from the different queues, for which there are many examples: • Schedule any processes in higher priority queues until there are no more processes to schedule • Age the processes in the lower priority queues (increase their priority) so they float up over time – Can also use different algorithms for different priority levels, e.g., RR for high priority, FCFS/SJF for lower priority, etc. SIT222 Session 3 36 Summary • Introduction to scheduling • Objectives of scheduling • Scheduling algorithms SIT222 Session 3 37 ...
View Full Document

This note was uploaded on 09/25/2010 for the course SIT 281 taught by Professor Vickymak during the Two '09 term at Deakin.

Ask a homework question - tutors are online