[Intel-gfx] [PATCH 3/5] gem_stress: more library refactoring

Ben Widawsky ben at bwidawsk.net
Mon Jan 16 03:21:24 CET 2012


Pulled out "global" library stuff into lib/gem_stress.c.

It is not thread-safe.

Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 lib/Makefile.am    |    1 +
 lib/gem_stress.c   |  238 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/gem_stress.h   |    4 +
 tests/gem_stress.c |  208 +---------------------------------------------
 4 files changed, 245 insertions(+), 206 deletions(-)
 create mode 100644 lib/gem_stress.c

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 6e6463a..0d7aa9b 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -26,5 +26,6 @@ libintel_tools_la_SOURCES = 	\
 	gem_stress_i830.c	\
 	gen6_render.h		\
 	gem_stress_gen6.c	\
+	gem_stress.c		\
 	intel_reg_map.c
 
diff --git a/lib/gem_stress.c b/lib/gem_stress.c
new file mode 100644
index 0000000..676e9fd
--- /dev/null
+++ b/lib/gem_stress.c
@@ -0,0 +1,238 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ *    Ben Widawsky <ben at bwidawsk.net>
+ *    Daniel Vetter <daniel.vetter at ffwll.ch>
+ *
+ */
+
+#include "gem_stress.h"
+
+void sanitize_tiles_per_buf(void)
+{
+	if (options.tiles_per_buf > options.scratch_buf_size / TILE_BYTES(options.tile_size))
+		options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
+}
+
+
+void
+sanitize_stride(struct scratch_buf *buf)
+{
+
+	if (buf_height(buf) > options.max_dimension)
+		buf->stride = options.scratch_buf_size / options.max_dimension;
+
+	if (buf_height(buf) < options.tile_size)
+		buf->stride = options.scratch_buf_size / options.tile_size;
+
+	if (buf_width(buf) < options.tile_size)
+		buf->stride = options.tile_size * sizeof(uint32_t);
+
+	assert(buf->stride <= 8192);
+	assert(buf_width(buf) <= options.max_dimension);
+	assert(buf_height(buf) <= options.max_dimension);
+
+	assert(buf_width(buf) >= options.tile_size);
+	assert(buf_height(buf) >= options.tile_size);
+
+}
+
+void
+init_buffer(struct scratch_buf *buf, unsigned size)
+{
+	buf->bo = drm_intel_bo_alloc(bufmgr, "tiled bo", size, 4096);
+	assert(buf->bo);
+	buf->tiling = I915_TILING_NONE;
+	buf->stride = 4096;
+
+	sanitize_stride(buf); \
+
+	if (options.no_hw)
+		buf->data = malloc(size);
+	else {
+		if (options.use_cpu_maps)
+			drm_intel_bo_map(buf->bo, 1);
+		else
+			drm_intel_gem_bo_map_gtt(buf->bo);
+		buf->data = buf->bo->virtual;
+	}
+
+	buf->num_tiles = options.tiles_per_buf;
+}
+
+void parse_options(int argc, char **argv, int _devid)
+{
+	int c, tmp;
+	int option_index = 0;
+	static struct option long_options[] = {
+		{"no-hw", 0, 0, 'd'},
+		{"buf-size", 1, 0, 's'},
+		{"gpu-busy-load", 1, 0, 'g'},
+		{"no-signals", 0, 0, 'S'},
+		{"buffer-count", 1, 0, 'c'},
+		{"trace-tile", 1, 0, 't'},
+		{"disable-blt", 0, 0, 'b'},
+		{"disable-render", 0, 0, 'r'},
+		{"untiled", 0, 0, 'u'},
+		{"x-tiled", 0, 0, 'x'},
+		{"use-cpu-maps", 0, 0, 'm'},
+		{"rounds", 1, 0, 'o'},
+		{"no-fail", 0, 0, 'f'},
+		{"tiles-per-buf", 0, 0, 'p'},
+#define DUCTAPE 0xdead0001
+		{"remove-duct-tape", 0, 0, DUCTAPE},
+#define TILESZ	0xdead0002
+		{"tile-size", 1, 0, TILESZ},
+#define CHCK_RENDER 0xdead0003
+		{"check-render-cpyfn", 0, 0, CHCK_RENDER},
+	};
+
+	options.scratch_buf_size = 256*4096;
+	options.no_hw = 0;
+	options.use_signal_helper = 1;
+	options.gpu_busy_load = 0;
+	options.num_buffers = 0;
+	options.trace_tile = -1;
+	options.use_render = 1;
+	options.use_blt = 1;
+	options.forced_tiling = -1;
+	options.use_cpu_maps = 0;
+	options.total_rounds = 512;
+	options.fail = 1;
+	options.ducttape = 1;
+	options.tile_size = 16;
+	options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
+	options.check_render_cpyfn = 0;
+
+	while((c = getopt_long(argc, argv, "ds:g:c:t:rbuxmo:fp:",
+			       long_options, &option_index)) != -1) {
+		switch(c) {
+		case 'd':
+			options.no_hw = 1;
+			printf("no-hw debug mode\n");
+			break;
+		case 'S':
+			options.use_signal_helper = 0;
+			printf("disabling that pesky nuisance who keeps interrupting us\n");
+			break;
+		case 's':
+			tmp = atoi(optarg);
+			if (tmp < options.tile_size*8192)
+				printf("scratch buffer size needs to be at least %i\n",
+				       options.tile_size*8192);
+			else if (tmp & (tmp - 1)) {
+				printf("scratch buffer size needs to be a power-of-two\n");
+			} else {
+				printf("fixed scratch buffer size to %u\n", tmp);
+				options.scratch_buf_size = tmp;
+				sanitize_tiles_per_buf();
+			}
+			break;
+		case 'g':
+			tmp = atoi(optarg);
+			if (tmp < 0 || tmp > 10)
+				printf("gpu busy load needs to be bigger than 0 and smaller than 10\n");
+			else {
+				printf("gpu busy load factor set to %i\n", tmp);
+			}
+			break;
+		case 'c':
+			options.num_buffers = atoi(optarg);
+			printf("buffer count set to %i\n", options.num_buffers);
+			break;
+		case 't':
+			options.trace_tile = atoi(optarg);
+			printf("tracing tile %i\n", options.trace_tile);
+			break;
+		case 'r':
+			options.use_render = 0;
+			printf("disabling render copy\n");
+			break;
+		case 'b':
+			options.use_blt = 0;
+			printf("disabling blt copy\n");
+			break;
+		case 'u':
+			options.forced_tiling = I915_TILING_NONE;
+			printf("disabling tiling\n");
+			break;
+		case 'x':
+			if (options.use_cpu_maps) {
+				printf("tiling not possible with cpu maps\n");
+			} else {
+				options.forced_tiling = I915_TILING_X;
+				printf("using only X-tiling\n");
+			}
+			break;
+		case 'm':
+			options.use_cpu_maps = 1;
+			options.forced_tiling = I915_TILING_NONE;
+			printf("disabling tiling\n");
+			break;
+		case 'o':
+			options.total_rounds = atoi(optarg);
+			printf("total rounds %i\n", options.total_rounds);
+			break;
+		case 'f':
+			options.fail = 0;
+			printf("not failing when detecting errors\n");
+			break;
+		case 'p':
+			options.tiles_per_buf = atoi(optarg);
+			printf("tiles per buffer %i\n", options.tiles_per_buf);
+			break;
+		case DUCTAPE:
+			options.ducttape = 0;
+			printf("applying duct-tape\n");
+			break;
+		case TILESZ:
+			options.tile_size = atoi(optarg);
+			sanitize_tiles_per_buf();
+			printf("til size %i\n", options.tile_size);
+			break;
+		case CHCK_RENDER:
+			options.check_render_cpyfn = 1;
+			printf("checking render copy function\n");
+			break;
+		default:
+			printf("unkown command options\n");
+			break;
+		}
+	}
+
+	if (optind < argc)
+		printf("unkown command options\n");
+
+	/* actually 32767, according to docs, but that kills our nice pot calculations. */
+	options.max_dimension = 16*1024;
+	if (options.use_render) {
+		if (IS_GEN2(_devid) || IS_GEN3(_devid))
+			options.max_dimension = 2048;
+		else
+			options.max_dimension = 8192;
+	}
+	printf("Limiting buffer to %dx%d\n",
+	       options.max_dimension, options.max_dimension);
+}
+
+
diff --git a/lib/gem_stress.h b/lib/gem_stress.h
index 0db2229..adc9502 100644
--- a/lib/gem_stress.h
+++ b/lib/gem_stress.h
@@ -62,6 +62,10 @@ extern int fence_storm;
 #define TILE_BYTES(size)	((size)*(size)*sizeof(uint32_t))
 
 void keep_gpu_busy(void);
+void sanitize_tiles_per_buf(void);
+void sanitize_stride(struct scratch_buf *buf);
+void init_buffer(struct scratch_buf *buf, unsigned size);
+void parse_options(int argc, char **argv, int devid);
 
 static inline void emit_vertex_2s(int16_t x, int16_t y)
 {
diff --git a/tests/gem_stress.c b/tests/gem_stress.c
index 8338705..57b863e 100644
--- a/tests/gem_stress.c
+++ b/tests/gem_stress.c
@@ -418,49 +418,6 @@ static void fan_in_and_check(void)
 	}
 }
 
-static void sanitize_stride(struct scratch_buf *buf)
-{
-
-	if (buf_height(buf) > options.max_dimension)
-		buf->stride = options.scratch_buf_size / options.max_dimension;
-
-	if (buf_height(buf) < options.tile_size)
-		buf->stride = options.scratch_buf_size / options.tile_size;
-
-	if (buf_width(buf) < options.tile_size)
-		buf->stride = options.tile_size * sizeof(uint32_t);
-
-	assert(buf->stride <= 8192);
-	assert(buf_width(buf) <= options.max_dimension);
-	assert(buf_height(buf) <= options.max_dimension);
-
-	assert(buf_width(buf) >= options.tile_size);
-	assert(buf_height(buf) >= options.tile_size);
-
-}
-
-static void init_buffer(struct scratch_buf *buf, unsigned size)
-{
-	buf->bo = drm_intel_bo_alloc(bufmgr, "tiled bo", size, 4096);
-	assert(buf->bo);
-	buf->tiling = I915_TILING_NONE;
-	buf->stride = 4096;
-
-	sanitize_stride(buf);
-
-	if (options.no_hw)
-		buf->data = malloc(size);
-	else {
-		if (options.use_cpu_maps)
-			drm_intel_bo_map(buf->bo, 1);
-		else
-			drm_intel_gem_bo_map_gtt(buf->bo);
-		buf->data = buf->bo->virtual;
-	}
-
-	buf->num_tiles = options.tiles_per_buf;
-}
-
 static void permute_array(void *array, unsigned size,
 			  void (*exchange_func)(void *array, unsigned i, unsigned j))
 {
@@ -611,168 +568,6 @@ static int get_num_fences(void)
 	return val - 2;
 }
 
-static void sanitize_tiles_per_buf(void)
-{
-	if (options.tiles_per_buf > options.scratch_buf_size / TILE_BYTES(options.tile_size))
-		options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
-}
-
-static void parse_options(int argc, char **argv)
-{
-	int c, tmp;
-	int option_index = 0;
-	static struct option long_options[] = {
-		{"no-hw", 0, 0, 'd'},
-		{"buf-size", 1, 0, 's'},
-		{"gpu-busy-load", 1, 0, 'g'},
-		{"no-signals", 0, 0, 'S'},
-		{"buffer-count", 1, 0, 'c'},
-		{"trace-tile", 1, 0, 't'},
-		{"disable-blt", 0, 0, 'b'},
-		{"disable-render", 0, 0, 'r'},
-		{"untiled", 0, 0, 'u'},
-		{"x-tiled", 0, 0, 'x'},
-		{"use-cpu-maps", 0, 0, 'm'},
-		{"rounds", 1, 0, 'o'},
-		{"no-fail", 0, 0, 'f'},
-		{"tiles-per-buf", 0, 0, 'p'},
-#define DUCTAPE 0xdead0001
-		{"remove-duct-tape", 0, 0, DUCTAPE},
-#define TILESZ	0xdead0002
-		{"tile-size", 1, 0, TILESZ},
-#define CHCK_RENDER 0xdead0003
-		{"check-render-cpyfn", 0, 0, CHCK_RENDER},
-	};
-
-	options.scratch_buf_size = 256*4096;
-	options.no_hw = 0;
-	options.use_signal_helper = 1;
-	options.gpu_busy_load = 0;
-	options.num_buffers = 0;
-	options.trace_tile = -1;
-	options.use_render = 1;
-	options.use_blt = 1;
-	options.forced_tiling = -1;
-	options.use_cpu_maps = 0;
-	options.total_rounds = 512;
-	options.fail = 1;
-	options.ducttape = 1;
-	options.tile_size = 16;
-	options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
-	options.check_render_cpyfn = 0;
-
-	while((c = getopt_long(argc, argv, "ds:g:c:t:rbuxmo:fp:",
-			       long_options, &option_index)) != -1) {
-		switch(c) {
-		case 'd':
-			options.no_hw = 1;
-			printf("no-hw debug mode\n");
-			break;
-		case 'S':
-			options.use_signal_helper = 0;
-			printf("disabling that pesky nuisance who keeps interrupting us\n");
-			break;
-		case 's':
-			tmp = atoi(optarg);
-			if (tmp < options.tile_size*8192)
-				printf("scratch buffer size needs to be at least %i\n",
-				       options.tile_size*8192);
-			else if (tmp & (tmp - 1)) {
-				printf("scratch buffer size needs to be a power-of-two\n");
-			} else {
-				printf("fixed scratch buffer size to %u\n", tmp);
-				options.scratch_buf_size = tmp;
-				sanitize_tiles_per_buf();
-			}
-			break;
-		case 'g':
-			tmp = atoi(optarg);
-			if (tmp < 0 || tmp > 10)
-				printf("gpu busy load needs to be bigger than 0 and smaller than 10\n");
-			else {
-				printf("gpu busy load factor set to %i\n", tmp);
-				gpu_busy_load = options.gpu_busy_load = tmp;
-			}
-			break;
-		case 'c':
-			options.num_buffers = atoi(optarg);
-			printf("buffer count set to %i\n", options.num_buffers);
-			break;
-		case 't':
-			options.trace_tile = atoi(optarg);
-			printf("tracing tile %i\n", options.trace_tile);
-			break;
-		case 'r':
-			options.use_render = 0;
-			printf("disabling render copy\n");
-			break;
-		case 'b':
-			options.use_blt = 0;
-			printf("disabling blt copy\n");
-			break;
-		case 'u':
-			options.forced_tiling = I915_TILING_NONE;
-			printf("disabling tiling\n");
-			break;
-		case 'x':
-			if (options.use_cpu_maps) {
-				printf("tiling not possible with cpu maps\n");
-			} else {
-				options.forced_tiling = I915_TILING_X;
-				printf("using only X-tiling\n");
-			}
-			break;
-		case 'm':
-			options.use_cpu_maps = 1;
-			options.forced_tiling = I915_TILING_NONE;
-			printf("disabling tiling\n");
-			break;
-		case 'o':
-			options.total_rounds = atoi(optarg);
-			printf("total rounds %i\n", options.total_rounds);
-			break;
-		case 'f':
-			options.fail = 0;
-			printf("not failing when detecting errors\n");
-			break;
-		case 'p':
-			options.tiles_per_buf = atoi(optarg);
-			printf("tiles per buffer %i\n", options.tiles_per_buf);
-			break;
-		case DUCTAPE:
-			options.ducttape = 0;
-			printf("applying duct-tape\n");
-			break;
-		case TILESZ:
-			options.tile_size = atoi(optarg);
-			sanitize_tiles_per_buf();
-			printf("til size %i\n", options.tile_size);
-			break;
-		case CHCK_RENDER:
-			options.check_render_cpyfn = 1;
-			printf("checking render copy function\n");
-			break;
-		default:
-			printf("unkown command options\n");
-			break;
-		}
-	}
-
-	if (optind < argc)
-		printf("unkown command options\n");
-
-	/* actually 32767, according to docs, but that kills our nice pot calculations. */
-	options.max_dimension = 16*1024;
-	if (options.use_render) {
-		if (IS_GEN2(devid) || IS_GEN3(devid))
-			options.max_dimension = 2048;
-		else
-			options.max_dimension = 8192;
-	}
-	printf("Limiting buffer to %dx%d\n",
-	       options.max_dimension, options.max_dimension);
-}
-
 static void init(void)
 {
 	int i;
@@ -862,7 +657,8 @@ int main(int argc, char **argv)
 	drm_fd = drm_open_any();
 	devid = intel_get_drm_devid(drm_fd);
 
-	parse_options(argc, argv);
+	parse_options(argc, argv, devid);
+	gpu_busy_load = options.gpu_busy_load;
 
 	/* start our little helper early before too may allocations occur */
 	if (options.use_signal_helper)
-- 
1.7.8.3




More information about the Intel-gfx mailing list