perf test 6: Fix missing kvm module load for s390 [Linux 4.9.187]

This Linux kernel change "perf test 6: Fix missing kvm module load for s390" is included in the Linux 4.9.187 release. This change is authored by Thomas Richter <tmricht [at] linux.ibm.com> on Tue Jun 4 07:35:04 2019 +0200. The commit for this change in Linux stable tree is 9a501cd (patch) which is from upstream commit 53fe307. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 53fe307.

perf test 6: Fix missing kvm module load for s390

[ Upstream commit 53fe307dfd309e425b171f6272d64296a54f4dff ]

Command

   # perf test -Fv 6

fails with error

   running test 100 'kvm-s390:kvm_s390_create_vm' failed to parse
    event 'kvm-s390:kvm_s390_create_vm', err -1, str 'unknown tracepoint'
    event syntax error: 'kvm-s390:kvm_s390_create_vm'
                         \___ unknown tracepoint

when the kvm module is not loaded or not built in.

Fix this by adding a valid function which tests if the module
is loaded. Loaded modules (or builtin KVM support) have a
directory named
  /sys/kernel/debug/tracing/events/kvm-s390
for this tracepoint.

Check for existence of this directory.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/20190604053504.43073-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>

There are 27 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 tools/perf/tests/parse-events.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index aa9276b..9134a0c 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -12,6 +12,32 @@
 #define PERF_TP_SAMPLE_TYPE (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | \
                 PERF_SAMPLE_CPU | PERF_SAMPLE_PERIOD)

+#if defined(__s390x__)
+/* Return true if kvm module is available and loaded. Test this
+ * and retun success when trace point kvm_s390_create_vm
+ * exists. Otherwise this test always fails.
+ */
+static bool kvm_s390_create_vm_valid(void)
+{
+   char *eventfile;
+   bool rc = false;
+
+   eventfile = get_events_file("kvm-s390");
+
+   if (eventfile) {
+       DIR *mydir = opendir(eventfile);
+
+       if (mydir) {
+           rc = true;
+           closedir(mydir);
+       }
+       put_events_file(eventfile);
+   }
+
+   return rc;
+}
+#endif
+
 static int test__checkevent_tracepoint(struct perf_evlist *evlist)
 {
    struct perf_evsel *evsel = perf_evlist__first(evlist);
@@ -1593,6 +1619,7 @@ struct evlist_test {
    {
        .name  = "kvm-s390:kvm_s390_create_vm",
        .check = test__checkevent_tracepoint,
+       .valid = kvm_s390_create_vm_valid,
        .id    = 100,
    },
 #endif

Leave a Reply

Your email address will not be published. Required fields are marked *