diff options
author | Edward Tomasz Napierala <trasz@FreeBSD.org> | 2018-07-04 13:39:48 +0000 |
---|---|---|
committer | Edward Tomasz Napierala <trasz@FreeBSD.org> | 2018-07-04 13:39:48 +0000 |
commit | fc3bc496f49cfa54027371eea01407363538a8c7 (patch) | |
tree | 7a2d6d498d5a37b3315c7743eee128adc967f54e /tools/tools | |
parent | 515a5d0239f30c6505e0a5ae45340ce2624d9e75 (diff) | |
download | src-fc3bc496f49cfa54027371eea01407363538a8c7.tar.gz src-fc3bc496f49cfa54027371eea01407363538a8c7.zip |
Add threaded pipe ping benchmark.
Obtained from: CheriBSD
MFC after: 2 weeks
Sponsored by: DARPA, AFRL
Notes
Notes:
svn path=/head/; revision=335943
Diffstat (limited to 'tools/tools')
-rw-r--r-- | tools/tools/syscall_timing/Makefile | 2 | ||||
-rw-r--r-- | tools/tools/syscall_timing/syscall_timing.c | 80 |
2 files changed, 82 insertions, 0 deletions
diff --git a/tools/tools/syscall_timing/Makefile b/tools/tools/syscall_timing/Makefile index 50bc587225c1..6d87bde582ce 100644 --- a/tools/tools/syscall_timing/Makefile +++ b/tools/tools/syscall_timing/Makefile @@ -6,6 +6,8 @@ PROG= syscall_timing CFLAGS+= -static -O MAN= +LIBADD= pthread + WARNS= 6 .include <bsd.prog.mk> diff --git a/tools/tools/syscall_timing/syscall_timing.c b/tools/tools/syscall_timing/syscall_timing.c index 6694294b4ef3..05266179c413 100644 --- a/tools/tools/syscall_timing/syscall_timing.c +++ b/tools/tools/syscall_timing/syscall_timing.c @@ -44,6 +44,7 @@ #include <fcntl.h> #include <inttypes.h> #include <limits.h> +#include <pthread.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -158,6 +159,73 @@ test_clock_gettime(uintmax_t num, uintmax_t int_arg __unused, const char *path _ return (i); } +struct pipepingtd_ctx { + int fd; + uintmax_t int_arg; +}; + +static void * +pipepingtd_proc(void *arg) +{ + struct pipepingtd_ctx *ctxp; + int fd; + void *buf; + uintmax_t int_arg; + ssize_t ret; + + ctxp = arg; + fd = ctxp->fd; + int_arg = ctxp->int_arg; + + buf = malloc(int_arg); + if (buf == NULL) + err(1, "malloc"); + + for (;;) { + ret = read(fd, buf, int_arg); + if ((uintmax_t)ret != int_arg) + err(1, "read"); + ret = write(fd, buf, int_arg); + if ((uintmax_t)ret != int_arg) + err(1, "write"); + } +} + +static uintmax_t +test_pipepingtd(uintmax_t num, uintmax_t int_arg, const char *path __unused) +{ + struct pipepingtd_ctx ctx; + char buf[int_arg]; + pthread_t td; + uintmax_t i; + ssize_t ret; + int error, fd[2]; + + if (pipe(fd) < 0) + err(-1, "pipe"); + + ctx.fd = fd[1]; + ctx.int_arg = int_arg; + + error = pthread_create(&td, NULL, pipepingtd_proc, &ctx); + if (error != 0) + err(1, "pthread_create"); + + benchmark_start(); + BENCHMARK_FOREACH(i, num) { + ret = write(fd[0], buf, int_arg); + if ((uintmax_t)ret != int_arg) + err(1, "write"); + ret = read(fd[0], buf, int_arg); + if ((uintmax_t)ret != int_arg) + err(1, "read"); + } + benchmark_stop(); + pthread_cancel(td); + + return (i); +} + static uintmax_t test_gettimeofday(uintmax_t num, uintmax_t int_arg __unused, const char *path __unused) { @@ -752,6 +820,18 @@ static const struct test tests[] = { */ { "pipeping_100000", test_pipeping, .t_flags = 0, .t_int = 100000 }, { "pipeping_1000000", test_pipeping, .t_flags = 0, .t_int = 1000000 }, +#endif + { "pipepingtd_1", test_pipepingtd, .t_flags = 0, .t_int = 1 }, + { "pipepingtd_10", test_pipepingtd, .t_flags = 0, .t_int = 10 }, + { "pipepingtd_100", test_pipepingtd, .t_flags = 0, .t_int = 100 }, + { "pipepingtd_1000", test_pipepingtd, .t_flags = 0, .t_int = 1000 }, + { "pipepingtd_10000", test_pipepingtd, .t_flags = 0, .t_int = 10000 }, +#ifdef notyet + /* + * XXX: Doesn't work; kernel pipe buffer too small? + */ + { "pipepingtd_100000", test_pipepingtd, .t_flags = 0, .t_int = 100000 }, + { "pipepingtd_1000000", test_pipepingtd, .t_flags = 0, .t_int = 1000000 }, #endif { "gettimeofday", test_gettimeofday, .t_flags = 0 }, { "getpriority", test_getpriority, .t_flags = 0 }, |