From owner-svn-src-head@freebsd.org Wed Jul 4 13:39:50 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 09BFA1037825; Wed, 4 Jul 2018 13:39:50 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id B31FE7B5B6; Wed, 4 Jul 2018 13:39:49 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 959963C90; Wed, 4 Jul 2018 13:39:49 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w64Ddnje008169; Wed, 4 Jul 2018 13:39:49 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64Ddndw008168; Wed, 4 Jul 2018 13:39:49 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201807041339.w64Ddndw008168@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Wed, 4 Jul 2018 13:39:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335943 - head/tools/tools/syscall_timing X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/tools/tools/syscall_timing X-SVN-Commit-Revision: 335943 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2018 13:39:50 -0000 Author: trasz Date: Wed Jul 4 13:39:48 2018 New Revision: 335943 URL: https://svnweb.freebsd.org/changeset/base/335943 Log: Add threaded pipe ping benchmark. Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA, AFRL Modified: head/tools/tools/syscall_timing/Makefile head/tools/tools/syscall_timing/syscall_timing.c Modified: head/tools/tools/syscall_timing/Makefile ============================================================================== --- head/tools/tools/syscall_timing/Makefile Wed Jul 4 13:38:02 2018 (r335942) +++ head/tools/tools/syscall_timing/Makefile Wed Jul 4 13:39:48 2018 (r335943) @@ -6,6 +6,8 @@ PROG= syscall_timing CFLAGS+= -static -O MAN= +LIBADD= pthread + WARNS= 6 .include Modified: head/tools/tools/syscall_timing/syscall_timing.c ============================================================================== --- head/tools/tools/syscall_timing/syscall_timing.c Wed Jul 4 13:38:02 2018 (r335942) +++ head/tools/tools/syscall_timing/syscall_timing.c Wed Jul 4 13:39:48 2018 (r335943) @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -158,7 +159,74 @@ test_clock_gettime(uintmax_t num, uintmax_t int_arg __ 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) { struct timeval tv; @@ -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 },