aboutsummaryrefslogtreecommitdiff
path: root/tools/tools
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2018-07-04 13:34:43 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2018-07-04 13:34:43 +0000
commit8499b5606b99e980f110e298bb6fd9dff02cdcf7 (patch)
treea17812dc8407bb49a83396a58d48e865bce39b2d /tools/tools
parentec58d06a1db2a4cb0c3537524e212a05713022b4 (diff)
downloadsrc-8499b5606b99e980f110e298bb6fd9dff02cdcf7.tar.gz
src-8499b5606b99e980f110e298bb6fd9dff02cdcf7.zip
Add a trivial "pipe ping" (two processes) benchmark.
Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA, AFRL
Notes
Notes: svn path=/head/; revision=335941
Diffstat (limited to 'tools/tools')
-rw-r--r--tools/tools/syscall_timing/syscall_timing.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/tools/tools/syscall_timing/syscall_timing.c b/tools/tools/syscall_timing/syscall_timing.c
index ba15c9ed4fd3..6694294b4ef3 100644
--- a/tools/tools/syscall_timing/syscall_timing.c
+++ b/tools/tools/syscall_timing/syscall_timing.c
@@ -31,6 +31,7 @@
#include <sys/types.h>
#include <sys/mman.h>
+#include <sys/procdesc.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
@@ -251,6 +252,52 @@ test_select(uintmax_t num, uintmax_t int_arg __unused, const char *path __unused
}
static uintmax_t
+test_pipeping(uintmax_t num, uintmax_t int_arg, const char *path __unused)
+{
+ char buf[int_arg];
+ uintmax_t i;
+ ssize_t ret;
+ pid_t pid;
+ int fd[2], procfd;
+
+ if (pipe(fd) < 0)
+ err(-1, "pipe");
+
+ pid = pdfork(&procfd, 0);
+ if (pid < 0)
+ err(1, "pdfork");
+
+ if (pid == 0) {
+ close(fd[0]);
+
+ for (;;) {
+ ret = read(fd[1], buf, int_arg);
+ if ((uintmax_t)ret != int_arg)
+ err(1, "read");
+ ret = write(fd[1], buf, int_arg);
+ if ((uintmax_t)ret != int_arg)
+ err(1, "write");
+ }
+ }
+
+ close(fd[1]);
+
+ 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();
+
+ close(procfd);
+ return (i);
+}
+
+static uintmax_t
test_socket_stream(uintmax_t num, uintmax_t int_arg, const char *path __unused)
{
uintmax_t i;
@@ -694,6 +741,18 @@ static const struct test tests[] = {
{ "getppid", test_getppid, .t_flags = 0 },
{ "getresuid", test_getresuid, .t_flags = 0 },
{ "clock_gettime", test_clock_gettime, .t_flags = 0 },
+ { "pipeping_1", test_pipeping, .t_flags = 0, .t_int = 1 },
+ { "pipeping_10", test_pipeping, .t_flags = 0, .t_int = 10 },
+ { "pipeping_100", test_pipeping, .t_flags = 0, .t_int = 100 },
+ { "pipeping_1000", test_pipeping, .t_flags = 0, .t_int = 1000 },
+ { "pipeping_10000", test_pipeping, .t_flags = 0, .t_int = 10000 },
+#ifdef notyet
+ /*
+ * XXX: Doesn't work; kernel pipe buffer too small?
+ */
+ { "pipeping_100000", test_pipeping, .t_flags = 0, .t_int = 100000 },
+ { "pipeping_1000000", test_pipeping, .t_flags = 0, .t_int = 1000000 },
+ #endif
{ "gettimeofday", test_gettimeofday, .t_flags = 0 },
{ "getpriority", test_getpriority, .t_flags = 0 },
{ "getprogname", test_getprogname, .t_flags = 0 },