perf kvm: Disable live command if timerfd is not supported
authorDavid Ahern <dsahern@gmail.com>
Tue, 29 Oct 2013 16:43:16 +0000 (10:43 -0600)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 5 Nov 2013 13:03:22 +0000 (10:03 -0300)
If the OS does not have timerfd support (e.g., older OS'es like RHEL5)
disable perf kvm stat live.

Signed-off-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1383064996-20933-2-git-send-email-dsahern@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kvm.c
tools/perf/config/Makefile
tools/perf/config/feature-checks/Makefile
tools/perf/config/feature-checks/test-all.c
tools/perf/config/feature-checks/test-timerfd.c [new file with mode: 0644]

index cb05f39d8a77f4e5d6d897d82a2876eed5028a5b..cd9f92078aba2e42aaadb8b48f7dad04e23f3485 100644 (file)
@@ -20,7 +20,9 @@
 #include "util/data.h"
 
 #include <sys/prctl.h>
+#ifdef HAVE_TIMERFD_SUPPORT
 #include <sys/timerfd.h>
+#endif
 
 #include <termios.h>
 #include <semaphore.h>
@@ -337,6 +339,7 @@ static void init_kvm_event_record(struct perf_kvm_stat *kvm)
                INIT_LIST_HEAD(&kvm->kvm_events_cache[i]);
 }
 
+#ifdef HAVE_TIMERFD_SUPPORT
 static void clear_events_cache_stats(struct list_head *kvm_events_cache)
 {
        struct list_head *head;
@@ -358,6 +361,7 @@ static void clear_events_cache_stats(struct list_head *kvm_events_cache)
                }
        }
 }
+#endif
 
 static int kvm_events_hash_fn(u64 key)
 {
@@ -783,6 +787,7 @@ static void print_result(struct perf_kvm_stat *kvm)
                pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events);
 }
 
+#ifdef HAVE_TIMERFD_SUPPORT
 static int process_lost_event(struct perf_tool *tool,
                              union perf_event *event __maybe_unused,
                              struct perf_sample *sample __maybe_unused,
@@ -793,6 +798,7 @@ static int process_lost_event(struct perf_tool *tool,
        kvm->lost_events++;
        return 0;
 }
+#endif
 
 static bool skip_sample(struct perf_kvm_stat *kvm,
                        struct perf_sample *sample)
@@ -872,6 +878,7 @@ static bool verify_vcpu(int vcpu)
        return true;
 }
 
+#ifdef HAVE_TIMERFD_SUPPORT
 /* keeping the max events to a modest level to keep
  * the processing of samples per mmap smooth.
  */
@@ -1213,6 +1220,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
 out:
        return rc;
 }
+#endif
 
 static int read_events(struct perf_kvm_stat *kvm)
 {
@@ -1379,6 +1387,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv)
        return kvm_events_report_vcpu(kvm);
 }
 
+#ifdef HAVE_TIMERFD_SUPPORT
 static struct perf_evlist *kvm_live_event_list(void)
 {
        struct perf_evlist *evlist;
@@ -1566,6 +1575,7 @@ out:
 
        return err;
 }
+#endif
 
 static void print_kvm_stat_usage(void)
 {
@@ -1604,8 +1614,10 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv)
        if (!strncmp(argv[1], "rep", 3))
                return kvm_events_report(&kvm, argc - 1 , argv + 1);
 
+#ifdef HAVE_TIMERFD_SUPPORT
        if (!strncmp(argv[1], "live", 4))
                return kvm_events_live(&kvm, argc - 1 , argv + 1);
+#endif
 
 perf_stat:
        return cmd_stat(argc, argv, NULL);
index ffb5f55c8fba46723cf88d80c13182ba569c699e..be8bb9a772876286a37e5d65e75233a66518198f 100644 (file)
@@ -397,6 +397,13 @@ else
   endif
 endif
 
+$(call feature_check,timerfd)
+ifeq ($(feature-timerfd), 1)
+  CFLAGS += -DHAVE_TIMERFD_SUPPORT
+else
+  msg := $(warning No timerfd support. Disables 'perf kvm stat live');
+endif
+
 disable-python = $(eval $(disable-python_code))
 define disable-python_code
   CFLAGS += -DNO_LIBPYTHON
index d37d58d273fec8b440f2e172021a03279aa1502c..c803f17fb9869648c97ba9efe93e3a05b4e4329d 100644 (file)
@@ -25,7 +25,8 @@ FILES=                                        \
        test-libunwind                  \
        test-on-exit                    \
        test-stackprotector-all         \
-       test-stackprotector
+       test-stackprotector             \
+       test-timerfd
 
 CC := $(CC) -MD
 
@@ -136,6 +137,9 @@ test-on-exit:
 test-backtrace:
        $(BUILD)
 
+test-timerfd:
+       $(BUILD)
+
 -include *.d
 
 ###############################
index 50d431892a0ce28bd229e24e5053452651f8ff1b..59e7a705e146d4eb8ea029ebf74878411f8e3898 100644 (file)
 # include "test-libnuma.c"
 #undef main
 
+#define main main_test_timerfd
+# include "test-timerfd.c"
+#undef main
+
 int main(int argc, char *argv[])
 {
        main_test_libpython();
@@ -101,6 +105,7 @@ int main(int argc, char *argv[])
        main_test_on_exit();
        main_test_backtrace();
        main_test_libnuma();
+       main_test_timerfd();
 
        return 0;
 }
diff --git a/tools/perf/config/feature-checks/test-timerfd.c b/tools/perf/config/feature-checks/test-timerfd.c
new file mode 100644 (file)
index 0000000..8c5c083
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * test for timerfd functions used by perf-kvm-stat-live
+ */
+#include <sys/timerfd.h>
+
+int main(void)
+{
+       struct itimerspec new_value;
+
+       int fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
+       if (fd < 0)
+               return 1;
+
+       if (timerfd_settime(fd, 0, &new_value, NULL) != 0)
+               return 1;
+
+       return 0;
+}
This page took 0.028648 seconds and 5 git commands to generate.