Commit ecdac968 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Arnaldo Carvalho de Melo

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: default avatarDavidlohr 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 424e9634
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <limits.h> #include <limits.h>
#include <err.h>
#define DATASIZE 100 #define DATASIZE 100
...@@ -50,12 +51,6 @@ struct receiver_context { ...@@ -50,12 +51,6 @@ struct receiver_context {
int wakefd; int wakefd;
}; };
static void barf(const char *msg)
{
fprintf(stderr, "%s (error: %s)\n", msg, strerror(errno));
exit(1);
}
static void fdpair(int fds[2]) static void fdpair(int fds[2])
{ {
if (use_pipes) { if (use_pipes) {
...@@ -66,7 +61,7 @@ static void fdpair(int fds[2]) ...@@ -66,7 +61,7 @@ static void fdpair(int fds[2])
return; return;
} }
barf(use_pipes ? "pipe()" : "socketpair()"); err(EXIT_FAILURE, use_pipes ? "pipe()" : "socketpair()");
} }
/* Block until we're ready to go */ /* Block until we're ready to go */
...@@ -77,11 +72,11 @@ static void ready(int ready_out, int wakefd) ...@@ -77,11 +72,11 @@ static void ready(int ready_out, int wakefd)
/* Tell them we're ready. */ /* Tell them we're ready. */
if (write(ready_out, &dummy, 1) != 1) if (write(ready_out, &dummy, 1) != 1)
barf("CLIENT: ready write"); err(EXIT_FAILURE, "CLIENT: ready write");
/* Wait for "GO" signal */ /* Wait for "GO" signal */
if (poll(&pollfd, 1, -1) != 1) if (poll(&pollfd, 1, -1) != 1)
barf("poll"); err(EXIT_FAILURE, "poll");
} }
/* Sender sprays loops messages down each file descriptor */ /* Sender sprays loops messages down each file descriptor */
...@@ -101,7 +96,7 @@ static void *sender(struct sender_context *ctx) ...@@ -101,7 +96,7 @@ static void *sender(struct sender_context *ctx)
ret = write(ctx->out_fds[j], data + done, ret = write(ctx->out_fds[j], data + done,
sizeof(data)-done); sizeof(data)-done);
if (ret < 0) if (ret < 0)
barf("SENDER: write"); err(EXIT_FAILURE, "SENDER: write");
done += ret; done += ret;
if (done < DATASIZE) if (done < DATASIZE)
goto again; goto again;
...@@ -131,7 +126,7 @@ static void *receiver(struct receiver_context* ctx) ...@@ -131,7 +126,7 @@ static void *receiver(struct receiver_context* ctx)
again: again:
ret = read(ctx->in_fds[0], data + done, DATASIZE - done); ret = read(ctx->in_fds[0], data + done, DATASIZE - done);
if (ret < 0) if (ret < 0)
barf("SERVER: read"); err(EXIT_FAILURE, "SERVER: read");
done += ret; done += ret;
if (done < DATASIZE) if (done < DATASIZE)
goto again; goto again;
...@@ -144,14 +139,14 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *)) ...@@ -144,14 +139,14 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *))
{ {
pthread_attr_t attr; pthread_attr_t attr;
pthread_t childid; pthread_t childid;
int err; int ret;
if (!thread_mode) { if (!thread_mode) {
/* process mode */ /* process mode */
/* Fork the receiver. */ /* Fork the receiver. */
switch (fork()) { switch (fork()) {
case -1: case -1:
barf("fork()"); err(EXIT_FAILURE, "fork()");
break; break;
case 0: case 0:
(*func) (ctx); (*func) (ctx);
...@@ -165,19 +160,17 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *)) ...@@ -165,19 +160,17 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *))
} }
if (pthread_attr_init(&attr) != 0) if (pthread_attr_init(&attr) != 0)
barf("pthread_attr_init:"); err(EXIT_FAILURE, "pthread_attr_init:");
#ifndef __ia64__ #ifndef __ia64__
if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0) if (pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN) != 0)
barf("pthread_attr_setstacksize"); err(EXIT_FAILURE, "pthread_attr_setstacksize");
#endif #endif
err = pthread_create(&childid, &attr, func, ctx); ret = pthread_create(&childid, &attr, func, ctx);
if (err != 0) { if (ret != 0)
fprintf(stderr, "pthread_create failed: %s (%d)\n", err(EXIT_FAILURE, "pthread_create failed");
strerror(err), err);
exit(-1);
}
return childid; return childid;
} }
...@@ -207,14 +200,14 @@ static unsigned int group(pthread_t *pth, ...@@ -207,14 +200,14 @@ static unsigned int group(pthread_t *pth,
+ num_fds * sizeof(int)); + num_fds * sizeof(int));
if (!snd_ctx) if (!snd_ctx)
barf("malloc()"); err(EXIT_FAILURE, "malloc()");
for (i = 0; i < num_fds; i++) { for (i = 0; i < num_fds; i++) {
int fds[2]; int fds[2];
struct receiver_context *ctx = malloc(sizeof(*ctx)); struct receiver_context *ctx = malloc(sizeof(*ctx));
if (!ctx) if (!ctx)
barf("malloc()"); err(EXIT_FAILURE, "malloc()");
/* Create the pipe between client and server */ /* Create the pipe between client and server */
...@@ -281,7 +274,7 @@ int bench_sched_messaging(int argc, const char **argv, ...@@ -281,7 +274,7 @@ int bench_sched_messaging(int argc, const char **argv,
pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t)); pth_tab = malloc(num_fds * 2 * num_groups * sizeof(pthread_t));
if (!pth_tab) if (!pth_tab)
barf("main:malloc()"); err(EXIT_FAILURE, "main:malloc()");
fdpair(readyfds); fdpair(readyfds);
fdpair(wakefds); fdpair(wakefds);
...@@ -294,13 +287,13 @@ int bench_sched_messaging(int argc, const char **argv, ...@@ -294,13 +287,13 @@ int bench_sched_messaging(int argc, const char **argv,
/* Wait for everyone to be ready */ /* Wait for everyone to be ready */
for (i = 0; i < total_children; i++) for (i = 0; i < total_children; i++)
if (read(readyfds[0], &dummy, 1) != 1) if (read(readyfds[0], &dummy, 1) != 1)
barf("Reading for readyfds"); err(EXIT_FAILURE, "Reading for readyfds");
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
/* Kick them off */ /* Kick them off */
if (write(wakefds[1], &dummy, 1) != 1) if (write(wakefds[1], &dummy, 1) != 1)
barf("Writing to start them"); err(EXIT_FAILURE, "Writing to start them");
/* Reap them all */ /* Reap them all */
for (i = 0; i < total_children; i++) for (i = 0; i < total_children; i++)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment