0% found this document useful (0 votes)
49 views

Chapter 6: CPU Scheduling Preemptive vs. Non-Preemptive Scheduling

The document discusses different CPU scheduling algorithms including non-preemptive and preemptive scheduling. It defines key performance criteria for scheduling like CPU utilization, throughput, turnaround time, waiting time and response time. Specific algorithms covered include First Come First Served (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round Robin (RR). Examples are provided to illustrate how each algorithm works using Gantt charts and calculations of waiting times. Preemptive vs non-preemptive nature of the algorithms is also discussed.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Chapter 6: CPU Scheduling Preemptive vs. Non-Preemptive Scheduling

The document discusses different CPU scheduling algorithms including non-preemptive and preemptive scheduling. It defines key performance criteria for scheduling like CPU utilization, throughput, turnaround time, waiting time and response time. Specific algorithms covered include First Come First Served (FCFS), Shortest Job First (SJF), Priority Scheduling, and Round Robin (RR). Examples are provided to illustrate how each algorithm works using Gantt charts and calculations of waiting times. Preemptive vs non-preemptive nature of the algorithms is also discussed.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Preemptive vs.

Non-preemptive
Chapter 6: CPU Scheduling
Scheduling
• Always want to have CPU working • Non-preemptive scheduling
• Usually many processes in ready queue – A new process is selected to run either
– Ready to run on CPU • when a process terminates or
– Consider a single CPU here • when an explicit system request causes a wait state
• Need strategies (e.g., I/O or wait for child)
– Selecting next process to run • Preemptive scheduling
– For allocating CPU time – New process selected to run also when
– What happens after a process does a system call? • An interrupt occurs
• Short-term scheduling • When new processes become ready
– Must not take much CPU time

Performance Criteria Scheduling Algorithms


• CPU utilization • First-come, First-Served (FCFS)
– Percentage of time that CPU is busy (and not idle), over – Complete the jobs in order of arrival
some period of time
• Throughput • Shortest Job First (SJF)
– Complete the job with shortest next CPU requirement
– Number of jobs completed per unit time (e.g., burst)
• Turnaround time – Provably optimal w.r.t. average waiting time
– Time interval from submission of a process until • Priority
completion of the process
– Processes have a priority number
• Waiting time – Allocate CPU to process with highest priority
– Sum of the time periods spent in the ready queue
• Round-Robin (RR)
• Response time – Each process gets a small unit of time on CPU (time
– Time from submission until first output/input quantum or time slice)
– May approximate by time from submission until first – For now, assume a FIFO queue of processes
access to CPU

FCFS: First-Come First-Served Solution: Gantt Chart Method


P1 P2 P3 P4 P5
• Implement with a FIFO ready queue
20 32 40 56 60
• Major disadvantage can be long wait times
• Example • Waiting times:
– Draw Gantt chart • P1: 0
– Compute the average wait time for processes • P2: 20
with the following burst times and queue order: • P3: 32
• P1: 20, P2: 12, P3: 8, P4: 16, P5: 4 • P4: 40
• P5: 56
• Average wait time: 29.6

1
SJF: Shortest Job First SJF Solution
P5 P3 P2 P4 P1
• The job with the shortest next CPU burst
time is selected 4 12 24 40 60

• Example (from before): • Waiting times:


– CPU job burst times: • P1: 40
• P1: 20, P2: 12, P3: 8, P4: 16, P5: 4 • P2: 12
– Draw Gantt chart and compute the average • P3: 4
waiting time given SJF CPU scheduling • P4: 24
• P5: 0
• Average wait time: 16

SJF Example Estimate


• Provably shortest average wait time
• However, requires future knowledge • Say, α = 0.5
• May have an estimate, to predict next CPU burst • τ0 = 10
– E.g., base on last CPU burst and a number summarizing
history of CPU bursts • CPU burst, t = 6
τn+1 = α * t + (1 - α) * τn • What is estimate of next CPU burst?
– Where t is the last CPU burst value, α is a constant τ1 = 0.5 * 6 + 0.5 * 10 = 8
indicating how much to base estimate on last CPU
burst, and τn is the last estimate

Priority Scheduling Which Scheduling Algorithms


• Have to decide on a numbering scheme Can be Preemptive?
– 0 can be highest or lowest
• FCFS as priority: all have equal priorities • FCFS (First-come, First-Served)
• SJF as priority: priority is reciprocal of predicted – Non-preemptive
CPU burst • SJF (Shortest Job First)
• Priorities can be – Can be either
– Internal – Choice when a new job arrives
• according to O/S factors (e.g., memory requirements) – Can preempt or not
– External: e.g., User importance • Priority
– Static: fixed for the duration of the process – Can be either
– Dynamic – Choice when a processes priority changes or when a
• Changing during processing higher priority process arrives
• E.g., as a function of amount of CPU usage, or length of time
waiting (a solution to indefinite blocking or starvation)

2
RR (Round Robin) Scheduling Solution
completes
completes completes completes completes

• Give each process a unit of time (time slice,


quantum) of execution on CPU P1 P2 P3 P4 P5 P1 P2 P3 P4 P1 P2 P4 P1 P4 P1

• Then move to next process 4 8 12 16 20 24 28 32 36 40 44 48 52 56 60

• Waiting times:
• Continue until all processes completed
• P1: 16 + 12 + 8 + 4 = 40
• Example
• P2: 4 + 16 + 12 = 32
– CPU job burst times & order in queue
• P1: 20, P2: 12, P3: 8, P4: 16, P5: 4 • P3: 8 + 16 = 24
– Draw Gantt chart, and compute average wait time • P4: 12 + 16 + 8 = 36
• P5: 16
• Average wait time: 29.6

Calculate Other Measurements


• Response time
Response Time Calculations
– Estimate by time from job submission to time to first
CPU dispatch Job FCFS SJF RR
– Assume all jobs submitted at same time, in order given
• Turnaround time P1 0 40 0
– Time interval from submission of a process until
completion of the process P2 20 12 4
FCFS P1 P2 P3 P4 P5 P3 32 4 8
20 32 40 56 60
P4 40 24 12
SJF P5 P3 P2 P4 P1
P5 56 0 16
4 12 24 40 60
RR P1 P2 P3 P4 P5 P1 P2 P3 P4 P1 P2 P4 P1 P4 P1 Average 29.6 16 8
4 8 12 16 20 24 28 32 36 40 44 48 52 56 60

Turnaround Time Calculations Performance Characterstics of


Job FCFS SJF RR
Scheduling Algorithms
P1 20 60 60 • Different algorithms will have different
performance characteristics
P2 32 24 44
• RR (Round Robin)
P3 40 12 32 – Good average response time
• Important for interactive or timesharing systems
P4 56 40 48
• SJF
P5 60 4 20 – Best average waiting time
– Some overhead w.r.t. estimates of CPU burst length
Average 41.6 28 40.8

Assume processes submitted at same time

3
Context Switching Issues Example
• These calculations have not taken context switch • Calculate average wait time for RR (round
duration into account
robin) scheduling, for
– In general, the context switch will take time
– Just like the CPU burst of a process takes time – Processes: P1: 24, P2: 4, P3: 4
– Response time, wait time etc. will be affected by – Assume this arrival order
context switch time
– Quantum = 4; context switch time = 1
• RR (Round Robin) & quantum duration
– The smaller the time quantum, the better the average
response time, but the more system overhead
– Want the quantum large compared to context switch
time

Solution: Average Wait Time


Multi-level Ready Queues
With Context Switch Time
• Multiple ready queues
P1 P2 P3 P1 P1 P1 P1 P1 – For different types of processes (e.g., system, vs. user
4 5 9 10 14 15 19 20 24 25 29 30 34 35 39 processes)
– For different priority processes (e.g., Mach)
• P1: 0 + 11 + 4 = 15
• P2: 5 • Each queue can
– Have a different scheduling algorithm
• P3:10
– Receive a different amount of CPU time
• Average: 10 – Have movement of processes to another queue
(feedback);
• e.g., if a process uses too much CPU time, put in a lower
(This is a case for dynamically varying the priority queue
time quantum, as in Mach.) • If a process is getting too little CPU time, put it in a higher
priority queue

Synchronization Issues
Multiprocessor Scheduling
• Symmetric multiprocessing
• When a computer has more than one processor, • Involves synchronization of access to global ready
need a method of dispatching processes queue
• Types of ready queues – E.g., only one processor must execute a job at one time
– Local: dispatch to a specific processor
• Processors: CPU1, CPU2, CPU3, …
– Global: dispatch to any processor (“load sharing”)
• When a processor (e.g., CPU1) accesses the ready
• Processor/process relationship queue
– Run on only a specific processor (e.g., if it must use a – All other processors (CPU2, CPU3, …) must wait, and
device on that processor’s private bus) be denied access to the ready queue
– Run on any processor – The accessing processor (e.g., CPU1) will remove a
• Symmetric: Each processor does own scheduling process from the ready, and dispatch it on itself
• Master/slave: – Then that processor will make the ready queue
– Master processor dispatches processes to slaves available for use by the other CPU’s (CPU2, CPU3, …)

4
Pre-emptive Scheduling &
Operating System Design
• With pre-emptive CPU scheduling, a new process
can run when interrupt occurs
• What if thread A was in the middle of updating
data structures, and was put back in ready queue
– Either on disk or in shared memory
• If thread B also accesses same data structures
– May access data structures in an inconsistent state
• Need mechanisms for cooperative data access
– Both in Kernel
• Kernel, in general, needs to handle interrupts
• Don’t want to loose interrupts
• Real-time & multi-processor issues
• May need preemption in the kernel itself
– And by multiple processes/threads

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy