advanced operating systems prof. muhammad saeed. february 11, 2014advanced operating systems2 the...
TRANSCRIPT
Advanced Operating Advanced Operating SystemsSystems
Prof. Muhammad Saeed
April 10, 2023 Advanced Operating Systems 2
The part of the operatingsystem that makes the choice of the process is called the scheduler, and the algorithm it uses is called the scheduling algorithm.
April 10, 2023 Advanced Operating Systems 3
The part of the operatingsystem that makes the choice of the process is called the scheduler, and the algorithm it uses is called the scheduling algorithm.
April 10, 2023 Advanced Operating Systems 4
The separation of mechanism and policy is a design principle in computer science. It states that mechanisms (those parts of a system implementation that control the authorization of operations and the allocation of resources) should not dictate (or overly restrict) the policies according to which decisions are made about which operations to authorize, and which resources to allocate.
April 10, 2023 Advanced Operating Systems 5
Scheduling the processor among all ready processesThe goal is to achieve:
High processor utilizationHigh throughput
number of processes completed per of unit time
Low response timetime elapsed from the submission of a request until the first response is produced
April 10, 2023 Advanced Operating Systems 6
Long-term: which process to admit?Medium-term: which process to swap in or out?Short-term: which ready process to execute next?
April 10, 2023 Advanced Operating Systems 7
April 10, 2023 Advanced Operating Systems 8
Determines which programs are admitted to the system for processingControls the degree of multiprogrammingAttempts to keep a balanced mix of processor-bound and I/O-bound processes
CPU usageSystem performance
Makes swapping decisions based on the current degree of multiprogramming
Controls which remains resident in memory and which jobs must be swapped out to reduce degree of multiprogramming
April 10, 2023 Advanced Operating Systems 9
Selects from among ready processes in memory which one is to execute next
The selected process is allocated the CPU
It is invoked on events that may lead to choose another process for execution:
Clock interruptsI/O interruptsOperating system calls and trapsSignals
April 10, 2023 Advanced Operating Systems 10
The selection function determines which ready process is selected next for executionThe decision mode specifies the instants in time the selection function is exercised
NonpreemptiveOnce a process is in the running state, it will continue until it terminates or blocks for an I/O
PreemptiveCurrently running process may be interrupted and moved to the Ready state by the OSPrevents one process from monopolizing the processor
April 10, 2023 Advanced Operating Systems 11
The dispatcher is the module that gives control of the CPU to the process selected by the short-term schedulerThe functions of the dispatcher include:
Switching contextSwitching to user modeJumping to the location in the user program to restart execution
The dispatch latency must be minimal
Context Switching: Saving and loading registers and memory maps, updating various tables and lists, flushing and reloading the memory cache, and so on.
April 10, 2023 Advanced Operating Systems 12
Processes require alternate use of processor and I/O in a repetitive fashionEach cycle consist of a CPU burst followed by an I/O burst
A process terminates on a CPU burst
CPU-bound processes have longer CPU bursts than I/O-bound processes
April 10, 2023 Advanced Operating Systems 13
User-oriented criteriaResponse Time: Elapsed time between the submission of a request and the receipt of a responseTurnaround Time: Elapsed time between the submission of a process to its completion
System-oriented criteriaProcessor utilizationThroughput: number of process completed per unit timefairness
April 10, 2023 Advanced Operating Systems 14
First-Come, First-Served SchedulingShortest-Job-First Scheduling
Also referred to as Shortest Process Next
Priority SchedulingRound-Robin SchedulingMultilevel Queue SchedulingMultilevel Feedback Queue Scheduling
April 10, 2023 Advanced Operating Systems 15
ProcessArrivalTime
ServiceTime
1
2
3
4
5
0
2
4
6
8
3
6
4
5
2
Service time = total processor time needed in one (CPU-I/O) cycle Jobs with long service time are CPU-bound jobs and are referred to as “long jobs”
April 10, 2023 Advanced Operating Systems 16
Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS)Decision mode: non-preemptive
a process runs until it blocks for an I/O
April 10, 2023 Advanced Operating Systems 17
Favors CPU-bound processesA CPU-bound process monopolizes the processorI/O-bound processes have to wait until completion of CPU-bound process
I/O-bound processes may have to wait even after their I/Os are completed (poor device utilization)
Better I/O device utilization could be achieved if I/O bound processes had higher priority
April 10, 2023 Advanced Operating Systems 18
Possibility of starvation for longer processes Lack of preemption is not suitable in a time sharing environmentSJF/SPN implicitly incorporates priorities
Shortest jobs are given preferencesCPU bound process have lower priority, but a process doing no I/O could still monopolize the CPU if it is the first to enter the system
April 10, 2023 Advanced Operating Systems 19
If the metric is turnaround time (response time), is SJF or FCFS better?For FCFS, resp_time=(3+9+13+18+20)/5 = ?Note that Rfcfs = 3+(3+6)+(3+6+4)+…. = ?For SJF, resp_time=(3+9+11+15+20)/5 = ?Note that Rfcfs = 3+(3+6)+(3+6+4)+…. = ?Which one is smaller? Is this always the case?
April 10, 2023 Advanced Operating Systems 20
Take each scheduling discipline, they both choose the same subset of jobs (first k jobs).At some point, each discipline chooses a different job (FCFS chooses k1 SJF chooses k2)Rfcfs=nR1+(n-1)R2+…+(n-k1)Rk1+….+(n-k2) Rk2+….+RnRsjf=nR1+(n-1)R2+…+(n-k2)Rk2+….+(n-k1) Rk1+….+RnWhich one is smaller? Rfcfs or Rsjf?
April 10, 2023 Advanced Operating Systems 21
Implemented by having multiple ready queues to represent each level of priorityScheduler the process of a higher priority over one of lower priorityLower-priority may suffer starvationTo alleviate starvation allow dynamic priorities
The priority of a process changes based on its age or execution history
April 10, 2023 Advanced Operating Systems 22
Clock interrupt is generated at periodic intervalsWhen an interrupt occurs, the currently running process is placed in the read queue
Next ready job is selected
Known as time slicing
Uses preemption based on a clockAn amount of time is determined that allows each process to use the processor for that length of time
April 10, 2023 Advanced Operating Systems 23
Selection function: same as FCFSDecision mode: preemptive
a process is allowed to run until the time slice period (quantum, typically from 10 to 100 ms) has expireda clock interrupt occurs and the running process is put on the ready queue
April 10, 2023 Advanced Operating Systems 24
Quantum must be substantially larger than the time required to handle the clock interrupt and dispatching Quantum should be larger then the typical interaction
but not much larger, to avoid penalizing I/O bound processes
April 10, 2023 Advanced Operating Systems 25
April 10, 2023 Advanced Operating Systems 26
Still favors CPU-bound processesAn I/O bound process uses the CPU for a time less than the time quantum before it is blocked waiting for an I/OA CPU-bound process runs for all its time slice and is put back into the ready queue
May unfairly get in front of blocked processes
April 10, 2023 Advanced Operating Systems 27
Preemptive scheduling with dynamic prioritiesN ready to execute queues with decreasing priorities:
P(RQ0) > P(RQ1) > ... > P(RQN)
Dispatcher selects a process for execution from RQi only if RQi-1 to RQ0 are emptyNew process are placed in RQ0After the first quantum, they are moved to RQ1 after the first quantum, and to RQ2 after the second quantum, … and to RQN after the Nth quantumI/O-bound processes remain in higher priority queues.
CPU-bound jobs drift downward. Hence, long jobs may starve
April 10, 2023 Advanced Operating Systems 28
Different RQs may have different quantum values
April 10, 2023 Advanced Operating Systems 29
April 10, 2023 Advanced Operating Systems 30
April 10, 2023 Advanced Operating Systems 31
Give processes lottery tickets for various system resources,such as CPU time. Whenever a scheduling decision has to be made, a lottery ticket is chosen at random, and the process holding that ticket gets the resource.When applied to CPU scheduling, the system might hold a lottery 50 times a second, with each winner getting 20 msec of CPU time as a prize. More important processes can be given extra tickets, to increase their odds of winning. If there are 100 tickets outstanding, and one process holds 20 of them, it will have a 20% chance of winning each lottery. In the long run, it will get about 20% of the CPU. In contrast to a priority scheduler, where it is very hard to state what having a priority of 40 actually means, here the rule is clear: a process holding a fraction f of the tickets will get about a fraction f of the resource in question.
April 10, 2023 Advanced Operating Systems 32
ENDEND