Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Feb 2010 10:51:03 GMT
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 174220 for review
Message-ID:  <201002031051.o13Ap3o6033398@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=174220

Change 174220 by rwatson@rwatson_vimage_client on 2010/02/03 10:50:29

	Benchmark various fork variations with exec of /usr/bin/true.

Affected files ...

.. //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#8 edit

Differences ...

==== //depot/projects/trustedbsd/capabilities/src/tools/tools/syscall_timing/syscall_timing.c#8 (text+ko) ====

@@ -455,6 +455,116 @@
 	benchmark_stop();
 }
 
+#define	USR_BIN_TRUE	"/usr/bin/true"
+static char *execve_args[] = { USR_BIN_TRUE, NULL};
+extern char **environ;
+
+void
+test_fork_exec(int num)
+{
+	pid_t pid;
+	int i;
+
+	pid = fork();
+	if (pid < 0)
+		err(-1, "test_fork: fork");
+	if (pid == 0) {
+		(void)execve(USR_BIN_TRUE, execve_args, environ);
+		err(-1, "execve");
+	}
+	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) {
+			(void)execve(USR_BIN_TRUE, execve_args, environ);
+			err(-1, "execve");
+		}
+		if (waitpid(pid, NULL, 0) < 0)
+			err(-1, "test_fork: waitpid");
+	}
+	benchmark_stop();
+}
+
+void
+test_vfork_exec(int num)
+{
+	pid_t pid;
+	int i;
+
+	pid = vfork();
+	if (pid < 0)
+		err(-1, "test_vfork: vfork");
+	if (pid == 0) {
+		(void)execve(USR_BIN_TRUE, execve_args, environ);
+		err(-1, "execve");
+	}
+	if (waitpid(pid, NULL, 0) < 0)
+		err(-1, "test_vfork: waitpid");
+	benchmark_start();
+	for (i = 0; i < num; i++) {
+		pid = vfork();
+		if (pid < 0)
+			err(-1, "test_vfork: vfork");
+		if (pid == 0) {
+			(void)execve(USR_BIN_TRUE, execve_args, environ);
+			err(-1, "execve");
+		}
+		if (waitpid(pid, NULL, 0) < 0)
+			err(-1, "test_vfork: waitpid");
+	}
+	benchmark_stop();
+}
+
+void
+test_pdfork_exec(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) {
+		(void)execve(USR_BIN_TRUE, execve_args, environ);
+		err(-1, "execve");
+	}
+	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) {
+			(void)execve(USR_BIN_TRUE, execve_args, environ);
+			err(-1, "execve");
+		}
+		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();
+}
+
 #define	MYNAME	"./syscall_timing"		/* Binary to run in sandbox. */
 
 /*
@@ -572,6 +682,9 @@
 	{ "fork", test_fork },
 	{ "vfork", test_vfork },
 	{ "pdfork", test_pdfork },
+	{ "fork_exec", test_fork_exec },
+	{ "vfork_exec", test_vfork_exec },
+	{ "pdfork_exec", test_pdfork_exec },
 	{ "sandbox", test_sandbox },
 };
 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?201002031051.o13Ap3o6033398>