Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [PATCH 2/2] xe_exec_system_allocator: Add benchmark
Date: Wed, 19 Jun 2024 20:50:57 -0700	[thread overview]
Message-ID: <20240620035057.3609916-2-matthew.brost@intel.com> (raw)
In-Reply-To: <20240620035057.3609916-1-matthew.brost@intel.com>

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 tests/intel/xe_exec_system_allocator.c | 31 +++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/tests/intel/xe_exec_system_allocator.c b/tests/intel/xe_exec_system_allocator.c
index 7b85f85e5e..1b93d6d87a 100644
--- a/tests/intel/xe_exec_system_allocator.c
+++ b/tests/intel/xe_exec_system_allocator.c
@@ -13,6 +13,7 @@
 
 #include <fcntl.h>
 #include <linux/mman.h>
+#include <time.h>
 
 #include "igt.h"
 #include "lib/igt_syncobj.h"
@@ -62,7 +63,8 @@ static void check_all_pages(void *ptr, uint64_t alloc_size, uint64_t stride)
 }
 
 static void touch_all_pages(int fd, uint32_t exec_queue, void *ptr,
-			    uint64_t alloc_size, uint64_t stride)
+			    uint64_t alloc_size, uint64_t stride,
+			    struct timespec *tv, uint64_t *submit)
 {
 	struct drm_xe_sync sync[1] = {
 		{ .type = DRM_XE_SYNC_TYPE_USER_FENCE,
@@ -97,6 +99,9 @@ static void touch_all_pages(int fd, uint32_t exec_queue, void *ptr,
 		igt_assert(b <= ARRAY_SIZE(data->batch));
 	}
 
+	igt_nsec_elapsed(tv);
+	*submit = igt_nsec_elapsed(tv);
+
 	addr = to_user_pointer(ptr);
 	for (i = 0; i < n_writes; ++i, addr += stride) {
 		struct batch_data *data = ptr + i * stride;
@@ -147,6 +152,7 @@ static void touch_all_pages(int fd, uint32_t exec_queue, void *ptr,
 #define odd(__i)	(__i & 1)
 
 #define MIX_BO_ALLOC	(0x1 << 0)
+#define BENCHMARK	(0x1 << 1)
 
 #define SYNC_FILE	"/tmp/xe_exec_system_allocator_sync"
 
@@ -185,9 +191,12 @@ evict(int fd, struct drm_xe_engine_class_instance *eci, uint64_t total_alloc,
       unsigned int flags)
 {
 	uint32_t vm, exec_queue;
-	int num_allocs = (9 * (total_alloc / alloc_size)) / 8;
+	int num_allocs = flags & BENCHMARK ? 1 :
+		(9 * (total_alloc / alloc_size)) / 8;
 	void **allocs;
 	uint32_t *bos = NULL;
+	struct timespec tv = {};
+	uint64_t submit, read, elapsed;
 	int i;
 
 	vm = xe_vm_create(fd, DRM_XE_VM_CREATE_FLAG_LR_MODE |
@@ -227,14 +236,24 @@ evict(int fd, struct drm_xe_engine_class_instance *eci, uint64_t total_alloc,
 		}
 		allocs[i] = alloc;
 
-		touch_all_pages(fd, exec_queue, allocs[i], alloc_size, stride);
+		touch_all_pages(fd, exec_queue, allocs[i], alloc_size, stride,
+				&tv, &submit);
 	}
 
 	if (barrier)
 		pthread_barrier_wait(barrier);
 
 	for (i = 0; i < num_allocs; ++i) {
+		if (flags & BENCHMARK)
+			read = igt_nsec_elapsed(&tv);
 		check_all_pages(allocs[i], alloc_size, stride);
+		if (flags & BENCHMARK) {
+			elapsed = igt_nsec_elapsed(&tv);
+			printf("Execution took %.3fms (submit %.1fus, read %.1fus, total %.1fus, read_total %.1fus)\n",
+			       1e-6 * elapsed, 1e-3 * submit, 1e-3 * read,
+			       1e-3 * (elapsed - submit),
+			       1e-3 * (elapsed - read));
+		}
 		if (bos && bos[i]) {
 			munmap(allocs[i], alloc_size);
 			gem_close(fd, bos[i]);
@@ -1262,6 +1281,12 @@ igt_main
 			break;
 		}
 
+	igt_subtest_f("fault-benchmark")
+		xe_for_each_engine(fd, hwe) {
+			evict(fd, hwe, SZ_64M, SZ_64M, SZ_4K, NULL, BENCHMARK);
+			break;
+		}
+
 	for (const struct section *s = esections; s->name; s++) {
 		igt_subtest_f("evict-%s", s->name)
 			xe_for_each_engine(fd, hwe) {
-- 
2.34.1


  reply	other threads:[~2024-06-20  3:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20  3:50 [PATCH 1/2] tests/xe: Add system_allocator test Matthew Brost
2024-06-20  3:50 ` Matthew Brost [this message]
2024-06-20  4:01 ` ✗ Fi.CI.BUILD: failure for series starting with [1/2] " Patchwork
2024-06-20  4:03 ` ✗ GitLab.Pipeline: warning " Patchwork

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=20240620035057.3609916-2-matthew.brost@intel.com \
    --to=matthew.brost@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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