summaryrefslogtreecommitdiff
path: root/src/cpu/kvm/perfevent.hh
diff options
context:
space:
mode:
authorAndreas Sandberg <andreas@sandberg.pp.se>2013-10-15 10:09:23 +0200
committerAndreas Sandberg <andreas@sandberg.pp.se>2013-10-15 10:09:23 +0200
commit4b8be6a90b39ef195313af2029cde2c0ca564a53 (patch)
treefaaeb4b7127734ecff67d716c0d655efc4b6a873 /src/cpu/kvm/perfevent.hh
parentd4f205ea2ff2800b253d4681afaa6af330bfa33b (diff)
downloadgem5-4b8be6a90b39ef195313af2029cde2c0ca564a53.tar.xz
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.
Diffstat (limited to 'src/cpu/kvm/perfevent.hh')
-rw-r--r--src/cpu/kvm/perfevent.hh35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/cpu/kvm/perfevent.hh b/src/cpu/kvm/perfevent.hh
index eed900994..b1b0da283 100644
--- a/src/cpu/kvm/perfevent.hh
+++ b/src/cpu/kvm/perfevent.hh
@@ -45,6 +45,8 @@
#include <inttypes.h>
+#include "config/have_perf_attr_exclude_host.hh"
+
/**
* PerfEvent counter configuration.
*/
@@ -125,6 +127,39 @@ class PerfKvmCounterConfig
return *this;
}
+ /**
+ * Exclude the events from the host (i.e., only include events
+ * from the guest system).
+ *
+ * Intel CPUs seem to support this attribute from Linux 3.2 and
+ * onwards. Non-x86 architectures currently ignore this attribute
+ * (Linux 3.12-rc5).
+ *
+ * @warn This attribute is ignored if it isn't present in the
+ * kernel headers or if the kernel doesn't support it.
+ *
+ * @param val true to exclude host events
+ */
+ PerfKvmCounterConfig &exclude_host(bool val) {
+#if HAVE_PERF_ATTR_EXCLUDE_HOST == 1
+ attr.exclude_host = val;
+#endif
+ return *this;
+ }
+
+ /**
+ * Exclude the hyper visor (i.e., only include events from the
+ * guest system).
+ *
+ * @warn This is attribute only seems to be ignored on Intel.
+ *
+ * @param val true to exclude host events
+ */
+ PerfKvmCounterConfig &exclude_hv(bool val) {
+ attr.exclude_hv = val;
+ return *this;
+ }
+
/** Underlying perf_event_attr structure describing the counter */
struct perf_event_attr attr;
};