diff options
| -rw-r--r-- | tools/perf/builtin-kvm.c | 12 | ||||
| -rw-r--r-- | tools/perf/config/Makefile | 7 | ||||
| -rw-r--r-- | tools/perf/config/feature-checks/Makefile | 6 | ||||
| -rw-r--r-- | tools/perf/config/feature-checks/test-all.c | 5 | ||||
| -rw-r--r-- | tools/perf/config/feature-checks/test-timerfd.c | 18 |
5 files changed, 47 insertions, 1 deletions
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c index cb05f39d8a77..cd9f92078aba 100644 --- a/tools/perf/builtin-kvm.c +++ b/tools/perf/builtin-kvm.c | |||
| @@ -20,7 +20,9 @@ | |||
| 20 | #include "util/data.h" | 20 | #include "util/data.h" |
| 21 | 21 | ||
| 22 | #include <sys/prctl.h> | 22 | #include <sys/prctl.h> |
| 23 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 23 | #include <sys/timerfd.h> | 24 | #include <sys/timerfd.h> |
| 25 | #endif | ||
| 24 | 26 | ||
| 25 | #include <termios.h> | 27 | #include <termios.h> |
| 26 | #include <semaphore.h> | 28 | #include <semaphore.h> |
| @@ -337,6 +339,7 @@ static void init_kvm_event_record(struct perf_kvm_stat *kvm) | |||
| 337 | INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); | 339 | INIT_LIST_HEAD(&kvm->kvm_events_cache[i]); |
| 338 | } | 340 | } |
| 339 | 341 | ||
| 342 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 340 | static void clear_events_cache_stats(struct list_head *kvm_events_cache) | 343 | static void clear_events_cache_stats(struct list_head *kvm_events_cache) |
| 341 | { | 344 | { |
| 342 | struct list_head *head; | 345 | struct list_head *head; |
| @@ -358,6 +361,7 @@ static void clear_events_cache_stats(struct list_head *kvm_events_cache) | |||
| 358 | } | 361 | } |
| 359 | } | 362 | } |
| 360 | } | 363 | } |
| 364 | #endif | ||
| 361 | 365 | ||
| 362 | static int kvm_events_hash_fn(u64 key) | 366 | static int kvm_events_hash_fn(u64 key) |
| 363 | { | 367 | { |
| @@ -783,6 +787,7 @@ static void print_result(struct perf_kvm_stat *kvm) | |||
| 783 | pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events); | 787 | pr_info("\nLost events: %" PRIu64 "\n\n", kvm->lost_events); |
| 784 | } | 788 | } |
| 785 | 789 | ||
| 790 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 786 | static int process_lost_event(struct perf_tool *tool, | 791 | static int process_lost_event(struct perf_tool *tool, |
| 787 | union perf_event *event __maybe_unused, | 792 | union perf_event *event __maybe_unused, |
| 788 | struct perf_sample *sample __maybe_unused, | 793 | struct perf_sample *sample __maybe_unused, |
| @@ -793,6 +798,7 @@ static int process_lost_event(struct perf_tool *tool, | |||
| 793 | kvm->lost_events++; | 798 | kvm->lost_events++; |
| 794 | return 0; | 799 | return 0; |
| 795 | } | 800 | } |
| 801 | #endif | ||
| 796 | 802 | ||
| 797 | static bool skip_sample(struct perf_kvm_stat *kvm, | 803 | static bool skip_sample(struct perf_kvm_stat *kvm, |
| 798 | struct perf_sample *sample) | 804 | struct perf_sample *sample) |
| @@ -872,6 +878,7 @@ static bool verify_vcpu(int vcpu) | |||
| 872 | return true; | 878 | return true; |
| 873 | } | 879 | } |
| 874 | 880 | ||
| 881 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 875 | /* keeping the max events to a modest level to keep | 882 | /* keeping the max events to a modest level to keep |
| 876 | * the processing of samples per mmap smooth. | 883 | * the processing of samples per mmap smooth. |
| 877 | */ | 884 | */ |
| @@ -1213,6 +1220,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm) | |||
| 1213 | out: | 1220 | out: |
| 1214 | return rc; | 1221 | return rc; |
| 1215 | } | 1222 | } |
| 1223 | #endif | ||
| 1216 | 1224 | ||
| 1217 | static int read_events(struct perf_kvm_stat *kvm) | 1225 | static int read_events(struct perf_kvm_stat *kvm) |
| 1218 | { | 1226 | { |
| @@ -1379,6 +1387,7 @@ kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) | |||
| 1379 | return kvm_events_report_vcpu(kvm); | 1387 | return kvm_events_report_vcpu(kvm); |
| 1380 | } | 1388 | } |
| 1381 | 1389 | ||
| 1390 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 1382 | static struct perf_evlist *kvm_live_event_list(void) | 1391 | static struct perf_evlist *kvm_live_event_list(void) |
| 1383 | { | 1392 | { |
| 1384 | struct perf_evlist *evlist; | 1393 | struct perf_evlist *evlist; |
| @@ -1566,6 +1575,7 @@ out: | |||
| 1566 | 1575 | ||
| 1567 | return err; | 1576 | return err; |
| 1568 | } | 1577 | } |
| 1578 | #endif | ||
| 1569 | 1579 | ||
| 1570 | static void print_kvm_stat_usage(void) | 1580 | static void print_kvm_stat_usage(void) |
| 1571 | { | 1581 | { |
| @@ -1604,8 +1614,10 @@ static int kvm_cmd_stat(const char *file_name, int argc, const char **argv) | |||
| 1604 | if (!strncmp(argv[1], "rep", 3)) | 1614 | if (!strncmp(argv[1], "rep", 3)) |
| 1605 | return kvm_events_report(&kvm, argc - 1 , argv + 1); | 1615 | return kvm_events_report(&kvm, argc - 1 , argv + 1); |
| 1606 | 1616 | ||
| 1617 | #ifdef HAVE_TIMERFD_SUPPORT | ||
| 1607 | if (!strncmp(argv[1], "live", 4)) | 1618 | if (!strncmp(argv[1], "live", 4)) |
| 1608 | return kvm_events_live(&kvm, argc - 1 , argv + 1); | 1619 | return kvm_events_live(&kvm, argc - 1 , argv + 1); |
| 1620 | #endif | ||
| 1609 | 1621 | ||
| 1610 | perf_stat: | 1622 | perf_stat: |
| 1611 | return cmd_stat(argc, argv, NULL); | 1623 | return cmd_stat(argc, argv, NULL); |
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile index ffb5f55c8fba..be8bb9a77287 100644 --- a/tools/perf/config/Makefile +++ b/tools/perf/config/Makefile | |||
| @@ -397,6 +397,13 @@ else | |||
| 397 | endif | 397 | endif |
| 398 | endif | 398 | endif |
| 399 | 399 | ||
| 400 | $(call feature_check,timerfd) | ||
| 401 | ifeq ($(feature-timerfd), 1) | ||
| 402 | CFLAGS += -DHAVE_TIMERFD_SUPPORT | ||
| 403 | else | ||
| 404 | msg := $(warning No timerfd support. Disables 'perf kvm stat live'); | ||
| 405 | endif | ||
| 406 | |||
| 400 | disable-python = $(eval $(disable-python_code)) | 407 | disable-python = $(eval $(disable-python_code)) |
| 401 | define disable-python_code | 408 | define disable-python_code |
| 402 | CFLAGS += -DNO_LIBPYTHON | 409 | CFLAGS += -DNO_LIBPYTHON |
diff --git a/tools/perf/config/feature-checks/Makefile b/tools/perf/config/feature-checks/Makefile index d37d58d273fe..c803f17fb986 100644 --- a/tools/perf/config/feature-checks/Makefile +++ b/tools/perf/config/feature-checks/Makefile | |||
| @@ -25,7 +25,8 @@ FILES= \ | |||
| 25 | test-libunwind \ | 25 | test-libunwind \ |
| 26 | test-on-exit \ | 26 | test-on-exit \ |
| 27 | test-stackprotector-all \ | 27 | test-stackprotector-all \ |
| 28 | test-stackprotector | 28 | test-stackprotector \ |
| 29 | test-timerfd | ||
| 29 | 30 | ||
| 30 | CC := $(CC) -MD | 31 | CC := $(CC) -MD |
| 31 | 32 | ||
| @@ -136,6 +137,9 @@ test-on-exit: | |||
| 136 | test-backtrace: | 137 | test-backtrace: |
| 137 | $(BUILD) | 138 | $(BUILD) |
| 138 | 139 | ||
| 140 | test-timerfd: | ||
| 141 | $(BUILD) | ||
| 142 | |||
| 139 | -include *.d | 143 | -include *.d |
| 140 | 144 | ||
| 141 | ############################### | 145 | ############################### |
diff --git a/tools/perf/config/feature-checks/test-all.c b/tools/perf/config/feature-checks/test-all.c index 50d431892a0c..59e7a705e146 100644 --- a/tools/perf/config/feature-checks/test-all.c +++ b/tools/perf/config/feature-checks/test-all.c | |||
| @@ -81,6 +81,10 @@ | |||
| 81 | # include "test-libnuma.c" | 81 | # include "test-libnuma.c" |
| 82 | #undef main | 82 | #undef main |
| 83 | 83 | ||
| 84 | #define main main_test_timerfd | ||
| 85 | # include "test-timerfd.c" | ||
| 86 | #undef main | ||
| 87 | |||
| 84 | int main(int argc, char *argv[]) | 88 | int main(int argc, char *argv[]) |
| 85 | { | 89 | { |
| 86 | main_test_libpython(); | 90 | main_test_libpython(); |
| @@ -101,6 +105,7 @@ int main(int argc, char *argv[]) | |||
| 101 | main_test_on_exit(); | 105 | main_test_on_exit(); |
| 102 | main_test_backtrace(); | 106 | main_test_backtrace(); |
| 103 | main_test_libnuma(); | 107 | main_test_libnuma(); |
| 108 | main_test_timerfd(); | ||
| 104 | 109 | ||
| 105 | return 0; | 110 | return 0; |
| 106 | } | 111 | } |
diff --git a/tools/perf/config/feature-checks/test-timerfd.c b/tools/perf/config/feature-checks/test-timerfd.c new file mode 100644 index 000000000000..8c5c083b4d3c --- /dev/null +++ b/tools/perf/config/feature-checks/test-timerfd.c | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /* | ||
| 2 | * test for timerfd functions used by perf-kvm-stat-live | ||
| 3 | */ | ||
| 4 | #include <sys/timerfd.h> | ||
| 5 | |||
| 6 | int main(void) | ||
| 7 | { | ||
| 8 | struct itimerspec new_value; | ||
| 9 | |||
| 10 | int fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); | ||
| 11 | if (fd < 0) | ||
| 12 | return 1; | ||
| 13 | |||
| 14 | if (timerfd_settime(fd, 0, &new_value, NULL) != 0) | ||
| 15 | return 1; | ||
| 16 | |||
| 17 | return 0; | ||
| 18 | } | ||
