diff options
author | Davidlohr Bueso <davidlohr@hp.com> | 2014-06-16 14:14:26 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-06-19 15:13:17 -0400 |
commit | ecdac96899e3db3f428e4d2e978f25e3f8d35a6c (patch) | |
tree | 1154dd97c0940e56a37917f8dc977e24b3e1902a /tools/perf/bench | |
parent | 424e9634887842ac59c1d06d3264aaeb18853c0b (diff) |
perf bench sched-messaging: Drop barf()
Instead of reinventing the wheel, we can use err(2) when dealing with
fatal errors. Exit code is now always EXIT_FAILURE (1).
Signed-off-by: Davidlohr Bueso <davidlohr@hp.com>
Cc: Aswin Chandramouleeswaran <aswin@hp.com>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: http://lkml.kernel.org/r/1402942467-10671-9-git-send-email-davidlohr@hp.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/bench')
-rw-r--r-- | tools/perf/bench/sched-messaging.c | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c index fc4fe91ee098..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++) |