Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Bommu Krishnaiah <krishnaiah.bommu@intel.com>,
	Oak Zeng <oak.zeng@intel.com>
Subject: [PATCH] RFC: tests/xe_svm: basic svm test
Date: Thu, 11 Jan 2024 15:13:04 +0530	[thread overview]
Message-ID: <20240111094304.395181-1-krishnaiah.bommu@intel.com> (raw)

Test will verify SVM basic functionality, by allocating a memory with
system allocator(malloc()) and accessing in GPU.

Kernel changes:
https://lore.kernel.org/dri-devel/20231221043812.3783313-1-oak.zeng@intel.com/

Signed-off-by: Bommu Krishnaiah <krishnaiah.bommu@intel.com>
Cc: Oak Zeng <oak.zeng@intel.com>
Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
---
 tests/intel/xe_svm.c | 136 +++++++++++++++++++++++++++++++++++++++++++
 tests/meson.build    |   1 +
 2 files changed, 137 insertions(+)
 create mode 100644 tests/intel/xe_svm.c

diff --git a/tests/intel/xe_svm.c b/tests/intel/xe_svm.c
new file mode 100644
index 000000000..f82cb8fc7
--- /dev/null
+++ b/tests/intel/xe_svm.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright © 2021 Intel Corporation
+ */
+
+/**
+ * TEST: Basic tests for svm functionality
+ * Category: Hardware building block
+ * Sub-category: svm-basic
+ * Functionality: svm
+ */
+
+#include "igt.h"
+#include "lib/igt_syncobj.h"
+#include "lib/intel_reg.h"
+#include "xe_drm.h"
+
+#include "xe/xe_ioctl.h"
+#include "xe/xe_query.h"
+#include <string.h>
+
+/**
+ * SUBTEST: svm-basic
+ * Description: Run svm basic test only once
+ * Test category: functionality test
+ */
+
+static void
+test_exec(int fd)
+{
+	uint32_t vm;
+	uint64_t addr = 0x1a0000;
+#define USER_FENCE_VALUE        0xdeadbeefdeadbeefull
+	struct drm_xe_sync sync[1] = {
+		{ .type = DRM_XE_SYNC_TYPE_USER_FENCE, .flags = DRM_XE_SYNC_FLAG_SIGNAL,
+			.timeline_value = USER_FENCE_VALUE },
+	};
+	struct drm_xe_exec exec = {
+		.num_batch_buffer = 1,
+		.num_syncs = 1,
+		.syncs = to_user_pointer(sync),
+	};
+	uint32_t exec_queues;
+	uint32_t bind_exec_queues;
+	uint64_t batch_offset;
+	uint64_t batch_addr;
+	size_t bo_size;
+	uint32_t bo = 0;
+	struct {
+		uint32_t batch[16];
+		uint64_t pad;
+		uint64_t vm_sync;
+		uint64_t exec_sync;
+		uint32_t data;
+	} *data;
+	int b;
+	uint64_t dst = (uint64_t *)malloc(4);
+
+	vm = xe_vm_create(fd, 0, 0);
+	bo_size = sizeof(*data) ;
+	bo_size = ALIGN(bo_size, xe_get_default_alignment(fd));
+
+	bo = xe_bo_create(fd, 0, bo_size,
+			all_memory_regions(fd) |
+			vram_if_possible(fd, 0),
+			DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM);
+
+	data = xe_bo_map(fd, bo, bo_size);
+	memset(data, 0, bo_size);
+
+	exec_queues = xe_exec_queue_create_class(fd, vm, DRM_XE_ENGINE_CLASS_COPY);
+	bind_exec_queues = xe_bind_exec_queue_create(fd, vm, 0);
+
+	sync[0].addr = to_user_pointer(&data[0].vm_sync);
+
+	xe_vm_bind_async_flags(fd, vm, bind_exec_queues, bo, 0,
+			addr, bo_size, sync, 1,
+			DRM_XE_VM_BIND_FLAG_IMMEDIATE);
+
+#define ONE_SEC MS_TO_NS(1000)
+	xe_wait_ufence(fd, &data[0].vm_sync, USER_FENCE_VALUE, bind_exec_queues, ONE_SEC);
+	data[0].vm_sync = 0;
+
+	batch_offset = (char *)&data[0].batch - (char *)data;
+	batch_addr = addr + batch_offset;
+
+	b = 0;
+	data[0].batch[b++] = MI_STORE_DWORD_IMM_GEN4;
+	data[0].batch[b++] = dst;
+	data[0].batch[b++] = dst >> 32;
+	data[0].batch[b++] = 0xc0ffee;
+	data[0].batch[b++] = MI_BATCH_BUFFER_END;
+	igt_assert(b <= ARRAY_SIZE(data[0].batch));
+
+	sync[0].addr = addr + (char *)&data[0].exec_sync - (char *)data;
+
+	exec.exec_queue_id = exec_queues;
+	exec.address = batch_addr;
+	xe_exec(fd, &exec);
+
+	xe_wait_ufence(fd, &data[0].exec_sync, USER_FENCE_VALUE, exec_queues, ONE_SEC);
+
+	sync[0].addr = to_user_pointer(&data[0].vm_sync);
+
+	xe_vm_unbind_async(fd, vm, bind_exec_queues, 0, addr, bo_size, sync, 1);
+
+	xe_wait_ufence(fd, &data[0].vm_sync, USER_FENCE_VALUE, bind_exec_queues, ONE_SEC);
+
+	igt_assert_eq(dst, 0xc0ffee);
+
+	if (exec_queues)
+		xe_exec_queue_destroy(fd, exec_queues);
+	if (bind_exec_queues)
+		xe_exec_queue_destroy(fd, bind_exec_queues);
+
+	free(data);
+	free(dst);
+	gem_close(fd, bo);
+
+	xe_vm_destroy(fd, vm);
+}
+
+igt_main
+{
+	int fd;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_XE);
+	}
+
+	igt_subtest_f("svm-basic")
+		test_exec(fd);
+
+	igt_fixture
+		drm_close_driver(fd);
+}
diff --git a/tests/meson.build b/tests/meson.build
index a6a8498e2..13cc7acae 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -313,6 +313,7 @@ intel_xe_progs = [
 	'xe_spin_batch',
 	'xe_sysfs_defaults',
 	'xe_sysfs_scheduler',
+	'xe_svm',
 ]
 
 msm_progs = [
-- 
2.25.1

             reply	other threads:[~2024-01-11  9:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-11  9:43 Bommu Krishnaiah [this message]
2024-01-11 11:35 ` ✓ Fi.CI.BAT: success for RFC: tests/xe_svm: basic svm test Patchwork
2024-01-11 12:43 ` ✓ CI.xeBAT: " Patchwork
2024-01-11 14:06 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-01-11 15:04 ` [PATCH] " Kamil Konieczny
2024-01-11 22:27 ` Zeng, Oak
2024-01-15 19:42   ` Zeng, Oak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240111094304.395181-1-krishnaiah.bommu@intel.com \
    --to=krishnaiah.bommu@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=oak.zeng@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox