Escolar Documentos
Profissional Documentos
Cultura Documentos
Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation
Chapter 6
Operating Systems
Basic Concepts
Maximum CPU utilization obtained with multiprogramming CPUI/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait. CPU burst distribution An I/O bound program typically has many very short CPU bursts A CPU bound program typically have a few very long CPU bursts
Chapter 6
Operating Systems
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 state. 4. Terminates. Scheduling under 1 and 4 is nonpreemptive (you dont have option) A new process must be selected for execution under 1 and 4 Under 2 and 3, we can: Allow the running process to continue: nonpreemptive. Perform scheduling: preemptive. Preemptive scheduling can lead to problems: what if a process is modifying shared data when it is preempted? Solutions in Chapter 7
Operating Systems 4
Chapter 6
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 process.
Chapter 6
Operating Systems
Dispatch Latency
Conflict phase: 1. Preemption of any processes running in the kernel 2. Low-priority processes release resources needed by the high-priority processes
Chapter 6 Operating Systems 6
Scheduling Criteria
CPU utilization: % of time CPU is busy Throughput: # of processes completed per time unit Depend on process length Turnaround time: total time elapsed between process creation and termination Include: waiting to get into memory, waiting in the ready queue, executing on the CPU, and doing I/O Waiting time: time spent in the ready queue Affected by CPU scheduling algorithm Response time: time between process creation and first response (not final output) Important for interaction (for time-sharing environment)
Chapter 6 Operating Systems 7
Optimization Criteria
Want maximize CPU utilization and throughput Want minimize turnaround time, waiting time, and response time Usually, want optimize the average measure Sometimes, want to optimize MIN or MAX values E.g. minimize the MAX response time For interactive systems, want minimize variance in response time Lead to predictability
Chapter 6
Operating Systems
CPU Scheduling Algorithms 1. 2. 3. 4. 5. FCFS scheduling Shortest-Job-First (SJR) Scheduling Priority Scheduling Round Robin Scheduling Multilevel Priority
Chapter 6
Operating Systems
Waiting time for P1 = 6; P2 = 0; P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. Convoy effect short process behind long process
Chapter 6 Operating Systems 11
n+1 tn (1 - ) n .
Chapter 6 Operating Systems 15
=0.5 0=10
Chapter 6
Operating Systems
16
Chapter 6
Operating Systems
17
3. 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 (what information should be available ?) nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem Starvation low priority processes may never execute. Solution Aging as time progresses increase the priority of the process.
Chapter 6 Operating Systems 18
Chapter 6
Operating Systems
19
Minimize overhead (context swaps). Processor sharing: make time slice as minimum as possible
Selecting the suitable time quantum is a trade off.
Chapter 6 Operating Systems 20
Chapter 6
Operating Systems
21
Typically, higher average turnaround than SJF, but better response why?.
Chapter 6 Operating Systems 22
5. Multilevel Queue
Ready queue is partitioned into separate queues: foreground (interactive) background (batch) Each queue has its own scheduling algorithm based on the type of the processes that is allocated to that queue, foreground RR background FCFS 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, 20% to background in FCFS
Chapter 6 Operating Systems 23
Chapter 6
Operating Systems
26
Chapter 6
Multiple-Processor Scheduling
CPU scheduling more complex when multiple CPUs are available (but load sharing is possible) Assume homogeneous systems (i.e., the processors are identical) Use a common ready queue Two scheduling approaches: Symmetric: Each processor is self-scheduling: each processor selects a process to execute from the common ready queue Must synchronize the processors to ensure two processors do not choose the same process and processes are not lost from queue Asymmetric: Appoint one processor as scheduler for the other processors Data sharing problem solved: only one processor accesses the queue.
Chapter 6 Operating Systems 28
Real-Time Scheduling
Hard real-time systems required to complete a critical task within a guaranteed amount of time. Soft real-time computing requires that critical processes receive priority over less fortunate ones. Priority Inversion Problem: A lower priority process is blocking a higher priority process from running. Solution: Priority Inheritance protocol
Chapter 6
Operating Systems
29
Real-Time Scheduling
Hard real-time systems: required to complete a critical task within a guaranteed amount of time A process is submitted with a time requirement for completion or performing I/O Scheduler either admits the process with guarantee that the deadline will be met or rejects the request Scheduler must know how long each OS function takes Cant use secondary storage or virtual memory Use special purpose dedicated hardware
Chapter 6
Operating Systems
30
Real-Time Scheduling
Soft real-time systems: requires that critical processes always have top priority, may lead to long delays or starvation of other processes (less restrictive than hard real time) Implementation issues: 1- Must use priority scheduling, real-time processes must have highest priority, need disallow process aging 2- Dispatch latency must be small Problem: many OS do not allow context switch during a system call (or even an IO), thus the dispatching will be delayed leading to high dispatch latency Solution: allow system calls to be preemptible
Chapter 6
Operating Systems
31
Chapter 6
Operating Systems
32
Algorithm Evaluation
How do we select a CPU-scheduling algorithm for a particular system? 1. Define desired criteria (e.g., maximize CPU utilization with the constraint that max response time < 1 second) 2. Evaluate/compare algorithms Four algorithm evaluation methods 1. Deterministic modeling 2. Queuing models 3. Simulations 4. Implementation
Chapter 6 Operating Systems 33
Deterministic Modeling
Use a specific predetermined workload and determines the performance of each algorithm for that workload What we did in class Simple and fast Results only valid for specific workload
Chapter 6
Operating Systems
34
Queuing Models
The computer system is viewed as a network of servers, each sever has a queue of waiting processes. E.g., CPU with ready queue, I/O device with device queue Given arrival rates and service rates, we can compute average queue length, average waiting time, etc. (called queuing-network analysis) Requires inaccurate/unrealistic assumptions for numerical solutions E.g. assume processes are independent, arrival rate follows Poisson distribution, service time follows exponential distribution Queuing models are only an approximation of a real system
Chapter 6 Operating Systems 35
Simulations
Two ways to generate the data to drive the simulation 1. Generate workload according to certain probability distributions 2. Use trace tapes that record the sequence of actual events in the real system Gather statistics of the algorithm performance as the simulation executes Non-trivial to design, code, and debug a simulator Simulations often require many hours of CPU time
Chapter 6 Operating Systems 36
Chapter 6
Operating Systems
37
Implementation
Implement the scheduling algorithm on a real system The accurate evaluation technique. Cost is tremendous: coding algorithm, modifying kernel data structures, system must be taken down Ideally, we want flexible scheduling algorithms During OS build-time, boot time, or run time, variables used by the scheduler can be changed by system manager or by user Few operating systems allow tunable scheduling. can you think of an example of tuning ?
Chapter 6 Operating Systems 38
Chapter 6
Operating Systems
39
Solaris 2 Scheduling
Priority based, four classes of scheduling: real-time, system, time sharing, and interactive Each class includes a set of priorities Default scheduling class for a process is time sharing Time sharing: use multilevel feedback queue, the higher the priority, the smaller the time slice (inverse relation). Interactive: same as time sharing Systems: for kernel processes only Priority is fixed, no time-slicing. Thread runs until it blocks or is preempted by a higher priority thread Real-time: highest priority (guaranteed response time) In this model, when two processes have the same priority number, use RR.
Chapter 6 Operating Systems 40
Solaris 2 Scheduling
Chapter 6
Operating Systems
41
Chapter 6
Operating Systems
42
Chapter 6
Operating Systems
43
Thread Scheduling
Local Scheduling How the threads library decides which thread to put onto an available LWP Global Scheduling How the kernel decides which kernel thread to run next
Chapter 6
Operating Systems
45
Chapter 6
Operating Systems
47