Skip to contentSkip to conversation

lib/xe/xe_spin: Integrate igt_spin_new with Xe.

PATCH In review [email protected] 4 participants 5 messages Apr 26, 2023 – Apr 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/xe/xe_spin: Integrate igt_spin_new with Xe.

From: Sai Gowtham Ch <[email protected]>

Extending the spin_create implementation and allocator handle support in xe, where it submits dummy work loads to engine. This Implementation is wrapped around vm_bind and unbind as we are supposed to do it manually for xe.

Cc Zbigniew Kempczyński <[email protected]>
---
 lib/xe/xe_spin.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/xe/xe_spin.h | 21 +++++++++++++--
 2 files changed, 86 insertions(+), 2 deletions(-)
lib/xe/xe_spin.c +67 -0
index 856d0ba2..503d440e 100644
@@ -82,6 +82,73 @@ void xe_spin_end(struct xe_spin *spin)
 	spin->end = 0;
 }
 
+static xe_spin_t *
+xe_spin_create(int fd, struct xe_spin_factory *opt)
+{
+	struct drm_xe_engine_class_instance *eci;
+	size_t bo_size = xe_get_default_alignment(fd);
+	uint32_t vm, bo, engine, syncobj;
+	uint64_t ahnd = opt->ahnd, addr;
+	struct xe_spin *spin;
+	struct drm_xe_sync sync = {
+		.flags = DRM_XE_SYNC_SYNCOBJ | DRM_XE_SYNC_SIGNAL,
+	};
+	struct drm_xe_exec exec = {
+		.num_batch_buffer = 1,
+		.num_syncs = 1,
+		.syncs = to_user_pointer(&sync),
+	};
+
+	spin = calloc(1, sizeof(struct xe_spin));
+	igt_assert(spin);
+
+	vm = xe_vm_create(fd, 0, 0);
+	bo = xe_bo_create(fd, eci->gt_id, vm, bo_size);
+	spin = xe_bo_map(fd, bo, 0x1000);
+	engine = xe_engine_create(fd, vm, eci, 0);
+	syncobj = syncobj_create(fd, 0);
+
+	if (ahnd)
+		addr = intel_allocator_alloc_with_strategy(ahnd, bo, bo_size, 0, ALLOC_STRATEGY_LOW_TO_HIGH);
+
+	xe_vm_bind_sync(fd, vm, bo, 0, addr, bo_size);
+
+	xe_spin_init(spin, addr, true);
+	exec.engine_id = engine;
+	exec.address = addr;
+	sync.handle = syncobj;
+	igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_EXEC, &exec), 0);
+
+	opt->bo = bo;
+	opt->vm = vm;
+	opt->engine = engine;
+	opt->spin = spin;
+	opt->syncobj = syncobj;
+
+	return opt->spin;
+
+}
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt)
+{
+	return xe_spin_create(fd, opt);
+}
+
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt)
+{
+	igt_assert(syncobj_wait(fd, &opt->syncobj, 1, INT64_MAX, 0,
+				NULL));
+}
+
+void xe_spin_free(int fd, struct xe_spin_factory *opt)
+{
+	xe_spin_end(opt->spin);
+	xe_engine_destroy(fd, opt->engine);
+	xe_vm_destroy(fd, opt->vm);
+	gem_close(fd, opt->bo);
+}
+
 void xe_cork_init(int fd, struct drm_xe_engine_class_instance *hwe,
 		  struct xe_cork *cork)
 {
lib/xe/xe_spin.h +19 -2
index 73f9a026..124fdebe 100644
@@ -15,17 +15,34 @@
 #include "xe_query.h"
 
 /* Mapped GPU object */
-struct xe_spin {
+struct  xe_spin_factory {
+	uint64_t ahnd;
+	uint32_t vm;
+	uint32_t bo;
+	uint32_t engine;
+	uint32_t syncobj;
+	struct xe_spin *spin;
+};
+
+typedef struct xe_spin {
 	uint32_t batch[16];
 	uint64_t pad;
 	uint32_t start;
 	uint32_t end;
-};
+} xe_spin_t;
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt);
+
+#define xe_spin_new(fd, ...) \
+	__xe_spin_factory(fd, &((xe_spin_factory *opt){__VA__ARGS}))
 
 void xe_spin_init(struct xe_spin *spin, uint64_t addr, bool preempt);
 bool xe_spin_started(struct xe_spin *spin);
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt);
 void xe_spin_wait_started(struct xe_spin *spin);
 void xe_spin_end(struct xe_spin *spin);
+void xe_spin_free(int fd, struct xe_spin_factory *opt);
 
 struct xe_cork {
 	struct xe_spin *spin;
Signature · 1 line
2.39.1
#1 lore raw

[igt-dev] ✗ Fi.CI.BAT: failure for lib/xe/xe_spin: Integrate igt_spin_new with Xe. (rev2)

== Series Details ==

== Series Details ==

Series: lib/xe/xe_spin: Integrate igt_spin_new with Xe. (rev2)
URL : https://patchwork.freedesktop.org/series/116880/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_13064 -> IGTPW_8869
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with IGTPW_8869 absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in IGTPW_8869, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/index.html

Participating hosts (41 -> 39)
------------------------------

Missing (2): fi-kbl-soraka fi-snb-2520m

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in IGTPW_8869:

### IGT changes ###

#### Possible regressions ####

* igt@kms_flip@basic-flip-vs-modeset@c-dp1:
- bat-adlp-9: [PASS][1] -> [FAIL][2] +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-adlp-9/igt@kms_flip@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-adlp-9/igt@kms_flip@[email protected]

* igt@kms_pipe_crc_basic@nonblocking-crc:
- bat-adlp-9: NOTRUN -> [INCOMPLETE][3]
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-adlp-9/igt@[email protected]

#### Suppressed ####

The following results come from untrusted machines, tests, or statuses. They do not affect the overall result.

* igt@i915_selftest@live@slpc:
- {bat-mtlp-8}: NOTRUN -> [FAIL][4] +2 similar issues
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-mtlp-8/igt@i915_selftest@[email protected]

Known issues
------------

Here are the changes found in IGTPW_8869 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@hangcheck:
- bat-dg2-11: [PASS][5] -> [ABORT][6] ([i915#7913])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-dg2-11/igt@i915_selftest@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-dg2-11/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@reset:
- bat-rpls-1: [PASS][7] -> [ABORT][8] ([i915#8384])
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-rpls-1/igt@i915_selftest@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rpls-1/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@slpc:
- bat-rpls-2: NOTRUN -> [FAIL][9] ([i915#6997] / [i915#7913])
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rpls-2/igt@i915_selftest@[email protected]

* igt@kms_chamelium_hpd@common-hpd-after-suspend:
- bat-rpls-2: NOTRUN -> [SKIP][10] ([i915#7828])
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rpls-2/igt@[email protected]

* igt@kms_flip@basic-flip-vs-modeset@b-dp1:
- bat-adlp-9: [PASS][11] -> [FAIL][12] ([i915#4190])
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-adlp-9/igt@kms_flip@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-adlp-9/igt@kms_flip@[email protected]

* igt@kms_pipe_crc_basic@nonblocking-crc-frame-sequence:
- bat-adlp-9: NOTRUN -> [SKIP][13] ([i915#3546])
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-adlp-9/igt@[email protected]

* igt@kms_pipe_crc_basic@suspend-read-crc:
- bat-rpls-2: NOTRUN -> [SKIP][14] ([i915#1845])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rpls-2/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@requests:
- {bat-mtlp-8}: [ABORT][15] ([i915#7920]) -> [PASS][16]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-mtlp-8/igt@i915_selftest@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-mtlp-8/igt@i915_selftest@[email protected]
- bat-rpls-2: [ABORT][17] ([i915#7913]) -> [PASS][18]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-rpls-2/igt@i915_selftest@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rpls-2/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@slpc:
- bat-rplp-1: [FAIL][19] ([i915#7913]) -> [PASS][20]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/bat-rplp-1/igt@i915_selftest@[email protected]
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/bat-rplp-1/igt@i915_selftest@[email protected]

#### Warnings ####

* igt@i915_suspend@basic-s3-without-i915:
- fi-tgl-1115g4: [INCOMPLETE][21] ([i915#8102]) -> [INCOMPLETE][22] ([i915#7443] / [i915#8102])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13064/fi-tgl-1115g4/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/fi-tgl-1115g4/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#1845]: https://gitlab.freedesktop.org/drm/intel/issues/1845
[i915#3546]: https://gitlab.freedesktop.org/drm/intel/issues/3546
[i915#4190]: https://gitlab.freedesktop.org/drm/intel/issues/4190
[i915#6645]: https://gitlab.freedesktop.org/drm/intel/issues/6645
[i915#6997]: https://gitlab.freedesktop.org/drm/intel/issues/6997
[i915#7443]: https://gitlab.freedesktop.org/drm/intel/issues/7443
[i915#7828]: https://gitlab.freedesktop.org/drm/intel/issues/7828
[i915#7913]: https://gitlab.freedesktop.org/drm/intel/issues/7913
[i915#7920]: https://gitlab.freedesktop.org/drm/intel/issues/7920
[i915#8102]: https://gitlab.freedesktop.org/drm/intel/issues/8102
[i915#8384]: https://gitlab.freedesktop.org/drm/intel/issues/8384

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_7271 -> IGTPW_8869

CI-20190529: 20190529
CI_DRM_13064: c76d02017c7f00e9ad94af7cb800ab20ded91e68 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_8869: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/index.html
IGT_7271: d12d7eb92226e14745a80e6bdd95384913a43548 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8869/index.html

#2 lore raw
In reply to [email protected]
Quoted 38 lines · On Thu-27-04-2023 01:46 am, [email protected] wrote:

From: Sai Gowtham Ch <[email protected]>

Extending the spin_create implementation and allocator handle support in xe, where it submits dummy work loads to engine. This Implementation is wrapped around vm_bind and unbind as we are supposed to do it manually for xe.

Cc Zbigniew Kempczyński <[email protected]>
---
  lib/xe/xe_spin.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
  lib/xe/xe_spin.h | 21 +++++++++++++--
  2 files changed, 86 insertions(+), 2 deletions(-)
lib/xe/xe_spin.c +17 -0
index 856d0ba2..503d440e 100644
@@ -82,6 +82,73 @@ void xe_spin_end(struct xe_spin *spin)
  	spin->end = 0;
  }
 
+static xe_spin_t *
+xe_spin_create(int fd, struct xe_spin_factory *opt)
+{
+	struct drm_xe_engine_class_instance *eci;
+	size_t bo_size = xe_get_default_alignment(fd);
+	uint32_t vm, bo, engine, syncobj;
+	uint64_t ahnd = opt->ahnd, addr;
+	struct xe_spin *spin;
+	struct drm_xe_sync sync = {
+		.flags = DRM_XE_SYNC_SYNCOBJ | DRM_XE_SYNC_SIGNAL,
+	};
+	struct drm_xe_exec exec = {
+		.num_batch_buffer = 1,
+		.num_syncs = 1,
+		.syncs = to_user_pointer(&sync),
+	};
+

lib/xe/xe_spin.c void xe_spin_end(struct xe_spin *spin) · line 111

Quoted 10 lines
lib/xe/xe_spin.c +10 -0
+	spin = calloc(1, sizeof(struct xe_spin));
+	igt_assert(spin);
+
+	vm = xe_vm_create(fd, 0, 0);
+	bo = xe_bo_create(fd, eci->gt_id, vm, bo_size);
+	spin = xe_bo_map(fd, bo, 0x1000);
+	engine = xe_engine_create(fd, vm, eci, 0);
+	syncobj = syncobj_create(fd, 0);
+
+	if (ahnd)

In i915, ahnd is used for relocations which 0 for XE. Is this ahnd is different than i915's?

Quoted 64 lines
lib/xe/xe_spin.c +40 -0
+		addr = intel_allocator_alloc_with_strategy(ahnd, bo, bo_size, 0, ALLOC_STRATEGY_LOW_TO_HIGH);
+
+	xe_vm_bind_sync(fd, vm, bo, 0, addr, bo_size);
+
+	xe_spin_init(spin, addr, true);
+	exec.engine_id = engine;
+	exec.address = addr;
+	sync.handle = syncobj;
+	igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_EXEC, &exec), 0);
+
+	opt->bo = bo;
+	opt->vm = vm;
+	opt->engine = engine;
+	opt->spin = spin;
+	opt->syncobj = syncobj;
+
+	return opt->spin;
+
+}
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt)
+{
+	return xe_spin_create(fd, opt);
+}
+
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt)
+{
+	igt_assert(syncobj_wait(fd, &opt->syncobj, 1, INT64_MAX, 0,
+				NULL));
+}
+
+void xe_spin_free(int fd, struct xe_spin_factory *opt)
+{
+	xe_spin_end(opt->spin);
+	xe_engine_destroy(fd, opt->engine);
+	xe_vm_destroy(fd, opt->vm);
+	gem_close(fd, opt->bo);
+}
+
  void xe_cork_init(int fd, struct drm_xe_engine_class_instance *hwe,
  		  struct xe_cork *cork)
  {
lib/xe/xe_spin.h +10 -1
index 73f9a026..124fdebe 100644
@@ -15,17 +15,34 @@
  #include "xe_query.h"
 
  /* Mapped GPU object */
-struct xe_spin {
+struct  xe_spin_factory {
+	uint64_t ahnd;
+	uint32_t vm;
+	uint32_t bo;
+	uint32_t engine;
+	uint32_t syncobj;
+	struct xe_spin *spin;
+};
+
+typedef struct xe_spin {
  	uint32_t batch[16];
  	uint64_t pad;

lib/xe/xe_spin.h line 38

Quoted 10 lines
lib/xe/xe_spin.h +7 -1
  	uint32_t start;
  	uint32_t end;
-};
+} xe_spin_t;
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt);
+
+#define xe_spin_new(fd, ...) \
+	__xe_spin_factory(fd, &((xe_spin_factory *opt){__VA__ARGS}))

So from kms tests, we need to call this helper as below:

if (is_xe_device(fd))

	xe_spin_new();
else
	igt_spin_new();

I am expecting some helper as below, so that we can avoid code churn in test level:

igt_spin_new() {
	if (is_xe_device(fd))
		xe_spin_new();
	else
		i915_spin_new();
}

- Bhanu

Quoted 10 lines
lib/xe/xe_spin.h +2 -0
  void xe_spin_init(struct xe_spin *spin, uint64_t addr, bool preempt);
  bool xe_spin_started(struct xe_spin *spin);
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt);
  void xe_spin_wait_started(struct xe_spin *spin);
  void xe_spin_end(struct xe_spin *spin);
+void xe_spin_free(int fd, struct xe_spin_factory *opt);
 
  struct xe_cork {
  	struct xe_spin *spin;
#3 lore raw
Quoted 57 lines

-----Original Message-----
From: Modem, Bhanuprakash <[email protected]>
Sent: Thursday, April 27, 2023 11:10 AM
To: Ch, Sai Gowtham <[email protected]>; igt- [email protected]; Kempczynski, Zbigniew <[email protected]>
Subject: Re: [igt-dev] [PATCH i-g-t] lib/xe/xe_spin: Integrate igt_spin_new with Xe.

Quoted 5 lines · On Thu-27-04-2023 01:46 am, [email protected] wrote:

From: Sai Gowtham Ch <[email protected]>

Extending the spin_create implementation and allocator handle support in xe, where it submits dummy work loads to engine. This Implementation is wrapped around vm_bind and unbind as we are supposed to

do it manually for xe.

Quoted 5 lines
Cc Zbigniew Kempczyński <[email protected]>
---
  lib/xe/xe_spin.c | 67

++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 32 lines
  lib/xe/xe_spin.h | 21 +++++++++++++--
  2 files changed, 86 insertions(+), 2 deletions(-)
lib/xe/xe_spin.c index renamed from lib/xe/xe_spin.c +0 -0

856d0ba2..503d440e 100644

lib/xe/xe_spin.c +21 -0
@@ -82,6 +82,73 @@ void xe_spin_end(struct xe_spin *spin)
  	spin->end = 0;
  }
 
+static xe_spin_t *
+xe_spin_create(int fd, struct xe_spin_factory *opt) {
+	struct drm_xe_engine_class_instance *eci;
+	size_t bo_size = xe_get_default_alignment(fd);
+	uint32_t vm, bo, engine, syncobj;
+	uint64_t ahnd = opt->ahnd, addr;
+	struct xe_spin *spin;
+	struct drm_xe_sync sync = {
+		.flags = DRM_XE_SYNC_SYNCOBJ | DRM_XE_SYNC_SIGNAL,
+	};
+	struct drm_xe_exec exec = {
+		.num_batch_buffer = 1,
+		.num_syncs = 1,
+		.syncs = to_user_pointer(&sync),
+	};
+
+	spin = calloc(1, sizeof(struct xe_spin));
+	igt_assert(spin);
+
+	vm = xe_vm_create(fd, 0, 0);
+	bo = xe_bo_create(fd, eci->gt_id, vm, bo_size);
Quoted 8 lines

lib/xe/xe_spin.c void xe_spin_end(struct xe_spin *spin) · line 111

Quoted 5 lines
lib/xe/xe_spin.c +5 -0
+	spin = xe_bo_map(fd, bo, 0x1000);
+	engine = xe_engine_create(fd, vm, eci, 0);
+	syncobj = syncobj_create(fd, 0);
+
+	if (ahnd)

In i915, ahnd is used for relocations which 0 for XE. Is this ahnd is different than i915's?

ahnd here returns allocator handle from GGT.

Quoted 82 lines
Quoted 63 lines
lib/xe/xe_spin.c +38 -0
+		addr = intel_allocator_alloc_with_strategy(ahnd, bo, bo_size, 0,
+ALLOC_STRATEGY_LOW_TO_HIGH);
+
+	xe_vm_bind_sync(fd, vm, bo, 0, addr, bo_size);
+
+	xe_spin_init(spin, addr, true);
+	exec.engine_id = engine;
+	exec.address = addr;
+	sync.handle = syncobj;
+	igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_EXEC, &exec), 0);
+
+	opt->bo = bo;
+	opt->vm = vm;
+	opt->engine = engine;
+	opt->spin = spin;
+	opt->syncobj = syncobj;
+
+	return opt->spin;
+
+}
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt) {
+	return xe_spin_create(fd, opt);
+}
+
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt) {
+	igt_assert(syncobj_wait(fd, &opt->syncobj, 1, INT64_MAX, 0,
+				NULL));
+}
+
+void xe_spin_free(int fd, struct xe_spin_factory *opt) {
+	xe_spin_end(opt->spin);
+	xe_engine_destroy(fd, opt->engine);
+	xe_vm_destroy(fd, opt->vm);
+	gem_close(fd, opt->bo);
+}
+
  void xe_cork_init(int fd, struct drm_xe_engine_class_instance *hwe,
  		  struct xe_cork *cork)
  {
lib/xe/xe_spin.h index renamed from lib/xe/xe_spin.h +0 -0

73f9a026..124fdebe 100644

lib/xe/xe_spin.h +10 -1
@@ -15,17 +15,34 @@
  #include "xe_query.h"
 
  /* Mapped GPU object */
-struct xe_spin {
+struct  xe_spin_factory {
+	uint64_t ahnd;
+	uint32_t vm;
+	uint32_t bo;
+	uint32_t engine;
+	uint32_t syncobj;
+	struct xe_spin *spin;
+};
+
+typedef struct xe_spin {
  	uint32_t batch[16];
  	uint64_t pad;

lib/xe/xe_spin.h line 38

Quoted 10 lines
lib/xe/xe_spin.h +7 -1
  	uint32_t start;
  	uint32_t end;
-};
+} xe_spin_t;
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt);
+
+#define xe_spin_new(fd, ...) \
+	__xe_spin_factory(fd, &((xe_spin_factory *opt){__VA__ARGS}))

So from kms tests, we need to call this helper as below:

if (is_xe_device(fd))

	xe_spin_new();
else
	igt_spin_new();
Quoted 8 lines

I am expecting some helper as below, so that we can avoid code churn in test level:

igt_spin_new() {
	if (is_xe_device(fd))
		xe_spin_new();
	else
		i915_spin_new();
}

Initial Plan was that same, however it is difficult to do that as spin_create()
uses igt_spin_t to collect all necessary information about spinner, Instead adding this check from test would make sense to me.

Quoted 12 lines

- Bhanu

Quoted 10 lines
lib/xe/xe_spin.h +2 -0
  void xe_spin_init(struct xe_spin *spin, uint64_t addr, bool preempt);
  bool xe_spin_started(struct xe_spin *spin);
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt);
  void xe_spin_wait_started(struct xe_spin *spin);
  void xe_spin_end(struct xe_spin *spin);
+void xe_spin_free(int fd, struct xe_spin_factory *opt);
 
  struct xe_cork {
  	struct xe_spin *spin;
#4 lore raw
Quoted 36 lines · Sai Gowtham
Quoted 36 lines

-----Original Message-----
From: Modem, Bhanuprakash <[email protected]>
Sent: Thursday, April 27, 2023 11:10 AM
To: Ch, Sai Gowtham <[email protected]>; igt- [email protected]; Kempczynski, Zbigniew <[email protected]>
Subject: Re: [igt-dev] [PATCH i-g-t] lib/xe/xe_spin: Integrate igt_spin_new with Xe.

Quoted 5 lines · On Thu-27-04-2023 01:46 am, [email protected] wrote:

From: Sai Gowtham Ch <[email protected]>

Extending the spin_create implementation and allocator handle support in xe, where it submits dummy work loads to engine. This Implementation is wrapped around vm_bind and unbind as we are supposed to

do it manually for xe.

Quoted 5 lines
Cc Zbigniew Kempczyński <[email protected]>
---
  lib/xe/xe_spin.c | 67

++++++++++++++++++++++++++++++++++++++++++++++++

Quoted 11 lines
  lib/xe/xe_spin.h | 21 +++++++++++++--
  2 files changed, 86 insertions(+), 2 deletions(-)
lib/xe/xe_spin.c index renamed from lib/xe/xe_spin.c +0 -0

856d0ba2..503d440e 100644

lib/xe/xe_spin.c +0 -0
@@ -82,6 +82,73 @@ void xe_spin_end(struct xe_spin *spin)
  	spin->end = 0;
  }
 
Quoted 16 lines
Quoted 8 lines
Quoted 8 lines
lib/xe/xe_spin.c +8 -0
+static xe_spin_t *
+xe_spin_create(int fd, struct xe_spin_factory *opt) {
+	struct drm_xe_engine_class_instance *eci;
+	size_t bo_size = xe_get_default_alignment(fd);
+	uint32_t vm, bo, engine, syncobj;
+	uint64_t ahnd = opt->ahnd, addr;
+	struct xe_spin *spin;
+	struct drm_xe_sync sync = {
Quoted 8 lines

lib/xe/xe_spin.c void xe_spin_end(struct xe_spin *spin) · line 101

Quoted 8 lines
lib/xe/xe_spin.c +8 -0
+		.flags = DRM_XE_SYNC_SYNCOBJ | DRM_XE_SYNC_SIGNAL,
+	};
+	struct drm_xe_exec exec = {
+		.num_batch_buffer = 1,
+		.num_syncs = 1,
+		.syncs = to_user_pointer(&sync),
+	};
+

Check ahnd here.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
lib/xe/xe_spin.c +5 -0
+	spin = calloc(1, sizeof(struct xe_spin));
+	igt_assert(spin);
+
+	vm = xe_vm_create(fd, 0, 0);
+	bo = xe_bo_create(fd, eci->gt_id, vm, bo_size);
Quoted 8 lines

lib/xe/xe_spin.c void xe_spin_end(struct xe_spin *spin) · line 111

Quoted 5 lines
lib/xe/xe_spin.c +5 -0
+	spin = xe_bo_map(fd, bo, 0x1000);
+	engine = xe_engine_create(fd, vm, eci, 0);
+	syncobj = syncobj_create(fd, 0);
+
+	if (ahnd)

In i915, ahnd is used for relocations which 0 for XE. Is this ahnd is different than i915's?

Quoted 1 line

ahnd here returns allocator handle from GGT.

For xe ahnd must be != 0. So assert on the beginning and this will be fine.

Quoted 91 lines
Quoted 82 lines
Quoted 63 lines
lib/xe/xe_spin.c +38 -0
+		addr = intel_allocator_alloc_with_strategy(ahnd, bo, bo_size, 0,
+ALLOC_STRATEGY_LOW_TO_HIGH);
+
+	xe_vm_bind_sync(fd, vm, bo, 0, addr, bo_size);
+
+	xe_spin_init(spin, addr, true);
+	exec.engine_id = engine;
+	exec.address = addr;
+	sync.handle = syncobj;
+	igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_EXEC, &exec), 0);
+
+	opt->bo = bo;
+	opt->vm = vm;
+	opt->engine = engine;
+	opt->spin = spin;
+	opt->syncobj = syncobj;
+
+	return opt->spin;
+
+}
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt) {
+	return xe_spin_create(fd, opt);
+}
+
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt) {
+	igt_assert(syncobj_wait(fd, &opt->syncobj, 1, INT64_MAX, 0,
+				NULL));
+}
+
+void xe_spin_free(int fd, struct xe_spin_factory *opt) {
+	xe_spin_end(opt->spin);
+	xe_engine_destroy(fd, opt->engine);
+	xe_vm_destroy(fd, opt->vm);
+	gem_close(fd, opt->bo);
+}
+
  void xe_cork_init(int fd, struct drm_xe_engine_class_instance *hwe,
  		  struct xe_cork *cork)
  {
lib/xe/xe_spin.h index renamed from lib/xe/xe_spin.h +0 -0

73f9a026..124fdebe 100644

lib/xe/xe_spin.h +10 -1
@@ -15,17 +15,34 @@
  #include "xe_query.h"
 
  /* Mapped GPU object */
-struct xe_spin {
+struct  xe_spin_factory {
+	uint64_t ahnd;
+	uint32_t vm;
+	uint32_t bo;
+	uint32_t engine;
+	uint32_t syncobj;
+	struct xe_spin *spin;
+};
+
+typedef struct xe_spin {
  	uint32_t batch[16];
  	uint64_t pad;

lib/xe/xe_spin.h line 38

Quoted 10 lines
lib/xe/xe_spin.h +7 -1
  	uint32_t start;
  	uint32_t end;
-};
+} xe_spin_t;
+
+xe_spin_t *
+__xe_spin_factory(int fd, struct xe_spin_factory *opt);
+
+#define xe_spin_new(fd, ...) \
+	__xe_spin_factory(fd, &((xe_spin_factory *opt){__VA__ARGS}))

So from kms tests, we need to call this helper as below:

if (is_xe_device(fd))

	xe_spin_new();
else
	igt_spin_new();
Quoted 8 lines

I am expecting some helper as below, so that we can avoid code churn in test level:

igt_spin_new() {
	if (is_xe_device(fd))
		xe_spin_new();
	else
		i915_spin_new();
}
Quoted 3 lines

Initial Plan was that same, however it is difficult to do that as spin_create()
uses igt_spin_t to collect all necessary information about spinner, Instead adding this check from test would make sense to me.

Don't hesitate and also return igt_spin_t from xe spinner. Just add fields you need for xe spinner and it should work.

--
Zbigniew

Quoted 12 lines
Quoted 12 lines

- Bhanu

Quoted 10 lines
lib/xe/xe_spin.h +2 -0
  void xe_spin_init(struct xe_spin *spin, uint64_t addr, bool preempt);
  bool xe_spin_started(struct xe_spin *spin);
+void xe_spin_sync_wait(int fd, struct xe_spin_factory *opt);
  void xe_spin_wait_started(struct xe_spin *spin);
  void xe_spin_end(struct xe_spin *spin);
+void xe_spin_free(int fd, struct xe_spin_factory *opt);
 
  struct xe_cork {
  	struct xe_spin *spin;