perf intel-pt: Fix exclude_guest setting
authorAdrian Hunter <adrian.hunter@intel.com>
Tue, 25 Jun 2024 10:45:32 +0000 (13:45 +0300)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 2 Jul 2024 22:24:07 +0000 (15:24 -0700)
In the past, the exclude_guest setting has had no effect on Intel PT
tracing, but that may not be the case in the future.

Set the flag correctly based upon whether KVM is using Intel PT
"Host/Guest" mode, which is determined by the kvm_intel module
parameter pt_mode:

 pt_mode=0 System-wide mode : host and guest output to host buffer
 pt_mode=1 Host/Guest mode : host/guest output to host/guest
                buffers respectively

Fixes: 6e86bfdc4a60 ("perf intel-pt: Support decoding of guest kernel")
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20240625104532.11990-3-adrian.hunter@intel.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/arch/x86/util/intel-pt.c

index c8fa15f280d298d36eb96a7413230208e848bc24..4b710e875953a7a72e068c5bbe3f6b1cc91e263a 100644 (file)
@@ -32,6 +32,7 @@
 #include "../../../util/tsc.h"
 #include <internal/lib.h> // page_size
 #include "../../../util/intel-pt.h"
+#include <api/fs/fs.h>
 
 #define KiB(x) ((x) * 1024)
 #define MiB(x) ((x) * 1024 * 1024)
@@ -428,6 +429,16 @@ static int intel_pt_track_switches(struct evlist *evlist)
 }
 #endif
 
+static bool intel_pt_exclude_guest(void)
+{
+       int pt_mode;
+
+       if (sysfs__read_int("module/kvm_intel/parameters/pt_mode", &pt_mode))
+               pt_mode = 0;
+
+       return pt_mode == 1;
+}
+
 static void intel_pt_valid_str(char *str, size_t len, u64 valid)
 {
        unsigned int val, last = 0, state = 1;
@@ -620,6 +631,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr,
                        }
                        evsel->core.attr.freq = 0;
                        evsel->core.attr.sample_period = 1;
+                       evsel->core.attr.exclude_guest = intel_pt_exclude_guest();
                        evsel->no_aux_samples = true;
                        evsel->needs_auxtrace_mmap = true;
                        intel_pt_evsel = evsel;