WIP: layered/cost: move refilling budgets into dispatch #870
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently budgets are refreshed in
layered_stopping
as part of callingrecord_cpu_cost
. This attempts to bill for the usage that has alreadyhappened, and if that takes the budget negative it refreshes from the global
budgets, refreshing them if needed to stay above 0. This means that the budget
for the previously scheduled layer will always be >=0, though not necessarily
at least one time slice, potentially making it impossible to schedule that
layer in the future (particularly bad for confined layers).
While billing in
stopping
makes sense for accurate attribution, refreshinghere might not. To stay fair we should only refresh our budgets when there is
nothing capable of running without refreshing the budgets.
This changes alters the logic to run in
dispatch
. We first attempt a full setof dispatch loops with the existing per-CPU budgets. After this fails (there
was nothing this CPU could run within the constraints of the local budgets), we
query the global budgets and refill local budgets as best we can. If we still
can't schedule anything, we refill the global budgets and try again.
The new flow in
dispatch
is as follows:dispatching with these local budgets.
and attempt dispatching with these local budgets.
This should defer to the local budgets in the common case, drain from the
global budgets wherever that achieves forward progress, and refill the global
budgets only when necessary (forward process cannot be made on this CPU). We
may benefit from a spin-lock on refreshing the global budgets to prevent
multiple CPUs doing it at the same time.
Test plan: