Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Lucas De Marchi <lucas.demarchi@intel.com>
Subject: [PATCH i-g-t 2/2] lib/xe: Abstract virtual/parallel setup
Date: Wed, 14 Aug 2024 10:50:13 -0700	[thread overview]
Message-ID: <20240814175013.3679997-2-lucas.demarchi@intel.com> (raw)
In-Reply-To: <20240814175013.3679997-1-lucas.demarchi@intel.com>

Add 2 new functions, xe_gt_count_engines_by_class and
xe_gt_fill_engines_by_class, that can be user as helpers to setup
parallel/virtual exec queue. All the tests were basically looping
and filtering engines that matched gt and class.

Place these new functions in xe_util.c as currently we lack a better
placement. xe_query.c and xe_gt.c could probably be other candidates,
but they all mix all kind of namespaces too.

Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
---
 lib/xe/xe_util.c               | 47 ++++++++++++++++++++++++++++++++++
 lib/xe/xe_util.h               |  7 +++++
 tests/intel/xe_exec_balancer.c | 31 +++++-----------------
 tests/intel/xe_exec_reset.c    | 11 +++-----
 tests/intel/xe_exec_threads.c  | 30 +++++-----------------
 5 files changed, 70 insertions(+), 56 deletions(-)

diff --git a/lib/xe/xe_util.c b/lib/xe/xe_util.c
index 050162b5e..9482819c2 100644
--- a/lib/xe/xe_util.c
+++ b/lib/xe/xe_util.c
@@ -255,3 +255,50 @@ bool xe_is_gt_in_c6(int fd, int gt)
 
 	return strcmp(gt_c_state, "gt-c6") == 0;
 }
+
+/**
+ * xe_gt_fill_engines_by_class:
+ * @fd: pointer to xe drm fd
+ * @gt: gt number
+ * @class: engine class to use to filter engines
+ * @eci: output argument to copy engines to
+ *
+ * Fill out @drm_xe_engine_class_instance with all the engines in @gt that have
+ * a certain @class.
+ *
+ * Return: number of engines that match the gt and clas
+ */
+int xe_gt_fill_engines_by_class(int fd, int gt, int class,
+				struct drm_xe_engine_class_instance eci[static XE_MAX_ENGINE_INSTANCE])
+{
+	struct drm_xe_engine_class_instance *hwe;
+	int n = 0;
+
+	xe_for_each_engine(fd, hwe)
+		if (hwe->engine_class == class && hwe->gt_id == gt)
+			eci[n++] = *hwe;
+
+	return n;
+}
+
+/**
+ * xe_gt_count_engines_by_class:
+ * @fd: pointer to xe drm fd
+ * @gt: gt number
+ * @class: engine class to use to filter engines
+ *
+ * Count number of engines in @gt that have a certain @class.
+ *
+ * Return: number of engines that match the gt and clas
+ */
+int xe_gt_count_engines_by_class(int fd, int gt, int class)
+{
+	struct drm_xe_engine_class_instance *hwe;
+	int n = 0;
+
+	xe_for_each_engine(fd, hwe)
+		if (hwe->engine_class == class && hwe->gt_id == gt)
+			n++;
+
+	return n;
+}
diff --git a/lib/xe/xe_util.h b/lib/xe/xe_util.h
index 6480ea01a..b9fbfc5cd 100644
--- a/lib/xe/xe_util.h
+++ b/lib/xe/xe_util.h
@@ -12,6 +12,8 @@
 #include <stdint.h>
 #include <xe_drm.h>
 
+#include "xe_query.h"
+
 #define XE_IS_SYSMEM_MEMORY_REGION(fd, region) \
 	(xe_region_class(fd, region) == DRM_XE_MEM_REGION_CLASS_SYSMEM)
 #define XE_IS_VRAM_MEMORY_REGION(fd, region) \
@@ -47,4 +49,9 @@ void xe_bind_unbind_async(int fd, uint32_t vm, uint32_t bind_engine,
 
 bool xe_is_gt_in_c6(int fd, int gt);
 
+int xe_gt_fill_engines_by_class(int fd, int gt, int class,
+				struct drm_xe_engine_class_instance eci[static XE_MAX_ENGINE_INSTANCE]);
+int xe_gt_count_engines_by_class(int fd, int gt, int class);
+
+
 #endif /* XE_UTIL_H */
diff --git a/tests/intel/xe_exec_balancer.c b/tests/intel/xe_exec_balancer.c
index 53ea245a0..36dc56707 100644
--- a/tests/intel/xe_exec_balancer.c
+++ b/tests/intel/xe_exec_balancer.c
@@ -22,6 +22,7 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 #include "xe/xe_spin.h"
+#include "xe/xe_util.h"
 #include <string.h>
 
 /**
@@ -52,16 +53,10 @@ static void test_all_active(int fd, int gt, int class)
 		struct xe_spin spin;
 	} *data;
 	struct xe_spin_opts spin_opts = { .preempt = false };
-	struct drm_xe_engine_class_instance *hwe;
 	struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
-	int i, num_placements = 0;
+	int i, num_placements;
 
-	xe_for_each_engine(fd, hwe) {
-		if (hwe->engine_class != class || hwe->gt_id != gt)
-			continue;
-
-		eci[num_placements++] = *hwe;
-	}
+	num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
 	if (num_placements < 2)
 		return;
 
@@ -184,18 +179,12 @@ test_exec(int fd, int gt, int class, int n_exec_queues, int n_execs,
 		uint64_t pad;
 		uint32_t data;
 	} *data;
-	struct drm_xe_engine_class_instance *hwe;
 	struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
-	int i, j, b, num_placements = 0;
+	int i, j, b, num_placements;
 
 	igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
 
-	xe_for_each_engine(fd, hwe) {
-		if (hwe->engine_class != class || hwe->gt_id != gt)
-			continue;
-
-		eci[num_placements++] = *hwe;
-	}
+	num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
 	if (num_placements < 2)
 		return;
 
@@ -403,19 +392,13 @@ test_cm(int fd, int gt, int class, int n_exec_queues, int n_execs,
 		uint64_t exec_sync;
 		uint32_t data;
 	} *data;
-	struct drm_xe_engine_class_instance *hwe;
 	struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
-	int i, j, b, num_placements = 0;
+	int i, j, b, num_placements;
 	int map_fd = -1;
 
 	igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
 
-	xe_for_each_engine(fd, hwe) {
-		if (hwe->engine_class != class || hwe->gt_id != gt)
-			continue;
-
-		eci[num_placements++] = *hwe;
-	}
+	num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
 	if (num_placements < 2)
 		return;
 
diff --git a/tests/intel/xe_exec_reset.c b/tests/intel/xe_exec_reset.c
index bcda78609..efb7f9e89 100644
--- a/tests/intel/xe_exec_reset.c
+++ b/tests/intel/xe_exec_reset.c
@@ -20,6 +20,7 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 #include "xe/xe_spin.h"
+#include "xe/xe_util.h"
 #include <string.h>
 
 #define SYNC_OBJ_SIGNALED	(0x1 << 0)
@@ -162,21 +163,15 @@ test_balancer(int fd, int gt, int class, int n_exec_queues, int n_execs,
 		uint32_t data;
 	} *data;
 	struct xe_spin_opts spin_opts = { .preempt = false };
-	struct drm_xe_engine_class_instance *hwe;
 	struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
-	int i, j, b, num_placements = 0, bad_batches = 1;
+	int i, j, b, num_placements, bad_batches = 1;
 
 	igt_assert_lte(n_exec_queues, MAX_N_EXECQUEUES);
 
 	if (flags & CLOSE_FD)
 		fd = drm_open_driver(DRIVER_XE);
 
-	xe_for_each_engine(fd, hwe) {
-		if (hwe->engine_class != class || hwe->gt_id != gt)
-			continue;
-
-		eci[num_placements++] = *hwe;
-	}
+	num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
 	if (num_placements < 2)
 		return;
 
diff --git a/tests/intel/xe_exec_threads.c b/tests/intel/xe_exec_threads.c
index 06452862e..6fdafdff5 100644
--- a/tests/intel/xe_exec_threads.c
+++ b/tests/intel/xe_exec_threads.c
@@ -22,6 +22,7 @@
 #include "xe/xe_ioctl.h"
 #include "xe/xe_query.h"
 #include "xe/xe_spin.h"
+#include "xe/xe_util.h"
 #include <string.h>
 
 #define MAX_N_EXEC_QUEUES	16
@@ -64,9 +65,8 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 		uint64_t pad;
 		uint32_t data;
 	} *data;
-	struct drm_xe_engine_class_instance *hwe;
 	struct drm_xe_engine_class_instance eci[XE_MAX_ENGINE_INSTANCE];
-	int i, j, b, num_placements = 0;
+	int i, j, b, num_placements;
 	bool owns_vm = false, owns_fd = false;
 
 	igt_assert_lte(n_exec_queues, MAX_N_EXEC_QUEUES);
@@ -81,12 +81,7 @@ test_balancer(int fd, int gt, uint32_t vm, uint64_t addr, uint64_t userptr,
 		owns_vm = true;
 	}
 
-	xe_for_each_engine(fd, hwe) {
-		if (hwe->engine_class != class || hwe->gt_id != gt)
-			continue;
-
-		eci[num_placements++] = *hwe;
-	}
+	num_placements = xe_gt_fill_engines_by_class(fd, gt, class, eci);
 	igt_assert_lt(1, num_placements);
 
 	bo_size = sizeof(*data) * n_execs;
@@ -963,14 +958,7 @@ static void threads(int fd, int flags)
 	if (flags & BALANCER) {
 		xe_for_each_gt(fd, gt)
 			xe_for_each_engine_class(class) {
-				int num_placements = 0;
-
-				xe_for_each_engine(fd, hwe) {
-					if (hwe->engine_class != class ||
-					    hwe->gt_id != gt)
-						continue;
-					++num_placements;
-				}
+				int num_placements = xe_gt_count_engines_by_class(fd, gt, class);
 
 				if (num_placements > 1)
 					n_engines += 2;
@@ -1021,16 +1009,10 @@ static void threads(int fd, int flags)
 	if (flags & BALANCER) {
 		xe_for_each_gt(fd, gt)
 			xe_for_each_engine_class(class) {
-				int num_placements = 0;
+				int num_placements;
 				int *data_flags = (int[]){ VIRTUAL, PARALLEL, -1 };
 
-				xe_for_each_engine(fd, hwe) {
-					if (hwe->engine_class != class ||
-					    hwe->gt_id != gt)
-						continue;
-					++num_placements;
-				}
-
+				num_placements = xe_gt_count_engines_by_class(fd, gt, class);
 				if (num_placements <= 1)
 					continue;
 
-- 
2.43.0


  reply	other threads:[~2024-08-14 17:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-14 17:50 [PATCH i-g-t 1/2] lib/xe: Add XE_MAX_ENGINE_INSTANCE Lucas De Marchi
2024-08-14 17:50 ` Lucas De Marchi [this message]
2024-08-16 18:40   ` [PATCH i-g-t 2/2] lib/xe: Abstract virtual/parallel setup Matthew Brost
2024-08-14 19:10 ` ✓ CI.xeBAT: success for series starting with [i-g-t,1/2] lib/xe: Add XE_MAX_ENGINE_INSTANCE Patchwork
2024-08-14 19:22 ` ✓ Fi.CI.BAT: " Patchwork
2024-08-15  2:42 ` ✗ CI.xeFULL: failure " Patchwork
2024-08-15 20:50 ` ✗ Fi.CI.IGT: " Patchwork
2024-08-16 18:38 ` [PATCH i-g-t 1/2] " Matthew Brost
2024-08-16 19:59 ` Lucas De Marchi

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=20240814175013.3679997-2-lucas.demarchi@intel.com \
    --to=lucas.demarchi@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=umesh.nerlige.ramappa@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