1 / 24

Operating Systems, 371-1-1631 Winter Semester 2011

Operating Systems, 371-1-1631 Winter Semester 2011. Practical Session 4, Threads (cont.) Scheduling. A quick recap. Quality criteria measures: Throughput – The number of completed processes per time unit. Turnaround time – The time interval between the process submission and its completion.

andie
Download Presentation

Operating Systems, 371-1-1631 Winter Semester 2011

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. Operating Systems, 371-1-1631Winter Semester 2011 Practical Session 4, Threads (cont.) Scheduling

  2. A quick recap Quality criteria measures: • Throughput – The number of completed processes per time unit. • Turnaround time – The time interval between the process submission and its completion. • Waiting time – The sum of all time intervals in which the process was in the ready queue. • Response time – The time taken between submitting a command and the generation of first output. • CPU utilization – Percentage of time in which the CPU is not idle.

  3. A quick recap Two types of scheduling: • Preemptive schedulingA task may be rescheduled to operate at a later time (for example, it may be rescheduled by the scheduler upon the arrival of a “more important” task). • Non Preemptive scheduling (cooperative)Task switching can only be performed with explicitly defined system services (for example: the termination task, explicit call to yield() , I/O operation which changes the process state to blocking, etc’…).

  4. A quick recap Scheduling algorithms taught in class: • FCFS (First – Come, First – Served). • Non preemptive. • Convoy effect. • SJF (Shortest Job First). • Optimal with respect to the minimal average turnaround time (waiting time as well!). • No way of knowing the length of the next CPU burst. • Can approximate next burst according to: Tn+1=tn+(1- )Tnwhere tn is the most recent information and Tn is history • Preemptive (Shortest Remaining Time First) or non preemptive. • Round Robin. • When using large time slices it imitates FCFS. • When using time slices which are closer to context switch time, more CPU time is wasted on switches.

  5. A quick recap • Guaranteed scheduling. • Constantly calculates, per process, the ratio of allocated CPU time and amount of CPU time a process is entitled to. • Guarantees 1/n of CPU time. • Priority scheduling. • A generalization of SJF (How?). • Multi Level Queue scheduling. • Partition the ready queue. • Each partition employs its own scheduling scheme. • A process from a lower priority group may run only if there is no higher priority process. May cause starvation!

  6. A quick recap • Dynamic Multi Level scheduling. • Takes into account the time spent waiting (the notion of aging to prevent starvation). • Highest Response Ratio Next (setting priorities): • Feedback scheduling. • Demote processes running longer. • Combine with aging to prevent starvation. • Two Level scheduling. • Involves schedulers for Memory-CPU operations, and another scheduler for Memory-Disk operations.

  7. Warm up (1) • Why bother with multiprogramming? • Assume processes in a given system waits for I/O 60% of the time. • What is the approximate CPU utilization with one process running? • What is the approximate CPU utilization with three processes running?

  8. Warm up (1) • If a process is blocking on I/O 60% of the time, than there is only 40% CPU is utilization. • At a given moment, the probability that all three processes are blocking on I/O is 0.63. That means that the CPU utilization is (1-0.63)=0.8704, or roughly 87%.

  9. Warm up (2) • Q: Assume a single CPU machine with a non preemptive scheduler, attempting to schedule n independent processes. How many possible schedules exist? • A: This is exactly like ordering a set of n different letters to form an n-long word. This results in n! different possible schedules.

  10. Round Robin • The following is a list of processes which require scheduling: • PA – 6 TU (time units) • PB – 3 TU • PC – 1 TU • PD – 7 TU • What is the optimal quanta size when scheduling with RR to achieve minimal average turnaround time? (assume 0 cost context switches, and that all processes are in the ‘ready’ queue)

  11. Round RobinPA=6, PB=3, PC=1, PD=7 • Quanta = 1: • Quanta = 2: • Quanta = 3: 10.75 TU • Quanta = 4: 11.5 TU • Quanta = 5: 12.25 TU • Quanta = 6: 10.5 TU • Quanta = 7: 10.5 TU (3+9+15+17)/4=11 TU (5+10+14+17)/4=11.5 TU

  12. Round Robin Turnaround time depends on the size of the time quantum used. Note that it does not necessarily improve as time quantum size increases!

  13. Non preemptive scheduling (Taken from Tanenbaum) Assume 5 different jobs arrive at a computer center, roughly at the same time (same clock tick). Their expected run times are 10, 6, 2, 4 and 8 TU. Their (externally determined) priorities are 3, 5, 2, 1 and 4 respectively. For each of the following scheduling algorithm, determine the mean process turnaround time. Ignore process switching overhead. All jobs are completely CPU bound. • Priority Scheduling (non-preemptive). [Higher number means higher priority] • First come first served (in order 10, 6, 2, 4, 8) (non-preemptive) • Shortest job first (non-preemptive) • Priority Scheduling: (6+14+24+26+30)/5=20 • FCFS:(10+16+18+22+30)/5=19.2 • SJF:(2+6+12+20+30)/5=14

  14. Preemptive dynamic priorities scheduling • (Taken from Silberschatz, 5-9) • Consider the following preemptive priority scheduling algorithm based on dynamically changing priorities (Larger priority numbers imply higher priority) When a process is waiting for the CPU (in the ready queue, but not running), its priority changes at rate α; when it is running, its priority changes at rate β. All processes are given a priority of 0 when they enter the ready queue. The parameters α and β can be set. • What is the algorithm that results from β > α > 0? • What is the algorithm that results from α < β < 0? • Is there a starvation problem in 1? in 2? explain.

  15. Preemptive dynamic priorities scheduling • >>0. To get a better feeling of the problem, we will create an example:C, P1, P2, P3 arrive one after the other and last for 3 TU, =1 and =2(bold marks the running process): The resulting schedule is FCFS. Slightly more formal: If a process is running it must have the highest priority value. While it is running, it’s priority value increases at a rate greater than any other waiting process. As a result, it will continue it’s run until it completes (or waits on I/O, for example). All processes in the waiting queue, increase their priority at the same rate, hence the one which arrived earliest will have the highest priority once the CPU is available.

  16. Preemptive dynamic priorities scheduling •  <<0. We will use (almost) the same example problem as before, but this time =-2, =-1: The resulting schedule is LIFO. More formally: If a process is running it must have the highest priority value. While it is running, it’s priority value decreases at a lower rate than any other waiting process. As a result, it will continue it’s run until it completes (or waits on I/O, for example), or a new process with priority 0 is introduced. As before, all processes in the waiting queue, decrease their priority at the same rate, hence the one which arrived later will have the highest priority once the CPU is available.

  17. Preemptive dynamic priorities scheduling In the first case it is easy to see that there is no starvation problem. When the Kth process is introduced it will await at most (K-1)max{timei} time units. This number might be large but it is still finite. This is not true for the second case. Consider the following scenario: P1 is introduced and receives CPU time. While still working a 2nd process, P2, is initiated. According to this scheduling algorithm, P2will receive the CPU time and P1 will have to wait. As long as enough new processes are introduced P1 will never have a chance to complete it’s task.

  18. Guaranteed scheduling Three processes run on a preemptive (switching is done on every round), guaranteed scheduling (ties are broken with preference to the lower ID process) OS. They require the use of both the CPU and I/O: P1 – 1 TU CPU, 4 TU I/O, 2 TU CPU P2 – 1 CPU, 2 I/O, 2 CPU P3 – 2 CPU, 1 I/O, 2 CPU For questions 1-3 draw a Gantt chart and compute the avg. TA time: Identical arrival time, I/O is done on separate devices. Identical arrival time, I/O is done on the same device with FCFS scheduling. Process arrival time is: P1 at 0, P2 at 1 and P3 at 2. I/O is done on separate devices. Would Round Robin produce the same results? Explain your answer.

  19. Guaranteed scheduling 1. The Gantt table: Avg. TA: (7+8+10)/3=8.33

  20. Guaranteed scheduling 2. The Gantt table: Avg. TA: (7+9+11)/3=9

  21. Guaranteed scheduling 3. The Gantt table: Avg. TA: (7+7+8)/3=7.33

  22. Guaranteed scheduling 4. No, RR implements fairness only between process waiting in ready state, and hence no process will receive two consecutive time slices while another process is waiting. This is in contrast to Guaranteed scheduling, which takes into account all the time the process spent in the system.

  23. Multi-core Scheduling נניח כי עומד לרשותנו מחשב בעל שני מעבדים (C1, C2). בכל רגע נתון עובדים שני המעבדים אלא אם כן אין יותר עבודות ממתינות.למערכת מגיעים בו זמנית אוסף של 13 תהליכים משלושה טיפוסים כמפורט להלן: • תהליכי A – תהליכים קצרים שמסתיימים לאחר יחידת זמן אחת (תהליך יחיד) • תהליכי B – תהליכים ארוכים מעט יותר שמסתיימים לאחר שתי יחידות זמן (7 תהליכים) • תהליכי C – תהליכים שמסתיימים לאחר שלוש יחידות זמן (5 תהליכים). עבור שני האלגוריתמים הבאים חשבו: • מה יהיה ה-turnaround time הממוצע ואיזה אלגוריתם מוצלח יותר עפ"י מדד זה? • בכמה זמן CPU נעשה שימוש ואיזה אלגוריתם מוצלח יותר עפ"י מדד זה? • מהו משך הזמן הנדרש לסיום החישוב ואיזה אלגוריתם מוצלח יותר עפ"י מדד זה? • תהליכים מטיפוס A ו-B מופנים למעבד C1 שמפעיל SJF על תהליכים אלו. כל תהליכי C מופנים למעבד C2. במידה ומעבד מסוים סיים את עבודתו לפני השני הוא מטפל בתהליכים הנותרים עפ"י עיקרון SJF. • התהליכים מופנים למעבדים השונים עפ"י SJF.

  24. Multi-core Scheduling נצייר טבלת Gantt לשני המעבדים: עבור האלגוריתם הראשון: ועבור האלגוריתם השני: כעת ניתן לענות על השאלות בקלות: • לראשון – avg. TA=(64+45)/13=109/13=8.38לשני – avg. TA=(55+45)/13=100/13=7.53ולכן ברור כי SJF יהיה מוצלח יותר בשיטה זו (עדיף על פני Affinity). • ברור שבשני השיטות משך החישוב הנדרש יהיה זהה: 30. בשיטה אחת 15+15 ואילו בשיטה השניה 16+14. • במפתיע, על אף היותו מוצלח יותר מבחינת turnaround אלגוריתם SJF מסיים מאוחר יותר, כעבור 16 יחיודת זמן, בעוד שהאלגוריתם הראשון מסיים לאחר 15 יחידות זמן.

More Related