mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
base-hw: always use 'unsigned' for priorities
At some points in the code, 'signed' was used instead of the more appropriate 'unsigned' type. Ref #4217
This commit is contained in:
parent
b922dc5c10
commit
6e4ef43bf0
@ -34,7 +34,7 @@ void Cpu_scheduler::_reset_claims(unsigned const p)
|
|||||||
void Cpu_scheduler::_next_round()
|
void Cpu_scheduler::_next_round()
|
||||||
{
|
{
|
||||||
_residual = _quota;
|
_residual = _quota;
|
||||||
_for_each_prio([&] (unsigned const p) { _reset_claims(p); });
|
_for_each_prio([&] (Cpu_priority const p, bool &) { _reset_claims(p); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -90,21 +90,23 @@ void Cpu_scheduler::_head_filled(unsigned const r)
|
|||||||
|
|
||||||
bool Cpu_scheduler::_claim_for_head()
|
bool Cpu_scheduler::_claim_for_head()
|
||||||
{
|
{
|
||||||
for (signed p = Prio::MAX; p > Prio::MIN - 1; p--) {
|
bool result { false };
|
||||||
|
_for_each_prio([&] (Cpu_priority const p, bool &cancel_for_each_prio) {
|
||||||
Double_list_item<Cpu_share> *const item { _rcl[p].head() };
|
Double_list_item<Cpu_share> *const item { _rcl[p].head() };
|
||||||
|
|
||||||
if (!item)
|
if (!item)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
Cpu_share &share { item->payload() };
|
Cpu_share &share { item->payload() };
|
||||||
|
|
||||||
if (!share._claim)
|
if (!share._claim)
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
_set_head(share, share._claim, 1);
|
_set_head(share, share._claim, 1);
|
||||||
return 1;
|
result = true;
|
||||||
}
|
cancel_for_each_prio = true;
|
||||||
return 0;
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,27 +47,28 @@ class Kernel::Cpu_priority
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
enum {
|
static constexpr unsigned min() { return 0; }
|
||||||
MIN = 0,
|
static constexpr unsigned max() { return cpu_priorities - 1; }
|
||||||
MAX = cpu_priorities - 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct priority with value 'v'
|
* Construct priority with value 'v'
|
||||||
*/
|
*/
|
||||||
Cpu_priority(signed const v) : _value(Genode::min(v, MAX)) { }
|
Cpu_priority(unsigned const v)
|
||||||
|
:
|
||||||
|
_value { Genode::min(v, max()) }
|
||||||
|
{ }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Standard operators
|
* Standard operators
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Cpu_priority &operator =(signed const v)
|
Cpu_priority &operator =(unsigned const v)
|
||||||
{
|
{
|
||||||
_value = Genode::min(v, MAX);
|
_value = Genode::min(v, max());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
operator signed() const { return _value; }
|
operator unsigned() const { return _value; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ class Kernel::Cpu_share
|
|||||||
|
|
||||||
Double_list_item<Cpu_share> _fill_item { *this };
|
Double_list_item<Cpu_share> _fill_item { *this };
|
||||||
Double_list_item<Cpu_share> _claim_item { *this };
|
Double_list_item<Cpu_share> _claim_item { *this };
|
||||||
signed const _prio;
|
Cpu_priority const _prio;
|
||||||
unsigned _quota;
|
unsigned _quota;
|
||||||
unsigned _claim;
|
unsigned _claim;
|
||||||
unsigned _fill { 0 };
|
unsigned _fill { 0 };
|
||||||
@ -93,7 +94,7 @@ class Kernel::Cpu_share
|
|||||||
* \param p claimed priority
|
* \param p claimed priority
|
||||||
* \param q claimed quota
|
* \param q claimed quota
|
||||||
*/
|
*/
|
||||||
Cpu_share(signed const p, unsigned const q)
|
Cpu_share(Cpu_priority const p, unsigned const q)
|
||||||
: _prio(p), _quota(q), _claim(q) { }
|
: _prio(p), _quota(q), _claim(q) { }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -111,8 +112,8 @@ class Kernel::Cpu_scheduler
|
|||||||
typedef Cpu_share Share;
|
typedef Cpu_share Share;
|
||||||
typedef Cpu_priority Prio;
|
typedef Cpu_priority Prio;
|
||||||
|
|
||||||
Double_list<Cpu_share> _rcl[Prio::MAX + 1]; /* ready claims */
|
Double_list<Cpu_share> _rcl[Prio::max() + 1]; /* ready claims */
|
||||||
Double_list<Cpu_share> _ucl[Prio::MAX + 1]; /* unready claims */
|
Double_list<Cpu_share> _ucl[Prio::max() + 1]; /* unready claims */
|
||||||
Double_list<Cpu_share> _fills { }; /* ready fills */
|
Double_list<Cpu_share> _fills { }; /* ready fills */
|
||||||
Share &_idle;
|
Share &_idle;
|
||||||
Share *_head = nullptr;
|
Share *_head = nullptr;
|
||||||
@ -125,8 +126,15 @@ class Kernel::Cpu_scheduler
|
|||||||
bool _need_to_schedule { true };
|
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)
|
||||||
for (signed p = Prio::MAX; p > Prio::MIN - 1; p--) { f(p); } }
|
{
|
||||||
|
bool cancel_for_each_prio { false };
|
||||||
|
for (unsigned p = Prio::max(); p != Prio::min() - 1; p--) {
|
||||||
|
f(p, cancel_for_each_prio);
|
||||||
|
if (cancel_for_each_prio)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void _reset(Cpu_share &share);
|
static void _reset(Cpu_share &share);
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
|
|||||||
* \param label debugging label
|
* \param label debugging label
|
||||||
*/
|
*/
|
||||||
Thread(char const * const label)
|
Thread(char const * const label)
|
||||||
: Thread(Cpu_priority::MIN, 0, label, true) { }
|
: Thread(Cpu_priority::min(), 0, label, true) { }
|
||||||
|
|
||||||
~Thread();
|
~Thread();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ class Genode::Platform_thread : Noncopyable
|
|||||||
|
|
||||||
unsigned _scale_priority(unsigned virt_prio)
|
unsigned _scale_priority(unsigned virt_prio)
|
||||||
{
|
{
|
||||||
return Cpu_session::scale_priority(Kernel::Cpu_priority::MAX,
|
return Cpu_session::scale_priority(Kernel::Cpu_priority::max(),
|
||||||
virt_prio);
|
virt_prio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Kernel::Vm::Vm(unsigned,
|
|||||||
Identity & id)
|
Identity & id)
|
||||||
:
|
:
|
||||||
Kernel::Object { *this },
|
Kernel::Object { *this },
|
||||||
Cpu_job(Cpu_priority::MIN, 0),
|
Cpu_job(Cpu_priority::min(), 0),
|
||||||
_state(state),
|
_state(state),
|
||||||
_context(context),
|
_context(context),
|
||||||
_id(id),
|
_id(id),
|
||||||
|
@ -140,7 +140,7 @@ Kernel::Vm::Vm(unsigned cpu,
|
|||||||
Identity & id)
|
Identity & id)
|
||||||
:
|
:
|
||||||
Kernel::Object { *this },
|
Kernel::Object { *this },
|
||||||
Cpu_job(Cpu_priority::MIN, 0),
|
Cpu_job(Cpu_priority::min(), 0),
|
||||||
_state(state),
|
_state(state),
|
||||||
_context(context),
|
_context(context),
|
||||||
_id(id),
|
_id(id),
|
||||||
|
@ -115,7 +115,7 @@ Vm::Vm(unsigned cpu,
|
|||||||
Identity & id)
|
Identity & id)
|
||||||
:
|
:
|
||||||
Kernel::Object { *this },
|
Kernel::Object { *this },
|
||||||
Cpu_job(Cpu_priority::MIN, 0),
|
Cpu_job(Cpu_priority::min(), 0),
|
||||||
_state(state),
|
_state(state),
|
||||||
_context(context),
|
_context(context),
|
||||||
_id(id),
|
_id(id),
|
||||||
|
Loading…
Reference in New Issue
Block a user