itfn 2601 introduction to operating systems
DESCRIPTION
ITFN 2601 Introduction to Operating Systems. Lecture 4 Scheduling. Agenda. Scheduling Batch Interactive Real-Time Threads. Scheduling: When. New Process is Created Parent Process Child Process Process Exits When a process blocks I/O Interrupt occurs Clock Interrupts Non-preemptive - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/1.jpg)
ITFN 2601Introduction to Operating
Systems
Lecture 4Scheduling
![Page 2: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/2.jpg)
Agenda
SchedulingBatchInteractiveReal-TimeThreads
![Page 3: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/3.jpg)
Scheduling: When
New Process is CreatedParent ProcessChild Process
Process ExitsWhen a process blocksI/O Interrupt occurs
Clock InterruptsNon-preemptivePreemptive
![Page 4: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/4.jpg)
Objectives of a Good Scheduling Policy
FairnessEfficiencyLow response time (important for
interactive jobs)Low turnaround time (important for
batch jobs)High throughput
![Page 5: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/5.jpg)
Scheduling
ThroughputThe amount of useful work accomplished per unit time. This depends, of course, on what constitutes “useful work.” One common measure of throughput is jobs/minute (or second, or hour, depending on the kind of job)
UtilizationFor each device, the utilization of a device is the fraction of time the device is busy. A good scheduling algorithm keeps all the devices (CPUs, disk drives, etc.) busy most of the time.
![Page 6: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/6.jpg)
Scheduling Turnaround
The length of time between when the job arrives in the system and when it finally finishes
Response TimeThe length of time between when a job arrives in the system and when it starts to produce output. For interactive jobs, response time might be more important than turnaround.
Wait TimeThe amount of time the job is ready (runnable but not running). This is a better measure of scheduling quality than turnaround since the scheduler has no control of the mount of time the process spends computing or blocked waiting for I/O.
![Page 7: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/7.jpg)
Preemption
Needs a clock interrupt (or equivalent)Needed to guarantee fairnessFound in all modern general purpose
operating systemsWithout preemption, the system
implements “run to completion (or yield)”
![Page 8: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/8.jpg)
Scheduling Algorithms(Batch)
FIFO (First In First Out)FairestLow throughputHigh Turnaround
Shortest FirstHigh ThroughputLow TurnaroundUnfair for Large Jobs
![Page 9: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/9.jpg)
Scheduling Algorithms(Batch, cont)
Shortest RemainingHigh Turnaround on Long JobsUnfair for Large Jobs
Multi-Scheduling (CPU or Memory Limited)HIGH Turnaround (disk swaps)Throughput highly variable, probably lowFairness highly variable
![Page 10: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/10.jpg)
First-Come First-Served
The simplest possible scheduling discipline is called First-come, first-served (FCFS). The ready list is a simple queue (first-in/first-out). The scheduler simply runs the first job on the queue until it blocks, then it runs the new first job, and so on. When a job becomes ready it is simply added to the end of the queue.
![Page 11: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/11.jpg)
FCFS
Main advantage of FCFS is that it is easy to write and understand
No starvationIf one process gets into an infinite loop, it
will run forever and shut out all the othersFCFS tends to excessively favor long
bursts. CPU-bound processes
![Page 12: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/12.jpg)
Shortest Job First (SJF)
Whenever the CPU has to choose a burst to run, it chooses the shortest one
Non-preemptive policyPreemptive version of the SJN, called
shortest remaining time firstStarvation is possible
![Page 13: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/13.jpg)
Scheduling Algorithms(Interactive)
Round RobinFairest overallResponse time variable but finite
Priority SchedulingFair
“More Fair” for users with higher prioritiesResponse time inverse to priority
![Page 14: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/14.jpg)
Round-Robin
Round-robin (RR). RR keeps all the processes in a queue and runs the first one, like FCFS. After a length of time q (called quantum), if the current burst hasn’t completed, it is moved to the tail of the queue and the next process is started
![Page 15: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/15.jpg)
Round RobinAn important preemptive policyEssentially the preemptive version of FCFSThe key parameter is the quantum size qWhen a process is put into the running state, a timer
is set to qIf the timer goes off and the process is still running,
the OS preempts the process.The process is moved to the ready stateThe next job in the queue is selected to run
![Page 16: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/16.jpg)
Round Robin
Quantum can’t be too largeQuantum can’t be too smallWhat quantum should we choose
TradeoffSmall q makes system more responsiveLarge q makes system more efficient since
there’s less switching
![Page 17: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/17.jpg)
Round Robin, Example
![Page 18: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/18.jpg)
Priority Scheduling
Always run the highest priority processPreemptive or non-preemptivePriorities can be assigned externally to
processes based on their importanceAssigned (and changed) dynamically
![Page 19: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/19.jpg)
Other Interactive Scheduling
Multiple QueuesShortest Process NextGuaranteed SchedulingLottery SchedulingFair-Share Scheduling
![Page 20: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/20.jpg)
Scheduling Algorithms(Interactive, cont)
Multi-QuantizedResponse time proportionate to quantaMore bookkeeping
Shortest Process NextEstimation of process lengthUnfair for large jobsFast response for small jobs
![Page 21: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/21.jpg)
Scheduling Algorithms(Interactive, cont)
Guaranteed SchedulingLottery Scheduling
Alotted time proportional to Job Size/Importance
SharingFair by user, not necessarily fair by jobResponses become disproportionate
![Page 22: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/22.jpg)
Scheduling Algorithms(Real-Time)
Small JobsHigh PriorityPeriodic/AperiodicSchedulable?
Iff the sum of the ratios CPU Time to Period time is less than one
Sum(CPU/Period) <= 1Static/Dynamic?
![Page 23: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/23.jpg)
Scheduler Mechanism
Some processes are intrinsically more important at some times than othersTime-dependent responseHigh-priority request
How can a process raise it’s scheduling priority?
![Page 24: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/24.jpg)
Thread Scheduling
User-level threadsProcess has a Thread SchedulerSame concept as Process SchedulerConflicts with Process Scheduling
Kernel Level ThreadsKernel has Thread and Process SchedulerTwo Quanta’s
Thread QuantaProcess Quanta
![Page 25: ITFN 2601 Introduction to Operating Systems](https://reader036.vdocuments.net/reader036/viewer/2022070503/568156e3550346895dc48b10/html5/thumbnails/25.jpg)
Summary
Scheduler responsible for many goals
Scheduling algorithms complex
Know your math!