gem5  v20.1.0.0
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
BaseKvmTimer Class Referenceabstract

Timer functions to interrupt VM execution after a number of simulation ticks. More...

#include <timer.hh>

Inheritance diagram for BaseKvmTimer:
PerfKvmTimer PosixKvmTimer

Public Member Functions

 BaseKvmTimer (int signo, float hostFactor, Tick hostFreq)
 Setup basic timer functionality shared by all timer implementations. More...
 
virtual ~BaseKvmTimer ()
 
virtual void arm (Tick ticks)=0
 Arm the timer so that it fires after a certain number of ticks. More...
 
virtual void disarm ()=0
 Disarm the timer. More...
 
virtual bool expired ()
 
Tick resolution ()
 Determine the resolution of the timer in ticks. More...
 
Tick ticksFromHostCycles (uint64_t cycles)
 Convert cycles executed on the host into Ticks executed in the simulator. More...
 
Tick ticksFromHostNs (uint64_t ns)
 Convert nanoseconds executed on the host into Ticks executed in the simulator. More...
 

Protected Member Functions

virtual Tick calcResolution ()=0
 Calculate the timer resolution, used by resolution() which caches the result. More...
 
uint64_t hostNs (Tick ticks)
 Convert a time in simulator ticks to host nanoseconds. More...
 
uint64_t hostCycles (Tick ticks)
 Convert a time in simulator ticks to host cycles. More...
 

Protected Attributes

int signo
 Signal to deliver when the timer times out. More...
 

Private Attributes

Tick _resolution
 Cached resolution. More...
 
float hostFactor
 Performance scaling factor. More...
 
Tick hostFreq
 Host frequency. More...
 

Detailed Description

Timer functions to interrupt VM execution after a number of simulation ticks.

The timer allows scaling of the host time to take performance differences between the simulated and real CPU into account.

The performance scaling factor is ratio between the target's CPI and the host's CPI. It is larger than 1 if the host is faster than the target and lower than 1 if it is slower.

When the timer times out, it sends a signal to the thread that started the timer. The signal forces KVM to drop out of the system call that started the guest and hands control to gem5.

Definition at line 60 of file timer.hh.

Constructor & Destructor Documentation

◆ BaseKvmTimer()

BaseKvmTimer::BaseKvmTimer ( int  signo,
float  hostFactor,
Tick  hostFreq 
)
inline

Setup basic timer functionality shared by all timer implementations.

Parameters
signoSignal to deliver
hostFactorPerformance scaling factor
hostFreqClock frequency of the host

Definition at line 71 of file timer.hh.

◆ ~BaseKvmTimer()

virtual BaseKvmTimer::~BaseKvmTimer ( )
inlinevirtual

Definition at line 74 of file timer.hh.

Member Function Documentation

◆ arm()

virtual void BaseKvmTimer::arm ( Tick  ticks)
pure virtual

Arm the timer so that it fires after a certain number of ticks.

Note
A timer implementation is free to convert between simulation ticks and virtualized time using any method it chooses. The accuracy of the timer therefore depends on what it measures, an accurate timer implementation should measure the number of cycles or instructions executed in the guest. If such counters are unavailable, it may fallback to wall clock time.
Parameters
ticksNumber of ticks until the timer fires

Implemented in PosixKvmTimer, and PerfKvmTimer.

◆ calcResolution()

virtual Tick BaseKvmTimer::calcResolution ( )
protectedpure virtual

Calculate the timer resolution, used by resolution() which caches the result.

Returns
Minimum number of ticks the timer can resolve

Implemented in PosixKvmTimer, and PerfKvmTimer.

Referenced by resolution().

◆ disarm()

virtual void BaseKvmTimer::disarm ( )
pure virtual

Disarm the timer.

When this method has returned, the timer may no longer deliver signals upon timeout.

Implemented in PosixKvmTimer, and PerfKvmTimer.

◆ expired()

virtual bool BaseKvmTimer::expired ( )
inlinevirtual

Reimplemented in PosixKvmTimer.

Definition at line 96 of file timer.hh.

◆ hostCycles()

uint64_t BaseKvmTimer::hostCycles ( Tick  ticks)
inlineprotected

Convert a time in simulator ticks to host cycles.

Returns
Simulation ticks converted into CPU cycles on the host

Definition at line 159 of file timer.hh.

References hostFactor, and hostFreq.

Referenced by PerfKvmTimer::arm().

◆ hostNs()

uint64_t BaseKvmTimer::hostNs ( Tick  ticks)
inlineprotected

Convert a time in simulator ticks to host nanoseconds.

Returns
Simulation ticks converted into nanoseconds on the host

Definition at line 149 of file timer.hh.

References hostFactor, and SimClock::Float::ns.

Referenced by PosixKvmTimer::arm().

◆ resolution()

Tick BaseKvmTimer::resolution ( )
inline

Determine the resolution of the timer in ticks.

This method is mainly used to determine the smallest number of ticks the timer can wait before triggering a signal.

Returns
Minimum number of ticks the timer can resolve

Definition at line 107 of file timer.hh.

References _resolution, and calcResolution().

Referenced by PosixKvmTimer::calcResolution().

◆ ticksFromHostCycles()

Tick BaseKvmTimer::ticksFromHostCycles ( uint64_t  cycles)
inline

Convert cycles executed on the host into Ticks executed in the simulator.

Scales the results using the hostFactor to take CPU performance differences into account.

Returns
Host cycles executed in VM converted to simulation ticks

Definition at line 120 of file timer.hh.

References hostFactor, and hostFreq.

Referenced by PosixKvmTimer::calcResolution(), and PerfKvmTimer::calcResolution().

◆ ticksFromHostNs()

Tick BaseKvmTimer::ticksFromHostNs ( uint64_t  ns)
inline

Convert nanoseconds executed on the host into Ticks executed in the simulator.

Scales the results using the hostFactor to take CPU performance differences into account.

Returns
Nanoseconds executed in VM converted to simulation ticks

Definition at line 131 of file timer.hh.

References hostFactor, SimClock::Float::ns, and ArmISA::ns.

Referenced by PosixKvmTimer::calcResolution().

Member Data Documentation

◆ _resolution

Tick BaseKvmTimer::_resolution
mutableprivate

Cached resolution.

Definition at line 168 of file timer.hh.

Referenced by resolution().

◆ hostFactor

float BaseKvmTimer::hostFactor
private

Performance scaling factor.

Definition at line 171 of file timer.hh.

Referenced by hostCycles(), hostNs(), ticksFromHostCycles(), and ticksFromHostNs().

◆ hostFreq

Tick BaseKvmTimer::hostFreq
private

Host frequency.

Definition at line 173 of file timer.hh.

Referenced by hostCycles(), and ticksFromHostCycles().

◆ signo

int BaseKvmTimer::signo
protected

Signal to deliver when the timer times out.

Definition at line 164 of file timer.hh.

Referenced by PerfKvmTimer::PerfKvmTimer(), and PosixKvmTimer::PosixKvmTimer().


The documentation for this class was generated from the following file:

Generated on Wed Sep 30 2020 14:02:21 for gem5 by doxygen 1.8.17