kvm: Add experimental support for a perf-based execution timer
Add support for using the CPU cycle counter instead of a normal POSIX timer to generate timed exits to gem5. This should, in theory, provide better resolution when requesting timer signals. The perf-based timer requires a fairly recent kernel since it requires a working PERF_EVENT_IOC_PERIOD ioctl. This ioctl has existed in the kernel for a long time, but it used to be completely broken due to an inverted match when the kernel copied things from user space. Additionally, the ioctl does not change the sample period correctly on all kernel versions which implement it. It is currently only known to work reliably on kernel version 3.7 and above on ARM.
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "cpu/kvm/perfevent.hh"
|
||||
#include "sim/core.hh"
|
||||
|
||||
/**
|
||||
@@ -203,4 +204,44 @@ class PosixKvmTimer : public BaseKvmTimer
|
||||
timer_t timer;
|
||||
};
|
||||
|
||||
/**
|
||||
* PerfEvent based timer using the host's CPU cycle counter.
|
||||
*
|
||||
* @warning There is a known problem in some versions of the PerfEvent
|
||||
* API that prevents the counter overflow period from being updated
|
||||
* reliably, which might break this timer. See PerfKvmCounter::period()
|
||||
* for details.
|
||||
*/
|
||||
class PerfKvmTimer : public BaseKvmTimer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create a timer that uses an existing hardware cycle counter.
|
||||
*
|
||||
* @note The performance counter must be configured for overflow
|
||||
* sampling, which in practice means that it must have a non-zero
|
||||
* sample period. The initial sample period is ignored since
|
||||
* period will be updated when arm() is called.
|
||||
*
|
||||
* @param ctr Attached performance counter configured for overflow
|
||||
* reporting.
|
||||
* @param signo Signal to deliver
|
||||
* @param hostFactor Performance scaling factor
|
||||
* @param hostFreq Clock frequency of the host
|
||||
*/
|
||||
PerfKvmTimer(PerfKvmCounter &ctr,
|
||||
int signo,
|
||||
float hostFactor, Tick hostFreq);
|
||||
~PerfKvmTimer();
|
||||
|
||||
void arm(Tick ticks);
|
||||
void disarm();
|
||||
|
||||
protected:
|
||||
Tick calcResolution();
|
||||
|
||||
private:
|
||||
PerfKvmCounter &hwOverflow;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user