14 #include "../util/util.h"
15 #include "../util/parse-options.h"
16 #include "../builtin.h"
29 #include <sys/types.h>
31 #define LOOPS_DEFAULT 1000000
36 "Specify number of loops"),
40 static const char *
const bench_sched_pipe_usage[] = {
41 "perf bench sched pipe <options>",
48 int pipe_1[2], pipe_2[2];
50 struct timeval start, stop, diff;
51 unsigned long long result_usec = 0;
58 int __maybe_unused
ret, wait_stat;
62 bench_sched_pipe_usage, 0);
73 for (
i = 0;
i < loops;
i++) {
74 ret =
read(pipe_1[0], &m,
sizeof(
int));
75 ret =
write(pipe_2[1], &m,
sizeof(
int));
78 for (
i = 0;
i < loops;
i++) {
79 ret =
write(pipe_1[1], &m,
sizeof(
int));
80 ret =
read(pipe_2[0], &m,
sizeof(
int));
85 timersub(&stop, &start, &diff);
88 retpid = waitpid(pid, &wait_stat, 0);
89 assert((retpid == pid) && WIFEXITED(wait_stat));
96 printf(
"# Executed %d pipe operations between two tasks\n\n",
99 result_usec = diff.
tv_sec * 1000000;
102 printf(
" %14s: %lu.%03lu [sec]\n\n",
"Total time",
104 (
unsigned long) (diff.
tv_usec/1000));
106 printf(
" %14lf usecs/op\n",
107 (
double)result_usec / (
double)loops);
109 (
int)((
double)loops /
110 ((
double)result_usec / (
double)1000000)));
116 (
unsigned long) (diff.
tv_usec / 1000));