690 likes | 1.47k Views
Resources and Resource Access Control. Hoon Oh University of Ulsan. Outline. Resources: Definition and Assumptions Resource Access Control Non-preemptive critical sections Basic priority-inheritance protocol Basic priority-ceiling protocol. Resources. Examples for resources Memories
E N D
Resources and Resource Access Control Hoon OhUniversity of Ulsan
Outline • Resources: Definition and Assumptions • Resource Access Control • Non-preemptive critical sections • Basic priority-inheritance protocol • Basic priority-ceiling protocol
Resources • Examples for resources • Memories • Communication channels • Mutexes • Queues
Assumptions • System contains only one processor • System contains ρtypes of serially reusable resources R1, R2, … ,Rρ • There are υi(υ= “upsilon”) indistinguishable units of a resource of type Ri • plentiful resources are ignored • binary semaphore has one unit • counting semaphore has nunits
Assumptions • Serially reusable resources are allocated to jobs on a non-preemptive basis and used in a mutually exclusive manner • If a resource can be used by more than one jobs at the same time, this is modeled as a resource with several units, each used in a mutual exclusive manner
Mutual Exclusive Resource Access • A lock-based concurrency control mechanism assumed to be used to enforce mutual exclusive access to resources • When a job wants to use ηiunits of a resource Ri, it executes a lock L(Ri, ηi) (η = “eta”) to request them • When the job no longer needs the resources, it releases them be executing an unlock U(Ri, ηi)
Mutual Exclusive Resource Access • When a lock request fails, the requesting job is blocked and loses the processor • It stays blocked until the scheduler grants the resources the job is waiting for • If a resource has only 1 unit, the simpler notations L(Ri) and U(Ri) are used for lock and unlock
Critical Section • A segment of a job that begins with a lock and ends at a matching unlock is called a critical section • Resources are released in last-in-first-out order • A critical section that is not included in other critical sections is called an outermost critical section
Critical Section • Critical sections are denoted by [R, η; e], where R gives the name and η the number of units of a resource and e the (maximum) execution time of the critical section • If there is only one unit of a resource the simpler notation [R; e] is used
Nested Critical Sections • Nested critical sections are denoted by nested square brackets • [R1; 7 [R2; 3]] indicates that the critical section beginning with L(R1) includes another critical section that begins with L(R2) • Locks are locked and unlocked in the following order: L(R1), L(R2), U(R2), U(R1)
Resource Conflicts • Two jobs conflict with each other, if some of the resources they require are of the same type • They contend for a resource when one job requests a resource that the other job already has • These terms are used interchangeably
Resource Conflicts • Jobs J1, J2, and J3with feasible intervals (6,14], (2, 17], (0,18] • Critical sections: [R; 2], [R; 4], [R; 4] for jobs 1, 2, 3 • EDF-schedule
Priority Inversion • Priority inversion occurs, when a low-priority job executes while a ready higher-priority job waits
Timing Anomalies • Timing Anomalies can occur due to priority inversion • Assume that critical section of job 3 is reduced to [R; 2.5] instead of [R; 4]
Resource Conflicts • In this example J1is blocked by J3 • But J3is preempted by J2 • Thus J1has to wait for the lower-priority job J2that does not even require the resource that J1needs • In this case priority inversion is considered uncontrolled
Need for Protocols • Protocols are needed to handle priority inversion in a controlled way and to avoid deadlock
Deadlock • Deadlock can occur, if jobs block each other from execution • Example: • Job 1: L(R1), L(R2), U(R2), U(R1) • Job 2: L(R2), L(R1), U(R1), U(R2) Job 1 and job 2 block each other
Wait-for-Graphs • Wait-for-Graphs are used to describe the dynamic-blocking relationship among jobs • Vertexes represent jobs and resources • Edges can express that • a job ownsa resource • a job waits fora resource • A cyclic path in a wait-for-graph indicates a deadlock
Wait-for-Graphs • In the example: • There is only one unit of resource R • J2 waits for 1 unit of the resource of R • J3holds 1 unit of the resource R (or the resource waits for its release) • J1 does neither hold or wait for resource R
Wait for Graph • The following system is deadlocked
Specification of Resource Requirements • The fact that a job (or task) requires a resource is represented by an edge from a job (or task) to the resource • Each edge may be labeled by one or more tuples or numbers, each for a critical section of the job (task) which uses the resource • first element gives numbers of units used in critical section (omitted, if only one unit) • second element specifies duration of critical section
Specification of Resource Requirements • J1needs R for 2 time units More complex example • J2needs R for 4 time units • J3needs R for 4 time units • More complex example
Non-preemptive Critical Sections Protocol (NPCS) • Simplest resource access control protocol • All critical sections are scheduled non-preemptively
Non-preemptive Critical Sections Protocol (NPCS) • Advantages • Simple to implement • Uncontrolled priority inversion cannot occur • A high-priority job can only be blocked once because of a low-priority job • Good protocol when critical sections are short • The blocking time due to resource conflict is
Non-preemptive Critical Sections Protocol (NPCS) • Disadvantages • Every job can be blocked by every lower-priority job even if there is no resource conflict between them
Priority Inheritance Protocol • Works with any priority-driven scheduling algorithm • Uncontrolled priority inversion cannot occur • Protocol does not avoid deadlock • External mechanisms needed to avoid deadlock
Basic Priority Inheritance Protocol • Assumption: • All resources have only one unit • Definitions: • The priority of a job according to the scheduling algorithm is its assigned priority • At any time t,each ready job Jlis scheduled and executes at its current priority πl(t), which may differ from its assigned priority and vary with time
Basic Priority Inheritance Protocol • Priority Inheritance • The current priorityπl(t)of a job Jlmay be raised to the higher priority πh(t)of a job Jh • When this happens, we say that the lower-priority job Jl inherits the priority of higher-priority job Jh, and that Jlexecutes at its inherited priority πh(t)
Basic Priority Inheritance Protocol • Scheduling Rule • Ready jobs are scheduled on the processor preemptively in a priority-driven manner according to their current priorities. • At its release time t, the current priorityπ(t) of every job J is equal to its assigned priority • The job remains at this priority except under the condition stated in the priority-inheritance rule
Basic Priority Inheritance Protocol • Allocation Rule • When a job Jrequests a resource Rat time t, a) if R is free, R is allocated to J until J releases the resource, and b) if R is not free, the request is denied and J is blocked
Basic Priority Inheritance Protocol • Priority-Inheritance Rule • When the requesting job J becomes blocked, the job Jlwhich blocks J inherits the current priorityπ(t) of J. • The job Jlexecutes at its inherited priorityπ(t) until it releases R • At that time, the priority of Jlreturns to its priorityπl(t’) at the time t’ when it acquired the resource R
Basic Priority Inheritance Protocol • When J1requests resource R and becomes blocked at time 3, job J3inherits the priorityπ1of job J1 • When J2becomes ready at time 5, it cannot preempt J3because its priorityπ2is lower than the inherited priorityπ1of J3 • As a consequence J3completes its critical section as soon as possible
Basic Priority-Inheritance Protocol • Two types of blocking: • direct blocking • priority-inheritance blocking • Priority-inheritance is transitive • Protocol does not prevent deadlock
Basic Priority-Inheritance Protocol • Protocol does not minimize the blocking time • A job that requires υ resources and conflicts with klower-priority jobs can be blocked for min(υ, k) times, each for the duration of an outermost critical section (see Liu: p.289)
Basic Priority Ceiling Protocol • Basic priority ceiling protocol extends priority-inheritance protocol to prevent deadlocks and aims to further reduce the blocking time • Assumptions: • Assigned priorities of all jobs are fixed • The resources required by all jobs are known a priori before the execution of any job begins
Basic Priority Ceiling Protocol • Definitions • The priority ceiling of any resource Riis the highest priority of all jobs that require R and is denotedΠ(Ri) • At any time t, the current priority ceiling of the system is • equal to the highest priority ceiling Π(t) of the resources that are in use at the time, if some resources are in use • otherwise it is Ω, a non-existing priority that is lower than the priority of any job
Basic Priority-Ceiling Protocol • Scheduling Rule • As its release time t, the current priorityπ(t) of each job J is equal to its assigned priority • The job remains at this priority except under the condition stated in the Priority-Inheritance rule • Every job J is scheduled preemptively and in a priority-driven manner at its current priorityπ(t)
Basic Priority-Ceiling Protocol • Allocation Rule • When a job J requests a resource R at time t, a) R is held by another job, the request is denied and J is blocked b) R is free i. If J’s current priorityπ(t) is higher than the current priority ceilingΠ(t), R is allocated to J ii. If J’s current priorityπ(t) is not higher than the current ceiling Π(t), R is allocated to J only if J is the job holding the resource(s) whose priority ceiling is equal toΠ(t); otherwise J’s request is denied and J becomes blocked
Basic Priority-Ceiling Protocol • Priority-Inheritance Rule • When Jbecomes blocked, the job Jlwhich blocks Jinherits the current priorityπ(t) of J. • Jlexecutes at its inherited priorityπ(t) until the time where it releases every resource whose priority ceiling is equal to or higher thanπ(t) • At that time, the priority of Jlreturns to its priorityπl(t’) at the time t’ when it was granted the resource(s)
Differences Priority-Inheritance and Priority-Ceiling Protocols • Priority-Inheritance protocol is greedy • A requesting job will always get access to a resource, if this resource is free • Priority-Ceiling protocol is non-greedy • A requesting job may not get access to a resource, though the resource is free (because of additional allocation rule b.ii)
Basic Priority-Ceiling Protocol • There are three ways in which a job J can be blocked by a lower-priority job when using the priority-ceiling protocol • Direct Blocking • Priority-Inheritance Blocking • Avoidance Blocking
Basic Priority-Ceiling Protocol • Direct Blocking • A job can be directly blocked by a lower-priority job that owns the requested resource (Allocation Rule a)
Basic Priority-Ceiling Protocol • Priority-Inheritance Blocking • A job Jcan be blocked by a lower-priority job Jlthat has inherited the priority of a higher-priority job Jh • Figure shows only the inheritance due to direct blocking
Basic Priority-Ceiling Protocol • Avoidance Blocking • A job J is blocked by a lower-priority job Jlwhen J requests a resource R that is free at that time • Blocking is due to the fact that Jlholds another resource X whose priority ceiling is equal to or higher than J’s priorityπ(t)
Priority-Ceiling Protocol • Theorem 8.1 (Liu) states that the priority-ceiling protocol is deadlock free! • “When resource accesses of a system of preemptive, priority-driven jobs on one processor are controlled by the priority-ceiling protocol, deadlock can never occur”
Basic Priority-Ceiling Protocol Computation of Blocking-Time • The calculation of blocking time is simplified due to Theorem 8.2 (Liu) • “When resource accesses of preemptive, priority-driven jobs on one processor are controlled by the priority-ceiling protocol, a job can be blocked for at most the duration of one critical section”
Basic Priority-Ceiling Protocol Computation of Blocking-Time • Example • J1can be directly blocked by J4for one unit of time • J2and J3can be priority-inheritance blocked by J4since J4can inherit the priorityπ1 • b1(rc)=b2(rc)=b3(rc)=1