Skip to contentSkip to conversation

igt/gem_trtt: Exercise the TRTT hardware

PATCH Superseded [email protected] 4 participants 30 messages Jan 9, 2016 – Oct 27, 2016 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

---
 tests/Makefile.sources |   1 +
 tests/gem_trtt.c       | 396 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 397 insertions(+)
 create mode 100644 tests/gem_trtt.c
tests/Makefile.sources +1 -0
index d594038..068a44e 100644
@@ -64,6 +64,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_trtt.c new file +396 -0

396 lines not on this page · raw message

Signature · 6 lines
1.9.2

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

tests/gem_trtt.c line 138

Quoted 4 lines · On Sat, Jan 09, 2016 at 05:01:30PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +4 -0
+static void* mmap_bo(int fd, uint32_t handle, uint64_t size)
+{
+	uint32_t *ptr = gem_mmap__cpu(fd, handle, 0, size, PROT_READ);
+	gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);

read-only mapping, but set to the cpu write domain? Seems inconsistent.

Quoted 4 lines
tests/gem_trtt.c new file +3 -0
+	return ptr;
+}
 
+/* gem_store_data_svm

tests/gem_trtt.c line 169

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: data to be store at destination
+ * @end: whether to end batch buffer or not
+*/
+static int gem_store_data_svm(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			uint64_t vaddr, uint32_t data, bool end)

Urm, what?

Just call this what it is,
emit_store_dword(cs, offset, vaddr, value);

Don't pass in bool end, since it is going to used exactly once and just confuses all the other callers.

tests/gem_trtt.c line 175

Quoted 6 lines
tests/gem_trtt.c new file +6 -0
+{
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */
+
+	cmd_buf[dw_offset++] = data;

Interesting use of whitespace.

Quoted 11 lines
tests/gem_trtt.c new file +10 -0
+	if (end) {
+		cmd_buf[dw_offset++] = MI_BATCH_BUFFER_END;
+		cmd_buf[dw_offset++] = 0;
 
+	}
+
+	return dw_offset;
+}
+
+/* setup_execbuffer
+ * helper for buffer execution

tests/gem_trtt.c line 195

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+ * @execbuf - pointer to execbuffer
+ * @exec_object - pointer to exec object2 struct
+ * @ring - ring to be used
+ * @buffer_count - how manu buffers to submit
+ * @batch_length - length of batch buffer
+*/
+static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
+			     struct drm_i915_gem_exec_object2 *exec_object,
+			     int ring, int buffer_count, int batch_length)
+{

How about memset(execbuf, 0, sizeof(*execbuf));

Quoted 14 lines
tests/gem_trtt.c new file +14 -0
+	execbuf->buffers_ptr = (unsigned long)exec_object;
+	execbuf->buffer_count = buffer_count;
+	execbuf->batch_start_offset = 0;
+	execbuf->batch_len = batch_length;
+	execbuf->cliprects_ptr = 0;
+	execbuf->num_cliprects = 0;
+	execbuf->DR1 = 0;
+	execbuf->DR4 = 0;
+	execbuf->flags = ring;
+	i915_execbuffer2_set_context_id(*execbuf, 0);
+	execbuf->rsvd2 = 0;
+}
+
+/* submit_and_sync

tests/gem_trtt.c line 219

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+ * Helper function for exec and sync functions
+ * @fd - drm fd
+ * @execbuf - pointer to execbuffer
+ * @batch_buf_handle - batch buffer handle
+*/
+static void submit_and_sync(int fd, struct drm_i915_gem_execbuffer2 *execbuf,
+			    uint32_t batch_buf_handle)
+{
+	gem_execbuf(fd, execbuf);
+	gem_sync(fd, batch_buf_handle);

The only caller of this also does its own sync. This seems irrelevant and serves a bad example.

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+}
+
+struct local_i915_gem_context_trtt_param {
+	uint64_t l3_table_address;
+	uint32_t invd_tile_val;

tests/gem_trtt.c line 234

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	uint32_t null_tile_val;
+};
+
+/* send_trtt_params
+ * Helper function to request KMD to enable TRTT
+ * @fd - drm fd
+ * @ctx_id - id of the context for which TRTT is to be enabled
+ * @l3_table_address - GFX address of the L3 table
+*/
+static void send_trtt_params(int fd, uint32_t ctx_id, uint64_t l3_table_address)

It is not a socket, pipe, or other transport medium. Just setup_trtt().

tests/gem_trtt.c line 263

Quoted 11 lines
tests/gem_trtt.c new file +11 -0
+#define TABLE_SIZE 0x1000
+#define TILE_SIZE 0x10000
+
+#define FIRST_TILE_ADDRESS 0xF00000000000
+#define LAST_TILE_ADDRESS  0xFFFFFFFF0000
+
+#define BO_ALLOC_AND_SETUP(fd, bo_size, bo_handle, bo_offset, idx) \
+	bo_handle = gem_create(fd, bo_size); \
+	bo_offset = current_ppgtt_offset; \
+	setup_exec_obj(&exec_object2[idx], bo_handle, EXEC_OBJECT_PINNED, bo_offset); \
+	current_ppgtt_offset += bo_size;

Function!

Quoted 42 lines
tests/gem_trtt.c new file +42 -0
+
+/* basic test
+ * This test will add a series of MI_STORE_ commands, first to update the
+ * TR-TT table entries and then to update the data buffers using the TR-TT VA,
+ * exercising the programming the table programming done previously
+*/
+static void gem_basic_trtt_use(void)
+{
+	int fd;
+	int ring, len = 0;
+	uint32_t *ptr;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec_object2[8];
+	uint32_t batch_buffer[BO_SIZE];
+
+	uint32_t l3_tbl_handle, l2_tbl1_handle, l2_tbl2_handle;
+	uint32_t l1_tbl1_handle, l1_tbl2_handle, batch_buf_handle;
+	uint32_t buffer1_handle, buffer2_handle;
+
+	uint64_t l3_tbl_offset, l2_tbl1_offset, l2_tbl2_offset;
+	uint64_t l1_tbl1_offset, l1_tbl2_offset;
+	uint64_t buffer1_offset, buffer2_offset;
+
+	uint32_t data;
+	uint64_t address, current_ppgtt_offset = 0x10000;
+
+	fd = drm_open_driver(DRIVER_INTEL);
+	igt_require(uses_full_ppgtt(fd, FULL_48_BIT_PPGTT));
+	igt_require(has_softpin_support(fd));
+	igt_require(has_trtt_support(fd));
+
+	/* Allocate a L3 table BO */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l3_tbl_handle, l3_tbl_offset, 0);
+
+	/* Allocate two L2 table BOs */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l2_tbl1_handle, l2_tbl1_offset, 1);
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l2_tbl2_handle, l2_tbl2_offset, 2);
+
+	/* Allocate two L1 table BOs */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l1_tbl1_handle, l1_tbl1_offset, 3);
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l1_tbl2_handle, l1_tbl2_offset, 4);
+

tests/gem_trtt.c line 315

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	/* Align the PPGTT offsets for the 2 data buffers to next 64 KB boundary */
+	current_ppgtt_offset = ALIGN(current_ppgtt_offset, TILE_SIZE);
+
+	/* Allocate two Data buffer BOs */
+	BO_ALLOC_AND_SETUP(fd, TILE_SIZE, buffer1_handle, buffer1_offset, 5);
+	BO_ALLOC_AND_SETUP(fd, TILE_SIZE, buffer2_handle, buffer2_offset, 6);
+
+	/* Finally allocate Batch buffer BO */
+	batch_buf_handle = gem_create(fd, BO_SIZE);
+	setup_exec_obj(&exec_object2[7], batch_buf_handle, 0, 0);

Scary jump from idx to 7.
Why not just pin this as well to reduce the code complexity? Afterwards setup_exec_obj() can allocate an object all by itself.

Quoted 24 lines
tests/gem_trtt.c new file +24 -0
+
+	/* Add commands to update the two L3 table entries to point them to the L2 tables*/
+	address = l3_tbl_offset;
+	data = l2_tbl1_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	address = l3_tbl_offset + 511*sizeof(uint64_t);
+	data = l2_tbl2_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update an entry of 2 L2 tables to point them to the L1 tables*/
+	address = l2_tbl1_offset;
+	data = l1_tbl1_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	address = l2_tbl2_offset + 511*sizeof(uint64_t);
+	data = l1_tbl2_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update an entry of 2 L1 tables to point them to the data buffers*/
+	address = l1_tbl1_offset;
+	data = buffer1_offset >> 16;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+

tests/gem_trtt.c line 349

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	address = l1_tbl2_offset + 1023*sizeof(uint32_t);
+	data = buffer2_offset >> 16;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update the 2 data buffers, using their TRTT VA */
+	data = 0x12345678;
+	len = gem_store_data_svm(fd, batch_buffer, len, FIRST_TILE_ADDRESS, data, false);
+	len = gem_store_data_svm(fd, batch_buffer, len, LAST_TILE_ADDRESS, data, true);
+
+	gem_write(fd, batch_buf_handle, 0, batch_buffer, len*4);

Or for even shorter code: batch_buffer =
gem_mmap__cpu(exec_object[batch].handle);

Quoted 27 lines
tests/gem_trtt.c new file +27 -0
+
+	/* Request KMD to setup the TR-TT */
+	send_trtt_params(fd, 0, l3_tbl_offset);
+
+	ring = I915_EXEC_RENDER;
+	setup_execbuffer(&execbuf, exec_object2, ring, 8, len*4);
+
+	/* submit command buffer */
+	submit_and_sync(fd, &execbuf, batch_buf_handle);
+
+	/* read the 2 data buffers to check for the value written by the GPU */
+	ptr = mmap_bo(fd, buffer1_handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);
+
+	ptr = mmap_bo(fd, buffer2_handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);
+
+	gem_close(fd, l3_tbl_handle);
+	gem_close(fd, l2_tbl1_handle);
+	gem_close(fd, l2_tbl2_handle);
+	gem_close(fd, l1_tbl1_handle);

tests/gem_trtt.c line 386

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	gem_close(fd, l1_tbl2_handle);
+	gem_close(fd, buffer1_handle);
+	gem_close(fd, buffer2_handle);
+	gem_close(fd, batch_buf_handle);
+	close(fd);
+}
+
+int main(int argc, char* argv[])
+{
+	igt_subtest_init(argc, argv);

Together these are igt_main, and then you can also drop igt_exit.

tests/gem_trtt.c line 387

Quoted 1 line
tests/gem_trtt.c new file +1 -0
+	igt_skip_on_simulation();

I think you want this on simulation as well, as least "basic".

Quoted 12 lines
tests/gem_trtt.c new file +9 -0
+
+	/* test needs 48 PPGTT & Soft Pin support */
+	igt_subtest("basic") {
+		gem_basic_trtt_use();
+	}
+
+	igt_exit();
+}
+
Signature · 1 line
1.9.2
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 9 lines · Chris Wilson

tests/gem_trtt.c line 219

Quoted 5 lines · On Sat, Jan 09, 2016 at 05:01:30PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +5 -0
+static void submit_and_sync(int fd, struct drm_i915_gem_execbuffer2 *execbuf,
+			    uint32_t batch_buf_handle)
+{
+	gem_execbuf(fd, execbuf);
+	gem_sync(fd, batch_buf_handle);

The only caller of this also does its own sync. This seems irrelevant and serves a bad example.

Oh, I see why. Your code is broken...

...
...
...

You didn't mark the output buffers as being written. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw
In reply to Chris Wilson
Quoted 7 lines · Chris Wilson

tests/gem_trtt.c line 138

Quoted 4 lines · On Sat, Jan 09, 2016 at 05:01:30PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +4 -0
+static void* mmap_bo(int fd, uint32_t handle, uint64_t size)
+{
+	uint32_t *ptr = gem_mmap__cpu(fd, handle, 0, size, PROT_READ);
+	gem_set_domain(fd, handle, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);

read-only mapping, but set to the cpu write domain? Seems inconsistent.

Yes write not required, will change.

Quoted 18 lines
Quoted 5 lines
tests/gem_trtt.c new file +3 -0
+	return ptr;
+}
 
+/* gem_store_data_svm

tests/gem_trtt.c line 169

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: data to be store at destination
+ * @end: whether to end batch buffer or not
+*/
+static int gem_store_data_svm(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			uint64_t vaddr, uint32_t data, bool end)

Urm, what?

Quoted 6 lines

Just call this what it is,
emit_store_dword(cs, offset, vaddr, value);

Don't pass in bool end, since it is going to used exactly once and just confuses all the other callers.

Fine, will cleanup this.

Quoted 9 lines

tests/gem_trtt.c line 175

Quoted 6 lines
tests/gem_trtt.c new file +6 -0
+{
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */
+
+	cmd_buf[dw_offset++] = data;

Interesting use of whitespace.

Sorry, will remove.

Quoted 15 lines
Quoted 15 lines
tests/gem_trtt.c new file +14 -0
+	if (end) {
+		cmd_buf[dw_offset++] = MI_BATCH_BUFFER_END;
+		cmd_buf[dw_offset++] = 0;
 
+	}
+
+	return dw_offset;
+}
+
+/* setup_execbuffer
+ * helper for buffer execution
+ * @execbuf - pointer to execbuffer
+ * @exec_object - pointer to exec object2 struct
+ * @ring - ring to be used
+ * @buffer_count - how manu buffers to submit
Quoted 9 lines

tests/gem_trtt.c line 195

Quoted 6 lines

+ * @batch_length - length of batch buffer

tests/gem_trtt.c new file +5 -0
+*/
+static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
+			     struct drm_i915_gem_exec_object2 *exec_object,
+			     int ring, int buffer_count, int batch_length)
+{

How about memset(execbuf, 0, sizeof(*execbuf));

Will use memset.

Quoted 19 lines
Quoted 19 lines
tests/gem_trtt.c new file +19 -0
+	execbuf->buffers_ptr = (unsigned long)exec_object;
+	execbuf->buffer_count = buffer_count;
+	execbuf->batch_start_offset = 0;
+	execbuf->batch_len = batch_length;
+	execbuf->cliprects_ptr = 0;
+	execbuf->num_cliprects = 0;
+	execbuf->DR1 = 0;
+	execbuf->DR4 = 0;
+	execbuf->flags = ring;
+	i915_execbuffer2_set_context_id(*execbuf, 0);
+	execbuf->rsvd2 = 0;
+}
+
+/* submit_and_sync
+ * Helper function for exec and sync functions
+ * @fd - drm fd
+ * @execbuf - pointer to execbuffer
+ * @batch_buf_handle - batch buffer handle
+*/
Quoted 9 lines

tests/gem_trtt.c line 219

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+static void submit_and_sync(int fd, struct drm_i915_gem_execbuffer2 *execbuf,
+			    uint32_t batch_buf_handle)
+{
+	gem_execbuf(fd, execbuf);
+	gem_sync(fd, batch_buf_handle);

The only caller of this also does its own sync. This seems irrelevant and serves a bad example.

Ok no real need to do an explicit sync, when Sync will happen implicitly on mmap of BOs (moving to CPU domain) to verify the Store result.

Quoted 9 lines
Quoted 9 lines
tests/gem_trtt.c new file +9 -0
+}
+
+struct local_i915_gem_context_trtt_param {
+	uint64_t l3_table_address;
+	uint32_t invd_tile_val;
+	uint32_t null_tile_val;
+};
+
+/* send_trtt_params
Quoted 9 lines

Review

Quoted 6 lines

+ * Helper function to request KMD to enable TRTT
+ * @fd - drm fd
+ * @ctx_id - id of the context for which TRTT is to be enabled
+ * @l3_table_address - GFX address of the L3 table

(quoted diff) +2 -0
+*/
+static void send_trtt_params(int fd, uint32_t ctx_id, uint64_t l3_table_address)

It is not a socket, pipe, or other transport medium. Just setup_trtt().

Fine will rename it.

Quoted 5 lines
Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+#define TABLE_SIZE 0x1000
+#define TILE_SIZE 0x10000
+
+#define FIRST_TILE_ADDRESS 0xF00000000000
+#define LAST_TILE_ADDRESS  0xFFFFFFFF0000
Quoted 9 lines

tests/gem_trtt.c line 263

Quoted 6 lines
tests/gem_trtt.c new file +6 -0
+
+#define BO_ALLOC_AND_SETUP(fd, bo_size, bo_handle, bo_offset, idx) \
+	bo_handle = gem_create(fd, bo_size); \
+	bo_offset = current_ppgtt_offset; \
+	setup_exec_obj(&exec_object2[idx], bo_handle, EXEC_OBJECT_PINNED, bo_offset); \
+	current_ppgtt_offset += bo_size;

Function!

Is it affecting the readability ?
Actually in this case, it was more convenient for me to use a macro. With function will have to pass the addresses of multiple variables.

Quoted 48 lines
Quoted 48 lines
tests/gem_trtt.c new file +48 -0
+
+/* basic test
+ * This test will add a series of MI_STORE_ commands, first to update the
+ * TR-TT table entries and then to update the data buffers using the TR-TT VA,
+ * exercising the programming the table programming done previously
+*/
+static void gem_basic_trtt_use(void)
+{
+	int fd;
+	int ring, len = 0;
+	uint32_t *ptr;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec_object2[8];
+	uint32_t batch_buffer[BO_SIZE];
+
+	uint32_t l3_tbl_handle, l2_tbl1_handle, l2_tbl2_handle;
+	uint32_t l1_tbl1_handle, l1_tbl2_handle, batch_buf_handle;
+	uint32_t buffer1_handle, buffer2_handle;
+
+	uint64_t l3_tbl_offset, l2_tbl1_offset, l2_tbl2_offset;
+	uint64_t l1_tbl1_offset, l1_tbl2_offset;
+	uint64_t buffer1_offset, buffer2_offset;
+
+	uint32_t data;
+	uint64_t address, current_ppgtt_offset = 0x10000;
+
+	fd = drm_open_driver(DRIVER_INTEL);
+	igt_require(uses_full_ppgtt(fd, FULL_48_BIT_PPGTT));
+	igt_require(has_softpin_support(fd));
+	igt_require(has_trtt_support(fd));
+
+	/* Allocate a L3 table BO */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l3_tbl_handle, l3_tbl_offset, 0);
+
+	/* Allocate two L2 table BOs */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l2_tbl1_handle, l2_tbl1_offset, 1);
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l2_tbl2_handle, l2_tbl2_offset, 2);
+
+	/* Allocate two L1 table BOs */
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l1_tbl1_handle, l1_tbl1_offset, 3);
+	BO_ALLOC_AND_SETUP(fd, TABLE_SIZE, l1_tbl2_handle, l1_tbl2_offset, 4);
+
+	/* Align the PPGTT offsets for the 2 data buffers to next 64 KB boundary */
+	current_ppgtt_offset = ALIGN(current_ppgtt_offset, TILE_SIZE);
+
+	/* Allocate two Data buffer BOs */
+	BO_ALLOC_AND_SETUP(fd, TILE_SIZE, buffer1_handle, buffer1_offset, 5);
+	BO_ALLOC_AND_SETUP(fd, TILE_SIZE, buffer2_handle, buffer2_offset, 6);
Quoted 8 lines

tests/gem_trtt.c line 315

Quoted 4 lines
tests/gem_trtt.c new file +4 -0
+
+	/* Finally allocate Batch buffer BO */
+	batch_buf_handle = gem_create(fd, BO_SIZE);
+	setup_exec_obj(&exec_object2[7], batch_buf_handle, 0, 0);

Scary jump from idx to 7.
Why not just pin this as well to reduce the code complexity? Afterwards setup_exec_obj() can allocate an object all by itself.

Did not pin the BB also, as it could have given an impression that Soft Pinning is required for all the BOs when using TR-TT. Also this will let us test KMD, that it doesn't place the BB in the segment reserved for TR-TT.

Quoted 30 lines
Quoted 30 lines
tests/gem_trtt.c new file +29 -0
+
+	/* Add commands to update the two L3 table entries to point them to the L2 tables*/
+	address = l3_tbl_offset;
+	data = l2_tbl1_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	address = l3_tbl_offset + 511*sizeof(uint64_t);
+	data = l2_tbl2_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update an entry of 2 L2 tables to point them to the L1 tables*/
+	address = l2_tbl1_offset;
+	data = l1_tbl1_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	address = l2_tbl2_offset + 511*sizeof(uint64_t);
+	data = l1_tbl2_offset;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update an entry of 2 L1 tables to point them to the data buffers*/
+	address = l1_tbl1_offset;
+	data = buffer1_offset >> 16;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	address = l1_tbl2_offset + 1023*sizeof(uint32_t);
+	data = buffer2_offset >> 16;
+	len = gem_store_data_svm(fd, batch_buffer, len, address, data, false);
+
+	/* Add commands to update the 2 data buffers, using their TRTT VA */
Quoted 9 lines

tests/gem_trtt.c line 349

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+	data = 0x12345678;
+	len = gem_store_data_svm(fd, batch_buffer, len, FIRST_TILE_ADDRESS, data, false);
+	len = gem_store_data_svm(fd, batch_buffer, len, LAST_TILE_ADDRESS, data, true);
+
+	gem_write(fd, batch_buf_handle, 0, batch_buffer, len*4);

Or for even shorter code: batch_buffer =
gem_mmap__cpu(exec_object[batch].handle);

Actually its easier to trace the explicit update through Pwrite.

Quoted 40 lines
Quoted 27 lines
tests/gem_trtt.c new file +27 -0
+
+	/* Request KMD to setup the TR-TT */
+	send_trtt_params(fd, 0, l3_tbl_offset);
+
+	ring = I915_EXEC_RENDER;
+	setup_execbuffer(&execbuf, exec_object2, ring, 8, len*4);
+
+	/* submit command buffer */
+	submit_and_sync(fd, &execbuf, batch_buf_handle);
+
+	/* read the 2 data buffers to check for the value written by the GPU */
+	ptr = mmap_bo(fd, buffer1_handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);
+
+	ptr = mmap_bo(fd, buffer2_handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);
+
+	gem_close(fd, l3_tbl_handle);
+	gem_close(fd, l2_tbl1_handle);
+	gem_close(fd, l2_tbl2_handle);
+	gem_close(fd, l1_tbl1_handle);

tests/gem_trtt.c line 386

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	gem_close(fd, l1_tbl2_handle);
+	gem_close(fd, buffer1_handle);
+	gem_close(fd, buffer2_handle);
+	gem_close(fd, batch_buf_handle);
+	close(fd);
+}
+
+int main(int argc, char* argv[])
+{
+	igt_subtest_init(argc, argv);

Together these are igt_main, and then you can also drop igt_exit.

Quoted 4 lines

tests/gem_trtt.c line 387

Quoted 1 line
tests/gem_trtt.c new file +1 -0
+	igt_skip_on_simulation();

I think you want this on simulation as well, as least "basic".

Thanks, will use igt_main..

Quoted 4 lines
Quoted 4 lines
tests/gem_trtt.c new file +4 -0
+
+	/* test needs 48 PPGTT & Soft Pin support */
+	igt_subtest("basic") {
+		gem_basic_trtt_use();
Quoted 9 lines
Quoted 8 lines
tests/gem_trtt.c new file +5 -1
+	}
+
+	igt_exit();
+}
+
--

1.9.2

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

#4 lore raw

PATCH v2 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

---
 lib/ioctl_wrappers.c   |  25 ++-
 lib/ioctl_wrappers.h   |   2 +
 tests/Makefile.sources |   1 +
 tests/gem_trtt.c       | 446 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 466 insertions(+), 8 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/ioctl_wrappers.c +17 -8
index e348f26..46e1db2 100644
@@ -833,6 +833,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	do_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_SETPARAM, p);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -843,14 +859,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
lib/ioctl_wrappers.h +2 -0
index fe2f687..258c612 100644
@@ -105,9 +105,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
tests/Makefile.sources +1 -0
index d594038..068a44e 100644
@@ -64,6 +64,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_trtt.c new file +446 -0

446 lines not on this page · raw message

Signature · 6 lines
1.9.2

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

tests/gem_trtt.c line 147

Quoted 6 lines · On Fri, Jan 22, 2016 at 09:07:47PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +6 -0
+static int emit_store_dword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint32_t data)
+{
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */

To violate this would be a severe bug in the caller. To mask it here does something that the caller does not expect, very dangerous when playing with PT. Either way does not serve well as a demonstration.

assert((vaddr & (-(1<<48)|3)) == 0); or hex equivalent. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

PATCH v3 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/ioctl_wrappers.c   |  25 ++-
 lib/ioctl_wrappers.h   |   2 +
 tests/Makefile.sources |   1 +
 tests/gem_trtt.c       | 483 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 503 insertions(+), 8 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/ioctl_wrappers.c +17 -8
index 4071260..f6ba8e1 100644
@@ -882,6 +882,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -892,14 +908,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
lib/ioctl_wrappers.h +2 -0
index dc0827a..bcabe30 100644
@@ -107,9 +107,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
tests/Makefile.sources +1 -0
index f8b18b0..e6081f6 100644
@@ -73,6 +73,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_trtt.c new file +483 -0

483 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw
Quoted 1 line · On Thu, Mar 03, 2016 at 10:25:59AM +0530, [email protected] wrote:

+static bool uses_full_ppgtt(int fd, int min)

gem_gtt_type()

Quoted 1 line

+static bool has_softpin_support(int fd)

gem_has_softpin()

Quoted 26 lines
tests/gem_trtt.c new file +26 -0
+static int emit_store_dword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint32_t data)
+{
+	/* Check that softpin addresses are in the correct form */
+	assert(vaddr == gen8_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	assert((vaddr & 3) == 0);
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */
+	cmd_buf[dw_offset++] = data;
+
+	return dw_offset;
+}
+
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,

tests/gem_trtt.c line 188

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+			    uint64_t vaddr, uint64_t data)
+{
+	/* Check that softpin addresses are in the correct form */
+	assert(vaddr == gen8_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	assert((vaddr & 3) == 0);
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;

You just asserted above that the low bits aren't set.

Review

Quoted 1 line
(quoted diff) +1 -0
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */

This conflicts with the value that would be set by the kernel (if it had to the relocation). Who is correct? If not required, please don't raise the spectre of devastating bugs.

Quoted 6 lines
tests/gem_trtt.c new file +6 -0
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}
+

tests/gem_trtt.c line 205

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+/* emit_bb_end
+ * populate batch buffer with MI_BATCH_BUFFER_END command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ */
+static int emit_bb_end(int fd, uint32_t *cmd_buf, uint32_t dw_offset)
+{
+	cmd_buf[dw_offset++] = MI_BATCH_BUFFER_END;
+	cmd_buf[dw_offset++] = 0;

Why? execbuf.batch_len must be aligned, but the CS parser doesn't care, and there is no guarantee that you are aligned coming into emit_bb_end().

Quoted 124 lines
tests/gem_trtt.c new file +124 -0
+
+	return dw_offset;
+}
+
+/* setup_execbuffer
+ * helper for buffer execution
+ * @execbuf - pointer to execbuffer
+ * @exec_object - pointer to exec object2 struct
+ * @ring - ring to be used
+ * @buffer_count - how manu buffers to submit
+ * @batch_length - length of batch buffer
+ */
+static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
+			     struct drm_i915_gem_exec_object2 *exec_object,
+			     uint32_t ctx_id, int ring, int buffer_count, int batch_length)
+{
+	memset(execbuf, 0, sizeof(*execbuf));
+
+	execbuf->buffers_ptr = (unsigned long)exec_object;
+	execbuf->buffer_count = buffer_count;
+	execbuf->batch_len = batch_length;
+	execbuf->flags = ring;
+	i915_execbuffer2_set_context_id(*execbuf, ctx_id);
+}
+
+#define TABLE_SIZE 0x1000
+#define TILE_SIZE 0x10000
+
+#define TRTT_SEGMENT_SIZE (1ULL << 44)
+#define PPGTT_SIZE (1ULL << 48)
+
+#define NULL_TILE_PATTERN    0xFFFFFFFF
+#define INVALID_TILE_PATTERN 0xFFFFFFFE
+
+struct local_i915_gem_context_trtt_param {
+	uint64_t segment_base_addr;
+	uint64_t l3_table_address;
+	uint32_t invd_tile_val;
+	uint32_t null_tile_val;
+};
+
+/* setup_trtt
+ * Helper function to request KMD to enable TRTT
+ * @fd - drm fd
+ * @ctx_id - id of the context for which TRTT is to be enabled
+ * @l3_table_address - GFX address of the L3 table
+ * @segment_base_addr - offset of the TRTT segment in PPGTT space
+ */
+static void
+setup_trtt(int fd, uint32_t ctx_id, uint64_t l3_table_address,
+	   uint64_t segment_base_addr)
+{
+	struct local_i915_gem_context_param ctx_param;
+	struct local_i915_gem_context_trtt_param trtt_param;
+
+	memset(&ctx_param, 0, sizeof(ctx_param));
+
+	trtt_param.null_tile_val = NULL_TILE_PATTERN;
+	trtt_param.invd_tile_val = INVALID_TILE_PATTERN;
+	trtt_param.l3_table_address = l3_table_address;
+	trtt_param.segment_base_addr = segment_base_addr;
+
+	ctx_param.context = ctx_id;
+	ctx_param.size = sizeof(trtt_param);
+	ctx_param.param = LOCAL_CONTEXT_PARAM_TRTT;
+	ctx_param.value = (uint64_t)&trtt_param;
+
+	gem_context_set_param(fd, &ctx_param);
+}
+
+/* bo_alloc_setup
+ * allocate bo and populate exec object
+ * @exec_object2 - pointer to exec object
+ * @bo_sizee - buffer size
+ * @flags - exec flags
+ * @bo_offset - pointer to the current PPGTT offset
+ */
+static void bo_alloc_setup(int fd, struct drm_i915_gem_exec_object2 *exec_object2,
+			   uint64_t bo_size, uint64_t flags, uint64_t *bo_offset)
+{
+	memset(exec_object2, 0, sizeof(*exec_object2));
+	exec_object2->handle = gem_create(fd, bo_size);
+	exec_object2->flags = flags;
+
+	if (bo_offset)
+	{
+		exec_object2->offset = *bo_offset;
+		*bo_offset += bo_size;
+	}
+}
+
+/* submit_trtt_context
+ * This helper function will create a new context if the TR-TT segment
+ * base address is not zero, allocate a L3 table page, 2 pages apiece
+ * for L2/L1 tables and couple of data buffers of 64KB in size, matching the
+ * Tile size. The 2 data buffers will be mapped to the 2 ends of TRTT virtual
+ * space. Series of MI_STORE_DWORD_IMM commands will be added in the batch
+ * buffer to first update the TR-TT table entries and then to update the data
+ * buffers using their TR-TT VA, exercising the table programming done
+ * previously.
+ * Invoke CONTEXT_SETPARAM ioctl to request KMD to enable TRTT.
+ * Invoke execbuffer to submit the batch buffer.
+ * Verify value of first DWORD in the 2 data buffer matches the data asked
+ * to be written by the GPU.
+ */
+static void submit_trtt_context(int fd, uint64_t segment_base_addr)
+{
+	enum {
+		L3_TBL,
+		L2_TBL1,
+		L2_TBL2,
+		L1_TBL1,
+		L1_TBL2,
+		DATA1,
+		DATA2,
+		BATCH,
+		NUM_BUFFERS,
+	};
+
+	int ring, len = 0;
+	uint32_t *ptr;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec_object2[NUM_BUFFERS];
+	uint32_t batch_buffer[BO_SIZE];

tests/gem_trtt.c line 339

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+	uint32_t ctx_id, data, last_entry_offset;
+	uint64_t cur_ppgtt_off, exec_flags;
+	uint64_t first_tile_addr, last_tile_addr;
+
+	first_tile_addr = segment_base_addr;
+	last_tile_addr  = first_tile_addr + TRTT_SEGMENT_SIZE - TILE_SIZE;
+
+	if (segment_base_addr == 0) {
+		/* Use the default context for first iteration */
+		ctx_id = 0;

Seems like a variable the callee wants to control. (Otherwise you are missing a significant test for non-default contexts). It also implies that we don't test what happens when we call set-trtt-context twice on a context.

Quoted 80 lines
tests/gem_trtt.c new file +80 -0
+		/* To avoid conflict with the TR-TT segment */
+		cur_ppgtt_off = TRTT_SEGMENT_SIZE;
+	} else {
+		/* Create a new context to have different TRTT settings
+		 * on every iteration.
+		 */
+		ctx_id = gem_context_create(fd);
+		cur_ppgtt_off = 0;
+	}
+
+	exec_flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+
+	/* first allocate Batch buffer BO */
+	bo_alloc_setup(fd, &exec_object2[BATCH], BO_SIZE, exec_flags, NULL);
+
+	/* table BOs and data buffer BOs are written by GPU and are soft pinned */
+	exec_flags |= (EXEC_OBJECT_WRITE | EXEC_OBJECT_PINNED);
+
+	/* Allocate a L3 table BO */
+	bo_alloc_setup(fd, &exec_object2[L3_TBL], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Allocate two L2 table BOs */
+	bo_alloc_setup(fd, &exec_object2[L2_TBL1], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[L2_TBL2], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Allocate two L1 table BOs */
+	bo_alloc_setup(fd, &exec_object2[L1_TBL1], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[L1_TBL2], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Align the PPGTT offsets for the 2 data buffers to next 64 KB boundary */
+	cur_ppgtt_off = ALIGN(cur_ppgtt_off, TILE_SIZE);
+
+	/* Allocate two Data buffer BOs */
+	bo_alloc_setup(fd, &exec_object2[DATA1], TILE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[DATA2], TILE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Add commands to update the two L3 table entries to point them to the L2 tables*/
+	last_entry_offset = 511*sizeof(uint64_t);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L3_TBL].offset,
+			       exec_object2[L2_TBL1].offset);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L3_TBL].offset + last_entry_offset,
+			       exec_object2[L2_TBL2].offset);
+
+	/* Add commands to update an entry of 2 L2 tables to point them to the L1 tables*/
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L2_TBL1].offset,
+			       exec_object2[L1_TBL1].offset);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L2_TBL2].offset + last_entry_offset,
+			       exec_object2[L1_TBL2].offset);
+
+	/* Add commands to update an entry of 2 L1 tables to point them to the data buffers*/
+	last_entry_offset = 1023*sizeof(uint32_t);
+
+	len = emit_store_dword(fd, batch_buffer, len,
+			       exec_object2[L1_TBL1].offset,
+			       exec_object2[DATA1].offset >> 16);
+
+	len = emit_store_dword(fd, batch_buffer, len,
+			       exec_object2[L1_TBL2].offset + last_entry_offset,
+			       exec_object2[DATA2].offset >> 16);
+
+	/* Add commands to update the 2 data buffers, using their TRTT VA */
+	data = 0x12345678;
+	len = emit_store_dword(fd, batch_buffer, len, first_tile_addr, data);
+	len = emit_store_dword(fd, batch_buffer, len, last_tile_addr, data);
+
+	len = emit_bb_end(fd, batch_buffer, len);
+	gem_write(fd, exec_object2[BATCH].handle, 0, batch_buffer, len*4);
+
+	/* Request KMD to setup the TR-TT */
+	setup_trtt(fd, ctx_id, exec_object2[L3_TBL].offset, first_tile_addr);
+
+	ring = I915_EXEC_RENDER;
+	setup_execbuffer(&execbuf, exec_object2, ctx_id, ring, NUM_BUFFERS, len*4);

tests/gem_trtt.c line 429

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+
+	/* submit command buffer */
+	gem_execbuf(fd, &execbuf);
+
+	/* read the 2 data buffers to check for the value written by the GPU */
+	ptr = mmap_bo(fd, exec_object2[DATA1].handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);

Just igt_assert_eq_u32(ptr[0], expected);

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+
+	ptr = mmap_bo(fd, exec_object2[DATA2].handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",

tests/gem_trtt.c line 444

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+		data, ptr[0]);
+
+	gem_close(fd, exec_object2[L3_TBL].handle);
+	gem_close(fd, exec_object2[L2_TBL1].handle);
+	gem_close(fd, exec_object2[L2_TBL2].handle);
+	gem_close(fd, exec_object2[L1_TBL1].handle);
+	gem_close(fd, exec_object2[L1_TBL2].handle);
+	gem_close(fd, exec_object2[DATA1].handle);
+	gem_close(fd, exec_object2[DATA2].handle);
+	gem_close(fd, exec_object2[BATCH].handle);

Before we destroy the context (or exit), how about a query_trtt(). We should also query after create to ensure that the defaults are set. Just thinking that is better doing the query after several steps (i.e. the execbuf) rather than immediately after the set in order to give time for something to go wrong. We should also ensure that everything remains set after a GPU hang and suspend/resume.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

Thanks for the review.

Quoted 3 lines · Chris Wilson
Quoted 1 line · On Thu, Mar 03, 2016 at 10:25:59AM +0530, [email protected] wrote:

+static bool uses_full_ppgtt(int fd, int min)

gem_gtt_type()

fine will change like this,

	gem_gtt_type(fd) > 2
Quoted 4 lines
Quoted 2 lines

+static bool has_softpin_support(int fd)

gem_has_softpin()

fine will use gem_has_softpin()

Quoted 40 lines
Quoted 27 lines
tests/gem_trtt.c new file +26 -0
+static int emit_store_dword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint32_t data)
+{
+	/* Check that softpin addresses are in the correct form */
+	assert(vaddr == gen8_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	assert((vaddr & 3) == 0);
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */
+	cmd_buf[dw_offset++] = data;
+
+	return dw_offset;
+}
+
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,

tests/gem_trtt.c line 188

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+			    uint64_t vaddr, uint64_t data)
+{
+	/* Check that softpin addresses are in the correct form */
+	assert(vaddr == gen8_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	assert((vaddr & 3) == 0);
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = vaddr & 0xFFFFFFFC;

You just asserted above that the low bits aren't set.

Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	cmd_buf[dw_offset++] = (vaddr >> 32) & 0xFFFF; /* bits 32:47 */

This conflicts with the value that would be set by the kernel (if it had to the relocation). Who is correct? If not required, please don't raise the spectre of devastating bugs.

Sorry will modify like this,

	cmd_buf[dw_offset++] = (uint32_t)vaddr;
	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
Quoted 12 lines
Quoted 12 lines
tests/gem_trtt.c new file +12 -0
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}
+
+/* emit_bb_end
+ * populate batch buffer with MI_BATCH_BUFFER_END command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ */
Quoted 9 lines

tests/gem_trtt.c line 205

Quoted 4 lines
tests/gem_trtt.c new file +4 -0
+static int emit_bb_end(int fd, uint32_t *cmd_buf, uint32_t dw_offset)
+{
+	cmd_buf[dw_offset++] = MI_BATCH_BUFFER_END;
+	cmd_buf[dw_offset++] = 0;

Why? execbuf.batch_len must be aligned, but the CS parser doesn't care, and there is no guarantee that you are aligned coming into emit_bb_end().

Sorry, will change like this,

	dw_offset = ALIGN(dw_offset, 2);
	cmd_buf[dw_offset++] = MI_BATCH_BUFFER_END;
	dw_offset++;
Quoted 131 lines
Quoted 131 lines
tests/gem_trtt.c new file +131 -0
+
+	return dw_offset;
+}
+
+/* setup_execbuffer
+ * helper for buffer execution
+ * @execbuf - pointer to execbuffer
+ * @exec_object - pointer to exec object2 struct
+ * @ring - ring to be used
+ * @buffer_count - how manu buffers to submit
+ * @batch_length - length of batch buffer
+ */
+static void setup_execbuffer(struct drm_i915_gem_execbuffer2 *execbuf,
+			     struct drm_i915_gem_exec_object2 *exec_object,
+			     uint32_t ctx_id, int ring, int buffer_count, int batch_length)
+{
+	memset(execbuf, 0, sizeof(*execbuf));
+
+	execbuf->buffers_ptr = (unsigned long)exec_object;
+	execbuf->buffer_count = buffer_count;
+	execbuf->batch_len = batch_length;
+	execbuf->flags = ring;
+	i915_execbuffer2_set_context_id(*execbuf, ctx_id);
+}
+
+#define TABLE_SIZE 0x1000
+#define TILE_SIZE 0x10000
+
+#define TRTT_SEGMENT_SIZE (1ULL << 44)
+#define PPGTT_SIZE (1ULL << 48)
+
+#define NULL_TILE_PATTERN    0xFFFFFFFF
+#define INVALID_TILE_PATTERN 0xFFFFFFFE
+
+struct local_i915_gem_context_trtt_param {
+	uint64_t segment_base_addr;
+	uint64_t l3_table_address;
+	uint32_t invd_tile_val;
+	uint32_t null_tile_val;
+};
+
+/* setup_trtt
+ * Helper function to request KMD to enable TRTT
+ * @fd - drm fd
+ * @ctx_id - id of the context for which TRTT is to be enabled
+ * @l3_table_address - GFX address of the L3 table
+ * @segment_base_addr - offset of the TRTT segment in PPGTT space
+ */
+static void
+setup_trtt(int fd, uint32_t ctx_id, uint64_t l3_table_address,
+	   uint64_t segment_base_addr)
+{
+	struct local_i915_gem_context_param ctx_param;
+	struct local_i915_gem_context_trtt_param trtt_param;
+
+	memset(&ctx_param, 0, sizeof(ctx_param));
+
+	trtt_param.null_tile_val = NULL_TILE_PATTERN;
+	trtt_param.invd_tile_val = INVALID_TILE_PATTERN;
+	trtt_param.l3_table_address = l3_table_address;
+	trtt_param.segment_base_addr = segment_base_addr;
+
+	ctx_param.context = ctx_id;
+	ctx_param.size = sizeof(trtt_param);
+	ctx_param.param = LOCAL_CONTEXT_PARAM_TRTT;
+	ctx_param.value = (uint64_t)&trtt_param;
+
+	gem_context_set_param(fd, &ctx_param);
+}
+
+/* bo_alloc_setup
+ * allocate bo and populate exec object
+ * @exec_object2 - pointer to exec object
+ * @bo_sizee - buffer size
+ * @flags - exec flags
+ * @bo_offset - pointer to the current PPGTT offset
+ */
+static void bo_alloc_setup(int fd, struct drm_i915_gem_exec_object2 *exec_object2,
+			   uint64_t bo_size, uint64_t flags, uint64_t *bo_offset)
+{
+	memset(exec_object2, 0, sizeof(*exec_object2));
+	exec_object2->handle = gem_create(fd, bo_size);
+	exec_object2->flags = flags;
+
+	if (bo_offset)
+	{
+		exec_object2->offset = *bo_offset;
+		*bo_offset += bo_size;
+	}
+}
+
+/* submit_trtt_context
+ * This helper function will create a new context if the TR-TT segment
+ * base address is not zero, allocate a L3 table page, 2 pages apiece
+ * for L2/L1 tables and couple of data buffers of 64KB in size, matching the
+ * Tile size. The 2 data buffers will be mapped to the 2 ends of TRTT virtual
+ * space. Series of MI_STORE_DWORD_IMM commands will be added in the batch
+ * buffer to first update the TR-TT table entries and then to update the data
+ * buffers using their TR-TT VA, exercising the table programming done
+ * previously.
+ * Invoke CONTEXT_SETPARAM ioctl to request KMD to enable TRTT.
+ * Invoke execbuffer to submit the batch buffer.
+ * Verify value of first DWORD in the 2 data buffer matches the data asked
+ * to be written by the GPU.
+ */
+static void submit_trtt_context(int fd, uint64_t segment_base_addr)
+{
+	enum {
+		L3_TBL,
+		L2_TBL1,
+		L2_TBL2,
+		L1_TBL1,
+		L1_TBL2,
+		DATA1,
+		DATA2,
+		BATCH,
+		NUM_BUFFERS,
+	};
+
+	int ring, len = 0;
+	uint32_t *ptr;
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec_object2[NUM_BUFFERS];
+	uint32_t batch_buffer[BO_SIZE];
+	uint32_t ctx_id, data, last_entry_offset;
+	uint64_t cur_ppgtt_off, exec_flags;
+	uint64_t first_tile_addr, last_tile_addr;
+
+	first_tile_addr = segment_base_addr;
+	last_tile_addr  = first_tile_addr + TRTT_SEGMENT_SIZE - TILE_SIZE;
+
Quoted 9 lines

tests/gem_trtt.c line 339

Quoted 3 lines
tests/gem_trtt.c new file +3 -0
+	if (segment_base_addr == 0) {
+		/* Use the default context for first iteration */
+		ctx_id = 0;

Seems like a variable the callee wants to control. (Otherwise you are missing a significant test for non-default contexts). It also implies that we don't test what happens when we call set-trtt-context twice on a context.

As per the current logic, the callee will use non-default context for the non zero TR-TT segment start location.

Should a new subtest be added to check the case when set-trtt-context is called twice, which is expected to fail.

Quoted 84 lines
Quoted 84 lines
tests/gem_trtt.c new file +84 -0
+		/* To avoid conflict with the TR-TT segment */
+		cur_ppgtt_off = TRTT_SEGMENT_SIZE;
+	} else {
+		/* Create a new context to have different TRTT settings
+		 * on every iteration.
+		 */
+		ctx_id = gem_context_create(fd);
+		cur_ppgtt_off = 0;
+	}
+
+	exec_flags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
+
+	/* first allocate Batch buffer BO */
+	bo_alloc_setup(fd, &exec_object2[BATCH], BO_SIZE, exec_flags, NULL);
+
+	/* table BOs and data buffer BOs are written by GPU and are soft pinned */
+	exec_flags |= (EXEC_OBJECT_WRITE | EXEC_OBJECT_PINNED);
+
+	/* Allocate a L3 table BO */
+	bo_alloc_setup(fd, &exec_object2[L3_TBL], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Allocate two L2 table BOs */
+	bo_alloc_setup(fd, &exec_object2[L2_TBL1], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[L2_TBL2], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Allocate two L1 table BOs */
+	bo_alloc_setup(fd, &exec_object2[L1_TBL1], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[L1_TBL2], TABLE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Align the PPGTT offsets for the 2 data buffers to next 64 KB boundary */
+	cur_ppgtt_off = ALIGN(cur_ppgtt_off, TILE_SIZE);
+
+	/* Allocate two Data buffer BOs */
+	bo_alloc_setup(fd, &exec_object2[DATA1], TILE_SIZE, exec_flags, &cur_ppgtt_off);
+	bo_alloc_setup(fd, &exec_object2[DATA2], TILE_SIZE, exec_flags, &cur_ppgtt_off);
+
+	/* Add commands to update the two L3 table entries to point them to the L2 tables*/
+	last_entry_offset = 511*sizeof(uint64_t);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L3_TBL].offset,
+			       exec_object2[L2_TBL1].offset);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L3_TBL].offset + last_entry_offset,
+			       exec_object2[L2_TBL2].offset);
+
+	/* Add commands to update an entry of 2 L2 tables to point them to the L1 tables*/
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L2_TBL1].offset,
+			       exec_object2[L1_TBL1].offset);
+
+	len = emit_store_qword(fd, batch_buffer, len,
+			       exec_object2[L2_TBL2].offset + last_entry_offset,
+			       exec_object2[L1_TBL2].offset);
+
+	/* Add commands to update an entry of 2 L1 tables to point them to the data buffers*/
+	last_entry_offset = 1023*sizeof(uint32_t);
+
+	len = emit_store_dword(fd, batch_buffer, len,
+			       exec_object2[L1_TBL1].offset,
+			       exec_object2[DATA1].offset >> 16);
+
+	len = emit_store_dword(fd, batch_buffer, len,
+			       exec_object2[L1_TBL2].offset + last_entry_offset,
+			       exec_object2[DATA2].offset >> 16);
+
+	/* Add commands to update the 2 data buffers, using their TRTT VA */
+	data = 0x12345678;
+	len = emit_store_dword(fd, batch_buffer, len, first_tile_addr, data);
+	len = emit_store_dword(fd, batch_buffer, len, last_tile_addr, data);
+
+	len = emit_bb_end(fd, batch_buffer, len);
+	gem_write(fd, exec_object2[BATCH].handle, 0, batch_buffer, len*4);
+
+	/* Request KMD to setup the TR-TT */
+	setup_trtt(fd, ctx_id, exec_object2[L3_TBL].offset, first_tile_addr);
+
+	ring = I915_EXEC_RENDER;
+	setup_execbuffer(&execbuf, exec_object2, ctx_id, ring, NUM_BUFFERS, len*4);
+
+	/* submit command buffer */
+	gem_execbuf(fd, &execbuf);
+
Quoted 8 lines

tests/gem_trtt.c line 429

Quoted 6 lines
tests/gem_trtt.c new file +6 -0
+	/* read the 2 data buffers to check for the value written by the GPU */
+	ptr = mmap_bo(fd, exec_object2[DATA1].handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);

Just igt_assert_eq_u32(ptr[0], expected);

Fine will change.

Quoted 15 lines
Quoted 15 lines
tests/gem_trtt.c new file +14 -0
+
+	ptr = mmap_bo(fd, exec_object2[DATA2].handle, TILE_SIZE);
+	igt_fail_on_f(ptr[0] != data,
+		"\nCPU read does not match GPU write,\
+		expected: 0x%x, got: 0x%x\n",
+		data, ptr[0]);
+
+	gem_close(fd, exec_object2[L3_TBL].handle);
+	gem_close(fd, exec_object2[L2_TBL1].handle);
+	gem_close(fd, exec_object2[L2_TBL2].handle);
+	gem_close(fd, exec_object2[L1_TBL1].handle);
+	gem_close(fd, exec_object2[L1_TBL2].handle);
+	gem_close(fd, exec_object2[DATA1].handle);
+	gem_close(fd, exec_object2[DATA2].handle);
Quoted 8 lines

tests/gem_trtt.c line 444

Quoted 1 line
tests/gem_trtt.c new file +1 -0
+	gem_close(fd, exec_object2[BATCH].handle);

Before we destroy the context (or exit), how about a query_trtt(). We should also query after create to ensure that the defaults are set. Just thinking that is better doing the query after several steps (i.e. the execbuf) rather than immediately after the set in order to give time for something to go wrong. We should also ensure that everything remains set after a GPU hang and suspend/resume.

Nice suggestion, currently get-trtt-context will just retrieve the TR-TT params stored with a Driver for a given context. Should the Context image itself be read to ensure that settings are intact or not ?

Best regards
Akash

Quoted 2 lines

-Chris

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

#9 lore raw
Quoted 11 lines · Akash
Quoted 6 lines

Before we destroy the context (or exit), how about a query_trtt(). We should also query after create to ensure that the defaults are set. Just thinking that is better doing the query after several steps (i.e. the execbuf) rather than immediately after the set in order to give time for something to go wrong. We should also ensure that everything remains set after a GPU hang and suspend/resume.

Nice suggestion, currently get-trtt-context will just retrieve the TR-TT params stored with a Driver for a given context. Should the Context image itself be read to ensure that settings are intact or not ?

I'm happy with reading back the driver state (as opposed to the context image). We're verifying that the hw is setup via the execbuf, we just want to double check that the kernel reports the correct setup as well. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw
Quoted 8 lines · Chris Wilson
Quoted 7 lines · Akash
Quoted 6 lines

Before we destroy the context (or exit), how about a query_trtt(). We should also query after create to ensure that the defaults are set. Just thinking that is better doing the query after several steps (i.e. the execbuf) rather than immediately after the set in order to give time for something to go wrong. We should also ensure that everything remains set after a GPU hang and suspend/resume.

Quoted 8 lines
Quoted 4 lines

Nice suggestion, currently get-trtt-context will just retrieve the TR-TT params stored with a Driver for a given context. Should the Context image itself be read to ensure that settings are intact or not ?

I'm happy with reading back the driver state (as opposed to the context image). We're verifying that the hw is setup via the execbuf, we just want to double check that the kernel reports the correct setup as well.

Fine, will use get-trtt-context only. The trtt params stored with the Driver should be invariant.

Best regards
Akash

Quoted 2 lines

-Chris

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

#11 lore raw

PATCH v4 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/ioctl_wrappers.c   |  39 +++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_trtt.c       | 498 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 533 insertions(+), 8 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/ioctl_wrappers.c +31 -8
index 4071260..fb5de07 100644
@@ -882,6 +882,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -892,14 +908,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1063,6 +1072,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index dc0827a..d23fa96 100644
@@ -107,9 +107,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -143,6 +145,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
tests/Makefile.sources +1 -0
index f8b18b0..e6081f6 100644
@@ -73,6 +73,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_trtt.c new file +498 -0

498 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw
Quoted 4 lines · On 3/9/2016 11:31 AM, [email protected] wrote:

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

...

Quoted 3 lines
tests/gem_trtt.c new file +0 -0
@@ -0,0 +1,498 @@

...

tests/gem_trtt.c line 69

Quoted 12 lines
tests/gem_trtt.c new file +12 -0
+
+/* gen8_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+ */
+#define GEN8_HIGH_ADDRESS_BIT 47
+static uint64_t gen8_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}

^^^ These came from gem_softpin, didnt they?
[https://cgit.freedesktop.org/xorg/app/intel-gpu-tools/commit/?id=7cb35109645e6495f67981b9930587c1ddfe4f90]

Would you consider moving them to lib/?
(I think igt_aux is a good place).

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

#13 lore raw
Quoted 10 lines · Michel Thierry
Quoted 4 lines · On 3/9/2016 11:31 AM, [email protected] wrote:

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

...

Quoted 3 lines
tests/gem_trtt.c new file +0 -0
@@ -0,0 +1,498 @@

...

Quoted 16 lines

tests/gem_trtt.c line 69

Quoted 13 lines
tests/gem_trtt.c new file +3 -0
+
+/* gen8_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] ==

[47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+ */

tests/gem_trtt.c new file +6 -0
+#define GEN8_HIGH_ADDRESS_BIT 47
+static uint64_t gen8_canonical_addr(uint64_t address)
+{
+    __u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+    return (__s64)(address << shift) >> shift;
+}

^^^ These came from gem_softpin, didnt they?
[https://cgit.freedesktop.org/xorg/app/intel-gpu-tools/commit/?id=7cb35109645e6495f67981b9930587c1ddfe4f90]

Yes copied as is from gem_softpin.

Quoted 2 lines

Would you consider moving them to lib/?
(I think igt_aux is a good place).

Can I move it to igt_aux.h then ?

Best regards
Akash

Quoted 3 lines

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

#14 lore raw

PATCH v5 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/igt_aux.c          |  11 +
 lib/igt_aux.h          |   1 +
 lib/igt_gt.h           |   2 +
 lib/ioctl_wrappers.c   |  39 +++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_softpin.c    |  18 +-
 tests/gem_trtt.c       | 601 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 653 insertions(+), 23 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/igt_aux.c +11 -0
index 7d35666..c5fedb5 100644
@@ -206,6 +206,17 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
 	int_arr[j] = tmp;
 }
 
+/* igt_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+*/
+uint64_t igt_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}
+
 static uint32_t
 hars_petruska_f54_1_random_unsafe(void)
 {
lib/igt_aux.h +1 -0
index 427719e..85fc64b 100644
@@ -48,6 +48,7 @@ void igt_permute_array(void *array, unsigned size,
 void igt_progress(const char *header, uint64_t i, uint64_t total);
 void igt_print_activity(void);
 bool igt_check_boolean_env_var(const char *env_var, bool default_value);
+uint64_t igt_canonical_addr(uint64_t address);
 
 bool igt_aub_dump_enabled(void);
 
lib/igt_gt.h +2 -0
index b7c5c4a..d4e9dbb 100644
@@ -98,4 +98,6 @@ extern const struct intel_execution_engine {
 	unsigned flags;
 } intel_execution_engines[];
 
+#define GEN8_HIGH_ADDRESS_BIT 47
+
 #endif /* IGT_GT_H */
lib/ioctl_wrappers.c +31 -8
index 4071260..fb5de07 100644
@@ -882,6 +882,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -892,14 +908,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1063,6 +1072,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index dc0827a..d23fa96 100644
@@ -107,9 +107,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -143,6 +145,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
tests/Makefile.sources +1 -0
index f8b18b0..e6081f6 100644
@@ -73,6 +73,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_softpin.c +3 -15
index 1b3d9d3..3eee08f 100644
@@ -31,18 +31,6 @@
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -70,7 +58,7 @@ static void test_invalid(int fd)
 
 	/* Check beyond bounds of aperture */
 	object.offset = gem_aperture_size(fd) - 4096;
-	object.offset = gen8_canonical_addr(object.offset);
+	object.offset = igt_canonical_addr(object.offset);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
 	/* Check gen8 canonical addressing */
@@ -78,7 +66,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull << GEN8_HIGH_ADDRESS_BIT;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
 
@@ -88,7 +76,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull<<32;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		object.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
tests/gem_trtt.c new file +601 -0

601 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v5 1/1
#15 lore raw
Quoted 64 lines · On 3/11/2016 11:48 AM, [email protected] wrote:

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

Quoted 3 lines
Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>

Test looks good to me.

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

#16 lore raw

PATCH v6 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

v6:
- Allow each subtest to have their own private drm file instance.
- Update the basic subtest to check each segment location for both default and User created contexts (Chris).
- Reorder igt_require(softpin/64b_ppgtt/trtt) to have trtt first (Chris).
- Update the invalid subtest to check for the improper value of Null & Invalid tiles.

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/igt_aux.c          |  11 +
 lib/igt_aux.h          |   1 +
 lib/igt_gt.h           |   2 +
 lib/ioctl_wrappers.c   |  39 ++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_softpin.c    |  18 +-
 tests/gem_trtt.c       | 627 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 679 insertions(+), 23 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/igt_aux.c +11 -0
index 7d35666..c5fedb5 100644
@@ -206,6 +206,17 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
 	int_arr[j] = tmp;
 }
 
+/* igt_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+*/
+uint64_t igt_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}
+
 static uint32_t
 hars_petruska_f54_1_random_unsafe(void)
 {
lib/igt_aux.h +1 -0
index 427719e..85fc64b 100644
@@ -48,6 +48,7 @@ void igt_permute_array(void *array, unsigned size,
 void igt_progress(const char *header, uint64_t i, uint64_t total);
 void igt_print_activity(void);
 bool igt_check_boolean_env_var(const char *env_var, bool default_value);
+uint64_t igt_canonical_addr(uint64_t address);
 
 bool igt_aub_dump_enabled(void);
 
lib/igt_gt.h +2 -0
index b7c5c4a..d4e9dbb 100644
@@ -98,4 +98,6 @@ extern const struct intel_execution_engine {
 	unsigned flags;
 } intel_execution_engines[];
 
+#define GEN8_HIGH_ADDRESS_BIT 47
+
 #endif /* IGT_GT_H */
lib/ioctl_wrappers.c +31 -8
index 4071260..fb5de07 100644
@@ -882,6 +882,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -892,14 +908,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1063,6 +1072,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index dc0827a..d23fa96 100644
@@ -107,9 +107,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -143,6 +145,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
tests/Makefile.sources +1 -0
index f8b18b0..e6081f6 100644
@@ -73,6 +73,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_softpin.c +3 -15
index 1b3d9d3..3eee08f 100644
@@ -31,18 +31,6 @@
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -70,7 +58,7 @@ static void test_invalid(int fd)
 
 	/* Check beyond bounds of aperture */
 	object.offset = gem_aperture_size(fd) - 4096;
-	object.offset = gen8_canonical_addr(object.offset);
+	object.offset = igt_canonical_addr(object.offset);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
 	/* Check gen8 canonical addressing */
@@ -78,7 +66,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull << GEN8_HIGH_ADDRESS_BIT;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
 
@@ -88,7 +76,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull<<32;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		object.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
tests/gem_trtt.c new file +627 -0

627 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw
Quoted 6 lines · On Fri, Mar 18, 2016 at 02:07:40PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +6 -0
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address

tests/gem_trtt.c line 98

Quoted 10 lines
tests/gem_trtt.c new file +10 -0
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint64_t data)
+{
+	/* Check that softpin addresses are in the correct form */
+	igt_assert_eq_u64(vaddr, igt_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	igt_assert((vaddr & 3) == 0);

If I remember correctly a qword write from SDI must be 8 byte aligned. Right?

tests/gem_trtt.c line 107

Quoted 9 lines
tests/gem_trtt.c new file +9 -0
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = (uint32_t)vaddr;
+	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}

Hopefully final comments!

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#18 lore raw
Quoted 12 lines · Chris Wilson
Quoted 11 lines · On Fri, Mar 18, 2016 at 02:07:40PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +11 -0
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint64_t data)
+{
Quoted 8 lines

tests/gem_trtt.c line 73

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+	/* Check that softpin addresses are in the correct form */
+	igt_assert_eq_u64(vaddr, igt_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	igt_assert((vaddr & 3) == 0);

If I remember correctly a qword write from SDI must be 8 byte aligned. Right?

Yes right. Sorry, my bad..

Quoted 13 lines

tests/gem_trtt.c line 107

Quoted 10 lines
tests/gem_trtt.c new file +9 -0
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = (uint32_t)vaddr;
+	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}

Hopefully final comments!

Quoted 3 lines

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.

Fine will add, thanks for suggesting this
So the signal will interrupt the Driver, which would be waiting for the vma unbind to complete, from the eviction path.

Best regards
Akash

Quoted 2 lines

-Chris

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

#19 lore raw
Quoted 38 lines · Akash
Quoted 12 lines · Chris Wilson
Quoted 11 lines · On Fri, Mar 18, 2016 at 02:07:40PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +11 -0
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint64_t data)
+{
Quoted 8 lines

tests/gem_trtt.c line 73

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+	/* Check that softpin addresses are in the correct form */
+	igt_assert_eq_u64(vaddr, igt_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	igt_assert((vaddr & 3) == 0);

If I remember correctly a qword write from SDI must be 8 byte aligned. Right?

Yes right. Sorry, my bad..

Quoted 13 lines

tests/gem_trtt.c line 107

Quoted 10 lines
tests/gem_trtt.c new file +9 -0
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = (uint32_t)vaddr;
+	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}

Hopefully final comments!

Quoted 7 lines
Quoted 3 lines

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.

Fine will add, thanks for suggesting this
So the signal will interrupt the Driver, which would be waiting for the vma unbind to complete, from the eviction path.

Right, and we will report the error back to userspace as EINTR and userspace will restart the syscall and we expect it to succeed (eventually). Just useful for flushing out the error handling.

Having just remembered how useful this might be, I just extended gem_softpin for similar reasons:
+ igt_subtest("evict-active-interruptible") {
+ struct timespec start = {};
+ while (igt_seconds_elapsed(&start) < 20)
+ test_evict_active(fd);
+ }
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#20 lore raw
Quoted 53 lines · Chris Wilson
Quoted 38 lines · Akash
Quoted 12 lines · Chris Wilson
Quoted 11 lines · On Fri, Mar 18, 2016 at 02:07:40PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +11 -0
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint64_t data)
+{
Quoted 8 lines

tests/gem_trtt.c line 73

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+	/* Check that softpin addresses are in the correct form */
+	igt_assert_eq_u64(vaddr, igt_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	igt_assert((vaddr & 3) == 0);

If I remember correctly a qword write from SDI must be 8 byte aligned. Right?

Yes right. Sorry, my bad..

Quoted 13 lines

tests/gem_trtt.c line 107

Quoted 10 lines
tests/gem_trtt.c new file +9 -0
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = (uint32_t)vaddr;
+	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}

Hopefully final comments!

Quoted 7 lines
Quoted 3 lines

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.

Fine will add, thanks for suggesting this
So the signal will interrupt the Driver, which would be waiting for the vma unbind to complete, from the eviction path.

Right, and we will report the error back to userspace as EINTR and userspace will restart the syscall and we expect it to succeed (eventually). Just useful for flushing out the error handling.

Having just remembered how useful this might be, I just extended gem_softpin for similar reasons:

Review

Quoted 5 lines
(quoted diff) +5 -0
+       igt_subtest("evict-active-interruptible") {
+               struct timespec start = {};
+               while (igt_seconds_elapsed(&start) < 20)
+                       test_evict_active(fd);
+       }

Thanks I just tested the interruptible versions like this :-

+ igt_fork_signal_helper();
+ igt_subtest("evict_active-interruptible")
+ test_evict_active();
+
+ igt_subtest("evict_hang-interruptible")
+ test_evict_hang();
+ igt_stop_signal_helper();

Actually the hanging object test implicitly exercises the interruption case (otherwise the test won't pass), error recovery as a part of GPU reset wakes up/interrupts the waiters.

Best regards
Akash

Quoted 2 lines

-Chris

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

#21 lore raw

PATCH v7 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

v6:
- Allow each subtest to have their own private drm file instance.
- Update the basic subtest to check each segment location for both default and User created contexts (Chris).
- Reorder igt_require(softpin/64b_ppgtt/trtt) to have trtt first (Chris).
- Update the invalid subtest to check for the improper value of Null & Invalid tiles.

v7:
- Add interruptible version of the 2 eviction subtests (Chris)
- Correct the alignment check for the MI Store qword command (Chris).

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/igt_aux.c          |  11 +
 lib/igt_aux.h          |   1 +
 lib/igt_gt.h           |   2 +
 lib/ioctl_wrappers.c   |  39 ++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_softpin.c    |  18 +-
 tests/gem_trtt.c       | 635 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 687 insertions(+), 23 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/igt_aux.c +11 -0
index 7d35666..c5fedb5 100644
@@ -206,6 +206,17 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
 	int_arr[j] = tmp;
 }
 
+/* igt_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+*/
+uint64_t igt_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}
+
 static uint32_t
 hars_petruska_f54_1_random_unsafe(void)
 {
lib/igt_aux.h +1 -0
index 427719e..85fc64b 100644
@@ -48,6 +48,7 @@ void igt_permute_array(void *array, unsigned size,
 void igt_progress(const char *header, uint64_t i, uint64_t total);
 void igt_print_activity(void);
 bool igt_check_boolean_env_var(const char *env_var, bool default_value);
+uint64_t igt_canonical_addr(uint64_t address);
 
 bool igt_aub_dump_enabled(void);
 
lib/igt_gt.h +2 -0
index b7c5c4a..d4e9dbb 100644
@@ -98,4 +98,6 @@ extern const struct intel_execution_engine {
 	unsigned flags;
 } intel_execution_engines[];
 
+#define GEN8_HIGH_ADDRESS_BIT 47
+
 #endif /* IGT_GT_H */
lib/ioctl_wrappers.c +31 -8
index 4071260..fb5de07 100644
@@ -882,6 +882,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -892,14 +908,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(drmIoctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1063,6 +1072,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index dc0827a..d23fa96 100644
@@ -107,9 +107,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -143,6 +145,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
tests/Makefile.sources +1 -0
index f8b18b0..e6081f6 100644
@@ -73,6 +73,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_softpin.c +3 -15
index 1b3d9d3..3eee08f 100644
@@ -31,18 +31,6 @@
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -70,7 +58,7 @@ static void test_invalid(int fd)
 
 	/* Check beyond bounds of aperture */
 	object.offset = gem_aperture_size(fd) - 4096;
-	object.offset = gen8_canonical_addr(object.offset);
+	object.offset = igt_canonical_addr(object.offset);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
 	/* Check gen8 canonical addressing */
@@ -78,7 +66,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull << GEN8_HIGH_ADDRESS_BIT;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
 
@@ -88,7 +76,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull<<32;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		object.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
tests/gem_trtt.c new file +635 -0

635 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#22 lore raw
In reply to Goel, Akash
Quoted 63 lines · Akash
Quoted 53 lines · Chris Wilson
Quoted 38 lines · Akash
Quoted 12 lines · Chris Wilson
Quoted 11 lines · On Fri, Mar 18, 2016 at 02:07:40PM +0530, [email protected] wrote:
tests/gem_trtt.c new file +11 -0
+/* emit_store_qword
+ * populate batch buffer with MI_STORE_DWORD_IMM command
+ * @fd: drm file descriptor
+ * @cmd_buf: batch buffer
+ * @dw_offset: write offset in batch buffer
+ * @vaddr: destination Virtual address
+ * @data: u64 data to be stored at destination
+ */
+static int emit_store_qword(int fd, uint32_t *cmd_buf, uint32_t dw_offset,
+			    uint64_t vaddr, uint64_t data)
+{
Quoted 8 lines

tests/gem_trtt.c line 73

Quoted 5 lines
tests/gem_trtt.c new file +5 -0
+	/* Check that softpin addresses are in the correct form */
+	igt_assert_eq_u64(vaddr, igt_canonical_addr(vaddr));
+
+	/* SDI cannot write to unaligned addresses */
+	igt_assert((vaddr & 3) == 0);

If I remember correctly a qword write from SDI must be 8 byte aligned. Right?

Yes right. Sorry, my bad..

Quoted 13 lines

tests/gem_trtt.c line 107

Quoted 10 lines
tests/gem_trtt.c new file +9 -0
+
+	cmd_buf[dw_offset++] = MI_STORE_DWORD_IMM | 0x3;
+	cmd_buf[dw_offset++] = (uint32_t)vaddr;
+	cmd_buf[dw_offset++] = (uint32_t)(vaddr >> 32);
+	cmd_buf[dw_offset++] = data;
+	cmd_buf[dw_offset++] = data >> 32;
+
+	return dw_offset;
+}

Hopefully final comments!

Quoted 7 lines
Quoted 3 lines

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.

Fine will add, thanks for suggesting this
So the signal will interrupt the Driver, which would be waiting for the vma unbind to complete, from the eviction path.

Right, and we will report the error back to userspace as EINTR and userspace will restart the syscall and we expect it to succeed (eventually). Just useful for flushing out the error handling.

Having just remembered how useful this might be, I just extended gem_softpin for similar reasons:

Review

Quoted 5 lines
(quoted diff) +5 -0
+       igt_subtest("evict-active-interruptible") {
+               struct timespec start = {};
+               while (igt_seconds_elapsed(&start) < 20)
+                       test_evict_active(fd);
+       }

Thanks I just tested the interruptible versions like this :-

Review

Quoted 3 lines
(quoted diff) +3 -0
+	igt_fork_signal_helper();
+	igt_subtest("evict_active-interruptible")
+		 test_evict_active();

The point about looping is to try and ensure that every possible code path is interrupted (since we only interrupt every 2us and the code paths tend to be shorter than than!). So we repeat the test in the vain hope of hitting something else.

Quoted 7 lines
(quoted diff) +3 -0
+	igt_subtest("evict_hang-interruptible")
+		test_evict_hang();
+	igt_stop_signal_helper();

Actually the hanging object test implicitly exercises the interruption case (otherwise the test won't pass), error recovery as a part of GPU reset wakes up/interrupts the waiters.

But only in one spot :)
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#23 lore raw
Quoted 29 lines · Chris Wilson
Quoted 28 lines · Akash
Quoted 18 lines · Chris Wilson
Quoted 10 lines · Akash
Quoted 6 lines

Hopefully final comments!

Missed EINTR handling during evict, If you repeat the busy/hang tests within the igt_fork_signal_helper(); igt_stop_signal_helper() that should cover catching an inopportune signal.

Fine will add, thanks for suggesting this
So the signal will interrupt the Driver, which would be waiting for the vma unbind to complete, from the eviction path.

Right, and we will report the error back to userspace as EINTR and userspace will restart the syscall and we expect it to succeed (eventually). Just useful for flushing out the error handling.

Having just remembered how useful this might be, I just extended gem_softpin for similar reasons:

Review

Quoted 5 lines
(quoted diff) +5 -0
+       igt_subtest("evict-active-interruptible") {
+               struct timespec start = {};
+               while (igt_seconds_elapsed(&start) < 20)
+                       test_evict_active(fd);
+       }

Thanks I just tested the interruptible versions like this :-

Quoted 7 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	igt_fork_signal_helper();
+	igt_subtest("evict_active-interruptible")
+		 test_evict_active();

The point about looping is to try and ensure that every possible code path is interrupted (since we only interrupt every 2us and the code paths tend to be shorter than than!).

Thanks, will follow the gem_softpin.c example.

I hope you meant 2ms here & not 2us, since the signal_helper_process is sending signals at the ~500 Hz rate.

Best regards
Akash

Quoted 7 lines

So we repeat the test in the vain hope of hitting something else.

Quoted 4 lines
(quoted diff) +3 -0
+	igt_subtest("evict_hang-interruptible")
+		test_evict_hang();
+	igt_stop_signal_helper();
Quoted 7 lines
Quoted 3 lines

Actually the hanging object test implicitly exercises the interruption case (otherwise the test won't pass), error recovery as a part of GPU reset wakes up/interrupts the waiters.

But only in one spot :)
-Chris

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

#24 lore raw
Quoted 9 lines · Akash
Quoted 3 lines · Chris Wilson

The point about looping is to try and ensure that every possible code path is interrupted (since we only interrupt every 2us and the code paths tend to be shorter than than!).

Thanks, will follow the gem_softpin.c example.

I hope you meant 2ms here & not 2us, since the signal_helper_process is sending signals at the ~500 Hz rate.

Yeah, failed hopeless. Though I thought it was a 5000Hz rate. Any way the point is that the chance of a signal interrupting a critical path anywhere other than at a wait is small, and so we want to repeat the test a few times to increase our chances.
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#25 lore raw
Quoted 8 lines · Chris Wilson
Quoted 7 lines · Akash
Quoted 3 lines · Chris Wilson

The point about looping is to try and ensure that every possible code path is interrupted (since we only interrupt every 2us and the code paths tend to be shorter than than!).

Thanks, will follow the gem_softpin.c example.

Quoted 7 lines
Quoted 2 lines

I hope you meant 2ms here & not 2us, since the signal_helper_process is sending signals at the ~500 Hz rate.

Yeah, failed hopeless. Though I thought it was a 5000Hz rate. Any way the point is that the chance of a signal interrupting a critical path anywhere other than at a wait is small, and so we want to repeat the test a few times to increase our chances.

Just rebased. Should I use the 'igt_interruptible' now for eviction tests in place of

+ igt_subtest("evict-active-interruptible") {
+ struct timespec start = {};
+ while (igt_seconds_elapsed(&start) < 20)
+ test_evict_active(fd);
+ }

Quoted 2 lines

-Chris

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

#26 lore raw
Quoted 22 lines · Akash
Quoted 8 lines · Chris Wilson
Quoted 7 lines · Akash
Quoted 3 lines · Chris Wilson

The point about looping is to try and ensure that every possible code path is interrupted (since we only interrupt every 2us and the code paths tend to be shorter than than!).

Thanks, will follow the gem_softpin.c example.

Quoted 7 lines
Quoted 2 lines

I hope you meant 2ms here & not 2us, since the signal_helper_process is sending signals at the ~500 Hz rate.

Yeah, failed hopeless. Though I thought it was a 5000Hz rate. Any way the point is that the chance of a signal interrupting a critical path anywhere other than at a wait is small, and so we want to repeat the test a few times to increase our chances.

Just rebased. Should I use the 'igt_interruptible' now for eviction tests in place of

Review

Quoted 5 lines
(quoted diff) +5 -0
+       igt_subtest("evict-active-interruptible") {
+               struct timespec start = {};
+               while (igt_seconds_elapsed(&start) < 20)
+                       test_evict_active(fd);
+       }

Please give it a whirl. It was the outcome of our discussion, trying to be more accurate as to when repeating an ioctl due to signal interruption is actually worthwhile. Improvements welcome!
-Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

PATCH v8 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

v6:
- Allow each subtest to have their own private drm file instance.
- Update the basic subtest to check each segment location for both default and User created contexts (Chris).
- Reorder igt_require(softpin/64b_ppgtt/trtt) to have trtt first (Chris).
- Update the invalid subtest to check for the improper value of Null & Invalid tiles.

v7:
- Add interruptible version of the 2 eviction subtests (Chris)
- Correct the alignment check for the MI Store qword command (Chris).

v8:
- Use new igt_interruptible macro for the interruptible subtests, as its more effective & precise.
- Remove interruptible version of evict_hang subtest, as it doesn't provide any additional coverage (Chris)
- Rebased.

Cc Chris Wilson <[email protected]>
Cc Michel Thierry <[email protected]>
---
 lib/igt_aux.c          |  11 +
 lib/igt_aux.h          |   1 +
 lib/igt_gt.h           |   1 +
 lib/ioctl_wrappers.c   |  39 ++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_softpin.c    |  18 +-
 tests/gem_trtt.c       | 630 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 681 insertions(+), 23 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/igt_aux.c +11 -0
index da21f10..958cc53 100644
@@ -399,6 +399,17 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
 	int_arr[j] = tmp;
 }
 
+/* igt_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+*/
+uint64_t igt_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}
+
 static uint32_t
 hars_petruska_f54_1_random_unsafe(void)
 {
lib/igt_aux.h +1 -0
index 101fad1..d1154f0 100644
@@ -56,6 +56,7 @@ void igt_permute_array(void *array, unsigned size,
 void igt_progress(const char *header, uint64_t i, uint64_t total);
 void igt_print_activity(void);
 bool igt_check_boolean_env_var(const char *env_var, bool default_value);
+uint64_t igt_canonical_addr(uint64_t address);
 
 bool igt_aub_dump_enabled(void);
 
lib/igt_gt.h +1 -0
index dfe1cfb..28f2e2a 100644
@@ -108,5 +108,6 @@ extern const struct intel_execution_engine {
 	     e__++) \
 		for_if (gem_has_ring(fd, flags__ = e__->exec_id | e__->flags))
 
+#define GEN8_HIGH_ADDRESS_BIT 47
 
 #endif /* IGT_GT_H */
lib/ioctl_wrappers.c +31 -8
index 076bce8..b7c38f9 100644
@@ -892,6 +892,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -902,14 +918,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1073,6 +1082,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index d986f61..c7a2348 100644
@@ -109,9 +109,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_BAN_PERIOD	0x1
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
+#define LOCAL_CONTEXT_PARAM_TRTT	0x4
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -143,6 +145,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_available_aperture_size(int fd);
 uint64_t gem_aperture_size(int fd);
tests/Makefile.sources +1 -0
index 5b119af..10e780c 100644
@@ -75,6 +75,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
tests/gem_softpin.c +3 -15
index 1a9ef02..e7a796a 100644
@@ -31,18 +31,6 @@
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -70,7 +58,7 @@ static void test_invalid(int fd)
 
 	/* Check beyond bounds of aperture */
 	object.offset = gem_aperture_size(fd) - 4096;
-	object.offset = gen8_canonical_addr(object.offset);
+	object.offset = igt_canonical_addr(object.offset);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
 	/* Check gen8 canonical addressing */
@@ -78,7 +66,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull << GEN8_HIGH_ADDRESS_BIT;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
 
@@ -88,7 +76,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull<<32;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		object.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
tests/gem_trtt.c new file +630 -0

630 lines not on this page · raw message

Signature · 6 lines
1.9.2

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

PATCH v9 1/1 igt/gem_trtt: Exercise the TRTT hardware

From: Akash Goel <[email protected]>

This patch provides the testcase to exercise the TRTT hardware.

Some platforms have an additional address translation hardware support in form of Tiled Resource Translation Table (TR-TT) which provides an extra level of abstraction over PPGTT.
This is useful for mapping Sparse/Tiled texture resources.

TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required for a new PPGTT instance, but TR-TT may not enabled for every context. 1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, which such chunk to use is conveyed to HW through a register.
Any GFX address, which lies in that reserved 44 bit range will be translated through TR-TT first and then through PPGTT to get the actual physical address.

TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and each level is contained within a 4KB page hence L3 and L2 is composed of 512 64b entries and L1 is composed of 1024 32b entries.

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

I915_GEM_CONTEXT_SETPARAM ioctl is used to request KMD to enable TRTT for a certain context, a new I915_CONTEXT_PARAM_ENABLE_TRTT param has been added to the CONTEXT_SETPARAM ioctl for that purpose.

v2:
- Add new wrapper function __gem_context_require_param and used that to detect the TR-TT support
- Use igt_main macro, rename certain function, remove extra white space, cleanup the code (Chris)
- Enhance the basic subtest to exercise all possible TR-TT segment start locations (i.e. 16 of them) & for every iteration create a new context.

v3:
- Get rid of some superfluous local variables (Chris)
- Add asserts to validate whether the GFX address used in MI_STORE_DATA_IMM command is in canonical form & is correctly aligned or not (Chris)
- Remove clearing of errno in has_trtt_support function (Chris)
- Use the 48B_ADDRESS flag for batch buffer BO also (Chris)
- Rebased.

v4:
- Add new subtest for invalid settings.
- Add new local function query_trtt to check the Driver state (Chris)
- Add new helper function gem_uses_64b_ppgtt to detect 64bit PPGTT support
- Remove local functions uses_full_ppgtt & has_softpin_support, instead use existing wrappers gem_has_softpin & gem_uses_64b_ppgtt (Chris).
- Remove redundant bit masking in emit_store_xxx functions (Chris).

v5:
- Add 2 new subtests checking the forceful eviction of active/hanging objects overlapping with the TR-TT segment (Chris).
- Move gen8_canonical_addr to igt_aux as its needed by other tests also, which does soft pinning, and not just gem_softpin (Michel)

v6:
- Allow each subtest to have their own private drm file instance.
- Update the basic subtest to check each segment location for both default and User created contexts (Chris).
- Reorder igt_require(softpin/64b_ppgtt/trtt) to have trtt first (Chris).
- Update the invalid subtest to check for the improper value of Null & Invalid tiles.

v7:
- Add interruptible version of the 2 eviction subtests (Chris)
- Correct the alignment check for the MI Store qword command (Chris).

v8:
- Use new igt_interruptible macro for the interruptible subtests, as its more effective & precise.
- Remove interruptible version of evict_hang subtest, as it doesn't provide any additional coverage (Chris)
- Rebased.

v9:
- Rebased.

---
 lib/igt_aux.c          |  11 +
 lib/igt_aux.h          |   1 +
 lib/igt_gt.h           |   1 +
 lib/ioctl_wrappers.c   |  39 ++-
 lib/ioctl_wrappers.h   |   3 +
 tests/Makefile.sources |   1 +
 tests/gem_softpin.c    |  18 +-
 tests/gem_trtt.c       | 630 +++++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 681 insertions(+), 23 deletions(-)
 create mode 100644 tests/gem_trtt.c
lib/igt_aux.c +11 -0
index 421f6d4..9cb4666 100644
@@ -487,6 +487,17 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
 	int_arr[j] = tmp;
 }
 
+/* igt_canonical_addr
+ * Used to convert any address into canonical form, i.e. [63:48] == [47].
+ * Based on kernel's sign_extend64 implementation.
+ * @address - a virtual address
+*/
+uint64_t igt_canonical_addr(uint64_t address)
+{
+	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
+	return (__s64)(address << shift) >> shift;
+}
+
 /**
  * igt_permute_array:
  * @array: pointer to array
lib/igt_aux.h +1 -0
index d30196b..3c55152 100644
@@ -106,6 +106,7 @@ void igt_permute_array(void *array, unsigned size,
 void igt_progress(const char *header, uint64_t i, uint64_t total);
 void igt_print_activity(void);
 bool igt_check_boolean_env_var(const char *env_var, bool default_value);
+uint64_t igt_canonical_addr(uint64_t address);
 
 bool igt_aub_dump_enabled(void);
 
lib/igt_gt.h +1 -0
index 8d6c573..45f0f18 100644
@@ -78,5 +78,6 @@ extern const struct intel_execution_engine {
 	     e__++) \
 		for_if (gem_has_ring(fd, flags__ = e__->exec_id | e__->flags))
 
+#define GEN8_HIGH_ADDRESS_BIT 47
 
 #endif /* IGT_GT_H */
lib/ioctl_wrappers.c +31 -8
index 95bc5e2..763eb4d 100644
@@ -938,6 +938,22 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
 	igt_assert(__gem_context_set_param(fd, p) == 0);
 }
 
+int __gem_context_require_param(int fd, uint64_t param)
+{
+	struct local_i915_gem_context_param p;
+	int ret;
+
+	p.context = 0;
+	p.param = param;
+	p.value = 0;
+	p.size = 0;
+
+	ret = igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p);
+	if (ret)
+		return -errno;
+	return 0;
+}
+
 /**
  * gem_context_require_param:
  * @fd: open i915 drm file descriptor
@@ -948,14 +964,7 @@ void gem_context_set_param(int fd, struct local_i915_gem_context_param *p)
  */
 void gem_context_require_param(int fd, uint64_t param)
 {
-	struct local_i915_gem_context_param p;
-
-	p.context = 0;
-	p.param = param;
-	p.value = 0;
-	p.size = 0;
-
-	igt_require(igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_CONTEXT_GETPARAM, &p) == 0);
+	igt_require(__gem_context_require_param(fd, param) == 0);
 }
 
 void gem_context_require_ban_period(int fd)
@@ -1112,6 +1121,20 @@ bool gem_uses_full_ppgtt(int fd)
 }
 
 /**
+ * gem_uses_64b_ppgtt:
+ * @fd: open i915 drm file descriptor
+ *
+ * Feature test macro to check whether the kernel internally uses full
+ * 64b per-process gtt to execute batches.
+ *
+ * Returns: Whether batches are run through full 64b ppgtt.
+ */
+bool gem_uses_64b_ppgtt(int fd)
+{
+	return gem_gtt_type(fd) > 2;
+}
+
+/**
  * gem_available_fences:
  * @fd: open i915 drm file descriptor
  *
lib/ioctl_wrappers.h +3 -0
index 465f760..775c098 100644
@@ -120,9 +120,11 @@ struct local_i915_gem_context_param {
 #define LOCAL_CONTEXT_PARAM_NO_ZEROMAP	0x2
 #define LOCAL_CONTEXT_PARAM_GTT_SIZE	0x3
 #define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE	0x4
+#define LOCAL_CONTEXT_PARAM_TRTT	0x5
 	uint64_t value;
 };
 void gem_context_require_ban_period(int fd);
+int __gem_context_require_param(int fd, uint64_t param);
 void gem_context_require_param(int fd, uint64_t param);
 void gem_context_get_param(int fd, struct local_i915_gem_context_param *p);
 void gem_context_set_param(int fd, struct local_i915_gem_context_param *p);
@@ -155,6 +157,7 @@ bool gem_has_bsd2(int fd);
 int gem_gtt_type(int fd);
 bool gem_uses_ppgtt(int fd);
 bool gem_uses_full_ppgtt(int fd);
+bool gem_uses_64b_ppgtt(int fd);
 int gem_available_fences(int fd);
 uint64_t gem_total_mappable_size(int fd);
 uint64_t gem_total_stolen_size(int fd);
tests/Makefile.sources +1 -0
index 6d081c3..211fb2e 100644
@@ -81,6 +81,7 @@ TESTS_progs_M = \
 	gem_streaming_writes \
 	gem_tiled_blits \
 	gem_tiled_partial_pwrite_pread \
+	gem_trtt \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	gvt_basic \
tests/gem_softpin.c +3 -15
index ea162c8..bd3631f 100644
@@ -31,18 +31,6 @@
 #define EXEC_OBJECT_PINNED	(1<<4)
 #define EXEC_OBJECT_SUPPORTS_48B_ADDRESS (1<<3)
 
-/* gen8_canonical_addr
- * Used to convert any address into canonical form, i.e. [63:48] == [47].
- * Based on kernel's sign_extend64 implementation.
- * @address - a virtual address
-*/
-#define GEN8_HIGH_ADDRESS_BIT 47
-static uint64_t gen8_canonical_addr(uint64_t address)
-{
-	__u8 shift = 63 - GEN8_HIGH_ADDRESS_BIT;
-	return (__s64)(address << shift) >> shift;
-}
-
 static void test_invalid(int fd)
 {
 	const uint32_t bbe = MI_BATCH_BUFFER_END;
@@ -70,7 +58,7 @@ static void test_invalid(int fd)
 
 	/* Check beyond bounds of aperture */
 	object.offset = gem_aperture_size(fd) - 4096;
-	object.offset = gen8_canonical_addr(object.offset);
+	object.offset = igt_canonical_addr(object.offset);
 	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
 	/* Check gen8 canonical addressing */
@@ -78,7 +66,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull << GEN8_HIGH_ADDRESS_BIT;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
 
@@ -88,7 +76,7 @@ static void test_invalid(int fd)
 		object.offset = 1ull<<32;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
 
-		object.offset = gen8_canonical_addr(object.offset);
+		object.offset = igt_canonical_addr(object.offset);
 		object.flags |= EXEC_OBJECT_SUPPORTS_48B_ADDRESS;
 		igt_assert_eq(__gem_execbuf(fd, &execbuf), 0);
 	}
tests/gem_trtt.c new file +630 -0

630 lines not on this page · raw message

Signature · 6 lines
1.9.2

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#29 lore raw
In reply to [email protected]
Quoted 3 lines

From: [email protected]
Sent: Saturday, January 09, 2016 7:32 PM

[...]

Quoted 10 lines

There is a provision to keep TR-TT Tables in virtual space, where the pages of TRTT tables will be mapped to PPGTT. This is the adopted mode, as in this mode UMD will have a full control on TR-TT management, with bare minimum support from KMD.
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. The entries of L1 table will contain the PPGTT offset of BOs actually backing the Sparse resources.

Just a side note. Using virtual address for TRTT table also benefits virtualization side. This way we can let guest own TRTT completely. Otherwise we have to virtualize TRTT table if physical address is used, which is very complex and could bring obvious performance impact.

It's appreciated if you can add this virtualization requirement in code comment so others can catch this limitation if they want to do some change in the future. :-)

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