dde_rump: fix clock functions

Issue #4459
This commit is contained in:
Christian Prochaska 2022-04-08 18:07:28 +02:00 committed by Christian Helmuth
parent 95aba3feef
commit d8211b65a5
3 changed files with 17 additions and 23 deletions

View File

@ -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; }
};
/**

View File

@ -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<Hard_context>
{
@ -57,8 +53,6 @@ class Hard_context : public Genode::Avl_node<Hard_context>
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)

View File

@ -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 <base/log.h>
#include <base/sleep.h>
#include <rump/env.h>
#include <rump/timed_semaphore.h>
#include <util/allocator_fap.h>
#include <util/random.h>
#include <util/string.h>
@ -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;
}