diff options
author | Andreas Sandberg <andreas@sandberg.pp.se> | 2013-06-03 13:39:11 +0200 |
---|---|---|
committer | Andreas Sandberg <andreas@sandberg.pp.se> | 2013-06-03 13:39:11 +0200 |
commit | c2ec232920354ac1c8e07e0d2fbb8b8b314343b5 (patch) | |
tree | 8bdcd552af72fbc86f8987b71205f86e7f996cde /src/cpu/kvm/base.cc | |
parent | 15f81b6ed9a2bc9821c90a4058b7b528e001a10f (diff) | |
download | gem5-c2ec232920354ac1c8e07e0d2fbb8b8b314343b5.tar.xz |
kvm: Allow architectures to override the cycle accounting mechanism
Some architectures have special registers in the guest that can be
used to do cycle accounting. This is generally preferrable since the
prevents the guest from seeing a non-monotonic clock. This changeset
adds a virtual method, getHostCycles(), that the architecture-specific
code can override to implement this functionallity. The default
implementation uses the hwCycles counter.
Diffstat (limited to 'src/cpu/kvm/base.cc')
-rw-r--r-- | src/cpu/kvm/base.cc | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc index b5f64664f..a0aa511ea 100644 --- a/src/cpu/kvm/base.cc +++ b/src/cpu/kvm/base.cc @@ -456,12 +456,15 @@ BaseKvmCPU::tick() } } +uint64_t +BaseKvmCPU::getHostCycles() const +{ + return hwCycles.read(); +} + Tick BaseKvmCPU::kvmRun(Tick ticks) { - uint64_t baseCycles(hwCycles.read()); - uint64_t baseInstrs(hwInstructions.read()); - // We might need to update the KVM state. syncKvmState(); // Entering into KVM implies that we'll have to reload the thread @@ -478,6 +481,11 @@ BaseKvmCPU::kvmRun(Tick ticks) DPRINTF(KvmRun, "KVM: Executing for %i ticks\n", ticks); timerOverflowed = false; + // Get hardware statistics after synchronizing contexts. The KVM + // state update might affect guest cycle counters. + uint64_t baseCycles(getHostCycles()); + uint64_t baseInstrs(hwInstructions.read()); + // Arm the run timer and start the cycle timer if it isn't // controlled by the overflow timer. Starting/stopping the cycle // timer automatically starts the other perf timers as they are in @@ -497,7 +505,7 @@ BaseKvmCPU::kvmRun(Tick ticks) hwCycles.stop(); - const uint64_t hostCyclesExecuted(hwCycles.read() - baseCycles); + const uint64_t hostCyclesExecuted(getHostCycles() - baseCycles); const uint64_t simCyclesExecuted(hostCyclesExecuted * hostFactor); const uint64_t instsExecuted(hwInstructions.read() - baseInstrs); const Tick ticksExecuted(runTimer->ticksFromHostCycles(hostCyclesExecuted)); |