Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jan 2013 17:48:20 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 219956 for review
Message-ID:  <201301071748.r07HmKN2044092@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@219956?ac=10

Change 219956 by brooks@brooks_zenith on 2013/01/07 17:47:52

	Checkpoint some work from December to produce timings of sandbox
	performance.

Affected files ...

.. //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/capsicum/minifile-capsicum.c#2 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/cheri/Makefile#2 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/cheri/minifile-cheri.c#2 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/minifile.c#7 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/minifile.h#3 edit

Differences ...

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/capsicum/minifile-capsicum.c#2 (text+ko) ====

@@ -33,11 +33,14 @@
 #include <sys/mman.h>
 #include <sys/stat.h>
 
+#include <machine/sysarch.h>
+
 #include <err.h>
 #include <magic.h>
 #include <stdlib.h>
 #define _WITH_DPRINTF
 #include <stdio.h>
+#include <unistd.h>
 
 #include "minifile.h"
 
@@ -50,7 +53,10 @@
 	void *magicbuf;
 	struct stat filesb, magicsb;
 	magic_t magic;
+	uint32_t timing[4];
 
+	timing[0] = sysarch(MIPS_GET_COUNT, NULL);
+
 	if (cap_enter() == -1)
 		err(1, "cap_enter");
 
@@ -59,7 +65,7 @@
 
 	if (fstat(MINIFILE_FILE_FD, &filesb) == -1)
 		err(1, "fstat input fd");
-	filesize = MAX(MINIFILE_BUF_MAX, filesb.st_size);
+	filesize = MIN(MINIFILE_BUF_MAX, filesb.st_size);
 	if ((filebuf = mmap(NULL, filesize, PROT_READ, 0, MINIFILE_FILE_FD,
 	    0)) == MAP_FAILED)
 		err(1, "mmap input fd");
@@ -79,7 +85,13 @@
                 exit(1);
         }
 
+	timing[1] = sysarch(MIPS_GET_COUNT, NULL);
+
 	type = magic_buffer(magic, filebuf, filesize);
+	timing[2] = sysarch(MIPS_GET_COUNT, NULL);
+	/* XXX: idealy would be after the dprintf to capture it's cost */
+	timing[3] = sysarch(MIPS_GET_COUNT, NULL);
+	write(MINIFILE_OUT_FD, timing, sizeof(uint32_t) * 4);
 	dprintf(MINIFILE_OUT_FD, "%s", type != NULL ? type : "badmagic");
 
 	return (0);

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/cheri/Makefile#2 (text+ko) ====

@@ -5,10 +5,12 @@
 
 .PATH: ${.CURDIR}/${MACHINE_ARCH}
 SRCS=	minifile-cheri.c			\
+	chsbrt.S				\
 	malloc.c				\
 	stub.c					\
-	subr_prf.c				\
-	chsbrt.S
+	subr_prf.c
+
+#	lib.S					\
 
 .PATH: ${.CURDIR}/../../../lib/libc/${MACHINE}/gen
 .PATH: ${.CURDIR}/../../../lib/libc/${MACHINE}/string
@@ -25,6 +27,7 @@
 SRCS+=	_flock_stub.c				\
 	_once_stub.c				\
 	_pthread_stubs.c			\
+	cerror.S				\
 	ffs.S					\
 	fileno.c				\
 	getprogname.c				\
@@ -53,7 +56,9 @@
 	strstr.c				\
 	strtol.c				\
 	strtoul.c				\
-	strtoull.c
+	strtoull.c				\
+	sysarch.S
+#	memcpy.S				\
 
 # Locale support
 .PATH: ${.CURDIR}/../../../lib/libc/locale
@@ -167,7 +172,6 @@
 	regerror.c				\
 	regexec.c				\
 	regfree.c				\
-	cerror.S
 
 MAN=
 

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/cheri/minifile-cheri.c#2 (text+ko) ====

@@ -33,6 +33,7 @@
 #include <sys/capability.h>
 
 #include <machine/cheri.h>
+#include <machine/sysarch.h>
 
 #include <magic.h>
 #include <stdlib.h>
@@ -46,11 +47,11 @@
  * Sandboxed magic_buffer invocation
  * 
  * a0 holds length of the output capabilty, a1 holds the length of the
- * magic data, and a2 holds the length of the input file buffer.
+ * magic data, and a2 holds the length of the input file buffer.  a3
+ * indicates if timing data should be collected.
  */
 int
-invoke(register_t a0, register_t a1, register_t a2,
-    register_t a3 __unused)
+invoke(register_t a0, register_t a1, register_t a2, register_t a3)
 {
 	int ret = 0;
 	size_t outsize, magicsize, filesize;
@@ -58,10 +59,16 @@
 	const char *type, *errstr;
 	void *magicbuf;
 	magic_t magic;
+	int dotimings;
+	uint32_t timings[4];
 
 	outsize = a0;
 	magicsize = a1;
 	filesize = a2;
+	dotimings = a3;
+
+	if (dotimings)
+		timings[0] = sysarch(MIPS_GET_COUNT, NULL);
 
 	if ((magicbuf = malloc(magicsize)) == NULL)
 		return (-1);
@@ -78,6 +85,9 @@
 		return (-1);
 	memcpy_fromcap(filebuf, MINIFILE_FILE_CAP, 0, filesize);
 
+	if (dotimings)
+		timings[1] = sysarch(MIPS_GET_COUNT, NULL);
+
         type = magic_buffer(magic, filebuf, filesize);
 	if (type == NULL) {
 		ret = -1;
@@ -85,7 +95,17 @@
 		type = (errstr == NULL ? "badmagic" : errstr);
 	}
 
+	if (dotimings)
+		timings[2] = sysarch(MIPS_GET_COUNT, NULL);
+
 	memcpy_tocap(MINIFILE_OUT_CAP, type, 0, MIN(strlen(type) + 1, outsize));
 
+	if (dotimings) {
+		timings[3] = sysarch(MIPS_GET_COUNT, NULL);
+
+		memcpy_tocap(MINIFILE_TIMING_CAP, timings, 0,
+		    (4 * sizeof(uint32_t)));
+	}
+
 	return (ret);
 }

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/minifile.c#7 (text+ko) ====

@@ -7,6 +7,7 @@
 
 #include <machine/cheri.h>
 #include <machine/cpuregs.h>
+#include <machine/sysarch.h>
 
 #include <err.h>
 #include <errno.h>
@@ -28,13 +29,15 @@
 	SB_CHERI
 } sbtype = SB_NONE;
 
+int dotimings;
+
 #define MAGIC_FILE	"/usr/share/misc/magic.mgc"
 
 static void
 usage(void)
 {
 
-	errx(1, "usage: minifile [-s <sandbox type>] <file> ...\n");
+	errx(1, "usage: minifile [-t] [-s <sandbox type>] <file> ...\n");
 }
 
 /*
@@ -97,9 +100,15 @@
 	char *type, *ttype;
 	int pfd[2];
 	int curfds[3], targetfds[3];
+	uint32_t start, preinvoke, *invoke, postinvoke, end;
+
+	if (dotimings)
+		start = sysarch(MIPS_GET_COUNT, NULL);
 
 	if (pipe(pfd) == -1)
 		err(1, "pipe()");
+	if (dotimings)
+		preinvoke = sysarch(MIPS_GET_COUNT, NULL);
 	pid = fork();
 	if (pid < 0)
 		err(1, "fork()");
@@ -117,7 +126,8 @@
 		if (prep_fds(curfds, targetfds, 3) == -1)
 			err(1, "pred_fds()");
 
-		execl("/usr/libexec/minifile-capsicum", "readpng", NULL);
+		execl("/usr/libexec/minifile-capsicum", "minifile-capsicum",
+		    NULL);
 		err(1, "exec /usr/libexec/minifile-capsicum");
 	} else {
 		close(pfd[1]);
@@ -133,26 +143,37 @@
 			close(pfd[0]);
 			type = "badmagic";
 		} else {
-			rlen = read(pfd[0], buf, 128);
+			rlen = read(pfd[0], buf, 128 + sizeof(uint32_t) * 4);
 			close(pfd[0]);
+			if (dotimings)
+				postinvoke = sysarch(MIPS_GET_COUNT, NULL);
 			if (rlen == -1)
 				type = "read error";
-			else if (rlen == 0 || rlen == 1)
+			else if (rlen <= sizeof(uint32_t) * 4 + 1)
 				type = "unknown";
 			else {
+				invoke = (uint32_t*)buf;
 				/* Don't trust the result */
-				ttype = buf + rlen;
-				strvisx(ttype, buf, rlen, 0);
+				ttype = buf + rlen + sizeof(uint32_t) * 4;
+				strvisx(ttype, buf + sizeof(uint32_t) * 4,
+				    rlen - sizeof(uint32_t) * 4, 0);
 				type = ttype;
 			}
 		}
 	}
 
+	if (dotimings) {
+		end = sysarch(MIPS_GET_COUNT, NULL);
+
+		printf("counts: %u %u %u %u %u %u %u %u\n", start, preinvoke,
+		    invoke[0], invoke[1], invoke[2], invoke[3], postinvoke, end);
+	}
+
 	return type;
 }
 
 static struct sandbox *sandbox;
-static struct chericap file_cap, magic_cap, out_cap;
+static struct chericap file_cap, magic_cap, out_cap, timing_cap;
 
 const char *
 cheri_magic_descriptor(void *magicbuf, size_t magicsize, int fd)
@@ -164,9 +185,13 @@
 	static char outbuf[4096];
 	const char *type;
 	char *ttype;
+	uint32_t start, preinvoke, invoke[4], postinvoke, end;
 
 	type = "badfile";
 
+	if (dotimings)
+		start = sysarch(MIPS_GET_COUNT, NULL);
+
 	outsize = 128;
 	CHERI_CINCBASE(10, 0, outbuf);
 	CHERI_CSETLEN(10, 10, outsize);
@@ -191,9 +216,19 @@
 	CHERI_CANDPERM(10, 10, CHERI_PERM_LOAD);
 	CHERI_CSC(10, 0, &file_cap, 0);
 
-	v = sandbox_invoke(sandbox, outsize, magicsize, filesize, 0,
-	    &out_cap, &magic_cap, &file_cap, NULL, NULL, NULL, NULL);
-	printf("%s: sandbox returned %ju\n", __func__, (uintmax_t)v);
+	CHERI_CINCBASE(10, 0, invoke);
+	CHERI_CSETLEN(10, 10, sizeof(uint32_t) * 4);
+	CHERI_CANDPERM(10, 10, CHERI_PERM_STORE);
+	CHERI_CSC(10, 0, &timing_cap, 0);
+
+	if (dotimings)
+		preinvoke = sysarch(MIPS_GET_COUNT, NULL);
+
+	v = sandbox_invoke(sandbox, outsize, magicsize, filesize, dotimings,
+	    &out_cap, &magic_cap, &file_cap, &timing_cap, NULL, NULL, NULL);
+
+	if (dotimings)
+		postinvoke = sysarch(MIPS_GET_COUNT, NULL);
 
 	outsize = strnlen(outbuf, outsize);
 	if (v == 0) {
@@ -207,6 +242,13 @@
 	if (munmap(filebuf, filesize) == -1)
 		warn("munmap filebuf");
 
+	if (dotimings) {
+		end = sysarch(MIPS_GET_COUNT, NULL);
+
+		printf("counts: %u %u %u %u %u %u %u %u\n", start, preinvoke,
+		    invoke[0], invoke[1], invoke[2], invoke[3], postinvoke, end);
+	}
+
 	return type;
 }
 
@@ -222,7 +264,7 @@
 	struct magic_set *magic;
 	struct stat magicsb;
 
-	while ((ch = getopt(argc, argv, "s:")) != -1) {
+	while ((ch = getopt(argc, argv, "s:t")) != -1) {
 		switch(ch) {
 		case 's':
 			if (strcmp(optarg, "none") == 0)
@@ -235,6 +277,12 @@
 				warnx("invalid sandbox type %s", optarg);
 				usage();
 			}
+			break;
+		case 't':
+			dotimings = 1;
+			break;
+		default:
+			usage();
 		}
 	}
 	argc -= optind;

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/minifile/minifile.h#3 (text+ko) ====

@@ -5,5 +5,6 @@
 #define	MINIFILE_OUT_CAP	1
 #define	MINIFILE_MAGIC_CAP	2
 #define	MINIFILE_FILE_CAP	3
+#define	MINIFILE_TIMING_CAP	4
 
 #define	MINIFILE_BUF_MAX	4096



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201301071748.r07HmKN2044092>