CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.

Slides:



Advertisements
Similar presentations
Operating Systems Lecture Notes Deadlocks Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Advertisements

Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
CPU Scheduling CPU Scheduler Performance metrics for CPU scheduling
Operating Systems ECE344 Ding Yuan Scheduling Lecture 10: Scheduling.
Chapter 5 CPU Scheduling. CPU Scheduling Topics: Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Deadlocks Andy Wang Operating Systems COP 4610 / CGS 5765.
Multi-Object Synchronization. Main Points Problems with synchronizing multiple objects Definition of deadlock – Circular waiting for resources Conditions.
Review: Chapters 1 – Chapter 1: OS is a layer between user and hardware to make life easier for user and use hardware efficiently Control program.
CS 3013 & CS 502 Summer 2006 Scheduling1 The art and science of allocating the CPU and other resources to processes.
OS Spring ’ 04 Scheduling Operating Systems Spring 2004.
OS Spring 2004 Concurrency: Principles of Deadlock Operating Systems Spring 2004.
OS Fall’02 Concurrency: Principles of Deadlock Operating Systems Fall 2002.
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
5: CPU-Scheduling1 Jerry Breecher OPERATING SYSTEMS SCHEDULING.
1 Concurrency: Deadlock and Starvation Chapter 6.
Wk 2 – Scheduling 1 CS502 Spring 2006 Scheduling The art and science of allocating the CPU and other resources to processes.
Job scheduling Queue discipline.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
 Scheduling  Linux Scheduling  Linux Scheduling Policy  Classification Of Processes In Linux  Linux Scheduling Classes  Process States In Linux.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 5 Operating Systems.
OPERATING SYSTEMS CPU SCHEDULING.  Introduction to CPU scheduling Introduction to CPU scheduling  Dispatcher Dispatcher  Terms used in CPU scheduling.
CS 153 Design of Operating Systems Spring 2015 Midterm Review.
1 Previous lecture review n Out of basic scheduling techniques none is a clear winner: u FCFS - simple but unfair u RR - more overhead than FCFS may not.
Lecture Topics: 11/13 Semaphores Deadlock Scheduling.
1 CSE451 Scheduling Autumn 2002 Gary Kimura Lecture #6 October 11, 2002.
1 Scheduling The part of the OS that makes the choice of which process to run next is called the scheduler and the algorithm it uses is called the scheduling.
Cpr E 308 Spring 2004 Real-time Scheduling Provide time guarantees Upper bound on response times –Programmer’s job! –Every level of the system Soft versus.
1 Announcements The fixing the bug part of Lab 4’s assignment 2 is now considered extra credit. Comments for the code should be on the parts you wrote.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Uniprocessor Scheduling
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CSE 153 Design of Operating Systems Winter 2015 Midterm Review.
CS333 Intro to Operating Systems Jonathan Walpole.
Processor Scheduling Hank Levy. 22/4/2016 Goals for Multiprogramming In a multiprogramming system, we try to increase utilization and thruput by overlapping.
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
Scheduling Algorithms : Important Aspects Minimize Response Time –Elapsed time to do an operation (job) –Response time is what the user sees Time to echo.
Deadlocks Mark Stanovich Operating Systems COP 4610.
Deadlocks.  Deadlocks: Occurs when threads are waiting for resources with circular dependencies Often involve nonpreemptable resources, which cannot.
1 CPU Scheduling Basic Concepts Scheduling Criteria Scheduling Algorithms Multiple-Processor Scheduling Real-Time Scheduling.
Silberschatz, Galvin and Gagne ©2009 Edited by Khoury, 2015 Operating System Concepts – 9 th Edition, Chapter 7: Deadlocks.
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.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
Lecturer 5: Process Scheduling Process Scheduling  Criteria & Objectives Types of Scheduling  Long term  Medium term  Short term CPU Scheduling Algorithms.
CS 153 Design of Operating Systems Winter 2016 Lecture 12: Scheduling & Deadlock.
Lecture 6 Deadlock 1. Deadlock and Starvation Let S and Q be two semaphores initialized to 1 P 0 P 1 wait (S); wait (Q); wait (Q); wait (S);. signal (S);
CPU Scheduling Scheduling processes (or kernel-level threads) onto the cpu is one of the most important OS functions. The cpu is an expensive resource.
CSE 120 Principles of Operating
Operating Systems Design (CS 423)
Applied Operating System Concepts -
Chapter 5a: CPU Scheduling
Chapter 2 Scheduling.
HW1 and Synchronization & Queuing
CPU Scheduling Basic Concepts Scheduling Criteria
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Operating System Concepts
Operating Systems.
CPU SCHEDULING.
Andy Wang Operating Systems COP 4610 / CGS 5765
CSE 451: Operating Systems Winter 2003 Lecture 6 Scheduling
SE350: Operating Systems Lecture 5: Deadlock.
CSE 153 Design of Operating Systems Winter 2019
CSE 153 Design of Operating Systems Winter 2019
CSE 542: Operating Systems
CSE 451: Operating Systems Winter 2001 Lecture 6 Scheduling
Presentation transcript:

CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock

2 Combining Algorithms l Scheduling algorithms can be combined u Have multiple queues u Use a different algorithm for each queue u Move processes among queues l Example: Multiple-level feedback queues (MLFQ) u Multiple queues representing different job types »Interactive, CPU-bound, batch, system, etc. u Queues have priorities, jobs on same queue scheduled RR u Jobs can move among queues based upon execution history »Feedback: Switch from interactive to CPU-bound behavior

Multi-level Feedback Queue (MFQ) l Goals: u Responsiveness u Low overhead u Starvation freedom u Some tasks are high/low priority u Fairness (among equal priority tasks) l Not perfect at any of them! u Used in Linux (and probably Windows, MacOS) 3

MFQ l Set of Round Robin queues u Each queue has a separate priority l High priority queues have short time slices u Low priority queues have long time slices l Scheduler picks first task in highest priority queue u If time slice expires, task drops one level 4

MFQ 5

6 Unix Scheduler l The canonical Unix scheduler uses a MLFQ u 3-4 classes spanning ~170 priority levels »Timesharing: first 60 priorities »System: next 40 priorities »Real-time: next 60 priorities »Interrupt: next 10 (Solaris) l Priority scheduling across queues, RR within a queue u The process with the highest priority always runs u Processes with the same priority are scheduled RR l Processes dynamically change priority u Increases over time if process blocks before end of quantum u Decreases over time if process uses entire quantum

7 Motivation of Unix Scheduler l The idea behind the Unix scheduler is to reward interactive processes over CPU hogs l Interactive processes (shell, editor, etc.) typically run using short CPU bursts u They do not finish quantum before waiting for more input l Want to minimize response time u Time from keystroke (putting process on ready queue) to executing keystroke handler (process running) u Don’t want editor to wait until CPU hog finishes quantum l This policy delays execution of CPU-bound jobs u But that’s ok

Multiprocessor Scheduling l This is its own topic, we wont go into it in detail u Could come back to it towards the end of the quarter l What would happen if we used MFQ on a multiprocessor? u Contention for scheduler spinlock u Multiple MFQ used – this optimization technique is called distributed locking and is common in concurrent programming l A couple of other considerations u Co-scheduling for parallel programs u Core affinity 8

Deadlock! 9

10 Deadlock—the deadly embrace! l Synchronization– we can easily shoot ourselves in the foot u Incorrect use of synchronization can block all processes u You have likely been intuitively avoiding this situation already l More generally, processes that allocate multiple resources generate dependencies on those resources u Locks, semaphores, monitors, etc., just represent the resources that they protect u If one process tries to access a resource that a second process holds, and vice-versa, they can never make progress l We call this situation deadlock, and we’ll look at: u Definition and conditions necessary for deadlock u Representation of deadlock conditions u Approaches to dealing with deadlock

Deadlock Definition l Resource: any (passive) thing needed by a thread to do its job (CPU, disk space, memory, lock) u Preemptable: can be taken away by OS u Non-preemptable: must leave with thread l Starvation: thread waits indefinitely l Deadlock: circular waiting for resources u Deadlock => starvation, but not vice versa lockA->Acquire(); … lockB->Acquire(); … lockA->Acquire(); Process 1Process 2 11

12 Deadlock Definition l Deadlock is a problem that can arise: u When processes compete for access to limited resources u When processes are incorrectly synchronized l Definition: u Deadlock exists among a set of processes if every process is waiting for an event that can be caused only by another process in the set lockA->Acquire(); … lockB->Acquire(); … lockA->Acquire(); Process 1Process 2

13 Deadlock and Resources l There are two kinds of resources: consumable and reusable u Consumable resources are generated and destroyed by processes: e.g., a process waiting for a message from another process u Reusable resources are allocated and released by processes: e.g., locks on files l Deadlock with consumable resources is usually treated as a correctness issue (e.g., proofs) or with timeouts l From here on, we only consider reusable resources

Dining Philosophers Each lawyer needs two chopsticks to eat. Each grabs chopstick on the right first. 14

Yet another Example 15

16 Conditions for Deadlock l Deadlock can exist if and only if the following four conditions hold simultaneously: 1. Mutual exclusion – At least one resource must be held in a non-sharable mode 2. Hold and wait – There must be one process holding one resource and waiting for another resource 3. No preemption – Resources cannot be preempted (critical sections cannot be aborted externally) 4. Circular wait – There must exist a set of processes [P 1, P 2, P 3,…,P n ] such that P 1 is waiting for P 2, P 2 for P 3, etc.

Circular Waiting 17

Next Class l Deadlock continued 18