Chapter 5: CPU Scheduling

Slides:



Advertisements
Similar presentations
CPU Scheduling.
Advertisements

Scheduling Algorithms
Chap 5 Process Scheduling. Basic Concepts Maximum CPU utilization obtained with multiprogramming CPU–I/O Burst Cycle – Process execution consists of a.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Chapter 6: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 6: CPU Scheduling Basic.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5-CPU Scheduling
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Basic Concepts Maximum CPU utilization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of SJF ProcessArrival TimeBurst Time P P P
Silberschatz, Galvin, and Gagne  Applied Operating System Concepts Module 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
Chapter 5: Process Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Basic Concepts Maximum CPU utilization can be obtained.
1 11/29/2015 Chapter 6: CPU Scheduling l Basic Concepts l Scheduling Criteria l Scheduling Algorithms l Multiple-Processor Scheduling l Real-Time Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 2, 2005 Chapter 5: CPU Scheduling Basic.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 5 CPU Scheduling Slide 1 Chapter 5 CPU Scheduling.
6.1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
1 Module 5: Scheduling CPU Scheduling Scheduling Algorithms Reading: Chapter
Basic Concepts Maximum CPU utilization obtained with multiprogramming
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5: Process Scheduling
lecture 5: CPU Scheduling
CPU SCHEDULING.
Chapter 6: CPU Scheduling
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
EEE Embedded Systems Design Process in Operating Systems 서강대학교 전자공학과
Chapter 5a: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Outline Scheduling algorithms Multi-processor scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
Shortest-Job-First (SJR) Scheduling
Chapter 6: CPU Scheduling
Topic 5 (Textbook - Chapter 6) CPU Scheduling
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria(기준, 척도) Scheduling Algorithms Multiple-Processor Scheduling Thread Scheduling Operating Systems Examples Algorithm Evaluation

Levels of Scheduling Running Ready Blocked Short Term Blocked, Suspend Ready, Suspend Medium Term New Exit Long Term

Levels of Scheduling Long-term Scheduling Long term scheduling is performed when a new process is created Medium-term Scheduling Medium-term scheduling is a part of the swapping function Short-term Scheduling Short-term scheduler is invoked whenever an event occurs, that may lead to the interruption of the current running process. For example clock interrupts, I/O interrupts, operating system calls, signals, etc.

Basic Concepts Goal of processor scheduling Burst (time) Maximum CPU utilization(활용) obtained with multiprogramming Burst (time) CPU Burst : Time it takes for the CPU to execute an operation(작업) I/O Burst : Time it takes for the CPU to wait for I/O task CPU–I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait CPU excution(CPU burst) I/O wait(I/O burst) Two types of CPU burst CPU bound program I/O bound program CPU burst distribution

Basic Concepts CPU burst vs I/O burst

Alternating Sequence of CPU And I/O Bursts Foreground jobs (interactive) – keyboard/mouse Background jobs (batch – no human interaction) I/O bound jobs CPU priority : I/O bound > CPU bound Compute-bound(CPU bound) jobs

Histogram of CPU-burst Times 4 2 1 milliseconds = 1/1000 second Short CPU burst I/O-oriented program would have a lot of short CPU bursts. Long CPU burst CPU-oriented program would be able to have many long CPU bursts.

Scheduling Case A – Total amount of work changes 1 3 Case A – Total amount of work changes (more Throughput(처리량)) disk scheduling Postman scheduling Case B – Total amount of work is not affected (no Throughput change) (Response time distribution changes) CPU scheduling, cafeteria line, bus line For case B If homogeneous(동종의) jobs? – no need to do scheduling If heterogeneous(이종의) jobs – scheduling needed eg – some jobs are I/O bound jobs, others are CPU bound jobs terminal (foreground) jobs, realtime jobs, batch jobs 5 4 6 2 1 3 10 14 13 10 3 10 1 14 11 1 10 3 1 Operating System Concepts

CPU Scheduler Multiprogramming environment CPU Scheduler selects processes in memory that are ready to execute, and allocates the CPU to one of them. CPU scheduling decisions may take place when a process: 1. Switches from running to waiting state. (eg I/O request) 2. Switches from running to ready state. (eg timerunout) 3. Switches from waiting to ready. (eg I/O finished interrupt) 4. Terminates. Scheduling under 1 and 4 is non-preemptive. ex) Nonpreemptible resource - printer, tape, … All other scheduling is preemptive. ex) Preemptible resource - CPU (both are applicable) Operating System Concepts

Dispatcher Dispatcher module 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 and restarting the program. Dispatch latency time which it takes for the dispatcher to stop one process and start another running. have to be short. (context switch overhead is the majority) Operating System Concepts

Scheduling Criteria (Performance Index) CPU utilization(이용률) keep the CPU as busy as possible Throughput(처리율) number of processes that complete their execution per time unit 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 completion of output (for time-sharing environment) Operating System Concepts

Scheduling Algorithms Criteria : Average waiting time Single processor algorithm First-Come, First-Served Scheduling Shortest-Job-First Scheduling Priority Scheduling Round-Robin Scheduling Multilevel Queue Scheduling Multilevel Feedback Queue Thread scheduling Multiple-Processor Scheduling Realtime Scheduling EDF (Earliest Deadline First) Rate Monotonic Rate Monotonic vs. EDF Examples Solaris 2 Scheduling, Windows XP Scheduling, Linux Scheduling Operating System Concepts

First-Come, First-Served (FCFS) Process Burst Time P1 24 P2 3 P3 3 Suppose that the processes arrive in the order: P1 , P2 , P3 Waiting time P1 = 0, P2 = 24, P3 = 27 Average waiting time: (0 + 24 + 27)/3 = 17 51 / 3 = 17 Convoy effect : short process behind long process P1 P2 P3 24 27 30

FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P2 , P3 , P1 The Gantt chart for the schedule is: Waiting time P1 = 6, P2 = 0, P3 = 3 Average waiting time: (6 + 0 + 3)/3 = 3 Much better than previous case. Process Burst Time P1 24 P2 3 P3 3 P2 P3 P1 3 6 30 (0 + 24 + 27)/3 = 17 P1: KT telephone bill prcoessing – hours P2, P3: KT homepage click – 1 second Operating System Concepts

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. Two approaches: Non-preemptive once CPU given to the process it cannot be preempted until completes its CPU burst. Preemptive if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is known as the Shortest-Remaining-Time-First (SRTF). SJF is optimal gives minimum average waiting time for a given set of processes. Demerit of SJF : Starvation Operating System Concepts

Example of Non-Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (non-preemptive) Average waiting time = (0 + 6 + 3 + 7)/4 = 4 P3 (1) P2 (4) P1 (7) P4 (4) P1 P3 P2 P4 3 7 8 12 16 (0-0, 8-2, 7-4, 12-5) Operating System Concepts

Example of Preemptive SJF Process Arrival Time Burst Time P1 0.0 7 P2 2.0 4 P3 4.0 1 P4 5.0 4 SJF (preemptive) Average waiting time = (9 + 1 + 0 +2)/4 = 3 -2 -5 -2 -2 -1 -4 But how do you know this at the process arrival time? Estimate? P1 P2 P3 P2 P4 P1 (7-2) (4-2) (1-1) (2-2) (4-4) (5-5) P1 P3 P2 4 2 11 P4 5 7 16 P1 : (0-0)+(11-2) = 9 P2 : (2-2)+(5-4)=1 P3 : (4=4) = 0 P4 : (7-5) = 2 Operating System Concepts

Determining Length of Next CPU Burst But how do you know the length of next CPU burst? (input data, branch, user …) Can only estimate the length. Can be done by using the length of previous CPU bursts, using exponential averaging(지수평균).  : taf, 타우 : Define 4. 1 , 3. burst CPU next the for value predicted 2. of lenght actual 1. £ = + a t n th Operating System Concepts

Examples of Exponential Averaging Define : Prediction of the Length of the Next CPU Burst t=0, t=1, t=2, t=3,

Priority Scheduling SJF (Shortest-Job-First) A priority number(integer) is associated with process The CPU is allocated to the process with the highest priority (smallest integer  highest priority). Preemptive nonpreemptive SJF is a priority scheduling where priority is the predicted next CPU burst time. Problem Starvation: low priority processes may never execute. Solution Aging: as time progresses increase the priority Operating System Concepts

Round Robin (RR) Time quantum expired Each process gets a small unit of CPU time (time quantum, slice), 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 the time quantum (slice) is q sec, then each process gets 1/n of CPU time in chunks of at most q sec at once.  No process waits more than (n-1)q sec. -- short job – after (n-1)q sec Waiting time is proportional(비례하는) to it’s own execution time Performance: q large  FIFO (good for compute bound jobs) q small  q must be large with respect to context switch, (문맥전환이 빈번해짐) otherwise overhead is too high. (good for I/O bound jobs & realtime jobs) Single q value cannot satisfy both  multilevel feedback queue Operating System Concepts

Example of RR with Time Quantum = 4 Process Burst Time P1 24 P2 3 P3 3 The Gantt chart is: Average waiting time : (6+4+7)/3 = 5.66 in case of SJF=3 Average turnaround time : (30+7+10)/3 = 15.6 in case of SJF=3 Typically, higher average turnaround than SJF, but better response P1 P2 P3 4 7 10 14 18 22 26 30

Example of RR with Time Quantum = 20 Process Burst Time P1 53 P2 17 P3 68 P4 24 The Gantt chart is: -20 -20 -13 -17 -20 -20 -20 -8 -20 -4 P1 P2 P3 P4 20 37 57 77 97 117 121 134 154 162

Time Quantum and Context Switch Time

Turnaround Time vs. Time Quantum At Q=5, averageTurnaround time = (15 + 8 + 9 + 17) / 4 = 12.25

Multilevel Queue Ready queue is partitioned into separate queues: foreground (interactive) background (batch – no human interaction) Each queue has its own scheduling algorithm eg: foreground (interative) queue -- RR background (batch) queue -- FCFS Scheduling must be done between the queues. Fixed priority scheduling serve all from foreground  then serve from background. Possibility of starvation. Time slice each queue gets a certain amount of CPU time which it can schedule amongst its processes Eg., 80% to foreground in RR, 20% to background in FCFS Operating System Concepts

Multilevel Queue Scheduling

Multilevel Feedback Queue A process can move between the various queues; aging can be implemented this way. Multilevel-feedback-queue scheduler defined by the following parameters: number of queues scheduling algorithms for each queue method used to determine when to upgrade a process method used to determine when to demote a process method used to determine which queue a process will enter when that process needs service Operating System Concepts

Example of Multilevel Feedback Queue Three queues: Q0 – time quantum 8 milliseconds Q1 – time quantum 16 milliseconds Q2 – FCFS Scheduling A new job enters queue Q0 which is served FCFS. When it gains CPU, job receives 8 milliseconds. If it does not finish in 8 milliseconds, job is moved to queue Q1. At Q1 job is again served FCFS and receives 16 additional ms. If it still does not complete, it is preempted and moved to queue Q2. Lower level queue executes only when higher level queues are empty at all time(preemptive) Q0 Q1 Q2 Operating System Concepts

Thread Scheduling Two types of thread scheduling User Level : process local scheduling How the threads library decides which thread to put onto an available LWP Kernel Level : system global scheduling How the kernel decides which kernel thread to run next

Pthread Scheduling API for POSIX #include <pthread.h> #include <stdio.h> #define NUM_THREADS 5 int main(int argc, char *argv[]) { int I, scope; pthread_t tid[NUM_THREADS]; pthread_attr_t attr; /* get the default attributes */ pthread_attr_init(&attr); /* first inquire on the current scope */ if (pthread_attr_getscope(&attr, &scope) != 0) printf(stderr, “Unable to get scheduling scope\n”); else { if (scope == PTHREAD_SCOPE_PROCESS) pritnf(“PTHREAD_SCOPE_PROCESS”); else if (scope == PTHREAD_SCOPE_SYSTEM) pritnf(“PTHREAD_SCOPE_SYSTEM”); else printf(stderr,”Illegal scope value.\n”); } /* set the scheduling algorithm to PCS(PROCESS) or (SCS)SYSTEM */ pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); /* set the scheduling policy - FIFO, RR, or OTHER pthread_attr_setschedpolicy(&attr, SCHED OTHER); */ /* create the threads */ for (i = 0; i < NUM_THREADS; i++) pthread_create(&tid[i],&attr,runner,NULL); /* now join on each thread */ pthread_join(tid[i], NULL); } /* Each thread will begin control in this function */ void *runner(void *param) { /* do some work */ printf("I am a thread\n"); pthread exit(0); pthread scheduling process-contention scope; PCS : user-level thread system-contention scope; CSC : kernel-level thread

Multiple-Processor Scheduling CPU scheduling more complex when multiple CPUs are available. Homogeneous(동종) processors within a multiprocessor. Load sharing(부하공유) Asymmetric multiprocessing(AMP) only one processor(master) accesses the system data structures, alleviating(완화하다) the need for data sharing. Symmetric Multiprocessing (SMP) each processor makes its own scheduling decisions. Operating System Concepts

Processor affinity(친화성) Processor affinity refers to binding a process or a set of processes to a specific CPU or a set of CPUs Override the system’s built-in scheduler to force a process to only run on specified CPUs. soft affinity hard affinity This can provide some performance gains in SMP and NUMA environments.

NUMA and CPU Scheduling NUMA(Non-Uniform Memory Access and CPU Scheduling

Multithread multicore system Multiple-Processors Recent trend to place multiple processor cores on same physical chip Faster and consume less power Multiple threads per core also growing Takes advantage of memory stall to make progress on another thread while memory retrieve happens Memory stall Multithread multicore system

Operating System Examples Solaris scheduling Windows XP scheduling Linux scheduling

Solaris 2 Scheduling

Solaris Dispatch Table Low High

Variable class : priority 1 to 15 Real-time class : priority 16 - 31 Windows XP Priorities Variable class : priority 1 to 15 Real-time class : priority 16 - 31

Priorities and Time-slice length

List of Tasks Indexed According to Priorities Linux Scheduling(Linux kernel 2.5) List of Tasks Indexed According to Priorities

Algorithm Evaluation Deterministic modeling – takes a particular predetermined workload and defines the performance of each algorithm for that workload Queueing models Simulation Implementation

Deterministic Modeling P1, …,P5 = (10, 29, 3, 7, 12) FCFS SJF RR

Evaluation by simulation

End of Chapter 5