Skip to contentSkip to conversation

lib/i915: Add helper for copying engine maps from one context to another

PATCH Superseded Tvrtko Ursulin 2 participants 8 messages Jan 24, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/i915: Add helper for copying engine maps from one context to another

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>
---
 lib/i915/gem_context.c | 30 ++++++++++++++++++++++++++++++
 lib/i915/gem_context.h |  2 ++
 2 files changed, 32 insertions(+)
lib/i915/gem_context.c +30 -0
index 0b6a554dfe27..41957b66ca52 100644
@@ -462,3 +462,33 @@ bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine)
 
 	return __gem_execbuf(fd, &execbuf) == -ENOENT;
 }
+
+/**
+ * gem_context_copy_engines:
+ * @src_fd: open i915 drm file descriptor where @src context belongs to
+ * @src: source engine map context id
+ * @dst_fd: open i915 drm file descriptor where @dst context belongs to
+ * @dst: destination engine map context id
+ *
+ * Special purpose wrapper for copying engine map from one context to another.
+ *
+ * In can be called regardless of whether the kernel supports context engine
+ * maps and is a no-op if not supported.
+ */
+void
+gem_context_copy_engines(int src_fd, uint32_t src, int dst_fd, uint32_t dst)
+{
+	I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, I915_EXEC_RING_MASK + 1);
+	struct drm_i915_gem_context_param param = {
+		.param = I915_CONTEXT_PARAM_ENGINES,
+		.ctx_id = src,
+		.size = sizeof(engines),
+		.value = to_user_pointer(&engines),
+	};
+
+	if (__gem_context_get_param(src_fd, &param) || !param.size)
+		return;
+
+	param.ctx_id = dst;
+	gem_context_set_param(dst_fd, &param);
+}
lib/i915/gem_context.h +2 -0
index cf2ba33fee8f..15e5db281b79 100644
@@ -42,6 +42,8 @@ uint32_t gem_context_clone(int i915,
 			   uint32_t src, unsigned int share,
 			   unsigned int flags);
 uint32_t gem_context_clone_with_engines(int i915, uint32_t src);
+void gem_context_copy_engines(int src_fd, uint32_t src,
+			      int dst_fd, uint32_t dst);
 
 uint32_t gem_queue_create(int i915);
 uint32_t gem_queue_clone_with_engines(int i915, uint32_t src);
Signature · 6 lines
2.20.1

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
#1 lore raw

PATCH 2/2 tests/i915/gem_exec_parallel:Set engine map to default context

From: Sreedhar Telukuntla <[email protected]>

Set the potential engine map of the parent client's default context to the newly created DRM client's default context. Without doing so there is a mismatch between the intended and actual engine used by the *-fds subtests.

v2: Fix FDS flags check

Tvrtko:
v3: Use new helper gem_context_copy_engines.

---
 tests/i915/gem_exec_parallel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/i915/gem_exec_parallel.c +4 -2
index cfbe78070873..0d4d6c6283e0 100644
@@ -83,10 +83,12 @@ static void *thread(void *data)
 		pthread_cond_wait(t->cond, t->mutex);
 	pthread_mutex_unlock(t->mutex);
 
-	if (t->flags & FDS)
+	if (t->flags & FDS) {
 		fd = drm_open_driver(DRIVER_INTEL);
-	else
+		gem_context_copy_engines(t->fd, 0, fd, 0);
+	} else {
 		fd = t->fd;
+	}
 
 	i = 0;
 	batch[i] = MI_STORE_DWORD_IMM | (t->gen < 6 ? 1 << 22 : 0);
Signature · 6 lines
2.20.1

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Reviewed-by on v1 2/2
#2 lore raw

Re: [igt-dev] [PATCH i-g-t 2/2] tests/i915/gem_exec_parallel:Set engine map to default context

Quoting Tvrtko Ursulin (2020-01-24 12:17:59)

Quoted 23 lines

From: Sreedhar Telukuntla <[email protected]>

Set the potential engine map of the parent client's default context to the newly created DRM client's default context. Without doing so there is a mismatch between the intended and actual engine used by the *-fds subtests.

v2: Fix FDS flags check

Tvrtko:
v3: Use new helper gem_context_copy_engines.

---
 tests/i915/gem_exec_parallel.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tests/i915/gem_exec_parallel.c +0 -0
index cfbe78070873..0d4d6c6283e0 100644

tests/i915/gem_exec_parallel.c static void *thread(void *data) · line 88

Quoted 8 lines
tests/i915/gem_exec_parallel.c +2 -2
@@ -83,10 +83,12 @@ static void *thread(void *data)
                pthread_cond_wait(t->cond, t->mutex);
        pthread_mutex_unlock(t->mutex);
 
-       if (t->flags & FDS)
+       if (t->flags & FDS) {
                fd = drm_open_driver(DRIVER_INTEL);
-       else
+               gem_context_copy_engines(t->fd, 0, fd, 0);

Makes sense,

-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#3 lore raw
In reply to Tvrtko Ursulin

Quoting Tvrtko Ursulin (2020-01-24 12:17:58)

Quoted 39 lines

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>
---
 lib/i915/gem_context.c | 30 ++++++++++++++++++++++++++++++
 lib/i915/gem_context.h |  2 ++
 2 files changed, 32 insertions(+)
lib/i915/gem_context.c +19 -0
index 0b6a554dfe27..41957b66ca52 100644
@@ -462,3 +462,33 @@ bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine)
 
        return __gem_execbuf(fd, &execbuf) == -ENOENT;
 }
+
+/**
+ * gem_context_copy_engines:
+ * @src_fd: open i915 drm file descriptor where @src context belongs to
+ * @src: source engine map context id
+ * @dst_fd: open i915 drm file descriptor where @dst context belongs to
+ * @dst: destination engine map context id
+ *
+ * Special purpose wrapper for copying engine map from one context to another.
+ *
+ * In can be called regardless of whether the kernel supports context engine
+ * maps and is a no-op if not supported.
+ */
+void
+gem_context_copy_engines(int src_fd, uint32_t src, int dst_fd, uint32_t dst)
+{
+       I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, I915_EXEC_RING_MASK + 1);
+       struct drm_i915_gem_context_param param = {
+               .param = I915_CONTEXT_PARAM_ENGINES,

lib/i915/gem_context.c bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine) · line 493

Quoted 10 lines
lib/i915/gem_context.c +10 -0
+               .ctx_id = src,
+               .size = sizeof(engines),
+               .value = to_user_pointer(&engines),
+       };
+
+       if (__gem_context_get_param(src_fd, &param) || !param.size)
+               return;
+
+       param.ctx_id = dst;
+       gem_context_set_param(dst_fd, &param);

You don't want to copy across the use-default set? You presume dst is already using defaults?
-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#4 lore raw
Quoted 45 lines · Chris Wilson

Quoting Tvrtko Ursulin (2020-01-24 12:17:58)

Quoted 44 lines

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>
---
  lib/i915/gem_context.c | 30 ++++++++++++++++++++++++++++++
  lib/i915/gem_context.h |  2 ++
  2 files changed, 32 insertions(+)
lib/i915/gem_context.c +24 -0
index 0b6a554dfe27..41957b66ca52 100644
@@ -462,3 +462,33 @@ bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine)
 
         return __gem_execbuf(fd, &execbuf) == -ENOENT;
  }
+
+/**
+ * gem_context_copy_engines:
+ * @src_fd: open i915 drm file descriptor where @src context belongs to
+ * @src: source engine map context id
+ * @dst_fd: open i915 drm file descriptor where @dst context belongs to
+ * @dst: destination engine map context id
+ *
+ * Special purpose wrapper for copying engine map from one context to another.
+ *
+ * In can be called regardless of whether the kernel supports context engine
+ * maps and is a no-op if not supported.
+ */
+void
+gem_context_copy_engines(int src_fd, uint32_t src, int dst_fd, uint32_t dst)
+{
+       I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, I915_EXEC_RING_MASK + 1);
+       struct drm_i915_gem_context_param param = {
+               .param = I915_CONTEXT_PARAM_ENGINES,
+               .ctx_id = src,
+               .size = sizeof(engines),
+               .value = to_user_pointer(&engines),
+       };
+
Quoted 8 lines

lib/i915/gem_context.c bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine) · line 493

Quoted 5 lines
lib/i915/gem_context.c +5 -0
+       if (__gem_context_get_param(src_fd, &param) || !param.size)
+               return;
+
+       param.ctx_id = dst;
+       gem_context_set_param(dst_fd, &param);

You don't want to copy across the use-default set? You presume dst is already using defaults?

Hm hm.. not sure. I guess it would be most in-line with what the helper say on the tin to copy as is. I'll respin.

Regards,

Tvrtko
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

Reviewed-by
#5 lore raw

Quoting Tvrtko Ursulin (2020-01-24 12:26:31)

Quoted 56 lines · Chris Wilson
Quoted 45 lines

Quoting Tvrtko Ursulin (2020-01-24 12:17:58)

Quoted 44 lines

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>
---
  lib/i915/gem_context.c | 30 ++++++++++++++++++++++++++++++
  lib/i915/gem_context.h |  2 ++
  2 files changed, 32 insertions(+)
lib/i915/gem_context.c +24 -0
index 0b6a554dfe27..41957b66ca52 100644
@@ -462,3 +462,33 @@ bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine)
 
         return __gem_execbuf(fd, &execbuf) == -ENOENT;
  }
+
+/**
+ * gem_context_copy_engines:
+ * @src_fd: open i915 drm file descriptor where @src context belongs to
+ * @src: source engine map context id
+ * @dst_fd: open i915 drm file descriptor where @dst context belongs to
+ * @dst: destination engine map context id
+ *
+ * Special purpose wrapper for copying engine map from one context to another.
+ *
+ * In can be called regardless of whether the kernel supports context engine
+ * maps and is a no-op if not supported.
+ */
+void
+gem_context_copy_engines(int src_fd, uint32_t src, int dst_fd, uint32_t dst)
+{
+       I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, I915_EXEC_RING_MASK + 1);
+       struct drm_i915_gem_context_param param = {
+               .param = I915_CONTEXT_PARAM_ENGINES,
+               .ctx_id = src,
+               .size = sizeof(engines),
+               .value = to_user_pointer(&engines),
+       };
+
Quoted 8 lines

lib/i915/gem_context.c bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine) · line 493

Quoted 5 lines
lib/i915/gem_context.c +5 -0
+       if (__gem_context_get_param(src_fd, &param) || !param.size)
+               return;
+
+       param.ctx_id = dst;
+       gem_context_set_param(dst_fd, &param);

You don't want to copy across the use-default set? You presume dst is already using defaults?

Quoted 2 lines

Hm hm.. not sure. I guess it would be most in-line with what the helper say on the tin to copy as is. I'll respin.

In which case, a preemptive

-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev

#6 lore raw

PATCH v2 1/2 lib/i915: Add helper for copying engine maps from one context to another

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

v2:
* Copy over even if src is unset. (Chris)

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>
---
 lib/i915/gem_context.c | 30 ++++++++++++++++++++++++++++++
 lib/i915/gem_context.h |  2 ++
 2 files changed, 32 insertions(+)
lib/i915/gem_context.c +30 -0
index 0b6a554dfe27..50dfee3d1030 100644
@@ -462,3 +462,33 @@ bool gem_context_has_engine(int fd, uint32_t ctx, uint64_t engine)
 
 	return __gem_execbuf(fd, &execbuf) == -ENOENT;
 }
+
+/**
+ * gem_context_copy_engines:
+ * @src_fd: open i915 drm file descriptor where @src context belongs to
+ * @src: source engine map context id
+ * @dst_fd: open i915 drm file descriptor where @dst context belongs to
+ * @dst: destination engine map context id
+ *
+ * Special purpose helper for copying engine map from one context to another.
+ *
+ * In can be called regardless of whether the kernel supports context engine
+ * maps and is a no-op if not supported.
+ */
+void
+gem_context_copy_engines(int src_fd, uint32_t src, int dst_fd, uint32_t dst)
+{
+	I915_DEFINE_CONTEXT_PARAM_ENGINES(engines, I915_EXEC_RING_MASK + 1);
+	struct drm_i915_gem_context_param param = {
+		.param = I915_CONTEXT_PARAM_ENGINES,
+		.ctx_id = src,
+		.size = sizeof(engines),
+		.value = to_user_pointer(&engines),
+	};
+
+	if (__gem_context_get_param(src_fd, &param))
+		return;
+
+	param.ctx_id = dst;
+	gem_context_set_param(dst_fd, &param);
+}
lib/i915/gem_context.h +2 -0
index cf2ba33fee8f..15e5db281b79 100644
@@ -42,6 +42,8 @@ uint32_t gem_context_clone(int i915,
 			   uint32_t src, unsigned int share,
 			   unsigned int flags);
 uint32_t gem_context_clone_with_engines(int i915, uint32_t src);
+void gem_context_copy_engines(int src_fd, uint32_t src,
+			      int dst_fd, uint32_t dst);
 
 uint32_t gem_queue_create(int i915);
 uint32_t gem_queue_clone_with_engines(int i915, uint32_t src);
Signature · 6 lines
2.20.1

_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev
Reviewed-by on v2 1/2
#7 lore raw

Quoting Tvrtko Ursulin (2020-01-24 12:28:33)

Quoted 10 lines

From: Tvrtko Ursulin <[email protected]>

We also need to support copying across file descriptors.

v2:
* Copy over even if src is unset. (Chris)

Cc Chris Wilson <[email protected]>
Cc Sreedhar Telukuntla <[email protected]>

-Chris
_______________________________________________
igt-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/igt-dev