Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Dec 2012 00:20:07 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 219906 for review
Message-ID:  <201212140020.qBE0K7dH069234@skunkworks.freebsd.org>

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

Change 219906 by brooks@brooks_zenith on 2012/12/14 00:19:39

	Snapshot the cycle counter at four points in the png decoding
	process:
	 - As the sandbox specific function is entered.
	 - As the core decoding function is entered and exited.
	 - As late as possible without waiting for a call to
	   read_png_finish() which may take an indefinite amout of time.
	
	Add a pair of accessor functions to retrieve the total
	runtime and the decoding time.

Affected files ...

.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/decode_png.c#6 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/imagebox.h#5 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#10 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng-cheri/Makefile#3 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng-cheri/readpng-cheri.c#7 edit
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng-cheri/sysarch.S#1 add
.. //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng/readpng.c#5 edit

Differences ...

==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/decode_png.c#6 (text+ko) ====

@@ -30,6 +30,8 @@
 
 #include <sys/types.h>
 
+#include <machine/sysarch.h>
+
 #include <png.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -53,6 +55,8 @@
 	png_infop end_info = NULL;
 	png_bytep *rows = NULL;
 
+	ids->is->times[1] = sysarch(MIPS_GET_COUNT, 0);
+
 	if ((png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
 	    NULL, NULL, NULL)) == NULL) {
 		ids->is->error = 1;
@@ -125,6 +129,7 @@
 error:
 	png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
 	close(ids->fd);
+	ids->is->times[2] = sysarch(MIPS_GET_COUNT, 0);
 	free(rows);
 }
 

==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/imagebox.h#5 (text+ko) ====

@@ -45,6 +45,7 @@
 	volatile uint32_t	 passes_remaining;
 	volatile uint32_t	 error;
 	volatile uint32_t	*buffer;
+	volatile uint32_t	 times[4];
 
 	void			*private;
 };
@@ -53,6 +54,9 @@
 
 void iboxstate_free(struct iboxstate *ps);
 
+uint32_t iboxstate_get_dtime(struct iboxstate *is);
+uint32_t iboxstate_get_ttime(struct iboxstate *is);
+
 struct iboxstate* png_read_start(int pfd, uint32_t maxw, uint32_t maxh,
 				 enum sbtype);
 int png_read_finish(struct iboxstate *ps);

==== //depot/projects/ctsrd/cheribsd/src/ctsrd-lib/libimagebox/pngbox.c#10 (text+ko) ====

@@ -37,6 +37,7 @@
 
 #include <machine/cheri.h>
 #include <machine/cpuregs.h>
+#include <machine/sysarch.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -70,6 +71,8 @@
 
 	decode_png(ids, NULL, NULL);
 
+	ids->is->times[3] = sysarch(MIPS_GET_COUNT, NULL);
+
 	free(ids);
 
 	pthread_exit(NULL);
@@ -89,6 +92,7 @@
 	is->width = width;
 	is->height = height;
 	is->passes_remaining = UINT32_MAX;
+	is->times[0] = sysarch(MIPS_GET_COUNT, NULL);
 
 	if ((pdp = malloc(sizeof(*pdp))) == NULL)
 		goto error;
@@ -145,6 +149,7 @@
 	is->width = width;
 	is->height = height;
 	is->passes_remaining = UINT32_MAX;
+	is->times[0] = sysarch(MIPS_GET_COUNT, NULL);
 		
 	if ((bfd = shm_open(SHM_ANON, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR))
 	     == -1)
@@ -219,7 +224,7 @@
 /*
  * XXX: rwatson reports that capabilities end up misaligned on the stack.
  */
-static struct chericap c1, c2;
+static struct chericap c1, c2, c3;
 
 static struct iboxstate*
 cheri_png_read_start(char *pngbuffer, size_t pnglen,
@@ -236,6 +241,7 @@
 	is->width = width;
 	is->height = height;
 	is->passes_remaining = UINT32_MAX;
+	is->times[0] = sysarch(MIPS_GET_COUNT, NULL);
 
         if ((is->buffer = malloc(is->width * is->height *
             sizeof(*is->buffer))) == NULL)
@@ -259,12 +265,18 @@
         CHERI_CANDPERM(10, 10, CHERI_PERM_LOAD);
         CHERI_CSC(10, 0, &c2, 0);
 
+        CHERI_CINCBASE(10, 0, is->times + 1);
+        CHERI_CSETLEN(10, 10, sizeof(uint32_t) * 2);
+        CHERI_CANDPERM(10, 10, CHERI_PERM_STORE);
+        CHERI_CSC(10, 0, &c3, 0);
+
         v = sandbox_invoke(sandbox, width, height, pnglen, 0,
-            &c1, &c2, NULL, NULL, NULL, NULL, NULL);
+            &c1, &c2, &c3, NULL, NULL, NULL, NULL);
 	if (ibox_verbose)
 		printf("%s: sandbox returned %ju\n", __func__, (uintmax_t)v);
 	is->valid_rows = height;
 	is->passes_remaining = 0;
+	is->times[3] = sysarch(MIPS_GET_COUNT, NULL);
 	return (is);
 error:
 	munmap(pngbuffer, pnglen);
@@ -403,3 +415,25 @@
 		break;
 	}
 }
+
+static uint32_t
+counter_diff(uint32_t first, uint32_t second)
+{
+
+	if (first < second)
+		return (second - first);
+	else
+		return (second + (UINT32_MAX - first));
+}
+
+uint32_t
+iboxstate_get_ttime(struct iboxstate *is) {
+
+	return (counter_diff(is->times[0], is->times[3]));
+}
+
+uint32_t
+iboxstate_get_dtime(struct iboxstate *is) {
+
+	return (counter_diff(is->times[1], is->times[2]));
+}

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng-cheri/Makefile#3 (text+ko) ====

@@ -14,6 +14,7 @@
 	setjmp.S				\
 	strcpy.c				\
 	execve.S				\
+	sysarch.S				\
 	cerror.S
 
 .PATH: ${.CURDIR}/../../../ctsrd-lib/libimagebox

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng-cheri/readpng-cheri.c#7 (text+ko) ====

@@ -34,6 +34,7 @@
 #include <sys/mman.h>
 
 #include <machine/cheri.h>
+#include <machine/sysarch.h>
 
 #include <png.h>
 #include <stdlib.h>
@@ -108,5 +109,7 @@
 	if (is.error == 0)
 		memcpy_tocap(1, ids.buffer, 0, sizeof(uint32_t) * a0 * a1);
 
+	memcpy_tocap(3, is.times + 1, 0, sizeof(uint32_t) * 2);
+
 	return (is.error);
 }

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/libexec/readpng/readpng.c#5 (text+ko) ====

@@ -32,6 +32,8 @@
 #include <sys/capability.h>
 #include <sys/mman.h>
 
+#include <machine/sysarch.h>
+
 #include <err.h>
 #include <png.h>
 #include <stdlib.h>
@@ -63,5 +65,6 @@
 		err(1, "mmap buffer");
 
 	decode_png(&ids, NULL, NULL);
+	ids.is->times[3] = sysarch(MIPS_GET_COUNT, NULL);
 	return (0);
 }



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