[PATCH i-g-t 6/8] lib/xe/xe_spin: Move declarations around

Lucas De Marchi lucas.demarchi at intel.com
Sat Jan 4 07:15:46 UTC 2025


xe_spin.h has 3 abstractions:

1) the integration with igt_dummyload
2) xe_spin, the bo to be exec'ed somewhere
3) xe_cork, that resembles more the igt_spin, abstracting the fd, vm,
   bind, etc

Group them so it's easier to understand each one.

Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
 lib/xe/xe_spin.c |  2 +-
 lib/xe/xe_spin.h | 54 +++++++++++++++++++++++++++---------------------
 2 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/lib/xe/xe_spin.c b/lib/xe/xe_spin.c
index 333f8d7d8..bb6318cef 100644
--- a/lib/xe/xe_spin.c
+++ b/lib/xe/xe_spin.c
@@ -232,7 +232,7 @@ xe_spin_create(int fd, const struct igt_spin_factory *opt)
 	return spin;
 }
 
-void xe_spin_sync_wait(int fd, struct igt_spin *spin)
+static void xe_spin_sync_wait(int fd, struct igt_spin *spin)
 {
 	igt_assert(syncobj_wait(fd, &spin->syncobj, 1, INT64_MAX, 0, NULL));
 }
diff --git a/lib/xe/xe_spin.h b/lib/xe/xe_spin.h
index 01f45eaeb..7c95996c3 100644
--- a/lib/xe/xe_spin.h
+++ b/lib/xe/xe_spin.h
@@ -15,6 +15,15 @@
 #include "xe_query.h"
 #include "lib/igt_dummyload.h"
 
+/* Wrapper to integrate with igt_dummyload, aka igt_spin */
+igt_spin_t *xe_spin_create(int fd, const struct igt_spin_factory *opt);
+void xe_spin_free(int fd, struct igt_spin *spin);
+
+/*
+ * xe_spin: abstract a bo mapped in the GPU that when exec'ed will spin the
+ * engine in which it's exec'ed
+ */
+
 /**
  * struct xe_spin_opts
  * @addr: offset of spinner within vm
@@ -30,11 +39,6 @@ struct xe_spin_opts {
 	bool write_timestamp;
 };
 
-struct xe_cork_opts {
-	uint64_t ahnd;
-	bool debug;
-};
-
 /* Mapped GPU object */
 struct xe_spin {
 	uint32_t batch[128];
@@ -46,6 +50,24 @@ struct xe_spin {
 	uint32_t timestamp;
 };
 
+uint32_t xe_spin_nsec_to_ticks(int fd, int gt_id, uint64_t nsec);
+void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts);
+#define xe_spin_init_opts(fd, ...) \
+	xe_spin_init(fd, &((struct xe_spin_opts){__VA_ARGS__}))
+bool xe_spin_started(struct xe_spin *spin);
+void xe_spin_wait_started(struct xe_spin *spin);
+void xe_spin_end(struct xe_spin *spin);
+
+/*
+ * xe_cork: higher level API that simplifies exec'ing an xe_spin by taking care
+ * of vm creation, exec call, etc.
+ */
+
+struct xe_cork_opts {
+	uint64_t ahnd;
+	bool debug;
+};
+
 struct xe_cork {
 	struct xe_spin *spin;
 	int fd;
@@ -65,27 +87,13 @@ struct xe_cork {
 	uint16_t num_placements;
 };
 
-igt_spin_t *xe_spin_create(int fd, const struct igt_spin_factory *opt);
-void xe_spin_init(struct xe_spin *spin, struct xe_spin_opts *opts);
-struct xe_cork *
-xe_cork_create(int fd, struct drm_xe_engine_class_instance *hwe, uint32_t vm,
-	      uint16_t width, uint16_t num_placements, struct xe_cork_opts *opts);
-void xe_cork_destroy(int fd, struct xe_cork *ctx);
-
+struct xe_cork *xe_cork_create(int fd, struct drm_xe_engine_class_instance *hwe,
+			       uint32_t vm, uint16_t width, uint16_t num_placements,
+			       struct xe_cork_opts *opts);
 #define xe_cork_create_opts(fd, hwe, vm, width, num_placements, ...) \
 	xe_cork_create(fd, hwe, vm, width, num_placements, \
 			&((struct xe_cork_opts){__VA_ARGS__}))
-
-#define xe_spin_init_opts(fd, ...) \
-	xe_spin_init(fd, &((struct xe_spin_opts){__VA_ARGS__}))
-
-uint32_t xe_spin_nsec_to_ticks(int fd, int gt_id, uint64_t nsec);
-
-bool xe_spin_started(struct xe_spin *spin);
-void xe_spin_sync_wait(int fd, struct igt_spin *spin);
-void xe_spin_wait_started(struct xe_spin *spin);
-void xe_spin_end(struct xe_spin *spin);
-void xe_spin_free(int fd, struct igt_spin *spin);
+void xe_cork_destroy(int fd, struct xe_cork *ctx);
 void xe_cork_sync_start(int fd, struct xe_cork *ctx);
 void xe_cork_sync_end(int fd, struct xe_cork *ctx);
 
-- 
2.47.0



More information about the igt-dev mailing list