120 likes | 305 Views
Resource and Resource Access Control. Fred Kuhns CS523. Blocking Time. Higher priority job is blocked by a lower priority job during a nonpreemptive interval: priority inversion . Nonpreemptivity: b i (nb) = max( q k ), i+1 k n, q k e i Self-Suspension
E N D
Resource and Resource Access Control Fred Kuhns CS523
Blocking Time • Higher priority job is blocked by a lower priority job during a nonpreemptive interval: priority inversion. • Nonpreemptivity: • bi(nb) = max(qk), i+1 k n, qk ei • Self-Suspension • bi(ss) = max SS of Ti + sum[min(ek, max SS of Tk),k=1 to k=(i-1)] • Context Switch • bi(cs) = 2CS CS523 – Operating Systems
i - 1 t ek k = 1 pk wi(t) = ei + bi(ss) + (Ki + 1)bi(np) + 2(Ki + 1)CS + Time Demand Analysis • Updated TDA equation to include blocking time. • But what about resource contention? CS523 – Operating Systems
Effects of Resource Contention • Add new term for blocking • bi(rb) • Priority Inversion • Uncontrolled priority inversion • Timing Anomalies • Resulting from priority inversion • Deadlock • Circular wait CS523 – Operating Systems
Resource Access Protocols • Resource Access protocol • Granting resource access requests • Scheduling of jobs which request resources • Goals: • Bound delay due Priority Inversion and Timing Anomalies • Prevent Deadlock • Three Examples: • Nonpreemptive Critical Sections • No deadlock, No uncontrolled Priority Inversion • Priority Inheritance Protocol • Deadlock, No uncontrolled Priority Inversion • Priority Ceiling Protocol • No deadlock, No uncontrolled Priority Inversion CS523 – Operating Systems
Some Notation • Ji is the ith job in Task T. Shorthand for Jji • i = Assigned priority of Job Ji; i(t) = current priority of Ji • If the decision to change the priority of Job Ji is made at t = t1 then • t- = t - and t+ = t + ; • i(t1-) = priority at and immediately before t1, • i(t1+) = priority immediately after the priority change • = nonexistent priority, lower than the lowest priority • At time t1 Job Ji requests resource Rk. • Rk Jl: Resource Rk is held by Job Jl • Ji Rk: Ji blocked onRk (Ji Rk Jl) • General scheduling and allocation assumptions: • Scheduling Rules: • Ready Jobs scheduled on processors preemptively in a priority driven manner according to their current priorities, i(t). • At Job release time the priority is equal to its assigned priority: if Ji released at t’, then i(t’) = i • Resource allocation: • If a resource is free then it is allocated when requested • if not free then the request is denied and the requesting job is blocked CS523 – Operating Systems
Nonpreemptive Critical Sections Protocol • Blocking time is bounded: bi(rc) = max(ck) for k = i+1,...,n and ck is the max critical section time of any job in task Tk. • NCSP Rule: • If Ji holds a resource it effectively has the highest priority in the system: i.e. it will not be preempted while holding a resource. • Assessment: • Advantage: simple and does not require prior knowledge of resource usage. Bounds delays and prevents deadlock. • Disadvantage, every job can be blocked by a lower priority job regardless of whether it contends for the same resources. CS523 – Operating Systems
Priority Inheritance Rules (PI) • Scheduling Rule: consistent with assumptions • Allocation Rule: consistent with assumptions • Priority-Inheritance Rule: • if Ji Rk Jl and l(t1-) = priority of Jl at t = t1 • then l(t1+) = i(t1) • until Jlreleases Rkwhen l(t2+) = l(t1-) • Assessment: • simple and works with any priority driven scheduler. Does not require foreknowledge. When no deadlock, no unbounded delay. • does not prevent deadlock • Two types of blocking: Direct and Priority Inheritance blocking • PI has the transitive property. • Does not result in minimal blocking time CS523 – Operating Systems
Basic Priority Ceiling Rules • Extends PI to prevent deadlock and reduce blocking time • Assumptions: • general scheduling rule; fixed assigned priorities • resource requirements of tasks known • (Rk) = priority ceiling for Rk = max(i) for all Ji requiring Rk • System priority ceiling = (t) = max[(Rk)] for all Rk in use at time t. If no resource in use then (Rk) = • Allocation Rule (Ji requests Rk at time t=t1): • if Ji Rk Jl at t = t1 then block Ji (no change) • else (Rk free at t1) if i(t1) > (t), then Rk Ji else if for some Rx Ji and (Rx) = (t1), then Rk Ji else deny and block (Ji Rk) • Priority-Inheritance Rule: • if Ji blocks on resource Rk held by Jl (Ji Rk)(note: Rk Jl and l(t1-) = priority of Jl at t = t1-)then l(t1+) = i(t1) (inherited priority) until Jlreleases all Rxwith (Rx) (t1) at t = t2 , l(t2+) = l(t1-) CS523 – Operating Systems
Stack-Based Priority Ceiling Protocol • Update Current Ceiling in the usual manner • Scheduling Rule: • Ji released and blocked until i(t) > (t) • When not blocked jobs are scheduled in the usual manner. • Allocation Rule: • Allocate when requested CS523 – Operating Systems
Ceiling-Priority Protocol • Update Current Ceiling in the usual manner • Scheduling Rule: • No resources held by Ji, i(t) = i • Resource held by Ji,i(t) = max((Rx)) for all resource Rx held by Ji • FIFO scheduling among jobs with equal priority • Allocation Rule: • Allocate when requested CS523 – Operating Systems
Comparison • worst case performance of stack-based and basic ceiling protocols are the same • stack-based version • supported by the Real-Time systems Annex of Ada95 • Jobs must not self-suspend • when jobs do not self-suspend, stack-based and ceiling-priority protocols yield the same schedules. • stack-based and ceiling-priority have the same worst-case blocking time. CS523 – Operating Systems