From 4b8be6a90b39ef195313af2029cde2c0ca564a53 Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Tue, 15 Oct 2013 10:09:23 +0200 Subject: kvm: Set the perf exclude_host attribute if available The performance counting framework in Linux 3.2 and onwards supports an attribute to exclude events generated by the host when running KVM. Setting this attribute allows us to get more reliable measurements of the guest machine. For example, on a highly loaded system, the instruction counts from the guest can be severely distorted by the host kernel (e.g., by page fault handlers). This changeset introduces a check for the attribute and enables it in the KVM CPU if present. --- src/cpu/kvm/base.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/cpu/kvm/base.cc') diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc index a8e115da7..d25e145a5 100644 --- a/src/cpu/kvm/base.cc +++ b/src/cpu/kvm/base.cc @@ -1133,6 +1133,12 @@ BaseKvmCPU::setupCounters() cfgCycles.disabled(true) .pinned(true); + // Try to exclude the host. We set both exclude_hv and + // exclude_host since different architectures use slightly + // different APIs in the kernel. + cfgCycles.exclude_hv(true) + .exclude_host(true); + if (perfControlledByTimer) { // We need to configure the cycles counter to send overflows // since we are going to use it to trigger timer signals that @@ -1206,6 +1212,12 @@ BaseKvmCPU::setupInstCounter(uint64_t period) PerfKvmCounterConfig cfgInstructions(PERF_TYPE_HARDWARE, PERF_COUNT_HW_INSTRUCTIONS); + // Try to exclude the host. We set both exclude_hv and + // exclude_host since different architectures use slightly + // different APIs in the kernel. + cfgInstructions.exclude_hv(true) + .exclude_host(true); + if (period) { // Setup a sampling counter if that has been requested. cfgInstructions.wakeupEvents(1) -- cgit v1.2.3