mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-22 10:14:04 +00:00
hw: merge booleans in scheduler into one state
Instead of having `_yield` and `_need_to_schedule` booleans, use one consistent state variable. Ref genodelabs/genode#5115
This commit is contained in:
parent
9d72c21894
commit
1c4078f23a
@ -70,7 +70,7 @@ void Cpu_scheduler::_current_claimed(unsigned const r)
|
|||||||
* at least ensure that it does not have to wait for all unprioritized
|
* at least ensure that it does not have to wait for all unprioritized
|
||||||
* scheduling contexts as well before being scheduled again.
|
* scheduling contexts as well before being scheduled again.
|
||||||
*/
|
*/
|
||||||
if (!_yield)
|
if (_state != YIELD)
|
||||||
_fills.to_head(&_current->_fill_item);
|
_fills.to_head(&_current->_fill_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ bool Cpu_scheduler::_schedule_fill()
|
|||||||
unsigned Cpu_scheduler::_trim_consumption(unsigned &q)
|
unsigned Cpu_scheduler::_trim_consumption(unsigned &q)
|
||||||
{
|
{
|
||||||
q = Genode::min(Genode::min(q, _current_quantum), _super_period_left);
|
q = Genode::min(Genode::min(q, _current_quantum), _super_period_left);
|
||||||
if (!_yield)
|
if (_state != YIELD)
|
||||||
return _current_quantum - q;
|
return _current_quantum - q;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -157,7 +157,6 @@ void Cpu_scheduler::update(time_t time)
|
|||||||
|
|
||||||
unsigned duration = (unsigned) (time - _last_time);
|
unsigned duration = (unsigned) (time - _last_time);
|
||||||
_last_time = time;
|
_last_time = time;
|
||||||
_need_to_schedule = false;
|
|
||||||
unsigned const r = _trim_consumption(duration);
|
unsigned const r = _trim_consumption(duration);
|
||||||
|
|
||||||
/* do not detract the quota if the current share was removed even now */
|
/* do not detract the quota if the current share was removed even now */
|
||||||
@ -166,9 +165,10 @@ void Cpu_scheduler::update(time_t time)
|
|||||||
else _current_filled(r);
|
else _current_filled(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
_yield = false;
|
|
||||||
_consumed(duration);
|
_consumed(duration);
|
||||||
|
|
||||||
|
_state = UP_TO_DATE;
|
||||||
|
|
||||||
if (_schedule_claim())
|
if (_schedule_claim())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -184,6 +184,9 @@ void Cpu_scheduler::ready(Share &s)
|
|||||||
assert(!s._ready && &s != &_idle);
|
assert(!s._ready && &s != &_idle);
|
||||||
|
|
||||||
s._ready = true;
|
s._ready = true;
|
||||||
|
|
||||||
|
bool out_of_date = false;
|
||||||
|
|
||||||
if (s._quota) {
|
if (s._quota) {
|
||||||
|
|
||||||
_ucl[s._prio].remove(&s._claim_item);
|
_ucl[s._prio].remove(&s._claim_item);
|
||||||
@ -192,12 +195,9 @@ void Cpu_scheduler::ready(Share &s)
|
|||||||
_rcl[s._prio].insert_head(&s._claim_item);
|
_rcl[s._prio].insert_head(&s._claim_item);
|
||||||
if (_current && _current->_claim) {
|
if (_current && _current->_claim) {
|
||||||
|
|
||||||
if (s._prio >= _current->_prio)
|
if (s._prio >= _current->_prio) out_of_date = true;
|
||||||
_need_to_schedule = true;
|
} else out_of_date = true;
|
||||||
} else
|
|
||||||
_need_to_schedule = true;
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
_rcl[s._prio].insert_tail(&s._claim_item);;
|
_rcl[s._prio].insert_tail(&s._claim_item);;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,7 +205,9 @@ void Cpu_scheduler::ready(Share &s)
|
|||||||
s._fill = _fill;
|
s._fill = _fill;
|
||||||
_fills.insert_tail(&s._fill_item);
|
_fills.insert_tail(&s._fill_item);
|
||||||
|
|
||||||
if (!_current || _current == &_idle) _need_to_schedule = true;
|
if (!_current || _current == &_idle) out_of_date = true;
|
||||||
|
|
||||||
|
if (out_of_date && _state == UP_TO_DATE) _state = OUT_OF_DATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -213,8 +215,7 @@ void Cpu_scheduler::unready(Share &s)
|
|||||||
{
|
{
|
||||||
assert(s._ready && &s != &_idle);
|
assert(s._ready && &s != &_idle);
|
||||||
|
|
||||||
if (&s == _current)
|
if (&s == _current && _state == UP_TO_DATE) _state = OUT_OF_DATE;
|
||||||
_need_to_schedule = true;
|
|
||||||
|
|
||||||
s._ready = false;
|
s._ready = false;
|
||||||
_fills.remove(&s._fill_item);
|
_fills.remove(&s._fill_item);
|
||||||
@ -229,8 +230,7 @@ void Cpu_scheduler::unready(Share &s)
|
|||||||
|
|
||||||
void Cpu_scheduler::yield()
|
void Cpu_scheduler::yield()
|
||||||
{
|
{
|
||||||
_yield = true;
|
_state = YIELD;
|
||||||
_need_to_schedule = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -198,17 +198,18 @@ class Kernel::Cpu_scheduler
|
|||||||
typedef Cpu_share Share;
|
typedef Cpu_share Share;
|
||||||
typedef Cpu_priority Prio;
|
typedef Cpu_priority Prio;
|
||||||
|
|
||||||
|
enum State { UP_TO_DATE, OUT_OF_DATE, YIELD };
|
||||||
|
|
||||||
|
State _state { UP_TO_DATE };
|
||||||
Share_list _rcl[Prio::max() + 1]; /* ready claims */
|
Share_list _rcl[Prio::max() + 1]; /* ready claims */
|
||||||
Share_list _ucl[Prio::max() + 1]; /* unready claims */
|
Share_list _ucl[Prio::max() + 1]; /* unready claims */
|
||||||
Share_list _fills { }; /* ready fills */
|
Share_list _fills { }; /* ready fills */
|
||||||
Share &_idle;
|
Share &_idle;
|
||||||
Share *_current = nullptr;
|
Share *_current = nullptr;
|
||||||
unsigned _current_quantum { 0 };
|
unsigned _current_quantum { 0 };
|
||||||
bool _yield = false;
|
|
||||||
unsigned const _super_period_length;
|
unsigned const _super_period_length;
|
||||||
unsigned _super_period_left { _super_period_length };
|
unsigned _super_period_left { _super_period_length };
|
||||||
unsigned const _fill;
|
unsigned const _fill;
|
||||||
bool _need_to_schedule { true };
|
|
||||||
time_t _last_time { 0 };
|
time_t _last_time { 0 };
|
||||||
|
|
||||||
template <typename F> void _for_each_prio(F f)
|
template <typename F> void _for_each_prio(F f)
|
||||||
@ -260,8 +261,10 @@ class Kernel::Cpu_scheduler
|
|||||||
*/
|
*/
|
||||||
Cpu_scheduler(Share &i, unsigned const q, unsigned const f);
|
Cpu_scheduler(Share &i, unsigned const q, unsigned const f);
|
||||||
|
|
||||||
bool need_to_schedule() { return _need_to_schedule; }
|
bool need_to_schedule() const { return _state != UP_TO_DATE; }
|
||||||
void timeout() { _need_to_schedule = true; }
|
|
||||||
|
void timeout() {
|
||||||
|
if (_state == UP_TO_DATE) _state = OUT_OF_DATE; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update state according to the current (absolute) time
|
* Update state according to the current (absolute) time
|
||||||
|
@ -265,13 +265,13 @@ void Cpu_scheduler_test::Cpu_scheduler::print(Output &output) const
|
|||||||
print(output, "(\n");
|
print(output, "(\n");
|
||||||
print(output, " quota: ", _super_period_left, "/", _super_period_length, ", ");
|
print(output, " quota: ", _super_period_left, "/", _super_period_length, ", ");
|
||||||
print(output, "fill: ", _fill, ", ");
|
print(output, "fill: ", _fill, ", ");
|
||||||
print(output, "need to schedule: ", _need_to_schedule ? "true" : "false", ", ");
|
print(output, "need to schedule: ", need_to_schedule() ? "true" : "false", ", ");
|
||||||
print(output, "last_time: ", _last_time);
|
print(output, "last_time: ", _last_time);
|
||||||
|
|
||||||
if (_current != nullptr) {
|
if (_current != nullptr) {
|
||||||
|
|
||||||
print(output, "\n current: ( ");
|
print(output, "\n current: ( ");
|
||||||
if (_need_to_schedule) {
|
if (need_to_schedule()) {
|
||||||
print(output, "\033[31m");
|
print(output, "\033[31m");
|
||||||
} else {
|
} else {
|
||||||
print(output, "\033[32m");
|
print(output, "\033[32m");
|
||||||
@ -280,7 +280,7 @@ void Cpu_scheduler_test::Cpu_scheduler::print(Output &output) const
|
|||||||
print(output, "quota: ", _current_quantum, ", ");
|
print(output, "quota: ", _current_quantum, ", ");
|
||||||
print(output, "\033[0m");
|
print(output, "\033[0m");
|
||||||
print(output, "claims: ", (_current && _current->_claim) ? "true" : "false", ", ");
|
print(output, "claims: ", (_current && _current->_claim) ? "true" : "false", ", ");
|
||||||
print(output, "yields: ", _yield ? "true" : "false", " ");
|
print(output, "yields: ", _state == YIELD ? "true" : "false", " ");
|
||||||
print(output, ")");
|
print(output, ")");
|
||||||
}
|
}
|
||||||
bool prios_empty { true };
|
bool prios_empty { true };
|
||||||
@ -303,7 +303,7 @@ void Cpu_scheduler_test::Cpu_scheduler::print(Output &output) const
|
|||||||
_rcl[prio].for_each([&] (Kernel::Cpu_share const &share) {
|
_rcl[prio].for_each([&] (Kernel::Cpu_share const &share) {
|
||||||
|
|
||||||
if (&share == _current && _current->_claim) {
|
if (&share == _current && _current->_claim) {
|
||||||
if (_need_to_schedule) {
|
if (need_to_schedule()) {
|
||||||
print(output, "\033[31m");
|
print(output, "\033[31m");
|
||||||
} else {
|
} else {
|
||||||
print(output, "\033[32m");
|
print(output, "\033[32m");
|
||||||
@ -343,7 +343,7 @@ void Cpu_scheduler_test::Cpu_scheduler::print(Output &output) const
|
|||||||
_fills.for_each([&] (Kernel::Cpu_share const &share) {
|
_fills.for_each([&] (Kernel::Cpu_share const &share) {
|
||||||
|
|
||||||
if (&share == _current && !_current->_claim) {
|
if (&share == _current && !_current->_claim) {
|
||||||
if (_need_to_schedule) {
|
if (need_to_schedule()) {
|
||||||
print(output, "\033[31m");
|
print(output, "\033[31m");
|
||||||
} else {
|
} else {
|
||||||
print(output, "\033[32m");
|
print(output, "\033[32m");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user