mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-22 15:02:25 +00:00
vbox: periodic timer based on absolute timestamps
Before timestamps where calculated as durations since current wakeup which introduces a systematical drift.
This commit is contained in:
parent
604f4c666b
commit
8d60bc11b5
@ -711,21 +711,20 @@ void genode_update_tsc(void (*update_func)(void), Genode::uint64_t update_us)
|
|||||||
using namespace Genode;
|
using namespace Genode;
|
||||||
using namespace Nova;
|
using namespace Nova;
|
||||||
|
|
||||||
enum { TSC_FACTOR = 1000ULL };
|
Trace::Timestamp const ticks_per_us = genode_cpu_hz() / (1000*1000);
|
||||||
|
Trace::Timestamp const ticks_per_update = ticks_per_us * update_us;
|
||||||
|
Trace::Timestamp const ticks_min_sleep = ticks_per_us * 100;
|
||||||
|
Trace::Timestamp wakeup_absolute = Trace::timestamp();
|
||||||
|
|
||||||
Genode::addr_t sem = Thread::myself()->native_thread().exc_pt_sel + Nova::SM_SEL_EC;
|
Genode::addr_t sem = Thread::myself()->native_thread().exc_pt_sel + Nova::SM_SEL_EC;
|
||||||
unsigned long tsc_khz = (genode_cpu_hz() / 1000) / TSC_FACTOR;
|
|
||||||
|
|
||||||
Trace::Timestamp us_64 = update_us;
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
update_func();
|
update_func();
|
||||||
|
|
||||||
Trace::Timestamp now = Trace::timestamp();
|
wakeup_absolute = max(wakeup_absolute + ticks_per_update,
|
||||||
|
Trace::timestamp() + ticks_min_sleep);
|
||||||
|
|
||||||
/* block until timeout fires or it gets canceled */
|
/* block until timeout fires or it gets canceled */
|
||||||
unsigned long long tsc_absolute = now + us_64 * tsc_khz;
|
Genode::uint8_t res = sm_ctrl(sem, SEMAPHORE_DOWN, wakeup_absolute);
|
||||||
Genode::uint8_t res = sm_ctrl(sem, SEMAPHORE_DOWN, tsc_absolute);
|
|
||||||
if (res != Nova::NOVA_OK && res != Nova::NOVA_TIMEOUT)
|
if (res != Nova::NOVA_OK && res != Nova::NOVA_TIMEOUT)
|
||||||
nova_die();
|
nova_die();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user