1 / 14

5. Process and thread scheduling

5. Process and thread scheduling. 5.1 Organization of Schedulers Embedded and Autonomous Schedulers 5.2 Scheduling Methods A Framework for Scheduling Common Scheduling Algorithms Comparison of Methods 5.3 Priority Inversion. Process and Thread Scheduling.

kim
Download Presentation

5. Process and thread 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. 5. Process and thread scheduling 5.1 Organization of Schedulers • Embedded and Autonomous Schedulers 5.2 Scheduling Methods • A Framework for Scheduling • Common Scheduling Algorithms • Comparison of Methods 5.3 Priority Inversion

  2. Process and Thread Scheduling • Scheduling occurs at two levels: • Process/job scheduling • Long term scheduling (seconds, minutes, …) • Move process to Ready List (RL) after creation(When and in which order?) • Dispatching • Short term scheduling (milliseconds) • Select process from Ready List to run • We use the term scheduling to refer to both

  3. Organization of Schedulers • Embedded • Called as function at end of kernel call • Runs as part of calling process • Autonomous • Separate process • Multiprocessor: may have dedicated CPU • Single-processor:scheduler and other processes alternate (every quantum)

  4. An Embedded Scheduler Scheduler() { do { find highest priority process p with p.status==ready_a; find a free cpu; if (cpu != NIL) Allocate_CPU(p,cpu); } while (cpu != NIL); do { find highest priority process p with p.status==ready_a; find lowest priority process q with p.status==running; if (Priority(p) > Priority(q)) Preempt(p,q); } while (Priority(p) > Priority(q)); if (self->Status.Type!=running) Preempt(p,self); }

  5. Scheduling Methods • Priority determines who runs • Can be static or dynamic • Given by Priority function: P = Priority(p) • p are parameters • Arbitration rule to break ties • Random • Chronological (FIFO) • Cyclic (Round Robin = RR) • When is scheduler invoked?—Decision mode • Preemptive: scheduler called periodically(quantum-oriented) or when system state changes • Nonpreemptive: scheduler called when process terminates or blocks

  6. Priority function Parameters • Possible parameters: • Attained service time (a) • Real time in system (r) • Total service time (t) • Period (d) • Deadline (explicit or implied by period) • External priority (e) • System load (not process-specific)

  7. Scheduling algorithms Name Decision mode Priority Arbitration FIFO: nonpreemptiveP = r random SJF: nonpreemptiveP = –t chronological/random SRT: preemptive P = –(t–a) chronological/random RR: preemptive P = 0 cyclic ML: preemptive P = e cyclic nonpreemptiveP = e chronological • n fixed priority levels • level P is serviced when n through P+1 empty

  8. Scheduling algorithms • MLF (Multilevel Feedback) • Like ML, but prioritychanges dynamically • Every process enters at highest level n • Each level P prescribes maximum time tP • tPincreases as P decreases • Typically: tn= T (a constant) tP = 2  tP+1

  9. Scheduling algorithms • MLF priority function: • depends on level n, and attained time, a P = n– log2(a/T+1) • derivation is in the book • but note: • there is no need to ever compute P • priority is known automatically by position in queue • MLF is preemptive: CPU is taken away whenever process exhausts tP • Arbitration rule (at highest non-empty level): cyclic (at quantum) or chronological (at tP)

  10. Scheduling Algorithms RM (Rate Monotonic): • Intended for periodic (real-time) processes • Preemptive • Highest priority: shortest period: P = –d EDF (Earliest Deadline First): • Intended for periodic (real-time) processes • Preemptive • Highest priority: shortest time to next deadline: P = –(d – r % d) • derivation r  d number of completed periods r % d time in current period d – r % d time remaining in current period

  11. Comparison of Methods • FIFO, SJF, SRT: Primarily for batch systems • total length of computation is the same for all • FIFO simplest • SJF & SRT have better average turnaround times: (r1+r2+…+rn)/n • Example: • Average turnaround times: • FIFO: ((0+5)+(3+2))/2 = 5.0 • SRT: ((2+5)+(0+2))/2 = 4.5 • SJF: same as FIFO (p1 arrived first, non-preemptive)

  12. Comparison of Methods • Time-sharing systems • Response time is critical • Use RR or MLF with RR within each queue • Choice of quantum determines overhead • When q  , RR approaches FIFO • When q  0, context switch overhead  100% • When q is much greater than context switch overhead, n processes run concurrently at 1/n CPU speed

  13. Comparison of Methods • Real-time systems • Feasible schedule: All deadlines are met • CPU utilization is defined as: U=∑ ti/di for all pi • If schedule is feasible, U  1 (but not vice versa): • EDF always yields feasible schedule if U  1. • RM yields feasible schedule if U<0.7 (approximately), otherwise, it may fail

  14. Comparison of Methods • Example • p1has service time 1.5, period 4 • p2 has service time 3, period 5 • U=(1.5/4) +3/5=.975 < 1 • EDF succeeds butRM fails

More Related