From f74962bdad2ed28629b5ec116be6549f455845cf Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Mon, 26 Dec 2022 12:48:37 +0100 Subject: [PATCH] base-hw scheduler: fix bug on removing head The scheduler did not consider the consumed quota during a call to "update" if the head that consumed the quota was removed from the scheduler. When this occured, the internal round time did not advance as expected but remained at its previous value untile the next call to "update" (without a removed head) This commit introduces a new flag that is set only when the head gets removed in order to detect and handle the situation correctly on the next call to "update". Ref #4151 Ref #4710 --- repos/base-hw/src/core/kernel/cpu_scheduler.cc | 11 ++++++++++- repos/base-hw/src/core/kernel/cpu_scheduler.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/repos/base-hw/src/core/kernel/cpu_scheduler.cc b/repos/base-hw/src/core/kernel/cpu_scheduler.cc index 62184c2a4a..59b129c097 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.cc +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.cc @@ -179,6 +179,13 @@ void Cpu_scheduler::update(time_t time) _head_filled(r); _consumed(duration); + + } else if (_head_was_removed) { + + _trim_consumption(duration); + _head_was_removed = false; + _head_yields = false; + _consumed(duration); } if (_claim_for_head()) @@ -258,8 +265,10 @@ void Cpu_scheduler::remove(Share &s) if (s._ready) unready(s); - if (&s == _head) + if (&s == _head) { _head = nullptr; + _head_was_removed = true; + } if (!s._quota) return; diff --git a/repos/base-hw/src/core/kernel/cpu_scheduler.h b/repos/base-hw/src/core/kernel/cpu_scheduler.h index 70e921f44c..944ba532f3 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.h +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.h @@ -120,6 +120,7 @@ class Kernel::Cpu_scheduler unsigned _head_quota = 0; bool _head_claims = false; bool _head_yields = false; + bool _head_was_removed = false; unsigned const _quota; unsigned _residual; unsigned const _fill;