Conflicts: tools/perf/Makefile tools/perf/builtin-test.c tools/perf/perf.h tools/perf/tests/parse-events.c tools/perf/util/evsel.h
Showing the changes to tools (20 of 1115 files). Show all
Unified · Split
| @@ -169,7 +169,35 @@ endif · 168 unmodified lines | ||
| 169 | 169 | |
| 170 | 170 | ### --- END CONFIGURATION SECTION --- |
| 171 | 171 | |
| 172 | −BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)util -Iutil -I. -I$(TRACE_EVENT_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE | |
| 172 | +ifeq ($(srctree),) | |
| 173 | +srctree := $(patsubst %/,%,$(dir $(shell pwd))) | |
| 174 | +srctree := $(patsubst %/,%,$(dir $(srctree))) | |
| 175 | +#$(info Determined 'srctree' to be $(srctree)) | |
| 176 | +endif | |
| 177 | + | |
| 178 | +ifneq ($(objtree),) | |
| 179 | +#$(info Determined 'objtree' to be $(objtree)) | |
| 180 | +endif | |
| 181 | + | |
| 182 | +ifneq ($(OUTPUT),) | |
| 183 | +#$(info Determined 'OUTPUT' to be $(OUTPUT)) | |
| 184 | +endif | |
| 185 | + | |
| 186 | +BASIC_CFLAGS = \ | |
| 187 | + -Iutil/include \ | |
| 188 | + -Iarch/$(ARCH)/include \ | |
| 189 | + $(if $(objtree),-I$(objtree)/arch/$(ARCH)/include/generated/uapi) \ | |
| 190 | + -I$(srctree)/arch/$(ARCH)/include/uapi \ | |
| 191 | + -I$(srctree)/arch/$(ARCH)/include \ | |
| 192 | + $(if $(objtree),-I$(objtree)/include/generated/uapi) \ | |
| 193 | + -I$(srctree)/include/uapi \ | |
| 194 | + -I$(srctree)/include \ | |
| 195 | + -I$(OUTPUT)util \ | |
| 196 | + -Iutil \ | |
| 197 | + -I. \ | |
| 198 | + -I$(TRACE_EVENT_DIR) \ | |
| 199 | + -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE | |
| 200 | + | |
| 173 | 201 | BASIC_LDFLAGS = |
| 174 | 202 | |
| 175 | 203 | ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y) |
| @@ -3,7 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | |
| 4 | 4 | #include <stdlib.h> |
| 5 | 5 | #include "../../util/types.h" |
| 6 | −#include "../../../../../arch/x86/include/asm/perf_regs.h" | |
| 6 | +#include <asm/perf_regs.h> | |
| 7 | 7 | |
| 8 | 8 | #ifndef ARCH_X86_64 |
| 9 | 9 | #define PERF_REGS_MASK ((1ULL << PERF_REG_X86_32_MAX) - 1) |
| @@ -22,9 +22,10 @@ · 21 unmodified lines | ||
| 22 | 22 | #include <pthread.h> |
| 23 | 23 | #include <math.h> |
| 24 | 24 | |
| 25 | −#include "../../arch/x86/include/asm/svm.h" | |
| 26 | −#include "../../arch/x86/include/asm/vmx.h" | |
| 27 | −#include "../../arch/x86/include/asm/kvm.h" | |
| 25 | +#if defined(__i386__) || defined(__x86_64__) | |
| 26 | +#include <asm/svm.h> | |
| 27 | +#include <asm/vmx.h> | |
| 28 | +#include <asm/kvm.h> | |
| 28 | 29 | |
| 29 | 30 | struct event_key { |
| 30 | 31 | #define INVALID_KEY (~0ULL) |
| @@ -58,7 +59,7 @@ struct kvm_event_key { · 27 unmodified lines | ||
| 58 | 59 | }; |
| 59 | 60 | |
| 60 | 61 | |
| 61 | −struct perf_kvm; | |
| 62 | +struct perf_kvm_stat; | |
| 62 | 63 | |
| 63 | 64 | struct kvm_events_ops { |
| 64 | 65 | bool (*is_begin_event)(struct perf_evsel *evsel, |
| @@ -66,7 +67,7 @@ struct kvm_events_ops { · 1 unmodified line | ||
| 66 | 67 | struct event_key *key); |
| 67 | 68 | bool (*is_end_event)(struct perf_evsel *evsel, |
| 68 | 69 | struct perf_sample *sample, struct event_key *key); |
| 69 | − void (*decode_key)(struct perf_kvm *kvm, struct event_key *key, | |
| 70 | + void (*decode_key)(struct perf_kvm_stat *kvm, struct event_key *key, | |
| 70 | 71 | char decode[20]); |
| 71 | 72 | const char *name; |
| 72 | 73 | }; |
| @@ -79,7 +80,7 @@ struct exit_reasons_table { · 6 unmodified lines | ||
| 79 | 80 | #define EVENTS_BITS 12 |
| 80 | 81 | #define EVENTS_CACHE_SIZE (1UL << EVENTS_BITS) |
| 81 | 82 | |
| 82 | −struct perf_kvm { | |
| 83 | +struct perf_kvm_stat { | |
| 83 | 84 | struct perf_tool tool; |
| 84 | 85 | struct perf_session *session; |
| 85 | 86 | |
| @@ -146,7 +147,7 @@ static struct exit_reasons_table svm_exit_reasons[] = { · 60 unmodified lines | ||
| 146 | 147 | SVM_EXIT_REASONS |
| 147 | 148 | }; |
| 148 | 149 | |
| 149 | −static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code) | |
| 150 | +static const char *get_exit_reason(struct perf_kvm_stat *kvm, u64 exit_code) | |
| 150 | 151 | { |
| 151 | 152 | int i = kvm->exit_reasons_size; |
| 152 | 153 | struct exit_reasons_table *tbl = kvm->exit_reasons; |
| @@ -162,7 +163,7 @@ static const char *get_exit_reason(struct perf_kvm *kvm, u64 exit_code) · 9 unmodified lines | ||
| 162 | 163 | return "UNKNOWN"; |
| 163 | 164 | } |
| 164 | 165 | |
| 165 | −static void exit_event_decode_key(struct perf_kvm *kvm, | |
| 166 | +static void exit_event_decode_key(struct perf_kvm_stat *kvm, | |
| 166 | 167 | struct event_key *key, |
| 167 | 168 | char decode[20]) |
| 168 | 169 | { |
| @@ -228,7 +229,7 @@ static bool mmio_event_end(struct perf_evsel *evsel, struct perf_sample *sample, · 59 unmodified lines | ||
| 228 | 229 | return false; |
| 229 | 230 | } |
| 230 | 231 | |
| 231 | −static void mmio_event_decode_key(struct perf_kvm *kvm __maybe_unused, | |
| 232 | +static void mmio_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, | |
| 232 | 233 | struct event_key *key, |
| 233 | 234 | char decode[20]) |
| 234 | 235 | { |
| @@ -271,7 +272,7 @@ static bool ioport_event_end(struct perf_evsel *evsel, · 36 unmodified lines | ||
| 271 | 272 | return kvm_entry_event(evsel); |
| 272 | 273 | } |
| 273 | 274 | |
| 274 | −static void ioport_event_decode_key(struct perf_kvm *kvm __maybe_unused, | |
| 275 | +static void ioport_event_decode_key(struct perf_kvm_stat *kvm __maybe_unused, | |
| 275 | 276 | struct event_key *key, |
| 276 | 277 | char decode[20]) |
| 277 | 278 | { |
| @@ -286,7 +287,7 @@ static struct kvm_events_ops ioport_events = { · 8 unmodified lines | ||
| 286 | 287 | .name = "IO Port Access" |
| 287 | 288 | }; |
| 288 | 289 | |
| 289 | −static bool register_kvm_events_ops(struct perf_kvm *kvm) | |
| 290 | +static bool register_kvm_events_ops(struct perf_kvm_stat *kvm) | |
| 290 | 291 | { |
| 291 | 292 | bool ret = true; |
| 292 | 293 | |
| @@ -311,7 +312,7 @@ struct vcpu_event_record { · 18 unmodified lines | ||
| 311 | 312 | }; |
| 312 | 313 | |
| 313 | 314 | |
| 314 | −static void init_kvm_event_record(struct perf_kvm *kvm) | |
| 315 | +static void init_kvm_event_record(struct perf_kvm_stat *kvm) | |
| 315 | 316 | { |
| 316 | 317 | unsigned int i; |
| 317 | 318 | |
| @@ -360,7 +361,7 @@ static struct kvm_event *kvm_alloc_init_event(struct event_key *key) · 42 unmodified lines | ||
| 360 | 361 | return event; |
| 361 | 362 | } |
| 362 | 363 | |
| 363 | −static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm, | |
| 364 | +static struct kvm_event *find_create_kvm_event(struct perf_kvm_stat *kvm, | |
| 364 | 365 | struct event_key *key) |
| 365 | 366 | { |
| 366 | 367 | struct kvm_event *event; |
| @@ -382,7 +383,7 @@ static struct kvm_event *find_create_kvm_event(struct perf_kvm *kvm, · 15 unmodified lines | ||
| 382 | 383 | return event; |
| 383 | 384 | } |
| 384 | 385 | |
| 385 | −static bool handle_begin_event(struct perf_kvm *kvm, | |
| 386 | +static bool handle_begin_event(struct perf_kvm_stat *kvm, | |
| 386 | 387 | struct vcpu_event_record *vcpu_record, |
| 387 | 388 | struct event_key *key, u64 timestamp) |
| 388 | 389 | { |
| @@ -429,7 +430,7 @@ static bool update_kvm_event(struct kvm_event *event, int vcpu_id, · 40 unmodified lines | ||
| 429 | 430 | return true; |
| 430 | 431 | } |
| 431 | 432 | |
| 432 | −static bool handle_end_event(struct perf_kvm *kvm, | |
| 433 | +static bool handle_end_event(struct perf_kvm_stat *kvm, | |
| 433 | 434 | struct vcpu_event_record *vcpu_record, |
| 434 | 435 | struct event_key *key, |
| 435 | 436 | u64 timestamp) |
| @@ -496,7 +497,7 @@ struct vcpu_event_record *per_vcpu_record(struct thread *thread, · 60 unmodified lines | ||
| 496 | 497 | return thread->priv; |
| 497 | 498 | } |
| 498 | 499 | |
| 499 | −static bool handle_kvm_event(struct perf_kvm *kvm, | |
| 500 | +static bool handle_kvm_event(struct perf_kvm_stat *kvm, | |
| 500 | 501 | struct thread *thread, |
| 501 | 502 | struct perf_evsel *evsel, |
| 502 | 503 | struct perf_sample *sample) |
| @@ -556,7 +557,7 @@ static struct kvm_event_key keys[] = { · 53 unmodified lines | ||
| 556 | 557 | { NULL, NULL } |
| 557 | 558 | }; |
| 558 | 559 | |
| 559 | −static bool select_key(struct perf_kvm *kvm) | |
| 560 | +static bool select_key(struct perf_kvm_stat *kvm) | |
| 560 | 561 | { |
| 561 | 562 | int i; |
| 562 | 563 | |
| @@ -592,7 +593,8 @@ static void insert_to_result(struct rb_root *result, struct kvm_event *event, · 29 unmodified lines | ||
| 592 | 593 | rb_insert_color(&event->rb, result); |
| 593 | 594 | } |
| 594 | 595 | |
| 595 | −static void update_total_count(struct perf_kvm *kvm, struct kvm_event *event) | |
| 596 | +static void | |
| 597 | +update_total_count(struct perf_kvm_stat *kvm, struct kvm_event *event) | |
| 596 | 598 | { |
| 597 | 599 | int vcpu = kvm->trace_vcpu; |
| 598 | 600 | |
| @@ -605,7 +607,7 @@ static bool event_is_valid(struct kvm_event *event, int vcpu) · 6 unmodified lines | ||
| 605 | 607 | return !!get_event_count(event, vcpu); |
| 606 | 608 | } |
| 607 | 609 | |
| 608 | −static void sort_result(struct perf_kvm *kvm) | |
| 610 | +static void sort_result(struct perf_kvm_stat *kvm) | |
| 609 | 611 | { |
| 610 | 612 | unsigned int i; |
| 611 | 613 | int vcpu = kvm->trace_vcpu; |
| @@ -644,7 +646,7 @@ static void print_vcpu_info(int vcpu) · 32 unmodified lines | ||
| 644 | 646 | pr_info("VCPU %d:\n\n", vcpu); |
| 645 | 647 | } |
| 646 | 648 | |
| 647 | −static void print_result(struct perf_kvm *kvm) | |
| 649 | +static void print_result(struct perf_kvm_stat *kvm) | |
| 648 | 650 | { |
| 649 | 651 | char decode[20]; |
| 650 | 652 | struct kvm_event *event; |
| @@ -687,7 +689,8 @@ static int process_sample_event(struct perf_tool *tool, · 36 unmodified lines | ||
| 687 | 689 | struct machine *machine) |
| 688 | 690 | { |
| 689 | 691 | struct thread *thread = machine__findnew_thread(machine, sample->tid); |
| 690 | − struct perf_kvm *kvm = container_of(tool, struct perf_kvm, tool); | |
| 692 | + struct perf_kvm_stat *kvm = container_of(tool, struct perf_kvm_stat, | |
| 693 | + tool); | |
| 691 | 694 | |
| 692 | 695 | if (thread == NULL) { |
| 693 | 696 | pr_debug("problem processing %d event, skipping it.\n", |
| @@ -718,7 +721,7 @@ static int get_cpu_isa(struct perf_session *session) · 24 unmodified lines | ||
| 718 | 721 | return isa; |
| 719 | 722 | } |
| 720 | 723 | |
| 721 | −static int read_events(struct perf_kvm *kvm) | |
| 724 | +static int read_events(struct perf_kvm_stat *kvm) | |
| 722 | 725 | { |
| 723 | 726 | int ret; |
| 724 | 727 | |
| @@ -767,7 +770,7 @@ static bool verify_vcpu(int vcpu) · 42 unmodified lines | ||
| 767 | 770 | return true; |
| 768 | 771 | } |
| 769 | 772 | |
| 770 | −static int kvm_events_report_vcpu(struct perf_kvm *kvm) | |
| 773 | +static int kvm_events_report_vcpu(struct perf_kvm_stat *kvm) | |
| 771 | 774 | { |
| 772 | 775 | int ret = -EINVAL; |
| 773 | 776 | int vcpu = kvm->trace_vcpu; |
| @@ -815,7 +818,8 @@ static const char * const record_args[] = { · 41 unmodified lines | ||
| 815 | 818 | _p; \ |
| 816 | 819 | }) |
| 817 | 820 | |
| 818 | −static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv) | |
| 821 | +static int | |
| 822 | +kvm_events_record(struct perf_kvm_stat *kvm, int argc, const char **argv) | |
| 819 | 823 | { |
| 820 | 824 | unsigned int rec_argc, i, j; |
| 821 | 825 | const char **rec_argv; |
| @@ -838,7 +842,8 @@ static int kvm_events_record(struct perf_kvm *kvm, int argc, const char **argv) · 16 unmodified lines | ||
| 838 | 842 | return cmd_record(i, rec_argv, NULL); |
| 839 | 843 | } |
| 840 | 844 | |
| 841 | −static int kvm_events_report(struct perf_kvm *kvm, int argc, const char **argv) | |
| 845 | +static int | |
| 846 | +kvm_events_report(struct perf_kvm_stat *kvm, int argc, const char **argv) | |
| 842 | 847 | { |
| 843 | 848 | const struct option kvm_events_report_options[] = { |
| 844 | 849 | OPT_STRING(0, "event", &kvm->report_event, "report event", |
| @@ -881,24 +886,37 @@ static void print_kvm_stat_usage(void) · 36 unmodified lines | ||
| 881 | 886 | printf("\nOtherwise, it is the alias of 'perf stat':\n"); |
| 882 | 887 | } |
| 883 | 888 | |
| 884 | −static int kvm_cmd_stat(struct perf_kvm *kvm, int argc, const char **argv) | |
| 889 | +static int kvm_cmd_stat(const char *file_name, int argc, const char **argv) | |
| 885 | 890 | { |
| 891 | + struct perf_kvm_stat kvm = { | |
| 892 | + .file_name = file_name, | |
| 893 | + | |
| 894 | + .trace_vcpu = -1, | |
| 895 | + .report_event = "vmexit", | |
| 896 | + .sort_key = "sample", | |
| 897 | + | |
| 898 | + .exit_reasons = svm_exit_reasons, | |
| 899 | + .exit_reasons_size = ARRAY_SIZE(svm_exit_reasons), | |
| 900 | + .exit_reasons_isa = "SVM", | |
| 901 | + }; | |
| 902 | + | |
| 886 | 903 | if (argc == 1) { |
| 887 | 904 | print_kvm_stat_usage(); |
| 888 | 905 | goto perf_stat; |
| 889 | 906 | } |
| 890 | 907 | |
| 891 | 908 | if (!strncmp(argv[1], "rec", 3)) |
| 892 | − return kvm_events_record(kvm, argc - 1, argv + 1); | |
| 909 | + return kvm_events_record(&kvm, argc - 1, argv + 1); | |
| 893 | 910 | |
| 894 | 911 | if (!strncmp(argv[1], "rep", 3)) |
| 895 | − return kvm_events_report(kvm, argc - 1 , argv + 1); | |
| 912 | + return kvm_events_report(&kvm, argc - 1 , argv + 1); | |
| 896 | 913 | |
| 897 | 914 | perf_stat: |
| 898 | 915 | return cmd_stat(argc, argv, NULL); |
| 899 | 916 | } |
| 917 | +#endif | |
| 900 | 918 | |
| 901 | −static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv) | |
| 919 | +static int __cmd_record(const char *file_name, int argc, const char **argv) | |
| 902 | 920 | { |
| 903 | 921 | int rec_argc, i = 0, j; |
| 904 | 922 | const char **rec_argv; |
| @@ -907,7 +925,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv) · 2 unmodified lines | ||
| 907 | 925 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 908 | 926 | rec_argv[i++] = strdup("record"); |
| 909 | 927 | rec_argv[i++] = strdup("-o"); |
| 910 | − rec_argv[i++] = strdup(kvm->file_name); | |
| 928 | + rec_argv[i++] = strdup(file_name); | |
| 911 | 929 | for (j = 1; j < argc; j++, i++) |
| 912 | 930 | rec_argv[i] = argv[j]; |
| 913 | 931 | |
| @@ -916,7 +934,7 @@ static int __cmd_record(struct perf_kvm *kvm, int argc, const char **argv) · 2 unmodified lines | ||
| 916 | 934 | return cmd_record(i, rec_argv, NULL); |
| 917 | 935 | } |
| 918 | 936 | |
| 919 | −static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv) | |
| 937 | +static int __cmd_report(const char *file_name, int argc, const char **argv) | |
| 920 | 938 | { |
| 921 | 939 | int rec_argc, i = 0, j; |
| 922 | 940 | const char **rec_argv; |
| @@ -925,7 +943,7 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv) · 2 unmodified lines | ||
| 925 | 943 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 926 | 944 | rec_argv[i++] = strdup("report"); |
| 927 | 945 | rec_argv[i++] = strdup("-i"); |
| 928 | − rec_argv[i++] = strdup(kvm->file_name); | |
| 946 | + rec_argv[i++] = strdup(file_name); | |
| 929 | 947 | for (j = 1; j < argc; j++, i++) |
| 930 | 948 | rec_argv[i] = argv[j]; |
| 931 | 949 | |
| @@ -934,7 +952,8 @@ static int __cmd_report(struct perf_kvm *kvm, int argc, const char **argv) · 2 unmodified lines | ||
| 934 | 952 | return cmd_report(i, rec_argv, NULL); |
| 935 | 953 | } |
| 936 | 954 | |
| 937 | −static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv) | |
| 955 | +static int | |
| 956 | +__cmd_buildid_list(const char *file_name, int argc, const char **argv) | |
| 938 | 957 | { |
| 939 | 958 | int rec_argc, i = 0, j; |
| 940 | 959 | const char **rec_argv; |
| @@ -943,7 +962,7 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv) · 2 unmodified lines | ||
| 943 | 962 | rec_argv = calloc(rec_argc + 1, sizeof(char *)); |
| 944 | 963 | rec_argv[i++] = strdup("buildid-list"); |
| 945 | 964 | rec_argv[i++] = strdup("-i"); |
| 946 | − rec_argv[i++] = strdup(kvm->file_name); | |
| 965 | + rec_argv[i++] = strdup(file_name); | |
| 947 | 966 | for (j = 1; j < argc; j++, i++) |
| 948 | 967 | rec_argv[i] = argv[j]; |
| 949 | 968 | |
| @@ -954,20 +973,12 @@ static int __cmd_buildid_list(struct perf_kvm *kvm, int argc, const char **argv) · 4 unmodified lines | ||
| 954 | 973 | |
| 955 | 974 | int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused) |
| 956 | 975 | { |
| 957 | − struct perf_kvm kvm = { | |
| 958 | − .trace_vcpu = -1, | |
| 959 | − .report_event = "vmexit", | |
| 960 | − .sort_key = "sample", | |
| 961 | − | |
| 962 | − .exit_reasons = svm_exit_reasons, | |
| 963 | − .exit_reasons_size = ARRAY_SIZE(svm_exit_reasons), | |
| 964 | − .exit_reasons_isa = "SVM", | |
| 965 | − }; | |
| 976 | + const char *file_name; | |
| 966 | 977 | |
| 967 | 978 | const struct option kvm_options[] = { |
| 968 | − OPT_STRING('i', "input", &kvm.file_name, "file", | |
| 979 | + OPT_STRING('i', "input", &file_name, "file", | |
| 969 | 980 | "Input file name"), |
| 970 | − OPT_STRING('o', "output", &kvm.file_name, "file", | |
| 981 | + OPT_STRING('o', "output", &file_name, "file", | |
| 971 | 982 | "Output file name"), |
| 972 | 983 | OPT_BOOLEAN(0, "guest", &perf_guest, |
| 973 | 984 | "Collect guest os data"), |
| @@ -1002,32 +1013,34 @@ int cmd_kvm(int argc, const char **argv, const char *prefix __maybe_unused) · 28 unmodified lines | ||
| 1002 | 1013 | if (!perf_host) |
| 1003 | 1014 | perf_guest = 1; |
| 1004 | 1015 | |
| 1005 | − if (!kvm.file_name) { | |
| 1016 | + if (!file_name) { | |
| 1006 | 1017 | if (perf_host && !perf_guest) |
| 1007 | − kvm.file_name = strdup("perf.data.host"); | |
| 1018 | + file_name = strdup("perf.data.host"); | |
| 1008 | 1019 | else if (!perf_host && perf_guest) |
| 1009 | − kvm.file_name = strdup("perf.data.guest"); | |
| 1020 | + file_name = strdup("perf.data.guest"); | |
| 1010 | 1021 | else |
| 1011 | − kvm.file_name = strdup("perf.data.kvm"); | |
| 1022 | + file_name = strdup("perf.data.kvm"); | |
| 1012 | 1023 | |
| 1013 | − if (!kvm.file_name) { | |
| 1024 | + if (!file_name) { | |
| 1014 | 1025 | pr_err("Failed to allocate memory for filename\n"); |
| 1015 | 1026 | return -ENOMEM; |
| 1016 | 1027 | } |
| 1017 | 1028 | } |
| 1018 | 1029 | |
| 1019 | 1030 | if (!strncmp(argv[0], "rec", 3)) |
| 1020 | − return __cmd_record(&kvm, argc, argv); | |
| 1031 | + return __cmd_record(file_name, argc, argv); | |
| 1021 | 1032 | else if (!strncmp(argv[0], "rep", 3)) |
| 1022 | − return __cmd_report(&kvm, argc, argv); | |
| 1033 | + return __cmd_report(file_name, argc, argv); | |
| 1023 | 1034 | else if (!strncmp(argv[0], "diff", 4)) |
| 1024 | 1035 | return cmd_diff(argc, argv, NULL); |
| 1025 | 1036 | else if (!strncmp(argv[0], "top", 3)) |
| 1026 | 1037 | return cmd_top(argc, argv, NULL); |
| 1027 | 1038 | else if (!strncmp(argv[0], "buildid-list", 12)) |
| 1028 | − return __cmd_buildid_list(&kvm, argc, argv); | |
| 1039 | + return __cmd_buildid_list(file_name, argc, argv); | |
| 1040 | +#if defined(__i386__) || defined(__x86_64__) | |
| 1029 | 1041 | else if (!strncmp(argv[0], "stat", 4)) |
| 1030 | − return kvm_cmd_stat(&kvm, argc, argv); | |
| 1042 | + return kvm_cmd_stat(file_name, argc, argv); | |
| 1043 | +#endif | |
| 1031 | 1044 | else |
| 1032 | 1045 | usage_with_options(kvm_usage, kvm_options); |
| 1033 | 1046 | |
| @@ -5,8 +5,9 @@ struct winsize; · 4 unmodified lines | ||
| 5 | 5 | |
| 6 | 6 | void get_term_dimensions(struct winsize *ws); |
| 7 | 7 | |
| 8 | +#include <asm/unistd.h> | |
| 9 | + | |
| 8 | 10 | #if defined(__i386__) |
| 9 | −#include "../../arch/x86/include/asm/unistd.h" | |
| 10 | 11 | #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") |
| 11 | 12 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
| 12 | 13 | #define CPUINFO_PROC "model name" |
| @@ -16,7 +17,6 @@ void get_term_dimensions(struct winsize *ws); · 3 unmodified lines | ||
| 16 | 17 | #endif |
| 17 | 18 | |
| 18 | 19 | #if defined(__x86_64__) |
| 19 | −#include "../../arch/x86/include/asm/unistd.h" | |
| 20 | 20 | #define rmb() asm volatile("lfence" ::: "memory") |
| 21 | 21 | #define cpu_relax() asm volatile("rep; nop" ::: "memory"); |
| 22 | 22 | #define CPUINFO_PROC "model name" |
| @@ -33,13 +33,11 @@ void get_term_dimensions(struct winsize *ws); · 10 unmodified lines | ||
| 33 | 33 | #endif |
| 34 | 34 | |
| 35 | 35 | #ifdef __s390__ |
| 36 | −#include "../../arch/s390/include/asm/unistd.h" | |
| 37 | 36 | #define rmb() asm volatile("bcr 15,0" ::: "memory") |
| 38 | 37 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 39 | 38 | #endif |
| 40 | 39 | |
| 41 | 40 | #ifdef __sh__ |
| 42 | −#include "../../arch/sh/include/asm/unistd.h" | |
| 43 | 41 | #if defined(__SH4A__) || defined(__SH5__) |
| 44 | 42 | # define rmb() asm volatile("synco" ::: "memory") |
| 45 | 43 | #else |
| @@ -50,35 +48,30 @@ void get_term_dimensions(struct winsize *ws); · 4 unmodified lines | ||
| 50 | 48 | #endif |
| 51 | 49 | |
| 52 | 50 | #ifdef __hppa__ |
| 53 | −#include "../../arch/parisc/include/asm/unistd.h" | |
| 54 | 51 | #define rmb() asm volatile("" ::: "memory") |
| 55 | 52 | #define cpu_relax() asm volatile("" ::: "memory"); |
| 56 | 53 | #define CPUINFO_PROC "cpu" |
| 57 | 54 | #endif |
| 58 | 55 | |
| 59 | 56 | #ifdef __sparc__ |
| 60 | −#include "../../arch/sparc/include/uapi/asm/unistd.h" | |
| 61 | 57 | #define rmb() asm volatile("":::"memory") |
| 62 | 58 | #define cpu_relax() asm volatile("":::"memory") |
| 63 | 59 | #define CPUINFO_PROC "cpu" |
| 64 | 60 | #endif |
| 65 | 61 | |
| 66 | 62 | #ifdef __alpha__ |
| 67 | −#include "../../arch/alpha/include/asm/unistd.h" | |
| 68 | 63 | #define rmb() asm volatile("mb" ::: "memory") |
| 69 | 64 | #define cpu_relax() asm volatile("" ::: "memory") |
| 70 | 65 | #define CPUINFO_PROC "cpu model" |
| 71 | 66 | #endif |
| 72 | 67 | |
| 73 | 68 | #ifdef __ia64__ |
| 74 | −#include "../../arch/ia64/include/asm/unistd.h" | |
| 75 | 69 | #define rmb() asm volatile ("mf" ::: "memory") |
| 76 | 70 | #define cpu_relax() asm volatile ("hint @pause" ::: "memory") |
| 77 | 71 | #define CPUINFO_PROC "model name" |
| 78 | 72 | #endif |
| 79 | 73 | |
| 80 | 74 | #ifdef __arm__ |
| 81 | −#include "../../arch/arm/include/asm/unistd.h" | |
| 82 | 75 | /* |
| 83 | 76 | * Use the __kuser_memory_barrier helper in the CPU helper page. See |
| 84 | 77 | * arch/arm/kernel/entry-armv.S in the kernel source for details. |
| @@ -89,13 +82,11 @@ void get_term_dimensions(struct winsize *ws); · 4 unmodified lines | ||
| 89 | 82 | #endif |
| 90 | 83 | |
| 91 | 84 | #ifdef __aarch64__ |
| 92 | −#include "../../arch/arm64/include/asm/unistd.h" | |
| 93 | 85 | #define rmb() asm volatile("dmb ld" ::: "memory") |
| 94 | 86 | #define cpu_relax() asm volatile("yield" ::: "memory") |
| 95 | 87 | #endif |
| 96 | 88 | |
| 97 | 89 | #ifdef __mips__ |
| 98 | −#include "../../arch/mips/include/asm/unistd.h" | |
| 99 | 90 | #define rmb() asm volatile( \ |
| 100 | 91 | ".set mips2\n\t" \ |
| 101 | 92 | "sync\n\t" \ |
| @@ -112,7 +103,7 @@ void get_term_dimensions(struct winsize *ws); · 10 unmodified lines | ||
| 112 | 103 | #include <sys/types.h> |
| 113 | 104 | #include <sys/syscall.h> |
| 114 | 105 | |
| 115 | −#include "../../include/uapi/linux/perf_event.h" | |
| 106 | +#include <linux/perf_event.h> | |
| 116 | 107 | #include "util/types.h" |
| 117 | 108 | #include <stdbool.h> |
| 118 | 109 | |
| @@ -3,8 +3,8 @@ · 2 unmodified lines | ||
| 3 | 3 | #include "evsel.h" |
| 4 | 4 | #include "evlist.h" |
| 5 | 5 | #include "sysfs.h" |
| 6 | −#include "../../../include/linux/hw_breakpoint.h" | |
| 7 | 6 | #include "tests.h" |
| 7 | +#include <linux/hw_breakpoint.h> | |
| 8 | 8 | |
| 9 | 9 | #define TEST_ASSERT_VAL(text, cond) \ |
| 10 | 10 | do { \ |
| @@ -18,8 +18,8 @@ · 17 unmodified lines | ||
| 18 | 18 | #include "cpumap.h" |
| 19 | 19 | #include "thread_map.h" |
| 20 | 20 | #include "target.h" |
| 21 | −#include "../../../include/linux/hw_breakpoint.h" | |
| 22 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 21 | +#include <linux/hw_breakpoint.h> | |
| 22 | +#include <linux/perf_event.h> | |
| 23 | 23 | #include "perf_regs.h" |
| 24 | 24 | |
| 25 | 25 | #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) |
| @@ -4,7 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | #include <linux/list.h> |
| 5 | 5 | #include <stdbool.h> |
| 6 | 6 | #include <stddef.h> |
| 7 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 7 | +#include <linux/perf_event.h> | |
| 8 | 8 | #include "types.h" |
| 9 | 9 | #include "xyarray.h" |
| 10 | 10 | #include "cgroup.h" |
| @@ -1379,6 +1379,8 @@ static void print_numa_topology(struct perf_header *ph, int fd __maybe_unused, · 1378 unmodified lines | ||
| 1379 | 1379 | |
| 1380 | 1380 | str = tmp + 1; |
| 1381 | 1381 | fprintf(fp, "# node%u cpu list : %s\n", c, str); |
| 1382 | + | |
| 1383 | + str += strlen(str) + 1; | |
| 1382 | 1384 | } |
| 1383 | 1385 | return; |
| 1384 | 1386 | error: |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | #ifndef __PERF_HEADER_H |
| 2 | 2 | #define __PERF_HEADER_H |
| 3 | 3 | |
| 4 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 4 | +#include <linux/perf_event.h> | |
| 5 | 5 | #include <sys/types.h> |
| 6 | 6 | #include <stdbool.h> |
| 7 | 7 | #include "types.h" |
| @@ -1,4 +1,4 @@ | ||
| 1 | −#include "../../../include/linux/hw_breakpoint.h" | |
| 1 | +#include <linux/hw_breakpoint.h> | |
| 2 | 2 | #include "util.h" |
| 3 | 3 | #include "../perf.h" |
| 4 | 4 | #include "evlist.h" |
| @@ -7,7 +7,7 @@ · 6 unmodified lines | ||
| 7 | 7 | #include <linux/list.h> |
| 8 | 8 | #include <stdbool.h> |
| 9 | 9 | #include "types.h" |
| 10 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 10 | +#include <linux/perf_event.h> | |
| 11 | 11 | #include "types.h" |
| 12 | 12 | |
| 13 | 13 | struct list_head; |
| @@ -2,7 +2,7 @@ · 1 unmodified line | ||
| 2 | 2 | #define __PMU_H |
| 3 | 3 | |
| 4 | 4 | #include <linux/bitops.h> |
| 5 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 5 | +#include <linux/perf_event.h> | |
| 6 | 6 | |
| 7 | 7 | enum { |
| 8 | 8 | PERF_PMU_FORMAT_VALUE_CONFIG, |
| @@ -8,7 +8,7 @@ · 7 unmodified lines | ||
| 8 | 8 | #include "symbol.h" |
| 9 | 9 | #include "thread.h" |
| 10 | 10 | #include <linux/rbtree.h> |
| 11 | −#include "../../../include/uapi/linux/perf_event.h" | |
| 11 | +#include <linux/perf_event.h> | |
| 12 | 12 | |
| 13 | 13 | struct sample_queue; |
| 14 | 14 | struct ip_callchain; |
| @@ -90,17 +90,17 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...) · 89 unmodified lines | ||
| 90 | 90 | if (!strbuf_avail(sb)) |
| 91 | 91 | strbuf_grow(sb, 64); |
| 92 | 92 | va_start(ap, fmt); |
| 93 | − len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | |
| 93 | + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | |
| 94 | 94 | va_end(ap); |
| 95 | 95 | if (len < 0) |
| 96 | − die("your vscnprintf is broken"); | |
| 96 | + die("your vsnprintf is broken"); | |
| 97 | 97 | if (len > strbuf_avail(sb)) { |
| 98 | 98 | strbuf_grow(sb, len); |
| 99 | 99 | va_start(ap, fmt); |
| 100 | − len = vscnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | |
| 100 | + len = vsnprintf(sb->buf + sb->len, sb->alloc - sb->len, fmt, ap); | |
| 101 | 101 | va_end(ap); |
| 102 | 102 | if (len > strbuf_avail(sb)) { |
| 103 | − die("this should not happen, your snprintf is broken"); | |
| 103 | + die("this should not happen, your vsnprintf is broken"); | |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | 106 | strbuf_setlen(sb, sb->len + len); |
| @@ -206,8 +206,10 @@ int get_msr(int cpu, off_t offset, unsigned long long *msr) · 205 unmodified lines | ||
| 206 | 206 | retval = pread(fd, msr, sizeof *msr, offset); |
| 207 | 207 | close(fd); |
| 208 | 208 | |
| 209 | − if (retval != sizeof *msr) | |
| 209 | + if (retval != sizeof *msr) { | |
| 210 | + fprintf(stderr, "%s offset 0x%zx read failed\n", pathname, offset); | |
| 210 | 211 | return -1; |
| 212 | + } | |
| 211 | 213 | |
| 212 | 214 | return 0; |
| 213 | 215 | } |
| @@ -1101,7 +1103,9 @@ void turbostat_loop() · 887 unmodified lines | ||
| 1101 | 1103 | |
| 1102 | 1104 | restart: |
| 1103 | 1105 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 1104 | − if (retval) { | |
| 1106 | + if (retval < -1) { | |
| 1107 | + exit(retval); | |
| 1108 | + } else if (retval == -1) { | |
| 1105 | 1109 | re_initialize(); |
| 1106 | 1110 | goto restart; |
| 1107 | 1111 | } |
| @@ -1114,7 +1118,9 @@ restart: · 6 unmodified lines | ||
| 1114 | 1118 | } |
| 1115 | 1119 | sleep(interval_sec); |
| 1116 | 1120 | retval = for_all_cpus(get_counters, ODD_COUNTERS); |
| 1117 | − if (retval) { | |
| 1121 | + if (retval < -1) { | |
| 1122 | + exit(retval); | |
| 1123 | + } else if (retval == -1) { | |
| 1118 | 1124 | re_initialize(); |
| 1119 | 1125 | goto restart; |
| 1120 | 1126 | } |
| @@ -1126,7 +1132,9 @@ restart: · 5 unmodified lines | ||
| 1126 | 1132 | flush_stdout(); |
| 1127 | 1133 | sleep(interval_sec); |
| 1128 | 1134 | retval = for_all_cpus(get_counters, EVEN_COUNTERS); |
| 1129 | − if (retval) { | |
| 1135 | + if (retval < -1) { | |
| 1136 | + exit(retval); | |
| 1137 | + } else if (retval == -1) { | |
| 1130 | 1138 | re_initialize(); |
| 1131 | 1139 | goto restart; |
| 1132 | 1140 | } |
| @@ -1545,8 +1553,11 @@ void turbostat_init() · 412 unmodified lines | ||
| 1545 | 1553 | int fork_it(char **argv) |
| 1546 | 1554 | { |
| 1547 | 1555 | pid_t child_pid; |
| 1556 | + int status; | |
| 1548 | 1557 | |
| 1549 | − for_all_cpus(get_counters, EVEN_COUNTERS); | |
| 1558 | + status = for_all_cpus(get_counters, EVEN_COUNTERS); | |
| 1559 | + if (status) | |
| 1560 | + exit(status); | |
| 1550 | 1561 | /* clear affinity side-effect of get_counters() */ |
| 1551 | 1562 | sched_setaffinity(0, cpu_present_setsize, cpu_present_set); |
| 1552 | 1563 | gettimeofday(&tv_even, (struct timezone *)NULL); |
| @@ -1556,7 +1567,6 @@ int fork_it(char **argv) · 3 unmodified lines | ||
| 1556 | 1567 | /* child */ |
| 1557 | 1568 | execvp(argv[0], argv); |
| 1558 | 1569 | } else { |
| 1559 | − int status; | |
| 1560 | 1570 | |
| 1561 | 1571 | /* parent */ |
| 1562 | 1572 | if (child_pid == -1) { |
| @@ -1568,7 +1578,7 @@ int fork_it(char **argv) · 5 unmodified lines | ||
| 1568 | 1578 | signal(SIGQUIT, SIG_IGN); |
| 1569 | 1579 | if (waitpid(child_pid, &status, 0) == -1) { |
| 1570 | 1580 | perror("wait"); |
| 1571 | − exit(1); | |
| 1581 | + exit(status); | |
| 1572 | 1582 | } |
| 1573 | 1583 | } |
| 1574 | 1584 | /* |
| @@ -1585,7 +1595,7 @@ int fork_it(char **argv) · 10 unmodified lines | ||
| 1585 | 1595 | |
| 1586 | 1596 | fprintf(stderr, "%.6f sec\n", tv_delta.tv_sec + tv_delta.tv_usec/1000000.0); |
| 1587 | 1597 | |
| 1588 | − return 0; | |
| 1598 | + return status; | |
| 1589 | 1599 | } |
| 1590 | 1600 | |
| 1591 | 1601 | void cmdline(int argc, char **argv) |
| @@ -1594,7 +1604,7 @@ void cmdline(int argc, char **argv) · 2 unmodified lines | ||
| 1594 | 1604 | |
| 1595 | 1605 | progname = argv[0]; |
| 1596 | 1606 | |
| 1597 | − while ((opt = getopt(argc, argv, "+pPSvisc:sC:m:M:")) != -1) { | |
| 1607 | + while ((opt = getopt(argc, argv, "+pPSvi:sc:sC:m:M:")) != -1) { | |
| 1598 | 1608 | switch (opt) { |
| 1599 | 1609 | case 'p': |
| 1600 | 1610 | show_core_only++; |
| @@ -1740,8 +1740,10 @@ sub install { · 1739 unmodified lines | ||
| 1740 | 1740 | open(IN, "$output_config") or dodie("Can't read config file"); |
| 1741 | 1741 | while (<IN>) { |
| 1742 | 1742 | if (/CONFIG_MODULES(=y)?/) { |
| 1743 | − $install_mods = 1 if (defined($1)); | |
| 1744 | − last; | |
| 1743 | + if (defined($1)) { | |
| 1744 | + $install_mods = 1; | |
| 1745 | + last; | |
| 1746 | + } | |
| 1745 | 1747 | } |
| 1746 | 1748 | } |
| 1747 | 1749 | close(IN); |
| @@ -1,4 +1,4 @@ | ||
| 1 | −TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug epoll | |
| 1 | +TARGETS = breakpoints kcmp mqueue vm cpu-hotplug memory-hotplug | |
| 2 | 2 | |
| 3 | 3 | all: |
| 4 | 4 | for TARGET in $(TARGETS); do \ |
| @@ -1,11 +0,0 @@ | ||
| 1 | −# Makefile for epoll selftests | |
| 2 | − | |
| 3 | −all: test_epoll | |
| 4 | −%: %.c | |
| 5 | − gcc -pthread -g -o $@ $^ | |
| 6 | − | |
| 7 | −run_tests: all | |
| 8 | − ./test_epoll | |
| 9 | − | |
| 10 | −clean: | |
| 11 | − $(RM) test_epoll | |
| @@ -1,344 +0,0 @@ | ||
| 1 | −/* | |
| 2 | − * tools/testing/selftests/epoll/test_epoll.c | |
| 3 | − * | |
| 4 | − * Copyright 2012 Adobe Systems Incorporated | |
| 5 | − * | |
| 6 | − * This program is free software; you can redistribute it and/or modify | |
| 7 | − * it under the terms of the GNU General Public License as published by | |
| 8 | − * the Free Software Foundation; either version 2 of the License, or | |
| 9 | − * (at your option) any later version. | |
| 10 | − * | |
| 11 | − * Paton J. Lewis <palewis@adobe.com> | |
| 12 | − * | |
| 13 | − */ | |
| 14 | − | |
| 15 | −#include <errno.h> | |
| 16 | −#include <fcntl.h> | |
| 17 | −#include <pthread.h> | |
| 18 | −#include <stdio.h> | |
| 19 | −#include <stdlib.h> | |
| 20 | −#include <unistd.h> | |
| 21 | −#include <sys/epoll.h> | |
| 22 | −#include <sys/socket.h> | |
| 23 | − | |
| 24 | −/* | |
| 25 | − * A pointer to an epoll_item_private structure will be stored in the epoll | |
| 26 | − * item's event structure so that we can get access to the epoll_item_private | |
| 27 | − * data after calling epoll_wait: | |
| 28 | − */ | |
| 29 | −struct epoll_item_private { | |
| 30 | − int index; /* Position of this struct within the epoll_items array. */ | |
| 31 | − int fd; | |
| 32 | − uint32_t events; | |
| 33 | − pthread_mutex_t mutex; /* Guards the following variables... */ | |
| 34 | − int stop; | |
| 35 | − int status; /* Stores any error encountered while handling item. */ | |
| 36 | − /* The following variable allows us to test whether we have encountered | |
| 37 | − a problem while attempting to cancel and delete the associated | |
| 38 | − event. When the test program exits, 'deleted' should be exactly | |
| 39 | − one. If it is greater than one, then the failed test reflects a real | |
| 40 | − world situation where we would have tried to access the epoll item's | |
| 41 | − private data after deleting it: */ | |
| 42 | − int deleted; | |
| 43 | −}; | |
| 44 | − | |
| 45 | −struct epoll_item_private *epoll_items; | |
| 46 | − | |
| 47 | −/* | |
| 48 | − * Delete the specified item from the epoll set. In a real-world secneario this | |
| 49 | − * is where we would free the associated data structure, but in this testing | |
| 50 | − * environment we retain the structure so that we can test for double-deletion: | |
| 51 | − */ | |
| 52 | −void delete_item(int index) | |
| 53 | −{ | |
| 54 | − __sync_fetch_and_add(&epoll_items[index].deleted, 1); | |
| 55 | −} | |
| 56 | − | |
| 57 | −/* | |
| 58 | − * A pointer to a read_thread_data structure will be passed as the argument to | |
| 59 | − * each read thread: | |
| 60 | − */ | |
| 61 | −struct read_thread_data { | |
| 62 | − int stop; | |
| 63 | − int status; /* Indicates any error encountered by the read thread. */ | |
| 64 | − int epoll_set; | |
| 65 | −}; | |
| 66 | − | |
| 67 | −/* | |
| 68 | − * The function executed by the read threads: | |
| 69 | − */ | |
| 70 | −void *read_thread_function(void *function_data) | |
| 71 | −{ | |
| 72 | − struct read_thread_data *thread_data = | |
| 73 | − (struct read_thread_data *)function_data; | |
| 74 | − struct epoll_event event_data; | |
| 75 | − struct epoll_item_private *item_data; | |
| 76 | − char socket_data; | |
| 77 | − | |
| 78 | − /* Handle events until we encounter an error or this thread's 'stop' | |
| 79 | − condition is set: */ | |
| 80 | − while (1) { | |
| 81 | − int result = epoll_wait(thread_data->epoll_set, | |
| 82 | − &event_data, | |
| 83 | − 1, /* Number of desired events */ | |
| 84 | − 1000); /* Timeout in ms */ | |
| 85 | − if (result < 0) { | |
| 86 | − /* Breakpoints signal all threads. Ignore that while | |
| 87 | − debugging: */ | |
| 88 | − if (errno == EINTR) | |
| 89 | − continue; | |
| 90 | − thread_data->status = errno; | |
| 91 | − return 0; | |
| 92 | − } else if (thread_data->stop) | |
| 93 | − return 0; | |
| 94 | − else if (result == 0) /* Timeout */ | |
| 95 | − continue; | |
| 96 | − | |
| 97 | − /* We need the mutex here because checking for the stop | |
| 98 | − condition and re-enabling the epoll item need to be done | |
| 99 | − together as one atomic operation when EPOLL_CTL_DISABLE is | |
| 100 | − available: */ | |
| 101 | − item_data = (struct epoll_item_private *)event_data.data.ptr; | |
| 102 | − pthread_mutex_lock(&item_data->mutex); | |
| 103 | − | |
| 104 | − /* Remove the item from the epoll set if we want to stop | |
| 105 | − handling that event: */ | |
| 106 | − if (item_data->stop) | |
| 107 | − delete_item(item_data->index); | |
| 108 | − else { | |
| 109 | − /* Clear the data that was written to the other end of | |
| 110 | − our non-blocking socket: */ | |
| 111 | − do { | |
| 112 | − if (read(item_data->fd, &socket_data, 1) < 1) { | |
| 113 | − if ((errno == EAGAIN) || | |
| 114 | − (errno == EWOULDBLOCK)) | |
| 115 | − break; | |
| 116 | − else | |
| 117 | − goto error_unlock; | |
| 118 | − } | |
| 119 | − } while (item_data->events & EPOLLET); | |
| 120 | − | |
| 121 | − /* The item was one-shot, so re-enable it: */ | |
| 122 | − event_data.events = item_data->events; | |
| 123 | − if (epoll_ctl(thread_data->epoll_set, | |
| 124 | − EPOLL_CTL_MOD, | |
| 125 | − item_data->fd, | |
| 126 | − &event_data) < 0) | |
| 127 | − goto error_unlock; | |
| 128 | − } | |
| 129 | − | |
| 130 | − pthread_mutex_unlock(&item_data->mutex); | |
| 131 | − } | |
| 132 | − | |
| 133 | −error_unlock: | |
| 134 | − thread_data->status = item_data->status = errno; | |
| 135 | − pthread_mutex_unlock(&item_data->mutex); | |
| 136 | − return 0; | |
| 137 | −} | |
| 138 | − | |
| 139 | −/* | |
| 140 | − * A pointer to a write_thread_data structure will be passed as the argument to | |
| 141 | − * the write thread: | |
| 142 | − */ | |
| 143 | −struct write_thread_data { | |
| 144 | − int stop; | |
| 145 | − int status; /* Indicates any error encountered by the write thread. */ | |
| 146 | − int n_fds; | |
| 147 | − int *fds; | |
| 148 | −}; | |
| 149 | − | |
| 150 | −/* | |
| 151 | − * The function executed by the write thread. It writes a single byte to each | |
| 152 | − * socket in turn until the stop condition for this thread is set. If writing to | |
| 153 | − * a socket would block (i.e. errno was EAGAIN), we leave that socket alone for | |
| 154 | − * the moment and just move on to the next socket in the list. We don't care | |
| 155 | − * about the order in which we deliver events to the epoll set. In fact we don't | |
| 156 | − * care about the data we're writing to the pipes at all; we just want to | |
| 157 | − * trigger epoll events: | |
| 158 | − */ | |
| 159 | −void *write_thread_function(void *function_data) | |
| 160 | −{ | |
| 161 | − const char data = 'X'; | |
| 162 | − int index; | |
| 163 | − struct write_thread_data *thread_data = | |
| 164 | − (struct write_thread_data *)function_data; | |
| 165 | − while (!write_thread_data->stop) | |
| 166 | − for (index = 0; | |
| 167 | − !thread_data->stop && (index < thread_data->n_fds); | |
| 168 | − ++index) | |
| 169 | − if ((write(thread_data->fds[index], &data, 1) < 1) && | |
| 170 | − (errno != EAGAIN) && | |
| 171 | − (errno != EWOULDBLOCK)) { | |
| 172 | − write_thread_data->status = errno; | |
| 173 | − return; | |
| 174 | − } | |
| 175 | −} | |
| 176 | − | |
| 177 | −/* | |
| 178 | − * Arguments are currently ignored: | |
| 179 | − */ | |
| 180 | −int main(int argc, char **argv) | |
| 181 | −{ | |
| 182 | − const int n_read_threads = 100; | |
| 183 | − const int n_epoll_items = 500; | |
| 184 | − int index; | |
| 185 | − int epoll_set = epoll_create1(0); | |
| 186 | − struct write_thread_data write_thread_data = { | |
| 187 | − 0, 0, n_epoll_items, malloc(n_epoll_items * sizeof(int)) | |
| 188 | − }; | |
| 189 | − struct read_thread_data *read_thread_data = | |
| 190 | − malloc(n_read_threads * sizeof(struct read_thread_data)); | |
| 191 | − pthread_t *read_threads = malloc(n_read_threads * sizeof(pthread_t)); | |
| 192 | − pthread_t write_thread; | |
| 193 | − | |
| 194 | − printf("-----------------\n"); | |
| 195 | − printf("Runing test_epoll\n"); | |
| 196 | − printf("-----------------\n"); | |
| 197 | − | |
| 198 | − epoll_items = malloc(n_epoll_items * sizeof(struct epoll_item_private)); | |
| 199 | − | |
| 200 | − if (epoll_set < 0 || epoll_items == 0 || write_thread_data.fds == 0 || | |
| 201 | − read_thread_data == 0 || read_threads == 0) | |
| 202 | − goto error; | |
| 203 | − | |
| 204 | − if (sysconf(_SC_NPROCESSORS_ONLN) < 2) { | |
| 205 | − printf("Error: please run this test on a multi-core system.\n"); | |
| 206 | − goto error; | |
| 207 | − } | |
| 208 | − | |
| 209 | − /* Create the socket pairs and epoll items: */ | |
| 210 | − for (index = 0; index < n_epoll_items; ++index) { | |
| 211 | − int socket_pair[2]; | |
| 212 | − struct epoll_event event_data; | |
| 213 | − if (socketpair(AF_UNIX, | |
| 214 | − SOCK_STREAM | SOCK_NONBLOCK, | |
| 215 | − 0, | |
| 216 | − socket_pair) < 0) | |
| 217 | − goto error; | |
| 218 | − write_thread_data.fds[index] = socket_pair[0]; | |
| 219 | − epoll_items[index].index = index; | |
| 220 | − epoll_items[index].fd = socket_pair[1]; | |
| 221 | − if (pthread_mutex_init(&epoll_items[index].mutex, NULL) != 0) | |
| 222 | − goto error; | |
| 223 | − /* We always use EPOLLONESHOT because this test is currently | |
| 224 | − structured to demonstrate the need for EPOLL_CTL_DISABLE, | |
| 225 | − which only produces useful information in the EPOLLONESHOT | |
| 226 | − case (without EPOLLONESHOT, calling epoll_ctl with | |
| 227 | − EPOLL_CTL_DISABLE will never return EBUSY). If support for | |
| 228 | − testing events without EPOLLONESHOT is desired, it should | |
| 229 | − probably be implemented in a separate unit test. */ | |
| 230 | − epoll_items[index].events = EPOLLIN | EPOLLONESHOT; | |
| 231 | − if (index < n_epoll_items / 2) | |
| 232 | − epoll_items[index].events |= EPOLLET; | |
| 233 | − epoll_items[index].stop = 0; | |
| 234 | − epoll_items[index].status = 0; | |
| 235 | − epoll_items[index].deleted = 0; | |
| 236 | − event_data.events = epoll_items[index].events; | |
| 237 | − event_data.data.ptr = &epoll_items[index]; | |
| 238 | − if (epoll_ctl(epoll_set, | |
| 239 | − EPOLL_CTL_ADD, | |
| 240 | − epoll_items[index].fd, | |
| 241 | − &event_data) < 0) | |
| 242 | − goto error; | |
| 243 | − } | |
| 244 | − | |
| 245 | − /* Create and start the read threads: */ | |
| 246 | − for (index = 0; index < n_read_threads; ++index) { | |
| 247 | − read_thread_data[index].stop = 0; | |
| 248 | − read_thread_data[index].status = 0; | |
| 249 | − read_thread_data[index].epoll_set = epoll_set; | |
| 250 | − if (pthread_create(&read_threads[index], | |
| 251 | − NULL, | |
| 252 | − read_thread_function, | |
| 253 | − &read_thread_data[index]) != 0) | |
| 254 | − goto error; | |
| 255 | − } | |
| 256 | − | |
| 257 | − if (pthread_create(&write_thread, | |
| 258 | − NULL, | |
| 259 | − write_thread_function, | |
| 260 | − &write_thread_data) != 0) | |
| 261 | − goto error; | |
| 262 | − | |
| 263 | − /* Cancel all event pollers: */ | |
| 264 | −#ifdef EPOLL_CTL_DISABLE | |
| 265 | − for (index = 0; index < n_epoll_items; ++index) { | |
| 266 | − pthread_mutex_lock(&epoll_items[index].mutex); | |
| 267 | − ++epoll_items[index].stop; | |
| 268 | − if (epoll_ctl(epoll_set, | |
| 269 | − EPOLL_CTL_DISABLE, | |
| 270 | − epoll_items[index].fd, | |
| 271 | − NULL) == 0) | |
| 272 | − delete_item(index); | |
| 273 | − else if (errno != EBUSY) { | |
| 274 | − pthread_mutex_unlock(&epoll_items[index].mutex); | |
| 275 | − goto error; | |
| 276 | − } | |
| 277 | − /* EBUSY means events were being handled; allow the other thread | |
| 278 | − to delete the item. */ | |
| 279 | − pthread_mutex_unlock(&epoll_items[index].mutex); | |
| 280 | − } | |
| 281 | −#else | |
| 282 | − for (index = 0; index < n_epoll_items; ++index) { | |
| 283 | − pthread_mutex_lock(&epoll_items[index].mutex); | |
| 284 | − ++epoll_items[index].stop; | |
| 285 | − pthread_mutex_unlock(&epoll_items[index].mutex); | |
| 286 | − /* Wait in case a thread running read_thread_function is | |
| 287 | − currently executing code between epoll_wait and | |
| 288 | − pthread_mutex_lock with this item. Note that a longer delay | |
| 289 | − would make double-deletion less likely (at the expense of | |
| 290 | − performance), but there is no guarantee that any delay would | |
| 291 | − ever be sufficient. Note also that we delete all event | |
| 292 | − pollers at once for testing purposes, but in a real-world | |
| 293 | − environment we are likely to want to be able to cancel event | |
| 294 | − pollers at arbitrary times. Therefore we can't improve this | |
| 295 | − situation by just splitting this loop into two loops | |
| 296 | − (i.e. signal 'stop' for all items, sleep, and then delete all | |
| 297 | − items). We also can't fix the problem via EPOLL_CTL_DEL | |
| 298 | − because that command can't prevent the case where some other | |
| 299 | − thread is executing read_thread_function within the region | |
| 300 | − mentioned above: */ | |
| 301 | − usleep(1); | |
| 302 | − pthread_mutex_lock(&epoll_items[index].mutex); | |
| 303 | − if (!epoll_items[index].deleted) | |
| 304 | − delete_item(index); | |
| 305 | − pthread_mutex_unlock(&epoll_items[index].mutex); | |
| 306 | − } | |
| 307 | −#endif | |
| 308 | − | |
| 309 | − /* Shut down the read threads: */ | |
| 310 | − for (index = 0; index < n_read_threads; ++index) | |
| 311 | − __sync_fetch_and_add(&read_thread_data[index].stop, 1); | |
| 312 | − for (index = 0; index < n_read_threads; ++index) { | |
| 313 | − if (pthread_join(read_threads[index], NULL) != 0) | |
| 314 | − goto error; | |
| 315 | − if (read_thread_data[index].status) | |
| 316 | − goto error; | |
| 317 | − } | |
| 318 | − | |
| 319 | − /* Shut down the write thread: */ | |
| 320 | − __sync_fetch_and_add(&write_thread_data.stop, 1); | |
| 321 | − if ((pthread_join(write_thread, NULL) != 0) || write_thread_data.status) | |
| 322 | − goto error; | |
| 323 | − | |
| 324 | − /* Check for final error conditions: */ | |
| 325 | − for (index = 0; index < n_epoll_items; ++index) { | |
| 326 | − if (epoll_items[index].status != 0) | |
| 327 | − goto error; | |
| 328 | − if (pthread_mutex_destroy(&epoll_items[index].mutex) < 0) | |
| 329 | − goto error; | |
| 330 | − } | |
| 331 | − for (index = 0; index < n_epoll_items; ++index) | |
| 332 | − if (epoll_items[index].deleted != 1) { | |
| 333 | − printf("Error: item data deleted %1d times.\n", | |
| 334 | − epoll_items[index].deleted); | |
| 335 | − goto error; | |
| 336 | − } | |
| 337 | − | |
| 338 | − printf("[PASS]\n"); | |
| 339 | − return 0; | |
| 340 | − | |
| 341 | − error: | |
| 342 | − printf("[FAIL]\n"); | |
| 343 | − return errno; | |
| 344 | −} | |
| @@ -35,7 +35,7 @@ · 34 unmodified lines | ||
| 35 | 35 | #include <sys/mount.h> |
| 36 | 36 | #include <sys/statfs.h> |
| 37 | 37 | #include "../../include/uapi/linux/magic.h" |
| 38 | −#include "../../include/linux/kernel-page-flags.h" | |
| 38 | +#include "../../include/uapi/linux/kernel-page-flags.h" | |
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | #ifndef MAX_PATH |