gem5  v21.1.0.2
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
gem5::BaseKvmTimer Class Referenceabstract

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

#include <timer.hh>

Inheritance diagram for gem5::BaseKvmTimer:
gem5::PerfKvmTimer gem5::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 63 of file timer.hh.

Constructor & Destructor Documentation

◆ BaseKvmTimer()

gem5::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 74 of file timer.hh.

◆ ~BaseKvmTimer()

virtual gem5::BaseKvmTimer::~BaseKvmTimer ( )
inlinevirtual

Definition at line 77 of file timer.hh.

Member Function Documentation

◆ arm()

virtual void gem5::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 gem5::PosixKvmTimer, and gem5::PerfKvmTimer.

◆ calcResolution()

virtual Tick gem5::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 gem5::PosixKvmTimer, and gem5::PerfKvmTimer.

Referenced by resolution().

◆ disarm()

virtual void gem5::BaseKvmTimer::disarm ( )
pure virtual

Disarm the timer.

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

Implemented in gem5::PosixKvmTimer, and gem5::PerfKvmTimer.

◆ expired()

virtual bool gem5::BaseKvmTimer::expired ( )
inlinevirtual

Reimplemented in gem5::PosixKvmTimer.

Definition at line 99 of file timer.hh.

◆ hostCycles()

uint64_t gem5::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 162 of file timer.hh.

References hostFactor, and hostFreq.

Referenced by gem5::PerfKvmTimer::arm().

◆ hostNs()

uint64_t gem5::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 152 of file timer.hh.

References hostFactor, and gem5::sim_clock::as_float::ns.

Referenced by gem5::PosixKvmTimer::arm().

◆ resolution()

Tick gem5::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 110 of file timer.hh.

References _resolution, and calcResolution().

Referenced by gem5::PosixKvmTimer::calcResolution().

◆ ticksFromHostCycles()

Tick gem5::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 123 of file timer.hh.

References hostFactor, and hostFreq.

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

◆ ticksFromHostNs()

Tick gem5::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 134 of file timer.hh.

References hostFactor, gem5::sim_clock::as_float::ns, and gem5::ArmISA::ns.

Referenced by gem5::PosixKvmTimer::calcResolution().

Member Data Documentation

◆ _resolution

Tick gem5::BaseKvmTimer::_resolution
mutableprivate

Cached resolution.

Definition at line 171 of file timer.hh.

Referenced by resolution().

◆ hostFactor

float gem5::BaseKvmTimer::hostFactor
private

Performance scaling factor.

Definition at line 174 of file timer.hh.

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

◆ hostFreq

Tick gem5::BaseKvmTimer::hostFreq
private

Host frequency.

Definition at line 176 of file timer.hh.

Referenced by hostCycles(), and ticksFromHostCycles().

◆ signo

int gem5::BaseKvmTimer::signo
protected

Signal to deliver when the timer times out.

Definition at line 167 of file timer.hh.

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


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

Generated on Tue Sep 21 2021 12:27:19 for gem5 by doxygen 1.8.17