13 #include "../util/util.h" 14 #include <subcmd/parse-options.h> 15 #include "../builtin.h" 27 #include <sys/types.h> 28 #include <sys/syscall.h> 29 #include <linux/time64.h> 40 #define LOOPS_DEFAULT 1000000 47 OPT_INTEGER(
'l',
"loop", &
loops,
"Specify number of loops"),
48 OPT_BOOLEAN(
'T',
"threaded", &
threaded,
"Specify threads/process based task setup"),
53 "perf bench sched pipe <options>",
63 for (i = 0; i <
loops; i++) {
65 ret = read(td->
pipe_read, &m,
sizeof(
int));
66 BUG_ON(ret !=
sizeof(
int));
68 BUG_ON(ret !=
sizeof(
int));
71 BUG_ON(ret !=
sizeof(
int));
72 ret = read(td->
pipe_read, &m,
sizeof(
int));
73 BUG_ON(ret !=
sizeof(
int));
83 int pipe_1[2], pipe_2[2];
84 struct timeval start, stop, diff;
85 unsigned long long result_usec = 0;
94 int __maybe_unused ret, wait_stat;
95 pid_t
pid, retpid __maybe_unused;
100 BUG_ON(pipe(pipe_2));
102 gettimeofday(&start, NULL);
104 for (t = 0; t < nr_threads; t++) {
121 for (t = 0; t < nr_threads; t++) {
128 for (t = 0; t < nr_threads; t++) {
131 ret = pthread_join(td->
pthread, NULL);
146 retpid = waitpid(pid, &wait_stat, 0);
147 assert((retpid == pid) && WIFEXITED(wait_stat));
150 gettimeofday(&stop, NULL);
151 timersub(&stop, &start, &diff);
155 printf(
"# Executed %d pipe operations between two %s\n\n",
158 result_usec = diff.tv_sec * USEC_PER_SEC;
159 result_usec += diff.tv_usec;
161 printf(
" %14s: %lu.%03lu [sec]\n\n",
"Total time",
163 (
unsigned long) (diff.tv_usec / USEC_PER_MSEC));
165 printf(
" %14lf usecs/op\n",
166 (
double)result_usec / (
double)
loops);
167 printf(
" %14d ops/sec\n",
168 (
int)((
double)loops /
169 ((
double)result_usec / (
double)USEC_PER_SEC)));
173 printf(
"%lu.%03lu\n",
175 (
unsigned long) (diff.tv_usec / USEC_PER_MSEC));
static void * worker_thread(void *__tdata)
#define BENCH_FORMAT_DEFAULT
static const char *const bench_sched_pipe_usage[]
int bench_sched_pipe(int argc, const char **argv)
#define BENCH_FORMAT_SIMPLE