diff mbox

[i-g-t,v3] lib/igt_gt: Allow non-default contexts to hang non-render rings

Message ID 1507757481-128840-1-git-send-email-vinay.belgaumkar@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vinay Belgaumkar Oct. 11, 2017, 9:31 p.m. UTC
This limitation does not exist in latest kernel. It was removed by this patch-

commit f7978a0c581a8a840a28306f8da43e06e7fef3bf

v2: Added commit id that removes the limitation(Chris Wilson)
V3: Generic way to find if kernel supports this instead of hardcoding gens(Chris Wilson)

Cc: Michel Thierry <michel.thierry@intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: Petri Latvala <petri.latvala@intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
---
 lib/igt_gt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

Comments

Daniele Ceraolo Spurio Oct. 11, 2017, 11:23 p.m. UTC | #1
On 11/10/17 14:31, Vinay Belgaumkar wrote:
> This limitation does not exist in latest kernel. It was removed by this patch-
> 
> commit f7978a0c581a8a840a28306f8da43e06e7fef3bf
> 
> v2: Added commit id that removes the limitation(Chris Wilson)
> V3: Generic way to find if kernel supports this instead of hardcoding gens(Chris Wilson)
> 
> Cc: Michel Thierry <michel.thierry@intel.com>
> Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
> Cc: Petri Latvala <petri.latvala@intel.com>
> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
> ---
>   lib/igt_gt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
>   1 file changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_gt.c b/lib/igt_gt.c
> index b3f3b38..183d8bb 100644
> --- a/lib/igt_gt.c
> +++ b/lib/igt_gt.c
> @@ -209,11 +209,51 @@ void igt_disallow_hang(int fd, igt_hang_t arg)
>   }
>   
>   /**
> + * has_ctx_exec:
> + * @fd: open i915 drm file descriptor
> + * @ring: execbuf ring flag
> + *
> + * This helper function checks if non default context submission is allowed
> + * on a ring.
> + *
> + * Returns:
> + * True if allowed
> + *
> + */
> +bool has_ctx_exec(int fd, unsigned ring)
> +{
> +	struct drm_i915_gem_execbuffer2 execbuf;
> +	struct drm_i915_gem_exec_object2 exec;
> +	bool supported;
> +
> +	/* silly ABI, the kernel thinks everyone who has BSD also has BSD2 */
> +	if ((ring & ~(3<<13)) == I915_EXEC_BSD) {
> +		if (ring & (3 << 13) && !gem_has_bsd2(fd))
> +			return false;
> +	}
> +
> +	memset(&exec, 0, sizeof(exec));
> +	memset(&execbuf, 0, sizeof(execbuf));
> +	execbuf.buffers_ptr = to_user_pointer(&exec);
> +	execbuf.buffer_count = 1;
> +	execbuf.flags = ring;
> +	execbuf.rsvd1 = gem_context_create(fd);
> +	/* If context submission is not allowed, this will return EINVAL
> +	 * Otherwise, this will return ENOENT on account of no gem obj
> +	 * being submitted */
> +	supported = __gem_execbuf(fd, &execbuf) == -ENOENT;
> +	gem_context_destroy(fd, execbuf.rsvd1);
> +
> +	return supported;
> +}
> +
> +/**
>    * igt_hang_ring_ctx:
>    * @fd: open i915 drm file descriptor
>    * @ctx: the contxt specifier
>    * @ring: execbuf ring flag
>    * @flags: set of flags to control execution
> + * @offset: The resultant gtt offset of the exec obj
>    *
>    * This helper function injects a hanging batch associated with @ctx into @ring.
>    * It returns a #igt_hang_t structure which must be passed to
> @@ -239,8 +279,11 @@ igt_hang_t igt_hang_ctx(int fd,
>   
>   	igt_require_hang_ring(fd, ring);
>   
> -	/* One day the kernel ABI will be fixed! */
> -	igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
> +	/* check if non-default ctx submission is allowed */
> +	if (!(has_ctx_exec(fd, ring)))
> +	{
> +		igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
> +	}
>   

Wouldn't

	igt_require(ctx == 0 || has_ctx_exec(fd, ring));

suffice here instead of the whole if block?

-Daniele

>   	param.context = ctx;
>   	param.size = 0;
>
Vinay Belgaumkar Oct. 11, 2017, 11:59 p.m. UTC | #2
On 10/11/2017 4:23 PM, Daniele Ceraolo Spurio wrote:
>
>
> On 11/10/17 14:31, Vinay Belgaumkar wrote:
>> This limitation does not exist in latest kernel. It was removed by
>> this patch-
>>
>> commit f7978a0c581a8a840a28306f8da43e06e7fef3bf
>>
>> v2: Added commit id that removes the limitation(Chris Wilson)
>> V3: Generic way to find if kernel supports this instead of hardcoding
>> gens(Chris Wilson)
>>
>> Cc: Michel Thierry <michel.thierry@intel.com>
>> Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
>> Cc: Petri Latvala <petri.latvala@intel.com>
>> Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar@intel.com>
>> ---
>>   lib/igt_gt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
>>   1 file changed, 45 insertions(+), 2 deletions(-)
>>
>> diff --git a/lib/igt_gt.c b/lib/igt_gt.c
>> index b3f3b38..183d8bb 100644
>> --- a/lib/igt_gt.c
>> +++ b/lib/igt_gt.c
>> @@ -209,11 +209,51 @@ void igt_disallow_hang(int fd, igt_hang_t arg)
>>   }
>>     /**
>> + * has_ctx_exec:
>> + * @fd: open i915 drm file descriptor
>> + * @ring: execbuf ring flag
>> + *
>> + * This helper function checks if non default context submission is
>> allowed
>> + * on a ring.
>> + *
>> + * Returns:
>> + * True if allowed
>> + *
>> + */
>> +bool has_ctx_exec(int fd, unsigned ring)
>> +{
>> +    struct drm_i915_gem_execbuffer2 execbuf;
>> +    struct drm_i915_gem_exec_object2 exec;
>> +    bool supported;
>> +
>> +    /* silly ABI, the kernel thinks everyone who has BSD also has
>> BSD2 */
>> +    if ((ring & ~(3<<13)) == I915_EXEC_BSD) {
>> +        if (ring & (3 << 13) && !gem_has_bsd2(fd))
>> +            return false;
>> +    }
>> +
>> +    memset(&exec, 0, sizeof(exec));
>> +    memset(&execbuf, 0, sizeof(execbuf));
>> +    execbuf.buffers_ptr = to_user_pointer(&exec);
>> +    execbuf.buffer_count = 1;
>> +    execbuf.flags = ring;
>> +    execbuf.rsvd1 = gem_context_create(fd);
>> +    /* If context submission is not allowed, this will return EINVAL
>> +     * Otherwise, this will return ENOENT on account of no gem obj
>> +     * being submitted */
>> +    supported = __gem_execbuf(fd, &execbuf) == -ENOENT;
>> +    gem_context_destroy(fd, execbuf.rsvd1);
>> +
>> +    return supported;
>> +}
>> +
>> +/**
>>    * igt_hang_ring_ctx:
>>    * @fd: open i915 drm file descriptor
>>    * @ctx: the contxt specifier
>>    * @ring: execbuf ring flag
>>    * @flags: set of flags to control execution
>> + * @offset: The resultant gtt offset of the exec obj
>>    *
>>    * This helper function injects a hanging batch associated with @ctx
>> into @ring.
>>    * It returns a #igt_hang_t structure which must be passed to
>> @@ -239,8 +279,11 @@ igt_hang_t igt_hang_ctx(int fd,
>>         igt_require_hang_ring(fd, ring);
>>   -    /* One day the kernel ABI will be fixed! */
>> -    igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
>> +    /* check if non-default ctx submission is allowed */
>> +    if (!(has_ctx_exec(fd, ring)))
>> +    {
>> +        igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
>> +    }
>>
>
> Wouldn't
>
>     igt_require(ctx == 0 || has_ctx_exec(fd, ring));
>
> suffice here instead of the whole if block?
>
> -Daniele

True, will make the change.

>
>>       param.context = ctx;
>>       param.size = 0;
>>
diff mbox

Patch

diff --git a/lib/igt_gt.c b/lib/igt_gt.c
index b3f3b38..183d8bb 100644
--- a/lib/igt_gt.c
+++ b/lib/igt_gt.c
@@ -209,11 +209,51 @@  void igt_disallow_hang(int fd, igt_hang_t arg)
 }
 
 /**
+ * has_ctx_exec:
+ * @fd: open i915 drm file descriptor
+ * @ring: execbuf ring flag
+ *
+ * This helper function checks if non default context submission is allowed
+ * on a ring.
+ *
+ * Returns:
+ * True if allowed
+ *
+ */
+bool has_ctx_exec(int fd, unsigned ring)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 exec;
+	bool supported;
+
+	/* silly ABI, the kernel thinks everyone who has BSD also has BSD2 */
+	if ((ring & ~(3<<13)) == I915_EXEC_BSD) {
+		if (ring & (3 << 13) && !gem_has_bsd2(fd))
+			return false;
+	}
+
+	memset(&exec, 0, sizeof(exec));
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = to_user_pointer(&exec);
+	execbuf.buffer_count = 1;
+	execbuf.flags = ring;
+	execbuf.rsvd1 = gem_context_create(fd);
+	/* If context submission is not allowed, this will return EINVAL
+	 * Otherwise, this will return ENOENT on account of no gem obj
+	 * being submitted */
+	supported = __gem_execbuf(fd, &execbuf) == -ENOENT;
+	gem_context_destroy(fd, execbuf.rsvd1);
+
+	return supported;
+}
+
+/**
  * igt_hang_ring_ctx:
  * @fd: open i915 drm file descriptor
  * @ctx: the contxt specifier
  * @ring: execbuf ring flag
  * @flags: set of flags to control execution
+ * @offset: The resultant gtt offset of the exec obj
  *
  * This helper function injects a hanging batch associated with @ctx into @ring.
  * It returns a #igt_hang_t structure which must be passed to
@@ -239,8 +279,11 @@  igt_hang_t igt_hang_ctx(int fd,
 
 	igt_require_hang_ring(fd, ring);
 
-	/* One day the kernel ABI will be fixed! */
-	igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
+	/* check if non-default ctx submission is allowed */
+	if (!(has_ctx_exec(fd, ring)))
+	{
+		igt_require(ctx == 0 || ring == I915_EXEC_RENDER);
+	}
 
 	param.context = ctx;
 	param.size = 0;