1 Wednesday, June 14, 2006 "Beware of bugs in the above code; I have only proved it correct, not tried it." - Donald Knuth.

Slides:



Advertisements
Similar presentations
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 5: CPU Scheduling.
Advertisements

Operating Systems Chapter 6
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.
Operating Systems CPU Scheduling. Agenda for Today What is Scheduler and its types Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization.
CPU Scheduling CS 3100 CPU Scheduling1. Objectives To introduce CPU scheduling, which is the basis for multiprogrammed operating systems To describe various.
Chapter 3: CPU Scheduling
Cs238 CPU Scheduling Dr. Alan R. Davis.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
Scheduling in Batch Systems
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.
02/04/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
Chapter 5-CPU Scheduling
A. Frank - P. Weisberg Operating Systems CPU Scheduling.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 8 Chapter 5: CPU Scheduling.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria 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.
Chapter 6: CPU Scheduling
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.
Scheduling. Alternating Sequence of CPU And I/O Bursts.
Silberschatz and Galvin  Operating System Concepts Module 5: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor.
Alternating Sequence of CPU And I/O Bursts. Histogram of CPU-burst Times.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 15 Scheduling Read Ch.
CE Operating Systems Lecture 7 Threads & Introduction to 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.
Purpose of Operating System Part 2 Monil Adhikari.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
1 Uniprocessor Scheduling Chapter 3. 2 Alternating Sequence of CPU And I/O Bursts.
Chapter 4 CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling Algorithm Evaluation.
Lecture 4 CPU scheduling. Basic Concepts Single Process  one process at a time Maximum CPU utilization obtained with multiprogramming CPU idle :waiting.
CPU Scheduling G.Anuradha Reference : Galvin. CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
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.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
1 Chapter 5: CPU Scheduling. 2 Basic Concepts Scheduling Criteria Scheduling Algorithms.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 6: CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms.
CPU Scheduling CSSE 332 Operating Systems Rose-Hulman Institute of Technology.
lecture 5: CPU Scheduling
Chapter 6: CPU Scheduling
So far…. Firmware identifies hardware devices present
Chapter5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
CPU Scheduling: Basic Concepts
CPU Scheduling.
CPU Scheduling: Basic Concepts
Chapter 5: CPU Scheduling
Presentation transcript:

1 Wednesday, June 14, 2006 "Beware of bugs in the above code; I have only proved it correct, not tried it." - Donald Knuth

2 User level Threads §Thread switching does not require kernel mode privileges because all thread management data structures are within the user address space. Advantages §Saves overhead of two mode switches (user to kernel and kernel to user) §Scheduling can be application specific

3 User level Threads Disadvantages §When thread executes a blocking system call all threads in that process are blocked §Pure ULT systems cannot take advantage of multiprocessing

4 Kernel level Threads One to One Model: All thread management is done by kernel Scheduling is done on thread basis

5 Implementing Threads in the Kernel A threads package managed by the kernel

6 Kernel level Threads Advantages §Kernel can simultaneously schedule multiple threads from same process on multiple processors §A process with more threads can get more CPU time than a process with fewer threads

7 Kernel level Threads Disadvantages §Switching between threads is more time consuming compared to ULT

8 pthreads §POSIX standard §pthreads define API for thread creation and synchronization §Specification for behavior, not implementation §May be provided as user or kernel level library

9 int count_val=0; int main(void){ int t_ret; pthread_t threadID; char cidentity[30]="Child"; char pidentity[30]="Parent"; t_ret=pthread_create(&threadID, NULL, inc_counter, (void*)cidentity); inc_counter((void*)pidentity); return 0; } Threads

10 void* inc_counter(void* data){ char* threadname; int i; threadname = (char*)data; for(i=0;i<5; i++){ printf("%s counter is %d\n", threadname, count_val); (count_val)++; sleep(rand()%2); } pthread_exit(NULL); }

11 One possible output Parent counter is 0 Parent counter is 1 Parent counter is 2 Child counter is 3 Parent counter is 4 Child counter is 4 Parent counter is 6 Child counter is 7 Child counter is 8 Child counter is 9

12 pthread_join §joinable §Similar to zombie processes pthread_detach §If we want to let a thread exit whenever it wants to.

13 Thread Issues What if a thread calls fork()?

14 Thread Issues Thread cancellation §Concurrent search §Web browser § Asynchronous signals like Ctrl-C §Deferred Cancellation l Cancellation points §Signal Handling l Unix allows threads to specify which signals it will accept and which it will block

15 Thread Issues Private thread data

16 Scheduling Long term scheduling Short term scheduling

17 Scheduling §Long-term scheduler (or job scheduler) l Batch systems: processes are more than the resources available to execute them l selects which processes should be brought into the ready queue §Short-term scheduler (or CPU scheduler) – selects which process should be executed next and allocates CPU

18 Scheduling §Long-term scheduler (or job scheduler) l Controls degree of multiprogramming l Arrival vs departure rate l Executes less frequently l Good mix of CPU bound and I/O bound

19 Scheduling We will focus on short term scheduling §Unix and windows have no long term scheduler §New process is placed in the memory l Limits l Human nature

20 §Process §Thread CPU Scheduling

21 Alternating Sequence of CPU And I/O Bursts

22 Multiprogramming l Allow more than user at once. l Does machine now run N times slower? Not necessarily! l Key observation: users bursty. If one idle, give other resources.

23

24 Histogram of CPU-burst Times Based on measurements Processes tend to get more I/O bound with time

25 Scheduling Algorithm Goals

26 CPU Scheduler §Selects from among the 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. 2.Switches from running to ready state. 3.Switches from waiting to ready. 4.Terminates. §Scheduling under 1 and 4 is nonpreemptive. §All other scheduling is preemptive.

27 Dispatcher §Dispatcher module gives control of the CPU to the process selected by the short-term scheduler; this involves: l switching context l switching to user mode l 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.

28 Scheduling Criteria §CPU utilization – keep the CPU as busy as possible §Throughput – # 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 output (for time- sharing environment)

29 Optimization Criteria §Max CPU utilization §Max throughput §Min turnaround time §Min waiting time §Min response time

30 §Variance in response time

31 §Small examples for demonstration purposes

32 First-Come, First-Served (FCFS) Scheduling §Example:ProcessBurst Time P 1 24 P 2 3 P 3 3 §Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: P1P1 P2P2 P3P

33 P1P1 P2P2 P3P §Example:ProcessBurst Time P 1 24 P 2 3 P 3 3 §Suppose that the processes arrive in the order: P 1, P 2, P 3 The Gantt Chart for the schedule is: §Waiting time for P 1 = 0; P 2 = 24; P 3 = 27 §Average waiting time: ( )/3 = 17 First-Come, First-Served (FCFS) Scheduling

34 FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P 2, P 3, P 1. §The Gantt chart for the schedule is: P1P1 P3P3 P2P

35 FCFS Scheduling (Cont.) Suppose that the processes arrive in the order P 2, P 3, P 1. §The Gantt chart for the schedule is: §Waiting time for P 1 = 6; P 2 = 0 ; P 3 = 3 §Average waiting time: ( )/3 = 3 §Much better than previous case. §Convoy effect short process behind long process P1P1 P3P3 P2P

36 Shortest-Job-First (SJR) Scheduling §Associate with each process the length of its next CPU burst. Use these lengths to schedule the process with the shortest time. §Two schemes: l nonpreemptive – once CPU given to the process it cannot be preempted until completes its CPU burst. l Preemptive – if a new process arrives with CPU burst length less than remaining time of current executing process, preempt. This scheme is know as the Shortest-Remaining-Time-First (SRTF). §SJF is optimal – gives minimum average waiting time for a given set of processes.

37 ProcessArrival TimeBurst Time P P P P §SJF (non-preemptive) §Average waiting time = ( )/4 - 4 Example of Non-Preemptive SJF

38 ProcessArrival TimeBurst Time P P P P §SJF (non-preemptive) §Average waiting time = ( )/4 = 4 Example of Non-Preemptive SJF P1P1 P3P3 P2P P4P4 812

39 Example of Preemptive SJF ProcessArrival TimeBurst Time P P P P §SJF (preemptive) §Average waiting time = ( )/4 - 3

40 Example of Preemptive SJF ProcessArrival TimeBurst Time P P P P §SJF (preemptive) §Average waiting time = ( )/4 = 3 P1P1 P3P3 P2P P4P4 57 P2P2 P1P1 16

41