From d8211b65a544fd4e85a9a9d098fb9fe51bef2b2a Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Fri, 8 Apr 2022 18:07:28 +0200 Subject: [PATCH] dde_rump: fix clock functions Issue #4459 --- repos/dde_rump/src/include/rump/env.h | 2 ++ .../dde_rump/src/include/util/hard_context.h | 8 +---- repos/dde_rump/src/lib/rump/hypercall.cc | 30 +++++++++---------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/repos/dde_rump/src/include/rump/env.h b/repos/dde_rump/src/include/rump/env.h index bf2c86dd49..02c44be17d 100644 --- a/repos/dde_rump/src/include/rump/env.h +++ b/repos/dde_rump/src/include/rump/env.h @@ -38,6 +38,7 @@ class Rump::Env Genode::Attached_rom_dataspace _config { _env, "config" }; Genode::Thread const *_ep_thread { Genode::Thread::myself() }; Timer::Connection _timer { _env }; + Timed_semaphore _sleep_sem { _env, _ep_thread, _timer }; public: @@ -48,6 +49,7 @@ class Rump::Env Genode::Attached_rom_dataspace &config_rom() { return _config; } Genode::Thread const *ep_thread() { return _ep_thread; } Timer::Connection &timer() { return _timer; } + Timed_semaphore &sleep_sem() { return _sleep_sem; } }; /** diff --git a/repos/dde_rump/src/include/util/hard_context.h b/repos/dde_rump/src/include/util/hard_context.h index af8f2cebe1..035bd6fb30 100644 --- a/repos/dde_rump/src/include/util/hard_context.h +++ b/repos/dde_rump/src/include/util/hard_context.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2014-2017 Genode Labs GmbH + * Copyright (C) 2014-2022 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -32,10 +32,6 @@ extern "C" { typedef void *(*func)(void *); -namespace Timer { - class Connection; -}; - class Hard_context : public Genode::Avl_node { @@ -57,8 +53,6 @@ class Hard_context : public Genode::Avl_node void set_lwp(lwp *l) { _lwp = l; } lwp *get_lwp() { return _lwp; } - static Timer::Connection &timer(); - bool higher(Hard_context *h) { return _myself > h->_myself; } Hard_context *find(Genode::Thread const *t) diff --git a/repos/dde_rump/src/lib/rump/hypercall.cc b/repos/dde_rump/src/lib/rump/hypercall.cc index 1ccf576571..ff6cf13bfa 100644 --- a/repos/dde_rump/src/lib/rump/hypercall.cc +++ b/repos/dde_rump/src/lib/rump/hypercall.cc @@ -6,7 +6,7 @@ */ /* - * Copyright (C) 2013-2017 Genode Labs GmbH + * Copyright (C) 2013-2022 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -52,13 +53,6 @@ static Hard_context *myself() } -Timer::Connection &Hard_context::timer() -{ - static Timer::Connection _timer { Rump::env().env() }; - return _timer; -} - - void rumpuser_curlwpop(int enum_rumplwpop, struct lwp *l) { Hard_context *h = myself(); @@ -300,10 +294,9 @@ void rumpuser_free(void *mem, size_t len) int rumpuser_clock_gettime(int enum_rumpclock, int64_t *sec, long *nsec) { - Hard_context *h = myself(); - Genode::uint64_t t = h->timer().elapsed_ms(); + Genode::uint64_t t = Rump::env().timer().elapsed_ms(); *sec = (int64_t)t / 1000; - *nsec = (t % 1000) * 1000; + *nsec = (t % 1000) * 1000 * 1000; return 0; } @@ -313,20 +306,25 @@ int rumpuser_clock_sleep(int enum_rumpclock, int64_t sec, long nsec) int nlocks; Genode::uint64_t msec = 0; - Timer::Connection &timer = myself()->timer(); - rumpkern_unsched(&nlocks, 0); switch (enum_rumpclock) { case RUMPUSER_CLOCK_RELWALL: msec = (Genode::uint64_t)sec * 1000 + nsec / (1000*1000UL); break; case RUMPUSER_CLOCK_ABSMONO: - msec = timer.elapsed_ms(); - msec = (((Genode::uint64_t)sec * 1000) + ((Genode::uint64_t)nsec / (1000 * 1000))) - msec; + Genode::uint64_t target_abs_msec = + (((Genode::uint64_t)sec * 1000) + + ((Genode::uint64_t)nsec / (1000 * 1000))); + Genode::uint64_t current_abs_msec = Rump::env().timer().elapsed_ms(); + + if (target_abs_msec > current_abs_msec) + msec = target_abs_msec - current_abs_msec; + break; } - timer.msleep(msec); + Rump::env().sleep_sem().down(true, Genode::Microseconds(msec * 1000)); + rumpkern_sched(nlocks, 0); return 0; }