mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-20 16:10:29 +00:00
Move timer from os to base repository
Since the timer and timeout handling is part of the base library (the dynamic linker), it belongs to the base repository. Besides moving the timer and its related infrastructure (alarm, timeout libs, tests) to the base repository, this patch also moves the timer from the 'drivers' subdirectory directly to 'src' and disamibuates the timer's build locations for the various kernels. Otherwise the different timer implementations could interfere with each other when using one build directory with multiple kernels. Note that this patch changes the include paths for the former os/timer, os/alarm.h, os/duration.h, and os/timed_semaphore.h to base/. Issue #3101
This commit is contained in:
5
repos/base-nova/src/timer/nova/target.mk
Normal file
5
repos/base-nova/src/timer/nova/target.mk
Normal file
@ -0,0 +1,5 @@
|
||||
TARGET = nova_timer_drv
|
||||
INC_DIR += $(PRG_DIR)
|
||||
SRC_CC += time_source.cc
|
||||
|
||||
include $(call select_from_repositories,src/timer/target.inc)
|
81
repos/base-nova/src/timer/nova/time_source.cc
Normal file
81
repos/base-nova/src/timer/nova/time_source.cc
Normal file
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* \brief Time source using Nova timed semaphore down
|
||||
* \author Alexander Boettcher
|
||||
* \author Martin Stein
|
||||
* \date 2014-06-24
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2017 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.
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
|
||||
/* NOVA includes */
|
||||
#include <nova/native_thread.h>
|
||||
|
||||
/* local includes */
|
||||
#include <time_source.h>
|
||||
|
||||
using namespace Genode;
|
||||
using namespace Nova;
|
||||
|
||||
|
||||
Timer::Time_source::Time_source(Env &env) : Threaded_time_source(env)
|
||||
{
|
||||
/* read out the tsc frequency once */
|
||||
Attached_rom_dataspace const platform_info { env, "platform_info" };
|
||||
Xml_node const hardware = platform_info.xml().sub_node("hardware");
|
||||
hardware.sub_node("tsc").attribute("freq_khz").value(&_tsc_khz);
|
||||
|
||||
start();
|
||||
}
|
||||
|
||||
|
||||
void Timer::Time_source::schedule_timeout(Microseconds duration,
|
||||
Timeout_handler &handler)
|
||||
{
|
||||
Threaded_time_source::handler(handler);
|
||||
|
||||
/* check whether to cancel last timeout */
|
||||
if (duration.value == 0 && _sem != ~0UL) {
|
||||
uint8_t res = Nova::sm_ctrl(_sem, Nova::SEMAPHORE_UP);
|
||||
if (res != Nova::NOVA_OK)
|
||||
nova_die();
|
||||
}
|
||||
/* remember timeout to be set during wait_for_timeout call */
|
||||
_timeout_us = duration.value;
|
||||
}
|
||||
|
||||
|
||||
void Timer::Time_source::_wait_for_irq()
|
||||
{
|
||||
if (_sem == ~0UL) {
|
||||
_sem = Thread::native_thread().exc_pt_sel + SM_SEL_EC; }
|
||||
|
||||
addr_t sem = _sem;
|
||||
|
||||
/* calculate absolute timeout */
|
||||
Trace::Timestamp now = Trace::timestamp();
|
||||
Trace::Timestamp us_64 = _timeout_us;
|
||||
|
||||
if (_timeout_us == max_timeout().value) {
|
||||
|
||||
/* tsc_absolute == 0 means blocking without timeout */
|
||||
uint8_t res = sm_ctrl(sem, SEMAPHORE_DOWN, 0);
|
||||
if (res != Nova::NOVA_OK && res != Nova::NOVA_TIMEOUT) {
|
||||
nova_die(); }
|
||||
|
||||
} else {
|
||||
|
||||
/* block until timeout fires or it gets canceled */
|
||||
unsigned long long tsc_absolute = now + us_64 * (_tsc_khz / TSC_FACTOR);
|
||||
uint8_t res = sm_ctrl(sem, SEMAPHORE_DOWN, tsc_absolute);
|
||||
if (res != Nova::NOVA_OK && res != Nova::NOVA_TIMEOUT) {
|
||||
nova_die(); }
|
||||
}
|
||||
}
|
88
repos/base-nova/src/timer/nova/time_source.h
Normal file
88
repos/base-nova/src/timer/nova/time_source.h
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* \brief Time source using Nova timed semaphore down
|
||||
* \author Alexander Boettcher
|
||||
* \author Martin Stein
|
||||
* \date 2014-06-24
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2017 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.
|
||||
*/
|
||||
|
||||
#ifndef _TIME_SOURCE_H_
|
||||
#define _TIME_SOURCE_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <trace/timestamp.h>
|
||||
|
||||
/* local includes */
|
||||
#include <threaded_time_source.h>
|
||||
|
||||
namespace Timer { class Time_source; }
|
||||
|
||||
|
||||
class Timer::Time_source : public Threaded_time_source
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::addr_t _sem { ~0UL };
|
||||
unsigned long _timeout_us { 0 };
|
||||
unsigned long _tsc_khz { 0 };
|
||||
Duration _curr_time { Microseconds(0) };
|
||||
Genode::Trace::Timestamp _tsc_start { Genode::Trace::timestamp() };
|
||||
Genode::Trace::Timestamp _tsc_last { _tsc_start };
|
||||
|
||||
/* 1 / ((us / (1000 * 1000)) * (tsc_khz * 1000)) */
|
||||
enum { TSC_FACTOR = 1000ULL };
|
||||
|
||||
inline Genode::uint64_t _tsc_to_us(Genode::uint64_t tsc) const
|
||||
{
|
||||
return (tsc) / (_tsc_khz / TSC_FACTOR);
|
||||
}
|
||||
|
||||
|
||||
/**************************
|
||||
** Threaded_time_source **
|
||||
**************************/
|
||||
|
||||
void _wait_for_irq();
|
||||
|
||||
public:
|
||||
|
||||
Time_source(Genode::Env &env);
|
||||
|
||||
|
||||
/*************************
|
||||
** Genode::Time_source **
|
||||
*************************/
|
||||
|
||||
void schedule_timeout(Microseconds duration,
|
||||
Timeout_handler &handler) override;
|
||||
|
||||
Microseconds max_timeout() const override
|
||||
{
|
||||
unsigned long long const max_us_ull = _tsc_to_us(~0ULL);
|
||||
return max_us_ull > ~0UL ? Microseconds(~0UL) : Microseconds(max_us_ull);
|
||||
}
|
||||
|
||||
Duration curr_time() override
|
||||
{
|
||||
using namespace Genode::Trace;
|
||||
|
||||
Timestamp const curr_tsc = timestamp();
|
||||
Microseconds const diff(_tsc_to_us(curr_tsc - _tsc_last));
|
||||
|
||||
/* update in irq context or if update rate is below 4000 irq/s */
|
||||
if (_irq || diff.value > 250) {
|
||||
_curr_time.add(diff);
|
||||
_tsc_last = curr_tsc;
|
||||
}
|
||||
|
||||
return _curr_time;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* _TIME_SOURCE_H_ */
|
Reference in New Issue
Block a user