Professional Documents
Culture Documents
Fred Kuhns
Washington
Time-Sharing (TS)
Multilevel feedback queues
Platform Issues
Interrupt latency Clock resolution Cost of a context switch
saving processor state and loading new instruction and data cache misses/flushes memory map cache (TLB) FPU state
Batch
Real-time
Some RT Characteristics
Determinism - one measure: delay between interrupt assertion and executing the ISR Responsiveness - time to service interrupt User Control Reliability Fail-soft operation
Clock Interrupts
How system keeps track of time implemented using a hardware clock interrupt interrupt at periodic intervals (clock tick) typically 10msec, see tick frequency defined by HZ in param.h High priority, second to power-failure interrupt (NMI).
Interrupt Latency
time to recognize interrupt and execute first instruction of ISR - Determinism
hardware, for example will CPU finish current instruction. kernel time to dispatch interrupt to correct ISR
Callout queue
Queue of functions to be processed at a particular tick system context, base interrupt priority (sw int) Example: for real-time systems insertion time is important Typical to optimize lookup time not insertion time
time-to-fire, absolute time, timing wheel (fixed size circular array)
packet retransmission, system management functions, device monitoring and polling
10
Alarms
BSD: alarm(), setitimer() SVR4: alarm(), hrtsys() Real-time - actual elapsed time
sends SIGALRM
11
BSD Scheduler
Policy - Multilevel Feedback queues Policy Goal - good response time for interactive tasks while guaranteeing batch job progress Priority based, dynamically adjusted Preemptive time-slicing (time quantum)
12
13
PROC structure
p_priority (kernel pri) p_usrpri (user pri) p_estcpu p_slptime
...
14
Calculation of Priority
Proc structure:
p_estcpu - estimate of cpu utilization p_nice - user-settable (-20 to 19, default = 0)
priority (p_usrpri) recalculated every 4 clock ticks p_estcpu incremented each clock tick process is running every second CPU usage is decayed
sleeping processes are ignored
15
BSD Formulas
Priority calculation (PUSER = 50)
16
17
18
19
kernel changes the current process pointers and loads new state.
20
21
22
Scheduler Implementations
SVR4 Solaris Mach Digital UNIX Other RT
23
SVR4 Scheduler
Redesigned from traditional approach Separate policy from implementation
Define scheduling classes
define framework with well defined interfaces Attempt to bound dispatch latencies Enhance application control
24
25
Kernel preemption points - PREMPT checks kprunrun at well defined points in the kernel runrun also used as in traditional implementations
26
SVR4 - Class-Independent
Responsible for
context switching, run queue management and preemption.
Highest (global) priority always runs priority range: 0 - 160, each with own queue
Default allocations:
real-time 100-159, system 60-99, timesharing 0-59
27
CL_TICK CL_FORK, CL_FORKRET CL_ENTERCLASS, CL_EXITCLASS CL_SLEEP, CL_WAKEUP CL_PREEMPT CL_YIELD CL_SETRUN
...
Fred Kuhns (12/2/2012) CS523 Operating Systems
28
System - fixed priority (FIFO). System tasks. Real-time: fixed priority and time quantum.
29
Solaris Overview
Multithreaded, Symmetric Multi-Processing Preemptive kernel - protected data structures MP Support - per cpu dispatch queues, one global kernel preempt queue. System Threads Priority Inheritance Turnstiles rather than wait queues
Interrupts handled using threads
30
Hidden Scheduling
Hidden Scheduling - kernel performs work asynchronously on behalf of threads, without considering priority of requester Solaris addresses by using system threads
Examples: STREAMS process and callout queue run at kernel priority which is lower than the RT class.
Callout processing is also a problem. Solaris uses two different callout queues: real-time and nonreal-time (callout thread).
31
Priority Inversion
Low priority thread holds a resource required by a higher priority thread. Partial solution - Priority Inheritance.
High priority thread lends its priority to the lower priority thread. Must be transitive kernel keeps a synchronization chain
32
33
MACH
Inherited base scheduling priority which is combined with a CPU usage factor CPU usage factor decayed 5/8 each second inactive threads set own priority after waking up. Clock handler charges current thread. Every 2 seconds, system thread scans run queue and recomputes priorities (addresses starvation) Fixed quantums, preemptive scheduling handoff scheduling - used by IPC
34
MACH MP Support
No cross processor interrupts processor sets thread runs on any of the processors from the assigned set. Processor allocation can be handled by a userlevel server Gang scheduling
dedicate one processor per thread. Minimize barrier synchronization delay
35
Digital UNIX
Time-sharing and real-time classes:
SCHED_OTHER, SCHED_FIFO, SCHED_RR,
Highest priority process is always run Priority range: 0-60 (0-29 TS, 20-31 SYS, 3263 RT) nonpreemptive kernel no control for priority inversion
36
Digital UNIX - MP
Per processor dispatch queues Scheduler will move threads between queues to balance load soft affinity
37