42 #include <sys/syscall.h>
51 #include "debug/KvmTimer.hh"
59 #ifndef sigev_notify_thread_id
60 #define sigev_notify_thread_id _sigev_un._tid
66 return syscall(__NR_gettid);
79 float hostFactor,
Tick hostFreq)
85 sev.sigev_notify = SIGEV_THREAD_ID;
86 sev.sigev_signo =
signo;
87 sev.sigev_notify_thread_id =
gettid();
88 sev.sigev_value.sival_ptr = NULL;
90 while (timer_create(clockID, &sev, &
timer) == -1) {
92 panic(
"timer_create: %i", errno);
104 struct itimerspec ts;
105 memset(&ts, 0,
sizeof(ts));
107 ts.it_interval.tv_sec = 0;
108 ts.it_interval.tv_nsec = 0;
109 ts.it_value.tv_sec =
hostNs(ticks) / 1000000000
ULL;
110 ts.it_value.tv_nsec =
hostNs(ticks) % 1000000000
ULL;
112 assert(ts.it_value.tv_nsec > 0 || ts.it_value.tv_sec > 0);
114 DPRINTF(KvmTimer,
"Arming POSIX timer: %i ticks (%is%ins)\n",
115 ticks, ts.it_value.tv_sec, ts.it_value.tv_nsec);
117 if (timer_settime(
timer, 0, &ts, NULL) == -1)
118 panic(
"PosixKvmTimer: Failed to arm timer\n");
124 struct itimerspec ts;
125 memset(&ts, 0,
sizeof(ts));
127 DPRINTF(KvmTimer,
"Disarming POSIX timer\n");
129 if (timer_settime(
timer, 0, &ts, NULL) == -1)
130 panic(
"PosixKvmTimer: Failed to disarm timer\n");
138 if (clock_getres(
clockID, &ts) == -1)
139 panic(
"PosixKvmTimer: Failed to get timer resolution\n");
141 const uint64_t res_ns(ts.tv_sec * 1000000000
ULL + ts.tv_nsec);
157 return std::max(resolution, min_cycles);
162 int signo,
float hostFactor,
Tick hostFreq)
PerfKvmCounter & hwOverflow
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
PosixKvmTimer(int signo, clockid_t clockID, float hostFactor, Tick hostFreq)
Tick resolution()
Determine the resolution of the timer in ticks.
uint64_t hostNs(Tick ticks)
Convert a time in simulator ticks to host nanoseconds.
void refresh(int refresh)
Enable a counter for a fixed number of events.
uint64_t hostCycles(Tick ticks)
Convert a time in simulator ticks to host cycles.
uint64_t Tick
Tick count type.
void period(uint64_t period)
Update the period of an overflow counter.
void disarm()
Disarm the timer.
void disarm()
Disarm the timer.
An instance of a performance counter.
#define ULL(N)
uint64_t constant
Tick ticksFromHostCycles(uint64_t cycles)
Convert cycles executed on the host into Ticks executed in the simulator.
Tick ticksFromHostNs(uint64_t ns)
Convert nanoseconds executed on the host into Ticks executed in the simulator.
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
void stop()
Stop counting.
void arm(Tick ticks)
Arm the timer so that it fires after a certain number of ticks.
Tick calcResolution()
Calculate the timer resolution, used by resolution() which caches the result.
Timer functions to interrupt VM execution after a number of simulation ticks.
int signo
Signal to deliver when the timer times out.
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...
PerfKvmTimer(PerfKvmCounter &ctr, int signo, float hostFactor, Tick hostFreq)
Create a timer that uses an existing hardware cycle counter.