1 / 102

Efficient CPU Scheduling for Optimal Processor Sharing

Explore CPU scheduling goals, priorities, policies, and schedulers with a focus on enhancing system performance and multitasking efficiency.

vphelan
Télécharger la présentation

Efficient CPU Scheduling for Optimal Processor Sharing

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. Chapter 5Processor Scheduling

  2. Goals of Processor Scheduling • The main goal of Processor (CPU) scheduling is the sharing of the processor(s) among the processes in the ready queue • The critical activities of OS are: • Carry out the orderingof the allocation and de-allocation jobs of the CPU to the various processes and threads, one at a time • Deciding when to de-allocate and allocate the CPU from a process to another process

  3. Priorities and Scheduling • Priorities can be used with either preemptive (Proactive)or non-preemptive scheduling. • Depending on the goals of an operating system, one or more of various scheduling policies can be used; each will result in a different system performance. • The criteria is based on relevant performance measures and the various scheduling policies are evaluated based on the criteria.

  4. CPU Scheduling Policies • First-come-first-served (FCFS) • Shortest job first (Shortest process next) • Longest job first • Priority scheduling • Round robin (RR) • Shortest remaining time (SRT) also known as shortest remaining time first (SRTF)

  5. Types of Schedulers • Long-term scheduler (memory allocation) • The OS decided to create a new process from the jobs waiting in the input queue and loaded into memory • Controls the degree of multiprogramming • Medium-term scheduler • The OS decides when and which process to swap out or swapin from or to memory. • This also controls the degree of multiprogramming. • Short-term scheduler (processor scheduling) • The OS decides when and which process the CPU will be allocated next to be executed.

  6. Basic Concepts • The success of CPU scheduling depends on an observed property of process as follows: • CPU Burst and I/O Burst Cycle – Process execution consists of a cycle of CPU execution and I/O wait • CPU burst followed by I/O burst • CPU burst distribution is of main concern Maximum CPU utilization obtained with multiprogramming

  7. Durations of CPU-burst Times Large number of short CPU burst Short burst Long burst Depend on the process and computer, they tend to have a frequently curve similar to the figure above, which the curve is characterized as exponential, with a large number of short CPU burst and small number of long CPU bursts.

  8. Scheduling with Multiple Queues In a system with multiprogramming OS, there are usually several processes in the ready queue waiting to be receive service from CPU. The degree of multiprogrammingrepresent the number of processes in memory. A system with different group of processes is called a multiclass system by given different workload. In multiclass systems, there is potential for starvation (indefinite waiting) of one or more processes.

  9. CPU Scheduler • Short-term scheduler selects from among the processes in ready queue, and allocates the CPU to one of them • Queue may be ordered in various ways • 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 • Terminates • Scheduling under 1 and 4 is nonpreemptive • All other scheduling is preemptive • Consider access to shared data • Consider preemption while in kernel mode • Consider interrupts occurring during crucial OS activities

  10. Dispatcher • Dispatchermodule gives control of the CPU to the process selected by the short-term scheduler; this involves: • switching context • switching to user mode • jumping to the proper location in the user program to restart that program • Dispatch latency – time it takes for the dispatcher to stop one process and start another running

  11. In non preemptivemeansonce a process enters the running state, it is NOT removed from the processor until it has completed its service time. means we allow the current process to finish its CPU burst time.

  12. In preemptive means suspending a work. making a task to wait for a while based on condition. This scheduling means we prevent the currently executing process.

  13. Scheduling Criteria • CPU utilization – keep the CPU as busy as possible • Throughput–# of processes that complete their execution per time unit, or the amount of time that material or items passing through a system or process; • Turnaround time – amount of time to execute 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) • Average turnaround time – The average time between the arrival time and completion time.

  14. CPU-IO Bursts of Processes An important property of a process is its CPU-IO burst • CPU Burst- is a process waits for I/O completion • I/O burst - is a process waits for CPU completion • An I/O bound process has many short CPU burst • A CPU bound process has few long CPU bursts • The OS tries to main maintain a balance of these two types pf processes

  15. CPU Scheduling Policies Categories of scheduling policies: • Non-Preemptive -- no interruptions are allowed. A process completes execution of its CPU burst • Preemptive – a process can be interrupted before the process completes its CPU burst

  16. FCFS Scheduling First come first served (FCFS) scheduling algorithm, a non-preemptive policy • The order of service is the same order of arrivals • Managed with FIFO queue • Simple to understand and implement • Scheduling is FAIR • The performance of this scheme is relatively poor

  17. First- Come, First-Served (FCFS) Scheduling FCFCis a basic analysis of scheduling policy calculate some of the performance metrics. ProcessBurst Time P1 24 P2 3 P3 3 • Suppose that the processes arrive in the order: P1 , P2 , P3 The Gantt Chart for the schedule is: • Waiting time for P1 = 0; P2 = 24; P3 = 27 • Average waiting time: (0 + 24 + 27)/3 = 17

  18. FCFS Scheduling (Cont.) 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

  19. Deterministic Modeling - FCFS Consider the following workload: Five processes arrive at time 0, in the order: P1, P2, P3, P4, P5; with CPU burst times: 135, 102, 56, 148, 125 msec., respectively. The chart for FCFS is: The average waiting time FCFS is: (0 + 135 + 237 + 293 + 441) / 5 = 221 msec Deterministic Modeling is a Mathematical model in which outcomes are precisely determined through known relationships among states and events, without any room for random variation

  20. Algorithm Evaluation • How to select CPU-scheduling algorithm for an OS? • Determine criteria, then evaluate algorithms • Deterministic modeling • Type of analytic evaluation • Takes a particular predetermined workload and defines the performance of each algorithm for that workload • Consider 5 processes arriving at time 0:

  21. Deterministic Evaluation • Consider the FCFS, SJF, and RR (Quantum=10 Msec) • For each algorithm, calculate minimum average waiting time • FCFS is 28ms: The Average Waiting Time is (0+10+39+42+49)/5=28 • Non-preemptive SFJ is 13ms: The Average Waiting Time is (10+32+0+3+20)/5=13 • RR is 23ms: The Average Waiting Time is (0+32+20+23+40)/5=23

  22. Shortest (Job) Process Next (SPN) Consider the following workload: Five processes arrive at time 0, in the order: P1, P2, P3, P4, P5; with CPU burst times (completion time between two states, no subtracting two numbers): P1: time between arriving time 283and completion time 418 = 135 (p3 is 4th SJF) P2: time between arriving time 56 and completion time 158 = 102 (p3 is 2stSJF) P3: time between arriving time 0and completion time 56 = 56 (p3 is 1stSJF) P4: time between arriving time 418 andcompletion time566 = 148 (p3 is 5th SJF) P5: time between arriving time56 andcompletion time283 = 125 (p3 is 3rd SJF) The average waiting time for SPN is: Job Arrived at ((P1)283+(P2)56+(P3) 0+(P4)418+ (P5) 158) / 5 = 183 msec.

  23. Shortest-Job-First (SJF) Scheduling • Associate with each process the length of its next CPU burst • Use these lengths to schedule the process with the shortest time • SJF is optimal – gives minimum average waiting time for a given set of processes • The difficulty is knowing the length of the next CPU request • Could ask the user

  24. Example of SJF Process Burst Time P1 6 (Completion time in Msec) P2 8 (Completion time in Msec) P3 7 (Completion time in Msec) P4 3 (Completion time in Msec) • SJF scheduling chart • Average waiting time = (3 + 16 + 9 + 0) / 4 = 7

  25. Stochastic Models • Discussed in Ch.3 that simulation model have variables that change values in a nondeterministic manner (with uncertainty). As stochastic model include random variables to implement uncertainly attributes. • Refer to an Example: Appendix E- page 509 from textbook for exam

  26. Normalization Turnaround Time (Ntat) • Ntat for each process is computed by dividing the turnaround time /CPU burst (by its service time ) 293 273 566 135 441 0 Process Strat CompletionWaitTurnaroundNtat P1 0 135 0 135 1.0 P2 135 237 135 237 2.323 P3 237 293 237 293 5.232 P4 293 441 293 441 2.979 P5 441 566 441 566 4.528 P1; 135/135 = 1.0 P3; 293/(293-237) =5.232 P2; 237/(237-135) = 2.323 P4; 441/(441-293)=2.929 P5; 566/(566-441)=4.528

  27. SJF (SPN) Scheduling • The scheduler selects the next the process with the shortest CPU burst • Basically a non-preemptive policy • SJF is optimal - gives the minimum average waiting time for a given set of processes. Non-Preemptive Shortest Job First Scheduling – Video 1:16

  28. Example of Shortest-remaining-time-first • Now we add the concepts of varying arrival times and preemption to the analysis ProcessArrival TimeBurst Time P10 8 P2 1 4 P32 9 P43 5 • Preemptive SJF Gantt Chart • Average waiting time = [(10-1)+(1-1)+(17-2)+5-3)]/4 = 26/4 = 6.5 msec

  29. SRTF Example Shortest remaining time first (SRTF_ a new process that arrives will cause the scheduler to interrupt the currently executing process. Suppose that another process, P6 arrives at time 200 with a CPU burst (Strat the process and Completing the process) of 65 Mirosec. This process (P6) arrives while P5 is executing and has to wait until process P5 completes.

  30. Shortest Remaining Time First • Shortest remaining time (SRTF) is a preemptive version of SPN scheduling. • With this scheduling policy, a new process that arrives will cause the scheduler to interrupt the currently executing process if the CPU burst of the newly arrived process is less than the remaining service period of the process currently executing. • There is then a context switch and the new process is started immediately.

  31. SRTF Scheduling • When there are no arrivals, the scheduler selects from the ready queue the process with the shortest CPU service period (burst). • As with SPN, this scheduling policy can be considered multi-class because the scheduler gives preference to the group of processes with the shortest remaining service time and processes with the shortest CPU burst.

  32. Gantt Chart for SRTF Example Turnaround time is the completion time 631 0 348 483 56 158 283 Process StartCPU burstWaitTurnaroundNtat P1 248 135 348 483 3.577 P2 56 102 56 158 1.549 P3 0 56 0 56 1.0 P4 483 148 483 631 4.263 P5 158 125 158 283 2.264 P6 200 65 83 148 2.276

  33. Turnaround Time Varies With The Time Quantum 80% of CPU bursts should be shorter than q

  34. Priority Scheduling • A priority number (integer) is associated with each process • The CPU is allocated to the process with the highest priority (smallest integer  highest priority) • Preemptive • Nonpreemptive • SJF is priority scheduling where priority is the inverse of predicted next CPU burst time • Problem Starvation – low priority processes may never execute • Solution  Aging– as time progresses increase the priority of the process

  35. Preemptive Scheduling • A running process can be interrupted when its time sliceexpires (round robin) • A running process can be interrupted when its remaining time is longer than the CPU burst of an arriving process shortestremaining time (SRTF) • Priority preemptive scheduling - A currently running process will be preempted if a higher-priority process arrives (PPS)

  36. Round Robin (RR) • Each process gets a small unit of CPU time (timequantumq), usually 10-100 milliseconds. After this time has elapsed, the process is preempted and added to the end of the ready queue. • If there are n processes in the ready queue and the time quantum is q, then each process gets 1/n of the CPU time in chunks of at most q time units at once. No process waits more than (n-1)q time units. • Timer interrupts every quantum to schedule next process • Performance • q large  FIFO • q small  q must be large with respect to context switch, otherwise overhead is too high

  37. Interrupts in Round Robin • RR scheduling is used in t-me sharing systems. It is the most common of the preemptive(Will have interruption) scheduling • When the executing interval of a process reaches the time quantum, the timer will cause the OS to interrupt the process • The OS carries out a context switch to the next selected process from the ready queue.

  38. Example of RR with Time Quantum (time slice) = 4 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

  39. Turnaround Time Varies With The Time Quantum (Time Slice) 80% of CPU bursts should be shorter than q

  40. Example with Round Robin The chart for Round-Robin, with Quantum =40 msec., is: The average waiting time is: (0 + 40 + 80 + 120 + 160)/5 = 80 msec.

  41. Evaluation of CPU Schedulers by Simulation

  42. Scheduling Algorithm Evaluation • Criteria for evaluation, and measure performance of the computer system • Maximize CPU utilization under certain constraints • Minimize response time • Maximize throughput under certain constraints • Analytic evaluation - use algorithm and system workload • Deterministic modeling • Queuing models • Simulation - involves programming a model of the computer system

  43. Example 3 Scheduling Assume the following processes P1,P2, P3, P4 and P5 arrive at 1, 2, 4, 5, 5 respectively. The CPU burst and the priority assigned to each process are: P1: 45 3 P2: 5 5 P3: 15 2 P4: 20 1 P5: 25 4 For FCFS, RR, SJF and PR scheduling, determine a) the turnaround time for every process, b) waiting time for every process and the average waiting time, c) throughput for the system. Use a time quantum of 10 time units, and negligible context time.

  44. Heuristic Algorithm • Allocate the CPU to the highest priority process. • When a process is selected for execution, assign it a time-slice. • If the process requests an I/O operation before the time-slice expires, raise its priority (i.e. assume it will carry out another I/O request soon) • If the time-slice expires, lower its priority (i.e., assume it is now in a CPU burst) and allocate the CPU to the highest priority ready process.

  45. Real-Time Scheduling Policies • These scheduling policies attempt to maintain the CPU allocated to the high-priority real-time processes. • One of the goals for this kind of scheduling is to guarantee fast response of the real-time processes.

More Related