summaryrefslogtreecommitdiff
path: root/src/cpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu')
-rw-r--r--src/cpu/kvm/base.cc12
-rw-r--r--src/cpu/kvm/perfevent.hh35
2 files changed, 47 insertions, 0 deletions
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)
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;
};