Download presentation
1
Process Scheduling -Dr. Nick
2
Topics for discussion Motivation Types of scheduling
Short-term scheduling Various scheduling criteria Various algorithms Priority queues First-come, first-served Round-robin Shortest process first Shortest remaining time and others Queuing Model and Performance Analysis
3
Process Scheduling On most multitasking system, only one process can truly be active at a time. The system must share its time between the execution of many processes. This sharing is called scheduling.
4
The CPU-I/O Cycle We observe that processes require alternate use of processor and I/O in a repetitive fashion Each cycle consist of a CPU burst (typically of 5 ms) followed by a (usually longer) I/O burst A process terminates on a CPU burst CPU-bound processes have longer CPU bursts than I/O-bound processes
5
CPU and I/O Bound Process
CPU Bound program has very long CPU burst I/O bound program tends to have very short CPU burst.
6
Classification of Scheduling Activity
7
Basic Concepts The objective of multiprogramming is to have some process running at all times to maximize CPU utilization. Productive CPU-Process management pattern. If you wait, I will take over….. CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait CPU burst distribution
8
Alternating Sequence of CPU And I/O Bursts
9
Histogram of CPU-burst Times
10
CPU Scheduler Selects from among the processes in memory that are ready to execute, and allocates the CPU to one of them CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates Scheduling under 1 and 4 is nonpreemptive All other scheduling is preemptive
11
Dispatcher Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: switching context switching to user mode jumping to the proper location in the user program to restart that program Dispatch latency – time it takes for the dispatcher to stop one process and start another running
12
Types of Schedulers
13
Short-term Scheduling
14
Context Switch with Timer inturrupt
15
Short-term scheduling
Short-term scheduler is invoked whenever an event occurs that may lead to the interruption of the current process or that may warrant the preemption of the current process in favor of another. Clock-interrupts, IO interrupts, OS calls, signals, real-time system policies are some such events. The main objective of short-term scheduling is to allocate processor time in such a way as to optimize one or more aspects of system behavior.
16
Short-term scheduling criteria
User-oriented: Response time: is the elapsed time between the submission of a request until the response begins to appear at the output. Typical goal of such system should be maximize the number of users who would experience average or better than average response time. System-oriented: Throughput: is the rate at which processes are completed. Focus is on the efficient and effective use of processors. Utilization : % of time a processor is kept busy.
17
Scheduling Criteria (Definition vs Optimization criteria)
CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – Number of processes that complete their execution per time unit. Maximize no. of processes /hour. Turnaround time – amount of time to execute a particular Process. From the time of submission to the time of completion, minimize the time batch users must wait for output. Waiting time – amount of time a process has been waiting in the ready queue-minimize this. Response time – amount of time it takes from when a request was submitted until the first response is produced-Minimize response time for interactive users. Fairness: Make sure that each process gets a fair share of CPU.
18
Other policies Turnaround time = Finish time - Arrival time
Normalized turnaround time = Turnaround time / service time Response time = arrival time - start time Overall wait time = response time + wait times in the ready queue (ready to run, but CPU not avail) Multilevel Priority Queues
19
CPU Dispatcher Another component involved in the function of CPU-scheduling is CPU dispatcher. Switching context Switching to user mode. Jumping to the proper location in the user program to restart that program.
20
Scheduling Algorithems
Queuing First Come First Serve Scheduling (FCFS) Shortest Job First Scheduling (SJF) Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback-Queue Scheduling
21
Scheduling Algorithm Goals
22
Policy versus Mechanism
Separate what is allowed to be done with how it is done a process knows which of its children threads are important and need priority Scheduling algorithm parameterized mechanism in the kernel Parameters filled in by user processes policy set by user process
23
Alternative scheduling policies
A selection function determines which among the ready processes is next selected for execution Selection functions are based on one or more of these items: 1) w - time spent in system so far, waiting and executing. 2) e - time spent on execution so far. 3) s - total service time required by the process. 4) resources required by the process When to apply the selection function is dependent on whether a preemptive or non-preemptive scheduling is used.
24
First Come First Served (FCFS)
Selection function: the process that has been waiting the longest in the ready queue (hence, FCFS) Decision mode: nonpreemptive a process run until it blocks itself
25
First Come First Serve Scheduling (FCFS)
Process Burst time P P
26
First Come First Serve Scheduling
The average of waiting time in this policy is usually quite long Waiting time for P1=0; P2=24; P3=27 Average waiting time= ( )/3=17
27
First Come First Serve Scheduling
Suppose we change the order of arriving job P2, P3, P1
28
First Come First Serve Scheduling
Consider if we have a CPU-bound process and many I/O-bound processes There is a convoy effect as all the other processes waiting for one of the big process to get off the CPU FCFS scheduling algorithm is non-preemptive
29
FCFS drawbacks A process that does not perform any I/O will monopolize the processor Favors CPU-bound processes I/O-bound processes have to wait until CPU-bound process completes They may have to wait even when their I/O are completed (poor device utilization) we could have kept the I/O devices busy by giving a bit more priority to I/O bound processes
30
Short job first scheduling (SJF)
This algorithm associates with each process the length of the processes’ next CPU burst If there is a tie, FCFS is used In other words, this algorithm can be also regard as shortest-next-cpu-burst algorithm
31
SJF Scheduling Q&A Why SJF is optimal?
Minimum average waiting time for set of Processes Why it has minimum average time? Decrease waiting time for short term process Why it can be used for long term scheduling? As long term process can be controlled by user intervention and execution is long. Is there any way to predict the next value in SJF? Technique with approximate SJF scheduling. Usage of SJF Print schedulers…a long term process controlled by user..
32
Short job first scheduling: Pros and Cons
SJF is optimal – gives minimum average waiting time for a given set of processes. Moving a short process before a long one decreases the waiting time of the short process more than it increases waiting time of the long process. Consequently the average time decreases The SJF scheme is often used for print schedulers since it is quite inexpensive to determine the size of the file to be printed ( the file size is often used for print schedulers). The real difficulty with SJF algorithm is knowing the length of the next CPU request. It can’t be implemented at the level of short term scheduling. There is no way to know the length of the next CPU burst, Although it be predicted with approximate scheduling, however it is costly and it shows exponential behavior
33
Example Processes Burst time P1 6 P2 8 P3 7 P4 3
FCFS average waiting time: ( )/4=10.25 SJF average waiting time: ( )/4=7
34
Short job first scheduling
Two schemes: Non-preemptive – once CPU given to the process it cannot be preempted until completes its CPU burst Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF)
35
Short job first scheduling- Non-preemptive
36
Short job first scheduling- Preemptive
The Average waiting time=
37
Priority Scheduling A priority number (integer) is associated with each process The CPU is allocated to the process with the highest priority (smallest integer ≡ highest priority) Preemptive Non-preemptive SJF is a special priority scheduling where priority is the predicted next CPU burst time, so that it can decide the priority The larger the CPU burst, the lower the priority For SJF priority is the inverse of the predicted next CPU burst.
38
Priority Scheduling As an example, consider the following set of processes, assumed to have arrived at time 0, in the order P1, P2, P5, with the length of the CPU burst given in milliseconds. Priorities can be defined as Internally – time limits, memory requirements, the number of open files, and the ratio of average I/O burst. Externally-importance of the process, the dept. sponsoring the work, human controlled
39
Priority Scheduling Compute Gantt chart
Processes Burst time Priority Arrival time P P P P P Compute Gantt chart Gantt chart for both preemptive and non-preemptive, also waiting time The average waiting time=( )/5=8.2
40
Priority Scheduling: problem and solution
Problem : Starvation – low priority processes may never execute. Solution : Aging – as time progresses increase the priority of the process. In preemptive scheduling during aging, however priority of a process is gradually reduce while it is running. Eventually, the priority of the running process is no longer be the highest, and the next process will start running.
41
Round-Robin Scheduling
The Round-Robin is designed especially for time sharing systems. It is similar FCFS but add preemption concept A small unit of time, called time quantum, is defined. Note that B in fig b moves to the tail of the queue.
42
Context Switch in Round-Robin Scheduling
Each process gets a small unit of CPU time (time quantum), usually milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue.
44
Round-Robin Scheduling Problem
45
Round-Robin Scheduling
The average waiting time is for quantum with 20 milliseconds=
46
Round-Robin Scheduling
Each process gets a small unit of CPU time (time quantum), usually milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units.
47
Round-Robin Scheduling
Performance q large => FIFO q small => q must be large with respect to context switch, otherwise overhead is too high Typically, higher average turnaround than SJF, but better response
48
Round-Robin Scheduling
One process with 10 time units If the quantum is 12 time units means process finishes in 1 time quantam. However if quanta is 6 then process requires 2 time quanta, resulting in context switch. If it is one time unit, then how many context switches?
49
Effectiveness of Round Robin Scheduling
Effectiveness of round-robin depends on The number of processes, and the size of the time quantum. Large # of processes means that the time between scheduling of single process also increases. Slow response Larger time quantum means that the time between the scheduling of a single process also increases Smaller time quantum means higher processing rates but also more overhead!
50
Time Quantum for Round Robin
must be substantially larger than the time required to handle the clock interrupt and dispatching should be larger then the typical interaction (but not much more to avoid penalizing I/O bound processes)
51
Average turnaround time with time quantum for RR
Given three processes of 10 time units each and a quantum of 1 unit, the average turnaround time is 29. If the time quanta is 10, however, the average turnaround time drops to 20. That means if the processes finish their next CPU burst in fixed time quanta then average time around time improved. Context switch time ofcourse increase average time around time
52
Round Robin Scheduling-Example with process switch.
53
Round Robin Scheduling Problem-Solution
54
Multilevel Queue Ready queue is partitioned into separate queues:
foreground (interactive) background (batch) Depends on memory size, process priority, process type. Each queue has its own scheduling algorithm foreground – RR background – FCFS
55
Multilevel Queue example
Foreground P (RR interval:20) P P Background P (FCFS) P
56
Multilevel Queue Scheduling must be done between the queues
Fixed priority scheduling; (i.e., serve all from foreground then from background). Possibility of starvation. Time slice – each queue gets a certain amount of CPU time which it can schedule amongst its processes; i.e., 80% to foreground in RR
57
Multilevel Queue Partition the ready queue into several separate queues. Processes can be classified into different groups and permanently assigned to one queue.
58
Multilevel Feedback Queue
A process can move between the various queues; aging can be implemented this way Multilevel-feedback-queue scheduler defined by the following confugurable parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service
59
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. *Separate processes with different CPU burst characteristics
60
5.4 Multiple-Processor Scheduling
We concentrate on systems in which the processors are identical (homogeneous) Asymmetric multiprocessing (by one master) is simple because only one processor access the system data structures. Symmetric multiprocessing, each processor is self-scheduling. Each processor may have their own ready queue.
61
Load balancing-B) Systems
On symmetric multiprocessing systems (SMP), it is important to keep the workload balanced among all processors to fully utilized the benefits of having more than one CPU. There are two general approached to load balancing: Push Migration and Pull Migration which is implemented in parallel on L-B systems. A specific task periodically checks the load on each processor-pushes overhead processor to idle or less-busy processor. Pull migration occurs when an idle processor pulls a waiting task from a busy processor. For example, linux runs its own load balancing algorithm every 200 ms. (push migration) or whenever the run queue for a processor is empty. However, load balancing counteracts the policy with process-affinity.
62
Symmetric Multithreading
An alternative strategy for symmetric multithreading is to provide multiple logical processors (rather than physical) Each of the logical processor general purpose as well as machine-state registers. It’s called hyper-threading technology on Intel processors
63
Symmetric Multithreading
The idea behind it is to create multiple logical processors on the same physical processor (sounds like two threads) But it is not software provide the feature, but hardware Each logical processor has its own architecture state, each logical processor is responsible for its own interrupt handling.
64
Symmetric Multithreading
65
Algorithm Evaluation Analytic Evaluation: Deterministic modeling:
Analytic evaluation uses the given algorithm and the system workload to produce a formula or number that evaluates the performance of the algorithm. Deterministic modeling: This method takes a particular predetermined workload and defines the performance of each algorithm. Simple and fast Exact numbers, help compares the algorithms; trends can be analyzed and proved separately. Describing scheduling algorithms and providing examples. In the next Slide we assume that for set of algorithms we maintain time quantum=10 milliseconds.
66
Formula for Scheduling Criteria
Turnaround time = Finish time - Arrival time Normalized turnaround time = Turnaround time / service time Response time = arrival time - start time Overall wait time = response time + wait times in the ready queue (ready to run, but CPU not avail)
67
FCFS The waiting time is 0 milliseconds for process P1, 10 milliseconds fro process P2, 39 milliseconds for process P3, 42 milliseconds for process P4, and 49 milliseconds for process P5. Thus the average waiting time is ( )/5=28 milliseconds
68
Non-Preemptive SJF scheduling
The waiting time is 10 milliseconds for process P1, 32 milliseconds for process P2, 0 milliseconds for process P3, 3 milliseconds for process P4, and 20 milliseconds for process P5. Thus the average waiting time is ( )/5=13 milliseconds
69
Round Robin Algorithm (time quantum=10 milliseconds)
The waiting time is 0 milliseconds for process P1, 32 milliseconds for process P2, 20 milliseconds for process P3, 23 milliseconds for process P4, and 40 milliseconds for process P5.Thus, the average waiting time is ( )/5=23 milliseconds.
70
Evaluation The average waiting time obtained with the SJF policy is less than half that obtained with FCFS scheduling; the RR algorithms gives us an intermediate value. For the environment described, (all processes and their times available at time 0), the SJF policy will result in the minimum waiting time.
71
Windows XP Priorities
72
Linux Scheduling Two algorithms: time-sharing and real-time
Prioritized credit-based – process with most credits is scheduled next Credit subtracted when timer interrupt occurs When credit = 0, another process chosen When all processes have credit = 0, recrediting occurs Based on factors including priority and history Real-time Soft real-time Posix.1b compliant – two classes FCFS and RR Highest priority process always runs first
73
The Relationship Between Priorities and Time-slice length
74
List of Tasks Indexed According to Priorities
75
Think Time What are the main tasks of the scheduler?
What is the difference between preemptive and non-Preemptive Scheduling? What are the advantages, Disadvantages of a shorter and and a longer scheduling quantum? Why is feedback scheduling useful for interactive processes? Are these scheduling policies subject to starvation. Shortest-job First, Round Robin, First Come First server, priority, multilevel feedback queue. Find the problems of every algorithm and compare every algorithm with deterministic model.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.