From 847c8cccd986996959688f6626850ac8ebc5698a Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 25 Jul 2012 13:59:50 +0200 Subject: [PATCH] Add 'Timer::Session::elapsed_ms' function This function allows a timer-session client to request a wall-clock time value from the timer. --- os/include/timer_session/client.h | 2 ++ os/include/timer_session/timer_session.h | 14 +++++++++++++- .../timer/foc/timer_session_component.h | 19 ++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/os/include/timer_session/client.h b/os/include/timer_session/client.h index 2806632d7..1a240f59e 100644 --- a/os/include/timer_session/client.h +++ b/os/include/timer_session/client.h @@ -25,6 +25,8 @@ namespace Timer { : Genode::Rpc_client(session) { } void msleep(unsigned ms) { call(ms); } + + unsigned long elapsed_ms() const { return call(); } }; } diff --git a/os/include/timer_session/timer_session.h b/os/include/timer_session/timer_session.h index 9d160243d..58e9cac41 100644 --- a/os/include/timer_session/timer_session.h +++ b/os/include/timer_session/timer_session.h @@ -29,14 +29,26 @@ namespace Timer { */ virtual void msleep(unsigned ms) = 0; + /** + * Return number of elapsed milliseconds since session creation + */ + virtual unsigned long elapsed_ms() const + { + /* + * XXX Remove default implementation by implementing the + * interface in all timer variants. + */ + return 0; } + /********************* ** RPC declaration ** *********************/ GENODE_RPC(Rpc_msleep, void, msleep, unsigned); + GENODE_RPC(Rpc_elapsed_ms, unsigned long, elapsed_ms); - GENODE_RPC_INTERFACE(Rpc_msleep); + GENODE_RPC_INTERFACE(Rpc_msleep, Rpc_elapsed_ms); }; } diff --git a/os/src/drivers/timer/foc/timer_session_component.h b/os/src/drivers/timer/foc/timer_session_component.h index 9f9812c86..761f34322 100644 --- a/os/src/drivers/timer/foc/timer_session_component.h +++ b/os/src/drivers/timer/foc/timer_session_component.h @@ -18,10 +18,12 @@ /* Genode includes */ #include #include +#include /* Fiasco.OC includes */ namespace Fiasco { #include +#include } @@ -63,8 +65,11 @@ namespace Timer { { private: - Genode::Rpc_entrypoint _entrypoint; - Session_capability _session_cap; + Genode::Rpc_entrypoint _entrypoint; + Session_capability _session_cap; + Genode::Attached_rom_dataspace _kip_ds; + Fiasco::l4_kernel_info_t * const _kip; + Fiasco::l4_cpu_time_t const _initial_clock_value; public: @@ -74,7 +79,10 @@ namespace Timer { Session_component(Genode::Cap_session *cap) : _entrypoint(cap, STACK_SIZE, "timer_session_ep"), - _session_cap(_entrypoint.manage(this)) + _session_cap(_entrypoint.manage(this)), + _kip_ds("l4v2_kip"), + _kip(_kip_ds.local_addr()), + _initial_clock_value(_kip->clock) { } /** @@ -109,6 +117,11 @@ namespace Timer { l4_ipc_sleep(l4_timeout(L4_IPC_TIMEOUT_NEVER, mus_to_timeout(1000*ms))); } + + unsigned long elapsed_ms() const + { + return (_kip->clock - _initial_clock_value) / 1000; + } }; }