Commit f116e7eb authored by Jan Kiszka's avatar Jan Kiszka

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
"peak".

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 <jan.kiszka@siemens.com>
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;
atomic_only();
......@@ -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;
else
tg->run_budget_ns = 0;
tg->run_start_ns = now;
xntimer_stop(&qs->limit_timer);
}
if (tg->run_budget_ns <= old_quota_ns)
consumed = old_quota_ns - tg->run_budget_ns;
else
consumed = 0;
if (tg->quota_ns >= consumed)
tg->run_budget_ns = tg->quota_ns - consumed;
else
tg->run_budget_ns = 0;
tg->run_credit_ns = 0; /* Drop accumulated credit. */
*quota_sum_r = quota_sum_all(qs);
......
Markdown is supported
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