Documente Academic
Documente Profesional
Documente Cultură
Past:
What an OS is, why we have them, what they do.
Process Scheduling Base hardware and support for operating systems
Process Management
Present:
Process Scheduling
Dickinson College
Future:
Computer Science 354 Concurrent programming
Memory management
Spring 2006 Storage management
Protection and Security
I/O request
Waiting or wait
Waiting
1
Job Scheduling Criterion Medium-term Scheduling
The medium-term scheduler swaps
The job scheduler determines the degree partially executed processes in and out to
of multiprogramming in the system. dynamically adjust the degree of
multiprogramming or to alter the process
The job scheduler attempts to maintain a mix.
New Swapped Out
balance of CPU Bound processes and I/O Jobs
Bound processes in the system. Job
Scheduler
Exit
Job Pool CPU Scheduler CPU
Waiting
2
Speeding up Context Switches CPU Scheduling
Context switching takes time. In designing the CPU scheduler there are
two major design questions that must be
Some techniques that have been used to answered:
speedup context switching include: Under what circumstances will the scheduler
Partial context switches be invoked?
Kernel register set Non-preemptive vs. Preemptive scheduling
Multiple register sets When the scheduler is invoked, what criterion
Machine language instruction will it use to select, from the ready queue, the
Threads next process to run?
Scheduling Algorithms
3
Random OS Quote Scheduling Metrics
The two main design principles of the There are a number of metrics that are
NeXT machine appear to be revenge and commonly used to evaluate the
spite. performance of a scheduling algorithm:
CPU Utilization
Don Lancaster Throughput
Turnaround Time
Wait Time
Waiting Time
Response Time
4
Scheduling Algorithms
Basic Strategies:
First-Come-First-Served (FCFS)
CPU Scheduling Shortest Job Next (SJN)
Algorithms Priority
Round Robin (RR)
Combined Strategies:
Multi-level Queues
Multi-level Feedback Queues
Comparing Scheduling
Modeling Processes
Algorithms
There are a variety of techniques for In order to use deterministic modeling or
evaluating and comparing the simulation it is necessary to model of how
performance of different scheduling processes behave.
algorithms: Typically processes alternate between bursts
Deterministic Modeling of CPU operations and blocking I/O requests.
Simulation Process 1: Process 2:
Implementation CPU 10 CPU 100
I/O Disk1 200 I/O Disk1 100
Theoretical approaches (e.g. Queuing CPU 20 CPU 100
models) I/O Disk1 150
CPU 10
5
SJN Example Shortest Next CPU Burst Next
Arrival CPU
Order Burst
0 350 Gantt Chart: The duration of past CPU bursts can be used as
1 125 a predictor of the duration of the next CPU burst.
0 75 200 450 800 1275
2 475 p4 p1 p3 p0 p2 One approach uses an exponential average:
3 250
4 75
Wait =
(0 + 75 + 200 + 450 + 800) tu
= 305 tu
job
τ n +1 = α ⋅ t n + (1− α )τ n
5 jobs
(75 + 200 + 450 + 800 + 1275) tu tu tn = actual length of nth (previous) CPU burst.
Turnaround = = 560 job
5 jobs τn = predicted length of nth CPU burst.
τn+1 = predicted length of next CPU burst.
SJN guarantees minimum average wait time. α = history scaling factor
RR Scheduling
RR Scheduling (w/ 50tu Time Slice)
(w/ 10 tu scheduling overhead)
Arrival CPU
Order Burst Gantt Chart: Gantt Chart:
0 350 0 120 240 360 480 540 575 635 670 790
0 100 200 300 400 475 550 650
1 125 p0 p1 p2 p3 p4 p0 p1 p2 p3 p4 p0 p1 p2 p3 p0 p1 p2 p3 p4 p0 p1 p2 p3 p4 p0 p1 p2 p3
2 475
3 250 650 750 850 950 1050 1150 1250 1275 790 910 1030 1150 1270 1390 1510 1535
p0 p2 p3 p0 p2 p3 p0 p2 p0 p2 p2 p2 p2 p0 p2 p3 p0 p2 p3 p0 p2 p0 p2 p2 p2 p2
4 75
Waiting p 0 = (0 + 200 + 175 + 125 + 100 + 100 + 50) tu = 750 tu Throughput, turnaround, wait, waiting and response time
calculations must now also include the overhead.
Waiting p 0 + ...+ Waiting p 4
Response =
total visits to ready queue
6
Multi-level Queues Multi-level Feedback Queues
The ready queue is divided into multiple levels. Similar to multi-level queues:
The queue for each level has a different priority. Each new process is assigned a priority.
Any job in higher priority queue will run before any job in The OS adjusts the priority of each process as it runs.
lower priority queue.
Thus, processes move among the different queues as they
Each queue may use its own internal scheduling run.
algorithm.
Processes are assigned to a specific queue. Priority 90-100
CPU Scheduler
Interrupt
CPU Scheduler or yield
System Interrupt Priority 75-89
Exit
New
or yield enqueuer dispatcher CPU
Interactive Exit processes Priority 50-74
New enqueuer dispatcher CPU
processes Batch Priority 0-49
Random OS Quote
"The Internet? We are not interested in it”
Bill Gates, 1993 Examples of Real OS
CPU Scheduling
"Sometimes we do get taken by surprise.
For example, when the Internet came
Algorithms
along, we had it as a fifth or sixth priority.”
Bill Gates, 1998
7
Linux OTHER Recrediting Solaris
If there are no threads ready to run Solaris uses preemptive scheduling with a
recrediting occurs: multi-level queue with four levels.
During recrediting, every thread in the system is The levels in order of decreasing priority are:
assigned credits using the following formula: Real time: Provides guaranteed bound on
pi response time.
pi = +K
2 System: Kernel threads
Threads that were blocked because they had 0 Interactive: User threads that are running in a
credits now windowing environment.
return to the ready queue with K credits. Time Sharing: Non-interactive user threads.
8
Scheduling Simulations
Scheduling simulations account for several
important factors that are frequently
Project #2 ignored by deterministic modeling:
CPU Scheduling Simulation Scheduling overhead
I/O Operations
Process Profiles
CPU Bound vs. I/O Bound
9
Process Description Files Provided Sample Processes
# Process name: must be unique among all
# processes for any given simulation.
PROCESS5 process1.dat: process2.dat: process3.dat:
# Process arrival time:
PROCESS1 PROCESS2 PROCESS3
15
0 50 10
# Process profile. This must begin with
# START and end with EXIT. Also every process START START START
# must start and end with a CPU burst. That is, CPU 20 CPU 10 CPU 15
# the first line after START and the last line EXIT EXIT EXIT
# before EXIT must be CPU bursts. In between
# the lines may be: # CPU <time>
# IO <device> <time>
START
CPU 25
IO DISK1 100
CPU 15
IO CDROM 50
CPU 25
EXIT
10