16#include <sys/timerfd.h>
28 mTimerFd = timerfd_create(CLOCK_MONOTONIC, 0);
30 SPDLOG_LOGGER_ERROR(
mSLog,
"Failed to create timerfd");
34 SPDLOG_LOGGER_WARN(
mSLog,
35 "No high resolution timer available. Clock might drift!");
44 SPDLOG_LOGGER_ERROR(
mSLog,
45 "The timer was not stopped properly. The simulation "
46 "behaviour is not guaranteed anymore.");
62 SPDLOG_LOGGER_ERROR(
mSLog,
"Read from timerfd failed");
68 auto now = IntervalClock::now();
82 SPDLOG_LOGGER_WARN(
mSLog,
"Timer overrun of {} timesteps at {}",
overruns,
85 SPDLOG_LOGGER_ERROR(
mSLog,
"The overrun has made the simulation to fail "
86 "because the flag is active");
99 auto rt = StartClock::now();
100 auto steady = IntervalClock::now();
107 ?
mStartAt.time_since_epoch() - rt.time_since_epoch() +
108 steady.time_since_epoch()
109 : steady.time_since_epoch();
113 struct itimerspec ts = {.it_interval = to_timespec(
mTickInterval),
114 .it_value = to_timespec(
start)};
116 ret = timerfd_settime(mTimerFd, TFD_TIMER_ABSTIME, &ts, 0);
130 struct itimerspec ts = {.it_interval = {0, 0}, .it_value = {0, 0}};
132 ret = timerfd_settime(mTimerFd, 0, &ts, 0);
spdlog::level::level_enum Level
static Log get(const std::string &name, Level filelevel=Level::info, Level clilevel=Level::off)
IntervalTimePoint mNextTick
enum DPsim::Timer::State mState
void start()
Start real-time timer.
void start(const StartTimePoint &startAt)
const long long & overruns()
std::chrono::time_point< StartClock, Ticks > StartTimePoint
void stop()
Stop real-time timer.
CPS::Logger::Log mSLog
Logger.
void sleep()
Suspend thread execution until next tick.
Timer(int flags=0, CPS::Logger::Level logLevel=CPS::Logger::Level::debug)
std::chrono::time_point< IntervalClock, Ticks > IntervalTimePoint
CPS::Logger::Level mLogLevel
Timer log level.