From 776c2a6046f076b6e9fc85dcde6523499507e900 Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Mon, 5 Feb 2024 10:23:39 +0100 Subject: [PATCH] hw: avoid state & code duplication in scheduler The `_head_was_removed` variable got introduced in solving #4710, but it reflects only whether `_head` is a valid pointer or not, thereby it duplicates state. Ref genodelabs/genode#5115 --- .../base-hw/src/core/kernel/cpu_scheduler.cc | 20 +++++-------------- repos/base-hw/src/core/kernel/cpu_scheduler.h | 1 - 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/repos/base-hw/src/core/kernel/cpu_scheduler.cc b/repos/base-hw/src/core/kernel/cpu_scheduler.cc index 91ca63e258..1d5b7f7331 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.cc +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.cc @@ -178,27 +178,19 @@ void Cpu_scheduler::update(time_t time) unsigned duration = (unsigned) (time - _last_time); _last_time = time; _need_to_schedule = false; + unsigned const r = _trim_consumption(duration); /* do not detract the quota if the head context was removed even now */ if (_head) { - unsigned const r = _trim_consumption(duration); - if (_head_claims) _head_claimed(r); else _head_filled(r); - - _head_yields = false; - _consumed(duration); - - } else if (_head_was_removed) { - - _trim_consumption(duration); - _head_was_removed = false; - _head_yields = false; - _consumed(duration); } + _head_yields = false; + _consumed(duration); + if (_claim_for_head()) return; @@ -276,10 +268,8 @@ 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 4699292f40..45247f6ae1 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.h +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.h @@ -134,7 +134,6 @@ 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;