diff options
Diffstat (limited to 'tools/perf/bench')
-rw-r--r-- | tools/perf/bench/bench.h | 1 | ||||
-rw-r--r-- | tools/perf/bench/futex-requeue.c | 10 | ||||
-rw-r--r-- | tools/perf/bench/futex-wake.c | 12 | ||||
-rw-r--r-- | tools/perf/bench/mem-memcpy.c | 9 | ||||
-rw-r--r-- | tools/perf/bench/mem-memset.c | 9 | ||||
-rw-r--r-- | tools/perf/bench/sched-messaging.c | 47 |
6 files changed, 41 insertions, 47 deletions
diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index eba46709b279..3c4dd44d45cb 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h | |||
@@ -43,5 +43,6 @@ extern int bench_futex_requeue(int argc, const char **argv, const char *prefix); | |||
43 | #define BENCH_FORMAT_UNKNOWN -1 | 43 | #define BENCH_FORMAT_UNKNOWN -1 |
44 | 44 | ||
45 | extern int bench_format; | 45 | extern int bench_format; |
46 | extern unsigned int bench_repeat; | ||
46 | 47 | ||
47 | #endif | 48 | #endif |
diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requeue.c index a16255876f1d..732403bfd31a 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c | |||
@@ -29,13 +29,6 @@ static u_int32_t futex1 = 0, futex2 = 0; | |||
29 | */ | 29 | */ |
30 | static unsigned int nrequeue = 1; | 30 | static unsigned int nrequeue = 1; |
31 | 31 | ||
32 | /* | ||
33 | * There can be significant variance from run to run, | ||
34 | * the more repeats, the more exact the overall avg and | ||
35 | * the better idea of the futex latency. | ||
36 | */ | ||
37 | static unsigned int repeat = 10; | ||
38 | |||
39 | static pthread_t *worker; | 32 | static pthread_t *worker; |
40 | static bool done = 0, silent = 0; | 33 | static bool done = 0, silent = 0; |
41 | static pthread_mutex_t thread_lock; | 34 | static pthread_mutex_t thread_lock; |
@@ -46,7 +39,6 @@ static unsigned int ncpus, threads_starting, nthreads = 0; | |||
46 | static const struct option options[] = { | 39 | static const struct option options[] = { |
47 | OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), | 40 | OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), |
48 | OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"), | 41 | OPT_UINTEGER('q', "nrequeue", &nrequeue, "Specify amount of threads to requeue at once"), |
49 | OPT_UINTEGER('r', "repeat", &repeat, "Specify amount of times to repeat the run"), | ||
50 | OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), | 42 | OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), |
51 | OPT_END() | 43 | OPT_END() |
52 | }; | 44 | }; |
@@ -146,7 +138,7 @@ int bench_futex_requeue(int argc, const char **argv, | |||
146 | pthread_cond_init(&thread_parent, NULL); | 138 | pthread_cond_init(&thread_parent, NULL); |
147 | pthread_cond_init(&thread_worker, NULL); | 139 | pthread_cond_init(&thread_worker, NULL); |
148 | 140 | ||
149 | for (j = 0; j < repeat && !done; j++) { | 141 | for (j = 0; j < bench_repeat && !done; j++) { |
150 | unsigned int nrequeued = 0; | 142 | unsigned int nrequeued = 0; |
151 | struct timeval start, end, runtime; | 143 | struct timeval start, end, runtime; |
152 | 144 | ||
diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index d096169b161e..50022cbce87e 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c | |||
@@ -30,15 +30,8 @@ static u_int32_t futex1 = 0; | |||
30 | */ | 30 | */ |
31 | static unsigned int nwakes = 1; | 31 | static unsigned int nwakes = 1; |
32 | 32 | ||
33 | /* | ||
34 | * There can be significant variance from run to run, | ||
35 | * the more repeats, the more exact the overall avg and | ||
36 | * the better idea of the futex latency. | ||
37 | */ | ||
38 | static unsigned int repeat = 10; | ||
39 | |||
40 | pthread_t *worker; | 33 | pthread_t *worker; |
41 | static bool done = 0, silent = 0; | 34 | static bool done = false, silent = false; |
42 | static pthread_mutex_t thread_lock; | 35 | static pthread_mutex_t thread_lock; |
43 | static pthread_cond_t thread_parent, thread_worker; | 36 | static pthread_cond_t thread_parent, thread_worker; |
44 | static struct stats waketime_stats, wakeup_stats; | 37 | static struct stats waketime_stats, wakeup_stats; |
@@ -47,7 +40,6 @@ static unsigned int ncpus, threads_starting, nthreads = 0; | |||
47 | static const struct option options[] = { | 40 | static const struct option options[] = { |
48 | OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), | 41 | OPT_UINTEGER('t', "threads", &nthreads, "Specify amount of threads"), |
49 | OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"), | 42 | OPT_UINTEGER('w', "nwakes", &nwakes, "Specify amount of threads to wake at once"), |
50 | OPT_UINTEGER('r', "repeat", &repeat, "Specify amount of times to repeat the run"), | ||
51 | OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), | 43 | OPT_BOOLEAN( 's', "silent", &silent, "Silent mode: do not display data/details"), |
52 | OPT_END() | 44 | OPT_END() |
53 | }; | 45 | }; |
@@ -149,7 +141,7 @@ int bench_futex_wake(int argc, const char **argv, | |||
149 | pthread_cond_init(&thread_parent, NULL); | 141 | pthread_cond_init(&thread_parent, NULL); |
150 | pthread_cond_init(&thread_worker, NULL); | 142 | pthread_cond_init(&thread_worker, NULL); |
151 | 143 | ||
152 | for (j = 0; j < repeat && !done; j++) { | 144 | for (j = 0; j < bench_repeat && !done; j++) { |
153 | unsigned int nwoken = 0; | 145 | unsigned int nwoken = 0; |
154 | struct timeval start, end, runtime; | 146 | struct timeval start, end, runtime; |
155 | 147 | ||
diff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c index 5ce71d3b72cf..2465141b554b 100644 --- a/tools/perf/bench/mem-memcpy.c +++ b/tools/perf/bench/mem-memcpy.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "../util/util.h" | 10 | #include "../util/util.h" |
11 | #include "../util/parse-options.h" | 11 | #include "../util/parse-options.h" |
12 | #include "../util/header.h" | 12 | #include "../util/header.h" |
13 | #include "../util/cloexec.h" | ||
13 | #include "bench.h" | 14 | #include "bench.h" |
14 | #include "mem-memcpy-arch.h" | 15 | #include "mem-memcpy-arch.h" |
15 | 16 | ||
@@ -83,7 +84,8 @@ static struct perf_event_attr cycle_attr = { | |||
83 | 84 | ||
84 | static void init_cycle(void) | 85 | static void init_cycle(void) |
85 | { | 86 | { |
86 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, 0); | 87 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, |
88 | perf_event_open_cloexec_flag()); | ||
87 | 89 | ||
88 | if (cycle_fd < 0 && errno == ENOSYS) | 90 | if (cycle_fd < 0 && errno == ENOSYS) |
89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 91 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
@@ -189,6 +191,11 @@ int bench_mem_memcpy(int argc, const char **argv, | |||
189 | argc = parse_options(argc, argv, options, | 191 | argc = parse_options(argc, argv, options, |
190 | bench_mem_memcpy_usage, 0); | 192 | bench_mem_memcpy_usage, 0); |
191 | 193 | ||
194 | if (no_prefault && only_prefault) { | ||
195 | fprintf(stderr, "Invalid options: -o and -n are mutually exclusive\n"); | ||
196 | return 1; | ||
197 | } | ||
198 | |||
192 | if (use_cycle) | 199 | if (use_cycle) |
193 | init_cycle(); | 200 | init_cycle(); |
194 | 201 | ||
diff --git a/tools/perf/bench/mem-memset.c b/tools/perf/bench/mem-memset.c index 9af79d2b18e5..75fc3e65fb2a 100644 --- a/tools/perf/bench/mem-memset.c +++ b/tools/perf/bench/mem-memset.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include "../util/util.h" | 10 | #include "../util/util.h" |
11 | #include "../util/parse-options.h" | 11 | #include "../util/parse-options.h" |
12 | #include "../util/header.h" | 12 | #include "../util/header.h" |
13 | #include "../util/cloexec.h" | ||
13 | #include "bench.h" | 14 | #include "bench.h" |
14 | #include "mem-memset-arch.h" | 15 | #include "mem-memset-arch.h" |
15 | 16 | ||
@@ -83,7 +84,8 @@ static struct perf_event_attr cycle_attr = { | |||
83 | 84 | ||
84 | static void init_cycle(void) | 85 | static void init_cycle(void) |
85 | { | 86 | { |
86 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, 0); | 87 | cycle_fd = sys_perf_event_open(&cycle_attr, getpid(), -1, -1, |
88 | perf_event_open_cloexec_flag()); | ||
87 | 89 | ||
88 | if (cycle_fd < 0 && errno == ENOSYS) | 90 | if (cycle_fd < 0 && errno == ENOSYS) |
89 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); | 91 | die("No CONFIG_PERF_EVENTS=y kernel support configured?\n"); |
@@ -181,6 +183,11 @@ int bench_mem_memset(int argc, const char **argv, | |||
181 | argc = parse_options(argc, argv, options, | 183 | argc = parse_options(argc, argv, options, |
182 | bench_mem_memset_usage, 0); | 184 | bench_mem_memset_usage, 0); |
183 | 185 | ||
186 | if (no_prefault && only_prefault) { | ||
187 | fprintf(stderr, "Invalid options: -o and -n are mutually exclusive\n"); | ||
188 | return 1; | ||
189 | } | ||
190 | |||
184 | if (use_cycle) | 191 | if (use_cycle) |
185 | init_cycle(); | 192 | init_cycle(); |
186 | 193 | ||
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c index cc1190a0849b..52a56599a543 100644 --- a/tools/perf/bench/sched-messaging.c +++ b/tools/perf/bench/sched-messaging.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <sys/time.h> | 28 | #include <sys/time.h> |
29 | #include <sys/poll.h> | 29 | #include <sys/poll.h> |
30 | #include <limits.h> | 30 | #include <limits.h> |
31 | #include <err.h> | ||
31 | 32 | ||
32 | #define DATASIZE 100 | 33 | #define DATASIZE 100 |
33 | 34 | ||
@@ -50,12 +51,6 @@ struct receiver_context { | |||
50 | int wakefd; | 51 | int wakefd; |
51 | }; | 52 | }; |
52 | 53 | ||
53 | static void barf(const char *msg) | ||
54 | { | ||
55 | fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno)); | ||
56 | exit(1); | ||
57 | } | ||
58 | |||
59 | static void fdpair(int fds[2]) | 54 | static void fdpair(int fds[2]) |
60 | { | 55 | { |
61 | if (use_pipes) { | 56 | if (use_pipes) { |
@@ -66,7 +61,7 @@ static void fdpair(int fds[2]) | |||
66 | return; | 61 | return; |
67 | } | 62 | } |
68 | 63 | ||
69 | barf(use_pipes ? "pipe()" : "socketpair()"); | 64 | err(EXIT_FAILURE, use_pipes ? "pipe()" : "socketpair()"); |
70 | } | 65 | } |
71 | 66 | ||
72 | /* Block until we're ready to go */ | 67 | /* Block until we're ready to go */ |
@@ -77,11 +72,11 @@ static void ready(int ready_out, int wakefd) | |||
77 | 72 | ||
78 | /* Tell them we're ready. */ | 73 | /* Tell them we're ready. */ |
79 | if (write(ready_out, &dummy, 1) != 1) | 74 | if (write(ready_out, &dummy, 1) != 1) |
80 | barf("CLIENT: ready write"); | 75 | err(EXIT_FAILURE, "CLIENT: ready write"); |
81 | 76 | ||
82 | /* Wait for "GO" signal */ | 77 | /* Wait for "GO" signal */ |
83 | if (poll(&pollfd, 1, -1) != 1) | 78 | if (poll(&pollfd, 1, -1) != 1) |
84 | barf("poll"); | 79 | err(EXIT_FAILURE, "poll"); |
85 | } | 80 | } |
86 | 81 | ||
87 | /* Sender sprays loops messages down each file descriptor */ | 82 | /* Sender sprays loops messages down each file descriptor */ |
@@ -101,7 +96,7 @@ again: | |||
101 | ret = write(ctx->out_fds[j], data + done, | 96 | ret = write(ctx->out_fds[j], data + done, |
102 | sizeof(data)-done); | 97 | sizeof(data)-done); |
103 | if (ret < 0) | 98 | if (ret < 0) |
104 | barf("SENDER: write"); | 99 | err(EXIT_FAILURE, "SENDER: write"); |
105 | done += ret; | 100 | done += ret; |
106 | if (done < DATASIZE) | 101 | if (done < DATASIZE) |
107 | goto again; | 102 | goto again; |
@@ -131,7 +126,7 @@ static void *receiver(struct receiver_context* ctx) | |||
131 | again: | 126 | again: |
132 | ret = read(ctx->in_fds[0], data + done, DATASIZE - done); | 127 | ret = read(ctx->in_fds[0], data + done, DATASIZE - done); |
133 | if (ret < 0) | 128 | if (ret < 0) |
134 | barf("SERVER: read"); | 129 | err(EXIT_FAILURE, "SERVER: read"); |
135 | done += ret; | 130 | done += ret; |
136 | if (done < DATASIZE) | 131 | if (done < DATASIZE) |
137 | goto again; | 132 | goto again; |
@@ -144,14 +139,14 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *)) | |||
144 | { | 139 | { |
145 | pthread_attr_t attr; | 140 | pthread_attr_t attr; |
146 | pthread_t childid; | 141 | pthread_t childid; |
147 | int err; | 142 | int ret; |
148 | 143 | ||
149 | if (!thread_mode) { | 144 | if (!thread_mode) { |
150 | /* process mode */ | 145 | /* process mode */ |
151 | /* Fork the receiver. */ | 146 | /* Fork the receiver. */ |
152 | switch (fork()) { | 147 | switch (fork()) { |
153 | case -1: | 148 | case -1: |
154 | barf("fork()"); | 149 | err(EXIT_FAILURE, "fork()"); |
155 | break; | 150 | break; |
156 | case 0: | 151 | case 0: |
157 | (*func) (ctx); | 152 | (*func) (ctx); |
@@ -165,19 +160,17 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *)) | |||
165 | } | 160 | } |
166 | 161 | ||
167 | if (pthread_attr_init(&attr) != 0) | 162 | if (pthread_attr_init(&attr) != 0) |
168 | barf("pthread_attr_init:"); | 163 | err(EXIT_FAILURE, "pthread_attr_init:"); |
169 | 164 | ||
170 | #ifndef __ia64__ | 165 | #ifndef __ia64__ |
171 | if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) | 166 | if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) |
172 | barf("pthread_attr_setstacksize"); | 167 | err(EXIT_FAILURE, "pthread_attr_setstacksize"); |
173 | #endif | 168 | #endif |
174 | 169 | ||
175 | err = pthread_create(&childid, &attr, func, ctx); | 170 | ret = pthread_create(&childid, &attr, func, ctx); |
176 | if (err != 0) { | 171 | if (ret != 0) |
177 | fprintf(stderr, "pthread_create failed: %s (%d)\n", | 172 | err(EXIT_FAILURE, "pthread_create failed"); |
178 | strerror(err), err); | 173 | |
179 | exit(-1); | ||
180 | } | ||
181 | return childid; | 174 | return childid; |
182 | } | 175 | } |
183 | 176 | ||
@@ -207,14 +200,14 @@ static unsigned int group(pthread_t *pth, | |||
207 | + num_fds * sizeof(int)); | 200 | + num_fds * sizeof(int)); |
208 | 201 | ||
209 | if (!snd_ctx) | 202 | if (!snd_ctx) |
210 | barf("malloc()"); | 203 | err(EXIT_FAILURE, "malloc()"); |
211 | 204 | ||
212 | for (i = 0; i < num_fds; i++) { | 205 | for (i = 0; i < num_fds; i++) { |
213 | int fds[2]; | 206 | int fds[2]; |
214 | struct receiver_context *ctx = malloc(sizeof(*ctx)); | 207 | struct receiver_context *ctx = malloc(sizeof(*ctx)); |
215 | 208 | ||
216 | if (!ctx) | 209 | if (!ctx) |
217 | barf("malloc()"); | 210 | err(EXIT_FAILURE, "malloc()"); |
218 | 211 | ||
219 | 212 | ||
220 | /* Create the pipe between client and server */ | 213 | /* Create the pipe between client and server */ |
@@ -281,7 +274,7 @@ int bench_sched_messaging(int argc, const char **argv, | |||
281 | 274 | ||
282 | pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t)); | 275 | pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t)); |
283 | if (!pth_tab) | 276 | if (!pth_tab) |
284 | barf("main:malloc()"); | 277 | err(EXIT_FAILURE, "main:malloc()"); |
285 | 278 | ||
286 | fdpair(readyfds); | 279 | fdpair(readyfds); |
287 | fdpair(wakefds); | 280 | fdpair(wakefds); |
@@ -294,13 +287,13 @@ int bench_sched_messaging(int argc, const char **argv, | |||
294 | /* Wait for everyone to be ready */ | 287 | /* Wait for everyone to be ready */ |
295 | for (i = 0; i < total_children; i++) | 288 | for (i = 0; i < total_children; i++) |
296 | if (read(readyfds[0], &dummy, 1) != 1) | 289 | if (read(readyfds[0], &dummy, 1) != 1) |
297 | barf("Reading for readyfds"); | 290 | err(EXIT_FAILURE, "Reading for readyfds"); |
298 | 291 | ||
299 | gettimeofday(&start, NULL); | 292 | gettimeofday(&start, NULL); |
300 | 293 | ||
301 | /* Kick them off */ | 294 | /* Kick them off */ |
302 | if (write(wakefds[1], &dummy, 1) != 1) | 295 | if (write(wakefds[1], &dummy, 1) != 1) |
303 | barf("Writing to start them"); | 296 | err(EXIT_FAILURE, "Writing to start them"); |
304 | 297 | ||
305 | /* Reap them all */ | 298 | /* Reap them all */ |
306 | for (i = 0; i < total_children; i++) | 299 | for (i = 0; i < total_children; i++) |
@@ -332,5 +325,7 @@ int bench_sched_messaging(int argc, const char **argv, | |||
332 | break; | 325 | break; |
333 | } | 326 | } |
334 | 327 | ||
328 | free(pth_tab); | ||
329 | |||
335 | return 0; | 330 | return 0; |
336 | } | 331 | } |