From owner-svn-src-head@freebsd.org Wed Jul 4 14:20:20 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 4865D103B590; Wed, 4 Jul 2018 14:20:20 +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 F2C057E1C6; Wed, 4 Jul 2018 14:20:19 +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 BB9CB4391; Wed, 4 Jul 2018 14:20:19 +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 w64EKJZA029716; Wed, 4 Jul 2018 14:20:19 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w64EKJQu029715; Wed, 4 Jul 2018 14:20:19 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201807041420.w64EKJQu029715@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 14:20:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335956 - 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: 335956 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 14:20:20 -0000 Author: trasz Date: Wed Jul 4 14:20:19 2018 New Revision: 335956 URL: https://svnweb.freebsd.org/changeset/base/335956 Log: Add a semaphore ping benchmark. Obtained from: CheriBSD MFC after: 2 weeks Sponsored by: DARPA, AFRL Modified: head/tools/tools/syscall_timing/syscall_timing.c Modified: head/tools/tools/syscall_timing/syscall_timing.c ============================================================================== --- head/tools/tools/syscall_timing/syscall_timing.c Wed Jul 4 14:18:12 2018 (r335955) +++ head/tools/tools/syscall_timing/syscall_timing.c Wed Jul 4 14:20:19 2018 (r335956) @@ -29,6 +29,7 @@ * $FreeBSD$ */ +#include #include #include #include @@ -47,6 +48,7 @@ #ifdef WITH_PTHREAD #include #endif +#include #include #include #include @@ -606,6 +608,65 @@ test_select(uintmax_t num, uintmax_t int_arg __unused, } static uintmax_t +test_semaping(uintmax_t num, uintmax_t int_arg __unused, const char *path __unused) +{ + uintmax_t i; + pid_t pid; + sem_t *buf; + int error, j, procfd; + + buf = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0); + if (buf == MAP_FAILED) + err(1, "mmap"); + + for (j = 0; j < 2; j++) { + error = sem_init(&buf[j], 1, 0); + if (error != 0) + err(1, "sem_init"); + } + + pid = pdfork(&procfd, 0); + if (pid < 0) + err(1, "pdfork"); + + if (pid == 0) { + for (;;) { + error = sem_wait(&buf[0]); + if (error != 0) + err(1, "sem_wait"); + error = sem_post(&buf[1]); + if (error != 0) + err(1, "sem_post"); + } + } + + benchmark_start(); + BENCHMARK_FOREACH(i, num) { + error = sem_post(&buf[0]); + if (error != 0) + err(1, "sem_post"); + error = sem_wait(&buf[1]); + if (error != 0) + err(1, "sem_wait"); + } + benchmark_stop(); + + close(procfd); + + for (j = 0; j < 2; j++) { + error = sem_destroy(&buf[j]); + if (error != 0) + err(1, "sem_destroy"); + } + + error = munmap(buf, PAGE_SIZE); + if (error != 0) + err(1, "munmap"); + + return (i); +} + +static uintmax_t test_setuid(uintmax_t num, uintmax_t int_arg __unused, const char *path __unused) { uid_t uid; @@ -900,6 +961,7 @@ static const struct test tests[] = { { "read_100000", test_read, .t_flags = FLAG_PATH, .t_int = 100000 }, { "read_1000000", test_read, .t_flags = FLAG_PATH, .t_int = 1000000 }, { "select", test_select, .t_flags = 0 }, + { "semaping", test_semaping, .t_flags = 0 }, { "setuid", test_setuid, .t_flags = 0 }, { "shmfd", test_shmfd, .t_flags = 0 }, { "shmfd_dup", test_shmfd_dup, .t_flags = 0 },