40#include <sys/syscall.h>
49#include "debug/KvmTimer.hh"
57#ifndef sigev_notify_thread_id
58#define sigev_notify_thread_id _sigev_un._tid
67 return syscall(__NR_gettid);
86 sev.sigev_notify = SIGEV_THREAD_ID;
89 sev.sigev_value.sival_ptr = NULL;
93 panic(
"timer_create: %i", errno);
105 struct itimerspec
ts;
106 memset(&
ts, 0,
sizeof(
ts));
108 ts.it_interval.tv_sec = 0;
109 ts.it_interval.tv_nsec = 0;
110 ts.it_value.tv_sec =
hostNs(ticks) / 1000000000ULL;
111 ts.it_value.tv_nsec =
hostNs(ticks) % 1000000000ULL;
113 assert(
ts.it_value.tv_nsec > 0 ||
ts.it_value.tv_sec > 0);
115 DPRINTF(KvmTimer,
"Arming POSIX timer: %i ticks (%is%ins)\n",
116 ticks,
ts.it_value.tv_sec,
ts.it_value.tv_nsec);
118 if (timer_settime(
timer, 0, &
ts, NULL) == -1)
119 panic(
"PosixKvmTimer: Failed to arm timer\n");
125 struct itimerspec
ts;
126 memset(&
ts, 0,
sizeof(
ts));
129 panic(
"PosixKvmTimer: Failed to disarm timer\n");
131 DPRINTF(KvmTimer,
"Disarmed POSIX timer: %is%ins left\n",
149 panic(
"PosixKvmTimer: Failed to get timer resolution\n");
151 const uint64_t res_ns(
ts.tv_sec * 1000000000ULL +
ts.tv_nsec);
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
BaseKvmTimer(int signo, float hostFactor, Tick hostFreq)
Setup basic timer functionality shared by all timer implementations.
Tick hostFreq
Host frequency.
Tick resolution()
Determine the resolution of the timer in ticks.
int signo
Signal to deliver when the timer times out.
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
float hostFactor
Performance scaling factor.
An instance of a performance counter.
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
void disarm()
Disarm the timer.
PerfKvmCounter & hwOverflow
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
void arm(Tick ticks) override
Arm the timer so that it fires after a certain number of ticks.
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Tick calcResolution() override
Calculate the timer resolution, used by resolution() which caches the result.
struct itimerspec prevTimerSpec
void disarm() override
Disarm the timer.
#define panic(...)
This implements a cprintf based panic() function.
Copyright (c) 2024 Arm Limited All rights reserved.
uint64_t Tick
Tick count type.
static const uint64_t MIN_HOST_CYCLES
Minimum number of cycles that a host can spend in a KVM call (used to calculate the resolution of som...