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:
@@ -8,4 +8,4 @@ LIBS += alarm
|
||||
|
||||
INC_DIR += $(BASE_DIR)/src/include
|
||||
|
||||
vpath % $(BASE_DIR)/../os/src/lib/timeout
|
||||
vpath % $(BASE_DIR)/src/lib/timeout
|
||||
|
||||
@@ -5,27 +5,12 @@ content: src/bootstrap
|
||||
src/bootstrap:
|
||||
$(mirror_from_rep_dir)
|
||||
|
||||
|
||||
TIMER_SRC := main.cc target.inc hw include
|
||||
|
||||
content: src/drivers/timer
|
||||
src/drivers/timer:
|
||||
mkdir -p $@
|
||||
cp -r $(addprefix $(GENODE_DIR)/repos/os/$@/,$(TIMER_SRC)) $@
|
||||
|
||||
content: include/spec/x86_32/trace/timestamp.h include/spec/x86_64/trace/timestamp.h
|
||||
|
||||
include/spec/%/trace/timestamp.h:
|
||||
mkdir -p $(dir $@)
|
||||
cp $(GENODE_DIR)/repos/os/$@ $@
|
||||
|
||||
|
||||
content: generalize_target_names
|
||||
|
||||
generalize_target_names: lib/mk src/lib src/drivers/timer
|
||||
generalize_target_names: lib/mk src/lib src/timer
|
||||
for spec in arm riscv x86_64; do \
|
||||
mv lib/mk/spec/$$spec/ld-hw.mk lib/mk/spec/$$spec/ld.mk; \
|
||||
done;
|
||||
sed -i "s/ld-hw/ld/" src/lib/ld/hw/target.mk
|
||||
sed -i "s/hw_timer_drv/timer/" src/drivers/timer/hw/target.mk
|
||||
sed -i "s/hw_timer_drv/timer/" src/timer/hw/target.mk
|
||||
|
||||
|
||||
7
repos/base-hw/src/timer/hw/target.mk
Normal file
7
repos/base-hw/src/timer/hw/target.mk
Normal file
@@ -0,0 +1,7 @@
|
||||
TARGET = hw_timer_drv
|
||||
REQUIRES = hw
|
||||
LIBS = syscall-hw
|
||||
INC_DIR += $(PRG_DIR)
|
||||
SRC_CC += time_source.cc
|
||||
|
||||
include $(call select_from_repositories,src/timer/target.inc)
|
||||
69
repos/base-hw/src/timer/hw/time_source.cc
Normal file
69
repos/base-hw/src/timer/hw/time_source.cc
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* \brief Time source that uses the timeout syscalls of the HW kernel
|
||||
* \author Martin Stein
|
||||
* \date 2012-05-03
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012-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/log.h>
|
||||
#include <base/signal.h>
|
||||
#include <base/entrypoint.h>
|
||||
|
||||
/* local includes */
|
||||
#include <time_source.h>
|
||||
|
||||
/* base-hw includes */
|
||||
#include <kernel/interface.h>
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
enum { MIN_TIMEOUT_US = 1000 };
|
||||
|
||||
|
||||
Timer::Time_source::Time_source(Env &env)
|
||||
:
|
||||
Signalled_time_source(env),
|
||||
_max_timeout_us(Kernel::timeout_max_us())
|
||||
{
|
||||
if (_max_timeout_us < MIN_TIMEOUT_US) {
|
||||
error("minimum timeout greater then maximum timeout");
|
||||
throw Genode::Exception();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Timer::Time_source::schedule_timeout(Microseconds duration,
|
||||
Timeout_handler &handler)
|
||||
{
|
||||
unsigned long duration_us = duration.value;
|
||||
if (duration_us < MIN_TIMEOUT_US) {
|
||||
duration_us = MIN_TIMEOUT_US; }
|
||||
|
||||
if (duration_us > max_timeout().value) {
|
||||
duration_us = max_timeout().value; }
|
||||
|
||||
_handler = &handler;
|
||||
_last_timeout_age_us = 0;
|
||||
Signal_context_capability cap = _signal_handler;
|
||||
Kernel::timeout(duration_us, (addr_t)cap.data());
|
||||
}
|
||||
|
||||
|
||||
Duration Timer::Time_source::curr_time()
|
||||
{
|
||||
unsigned long const timeout_age_us = Kernel::timeout_age_us();
|
||||
if (timeout_age_us > _last_timeout_age_us) {
|
||||
|
||||
/* increment time by the difference since the last update */
|
||||
_curr_time.add(Microseconds(timeout_age_us - _last_timeout_age_us));
|
||||
_last_timeout_age_us = timeout_age_us;
|
||||
}
|
||||
return _curr_time;
|
||||
}
|
||||
55
repos/base-hw/src/timer/hw/time_source.h
Normal file
55
repos/base-hw/src/timer/hw/time_source.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* \brief Time source that uses the timeout syscalls of the HW kernel
|
||||
* \author Martin Stein
|
||||
* \date 2012-05-03
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2012-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 <base/duration.h>
|
||||
|
||||
/* local includes */
|
||||
#include <signalled_time_source.h>
|
||||
|
||||
namespace Timer {
|
||||
|
||||
using Microseconds = Genode::Microseconds;
|
||||
using Duration = Genode::Duration;
|
||||
class Time_source;
|
||||
}
|
||||
|
||||
|
||||
class Timer::Time_source : public Genode::Signalled_time_source
|
||||
{
|
||||
private:
|
||||
|
||||
|
||||
Duration mutable _curr_time { Microseconds(0) };
|
||||
unsigned long mutable _last_timeout_age_us = 0;
|
||||
unsigned long const _max_timeout_us;
|
||||
|
||||
public:
|
||||
|
||||
Time_source(Genode::Env &env);
|
||||
|
||||
|
||||
/*************************
|
||||
** Genode::Time_source **
|
||||
*************************/
|
||||
|
||||
Duration curr_time() override;
|
||||
void schedule_timeout(Microseconds duration, Timeout_handler &handler) override;
|
||||
Microseconds max_timeout() const override {
|
||||
return Microseconds(_max_timeout_us); };
|
||||
};
|
||||
|
||||
#endif /* _TIME_SOURCE_H_ */
|
||||
Reference in New Issue
Block a user