From f8f66fa3df3ef5b4e30ee86d33a4e95476ba425a Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Mon, 22 Apr 2013 13:20:32 -0400 Subject: 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. --- src/cpu/kvm/timer.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/cpu/kvm/timer.cc') diff --git a/src/cpu/kvm/timer.cc b/src/cpu/kvm/timer.cc index 059d70f6b..e1f74a552 100644 --- a/src/cpu/kvm/timer.cc +++ b/src/cpu/kvm/timer.cc @@ -110,3 +110,37 @@ PosixKvmTimer::calcResolution() return resolution; } + + +PerfKvmTimer::PerfKvmTimer(PerfKvmCounter &ctr, + int signo, float hostFactor, Tick hostFreq) + : BaseKvmTimer(signo, hostFactor, hostFreq), + hwOverflow(ctr) +{ + hwOverflow.enableSignals(signo); +} + +PerfKvmTimer::~PerfKvmTimer() +{ +} + +void +PerfKvmTimer::arm(Tick ticks) +{ + hwOverflow.period(hostCycles(ticks)); + hwOverflow.refresh(1); +} + +void +PerfKvmTimer::disarm() +{ + hwOverflow.stop(); +} + +Tick +PerfKvmTimer::calcResolution() +{ + // This is a bit arbitrary, but in practice, we can't really do + // anything useful in less than ~1000 anyway. + return ticksFromHostCycles(1000); +} -- cgit v1.2.3