intTypePromotion=1

Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling

Chia sẻ: Xaydung K23 | Ngày: | Loại File: PPTX | Số trang:67

0
94
lượt xem
8
download

Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling trình bày các khái niệm cơ bản, tiêu chuẩn lập kế hoạch, lập kế hoạch các thuật toán, lập kế hoạch đa xử lý, hệ thống điều hành, thuật toán đánh giá,...

Chủ đề:
Lưu

Nội dung Text: Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling

  1. Chapter 5: CPU Scheduling Operating System Concepts – 8th Edition Operating System Concepts – 8th Edition 5.1 Silberschatz, Galvin and Gagne ©2009
  2. Chapter 5: CPU Scheduling s Basic Concepts s Scheduling Criteria s Scheduling Algorithms s Thread Scheduling s Multiple-Processor Scheduling s Operating Systems Examples s Algorithm Evaluation Operating System Concepts – 8th Edition 5.2 Silberschatz, Galvin and Gagne ©2009
  3. Objectives s To introduce CPU scheduling, which is the basis for multiprogrammed operating systems s To describe various CPU-scheduling algorithms s To discuss evaluation criteria for selecting a CPU-scheduling algorithm for a particular system Operating System Concepts – 8th Edition 5.3 Silberschatz, Galvin and Gagne ©2009
  4. Basic Concepts s Maximum CPU utilization obtained with multiprogramming s CPU–I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait s CPU burst distribution Operating System Concepts – 8th Edition 5.4 Silberschatz, Galvin and Gagne ©2009
  5. Alternating Sequence of CPU and I/O Bursts Operating System Concepts – 8th Edition 5.5 Silberschatz, Galvin and Gagne ©2009
  6. Histogram of CPU-burst Times Operating System Concepts – 8th Edition 5.6 Silberschatz, Galvin and Gagne ©2009
  7. CPU Scheduler s Selects from among the processes in ready queue, and allocates the CPU to one of them q Queue may be ordered in various ways s CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state 2. Switches from running to ready state 3. Switches from waiting to ready 4. Terminates s Scheduling under 1 and 4 is nonpreemptive s All other scheduling is preemptive q Consider access to shared data q Consider preemption while in kernel mode q Consider interrupts occurring during crucial OS activities Operating System Concepts – 8th Edition 5.7 Silberschatz, Galvin and Gagne ©2009
  8. Dispatcher s Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: q switching context q switching to user mode q jumping to the proper location in the user program to restart that program s Dispatch latency – time it takes for the dispatcher to stop one process and start another running Operating System Concepts – 8th Edition 5.8 Silberschatz, Galvin and Gagne ©2009
  9. Scheduling Criteria s CPU utilization – keep the CPU as busy as possible s Throughput – # of processes that complete their execution per time unit s Turnaround time – amount of time to execute a particular process s Waiting time – amount of time a process has been waiting in the ready queue s 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) Operating System Concepts – 8th Edition 5.9 Silberschatz, Galvin and Gagne ©2009
  10. Scheduling Algorithm Optimization Criteria s Max CPU utilization s Max throughput s Min turnaround time s Min waiting time s Min response time Operating System Concepts – 8th Edition 5.10 Silberschatz, Galvin and Gagne ©2009
  11. First-Come, First-Served (FCFS) Scheduling Process Burst Time P1 24 P2 3 P3 3 s Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: P1 P2 P3 0 24 27 30 s Waiting time for P1 = 0; P2 = 24; P3 = 27 s Average waiting time: (0 + 24 + 27)/3 = 17 Operating System Concepts – 8th Edition 5.11 Silberschatz, Galvin and Gagne ©2009
  12. FCFS Scheduling (Cont.) Suppose that the processes arrive in the order: P2 , P3 , P1 s The Gantt chart for the schedule is: P2 P3 P1 0 3 6 30 s Waiting time for P1 = 6; P2 = 0; P3 = 3 s Average waiting time: (6 + 0 + 3)/3 = 3 s Much better than previous case s Convoy effect - short process behind long process q Consider one CPU-bound and many I/O-bound processes Operating System Concepts – 8th Edition 5.12 Silberschatz, Galvin and Gagne ©2009
  13. Shortest-Job-First (SJF) Scheduling s Associate with each process the length of its next CPU burst q Use these lengths to schedule the process with the shortest time s SJF is optimal – gives minimum average waiting time for a given set of processes q The difficulty is knowing the length of the next CPU request q Could ask the user Operating System Concepts – 8th Edition 5.13 Silberschatz, Galvin and Gagne ©2009
  14. Example of SJF ProcessArriva l Time Burst Time P1 0.0 6 P2 2.0 8 P3 4.0 7 P4 5.0 3 s SJF scheduling chart P4 P1 P3 P2 0 3 9 16 24 s Average waiting time = (3 + 16 + 9 + 0) / 4 = 7 Operating System Concepts – 8th Edition 5.14 Silberschatz, Galvin and Gagne ©2009
  15. Determining Length of Next CPU Burst s Can only estimate the length – should be similar to the previous one q Then pick process with shortest predicted next CPU burst s Can be done by using the length of previous CPU bursts, using exponential averaging 1. t n = actual length of n th CPU burst 2. τ n +1 = predicted value for the next CPU burst 3. α, 0 ≤ α ≤ 1 4. Define : s Commonly, α set to ½ s Preemptive version called shortest-remaining-time-first τ n =1 = α t n + (1 − α )τ n . Operating System Concepts – 8th Edition 5.15 Silberschatz, Galvin and Gagne ©2009
  16. Prediction of the Length of the Next CPU Burst Operating System Concepts – 8th Edition 5.16 Silberschatz, Galvin and Gagne ©2009
  17. Examples of Exponential Averaging s =0 q n+1 = n q Recent history does not count s =1 q n+1 = tn q Only the actual last CPU burst counts s If we expand the formula, we get: n+1 = tn+(1 - ) tn -1 + … +(1 - )j tn -j + … +(1 - )n +1 0 s Since both and (1 - ) are less than or equal to 1, each successive term has less weight than its predecessor Operating System Concepts – 8th Edition 5.17 Silberschatz, Galvin and Gagne ©2009
  18. Example of Shortest-remaining-time-first s Now we add the concepts of varying arrival times and preemption to the analysis ProcessA arri Arrival TimeTBurst Time P1 0 8 P2 1 4 P3 2 9 P4 3 5 s Preemptive SJF Gantt Chart P1 P2 P4 P1 P3 0 1 5 10 17 26 s Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec Operating System Concepts – 8th Edition 5.18 Silberschatz, Galvin and Gagne ©2009
  19. Priority Scheduling s A priority number (integer) is associated with each process s The CPU is allocated to the process with the highest priority (smallest integer highest priority) q Preemptive q Nonpreemptive s SJF is priority scheduling where priority is the inverse of predicted next CPU burst time s Problem Starvation – low priority processes may never execute s Solution Aging – as time progresses increase the priority of the process Operating System Concepts – 8th Edition 5.19 Silberschatz, Galvin and Gagne ©2009
  20. Example of Priority Scheduling ProcessA arri Burst TimeT Priority P1 10 3 P2 1 1 P3 2 4 P4 1 5 P5 5 2 s Priority scheduling Gantt Chart P2 P5 P1 P3 P4 0 1 6 16 18 19 s Average waiting time = 8.2 msec Operating System Concepts – 8th Edition 5.20 Silberschatz, Galvin and Gagne ©2009
ADSENSE
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2