public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>,
	intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Cc: daniel.vetter@intel.com, christian.koenig@amd.com,
	thomas.hellstrom@intel.com, paulo.r.zanoni@intel.com,
	matthew.auld@intel.com
Subject: Re: [Intel-gfx] [RFC v4 07/14] drm/i915/vm_bind: Add out fence support
Date: Thu, 22 Sep 2022 12:31:40 +0300	[thread overview]
Message-ID: <87a66r7o1v.fsf@intel.com> (raw)
In-Reply-To: <20220921070945.27764-8-niranjana.vishwanathapura@intel.com>

On Wed, 21 Sep 2022, Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com> wrote:
> Add support for handling out fence for vm_bind call.
>
> Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
> Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
> ---
>  drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h   |  4 +
>  .../drm/i915/gem/i915_gem_vm_bind_object.c    | 81 +++++++++++++++++++
>  drivers/gpu/drm/i915/i915_vma.c               |  6 +-
>  drivers/gpu/drm/i915/i915_vma_types.h         |  7 ++
>  4 files changed, 97 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> index 4f3cfa1f6ef6..facba29ead04 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind.h
> @@ -6,6 +6,7 @@
>  #ifndef __I915_GEM_VM_BIND_H
>  #define __I915_GEM_VM_BIND_H
>  
> +#include <linux/dma-fence.h>

Unnecessary. Please use forward declarations.

>  #include <linux/types.h>
>  
>  #include <drm/drm_file.h>
> @@ -24,4 +25,7 @@ int i915_gem_vm_unbind_ioctl(struct drm_device *dev, void *data,
>  
>  void i915_gem_vm_unbind_all(struct i915_address_space *vm);
>  
> +void i915_vm_bind_signal_fence(struct i915_vma *vma,
> +			       struct dma_fence * const fence);
> +
>  #endif /* __I915_GEM_VM_BIND_H */
> diff --git a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> index 236f901b8b9c..5cd788404ee7 100644
> --- a/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> +++ b/drivers/gpu/drm/i915/gem/i915_gem_vm_bind_object.c
> @@ -7,6 +7,8 @@
>  
>  #include <linux/interval_tree_generic.h>
>  
> +#include <drm/drm_syncobj.h>
> +
>  #include "gem/i915_gem_context.h"
>  #include "gem/i915_gem_vm_bind.h"
>  
> @@ -106,6 +108,75 @@ static void i915_gem_vm_bind_remove(struct i915_vma *vma, bool release_obj)
>  		i915_gem_object_put(vma->obj);
>  }
>  
> +static int i915_vm_bind_add_fence(struct drm_file *file, struct i915_vma *vma,
> +				  u32 handle, u64 point)
> +{
> +	struct drm_syncobj *syncobj;
> +
> +	syncobj = drm_syncobj_find(file, handle);
> +	if (!syncobj) {
> +		DRM_DEBUG("Invalid syncobj handle provided\n");
> +		return -ENOENT;
> +	}
> +
> +	/*
> +	 * For timeline syncobjs we need to preallocate chains for
> +	 * later signaling.
> +	 */
> +	if (point) {
> +		vma->vm_bind_fence.chain_fence = dma_fence_chain_alloc();
> +		if (!vma->vm_bind_fence.chain_fence) {
> +			drm_syncobj_put(syncobj);
> +			return -ENOMEM;
> +		}
> +	} else {
> +		vma->vm_bind_fence.chain_fence = NULL;
> +	}
> +	vma->vm_bind_fence.syncobj = syncobj;
> +	vma->vm_bind_fence.value = point;
> +
> +	return 0;
> +}
> +
> +static void i915_vm_bind_put_fence(struct i915_vma *vma)
> +{
> +	if (!vma->vm_bind_fence.syncobj)
> +		return;
> +
> +	drm_syncobj_put(vma->vm_bind_fence.syncobj);
> +	dma_fence_chain_free(vma->vm_bind_fence.chain_fence);
> +}
> +
> +/**
> + * i915_vm_bind_signal_fence() - Add fence to vm_bind syncobj
> + * @vma: vma mapping requiring signaling
> + * @fence: fence to be added
> + *
> + * Associate specified @fence with the @vma's syncobj to be
> + * signaled after the @fence work completes.
> + */
> +void i915_vm_bind_signal_fence(struct i915_vma *vma,
> +			       struct dma_fence * const fence)
> +{
> +	struct drm_syncobj *syncobj = vma->vm_bind_fence.syncobj;
> +
> +	if (!syncobj)
> +		return;
> +
> +	if (vma->vm_bind_fence.chain_fence) {
> +		drm_syncobj_add_point(syncobj,
> +				      vma->vm_bind_fence.chain_fence,
> +				      fence, vma->vm_bind_fence.value);
> +		/*
> +		 * The chain's ownership is transferred to the
> +		 * timeline.
> +		 */
> +		vma->vm_bind_fence.chain_fence = NULL;
> +	} else {
> +		drm_syncobj_replace_fence(syncobj, fence);
> +	}
> +}
> +
>  static int i915_gem_vm_unbind_vma(struct i915_address_space *vm,
>  				  struct drm_i915_gem_vm_unbind *va)
>  {
> @@ -233,6 +304,13 @@ static int i915_gem_vm_bind_obj(struct i915_address_space *vm,
>  		goto unlock_vm;
>  	}
>  
> +	if (va->fence.flags & I915_TIMELINE_FENCE_SIGNAL) {
> +		ret = i915_vm_bind_add_fence(file, vma, va->fence.handle,
> +					     va->fence.value);
> +		if (ret)
> +			goto put_vma;
> +	}
> +
>  	pin_flags = va->start | PIN_OFFSET_FIXED | PIN_USER;
>  
>  	for_i915_gem_ww(&ww, ret, true) {
> @@ -257,6 +335,9 @@ static int i915_gem_vm_bind_obj(struct i915_address_space *vm,
>  		i915_gem_object_get(vma->obj);
>  	}
>  
> +	if (va->fence.flags & I915_TIMELINE_FENCE_SIGNAL)
> +		i915_vm_bind_put_fence(vma);
> +put_vma:
>  	if (ret)
>  		i915_vma_destroy(vma);
>  unlock_vm:
> diff --git a/drivers/gpu/drm/i915/i915_vma.c b/drivers/gpu/drm/i915/i915_vma.c
> index ff216e9a2c8d..f7d711e675d6 100644
> --- a/drivers/gpu/drm/i915/i915_vma.c
> +++ b/drivers/gpu/drm/i915/i915_vma.c
> @@ -1540,8 +1540,12 @@ int i915_vma_pin_ww(struct i915_vma *vma, struct i915_gem_ww_ctx *ww,
>  err_vma_res:
>  	i915_vma_resource_free(vma_res);
>  err_fence:
> -	if (work)
> +	if (work) {
> +		if (i915_vma_is_persistent(vma))
> +			i915_vm_bind_signal_fence(vma, &work->base.dma);
> +
>  		dma_fence_work_commit_imm(&work->base);
> +	}
>  err_rpm:
>  	if (wakeref)
>  		intel_runtime_pm_put(&vma->vm->i915->runtime_pm, wakeref);
> diff --git a/drivers/gpu/drm/i915/i915_vma_types.h b/drivers/gpu/drm/i915/i915_vma_types.h
> index d21bf97febaa..7fdbf73666e9 100644
> --- a/drivers/gpu/drm/i915/i915_vma_types.h
> +++ b/drivers/gpu/drm/i915/i915_vma_types.h
> @@ -311,6 +311,13 @@ struct i915_vma {
>  	/* @vm_rebind_link: link to vm_rebind_list and protected by vm_rebind_lock */
>  	struct list_head vm_rebind_link; /* Link in vm_rebind_list */
>  
> +	/** Timeline fence for vm_bind completion notification */
> +	struct {
> +		struct dma_fence_chain *chain_fence;
> +		struct drm_syncobj *syncobj;
> +		u64 value;
> +	} vm_bind_fence;
> +
>  	/** Interval tree structures for persistent vma */
>  
>  	/** @rb: node for the interval tree of vm for persistent vmas */

-- 
Jani Nikula, Intel Open Source Graphics Center

  reply	other threads:[~2022-09-22  9:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-21  7:09 [Intel-gfx] [RFC v4 00/14] drm/i915/vm_bind: Add VM_BIND functionality Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 01/14] drm/i915/vm_bind: Expose vm lookup function Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 02/14] drm/i915/vm_bind: Add __i915_sw_fence_await_reservation() Niranjana Vishwanathapura
2022-09-21  9:06   ` Tvrtko Ursulin
2022-09-21 17:47     ` Niranjana Vishwanathapura
2022-09-22  9:26   ` Jani Nikula
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 03/14] drm/i915/vm_bind: Expose i915_gem_object_max_page_size() Niranjana Vishwanathapura
2022-09-21  9:13   ` Tvrtko Ursulin
2022-09-21 18:00     ` Niranjana Vishwanathapura
2022-09-22  8:09       ` Tvrtko Ursulin
2022-09-22 16:18         ` Matthew Auld
2022-09-22 16:46           ` Niranjana Vishwanathapura
2022-09-23  7:45           ` Tvrtko Ursulin
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 04/14] drm/i915/vm_bind: Implement bind and unbind of object Niranjana Vishwanathapura
2022-09-22  9:29   ` Jani Nikula
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 05/14] drm/i915/vm_bind: Support for VM private BOs Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 06/14] drm/i915/vm_bind: Handle persistent vmas Niranjana Vishwanathapura
2022-09-27  2:36   ` Zeng, Oak
2022-09-27  5:45     ` Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 07/14] drm/i915/vm_bind: Add out fence support Niranjana Vishwanathapura
2022-09-22  9:31   ` Jani Nikula [this message]
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 08/14] drm/i915/vm_bind: Abstract out common execbuf functions Niranjana Vishwanathapura
2022-09-21 10:18   ` Tvrtko Ursulin
2022-09-21 18:17     ` Niranjana Vishwanathapura
2022-09-22  9:05       ` Tvrtko Ursulin
2022-09-22 14:12         ` Niranjana Vishwanathapura
2022-09-22  9:54   ` Jani Nikula
2022-09-24  4:22     ` Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 09/14] drm/i915/vm_bind: Implement I915_GEM_EXECBUFFER3 ioctl Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 10/14] drm/i915/vm_bind: Update i915_vma_verify_bind_complete() Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 11/14] drm/i915/vm_bind: Handle persistent vmas in execbuf3 Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 12/14] drm/i915/vm_bind: userptr dma-resv changes Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 13/14] drm/i915/vm_bind: Skip vma_lookup for persistent vmas Niranjana Vishwanathapura
2022-09-23  8:40   ` Tvrtko Ursulin
2022-09-24  4:30     ` Niranjana Vishwanathapura
2022-09-26 16:26       ` Tvrtko Ursulin
2022-09-26 17:09         ` Niranjana Vishwanathapura
2022-09-27  9:28           ` Tvrtko Ursulin
2022-09-27 15:37             ` Niranjana Vishwanathapura
2022-09-21  7:09 ` [Intel-gfx] [RFC v4 14/14] drm/i915/vm_bind: Add uapi for user to enable vm_bind_mode Niranjana Vishwanathapura
2022-09-21  8:33 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/vm_bind: Add VM_BIND functionality (rev3) Patchwork
2022-09-21  8:55 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a66r7o1v.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=matthew.auld@intel.com \
    --cc=niranjana.vishwanathapura@intel.com \
    --cc=paulo.r.zanoni@intel.com \
    --cc=thomas.hellstrom@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox