1 / 25

Operating Systems - Process (CPU) scheduling

Operating Systems - Process (CPU) scheduling. Seehwan Yoo MSE.cis.dku. Review. Computer systems ( hw ) Main components : CPU, mem , I/O devices Inter-connect: bus I/O device interaction w/ external world Comm . w/ cpu Interrupt Polling Direct memory access SW in computers

Download Presentation

Operating Systems - Process (CPU) 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. OperatingSystems- Process (CPU)scheduling Seehwan Yoo MSE.cis.dku

  2. Review • Computer systems (hw) • Main components: CPU, mem, I/O devices • Inter-connect: bus • I/O device • interaction w/ external world • Comm. w/ cpu • Interrupt • Polling • Direct memory access • SW in computers • OS kernel, user applications • Dual-mode execution • For protection • System call – interface to OS • Process • Abstraction of processor (CPU) / machine • Execution context • Cf.) program • Memory layout • Address space • Process states • State transition • Time-sharing system • Implementation with timer interrupt

  3. Process scheduling • Determine which process to run • Kernel maintains queues • Data structure! • Ready Q (runq) • Store processes in ready state • Device Q (ioq) • Store processes in waiting state (per-device) • Scheduler picks one of process to run during the next time slot • How?

  4. Overall picture of scheduling

  5. Scheduling • Diverse policies • Fair-share • First-In-First-Out • Shortest-Job-First • Good scheduler? • Evaluation criteria • CPU utilization • Throughput • Turn-around time • Waiting time • Response time

  6. Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput – # of processes that complete their execution per time unit • Turn-around time – amount of time tocomplete a particular process • Waiting time – amount of time a process has been waiting in the ready queue • Response time – amount of time it takes from when a request was submitted until the first response is produced, not output (for time-sharing environment)

  7. Anti-break! • Waiting time of blue-process? • Response time of red-process? • Turn around-time of blue-process at time 3? • Throughput of the system? • CPU utilization? a b c d e f

  8. First-In, First-Out • This is not a fair-share scheduler! • First-comer run until it is completed, or • Until it makes I/O request, or • Until it voluntarily yield CPU

  9. FIFO (FCFS) example ProcessBurst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 (at time 0) • The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17

  10. FIFO (FCFS) another example! Suppose that the processes arrive in the order: P2 , P3 , P1 • The Gantt chart for the schedule is: • 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 • Consider one CPU-bound and many I/O-bound processes

  11. Then, How about SJF? • Take the shortest job at first hand! ProcessArriva l TimeBurst Time P10.0 6 P2 2.0 8 P34.0 7 P45.0 3 • SJF scheduling chart • Average waiting time = (3 + 16 + 9 + 0) / 4 = 7

  12. And How about SRTF?- Running scheduler at every time tick • Take the remaining time job at first hand! • Now we add the concepts of varying arrival times and preemption to the analysis ProcessAarriArrival TimeTBurst Time P10 8 P2 1 4 P32 9 P43 5 • SRTF Gantt Chart • Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec

  13. Forget about it… • Only exist in theory • Who knows the shortest job? • It is the most well-known NP-hard problem • Homework)survey halting problem in the Internet

  14. But, an approximation can be made • From the last execution history • Commonly, α set to ½

  15. Like this,

  16. We can put them all together • Or stop it by now; • Break time

  17. Fair-share schedulerRound-robin (RR) • Gives no priority to all process • Pick up one process in an equal probability • If all the processes have the same time quantum, then all the processes would utilize CPU time evenly • Implementation would be… • Randomly pick up a process in the run queue • When time quantum is expired, put it in the retired queue • When there is no process in the run queue,switch run queue with retired queue • In practice, • Pick the first process in the run queue • Run it until time quantum is expired • When time quantum is expired, put it in the run queue (tail)

  18. RR property & example • Max (worst-case) response time? • Example ProcessBurst Time P1 24 P2 3 P3 3 • The Gantt chart is: • Typically, higher average turnaround than SJF, but better response • q should be large compared to context switch time • q usually 10ms to 100ms, context switch < 10 usec

  19. Priority-based scheduling • No fair-share scheduler! • Give a priority to a process • Scheduling according to the priority • Can be fixed • Can be dynamically changed • Consider low-class citizens! • Low-priority process could be starved • Respect the seniors! • Apply aging • Increase priority when a process is in the low priority for a long time

  20. Property of priority scheduling • Deterministic response time • Calculate it by hand! • Used in real-time systems • Rate-monotonic • Earliest-Deadline-First (EDF)

  21. Example of priority scheduling ProcessA arri Burst TimeTPriority P1 10 3 P2 1 1 P32 4 P41 5 P5 5 2 • Priority scheduling Gantt Chart • Average waiting time = 8.2 msec

  22. Re-think scheduling! • Basic ideas • Fair-share • First-in-First-out (FIFO, or queue) • Real-time • Do the right thing! • Does your application really want? • Compare • file copy (doing a lot of I/O operation) • Hanoii (scientific application for complex calculation)

  23. Thing to know – when you schedule process • Workload characteristics • CPU-bound jobs (CPU-intensive) • I/O-bound jobs (I/O-intensive) • Giving long CPU time for I/O-bound jobs • Giving high priority for CPU-bound jobs • What actually happens in the scheduler is • Complex • Homework) survey the Linux’s Scheduler

  24. A theory – Little’s Theorem • n = average queue length • W = average waiting time in queue • λ = average arrival rate into queue • Little’s law – in steady state, processes leaving queue must equal processes arriving, thus:n = λ x W • Valid for any scheduling algorithm and arrival distribution • For example, if on average 7 processes arrive per second, and normally 14 processes in queue, then average wait time per process = 2 seconds

  25. Summary page • Various schedulers • FIFO, SJF, SRTF, RR, priority-based • Evaluation criteria • Throughput, …time(s) • Workload characteristics • I/O or CPU-bound tasks • Think about the scheduler operation when I/O is involved?

More Related