Commit f116e7eb authored by Jan Kiszka's avatar Jan Kiszka
Browse files

cobalt/sched-quota: Account for already consumed time on limit update

If we change the quota value of thread group, we should take its already
consumed time during the current cycle into account. So far, we refilled
the budget blindly, which could have given the group an uncontrolled

This commit first update the run_budget_ns of an active group and kills
its limit timer. Then it refills run_budget_ns only with the remaining
budget of the current cycle, taking the new quota as limit.

Accumulated credits are still dropped - not worth to deal with their
complexity in this scenario.

Signed-off-by: Jan Kiszka's avatarJan Kiszka <>
parent 9f6e9ba5
......@@ -572,6 +572,8 @@ void xnsched_quota_set_limit(struct xnsched_quota_group *tg,
int *quota_sum_r)
struct xnsched_quota *qs = &tg->sched->quota;
xnticks_t old_quota_ns = tg->quota_ns;
xnticks_t now, elapsed, consumed;
......@@ -592,7 +594,30 @@ void xnsched_quota_set_limit(struct xnsched_quota_group *tg,
tg->quota_percent = quota_percent;
tg->quota_peak_percent = quota_peak_percent;
tg->run_budget_ns = tg->quota_ns;
if (group_is_active(tg)) {
now = xnclock_read_monotonic(&nkclock);
elapsed = now - tg->run_start_ns;
if (elapsed < tg->run_budget_ns)
tg->run_budget_ns -= elapsed;
tg->run_budget_ns = 0;
tg->run_start_ns = now;
if (tg->run_budget_ns <= old_quota_ns)
consumed = old_quota_ns - tg->run_budget_ns;
consumed = 0;
if (tg->quota_ns >= consumed)
tg->run_budget_ns = tg->quota_ns - consumed;
tg->run_budget_ns = 0;
tg->run_credit_ns = 0; /* Drop accumulated credit. */
*quota_sum_r = quota_sum_all(qs);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment