Date: Wed, 3 Feb 2010 00:42:53 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 174202 for review Message-ID: <201002030042.o130grBY044908@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=174202 Change 174202 by rwatson@rwatson_vimage_client on 2010/02/03 00:42:30 cap_enter, fork, pdfork benchmarks. Affected files ... .. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#4 edit Differences ... ==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#4 (text+ko) ==== @@ -29,9 +29,12 @@ #include <sys/types.h> #include <sys/capability.h> #include <sys/mman.h> +#include <sys/poll.h> +#include <sys/procdesc.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/time.h> +#include <sys/wait.h> #include <assert.h> #include <err.h> @@ -45,14 +48,14 @@ static struct timespec ts_start, ts_end; #define timespecsub(vvp, uvp) \ - do { \ - (vvp)->tv_sec -= (uvp)->tv_sec; \ - (vvp)->tv_nsec -= (uvp)->tv_nsec; \ - if ((vvp)->tv_nsec < 0) { \ - (vvp)->tv_sec--; \ - (vvp)->tv_nsec += 1000000000; \ - } \ - } while (0) + do { \ + (vvp)->tv_sec -= (uvp)->tv_sec; \ + (vvp)->tv_nsec -= (uvp)->tv_nsec; \ + if ((vvp)->tv_nsec < 0) { \ + (vvp)->tv_sec--; \ + (vvp)->tv_nsec += 1000000000; \ + } \ + } while (0) static void benchmark_start(void) @@ -339,6 +342,91 @@ close(shmfd); } +void +test_cap_enter(int num) +{ + int i; + + /* XXXRW: Note that some tests will fail after this test. */ + + if (cap_enter() < 0) + err(-1, "test_cap_enter: cap_enter"); + benchmark_start(); + for (i = 0; i < num; i++) { + if (cap_enter() < 0) + err(-1, "test_cap_enter: cap_enter"); + } + benchmark_stop(); +} + +void +test_fork(int num) +{ + pid_t pid; + int i; + + pid = fork(); + if (pid < 0) + err(-1, "test_fork: fork"); + if (pid == 0) + exit(0); + if (waitpid(pid, NULL, 0) < 0) + err(-1, "test_fork: waitpid"); + benchmark_start(); + for (i = 0; i < num; i++) { + pid = fork(); + if (pid < 0) + err(-1, "test_fork: fork"); + if (pid == 0) + exit(0); + if (waitpid(pid, NULL, 0) < 0) + err(-1, "test_fork: waitpid"); + } + benchmark_stop(); +} + +void +test_pdfork(int num) +{ + struct pollfd pollfd; + pid_t pid; + int fd, i, n; + + pid = pdfork(&fd); + if (pid < 0) + err(-1, "test_pdfork: pdfork"); + if (pid == 0) + exit(0); + pollfd.fd = fd; + pollfd.events = POLLHUP; + pollfd.revents = 0; + n = poll(&pollfd, 1, INFTIM); + if (n < 0) + err(-1, "poll"); + if (n != 1) + errx(-1, "poll returned %d", n); + close(fd); + + benchmark_start(); + for (i = 0; i < num; i++) { + pid = pdfork(&fd); + if (pid < 0) + err(-1, "test_pdfork: pdfork"); + if (pid == 0) + exit(0); + pollfd.fd = fd; + pollfd.events = POLLHUP; + pollfd.revents = 0; + n = poll(&pollfd, 1, INFTIM); + if (n < 0) + err(-1, "poll"); + if (n != 1) + errx(-1, "poll returned %d", n); + close(fd); + } + benchmark_stop(); +} + struct test { const char *t_name; void (*t_func)(int); @@ -359,6 +447,9 @@ { "test_cap_shmfd", test_cap_shmfd }, { "fstat_shmfd", test_fstat_shmfd }, { "fstat_cap_shmfd", test_fstat_cap_shmfd }, + { "cap_enter", test_cap_enter }, + { "fork", test_fork }, + { "pdfork", test_pdfork }, }; static const int tests_count = sizeof(tests) / sizeof(tests[0]);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201002030042.o130grBY044908>