From owner-p4-projects@FreeBSD.ORG Mon Jan 7 17:48:21 2013 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 96B7C6E; Mon, 7 Jan 2013 17:48:21 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 4D3746C for ; Mon, 7 Jan 2013 17:48:21 +0000 (UTC) (envelope-from brooks@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 2F60D9C9 for ; Mon, 7 Jan 2013 17:48:21 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.5/8.14.5) with ESMTP id r07HmKon044095 for ; Mon, 7 Jan 2013 17:48:20 GMT (envelope-from brooks@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.5/8.14.5/Submit) id r07HmKN2044092 for perforce@freebsd.org; Mon, 7 Jan 2013 17:48:20 GMT (envelope-from brooks@freebsd.org) Date: Mon, 7 Jan 2013 17:48:20 GMT Message-Id: <201301071748.r07HmKN2044092@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to brooks@freebsd.org using -f From: Brooks Davis Subject: PERFORCE change 219956 for review To: Perforce Change Reviews Precedence: bulk X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.14 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2013 17:48:21 -0000 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 #include +#include + #include #include #include #define _WITH_DPRINTF #include +#include #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 #include +#include #include #include @@ -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 #include +#include #include #include @@ -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 ] ...\n"); + errx(1, "usage: minifile [-t] [-s ] ...\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