mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-17 06:38:28 +00:00
timeout: use uint64_t for all plain time values
This enforces the use of unsigned 64-bit values for time in the duration type, the timeout framework, the timer session, the userland timer-drivers, and the alarm framework on all platforms. The commit also adapts the code that uses these tools accross all basic repositories (base, base-*, os. gems, libports, ports, dde_*) to use unsigned 64-bit values for time as well as far as this does not imply profound modifications. Fixes #3208
This commit is contained in:
committed by
Christian Helmuth
parent
e072ee480b
commit
181c78d482
@ -41,16 +41,17 @@ namespace Fiasco {
|
||||
using namespace Fiasco;
|
||||
using Microseconds = Genode::Microseconds;
|
||||
using Duration = Genode::Duration;
|
||||
using Genode::uint64_t;
|
||||
|
||||
|
||||
static l4_timeout_s mus_to_timeout(unsigned long mus)
|
||||
static l4_timeout_s mus_to_timeout(uint64_t mus)
|
||||
{
|
||||
if (mus == 0)
|
||||
return L4_IPC_TIMEOUT_0;
|
||||
else if (mus == ~0UL)
|
||||
else if (mus == ~(uint64_t)0)
|
||||
return L4_IPC_TIMEOUT_NEVER;
|
||||
|
||||
long e = Genode::log2(mus) - 7;
|
||||
long e = Genode::log2((unsigned long)mus) - 7;
|
||||
unsigned long m;
|
||||
if (e < 0) e = 0;
|
||||
m = mus / (1UL << e);
|
||||
@ -89,5 +90,5 @@ Duration Timer::Time_source::curr_time()
|
||||
}
|
||||
|
||||
|
||||
void Timer::Time_source::_usleep(unsigned long usecs) {
|
||||
void Timer::Time_source::_usleep(uint64_t usecs) {
|
||||
l4_ipc_sleep(l4_timeout(L4_IPC_TIMEOUT_NEVER, mus_to_timeout(usecs))); }
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
namespace Timer {
|
||||
|
||||
using Genode::uint64_t;
|
||||
using Microseconds = Genode::Microseconds;
|
||||
using Duration = Genode::Duration;
|
||||
class Session_component;
|
||||
@ -43,7 +44,7 @@ class Timer::Session_component : public Genode::Rpc_object<Session>,
|
||||
Genode::Timeout_scheduler &_timeout_scheduler;
|
||||
Genode::Signal_context_capability _sigh { };
|
||||
|
||||
unsigned long const _init_time_us =
|
||||
uint64_t const _init_time_us =
|
||||
_timeout_scheduler.curr_time().trunc_to_plain_us().value;
|
||||
|
||||
void handle_timeout(Duration) override {
|
||||
@ -59,7 +60,7 @@ class Timer::Session_component : public Genode::Rpc_object<Session>,
|
||||
** Timer::Session **
|
||||
********************/
|
||||
|
||||
void trigger_once(unsigned us) override {
|
||||
void trigger_once(uint64_t us) override {
|
||||
|
||||
/*
|
||||
* FIXME Workaround for the problem that Alarm scheduler may
|
||||
@ -70,11 +71,11 @@ class Timer::Session_component : public Genode::Rpc_object<Session>,
|
||||
* Alarm framework takes solely relative time values, please
|
||||
* remove this.
|
||||
*/
|
||||
Microseconds typed_us((us > ~0U >> 1) ? ~0U >> 1 : us);
|
||||
Microseconds typed_us((us > ~(uint64_t)0 >> 1) ? ~(uint64_t)0 >> 1 : us);
|
||||
_timeout.schedule_one_shot(typed_us, *this);
|
||||
}
|
||||
|
||||
void trigger_periodic(unsigned us) override {
|
||||
void trigger_periodic(uint64_t us) override {
|
||||
_timeout.schedule_periodic(Microseconds(us), *this); }
|
||||
|
||||
void sigh(Signal_context_capability sigh) override
|
||||
@ -84,15 +85,15 @@ class Timer::Session_component : public Genode::Rpc_object<Session>,
|
||||
_timeout.discard();
|
||||
}
|
||||
|
||||
unsigned long elapsed_ms() const override {
|
||||
uint64_t elapsed_ms() const override {
|
||||
return elapsed_us() / 1000; }
|
||||
|
||||
unsigned long elapsed_us() const override {
|
||||
uint64_t elapsed_us() const override {
|
||||
return _timeout_scheduler.curr_time().trunc_to_plain_us().value -
|
||||
_init_time_us; }
|
||||
|
||||
void msleep(unsigned) override { /* never called at the server side */ }
|
||||
void usleep(unsigned) override { /* never called at the server side */ }
|
||||
void msleep(uint64_t) override { /* never called at the server side */ }
|
||||
void usleep(uint64_t) override { /* never called at the server side */ }
|
||||
};
|
||||
|
||||
#endif /* _SESSION_COMPONENT_ */
|
||||
|
@ -29,8 +29,8 @@ void Timer::Time_source::schedule_timeout(Microseconds duration,
|
||||
|
||||
void Timer::Time_source::_wait_for_irq()
|
||||
{
|
||||
enum { SLEEP_GRANULARITY_US = 1000UL };
|
||||
unsigned long last_time_us = curr_time().trunc_to_plain_us().value;
|
||||
enum { SLEEP_GRANULARITY_US = 1000 };
|
||||
uint64_t last_time_us = curr_time().trunc_to_plain_us().value;
|
||||
_lock.lock();
|
||||
while (_next_timeout_us > 0) {
|
||||
_lock.unlock();
|
||||
@ -38,8 +38,8 @@ void Timer::Time_source::_wait_for_irq()
|
||||
try { _usleep(SLEEP_GRANULARITY_US); }
|
||||
catch (Blocking_canceled) { }
|
||||
|
||||
unsigned long curr_time_us = curr_time().trunc_to_plain_us().value;
|
||||
unsigned long sleep_duration_us = curr_time_us - last_time_us;
|
||||
uint64_t curr_time_us = curr_time().trunc_to_plain_us().value;
|
||||
uint64_t sleep_duration_us = curr_time_us - last_time_us;
|
||||
last_time_us = curr_time_us;
|
||||
|
||||
_lock.lock();
|
||||
|
@ -18,7 +18,11 @@
|
||||
/* local includes */
|
||||
#include <threaded_time_source.h>
|
||||
|
||||
namespace Timer { class Time_source; }
|
||||
namespace Timer {
|
||||
|
||||
using Genode::uint64_t;
|
||||
class Time_source;
|
||||
}
|
||||
|
||||
|
||||
class Timer::Time_source : public Threaded_time_source
|
||||
@ -28,10 +32,10 @@ class Timer::Time_source : public Threaded_time_source
|
||||
Genode::Env &_env;
|
||||
|
||||
Genode::Lock mutable _lock { };
|
||||
unsigned long _curr_time_us = 0;
|
||||
unsigned long _next_timeout_us = max_timeout().value;
|
||||
uint64_t _curr_time_us = 0;
|
||||
uint64_t _next_timeout_us = max_timeout().value;
|
||||
|
||||
void _usleep(unsigned long us);
|
||||
void _usleep(uint64_t us);
|
||||
|
||||
|
||||
/**************************
|
||||
|
@ -53,7 +53,7 @@ void Timer::Time_source::schedule_timeout(Microseconds duration,
|
||||
Timeout_handler &handler)
|
||||
{
|
||||
_handler = &handler;
|
||||
unsigned long duration_us = duration.value;
|
||||
uint64_t duration_us = duration.value;
|
||||
|
||||
/* timeout '0' is trigger to cancel the current pending, if required */
|
||||
if (!duration.value) {
|
||||
@ -62,8 +62,8 @@ void Timer::Time_source::schedule_timeout(Microseconds duration,
|
||||
} else {
|
||||
/* limit timer-interrupt rate */
|
||||
enum { MAX_TIMER_IRQS_PER_SECOND = 4*1000 };
|
||||
if (duration_us < 1000 * 1000 / MAX_TIMER_IRQS_PER_SECOND)
|
||||
duration_us = 1000 * 1000 / MAX_TIMER_IRQS_PER_SECOND;
|
||||
if (duration_us < (uint64_t)1000 * 1000 / MAX_TIMER_IRQS_PER_SECOND)
|
||||
duration_us = (uint64_t)1000 * 1000 / MAX_TIMER_IRQS_PER_SECOND;
|
||||
|
||||
if (duration_us > max_timeout().value)
|
||||
duration_us = max_timeout().value;
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
namespace Timer {
|
||||
|
||||
using Genode::uint64_t;
|
||||
using Microseconds = Genode::Microseconds;
|
||||
using Duration = Genode::Duration;
|
||||
class Time_source;
|
||||
@ -70,7 +71,7 @@ class Timer::Time_source : public Genode::Signalled_time_source
|
||||
|
||||
Genode::Io_port_connection _io_port;
|
||||
Genode::Irq_connection _timer_irq;
|
||||
unsigned long mutable _curr_time_us = 0;
|
||||
uint64_t mutable _curr_time_us = 0;
|
||||
Genode::uint16_t mutable _counter_init_value = 0;
|
||||
bool mutable _handled_wrap = false;
|
||||
|
||||
|
Reference in New Issue
Block a user