# Stack resource policy

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Stack_resource_policy
> Markdown URL: https://mediated.wiki/source/Stack_resource_policy.md
> Source: https://en.wikipedia.org/wiki/Stack_resource_policy
> Source revision: 1336114473
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

The **Stack Resource Policy** (SRP) is a resource allocation policy used in [real-time computing](/source/Real-time_computing), used for accessing shared resources when using [earliest deadline first scheduling](/source/Earliest_deadline_first_scheduling). It was defined by T. P. Baker.[1] SRP is not the same as the [Priority ceiling protocol](/source/Priority_ceiling_protocol) which is for fixed priority tasks (FP).

## Function

Each task is assigned a preemption level based upon the following formula where D(T_i) denotes the deadline of task i and \pi_i(T_i) denotes the preemption level of task i:

D(T_i) < D(T_j) \iff \pi_i(T_i) > \pi_i(T_j)

Each resource R has a current ceiling C_R(V_R) that represents the maximum of the preemption levels of the tasks that may be blocked, when there are V units of R available and \mu_R(J) is the maximum units of R that T_i may require at any one time. C_R(V_R) is assigned as follows:

C_R(V_R) = max(\{0\} \cup \{\pi(J) | V_R < \mu_R(J)\})

There is also a system ceiling \pi' which is the maximum of all current ceilings of the resources.

\pi' = max(\{C_R(i) | i = 1,...,m\} \cup \{\pi(J_c)\})

Any task T_i that wishes to preempt the system must first satisfy the following constraint:

\pi' < P_i(T_i)

This can be refined for [Operating System](/source/Operating_system) implementation (as in [MarteOS](/source/MarteOS)) by removing the multi-unit resources and defining the stack resource policy as follows

- All tasks are assigned a preemption level, in order to preserve the ordering of tasks in relation to each other when locking resources. The lowest relative deadline tasks are assigned the highest preemption level.
- Each [shared resource](/source/Shared_resource) has an associated ceiling level, which is the maximum preemption level of all the tasks that access this protected object.
- The system ceiling, at any instant in time, is the maximum active priority of all the tasks that are currently executing within the system.
- A task is only allowed to preempt the system when its absolute deadline is less than the currently executing task and its preemption level is higher than the current system ceiling.

## Relevancy

The 2011 book *Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications* by Giorgio C. Buttazzo featured a dedicated section to reviewing SRP from Baker 1991 work.[2][3]

## References

1. Baker, T. P. (1990). "A Stack-Based Resource Allocation Policy for Realtime Processes". *IEEE Real-Time Systems Symposium*

1. *Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications*, Giorgio C. Buttazzo, 2011

1. T.P. Baker, "Stack-Based Scheduling of Realtime Processes", The Real-Time Systems Journal 3,1 (March 1991)67-100

---
Adapted from the Wikipedia article [Stack resource policy](https://en.wikipedia.org/wiki/Stack_resource_policy) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Stack_resource_policy?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
