Skip to contentSkip to conversation

gem-stress librarification + ctx test

PATCH New Ben Widawsky 1 participant 6 messages Jan 16, 2012 Library code

lore
Share & tools
lore
#0 lore raw

cover gem-stress librarification + ctx test

My motivation for these patches is to test HW context support. In doing this I realized that all 3d state stuff is stuck in gem_stress. The 2nd and 3rd patches pull gem_stress out into a library.

gem_stress does not appear at all threadsafe. To cheaply workaround this (for now) deal with it by using fork/exec instead of multithreaded programs.

An example of how to do this is with the context test I created. Patch 4 and 5 implement this. Patch 4 is a simple wrapper for libdrm calls, patch 5 is the test itself. This won't compile for people unless they use my libdrm, and the test won't be usable unless people take my kernel. I plan to post those separately in the very near future. However for those interested the branches are available from my freedesktop.org repositories.

kernel:
git://people.freedesktop.org/~bwidawsk/drm-intel context-support

libdrm:
git://people.freedesktop.org/~bwidawsk/drm context-support

i-g-t:
git://people.freedesktop.org/~bwidawsk/intel-gpu-tools context-support

Ben Widawsky (5):
i-g-t: silence -Winline
gem_stress: make it library friendly
gem_stress: more library refactoring
context: libdrm wrappers
contexts: basic context test

 lib/Makefile.am         |    6 +
 lib/gem_stress.c        |  238 ++++++++
 lib/gem_stress.h        |  122 ++++
 lib/gem_stress_gen6.c   |  581 ++++++++++++++++++
 lib/gem_stress_i830.c   |  354 +++++++++++
 lib/gem_stress_i915.c   |  190 ++++++
 lib/gen6_render.h       | 1553 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/intel_batchbuffer.c |   40 ++-
 lib/intel_batchbuffer.h |    3 +
 lib/intel_gpu_tools.h   |    5 +
 tests/Makefile.am       |    6 +-
 tests/gem_ctx_basic.c   |  121 ++++
 tests/gem_stress.c      |  231 +-------
 tests/gem_stress.h      |  100 ---
 tests/gem_stress_gen6.c |  595 ------------------
 tests/gem_stress_i830.c |  354 -----------
 tests/gem_stress_i915.c |  190 ------
 tests/gen6_render.h     | 1553 -----------------------------------------------
 18 files changed, 3227 insertions(+), 3015 deletions(-)
 create mode 100644 lib/gem_stress.c
 create mode 100644 lib/gem_stress.h
 create mode 100644 lib/gem_stress_gen6.c
 create mode 100644 lib/gem_stress_i830.c
 create mode 100644 lib/gem_stress_i915.c
 create mode 100644 lib/gen6_render.h
 create mode 100644 tests/gem_ctx_basic.c
 delete mode 100644 tests/gem_stress.h
 delete mode 100644 tests/gem_stress_gen6.c
 delete mode 100644 tests/gem_stress_i830.c
 delete mode 100644 tests/gem_stress_i915.c
 delete mode 100644 tests/gen6_render.h
Signature · 1 line
1.7.8.3
#1 lore raw

PATCH 1/5 i-g-t: silence -Winline

In this case, the code already has a comment about the problem. We don't need to flood the build with this less than useful message.

---
 lib/intel_batchbuffer.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
lib/intel_batchbuffer.h +1 -0
index 4b0ae42..4dffda7 100644
@@ -43,6 +43,7 @@ void intel_batchbuffer_emit_reloc(struct intel_batchbuffer *batch,
  * be passed as structs rather than dwords, but that's a little bit of
  * work...
  */
+#pragma GCC diagnostic ignored "-Winline"
 static inline int
 intel_batchbuffer_space(struct intel_batchbuffer *batch)
 {
Signature · 1 line
1.7.8.3
#2 lore raw

PATCH 2/5 gem_stress: make it library friendly

In reply to Ben Widawsky

These are mostly just renames, and some very small refactors.

---
 lib/Makefile.am         |    5 +
 lib/gem_stress.h        |  118 ++++
 lib/gem_stress_gen6.c   |  581 ++++++++++++++++++
 lib/gem_stress_i830.c   |  354 +++++++++++
 lib/gem_stress_i915.c   |  190 ++++++
 lib/gen6_render.h       | 1553 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/intel_gpu_tools.h   |    5 +
 tests/Makefile.am       |    5 -
 tests/gem_stress.c      |   23 +-
 tests/gem_stress.h      |  100 ---
 tests/gem_stress_gen6.c |  595 ------------------
 tests/gem_stress_i830.c |  354 -----------
 tests/gem_stress_i915.c |  190 ------
 tests/gen6_render.h     | 1553 -----------------------------------------------
 14 files changed, 2822 insertions(+), 2804 deletions(-)
 create mode 100644 lib/gem_stress.h
 create mode 100644 lib/gem_stress_gen6.c
 create mode 100644 lib/gem_stress_i830.c
 create mode 100644 lib/gem_stress_i915.c
 create mode 100644 lib/gen6_render.h
 delete mode 100644 tests/gem_stress.h
 delete mode 100644 tests/gem_stress_gen6.c
 delete mode 100644 tests/gem_stress_i830.c
 delete mode 100644 tests/gem_stress_i915.c
 delete mode 100644 tests/gen6_render.h
lib/Makefile.am +5 -0
index 9607fcb..6e6463a 100644
@@ -21,5 +21,10 @@ libintel_tools_la_SOURCES = 	\
 	intel_mmio.c		\
 	intel_pci.c		\
 	intel_reg.h		\
+	gem_stress.h		\
+	gem_stress_i915.c	\
+	gem_stress_i830.c	\
+	gen6_render.h		\
+	gem_stress_gen6.c	\
 	intel_reg_map.c
 
lib/gem_stress.h new file +118 -0

118 lines not on this page · raw message

lib/gem_stress_gen6.c new file +581 -0

581 lines not on this page · raw message

lib/gem_stress_i830.c new file +354 -0

354 lines not on this page · raw message

lib/gem_stress_i915.c new file +190 -0

190 lines not on this page · raw message

lib/gen6_render.h new file +1553 -0

1,553 lines not on this page · raw message

lib/intel_gpu_tools.h +5 -0
index f2134bf..cd964bd 100644
@@ -25,6 +25,9 @@
  *
  */
 
+#ifndef _IGT_H_
+#define _IGT_H_
+
 #include <stdint.h>
 #include <sys/types.h>
 #include <pciaccess.h>
@@ -93,3 +96,5 @@ extern enum pch_type pch;
 void intel_check_pch(void);
 
 #define HAS_CPT (pch == PCH_CPT)
+
+#endif
tests/Makefile.am +0 -5
index 190d2d3..6fdc96f 100644
@@ -6,11 +6,6 @@ noinst_PROGRAMS = \
 
 gem_stress_SOURCES = \
 	gem_stress.c \
-	gem_stress.h \
-	gem_stress_i915.c \
-	gem_stress_i830.c \
-	gen6_render.h \
-	gem_stress_gen6.c \
 	$(NULL)
 
 TESTS_progs = \
tests/gem_stress.c +16 -7
index 7f93964..8338705 100644
@@ -297,22 +297,31 @@ static void render_copyfunc(struct scratch_buf *src, unsigned src_x, unsigned sr
 			    struct scratch_buf *dst, unsigned dst_x, unsigned dst_y,
 			    unsigned logical_tile_no)
 {
-	if (IS_GEN2(devid))
+
+	if (IS_GEN2(devid)) {
 		gen2_render_copyfunc(src, src_x, src_y,
 				     dst, dst_x, dst_y,
 				     logical_tile_no);
-	else if (IS_GEN3(devid))
+		intel_batchbuffer_flush(batch);
+	} else if (IS_GEN3(devid)) {
 		gen3_render_copyfunc(src, src_x, src_y,
 				     dst, dst_x, dst_y,
 				     logical_tile_no);
-	else if (IS_GEN6(devid))
-		gen6_render_copyfunc(src, src_x, src_y,
-				     dst, dst_x, dst_y,
-				     logical_tile_no);
-	else
+		intel_batchbuffer_flush(batch);
+	} else if (IS_GEN6(devid)) {
+		uint32_t ret;
+		intel_batchbuffer_flush(batch);
+		ret = gen6_render_copyfunc(src, src_x, src_y,
+					   dst, dst_x, dst_y,
+					   logical_tile_no);
+		gen6_render_flush(ret);
+		intel_batchbuffer_reset(batch);
+	} else {
 		blitter_copyfunc(src, src_x, src_y,
 				 dst, dst_x, dst_y,
 				 logical_tile_no);
+	}
+
 }
 
 static void next_copyfunc(int tile)
tests/gem_stress.h deleted +0 -100

100 lines not on this page · raw message

tests/gem_stress_gen6.c deleted +0 -595

31 lines not on this page · raw message

tests/gem_stress_i830.c deleted +0 -354

354 lines not on this page · raw message

tests/gem_stress_i915.c deleted +0 -190

190 lines not on this page · raw message

tests/gen6_render.h deleted +0 -1553

1,553 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.8.3

Part of the diff is not shown here. View the raw message.

#3 lore raw

PATCH 3/5 gem_stress: more library refactoring

In reply to Ben Widawsky

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

It is not thread-safe.

---
 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
lib/Makefile.am +1 -0
index 6e6463a..0d7aa9b 100644
@@ -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
 
lib/gem_stress.c new file +238 -0

238 lines not on this page · raw message

lib/gem_stress.h +4 -0
index 0db2229..adc9502 100644
@@ -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)
 {
tests/gem_stress.c +2 -206

226 lines not on this page · raw message

Signature · 6 lines
1.7.8.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH 4/5 context: libdrm wrappers

In reply to Ben Widawsky

This wraps libdrm functionality to create, destroy, and exec with contexts. This patch shouldn't be applied until libdrm for contexts is updated.

---
 lib/intel_batchbuffer.c |   40 +++++++++++++++++++++++++++++++++++-----
 lib/intel_batchbuffer.h |    2 ++
 2 files changed, 37 insertions(+), 5 deletions(-)
lib/intel_batchbuffer.c +35 -5
index 518435c..2344d53 100644
@@ -74,14 +74,13 @@ intel_batchbuffer_free(struct intel_batchbuffer *batch)
 
 #define CMD_POLY_STIPPLE_OFFSET       0x7906
 
-void
-intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring)
+static unsigned int
+flush_on_ring_common(struct intel_batchbuffer *batch, int ring)
 {
 	unsigned int used = batch->ptr - batch->buffer;
-	int ret;
 
 	if (used == 0)
-		return;
+		return 0;
 
 	if (IS_GEN5(batch->devid)) {
 		BEGIN_BATCH(2);
@@ -99,7 +98,17 @@ intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring)
 	/* Mark the end of the buffer. */
 	*(uint32_t *)(batch->ptr) = MI_BATCH_BUFFER_END; /* noop */
 	batch->ptr += 4;
-	used = batch->ptr - batch->buffer;
+	return batch->ptr - batch->buffer;
+}
+
+void
+intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring)
+{
+	int ret;
+	unsigned int used = flush_on_ring_common(batch, ring);
+
+	if (used == 0)
+		return;
 
 	ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer);
 	assert(ret == 0);
@@ -113,6 +122,27 @@ intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring)
 }
 
 void
+intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch)
+{
+	int ret;
+	unsigned int used = flush_on_ring_common(batch, I915_EXEC_RENDER);
+
+	if (used == 0)
+		return;
+
+	ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer);
+	assert(ret == 0);
+
+	batch->ptr = NULL;
+
+	ret = drm_intel_bo_context_exec(batch->bo, batch->context, used,
+					I915_EXEC_RENDER);
+	assert(ret == 0);
+
+	intel_batchbuffer_reset(batch);
+}
+
+void
 intel_batchbuffer_flush(struct intel_batchbuffer *batch)
 {
 	int ring = 0;
lib/intel_batchbuffer.h +2 -0
index 4dffda7..006fdd1 100644
@@ -12,6 +12,7 @@ struct intel_batchbuffer {
 	uint32_t devid;
 
 	drm_intel_bo *bo;
+	drm_intel_context *context;
 
 	uint8_t buffer[BATCH_SZ];
 	uint8_t *ptr;
@@ -25,6 +26,7 @@ void intel_batchbuffer_free(struct intel_batchbuffer *batch);
 
 void intel_batchbuffer_flush(struct intel_batchbuffer *batch);
 void intel_batchbuffer_flush_on_ring(struct intel_batchbuffer *batch, int ring);
+void intel_batchbuffer_flush_with_context(struct intel_batchbuffer *batch);
 
 void intel_batchbuffer_reset(struct intel_batchbuffer *batch);
 
Signature · 1 line
1.7.8.3
#5 lore raw

PATCH 5/5 contexts: basic context test

In reply to Ben Widawsky

This serves as an example of how to use the new gem_stress library functions, but shouldn't actually build until we get the libdrm updated functions in place.

---
 tests/Makefile.am     |    1 +
 tests/gem_ctx_basic.c |  121 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 0 deletions(-)
 create mode 100644 tests/gem_ctx_basic.c
tests/Makefile.am +1 -0
index 6fdc96f..15299a1 100644
@@ -55,6 +55,7 @@ TESTS_progs = \
 	drm_vma_limiter_cpu \
 	drm_vma_limiter_gtt \
 	drm_vma_limiter_cached \
+	gem_ctx_basic \
 	$(NULL)
 
 # IMPORTANT: The ZZ_ tests need to be run last!
tests/gem_ctx_basic.c new file +121 -0

121 lines not on this page · raw message

Signature · 6 lines
1.7.8.3

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx