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);
80 float hostFactor,
Tick hostFreq)
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);
172 int signo,
float hostFactor,
Tick hostFreq)
Timer functions to interrupt VM execution after a number of simulation ticks.
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.
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.
An instance of a performance counter.
void period(uint64_t period)
Update the period of an overflow counter.
void refresh(int refresh)
Enable a counter for a fixed number of events.
void enableSignals(pid_t tid, int signal)
Enable signal delivery to a thread on counter overflow.
void stop()
Stop counting.
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 - Pranith Kumar Copyright (c) 2020 Inria 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...