• No results found

6.3 A MILP-Based Blocking Analysis Framework for Spin Locks 119

6.3.7 Constraints for P|P Spin Locks

Priority-ordered preemptable spin locks ensure that each request is delayed at most once by a different request with a lower priority. For requests with the same priority no particular ordering is specified.

Similar to the non-preemptable spin locks based on priority-ordering (i.e., P|N and PF|N), we first establish a wait-time bound to bound the worst-case delay that a job of Ti can incur after issuing a request for a resource `q (with priority πi,q) until the request is satisfied.

For a global resource `q and a task Ti, let WqP|P(Ti) denote the smallest positive value that satisfies the following recurrence:

WqP|P(Ti) = S(Ti, `q) + LPi(Ti, `q) + LPlh(Ti, `q)

+ I(Ti, `q) + LPP(Ti, `q) + 1. (9)

The individual components of WqP|P(Ti) are defined as follows and justified in the proof of Lemma 12 below.

S(Ti, `q) bounds the maximum delay remote requests of equal or higher priority can contribute to the wait time of Ti’s request. However, since Ji can be preempted while spinning, “equal or higher priority” has to be interpreted with respect to the lowest locking priority used by either Ti (when accessing

`q) or a local higher-priority job (when accessing any resource). S(Ti, `q) thus accounts for all delays due to both Ti’s request and requests of local higher-priority tasks being blocked by remote requests of higher or equal priority:

S(Ti, `q) = X

`r∈Qlh∪{`q}

X

Tx∈τR πx,r≤π0r

njobs Tx, WqP|P(Ti)

· Nx,r · Lx,r

! ,

where lower-priority request that already held `q when Ji issued its request:

LPi(Ti, `q) = max

Tx∈τR{Lx,qx,q > πi,q}.

LPlh(Ti, `q) accounts for requests from local higher-priority jobs that are delayed by remote lower-priority requests:

In a P|P lock, Jican be preempted while busy-waiting, and hence interference due to the execution of local higher-priority jobs needs to be accounted for with I(Ti, `q):

Finally, LPP(Ti, `q) accounts for the (possibly transitive) delay that results from Ji or a higher-priority job being preempted while spinning:

LPP(Ti, `q) = prts Ti, WqP|P(Ti) · cpp(Ti, `q).

Here, prts(Ti, t) denotes the maximum number of preemptions that occur on Ti’s processor throughout any interval of length t while a job of Ti is

pending:

prts(Ti, t) , X

Th∈τlh

 t ph

 .

And cpp(Ti, `q) denotes the worst-case cost per preemption (of either Ji or a local higher-priority job) with respect to the increase in Ji’s waiting time due to a remote lower-priority request acquiring a contested resource:

cpp(Ti, `q) = max{cpplh(Ti), cppi(Ti, `q)},

where cpplh(Ti) denotes the worst-case cost per preemption of a higher-priority job, formally,

cpplh(Ti) = max{Lx,r | Tx ∈ τR ∧ `r∈ Qlh ∧ Th ∈ τlh ∧ Nh,r> 0 ∧ πh,r< πx,r},

and where cppi(Ti, `q) denotes the worst-case cost per preemption of Ji, formally,

cppi(Ti, `q) = max{Lx,q | Tx ∈ τR ∧ πi,q< πx,q}.

The fixed-point iteration can be aborted if no fixed-point with WqP|P(Ti, π) ≤ di is found. If the recurrence for WqP|P(Ti, π) converges, then it bounds the delay of a single request for `q issued with priority π.

Lemma 12. Let t0 denote the time a job Ji of task Ti attempts to lock a resource `q (with its assigned locking priority πi,q), and let t1 denote the time that Ji subsequently acquires the lock for `q. With P|P locks,

t1− t0≤ WqP|P(Ti).

Proof. Analogous to Lemma 11. Let R denote Ji’s request for `q. In any point in time t ∈ [t0, t1), Ji is either spinning or has been preempted by a local higher-priority job. We distinguish among seven different cases, depending on whether Ji is scheduled or preempted, whether a spinning job was already preempted, and whether a lower- or higher-priority request causes blocking at time t.

If Ji is spinning at time t, then R is blocked because `q is being used by a remote job Jx at time t. We consider three distinct cases: (i) Jx has a locking priority (with respect to `q) of at least πi,q, (ii) Jx has a locking priority (with respect to `q) lower than πi,q and Ji has not been preempted during [t0, t], or (iii) Jx has a locking priority (with respect to `q) lower than πi,q and Ji has previously been preempted during [t0, t).

Otherwise, if Ji has been preempted and a local higher-priority job Jh is scheduled at time t, then Jhis either (iv) executing normally, or it is spinning (which transitively delays Ji). If Jh is spinning, it requested some resource

`r (not necessarily `q) that is currently in use by a remote job Jx. We again distinguish among three cases: (v) Jx’s locking priority is at least as high as Jh’s locking priority (both with respect to `r), (vi) Jx’s locking priority is lower than Jh’s locking priority (both with respect to `r) and Jh has not been preempted while busy-waiting for `r, and (vii) Jx’s locking priority is lower than Jh’s locking priority (both with respect to `r) and Jh has been preempted while busy-waiting for `r.

We bound the maximum duration for which each of these conditions can hold during an interval of length WqP|P(Ti). We begin with requests of equal or higher priority delaying either Ji or a local higher-priority job.

Cases (i) and (v): In cases (i) and (v), in order for a remote task Tx to (transitively) delay Ji, it must either be using `q and have a locking priority π ≤ π , or it must be using some ` ∈ Qlh (where possibly ` = ` )

and have a locking priority higher than or equal to the locking priority of some task Th ∈ τlh that accesses `r (i.e., Nh,r > 0 and πx,q ≤ πh,r).

The cumulative length of all critical sections of all remote tasks satisfying either condition, which is given by S(Ti, `q), thus bounds the total duration during which either case (i) or case (v) occurs during an interval of length WqP|P(Ti).

Case (ii): If Ji is delayed by a job Jx using `q, and Jx has a lower locking priority than Ji and Ji has not been preempted during [t0, t], then Jx must have continuously used `q during [t0, t] since P|P locks ensure that jobs with lower locking priority cannot acquire `q while Ji is spinning. The maximum critical section length of any remote task Tx with πx,q > πi,q, as given by LPi(Ti, `q), thus bounds the maximum duration during which case (ii) occurs.

Cases (iii) and (vii): In P|P locks, if Ji is preempted while busy-waiting, then remote jobs with a locking priority lower than πi,qmay acquire `q while Ji is preempted, which may lead to case (iii). Similarly, if a local higher-priority job Jh is preempted while busy-waiting for a resource `r ∈ Qlh, remote jobs with a locking priority lower than πh,r may acquire `r while Jh is preempted, which may lead to case (vii). In both cases, additional (transitive) delay is caused by the preemption as Ji’s wait time is increased by the length of one lower-priority critical section. That is, each time that Ji is preempted, Ji may spin for up to an additional cppi(Ti, `q) time units when resuming execution, and each time that a local higher-priority job Jh is preempted while spinning, Ji may be transitively delayed for up to an additional cpplh(Ti) time units when Jh resumes execution, for a worst-case cost per preemption of cpp(Ti, `q). During an interval of length WqP|P(Ti), at most prts Ti, WqP|P(Ti) higher-priority jobs are released on Ji’s processor, which bounds the total number of preemptions. Hence the total cumulative duration during which either case (iii) or case (vii) occurs over the course of

an interval of length WqP|P(Ti) is bounded by LPP(Ti, `q).

Case (iv): Analogously to the regular response-time analysis of (preemptive) fixed-priority scheduling [19], during an interval of length WqP|P(Ti) starting at time t0 (at which no higher-priority jobs can be pending because Ji is scheduled and tasks are assumed to not self-suspend), each local higher-priority task Th ∈ τlh releases at most

WqP|P(Ti) ph



jobs, each of which executes for at most eh time units (not counting any spinning). The total delay due to the regular execution of higher-priority jobs during an interval of length WqP|P(Ti) starting at time t0 is hence bounded by I(Ti, `q).

Case (vi): Analogously to case (ii), if a higher-priority job Jh trying to lock a resource `r ∈ Qlh is not preempted, it spins waiting for a task Tx ∈ τR with πx,r > πh,r to release `r for at most the duration of one critical section.

During an interval of length WqP|P(Ti), each higher-priority task Th releases at most

WqP|P(Ti) ph



jobs, each of which accesses each `r∈ Qlh at most Nh,r times. As part of each such access, case (vi) occurs for the duration of at most one critical section. The total duration of case (vi) occurring during an interval of length WqP|P(Ti) is hence bounded by LPlh(Ti, `q).

This covers all possible ways in which Ji may be (transitively) delayed when trying to lock a resource `q. Therefore, during an interval of length WqP|P(Ti), the total delay incurred by Ji—that is, the total duration during which one of the seven analyzed cases occurs—is limited to S(Ti, `q) + LPi(Ti, `q) + LPP(Ti, `q) + I(Ti, `q) + LPlh(Ti, `q) = WqP|P(Ti) − 1. In other words, during an interval of length WqP|P(Ti) starting at time t0, Ji is unable to lock `q for at most WqP|P(Ti) − 1 time units. Ji thus ceases to spin and acquires `q at time t1 at most WqP|P(Ti) time units after initially trying to lock `q. 

In the following, we assume that the wait-time bound WqP|P(Ti), i.e., the smallest integer to satisfy Equation (9), can be computed via fixed-point

iteration. If, however, the fixed-point iteration does not converge, then the per-request maximum wait-time of Ji (with respect to `q) cannot be bounded with the presented approach and Constraint 24 below cannot be applied.

(Constraint 25 remains valid in either case.)

As before in the analysis of PF|N locks, we exploit that WqP|P(Ti) is monotonic with respect to scheduling priority. That is, the wait-time bound for a local higher-priority task Th is no longer than the wait-time bound for Ti. Formally,

∀Th ∈ τlh : WqP|P(Ti, π) ≥ WqP|P(Th, π). (10)

Note that Equation (10) depends specifically on the definitions of S(Ti, `q), since S(Ti, `q) is defined in terms of the minimum locking priority of Ti and all local higher-priority tasks, which ensures the required monotonicity.

Given the wait-time bound WqP|P(Ti), we can constrain the the number of requests for `q that can contribute to Ti’s spin delay, similar to Constraint 10.

First, we consider requests issued with higher or equal priority. As in the analysis of PF|N locks, we make the simplifying assumption that all higher-priority jobs issue requests for each `q with locking priority πqminHP.

Constraint 24. In any schedule ofτ when using P|P locks:

∀Pk, Pk6= P (Ti) : ∀`q∈ Qg: ∀Tx∈ τ (Pk), πx,q ≤ πminHPq :

Nx,qi

X

v=1

Xx,q,vS ≤ njobs Tx, WqP|P(Ti) · Nx,q· ncs(Ti, q).

Proof. Analogous to Constraint 10. Due to the monotonicity property stated in Equation (10), it is safe to use WqP|P(Ti) to bound the maximum duration of any request issued by Ji or any local higher-priority tasks. Each request R for `q issued by Ti or a local higher-priority task has a locking priority of

at least πqminHP. During any interval of length WqP|P(Ti), jobs of a remote task Tx with locking priority at least πqminHP (with respect to `q) issue at most njobs Tx, WqP|P(Ti) · Nx,q requests for `q. The stated bound follows since Ji and higher-priority jobs issue at most ncs(Ti, q) requests for `q. 

Next, we consider blocking requests of lower locking priority. Requests with lower locking priority can (possibly transitively) cause Ti to incur spin delay at most once for each request issued by Ti or a local higher-priority task.

Further, Ji can be (possibly transitively) blocked by a remote lower-priority request each time Ji or a local higher-priority job is preempted. (Recall that Jiand local higher-priority jobs are preempted at most Cqtimes in total while busy-waiting for `q, which is enforced with Constraints 21 and 22.)

Constraint 25. In any schedule ofτ when using P|P locks:

∀`q ∈ Qg : X

Tx∈τR πx,qqminHP

Nx,qi

X

v=1

Xx,q,vS ≤ ncs(Ti, q) + Cq.

Proof. Analogous to Constraints 23 and 11. Each request R for `q issued by Ti or a local higher-priority task has a locking priority of at least πqminHP. Ji can be directly or transitively delayed be remote lower-priority requests for a resource `q each time Ji or a local higher-priority task is preempted or issues a request for `q. Hence the total number of times that Ji or local higher-priority jobs busy-wait for `q, in addition to the number of times that Ji or local higher-priority jobs need to restart busy-waiting after being preempted, limits the number of requests issued with locking priority lower

than πqminHP that (transitively) delay Ji. 

This concludes our analysis of P|P locks. Together with the generic

Con-straints 1–7 (for any lock type), and the generic ConCon-straints 20–22 (for preemptable spin locks), the P|P-specific Constraints 24 and 25 define a MILP that bounds the maximum blocking incurred by any Ji. If the recur-rence given in Equation (9) does not converge for some `q, Constraint 24 must be omitted from the MILP for that resource `q.