CS 162 Discussion Section Week 4 9/30 - 10/4. Today’s Section ●Project administrivia ●Quiz ●Lecture Review ●Worksheet and Discussion.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Deadlock 2.
Scheduling Criteria CPU utilization – keep the CPU as busy as possible (from 0% to 100%) Throughput – # of processes that complete their execution per.
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.
Deadlocks Andy Wang Operating Systems COP 4610 / CGS 5765.
CS 162 Week 3 Discussion (2/13 – 2/14). Today’s Section Project Administrivia (5 min) Quiz (5 min) Review Lectures 6 and 7 (15 min) Worksheet and Discussion.
CS162 Operating Systems and Systems Programming Lecture 10 Deadlock (cont’d) Thread Scheduling February 22, 2006 Prof. Anthony D. Joseph
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
CS 311 – Lecture 23 Outline Kernel – Process subsystem Process scheduling Scheduling algorithms User mode and kernel mode Lecture 231CS Operating.
CS162 Operating Systems and Systems Programming Lecture 10 Deadlock (cont’d) Thread Scheduling September 30, 2009 Prof. John Kubiatowicz
CS162 Operating Systems and Systems Programming Lecture 7 Deadlock, CPU Scheduling February 9, 2011 Ion Stoica
CS 104 Introduction to Computer Science and Graphics Problems Operating Systems (2) Process Management 10/03/2008 Yang Song (Prepared by Yang Song and.
02/11/2004CSCI 315 Operating Systems Design1 CPU Scheduling Algorithms Notice: The slides for this lecture have been largely based on those accompanying.
CS162 Operating Systems and Systems Programming Lecture 10 Deadlock (cont’d) Thread Scheduling October 2, 2006 Prof. John Kubiatowicz
1 Scheduling Algorithms FCFS First-Come, First-Served Round-robin SJF Multilevel Feedback Queues.
Chapter 6: CPU Scheduling
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-3 CPU Scheduling Department of Computer Science and Software Engineering.
CS212: OPERATING SYSTEM Lecture 3: Process Scheduling 1.
COT 4600 Operating Systems Spring 2011 Dan C. Marinescu Office: HEC 304 Office hours: Tu-Th 5:00-6:00 PM.
Chapter 6 CPU SCHEDULING.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
CPU Scheduling CSCI 444/544 Operating Systems Fall 2008.
CSC139 Operating Systems Lecture 9 Deadlock Adapted from Prof. John Kubiatowicz's lecture notes for CS162 Copyright.
S CHEDULING A LGORITHMS Dr. Adil Yousif 1. CPU S CHEDULING How is the OS to decide which of several tasks to take off a queue? Scheduling: deciding which.
Lecture 7: Scheduling preemptive/non-preemptive scheduler CPU bursts
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
CS6502 Operating Systems - Dr. J. Garrido Deadlock – Part 2 (Lecture 7a) CS5002 Operating Systems Dr. Jose M. Garrido.
CSC139 Operating Systems Lecture 10 Deadlock (cont’d) Thread Scheduling Adapted from Prof. John Kubiatowicz's lecture notes for CS162
1 Real-Time Scheduling. 2Today Operating System task scheduling –Traditional (non-real-time) scheduling –Real-time scheduling.
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.
CS333 Intro to Operating Systems Jonathan Walpole.
Week 3: CPU Scheduling CS 162. Today’s Section Administrivia (2 min) Quiz (5 min) Review lecture 8 (10 min) Worksheet and Discussion (33 min)
Lecture Topics: 11/15 CPU scheduling: –Scheduling goals and algorithms.
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.
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.
Lecture 12 Scheduling Models for Computer Networks Dr. Adil Yousif.
CPU scheduling.  Single Process  one process at a time  Maximum CPU utilization obtained with multiprogramming  CPU idle :waiting time is wasted 2.
1 Lecture 5: CPU Scheduling Operating System Fall 2006.
Chapter 5: CPU Scheduling. 5.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 5: CPU Scheduling Basic Concepts Scheduling Criteria.
CPU Scheduling Andy Wang Operating Systems COP 4610 / CGS 5765.
CPU SCHEDULING.
Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM.
Operating Systems Processes Scheduling.
Scheduling (Priority Based)
Chapter 6: CPU Scheduling
CPU Scheduling G.Anuradha
Chapter 6: CPU Scheduling
CS162 Operating Systems and Systems Programming Lecture 8 Thread Scheduling February 19, 2014 Anthony D. Joseph
Module 5: CPU Scheduling
Andy Wang Operating Systems COP 4610 / CGS 5765
February 18, 2010 Ion Stoica CS162 Operating Systems and Systems Programming Lecture 10 Deadlock (cont’d) Thread.
CSCI 511 Operating Systems Chapter 7 Deadlock
Operating System Concepts
3: CPU Scheduling Basic Concepts Scheduling Criteria
Chapter5: CPU Scheduling
COT 4600 Operating Systems Spring 2011
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Chapter 6: CPU Scheduling
Chapter 5: CPU Scheduling
Module 5: CPU Scheduling
Chapter 6: CPU Scheduling
EECE.4810/EECE.5730 Operating Systems
CPU Scheduling.
Module 5: CPU Scheduling
Chapter 5: CPU Scheduling
Presentation transcript:

CS 162 Discussion Section Week 4 9/ /4

Today’s Section ●Project administrivia ●Quiz ●Lecture Review ●Worksheet and Discussion

Project 1 ●Autograder is up submit proj1-test ●Due 10/8 (Tuesday) at 11:59 PM submit proj1-code ●Due 10/9 (Wednesday) at 11:59 PM Final design doc & Project 1 Group Evals ●Questions?

Quiz…

1.Name the conditions causing deadlock, given definitions (0.5 points each): a.thread holding at least one resource waits to acquire other resources held by other threads b.only one thread at a time can use a resource c.resource only released voluntarily by the thread holding it after done using the resource d.chain of n threads T(i); T(i) depends on T(i+1); T(n) depends on T(0) (True/False) 2.Starvation implies deadlock 3.Deadlock implies starvation (that a thread waits indefinitely) 4.To find general deadlocks, it is enough to look for loops in the resource allocation graph.

Lecture Review

Lec 7.7 9/25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Starvation vs Deadlock Starvation vs. Deadlock –Starvation: thread waits indefinitely »Example, low-priority thread waiting for resources constantly in use by high-priority threads –Deadlock: circular waiting for resources »Thread A owns Res 1 and is waiting for Res 2 Thread B owns Res 2 and is waiting for Res 1 –Deadlock  Starvation but not vice versa »Starvation can end (but doesn’t have to) »Deadlock can’t end without external intervention Res 2 Res 1 Thread B Thread A Wait For Wait For Owned By Owned By

Lec 7.8 9/25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Four requirements for Deadlock Mutual exclusion –Only one thread at a time can use a resource Hold and wait –Thread holding at least one resource is waiting to acquire additional resources held by other threads No preemption –Resources are released only voluntarily by the thread holding the resource, after thread is finished with it Circular wait –There exists a set {T 1, …, T n } of waiting threads »T 1 is waiting for a resource that is held by T 2 »T 2 is waiting for a resource that is held by T 3 »…»… »T n is waiting for a resource that is held by T 1

Lec 7.9 9/25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 T1T1 T2T2 T3T3 R2R2 R1R1 T4T4 Deadlock Detection Algorithm Only one of each type of resource  look for loops More General Deadlock Detection Algorithm –Let [X] represent an m-ary vector of non-negative integers (quantities of resources of each type): [FreeResources]: Current free resources each type [Request X ]: Current requests from thread X [Alloc X ]: Current resources held by thread X –See if tasks can eventually terminate on their own [Avail] = [FreeResources] Add all nodes to UNFINISHED do { done = true Foreach node in UNFINISHED { if ([Request node ] <= [Avail]) { remove node from UNFINISHED [Avail] = [Avail] + [Alloc node ] done = false } } } until(done) –Nodes left in UNFINISHED  deadlocked

Lec /25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Toward right idea: –State maximum resource needs in advance –Allow particular thread to proceed if: (available resources - #requested)  max remaining that might be needed by any thread Banker’s algorithm (less conservative): –Allocate resources dynamically »Evaluate each request and grant if some ordering of threads is still deadlock free afterward »Keeps system in a “SAFE” state, i.e. there exists a sequence {T 1, T 2, … T n } with T 1 requesting all remaining resources, finishing, then T 2 requesting all remaining resources, etc.. –Algorithm allows the sum of maximum resource needs of all current threads to be greater than total resources Banker’s Algorithm for Preventing Deadlock

Lec /25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Banker’s Algorithm Technique: pretend each request is granted, then run deadlock detection algorithm, substitute ([Request node ] ≤ [Avail])  ([Max node ]-[Alloc node ] ≤ [Avail]) [FreeResources]: Current free resources each type [Max X ]: Max resources requested by thread X [Alloc X ]: Current resources held by thread X [Avail] = [FreeResources] Add all nodes to UNFINISHED do { done = true Foreach node in UNFINISHED { if ([Max node ]–[Alloc node ] <= [Avail]) { remove node from UNFINISHED [Avail] = [Avail] + [Alloc node ] done = false } } } until(done)

Lec /25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Summary: Deadlock Starvation vs. Deadlock –Starvation: thread waits indefinitely –Deadlock: circular waiting for resources Four conditions for deadlocks –Mutual exclusion »Only one thread at a time can use a resource –Hold and wait »Thread holding at least one resource is waiting to acquire additional resources held by other threads –No preemption »Resources are released only voluntarily by the threads –Circular wait »  set {T 1, …, T n } of threads with a cyclic waiting pattern Deadlock preemption Deadlock prevention (Banker’s algorithm)

Lec /25/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Scheduling Metrics Waiting Time: time the job is waiting in the ready queue –Time between job’s arrival in the ready queue and launching the job Service (Execution) Time: time the job is running Response (Completion) Time: –Time between job’s arrival in the ready queue and job’s completion –Response time is what the user sees: »Time to echo a keystroke in editor »Time to compile a program Response Time = Waiting Time + Service Time Throughput: number of jobs completed per unit of time –Throughput related to response time, but not same thing: »Minimizing response time will lead to more context switching than if you only maximized throughput

Lec 8. 9/30/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Scheduling Policy Goals/Criteria Minimize Response Time –Minimize elapsed time to do an operation (or job) Maximize Throughput –Two parts to maximizing throughput  Minimize overhead (for example, context-switching)  Efficient use of resources (CPU, disk, memory, etc) Fairness –Share CPU among users in some equitable way –Fairness is not minimizing average response time:  Better average response time by making system less fair

Lec 8. 9/30/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Summary Scheduling: selecting a process from the ready queue and allocating the CPU to it FCFS Scheduling: –Run threads to completion in order of submission –Pros: Simple (+) –Cons: Short jobs get stuck behind long ones (-) Round-Robin Scheduling: –Give each thread a small amount of CPU time when it executes; cycle between all ready threads –Pros: Better for short jobs (+) –Cons: Poor when jobs are same length (-)

Lec 8. 9/30/13 Anthony D. Joseph and John Canny CS162 ©UCB Fall 2013 Summary (cont’d) Shortest Job First (SJF)/Shortest Remaining Time First (SRTF): –Run whatever job has the least amount of computation to do/least remaining amount of computation to do –Pros: Optimal (average response time) –Cons: Hard to predict future, Unfair Multi-Level Feedback Scheduling: –Multiple queues of different priorities –Automatic promotion/demotion of process priority in order to approximate SJF/SRTF Lottery Scheduling: –Give each thread a number of tokens (short tasks  more tokens) –Reserve a minimum number of tokens for every thread to ensure forward progress/fairness

Worksheet …

1.Name the conditions causing deadlock, given definitions (0.5 points each): a.chain of n threads T(i); T(i) depends on T(i+1); T(n) depends on T(0) b.thread holding at least one resource waits to acquire other resources held by other threads c.resource only released voluntarily by the thread holding it after done using the resource d.only one thread at a time can use a resource (True/False) 2.Deadlock implies starvation (that a thread waits indefinitely) 3.Starvation implies deadlock 4.To find general deadlocks, it is enough to look for loops in the resource allocation graph.