mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 15:43:56 +00:00
timer connection: always work with microseconds
As the timer session now provides a method 'elapsed_us', there is no more need for doing any internal calculations with values of milliseconds. Ref #2400
This commit is contained in:
committed by
Christian Helmuth
parent
8750e373a0
commit
6dfb903bd0
@ -197,9 +197,9 @@ class Timer::Connection : public Genode::Connection<Session>,
|
|||||||
|
|
||||||
Timeout_handler *_handler { nullptr };
|
Timeout_handler *_handler { nullptr };
|
||||||
Lock _real_time_lock { Lock::UNLOCKED };
|
Lock _real_time_lock { Lock::UNLOCKED };
|
||||||
unsigned long _ms { elapsed_ms() };
|
unsigned long _us { elapsed_us() };
|
||||||
Timestamp _ts { _timestamp() };
|
Timestamp _ts { _timestamp() };
|
||||||
Duration _real_time { Milliseconds(_ms) };
|
Duration _real_time { Microseconds(_us) };
|
||||||
Duration _interpolated_time { _real_time };
|
Duration _interpolated_time { _real_time };
|
||||||
unsigned _interpolation_quality { 0 };
|
unsigned _interpolation_quality { 0 };
|
||||||
unsigned long _us_to_ts_factor { 1UL };
|
unsigned long _us_to_ts_factor { 1UL };
|
||||||
|
@ -28,5 +28,5 @@ void Timer::Connection::_update_real_time() { }
|
|||||||
|
|
||||||
Duration Timer::Connection::curr_time()
|
Duration Timer::Connection::curr_time()
|
||||||
{
|
{
|
||||||
return Duration(Milliseconds(elapsed_ms()));
|
return Duration(Microseconds(elapsed_us()));
|
||||||
}
|
}
|
||||||
|
@ -87,12 +87,12 @@ Duration Timer::Connection::_update_interpolated_time(Duration &interpolated_tim
|
|||||||
|
|
||||||
void Timer::Connection::_handle_timeout()
|
void Timer::Connection::_handle_timeout()
|
||||||
{
|
{
|
||||||
unsigned long const ms = elapsed_ms();
|
unsigned long const us = elapsed_us();
|
||||||
if (ms - _ms > REAL_TIME_UPDATE_PERIOD_US / 1000UL) {
|
if (us - _us > REAL_TIME_UPDATE_PERIOD_US) {
|
||||||
_update_real_time();
|
_update_real_time();
|
||||||
}
|
}
|
||||||
if (_handler) {
|
if (_handler) {
|
||||||
_handler->handle_timeout(Duration(Milliseconds(ms)));
|
_handler->handle_timeout(Duration(Microseconds(us)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ void Timer::Connection::_update_real_time()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Timestamp ts = 0UL;
|
Timestamp ts = 0UL;
|
||||||
unsigned long ms = 0UL;
|
unsigned long us = 0UL;
|
||||||
unsigned long latency_us = ~0UL;
|
unsigned long latency_us = ~0UL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -43,14 +43,14 @@ void Timer::Connection::_update_real_time()
|
|||||||
{
|
{
|
||||||
/* read out the two time values close in succession */
|
/* read out the two time values close in succession */
|
||||||
Timestamp volatile new_ts = _timestamp();
|
Timestamp volatile new_ts = _timestamp();
|
||||||
unsigned long volatile new_ms = elapsed_ms();
|
unsigned long volatile new_us = elapsed_us();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If interpolation is not ready, yet we cannot determine a latency
|
* If interpolation is not ready, yet we cannot determine a latency
|
||||||
* and take the values as they are.
|
* and take the values as they are.
|
||||||
*/
|
*/
|
||||||
if (_interpolation_quality < MAX_INTERPOLATION_QUALITY) {
|
if (_interpolation_quality < MAX_INTERPOLATION_QUALITY) {
|
||||||
ms = new_ms;
|
us = new_us;
|
||||||
ts = new_ts;
|
ts = new_ts;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ void Timer::Connection::_update_real_time()
|
|||||||
|
|
||||||
/* remember results if the latency was better than on the last trial */
|
/* remember results if the latency was better than on the last trial */
|
||||||
if (new_latency_us < latency_us) {
|
if (new_latency_us < latency_us) {
|
||||||
ms = new_ms;
|
us = new_us;
|
||||||
ts = new_ts;
|
ts = new_ts;
|
||||||
|
|
||||||
/* take the results if the latency fulfills the given maximum */
|
/* take the results if the latency fulfills the given maximum */
|
||||||
@ -72,13 +72,13 @@ void Timer::Connection::_update_real_time()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* determine timestamp and time difference */
|
/* determine timestamp and time difference */
|
||||||
unsigned long const ms_diff = ms - _ms;
|
unsigned long const us_diff = us - _us;
|
||||||
Timestamp ts_diff = ts - _ts;
|
Timestamp ts_diff = ts - _ts;
|
||||||
|
|
||||||
/* overwrite timestamp, time, and real time member */
|
/* overwrite timestamp, time, and real time member */
|
||||||
_ms = ms;
|
_us = us;
|
||||||
_ts = ts;
|
_ts = ts;
|
||||||
_real_time += Milliseconds(ms_diff);
|
_real_time += Microseconds(us_diff);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -89,7 +89,6 @@ void Timer::Connection::_update_real_time()
|
|||||||
|
|
||||||
unsigned factor_shift = _us_to_ts_factor_shift;
|
unsigned factor_shift = _us_to_ts_factor_shift;
|
||||||
unsigned long old_factor = _us_to_ts_factor;
|
unsigned long old_factor = _us_to_ts_factor;
|
||||||
unsigned long const us_diff = ms_diff * 1000UL;
|
|
||||||
Timestamp max_ts_diff = ~(Timestamp)0ULL >> factor_shift;
|
Timestamp max_ts_diff = ~(Timestamp)0ULL >> factor_shift;
|
||||||
Timestamp min_ts_diff_shifted = ~(Timestamp)0ULL >> 1;
|
Timestamp min_ts_diff_shifted = ~(Timestamp)0ULL >> 1;
|
||||||
|
|
||||||
@ -204,7 +203,7 @@ Duration Timer::Connection::curr_time()
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* use remote timer instead of timestamps */
|
/* use remote timer instead of timestamps */
|
||||||
interpolated_time += Milliseconds(elapsed_ms() - _ms);
|
interpolated_time += Microseconds(elapsed_us() - _us);
|
||||||
|
|
||||||
lock_guard.destruct();
|
lock_guard.destruct();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user