CS550: Scheduling in Representative Operating Systems

advertisement
Scheduling
in
Representative Operating Systems
1
Uniprocessor Scheduling
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
2
Uniprocessor Scheduling (cont.)
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
3
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
4
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
5
Scheduling Algorithms (cont.)
• Short-term scheduling criteria
– User oriented, performance related
• Turnaround time
• Response time
• Deadlines
– User oriented, other
• Predictability
– System oriented, performance related
• Throughput
• Processor utilization
– System oriented, other
• Fairness
• Enforcing priorities
• Balancing resources
• Priorities
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
6
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
7
Scheduling Algorithms (cont.)
• Scheduling policies
– First-Come-First Served (FCFS) or First-In-First-Out
(FIFO)
– Round Robin (RR)
– Shortest Process Next (SPN)
– Shortest Remaining Time (SRT)
– Highest Response Ratio Next (SRRN)
– Feedback
– Fair-Share Scheduling
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
8
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
9
Traditional UNIX Scheduling
• SVR3 and 4.3 BSD UNIX: designed primarily for time-sharing
interactive environment
• Scheduling algorithm objectives
– Provide good response time for interactive users
– Ensure that low-priority background jobs do not starve
• Scheduling algorithm implementation
–
–
–
–
–
–
Multilevel feedback using round robin within each of the priority queues
1 second preemption
Priority based on process type and execution history
Priorities are recomputed once per second
Base priority divides all processes into fixed bands of priority levels
Bands used to optimize access to block devices (e.g., disk) and to allow the
OS to respond quickly to system calls
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
10
Traditional UNIX Scheduling (cont.)
• Priority calculation
CPU j (i) =
CPU j ( i – 1)
2
P j (i) = Base j +
CPU j ( i – 1)
2
Where
CPU j (i) =
Pj(i) =
Base j
=
Measure of processor utilization by process j through interval i
Priority of process j at beginning of interval i ;
lower values equal higher priorities
Base priority of process j
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
11
Traditional UNIX Scheduling (cont.)
• Bands in decreasing order of priority
–
–
–
–
–
Swapper
Block I/O device control
File manipulation
Character I/O device control
User processes
• Goals
– Provide the most efficient use of I/O devices
– Within the user process band, use the execution history to penalize
processor-bound processes at the expense of I/O bound processes
• Example of process scheduling
– Processes A, B, and C are created at the same time with base priorities of
60
– Clock interrupts the system 60 times a second and increments counter for
running process
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
12
Traditional UNIX Scheduling (Example
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
13
Multiprocessor and Real-Time Scheduling
• Multiprocessor Thread Scheduling
– Load sharing
• Global queue of ready threads is maintained and each processor, when
idle, selects a thread from the queue
– Gang scheduling
• Set of related threads is scheduled to run on a set of processors at the
same time, on a one-to-one basis
– Dedicated processor assignment
• Each program is assigned a number of processors equal to the number
of threads in the program, for the duration of program execution
– Dynamic scheduling
• Number of threads in a process can be altered during course of
execution
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
14
Thread Scheduling
– Load Sharing
• Load is distributed evenly across the processors
• No centralized scheduler required
• The global queue can be organized and accessed using any
scheduling policy
• One of the most widely used schemes in multiprocessing
– Gang Scheduling
• Simultaneous scheduling of threads that make up a single
process
• Useful for applications where performance severely
degrades when any part of the application is not running
• Threads often need to synchronize with each other
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
15
Thread Scheduling
• Dedicated Processor Assignment
– When application is scheduled, each of its threads is assigned to a
processor that remains dedicated to that thread through completion
– Some processors may be idle
– No multiprogramming of processors
– Avoidance of process switching can improve speed of application
• Dynamic Scheduling
– The number of threads in the process are changed dynamically
– Both the OS and the application are involved in scheduling: the OS assigns
processors to jobs, the application decides which thread subset to run
– For applications that can take advantage of dynamic scheduling, this
approach is superior to both gang scheduling and dedicated processor
assignment
– The overhead may negate the apparent performance advantage
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
16
Real-Time Systems
• Correctness of the system depends not only on the logical result
of the computation but also on the time at which the results are
produced
• Tasks or processes attempt to control or react to events that take
place in the outside world
• The events being controlled occur in “real time”; the real-time
task must be able to keep up with these events
• Examples
–
–
–
–
–
–
Control of laboratory experiments
Process control plants
Robotics
Air traffic control
Telecommunications
Military command and control systems
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
17
Characteristics of Real-Time Operating Systems
• Deterministic
– Operations are performed at fixed, predetermined times or within
predetermined time intervals
– The OS must acknowledge interrupts in time and must have sufficient
capacity to handle all requests within required time
• Responsiveness
– How long, after acknowledgment, it takes the operating system to service
the interrupt
• User control
– User specifies task priority and may also specify the use of paging or
process swapping, and the processes resident in main memory,
• Reliability
– Loss or degradation of performance may have catastrophic consequences
– Attempt either to correct the problem or minimize its effects while
continuing to run
– Make sure that the most critical, high priority tasks execute
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
18
Features of Real-Time Operating Systems
• Fast process or thread switch
• Preemptive scheduling base on priority
• Minimization of intervals during which interrupts
are disabled
• Ability to respond to external interrupts quickly
• Use of special sequential files that can
accumulate data at a fast rate
• Special alarms and timeouts
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
19
Scheduling of a Real-Time Process
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
20
Scheduling of a Real-Time Process
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
21
Scheduling of a Real-Time Process
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
22
Scheduling of a Real-Time Process
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
23
Real-Time Scheduling
• Classes of algorithms
– Static table-driven scheduling
• Applicable to tasks that are periodic
• Scheduler develops a schedule that meet the requirements of all
periodic tasks
– Static priority-driven preemptive scheduling
• Uses priority-driven preemptive scheduling mechanism
• Priority assignment is related to the time constraints associated with
each task
– Dynamic planning-based scheduling
• After the arrival of a new task, an attempt is made to revise the
schedule such that the needs of the new task and the existing tasks are
met
– Dynamic best effort scheduling
• On arrival, task assigned priority based on its characteristics
• Deadline scheduling (e.g., earliest-deadline scheduling) is used
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
24
Deadline Scheduling
• Real-time applications are concerned with completing (or
starting) tasks on time
• Scheduling tasks with the earliest deadline minimized the fraction
of tasks that miss their deadlines
• Recent proposals for real-time task scheduling are based on
additional information about each task
–
–
–
–
–
–
–
Ready time
Starting deadline
Completion deadline
Processing time
Resource requirements
Priority
Subtask scheduler
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
25
Linux Scheduling
• Enhances the traditional UNIX scheduling by adding two new
scheduling classes for real-time processing
• Scheduling classes
– SCHED_FIFO: First-in-first-out real-time threads
– SCHED_RR: Round-robin real-time threads
– SCHED_OTHER: Other, non-real-time threads
• Multiple priorities can be used within each class; priorities for
real-time threads higher than for non-real-time threads
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
26
Linux Scheduling (cont.)
• Scheduling for the FIFO threads is done according with the
following rules
– An executing FIFO thread can be interrupted only when
• Another FIFO thread of higher priority becomes ready
• The executing FIFO thread becomes blocked, waiting for an event
• The executing FIFO thread voluntarily gives up the processor (sched_yield)
– When an executing FIFO thread is interrupted, it is placed in a queue
associated with its priority
– When a FIFO thread becomes ready and it has a higher priority than the
currently running thread, the running thread is pre-empted and the thread
with the higher priority is executed. If several threads have the same,
higher priority, the one that has been waiting the longest is assigned the
processor
• Scheduling for the Round-Robin threads is similar, except for a
time quota associated with each thread
– At the end of the time quota, the thread is suspended and a thread of equal
or higher priority is assigned the processor
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
27
Linux Scheduling (cont.)
• Example: The distinction between FIFO and RR scheduling
– Assumptions (a)
• A program has four threads with three relative priorities
• All waiting threads are ready to execute when the current thread waits or terminates
• No higher-priority thread is awakened while a thread is executing
– Scheduling of FIFO threads (b)
•
•
•
•
Thread D executes until it waits or terminates
Thread B executes (it has been waiting longer than C) until waits or terminates
Thread C executes
Thread A executes
– Scheduling of Round-Robin threads ( c )
• Thread D executes until it waits or terminates
• Threads B and C execute time-sliced
• Thread A executes
– Scheduling of non-real-time threads
• Execute only if no real-time threads are ready using the traditional UNIX scheduling
algorithm
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
28
Linux Scheduling: FIFO vs. RR
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
29
UNIX SVR4 Scheduling
• Complete redesign of the traditional UNIX scheduling algorithm
• Goal: give preference in the following order
– Highest preference to real-time processes
– Next-highest to kernel-mode processes
– Lowest preference to other user-mode processes (time-shared processes)
• Major enhancements
– The addition of a preemptable static priority scheduler
– The introduction of 160 priority levels divided into three priority classes
– The introduction of preemption points in the kernel (points where the kernel can
safely interrupt and schedule a new process)
• Priority classes and levels
– Real-time (159-100)
• Guaranteed execution before kernel or time-sharing processes
• Preemption points can be used to preempt kernel or user processes
– Kernel (99-60)
• Guaranteed execution before time-sharing processes
– Time-shared (59-0)
• Lowest-priority processes: user applications other than real-time
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
30
UNIX SVR4 Scheduling (cont.)
• Implementation
– A dispatch queue is associated with each priority level; processes at that level are
executed round-robin (dispq)
– A bit-map vector, dqactmap, has one bit for each priority level; a 1 indicates a
nonempty queue at that level
– When a process leaves the Running state (block, time-slice expiration, or
preemption), the dispatcher
• Checks the dqactmap, and
• Dispatches a process from the highest-priority non-empty queue
– When a defined preemption point is reached, the kernel
• Checks the flag kprunrun
• If set (at least one real-time process is in the Ready state), preempts the current process if
it is of lower priority than the highest-priority real-time ready process
– A real-time process has a fixed priority and a fixed quantum
– A time-sharing process has a variable priority and a variable time quantum
• The priority is reduced every time the process uses up the time quantum and is raised
when the process blocks on an event or resource
• The time quantum changes with the priority (100ms for priority 0, 10ms for 59)
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
31
UNIX SVR4 Scheduling: Dispatch Queues
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
32
Windows 2000 Scheduling
• Goal: optimize response for
– Single user in highly interactive environment, or
– Server
• Implementation
– Priority-driven preemptive scheduler with round-robin within a priority level
• When a thread becomes ready and has higher priority than the currently running thread,
the lower priority thread is preempted
– Dynamic priority variation as function of current thread activity for some levels
• Process and thread priorities organized into two bands (classes), each with 16
levels
– Real-time priorities:
• Real-time tasks or time-dependent functions (e.g., communications)
• Have precedence over other threads
– Variable priorities
• Non-real-time tasks and functions
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
33
Windows 2000 Scheduling (cont.)
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
34
Windows 2000 Scheduling (cont.)
• Real-time priority class
– All threads have a fixed priority that never changes
– All active threads at a given priority level are in a round-robin queue
• Variable priority class
– A thread’s priority begins at some initial assigned value and then may
change, up or down, during the thread’s lifetime
– There is a FIFO queue at each priority level, but a thread may migrate to
other queues within the variable priority class
– The initial priority of a thread is determined by
• Process base priority: attribute of the process object, from 0 to 15
• Thread base priority: equal to that of its process or within two levels
above or below that of the process
– Dynamic priority
• Thread starts with base priority and then fluctuates within given
boundaries, never falling under base priority or exceeding 15
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
35
Windows 2000 Scheduling (cont.)
• Variable priority class: dynamic priorities
– If thread is interrupted because it has used its current time quantum,
executive lowers its priority: processor-bound threads move toward lower
priorities
– If thread is interrupted to wait on an I/O event, executive raises its priority:
I/O-bound threads move toward higher priorities
• Priority raised more for interactive waits (e.g., wait on keyboard or display)
• Priority raised less for other I/O (e.g., disk I/O)
– Example
• A process object has a base priority of 4
• Each thread associated with this process can have an initial priority between 2
and 6 and dynamic priorities between 2 and 15
• The thread’s priority will change based on its execution characteristics
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
36
Windows 2000 Scheduling: Example of Dynamic Priorities
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
37
Windows 2000 Scheduling (cont.)
• Single processor vs. multiprocessor scheduling
– Single processor
• Highest-priority thread is always active unless it is waiting on an event
• If there is more than one thread at the highest priority, the processor is
shared, round-robin
– Multiprocessor system with N processors
• The (N – 1) highest-priority threads are always active, running on the
(N – 1) processors
• All other lower-priority threads share the remaining processor
• Example: three processors, two highest-priority threads run on two
processors, all other threads run on the remaining processor
• Exception for threads with processor affinity attribute
CS-550 (M.Soneru): Scheduling in Representative Operating Systems: [Sta’01]
38
Download