Operating Systems Lecture 14.

Slides:



Advertisements
Similar presentations
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Advertisements

Operating Systems CPU Scheduling. Agenda for Today What is Scheduler and its types Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization.
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.
02/04/2008CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 5-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.
1 Wednesday, June 14, 2006 "Beware of bugs in the above code; I have only proved it correct, not tried it." - Donald Knuth.
Modified from Silberschatz, Galvin and Gagne ©2009 Lecture 8 Chapter 5: CPU Scheduling.
CSCI 315 Operating Systems Design1 Introduction to CPU Scheduling Notice: The slides for this lecture have been largely based on those from the course.
CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Thread Scheduling Multiple-Processor Scheduling Operating Systems Examples Algorithm.
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.
CS333 Intro to Operating Systems Jonathan Walpole.
Purpose of Operating System Part 2 Monil Adhikari.
CPU Scheduling CSCI Introduction By switching the CPU among processes, the O.S. can make the system more productive –Some process is running at.
1 Module 5: Scheduling CPU Scheduling Scheduling Algorithms Reading: Chapter
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
CPU Scheduling CSSE 332 Operating Systems
Chapter 6: CPU Scheduling
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Chapter 5a: CPU Scheduling
CS399 New Beginnings Jonathan Walpole.
Chapter 5: CPU Scheduling
Operating Systems Processes Scheduling.
CPU scheduling 6. Schedulers, CPU Scheduling 6.1. Schedulers
Scheduling (Priority Based)
Chapter 5: CPU Scheduling
CPU Scheduling.
Chapter 6: CPU Scheduling
Chapter 6: CPU Scheduling
Process management Information maintained by OS for process management
Operating Systems Lecture 13.
Chapter 5: CPU Scheduling
CPU Scheduling Basic Concepts Scheduling Criteria
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Operating Systems Lecture 15.
Operating System Concepts
Chapter 5: CPU Scheduling
So far…. Firmware identifies hardware devices present
3: CPU Scheduling Basic Concepts Scheduling Criteria
CS510 Operating System Foundations
Chapter5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Operating System Concepts
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Q:何謂 CPU BURST與 I/O BURST?
Operating System , Fall 2000 EA101 W 9:00-10:00 F 9:00-11:00
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Topic 5 (Textbook - Chapter 6) CPU Scheduling
Module 5: CPU Scheduling
CPU Scheduling: Basic Concepts
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
CPU Scheduling.
CPU Scheduling: Basic Concepts
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

Operating Systems Lecture 14

© Copyright Virtual University of Pakistan Agenda for Today Review of previous lecture Short-term scheduler Dispatcher Reasons for invoking scheduler Optimization criteria FCFS, SJF, and SRTF 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Review of Lecture 13 Single and multi-threaded processes Thread models User- and kernel-level threads Pthreads library Sample multi-threaded code 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example 1 #include <stdio.h> #include <stdlib.h> #include <pthread.h> /* Prototype for a function to be passed to our thread */ void* MyThreadFunc(void *arg); int main() { pthread_t aThread; /* Create a thread and have it run the MyThreadFunction */ pthread_create(&aThread, NULL, MyThreadFunc, NULL); /* Parent waits for the aThread thread to exit */ pthread_join(aThread, NULL); printf ("Exiting the main function.\n"); return 0; } 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example 1 void* MyThreadFunc(void* arg) { printf ("Hello, world! ... The threaded version.\n"); return NULL; } $ gcc hello.c –o hello –lpthread –D_REENTRANT $ hello Hello, world! ... The threaded version. Exiting the main function. $ 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example 2 #include <pthread.h> #include <stdio.h> #define NUM_THREADS 5 void *PrintHello(void *threadid) { printf("\n%d: Hello World!\n", threadid); pthread_exit(NULL); } 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Example 2 int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc, t; for (t=0; t < NUM_THREADS; t++) { printf("Creating thread %d\n", t); rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t); if (rc) { printf("ERROR; return code is %d\n", rc); exit(-1); } pthread_exit(NULL); 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan CPU Scheduling Scheduling processes in the ready queue Short-term scheduler Different types of schedulers 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Life of a Process 2 December 2018 © Copyright Virtual University of Pakistan

Histogram of CPU-burst Times 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan CPU Scheduler Short-term scheduler Selects a process from among the processes in the ready queue Invokes the dispatcher to have the CPU allocated to the selected process 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Dispatcher Dispatcher 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 start (or restart) it 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Dispatcher Dispatch latency – time it takes for the dispatcher to stop one process and start another running. Typically, a few microseconds 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan CPU Scheduler CPU scheduling decisions may take place when a process: Switches from running to waiting state Switches from running to ready state Switches from waiting to ready Terminates 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan CPU Scheduler Scheduling under 1 and 4 is nonpreemptive. All other scheduling is preemptive. 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan 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 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Scheduling Criteria 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) 2 December 2018 © Copyright Virtual University of Pakistan

Optimization Criteria Maximize CPU utilization Maximize throughput Minimize turnaround time Minimize waiting time Minimize response time 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FCFS Scheduling The process that enters the ready queue first is scheduled first, regardless of the size of its next CPU burst Example: Process Burst Time P1 24 P2 3 P3 3 Suppose that processes arrive into the system in the order: P1, P2 , P3 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FCFS Scheduling Processes are served in the order: P1, P2, P3 The Gantt Chart for the schedule is: Waiting times P1 = 0; P2 = 24; P3 = 27 Average waiting time: (0+24+27)/3 = 17 P1 P2 P3 24 27 30 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan FCFS Scheduling Suppose that 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 Convoy effect short process behind long process P1 P3 P2 6 3 30 2 December 2018 © Copyright Virtual University of Pakistan

© Copyright Virtual University of Pakistan Recap of Lecture Short-term scheduler Examples of Pthreads Dispatcher Reasons for invoking scheduler Optimization criteria FCFS 2 December 2018 © Copyright Virtual University of Pakistan