Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling
lượt xem 14
download
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á,...
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Bài giảng Hệ điều hành nâng cao - Chapter 5: CPU Scheduling
- Chapter 5: CPU Scheduling Operating System Concepts – 8th Edition Operating System Concepts – 8th Edition 5.1 Silberschatz, Galvin and Gagne ©2009
- 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
- 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
- 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
- Alternating Sequence of CPU and I/O Bursts Operating System Concepts – 8th Edition 5.5 Silberschatz, Galvin and Gagne ©2009
- Histogram of CPU-burst Times Operating System Concepts – 8th Edition 5.6 Silberschatz, Galvin and Gagne ©2009
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- Prediction of the Length of the Next CPU Burst Operating System Concepts – 8th Edition 5.16 Silberschatz, Galvin and Gagne ©2009
- 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
- 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
- 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
- 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
CÓ THỂ BẠN MUỐN DOWNLOAD
-
Bài giảng Hệ điều hành nâng cao - Chapter 3: Processes
54 p | 139 | 15
-
Bài giảng Hệ điều hành nâng cao - Chapter 11: File System Implementation
63 p | 197 | 14
-
Bài giảng Hệ điều hành nâng cao - Chapter 19: Real - Time Systems
24 p | 101 | 13
-
Bài giảng Hệ điều hành nâng cao - Chapter 6: Process Synchronization
72 p | 207 | 11
-
Bài giảng Hệ điều hành nâng cao - Chapter 10: File - System Interface
43 p | 100 | 10
-
Bài giảng Hệ điều hành nâng cao - Chapter 12: Mass - Storage Systems
57 p | 172 | 10
-
Bài giảng Hệ điều hành nâng cao - Chapter 13: I/O Systems
42 p | 161 | 9
-
Bài giảng Hệ điều hành nâng cao - Chapter 2: Operating - System Structures
54 p | 178 | 9
-
Bài giảng Hệ điều hành nâng cao - Chapter 1: Introduction
48 p | 142 | 8
-
Bài giảng Hệ điều hành nâng cao - Chapter 4: Threads
45 p | 136 | 8
-
Bài giảng Hệ điều hành nâng cao - Chapter 21: The Linux System
62 p | 149 | 7
-
Bài giảng Hệ điều hành nâng cao - Chapter 20: Multimedia Systems
33 p | 129 | 6
-
Bài giảng Hệ điều hành nâng cao - Chapter 22: Windows XP
64 p | 93 | 6
-
Bài giảng Hệ điều hành nâng cao - Chapter 14: Protection
29 p | 77 | 5
-
Bài giảng Hệ điều hành nâng cao - Chapter 17: Distributed - File Systems
29 p | 88 | 5
-
Bài giảng Hệ điều hành nâng cao - Chapter 18: Distributed Coordination
54 p | 89 | 5
-
Bài giảng Hệ điều hành nâng cao - Chapter 16: Distributed System Structures
36 p | 105 | 4
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn