UCDavis, ecs251 Fall 2007 10/23/2007ecs251, fall 20071 Operating System Models ecs251 Fall 2007 : Operating System Models #3: Priority Inversion Dr. S.

Slides:



Advertisements
Similar presentations
Real Time Scheduling.
Advertisements

Chapter 7 - Resource Access Protocols (Critical Sections) Protocols: No Preemptions During Critical Sections Once a job enters a critical section, it cannot.
Priority Inheritance and Priority Ceiling Protocols
Washington WASHINGTON UNIVERSITY IN ST LOUIS Resource and Resource Access Control Fred Kuhns Applied Research Laboratory Computer Science and Engineering.
Outline Introduction Assumptions and notations
Introduction to Embedded Systems Resource Management - III Lecture 19.
Priority Inversion BAE5030 Advanced Embedded Systems 9/13/04.
Priority INHERITANCE PROTOCOLS
Copyright © 2000, Daniel W. Lewis. All Rights Reserved. CHAPTER 8 SCHEDULING.
1 EE5900 Advanced Embedded System For Smart Infrastructure RMS and EDF Scheduling.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
LUI SHA,RAGUNATHAN RAJKUMAR,JOHN P.LEHOCZKY IEEE TRANSACTIONS ON COMPUTERS, VOL. 39, NO. 9, SEPTEMBER 1990 Repesent : Shu Wei Ho.
Resource management and Synchronization Akos Ledeczi EECE 354, Fall 2010 Vanderbilt University.
0 Synchronization Problem Resource sharing –Requires mutual exclusion –Critical section A code section that should be executed mutually exclusively by.
CS5270 Lecture 31 Uppaal, and Scheduling, and Resource Access Protocols CS 5270 Lecture 3.
Resource Access Protocols
CprE 458/558: Real-Time Systems (G. Manimaran)1 CprE 458/558: Real-Time Systems Resource Access Control Protocols.
CSE 522 Real-Time Scheduling (3)
Mutual Exclusion.
Secure Operating Systems Lesson 5: Shared Objects.
Tanenbaum Ch 6 Silberschatz Ch 7
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.
© Andy Wellings, 2004 Roadmap  Introduction  Concurrent Programming  Communication and Synchronization  Completing the Java Model  Overview of the.
UCDavis, ecs150 Fall /23/2007ecs150, fall Operating System ecs150 Fall 2007 : Operating System #3: Priority Inversion (a paper on the class.
UCDavis, ecs150 Spring /21/2006ecs150, spring Operating System ecs150 Spring 2006 : Operating System #3: Priority Inversion (paper) Dr. S.
Spring 2002Real-Time Systems (Shin) Rate Monotonic Analysis Assumptions – A1. No nonpreemptible parts in a task, and negligible preemption cost –
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
Introduction to Embedded Systems
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Dave Bremer Otago Polytechnic,
Introduction to Embedded Systems Rabie A. Ramadan 6.
CS 153 Design of Operating Systems Spring 2015 Lecture 11: Scheduling & Deadlock.
Real-Time Systems Design1 Priority Inversion When a low-priority task blocks a higher-priority one, a priority inversion is said to occur Assume that priorities:
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
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.
Real Time Scheduling Telvis Calhoun CSc Outline Introduction Real-Time Scheduling Overview Tasks, Jobs and Schedules Rate/Deadline Monotonic Deferrable.
Real-Time Scheduling CS4730 Fall 2010 Dr. José M. Garrido Department of Computer Science and Information Systems Kennesaw State University.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Deadlocks Silberschatz Ch. 7 and Priority Inversion Problems.
Real Time Operating Systems Mutual Exclusion, Synchronization & Intertask Communication Course originally developed by Maj Ron Smith.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
1 Review of Process Mechanisms. 2 Scheduling: Policy and Mechanism Scheduling policy answers the question: Which process/thread, among all those ready.
- 1 -  P. Marwedel, Univ. Dortmund, Informatik 12, 2006 Universität Dortmund Periodic scheduling For periodic scheduling, the best that we can do is to.
Deadlock Operating Systems: Internals and Design Principles.
Introduction to Embedded Systems Rabie A. Ramadan 5.
A presentation for Brian Evans’ Embedded Software Class By Nate Forman Liaison Technology Inc. 3/30/2000 For Real-Time Scheduling.
CS333 Intro to Operating Systems Jonathan Walpole.
1.  System Characteristics  Features of Real-Time Systems  Implementing Real-Time Operating Systems  Real-Time CPU Scheduling  An Example: VxWorks5.x.
Undergraduate course on Real-time Systems Linköping University TDDD07 Real-time Systems Lecture 2: Scheduling II Simin Nadjm-Tehrani Real-time Systems.
CSCI1600: Embedded and Real Time Software Lecture 17: Concurrent Programming Steven Reiss, Fall 2015.
Operating Systems Scheduling. Scheduling Short term scheduler (CPU Scheduler) –Whenever the CPU becomes idle, a process must be selected for execution.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
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);
Process Management Deadlocks.
RTOS Scheduling 2.0 Problems - Solutions
Scheduling and Resource Access Protocols: Basic Aspects
Background on the need for Synchronization
Applied Operating System Concepts -
EEE 6494 Embedded Systems Design
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall2014 9/20/2018.
Realtime System Fundamentals : Scheduling and Priority-based scheduling B. Ramamurthy cse321-fall /27/2018.
CSCI1600: Embedded and Real Time Software
Lecture 2 Part 2 Process Synchronization
Chapter 8: Deadlocks.
CSCI1600: Embedded and Real Time Software
Implementing Mutual Exclusion
CHAPTER 8 Resources and Resource Access Control
CSCI1600: Embedded and Real Time Software
Presentation transcript:

UCDavis, ecs251 Fall /23/2007ecs251, fall Operating System Models ecs251 Fall 2007 : Operating System Models #3: Priority Inversion Dr. S. Felix Wu Computer Science Department University of California, Davis

UCDavis, ecs251 Fall /23/2007ecs251, fall Unexpected Effects between two OS control mechanisms l Real-time priority scheduling –Responsiveness: if a higher priority thread appears, serve it asap. l Mutual exclusion –Integrity: if a higher priority thread wants to enter a critical section being hold by a lower priority thread, it has to wait for the lower priority thread to leave “the critical section”.

UCDavis, ecs251 Fall /23/2007ecs251, fall lock unlock ::.::. 256 different priorities  64 scheduling classes RR

UCDavis, ecs251 Fall /23/2007ecs251, fall Real-Time Threads l Thread τ 1 L L L R x L l Thread τ 2 L L... L l Thread τ 3 L L L R x L... L l L: local CPU burst l R: resource required (Mutual Exclusion)

UCDavis, ecs251 Fall /23/2007ecs251, fall Example l Suppose that threads τ 1 and τ 3 share some data. l Access to the data is restricted using semaphore x: –each task executes the following code: l do local work (L) l sem_wait(s) (P(x)) –access shared resource (R) l sem_signal(s) (V(x)) l do more local work (L)

UCDavis, ecs251 Fall /23/2007ecs251, fall 20076Blocking τ 2 τ 3 t0t+3 t+4 R L L L R R L τ 1 t+6 L L L Blocked! L L L

UCDavis, ecs251 Fall /23/2007ecs251, fall The middle thread τ 2 τ 3 t0t+3 L L L R τ 1 L L L Blocked! t+2

UCDavis, ecs251 Fall /23/2007ecs251, fall Unbounded Priority Inversion τ 2 τ 3 t0t+3 t+253 RL L L R R L τ 1 t+254 L L L... L Blocked! t+2

UCDavis, ecs251 Fall /23/2007ecs251, fall Unbounded Priority Inversion τ 2-1 τ 3 t0t+3 t+2530 RL L L R R L τ 1 t+2 t+2540 L L L L Blocked! τ 2-2 τ 2-n L L

UCDavis, ecs251 Fall /23/2007ecs251, fall The problem.. l As long as we have priority and mutual exclusion at the same time, we will have some form of priority inversion. l How to resolve it? trade-off?

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Inheritance τ 2 τ 3 t0t+3t+4 L... L L L L R R L τ 1 t+2t+6 L L L R Blocked! dynamic  3 =  1 L... L

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Inheritance Protocols l L. Sha, R. Rajkumar, J. Lehoczky, “Priority Inheritance Protocols: An Approach to Real-Time Synchronization”, IEEE Transactions on Computers, Vol. 39, No. 9, pp , 1990

UCDavis, ecs251 Fall /23/2007ecs251, fall “The meteorological data gathering task ran as an infrequent, low priority thread, and used the information bus to publish its data. When publishing its data, it would acquire a mutex, do writes to the bus, and release the mutex. If an interrupt caused the information bus thread to be scheduled while this mutex was held, and if the information bus thread then attempted to acquire this same mutex in order to retrieve published data, this would cause it to block on the mutex, waiting until the meteorological thread released the mutex before it could continue. The spacecraft also contained a communications task that ran with medium priority.” High priority: retrieval of data from shared memory Medium priority: communications task Low priority: thread collecting meteorological data

UCDavis, ecs251 Fall /23/2007ecs251, fall Basic Priority Inheritance l For each resource (semaphore), a list of blocked threads must be stored in a priority queue. l A thread τ i uses its assigned priority, unless it is in its critical section and blocks some higher priority threads, in which case, thread τ i uses ( inherits ) the highest dynamic priority of all the threads it blocks. l Priority inheritance is transitive; that is, if thread τ i blocks τ j and τ j blocks τ k, then τ i can inherit the priority of τ k.

UCDavis, ecs251 Fall /23/2007ecs251, fall Mutex Priority Inheritance pthread_mutex_lock pthread_mutex_unlock ttt waiting queue t priority

UCDavis, ecs251 Fall /23/2007ecs251, fall pthread_mutex_lock pthread_mutex_unlock M1M1 ttt waiting queue t priority pthread_mutex_lock pthread_mutex_unlock M2M2 ttt waiting queue priority

UCDavis, ecs251 Fall /23/2007ecs251, fall Transitive Priority pthread_mutex_lock pthread_mutex_unlock M1M1 ttt waiting queue t priority pthread_mutex_lock pthread_mutex_unlock M2M2 tt waiting queue t priority

UCDavis, ecs251 Fall /23/2007ecs251, fall Problems l The Basic Priority Inheritance Protocol has two problems: –Deadlock - two threads need to access a pair of shared resources simultaneously. If the resources, say A and B, are accessed in opposite orders by each thread, then deadlock may occur. –Blocking Chain - the blocking duration is bounded (by at most the sum of critical section times), but that may be substantial.

UCDavis, ecs251 Fall /23/2007ecs251, fall Blocking Chain Example l Task  1 : L R 2 L R 3 L R 4 L... L R n L,2(n-1) l Task  2 : L R 2 R 2, 2(n-2) l Task  3 : L R 3 R 3, 2(n-3) l Task  4 : L R 4 R 4, 2(n-4) l... l Task  n-1 : L R n-1 R n-1, 2(n-(n-1)) l Task  n : L R n R n, 2(n-n) starting time

UCDavis, ecs251 Fall /23/2007ecs251, fall Blocking Chain τ 2 τ n 0 L R n τ 1 RnRn R n L L R 2 R2R2 Blocked! L R 2 L Blocked!

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Ceiling Protocols (PCP) l A higher priority thread can be blocked at most once, in its life time, by one lower priority thread. l Deadlocks are prevented/avoided (?!). l Transitive inheritance is prevented. l Are they really critical?

UCDavis, ecs251 Fall /23/2007ecs251, fall PCP l How do we accomplish these goals intuitively?

UCDavis, ecs251 Fall /23/2007ecs251, fall Locking a Mutex l If the “mutex M” is available and “thread T” needs it, should T lock it? pthread_mutex_lock pthread_mutex_unlock t Mutex?? Mutex + Priority Inheritance??

UCDavis, ecs251 Fall /23/2007ecs251, fall Risk for Locking a Mutex l If the “mutex M” is available and “thread T” needs it, should T lock it? pthread_mutex_lock pthread_mutex_unlock t t Checking before Locking it!! We don’t know whether the high priority thread will occur in the next X seconds! But, does it matter?

UCDavis, ecs251 Fall /23/2007ecs251, fall “Checking” What??

UCDavis, ecs251 Fall /23/2007ecs251, fall Mutex Priority Ceiling pthread_mutex_lock pthread_mutex_unlock ttt potential customers PC Max priority A preventive action (could be unnecessary though)

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Ceiling Should I get it? PC locked unlocked MaxPC value thread t 2 ??? 4 thread t 4 1 thread t 9 2 4

UCDavis, ecs251 Fall /23/2007ecs251, fall Mutex/PIP Get it as long as it is available! PC locked unlocked MaxPC value thread t 2 YES 4 thread t 4 1 thread t 9 7 4

UCDavis, ecs251 Fall /23/2007ecs251, fall PCP Not so Fast PC locked unlocked MaxPC value thread t 2 NO 4 thread t 4 1 thread t 9 7 4

UCDavis, ecs251 Fall /23/2007ecs251, fall PCP Not so Fast PC locked unlocked MaxPC value thread t 2 NO 4 thread t 4 2 thread t 9 7 4

UCDavis, ecs251 Fall /23/2007ecs251, fall PCP How about??? PC locked unlocked MaxPC value thread t 2 ?? 4 thread t 4 2 thread t 2 7 4

UCDavis, ecs251 Fall /23/2007ecs251, fall Are we sure about the claim of PCP? l A higher priority thread can be blocked at most once, in its life time, by one lower priority thread. l Deadlocks are prevented/avoided. l Try to find a “Counter Example” to show that PCP’s claim is FALSE!!

UCDavis, ecs251 Fall /23/2007ecs251, fall Critical Section Requirements (similar to 2PL) l Threads must lock and unlock in a “nested” or “pyramid” fashion: –Let L(S) = lock(S). –Let U(S) = unlock(S). –Example: L(s 1 );L(s 2 );L(s 3 );...;U(s 3 );U(s 2 );U(s 1 ); s 1 s 2 s 3

UCDavis, ecs251 Fall /23/2007ecs251, fall Executing Executing with Q locked Preempted Executing with V locked Blocked Tasks Ceiling-driven Indirectly Blocked

UCDavis, ecs251 Fall /23/2007ecs251, fall Executing Executing with Q locked Preempted Executing with V locked Blocked Priority Inversion (12,6,8,17) Ceiling-driven Indirectly Blocked

UCDavis, ecs251 Fall /23/2007ecs251, fall Executing Executing with Q locked Preempted Executing with V locked Blocked Priority Inversion Area (12,6,8,17) Ceiling-driven Indirectly Blocked

UCDavis, ecs251 Fall /23/2007ecs251, fall Process 1 Basic Priority Inheritance (9,12,14,17)

UCDavis, ecs251 Fall /23/2007ecs251, fall Process 1 Priority Ceiling (7,12,14,17) 11 locked

UCDavis, ecs251 Fall /23/2007ecs251, fall Can we do better??

UCDavis, ecs251 Fall /23/2007ecs251, fall a b c d process 11 Priority Ceiling Emulation (6,12,14,17) 11

UCDavis, ecs251 Fall /23/2007ecs251, fall “Kernel” Mutex OS Kernel User processes “No preemption in the Kernel mode”

UCDavis, ecs251 Fall /23/2007ecs251, fall PCP/PCE Mutex Obtain the PC value as my own priority pthread_mutex_lock pthread_mutex_unlock PC Less context switching No Mutex queue!?

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Ceiling Emulation l Each thread has a static (base) default priority assigned (perhaps by the deadline monotonic scheme). l Each resource has a static ceiling value defined, this is the maximum priority of the threads that use it. l A thread has a dynamic (active) priority that is the maximum of its own static priority and the ceiling values of any resources it has locked l As a consequence, a thread will only suffer a block at the very beginning of its execution l Once the thread starts actually executing, all the resources it needs must be free; if they were not, then some thread would have an equal or higher priority and the thread’s execution would be postponed

UCDavis, ecs251 Fall /23/2007ecs251, fall Property #1 l A job J can be blocked by a lower priority job J low, only if the priority of J is no higher than the highest ceiling of all locked mutexes by lower priority jobs before J is initiated.

UCDavis, ecs251 Fall /23/2007ecs251, fall Property #2 l J j in a mutex M j is preempted by J i in another mutex M i. Then, J j can not inherit a priority higher than or equal to J i until J i completes.

UCDavis, ecs251 Fall /23/2007ecs251, fall How? l J superhigh is blocked by J j (so J j will inherit) l But, that mutex must not be locked yet. l J j will never reach there before J i finishes.

UCDavis, ecs251 Fall /23/2007ecs251, fall Transitive Blocking

UCDavis, ecs251 Fall /23/2007ecs251, fall Transitive Blocking l PCP prevents Transitive Blocking l J 1, J 2, J 3 l J 3 blocks J 2, and J 2 blocks J 1 l J 3 will inherit priority of J 1, contradiction!

UCDavis, ecs251 Fall /23/2007ecs251, fall Deadlock Free of PCP

UCDavis, ecs251 Fall /23/2007ecs251, fall Deadlock Free of PCP l Circular waiting (circle must be two!) l Both of them must need both mutexes!

UCDavis, ecs251 Fall /23/2007ecs251, fall Property #3 l J i can be blocked by J low for at most one duration of mutex.

UCDavis, ecs251 Fall /23/2007ecs251, fall One duration block l J i can be blocked once for all J low ’s.

UCDavis, ecs251 Fall /23/2007ecs251, fall Priority Ceiling Protocols (PCP) l A higher priority thread can be blocked at most once, in its life time, by one lower priority thread. l Deadlocks are prevented/avoided (?!). l Transitive inheritance is prevented. l Are they really critical?

UCDavis, ecs251 Fall /23/2007ecs251, fall Summary l Priority Inversion l Basic Priority Inheritance l Priority Ceiling –Upgraded when a higher priority task (might not be the same as the ceiling value) is blocked due to the Ceiling value l Priority Ceiling Emulation –Immediately upgraded to the ceiling value after obtaining the lock