1 / 31

Chapter 5. Process Scheduling

Chapter 5. Process Scheduling. Clock interrupt handling Scheduler goal Traditional UNIX scheduling SVR4 scheduler Solaris 2.x scheduling enhancements Scheduling in Mach Other scheduling implementation. Clock Interrupt Handling. H/W clock interrupts the system at fixed time intervals

nancyjones
Download Presentation

Chapter 5. Process Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5. Process Scheduling • Clock interrupt handling • Scheduler goal • Traditional UNIX scheduling • SVR4 scheduler • Solaris 2.x scheduling enhancements • Scheduling in Mach • Other scheduling implementation

  2. Clock Interrupt Handling • H/W clock interrupts the system at fixed time intervals • The clock interrupt handler is second priority only to that of power-failure interrupt • The clock interrupt handler performs • rearms the h/w clock if necessary • updates CPU usage statistics for the current process

  3. Clock Interrupt Handling (cont) • performs scheduler-related functions, such as • priority recomputation • time-slice expiration handling • sends a SIGXCPU signal to the current process if it has exceeded its CPU usage quota • updates the time-of-day clock and other related clocks • handle callouts • wakes up system processes such as the swapper and pagedaemon when appropriate • handle alarm

  4. Callouts • A callout records a function that the kernel must invoke at a later time • e.g. SVR4 • int to_ID = timeout(void (*fn( )), caddr_t arg, long delta); • In system context • Used for periodic tasks • retransmission of network packets • scheduler and memory management functions • monitoring devices to avoid losing interrupts • polling devices that do not support interrupts

  5. Callouts (cont) • Callout implementation in BSD UNIX Callout listhead t = 2 roundrobin t = 1 schedcpu t = 4 f1 t = 0 f2 time left to fire 2 3 7 7 (a) Callout queue at on instant of time Callout listhead t = 1 roundrobin t = 1 schedcpu t = 4 f1 t = 0 f2 time left to fire 1 2 6 6 (b) Callout queue one tick later

  6. Alarms • A process requests the kernel to send it a signal after a specific amount of time • three types of alarms • real-time alarm • relates to the actual elapsed time, via a SIGALARM signal • high resolution  high accuracy • profiling alarm • measures the amount of time the process has been executing, via SIGPROF signal • virtual time alarm • monitors only the time spent by the process in user mode, via SIGVTALARM signal

  7. Scheduler Goals • Deliver acceptable performance to each Ap. • Categories of applications • interactive • spend a lot of time waiting user input • system needs to reduce the average time and variance btw user action and application response • acceptable delay is about 50 ~ 150ms • batch • do not require user interaction, as background jobs • criteria: task’s completion time • real-time • time-critical with guaranteed bounds on response time

  8. Traditional Scheduling • SVR3, 4.3 BSD • Scheduling target • time-sharing, interactive environment with several batch and foreground processes simultaneously • Scheduling policy • improve response time of interactive users, while ensuring that low priority, background jobs do not starve

  9. Traditional Scheduling (cont) • Priority-based • priority changes with time • preemptive time-slicing • Kernel is nonpreemptible • Process priority • 0 ~ 49: kernel, 50 ~ 127: process in user mode • proc structure • p_pri current scheduling priority • p_usrpri user mode priority • p_cpu measure of recent CPU usage • p_nice user-controllable nice factor

  10. Traditional Scheduling (cont) • Sleep priority • kernel value (0 ~ 49) • e.g. terminal input: 28, disk I/O: 20 • Priority calculation: schedcpu( ) • every tick, clock handler increments p_cpu for the current process • every second, p_cpu = p_cpu - decay factor; • p_usrpri = PUSER + p_cpu/4 + 2*p_nice; • PUSER is the baseline priority of 50

  11. 0 ~ 3 4 ~ 7 8 ~ 11 12 ~ 15 16 ~ 19 20 ~23 . . . Traditional Scheduling (cont) whichqs • Scheduler implementation qs 0 0 0 1 0 1 . . . P P P P P

  12. Traditional Scheduling (cont) • Situations for context switch • current process blocks on a resource, or exits • priority recomputation procedure results in the priority of another process becoming greater than that of of the current one • current process, or an interrupt handler, wakes up a higher-priority process

  13. Traditional Scheduling (cont) • Analysis • simple and effective • favor I/O-bound jobs • not scale well • no guarantee of CPU usage and response time • kernel is non-preemptive: priority inversion

  14. SVR4 Scheduler • Scheduling class • time sharing and real-time • class-independent routines • common services such as context switching, run queue manipulation, and preemption • class-dependent routines • priority computation and inheritance

  15. 160 159 158 157 156 155 . . . SVR4 Scheduler (cont) • SVR4 dispatch queues dqactmap dispq 0 0 1 0 0 1 . . . P P P P P

  16. SVR4 Scheduler (cont) • SVR4 kernel defines several preemption points • places in the kernel code where all kernel data structures are in a stable state, and the kernel is about to embark on a length computation • Three ranges of 160 priorities • 0 ~ 59: time-sharing class • 60 ~ 99: system priorities • 100 ~ 159: real-time class

  17. real-time system time-sharing SVR4 Scheduler (cont) Global class table rt_classfuncs rt-init • interface to the scheduling class sys_classfuncs sys-init ts_classfuncs ts-init proc structures p_cid p_clfuncs p_clproc . . . p_cid p_clfuncs p_clproc . . . p_cid p_clfuncs p_clproc . . . p_cid p_clfuncs p_clproc . . . class-dependent data class-dependent data class-dependent data class-dependent data

  18. SVR4 Scheduler (cont) • Time-sharing class • changes process priorities dynamically • round-robin scheduling with the same priority • event driven scheduling • reduces process priority each time it uses up its time slice • boosts the priority of the process if it blocks on an event or resource, or if it takes a long time to use up it quantum

  19. SVR4 Scheduler (cont) • Real-time class • scheduled before any kernel process • fixed priority and time quantum • requires bounded dispatch latency and response time event occurs Interrupt processing process made runnable dispatch latency response time nonpreemptive kernel processing time context switch initiated context switch process is scheduled to run application code process responds to event

  20. SVR4 Scheduler (cont) • Analysis • allows the addition of scheduling class • time-sharing class changes priorities based on events related to that process • favor I/O-bound and interactive jobs over CPU-bound ones • code path btw preemption points is too long for time-critical applications • difficult to tune the system properly for a mixed set of jobs

  21. Solaris 2.x Scheduling Enhancement • Preemptive kernel • most global kernel data structures must be protected by synchronization objects • implementation of interrupts using special kernel threads • Multiprocessor support • single dispatch queue for all processors

  22. T1 pri 120 T2 pri 130 T3 pri 100 T4 pri 132 T5 pri 135 T6 pri 130 T7 pri 115 P1 P2 P3 P4 P5 MP Scheduling in Solaris 2.x • Initial situation

  23. T2 pri 130 T7 pri 115 T1 pri 120 T6 pri 130 T3 pri 100 T4 pri 132 T5 pri 135 P5 P4 P2 P1 P3 MP Scheduling in Solaris (cont) about to be switched out • After T6 and T7 become runnable CPU_chosen_level = 130 about to be scheduled on P3 dispatcher queues

  24. Priority Inversion • Lower priority process holds a resource needed by a higher priority process, thereby blocking that higher priority process • Solved by priority inheritance • when a high-priority thread blocks on a resource, it temporarily transfer its priority to the lower priority thread that owns the resource

  25. T2 pri 130 T1 pri 100 T3 pri 110 T2 pri 130 T1 pri 100 T2 pri 130 T3 pri 110 T3 pri 110 T1 pri 100 Priority Inversion (cont) R currently running becomes runnable holds blocks (a) Initial situation runnable currently running holds blocks R dispatcher queues (b) Without priority inheritance currently running runnable holds blocks R inh pri = 130 dispatcher queues (c) With priority inheritance

  26. T6 pri 100 T7 pri 122 T6 pri 100 T4 pri 135 T5 pri 110 T7 pri 122 T5 pri 110 T4 pri 135 Priority Inversion (cont) currently running • Transitive priority inheritance holds blocks holds blocks R1 R2 becomes runnable (a) Initial situation currently running runnable holds blocks holds blocks R1 R2 inh pri = 135 inh pri = 135 dispatcher queues (b) Transitive priority inheritance

  27. T6 gp 110 T3 gp 70 T2 gp 90 ip 100 T4 gp 100 T1 gp 60 ip 100 T5 gp 80 R4 R1 R2 R3 Priority Inheritance blocked threads • Traversing the synchronization chain holds owner owner runnable holds holds owner owner wants holds currently running gp = global priority ip = inherited priority

  28. T6 gp 110 T3 gp 70 T4 gp 100 T2 gp 90 ip 100 T1 gp 60 ip 110 T5 gp 80 ip 110 R1 R2 R3 R4 Priority Inheritance (cont) blocked threads holds owner currently running owner holds holds owner owner holds gp = global priority ip = inherited priority blocked threads

  29. Priority Inheritance (cont) • Limitations • is not used for semaphores and condition variables since the owner is usually indeterminate • Turnstiles • reduce information maintained by kernel for hundreds of synchronization objects Turnstile pool active T active T T T T Blocked threads active T Synchronization objects

  30. Scheduling in Mach • Schedules threads regardless of the task to which they belong • Handoff scheduling • a thread can directly yield the processor to another thread w/o searching the run queue • improves the performance of the IPC calls • Multiprocessor support • processor allocation can be handled by a user-lever server program • gang scheduling

  31. Other Scheduling • Deadline-driven scheduling • Three-level scheduler • isochronous class • real-time class • general-purpose class • admission control

More Related