CSE 4/521 Introduction to Operating Systems

Similar documents
Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling

CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. Dispatcher. CPU Scheduler. Alternating Sequence of CPU and I/O Bursts

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 5: CPU Scheduling. Operating System Concepts 8 th Edition,

Chapter 6: CPU Scheduling

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts Essentials 8 th Edition

Properties of Processes

Chapter 5: Process Scheduling

CPU Scheduling (Part II)

Chapter 5: CPU Scheduling

CPU Scheduling Algorithms

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 6: CPU Scheduling. Operating System Concepts 9 th Edition

Chapter 5: Process Scheduling

CS307: Operating Systems

Chapter 6: CPU Scheduling

Chapter 5 CPU scheduling

Round Robin (RR) ACSC 271 Operating Systems. RR Example. RR Scheduling. Lecture 9: Scheduling Algorithms

Job Scheduling. CS170 Fall 2018

Chapter 5: CPU Scheduling

Chapter 5: CPU Scheduling. Operating System Concepts 9 th Edit9on

CPU Scheduling. Daniel Mosse. (Most slides are from Sherif Khattab and Silberschatz, Galvin and Gagne 2013)

Chapter 5 Process Scheduling

Lecture 5 / Chapter 6 (CPU Scheduling) Basic Concepts. Scheduling Criteria Scheduling Algorithms

Operating Systems CS 323 Ms. Ines Abbes

CS370 Operating Systems

CPU Scheduling. Operating Systems (Fall/Winter 2018) Yajin Zhou ( Zhejiang University

CPU Scheduling: Objectives

Chapter 5 Scheduling

OPERATING SYSTEMS CS3502 Spring Processor Scheduling. Chapter 5

CS370 Operating Systems

Scheduling. Today. Next Time Process interaction & communication

CS370 Operating Systems

CHAPTER 2: PROCESS MANAGEMENT

Operating System Concepts Ch. 5: Scheduling

LECTURE 3:CPU SCHEDULING

TDIU25: Operating Systems II. Processes, Threads and Scheduling

CS370 Operating Systems

Practice Exercises 305

Last class: Today: CPU Scheduling. CPU Scheduling Algorithms and Systems

Titolo presentazione. Scheduling. sottotitolo A.Y Milano, XX mese 20XX ACSO Tutoring MSc Eng. Michele Zanella

3. CPU Scheduling. Operating System Concepts with Java 8th Edition Silberschatz, Galvin and Gagn

CPU Scheduling. CSE 2431: Introduction to Operating Systems Reading: Chapter 6, [OSC] (except Sections )

Lecture 2 Process Management

CPU Scheduling. Rab Nawaz Jadoon. Assistant Professor DCS. Pakistan. COMSATS, Lahore. Department of Computer Science

Ch 4 : CPU scheduling

Process- Concept &Process Scheduling OPERATING SYSTEMS

So far. Next: scheduling next process from Wait to Run. 1/31/08 CSE 30341: Operating Systems Principles

Preview. Process Scheduler. Process Scheduling Algorithms for Batch System. Process Scheduling Algorithms for Interactive System

Chapter 19: Real-Time Systems. Operating System Concepts 8 th Edition,

Scheduling of processes

CS3733: Operating Systems

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

CSC Operating Systems Spring Lecture - XII Midterm Review. Tevfik Ko!ar. Louisiana State University. March 4 th, 2008.

Processes and Threads

COSC243 Part 2: Operating Systems

1.1 CPU I/O Burst Cycle

Start of Lecture: February 10, Chapter 6: Scheduling

Process Concept Process in Memory Process State new running waiting ready terminated Diagram of Process State

York University Lassonde School of Engineering Department of Electrical Engineering and Computer Science

Course Syllabus. Operating Systems

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Uniprocessor Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Three level scheduling

CISC 7310X. C05: CPU Scheduling. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/1/2018 CUNY Brooklyn College

ALL the assignments (A1, A2, A3) and Projects (P0, P1, P2) we have done so far.

Operating Systems. Lecture Process Scheduling. Golestan University. Hossein Momeni

Operating Systems Unit 3

CPU Scheduling. Schedulers. CPSC 313: Intro to Computer Systems. Intro to Scheduling. Schedulers in the OS

Chap 7, 8: Scheduling. Dongkun Shin, SKKU

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

CPU Scheduling: Part I ( 5, SGG) Operating Systems. Autumn CS4023

8: Scheduling. Scheduling. Mark Handley

Uniprocessor Scheduling. Aim of Scheduling

Uniprocessor Scheduling. Aim of Scheduling. Types of Scheduling. Long-Term Scheduling. Chapter 9. Response time Throughput Processor efficiency

by Maria Lima Term Paper for Professor Barrymore Warren Mercy College Division of Mathematics and Computer Information Science

Operating Systems ECE344. Ding Yuan

Lecture Topics. Announcements. Today: Uniprocessor Scheduling (Stallings, chapter ) Next: Advanced Scheduling (Stallings, chapter

Scheduling. The Basics

Scheduling. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Process interaction & communication

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Assignment 3 (Due date: Thursday, 10/15/2009, in class) Part One: Provide brief answers to the following Chapter Exercises questions:

Uniprocessor Scheduling. Chapter 9

Lecture 17: Threads and Scheduling. Thursday, 05 Nov 2009

Operating Systems. Scheduling

Operating Systems: Quiz2 December 15, Class: No. Name:

Announcements. Program #1. Program #0. Reading. Is due at 9:00 AM on Thursday. Re-grade requests are due by Monday at 11:59:59 PM.

CPU Scheduling. The scheduling problem: When do we make decision? - Have K jobs ready to run - Have N 1 CPUs - Which jobs to assign to which CPU(s)

Last Class: Processes

CSE120 Principles of Operating Systems. Prof Yuanyuan (YY) Zhou Scheduling

OPERATING SYSTEMS. COMS W1001 Introduction to Information Science. Boyi Xie

CPU scheduling. Alternating sequence of CPU and I/O bursts. P a g e 31

CPU Scheduling (1) CPU Scheduling (Topic 3) CPU Scheduling (2) CPU Scheduling (3) Resources fall into two classes:

Unit 3 : Process Management

Maximum CPU utilization obtained with multiprogramming. CPU I/O Burst Cycle Process execution consists of a cycle of CPU execution and I/O wait

Chapter 9. Uniprocessor Scheduling

CSE 120 Principles of Operating Systems Spring 2017

Transcription:

CSE 4/521 Introduction to Operating Systems Lecture 9 CPU Scheduling II (Scheduling Algorithms, Thread Scheduling, Real-time CPU Scheduling) Summer 2018

Overview Objective: 1. To describe priority scheduling and round-robin scheduling algorithm 2. To study options provided by Pthreads thread scheduling library. 3. To examine how real-time scheduling works Scheduling Algorithms Thread Scheduling Real-Time CPU Scheduling 2

Recap Basic Concepts CPU burst and I/O burst, CPU Scheduler Scheduling Criteria 5 criteria CPU utilization, Throughput, Turnaround time, Waiting time, Response time Scheduling Algorithms First-come-first-serve, Shortest-Job-First 3

Questions 1. What does each of the 6 scheduling criteria mean? Which needs to be maximized and minimized? (Easy) 2. Since the time period of the future is not known, how to guess the CPU burst time in SJF? (Medium) 3. Which of 2 scheduling algorithm lead to starvation? Or deadlock? [Difference between deadlock and starvation] (Hard) 4

Overview Scheduling Algorithms Thread Scheduling Real-Time CPU Scheduling 5

Overview Scheduling Algorithms Thread Scheduling Real-Time CPU Scheduling 6

Scheduling Algorithms 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 Problem = Starvation low priority processes may never execute Solution = Aging as time progresses increase the priority of the process 7

Scheduling Algorithms Example of Priority Scheduling ProcessA arri Burst TimeT Priority P 1 10 3 P 2 1 1 P 3 2 4 P 4 1 5 P 5 5 2 Priority scheduling Gantt Chart Average waiting time = 8.2 msec 8

Scheduling Algorithms Round-Robin Each process gets a small unit of CPU time (time quantum q). After 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. Performance: q large Þ FIFO q small Þ q must be large with respect to context switch, otherwise overhead is too high 9

Scheduling Algorithms Example of Round-Robin Process Burst Time P 1 24 P 2 3 P 3 3 The Gantt chart is: q = 4 P P 2 P 3 P 1 P 1 P 1 P P 1 1 1 0 4 7 10 14 18 22 26 30 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 10

Scheduling Algorithms Round-Robin Concerns 80% of CPU bursts should be shorter than q 11

Scheduling Algorithms Multilevel Queue Ready queue is partitioned into separate queues, eg: foreground (interactive) background (batch) Process permanently put into a queue Each queue has its own scheduling algorithm: foreground RR background FCFS Scheduling must be done between the queues: Time slice each queue gets a certain amount of CPU time, i.e., 80% to foreground in RR, 20% to background in FCFS 12

Scheduling Algorithms Multilevel Queue 13

Scheduling Algorithms Multilevel Feedback Queue A process can move between the 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 14

Scheduling Algorithms Example of Multilevel Feedback Queue Three queues: Q 0 RR with time quantum 8 milliseconds Q 1 RR time quantum 16 milliseconds Q 2 FCFS Scheduling: A new job enters queue Q 0 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 Q 1 At Q 1 job is again served FCFS and receives 16 additional milliseconds If it still does not complete, it is preempted and moved to queue Q 2 15

Overview Scheduling Algorithms Thread Scheduling Real-Time CPU Scheduling 16

Thread Scheduling Many-to-one and many-to-many models, thread library schedules user-level threads to run in kernel: Two methods: Process-contention scope (PCS) : Scheduling competition between threads of same process System-contention scope (SCS) Scheduling competition among all threads in system 17

Thread Scheduling - Pthreads #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) fprintf(stderr, "Unable to get scheduling scope\n"); else { if (scope == PTHREAD_SCOPE_PROCESS) printf("pthread_scope_process"); else if (scope == PTHREAD_SCOPE_SYSTEM) printf("pthread_scope_system"); else fprintf(stderr, "Illegal scope value.\n"); } /* set the scheduling algorithm to PCS or SCS */ pthread_attr_setscope(&attr,pthread_scope_system); /* create the threads */ for (i = 0; i < NUM_THREADS; i++) pthread_create(&tid[i],&attr,runner,null); /* now join on each thread */ for (i = 0; i < NUM_THREADS; i++) pthread_join(tid[i], NULL); } /* Each thread will begin control in this function */ void *runner(void *param) { /* do some work... */ pthread_exit(0); } 18

Overview Scheduling Algorithms Thread Scheduling Real-Time CPU Scheduling 19

Real-Time CPU Scheduling Can present obvious challenges Soft real-time systems no guarantee as to when critical real-time process will be scheduled Hard real-time systems task must be serviced by its deadline Two types of latencies affect performance 1. Interrupt latency time from arrival of interrupt to start of routine that services interrupt 2. Dispatch latency time for scheduler to take current process off CPU and switch to another 20

Real-Time CPU Scheduling Conflict phase of dispatch latency: 1.Preemption of any process running in kernel mode 2.Release by low-priority process of resources needed by high-priority processes event interrupt processing process made available conflicts response interval dispatch latency dispatch response to event real-time process execution time 21

Real-Time CPU Scheduling : Priority-based Scheduling For real-time scheduling, scheduler must support preemptive, prioritybased scheduling But only guarantees soft real-time For hard real-time must also provide ability to meet deadlines Processes have new characteristics: periodic ones require CPU at constant intervals Has processing time t, deadline d, period p 0 t d p Rate of periodic task is 1/p 22

Real-Time CPU Scheduling : Rate Monotonic Scheduling A priority is assigned based on the inverse of its period Shorter periods = higher priority; Longer periods = lower priority P 1 is assigned a higher priority than P 2. P1 = 50 P2 = 100 t1 = 20 t2 = 35 Deadline is to complete before next period 23

Real-Time CPU Scheduling : Missed Deadlines with Rate Monotonic Scheduling P1 = 50 P2 = 80 t1 = 25 t2 = 35 Deadline is to complete before next period There is no pre-emption in Rate Monotonic Scheduling 24

Real-Time CPU Scheduling: Earliest Deadline First Scheduling (EDF) Priorities are assigned according to deadlines: The earlier the deadline, the higher the priority The later the deadline, the lower the priority P1 = 50 P2 = 80 t1 = 25 t2 = 35 Deadline is to complete before next period 25

Credits for slides Silberschatz, Galvin and Gagne 26