Upload
nyasia-chinnock
View
221
Download
1
Tags:
Embed Size (px)
Citation preview
OPERATING SYSTEMS AND ARCHITECTURES CS-M98 PART 7 SCHEDULING
Benjamin Mora 1Swansea University
Dr. Benjamin Mora
CONTENT
Main Principles behind Scheduling.
Scheduling Algorithms.
Comparison of Several Algorithms.
2Benjamin MoraSwansea University
MAIN PRINCIPLES
3Benjamin MoraSwansea University
REMINDER: PROCESS STATES
4Benjamin MoraSwansea University
SCHEDULING Scheduling consists of determining which processes are to
be run by the processor.Mainly for multitasked environments.Mainly Pre-emptive.
The scheduler is the part of the OS managing scheduling. The scheduling algorithm is the algorithm used by the
scheduler. Process/Context Switching consists of switching between
tasks.Consume resources
5Benjamin MoraSwansea University
WHEN SCHEDULING When a process blocks (e.g. on I/O, a semaphore, or
voluntarily). When a process terminates. When a new process is created. When an interrupt occurs
e.g. blocking I/O operation now ready, so might want to activate waiting process.
End of a quantumcurrent process has had its time slot, OS will preempt it and run
another process. Note that some operating systems and some scheduling algorithms are non-preemptive, so this never happens.
6Benjamin MoraSwansea University
DECISION MODE Non-Multitask (Non-preemptive)
Processes will be run sequentially.
Co-operative (Non-preemptive)The process blocks itself when needed (termination, I/O, OS
request).
PreemptiveThe OS interrupts Processes. The process can be interrupted by the OS.When quantum time lapsed.More overhead.More interactive.
7Benjamin MoraSwansea University
DIFFERENCES BETWEEN PROCESSES Different processes: Different goals!
OS must have a good strategy.Adaptive mechanism.
CPU-bound processes.
Mainly computations, only a few I/O operations.More time can be allocated to these processes.
I/O-bound processes.
Most time waiting for events.
8Benjamin MoraSwansea University
SCHEDULING ALGORITHM TYPE Different Operating Systems, different goals! Interactive Environment:
Interact with the user. Personal computers.
Preemptive scheduling.Event programming.
Batch Environment:Send jobs to the system.
Data centers, supercomputers, etc…Global performances improved.Can be cooperative, preemptive with long delays.
9Benjamin MoraSwansea University
SUB-SCHEDULERS Long-Term Scheduler
Not Frequently Used, only on coarse-grained programs.Decides which programs to add to the pool.
Mid-Term Scheduler
For virtual memory management.
Short-Term Scheduler
Often called, makes fast decisions.Favor short tasks (real-time programs).
10Benjamin MoraSwansea University
SCHEDULING ALGORITHM TYPEReal-Time Operating Systems:
Ensuring/Meeting/Predicting deadlines.Upper bound execution time.Required efficient programming methodologies!
Planes, nuclear power plants, consoles, multimedia systems, etc…
Process environment better known from the start.
11Benjamin MoraSwansea University
SCHEDULING ALGORITHM TYPE Hard Real-Time. Deadlines must be met!
System failing otherwise Deterministic and reliable.
Though immediate detection & recovery must be implemented. Paging, Swapping & dynamic memory allocations usually not possible.
Proven/normalized/deterministic compilers. Interrupts minimized.
Planes, power plants, critical systems. Worst Case Executation Time must be known!
Soft Real-Time. Deadlines should be met! Relaxed constraints. Priority given to real-time processes. Results sometimes discarded if not on time. Multimedia systems. Consoles. Phones.
12Benjamin MoraSwansea University
SCHEDULING ALGORITHM TYPEFirm Real-Time. Intermediate between soft and
hard
Deadlines should be met. Any failure will degrade performance. “A few” misses could be accepted.
Results are invalid if obtained after deadline! The opportunity is lost
Interactive systems E.g, RealTime financial systems. High-Frequency Trading
Loss of money
13Benjamin MoraSwansea University
SCHEDULING OBJECTIVESFairness.
Make sure each process gets its fair share of the CPU, and no process suffers indefinite postponement.Priority settings possible.Balance resource usage.
Efficiency. Keep the CPU and the other parts of the system as busy
as possible.Reduced overhead.
14Benjamin MoraSwansea University
SCHEDULING OBJECTIVESBatch Systems:
Maximize throughput/jobs per hour. Turnaround time. Minimize time between submission
and termination.Maximize CPU utilization.
Interactive systems:Minimize response time.Increase productivity.
Real-Time Systems:Quite specific to the context.
15Benjamin MoraSwansea University
SCHEDULING ALGORITHMS
16Benjamin MoraSwansea University
SCHEDULING ALGORITHMSFirst come, first served.Round Robin.Priority scheduling.Shortest process next.Shortest remaining time & Highest Response Ratio
Next.Multilevel Feedback queues.Early Unix Priority Scheduling.Fair Share Scheduling.
17Benjamin MoraSwansea University
FIRST COME, FIRST SERVED FIFO list of ready processes. When a process terminates its execution, the next process
in the queue is executed. Nonpreemptive. High response time. Minimum overhead. Penalize short processes. No starvation.
18Benjamin MoraSwansea University
ROUND ROBIN (TIME SLICING) FIFO list. Widely used.
SimpleFairpreemptive.minimum overhead.no starvation.good response time for short processes
A quantum of time is defined.Must be carefully chosen. Depends on the processor type.
19Benjamin MoraSwansea University
P1
P2
P3
P4
FIFO List10 ms
10 ms
10 ms
10 ms
10 ms
10 ms
10 ms
PRIORITY SCHEDULINGAdding priorities to processes is sometimes
required.Highest priority processes are run.Several priority queues have to be handled.Round-Robin can be performed inside each queue.
May lead to starvation.The OS has to detect starvation.Priority may be decreased.
20Benjamin MoraSwansea University
SHORTEST PROCESS NEXT Select the expected shortest process.
High throughput.High overhead.Better for short processes.
Non-preemptive.
Requires estimating the amount of time required by each process.Can be estimated by the user for batch jobs.Can be done based on statistics acquired from the running
processes.
21Benjamin MoraSwansea University
RUNNING TIME PREDICTION
WithSn: Predicted evaluation of running time for the nth time the
process uses the CPU.Ti: Time used for the ith execution of the process.
To give more importance to the recent executions of the process, one can use:
22Benjamin MoraSwansea University
nn
n
inn Sn
nTn
TS11
1
11
nnn STS )1(1
SHORTEST REMAINING TIME, HIGHEST RESPONSE RATIO NEXT
Based on the same idea as Short Process Next.
Shortest Remaining Time:Preemptive version of Short Process Next.
Highest Response Ratio Next:Non-Preemptive.Minimization of the normalized turn around time.Minimize starvation.Priority =1+ (waiting_time/estimated_run_time)
23Benjamin MoraSwansea University
MULTILEVEL FEEDBACK QUEUES
24Benjamin MoraSwansea University
MULTILEVEL FEEDBACK QUEUESBased on multi-level queues.
Lowest levels have increased priorities, but also shortest quantum times.
A new process enters the lowest level queue and may preempt the current running process.
All levels but the last one (round-robin) are usually first come, first served.
25Benjamin MoraSwansea University
MULTILEVEL FEEDBACK QUEUESMain characteristics:
Preemptive.Throughput and response times OK, although not best.Possibly high overhead.May favor I/O bound processes.Possible starvation.
26Benjamin MoraSwansea University
EARLY UNIX PRIORITY SCHEDULINGEvery active process has a scheduling priority.
The CPU is given to the process having the highest priority The lowest priority value in implementation!
User process priorities change every quantum.Cannot go beyond a specific priority.Not for super-user processes.
27Benjamin MoraSwansea University
EARLY UNIX PRIORITY SCHEDULING Each process control block contains:
the CPU usage of the process. (cpu)a scheduling priority. (prio)
Rules: If a process does not use its entire time slice, the algorithm will
tend to run sooner.At every clock interupt, the CPU usage is incremented.At the end of every quantum (60 time units in example):
cpu = cpu / 2prio = cpu / 2 + BASE_LEVEL_PRIORITY;
28Benjamin MoraSwansea University
EARLY UNIX PRIORITY SCHEDULING
29Benjamin MoraSwansea University
SYSTEM VR4 AND SOLARIS
30Benjamin MoraSwansea University
FAIR SHARE SCHEDULING Fixed distribution of CPU usage among users and groups.
A weight is given to every user/group. A grp_cpu variable must be added per user/group
After every quantum, for every process:
31Benjamin MoraSwansea University
cpu = cpu / 2;grp_cpu = grp_cpu / 2;prio = cpu / 2 + weight*(grp_cpu/2)+ BASE_LEVEL_PRIORITY;
FAIR SHARE SCHEDULING : EXAMPLE
32Benjamin MoraSwansea University
=
COMPLETELY FAIR SCHEDULER Linux 2.6.23.
Not O(1) Scheduler.
Schedule classes.
Different scheduling policies:
SCHED_NORMAL, SCHED_BATCH, SCHED_IDLE.Real-time scheduler: SCHED_RR and SCHED_FIFO.
Uses a time-ordered red-black tree.
Nano-second granularity.
33Benjamin MoraSwansea University
COMPARISON OF SEVERAL ALGORITHMS
34Benjamin MoraSwansea University
ASSUMPTIONS 5 Processes arrive at time 0.
The CPU ready queue is empty at time 0.
The time needed for context switches can be ignored.
35Benjamin MoraSwansea University
ASSUMPTIONS In round robin scheduling, a process will release the CPU
voluntarily if it needs less than a quantum.
A newly arrived process is placed in the ready queue before a process whose quantum expires at the same time.
36Benjamin MoraSwansea University
COMPARISON
37Benjamin MoraSwansea University
CRITERIA / ANALYSISAverage waiting time.
Throughput.number of jobs finished in 30 ms.
Fairness/Efficiency:number of processes getting the CPU after 30 ms.
38Benjamin MoraSwansea University
COMPARISON
39Benjamin MoraSwansea University