Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 17/24] i915: Add gem_ctx_clone

2019-03-26 Thread Chris Wilson
Quoting Tvrtko Ursulin (2019-03-26 15:44:35)
> 
> On 22/03/2019 09:21, Chris Wilson wrote:
> > +static void clone_vm(int i915)
> > +{
> > + struct drm_i915_gem_context_create_ext_setparam set = {
> > + { .name = I915_CONTEXT_CREATE_EXT_SETPARAM },
> > + { .param = I915_CONTEXT_PARAM_VM },
> > + };
> > + struct drm_i915_gem_context_create_ext_clone ext = {
> > + { .name = I915_CONTEXT_CREATE_EXT_CLONE },
> > + .flags = I915_CONTEXT_CLONE_VM,
> > + };
> > + struct drm_i915_gem_context_create_ext create = {
> > + .flags = I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS,
> > + .extensions = to_user_pointer(&ext),
> > + };
> > + uint32_t vm_id[2];
> > + int expected;
> > +
> > + igt_require(__gem_context_set_param(i915, &set.param) == -ENOENT);
> > +
> > + set.param.ctx_id = gem_context_create(i915);
> > + gem_context_get_param(i915, &set.param);
> > + vm_id[0] = set.param.value;
> > + gem_context_destroy(i915, set.param.ctx_id);
> 
> Do you have in the VM ioctl IGT, or the ctx get/set VM, a subtest that 
> verifies VM survives context destroy, if it was exported before that? It 
> would need one I think.
> 
> But in this particular one, what is the reason you create one VM 
> indirectly via context create which is immediately destroyed? Exactly to 
> test the above mentioned?

It was precisely that to check that we could keep a VM from an earlier
context.

But honestly it was because I had forgotten about gem_vm_create() at
that point and had to go and write another bunch of tests.

> > + set.param.ctx_id = 0;
> > +
> > + vm_id[1] = gem_vm_create(i915);

And then I was supposed to check we got similar results using explict
allocation.

> > + for (int pass = 0; pass < 2; pass++) { /* cloning default, then child 
> > */
> > + igt_debug("Cloning %d\n", ext.clone_id);
> > + igt_assert_eq(__create_ext(i915, &create), 0);
> > +
> > + set.param.ctx_id = ext.clone_id;
> > + gem_context_get_param(i915, &set.param);
> > + expected = set.param.value;
> > +
> > + set.param.ctx_id = create.ctx_id;
> > + gem_context_get_param(i915, &set.param);
> > +
> > + igt_assert_eq_u64(set.param.param, I915_CONTEXT_PARAM_VM);
> > + igt_assert_eq((int)set.param.value, expected);
> > +
> > + gem_context_destroy(i915, create.ctx_id);
> > +
> > + expected = set.param.value = vm_id[0];
> > + set.param.ctx_id = ext.clone_id;
> > + gem_context_set_param(i915, &set.param);
> > +
> > + igt_assert_eq(__create_ext(i915, &create), 0);
> > +
> > + set.param.ctx_id = create.ctx_id;
> > + gem_context_get_param(i915, &set.param);
> > +
> > + igt_assert_eq_u64(set.param.param, I915_CONTEXT_PARAM_VM);
> > + igt_assert_eq((int)set.param.value, expected);
> > +
> > + gem_context_destroy(i915, create.ctx_id);
> > + ext.clone_id = gem_context_create(i915);
> > + }
> 
> vm_id[1] is unused.

Yeah...
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 17/24] i915: Add gem_ctx_clone

2019-03-26 Thread Chris Wilson
Quoting Tvrtko Ursulin (2019-03-26 15:44:35)
> 
> On 22/03/2019 09:21, Chris Wilson wrote:
> > +static void clone_engines(int i915)
> > +{
> > + struct drm_i915_gem_context_create_ext_setparam set = {
> > + { .name = I915_CONTEXT_CREATE_EXT_SETPARAM },
> > + { .param = I915_CONTEXT_PARAM_ENGINES },
> 
> Hm I don't remember seeing the engine map test in the series to this 
> point. Where is it?

"Are we nearly there yet?" Almost.

It's hard to tell what order to put these in as I use context cloning
for the gem_ctx_engine tests as well. You could say each subtest in a
separate patch so they all flow in some well defined order, I'm just
trying to make sure things work :)
-Chris
___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

Re: [Intel-gfx] [igt-dev] [PATCH i-g-t 17/24] i915: Add gem_ctx_clone

2019-03-26 Thread Tvrtko Ursulin


On 22/03/2019 09:21, Chris Wilson wrote:

Exercise cloning contexts, an extension of merely creating one.

Signed-off-by: Chris Wilson 
---
  tests/Makefile.sources |   1 +
  tests/i915/gem_ctx_clone.c | 421 +
  tests/meson.build  |   1 +
  3 files changed, 423 insertions(+)
  create mode 100644 tests/i915/gem_ctx_clone.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 809b25612..12f4bbd75 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -21,6 +21,7 @@ TESTS_progs = \
drm_import_export \
drm_mm \
drm_read \
+   i915/gem_ctx_clone \
i915/gem_vm_create \
kms_3d \
kms_addfb_basic \
diff --git a/tests/i915/gem_ctx_clone.c b/tests/i915/gem_ctx_clone.c
new file mode 100644
index 0..7d83c6350
--- /dev/null
+++ b/tests/i915/gem_ctx_clone.c
@@ -0,0 +1,421 @@
+/*
+ * Copyright © 2019 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "igt.h"
+#include "i915/gem_vm.h"
+#include "i915_drm.h"
+
+static int __create_ext(int i915, struct drm_i915_gem_context_create_ext *arg)
+{
+   int err;
+
+   err = 0;
+   if (igt_ioctl(i915, DRM_IOCTL_I915_GEM_CONTEXT_CREATE_EXT, arg))
+   err = -errno;
+
+   errno = 0;
+   return err;
+}
+
+static bool has_ctx_clone(int i915)
+{
+   struct drm_i915_gem_context_create_ext_clone ext = {
+   { .name = I915_CONTEXT_CREATE_EXT_CLONE },
+   .clone_id = -1,
+   };
+   struct drm_i915_gem_context_create_ext create = {
+   .flags = I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS,
+   .extensions = to_user_pointer(&ext),
+   };
+   return __create_ext(i915, &create) == -ENOENT;
+}
+
+static void invalid_clone(int i915)
+{
+   struct drm_i915_gem_context_create_ext_clone ext = {
+   { .name = I915_CONTEXT_CREATE_EXT_CLONE },
+   };
+   struct drm_i915_gem_context_create_ext create = {
+   .flags = I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS,
+   .extensions = to_user_pointer(&ext),
+   };
+
+   igt_assert_eq(__create_ext(i915, &create), 0);
+   gem_context_destroy(i915, create.ctx_id);
+
+   ext.flags = -1; /* Hopefully we won't run out of flags */
+   igt_assert_eq(__create_ext(i915, &create), -EINVAL);
+   ext.flags = 0;
+
+   ext.base.next_extension = -1;
+   igt_assert_eq(__create_ext(i915, &create), -EFAULT);
+   ext.base.next_extension = to_user_pointer(&ext);
+   igt_assert_eq(__create_ext(i915, &create), -E2BIG);
+   ext.base.next_extension = 0;
+
+   ext.clone_id = -1;
+   igt_assert_eq(__create_ext(i915, &create), -ENOENT);
+   ext.clone_id = 0;
+}
+
+static void clone_flags(int i915)
+{
+   struct drm_i915_gem_context_create_ext_setparam set = {
+   { .name = I915_CONTEXT_CREATE_EXT_SETPARAM },
+   { .param = I915_CONTEXT_PARAM_RECOVERABLE },
+   };
+   struct drm_i915_gem_context_create_ext_clone ext = {
+   { .name = I915_CONTEXT_CREATE_EXT_CLONE },
+   .flags = I915_CONTEXT_CLONE_FLAGS,
+   };
+   struct drm_i915_gem_context_create_ext create = {
+   .flags = I915_CONTEXT_CREATE_FLAGS_USE_EXTENSIONS,
+   .extensions = to_user_pointer(&ext),
+   };
+   int expected;
+
+   set.param.value = 1; /* default is recoverable */
+   igt_require(__gem_context_set_param(i915, &set.param) == 0);
+
+   for (int pass = 0; pass < 2; pass++) { /* cloning default, then child */
+   igt_debug("Cloning %d\n", ext.clone_id);
+   igt_assert_eq(__create_ext(i915, &create), 0);
+
+   set.param.ctx_id = ext.clone_id;
+   gem_context_get_param(i915, &set.param);
+   expected = set.param.value;
+
+