All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] drm: add flags to drm_syncobj_find_fence
@ 2018-09-19  9:04 Chunming Zhou
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

flags can be used by driver to decide whether need to block wait submission.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +-
 drivers/gpu/drm/drm_syncobj.c          | 4 ++--
 drivers/gpu/drm/v3d/v3d_gem.c          | 4 ++--
 drivers/gpu/drm/vc4/vc4_gem.c          | 2 +-
 include/drm/drm_syncobj.h              | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index d9d2ede96490..412fac238575 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1102,7 +1102,7 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
 {
 	int r;
 	struct dma_fence *fence;
-	r = drm_syncobj_find_fence(p->filp, handle, 0, &fence);
+	r = drm_syncobj_find_fence(p->filp, handle, 0, 0, &fence);
 	if (r)
 		return r;
 
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index e9ce623d049e..f796c9fc3858 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -235,7 +235,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
  * dma_fence_put().
  */
 int drm_syncobj_find_fence(struct drm_file *file_private,
-			   u32 handle, u64 point,
+			   u32 handle, u64 point, u64 flags,
 			   struct dma_fence **fence)
 {
 	struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
@@ -506,7 +506,7 @@ static int drm_syncobj_export_sync_file(struct drm_file *file_private,
 	if (fd < 0)
 		return fd;
 
-	ret = drm_syncobj_find_fence(file_private, handle, 0, &fence);
+	ret = drm_syncobj_find_fence(file_private, handle, 0, 0, &fence);
 	if (ret)
 		goto err_put_fd;
 
diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c
index 70c54774400b..97477879d3d4 100644
--- a/drivers/gpu/drm/v3d/v3d_gem.c
+++ b/drivers/gpu/drm/v3d/v3d_gem.c
@@ -521,12 +521,12 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
 	kref_init(&exec->refcount);
 
 	ret = drm_syncobj_find_fence(file_priv, args->in_sync_bcl,
-				     0, &exec->bin.in_fence);
+				     0, 0, &exec->bin.in_fence);
 	if (ret == -EINVAL)
 		goto fail;
 
 	ret = drm_syncobj_find_fence(file_priv, args->in_sync_rcl,
-				     0, &exec->render.in_fence);
+				     0, 0, &exec->render.in_fence);
 	if (ret == -EINVAL)
 		goto fail;
 
diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c
index 5b22e996af6c..251198194c38 100644
--- a/drivers/gpu/drm/vc4/vc4_gem.c
+++ b/drivers/gpu/drm/vc4/vc4_gem.c
@@ -1173,7 +1173,7 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
 
 	if (args->in_sync) {
 		ret = drm_syncobj_find_fence(file_priv, args->in_sync,
-					     0, &in_fence);
+					     0, 0, &in_fence);
 		if (ret)
 			goto fail;
 
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 425432b85a87..2eda44def639 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -134,7 +134,7 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
 void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, u64 point,
 			       struct dma_fence *fence);
 int drm_syncobj_find_fence(struct drm_file *file_private,
-			   u32 handle, u64 point,
+			   u32 handle, u64 point, u64 flags,
 			   struct dma_fence **fence);
 void drm_syncobj_free(struct kref *kref);
 int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/6] [RFC]drm: add syncobj timeline support v7
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-19  9:04   ` Chunming Zhou
  2018-09-19  9:04   ` [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS Chunming Zhou
  2018-09-19  9:04   ` [PATCH 6/6] drm/amdgpu: update version for timeline syncobj support in amdgpu Chunming Zhou
  2 siblings, 0 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	Daniel Rakos, Daniel Vetter, Dave Airlie, Christian Konig

This patch is for VK_KHR_timeline_semaphore extension, semaphore is called syncobj in kernel side:
This extension introduces a new type of syncobj that has an integer payload
identifying a point in a timeline. Such timeline syncobjs support the
following operations:
   * CPU query - A host operation that allows querying the payload of the
     timeline syncobj.
   * CPU wait - A host operation that allows a blocking wait for a
     timeline syncobj to reach a specified value.
   * Device wait - A device operation that allows waiting for a
     timeline syncobj to reach a specified value.
   * Device signal - A device operation that allows advancing the
     timeline syncobj to a specified value.

v1:
Since it's a timeline, that means the front time point(PT) always is signaled before the late PT.
a. signal PT design:
Signal PT fence N depends on PT[N-1] fence and signal opertion fence, when PT[N] fence is signaled,
the timeline will increase to value of PT[N].
b. wait PT design:
Wait PT fence is signaled by reaching timeline point value, when timeline is increasing, will compare
wait PTs value with new timeline value, if PT value is lower than timeline value, then wait PT will be
signaled, otherwise keep in list. syncobj wait operation can wait on any point of timeline,
so need a RB tree to order them. And wait PT could ahead of signal PT, we need a sumission fence to
perform that.

v2:
1. remove unused DRM_SYNCOBJ_CREATE_TYPE_NORMAL. (Christian)
2. move unexposed denitions to .c file. (Daniel Vetter)
3. split up the change to drm_syncobj_find_fence() in a separate patch. (Christian)
4. split up the change to drm_syncobj_replace_fence() in a separate patch.
5. drop the submission_fence implementation and instead use wait_event() for that. (Christian)
6. WARN_ON(point != 0) for NORMAL type syncobj case. (Daniel Vetter)

v3:
1. replace normal syncobj with timeline implemenation. (Vetter and Christian)
    a. normal syncobj signal op will create a signal PT to tail of signal pt list.
    b. normal syncobj wait op will create a wait pt with last signal point, and this wait PT is only signaled by related signal point PT.
2. many bug fix and clean up
3. stub fence moving is moved to other patch.

v4:
1. fix RB tree loop with while(node=rb_first(...)). (Christian)
2. fix syncobj lifecycle. (Christian)
3. only enable_signaling when there is wait_pt. (Christian)
4. fix timeline path issues.
5. write a timeline test in libdrm

v5: (Christian)
1. semaphore is called syncobj in kernel side.
2. don't need 'timeline' characters in some function name.
3. keep syncobj cb.

v6: (Christian)
1. merge syncobj_timeline to syncobj structure.
2. simplify some check sentences.
3. some misc change.
4. fix CTS failed issue.

v7: (Christian)
1. error handling when creating signal pt.
2. remove timeline naming in func.
3. export flags in find_fence.
4. allow reset timeline.

normal syncobj is tested by ./deqp-vk -n dEQP-VK*semaphore*
timeline syncobj is tested by ./amdgpu_test -s 9

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
Cc: Christian Konig <christian.koenig@amd.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Rakos <Daniel.Rakos@amd.com>
Cc: Daniel Vetter <daniel@ffwll.ch>
---
 drivers/gpu/drm/drm_syncobj.c              | 291 ++++++++++++++++++---
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |   2 +-
 include/drm/drm_syncobj.h                  |  65 ++---
 include/uapi/drm/drm.h                     |   1 +
 4 files changed, 285 insertions(+), 74 deletions(-)

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index f796c9fc3858..d69126b690c2 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -56,6 +56,9 @@
 #include "drm_internal.h"
 #include <drm/drm_syncobj.h>
 
+/* merge normal syncobj to timeline syncobj, the point interval is 1 */
+#define DRM_SYNCOBJ_INDIVIDUAL_POINT 1
+
 struct drm_syncobj_stub_fence {
 	struct dma_fence base;
 	spinlock_t lock;
@@ -82,6 +85,11 @@ static const struct dma_fence_ops drm_syncobj_stub_fence_ops = {
 	.release = drm_syncobj_stub_fence_release,
 };
 
+struct drm_syncobj_signal_pt {
+	struct dma_fence_array *base;
+	u64    value;
+	struct list_head list;
+};
 
 /**
  * drm_syncobj_find - lookup and reference a sync object.
@@ -124,8 +132,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
 {
 	int ret;
 
-	*fence = drm_syncobj_fence_get(syncobj);
-	if (*fence)
+	ret = drm_syncobj_search_fence(syncobj, 0, 0, fence);
+	if (!ret)
 		return 1;
 
 	spin_lock(&syncobj->lock);
@@ -133,10 +141,12 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
 	 * have the lock, try one more time just to be sure we don't add a
 	 * callback when a fence has already been set.
 	 */
-	if (syncobj->fence) {
-		*fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
-								 lockdep_is_held(&syncobj->lock)));
-		ret = 1;
+	if (!list_empty(&syncobj->signal_pt_list)) {
+		spin_unlock(&syncobj->lock);
+		drm_syncobj_search_fence(syncobj, 0, 0, fence);
+		if (*fence)
+			return 1;
+		spin_lock(&syncobj->lock);
 	} else {
 		*fence = NULL;
 		drm_syncobj_add_callback_locked(syncobj, cb, func);
@@ -164,6 +174,157 @@ void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,
 	spin_unlock(&syncobj->lock);
 }
 
+static void drm_syncobj_init(struct drm_syncobj *syncobj)
+{
+	spin_lock(&syncobj->lock);
+	syncobj->timeline_context = dma_fence_context_alloc(1);
+	syncobj->timeline = 0;
+	syncobj->signal_point = 0;
+	init_waitqueue_head(&syncobj->wq);
+
+	INIT_LIST_HEAD(&syncobj->signal_pt_list);
+	spin_unlock(&syncobj->lock);
+}
+
+static void drm_syncobj_fini(struct drm_syncobj *syncobj)
+{
+	struct drm_syncobj_signal_pt *signal_pt = NULL, *tmp;
+
+	spin_lock(&syncobj->lock);
+	list_for_each_entry_safe(signal_pt, tmp,
+				 &syncobj->signal_pt_list, list) {
+		list_del(&signal_pt->list);
+		dma_fence_put(&signal_pt->base->base);
+		kfree(signal_pt);
+	}
+	spin_unlock(&syncobj->lock);
+}
+
+static struct dma_fence
+*drm_syncobj_find_signal_pt_for_point(struct drm_syncobj *syncobj,
+				      uint64_t point)
+{
+	struct drm_syncobj_signal_pt *signal_pt;
+
+	if ((syncobj->type == DRM_SYNCOBJ_TYPE_TIMELINE) &&
+	    (point <= syncobj->timeline)) {
+		struct drm_syncobj_stub_fence *fence =
+			kzalloc(sizeof(struct drm_syncobj_stub_fence),
+				GFP_KERNEL);
+
+		if (!fence)
+			return NULL;
+		spin_lock_init(&fence->lock);
+		dma_fence_init(&fence->base,
+			       &drm_syncobj_stub_fence_ops,
+			       &fence->lock,
+			       syncobj->timeline_context,
+			       point);
+
+		dma_fence_signal(&fence->base);
+		return &fence->base;
+	}
+
+	list_for_each_entry(signal_pt, &syncobj->signal_pt_list, list) {
+		if (point > signal_pt->value)
+			continue;
+		if ((syncobj->type == DRM_SYNCOBJ_TYPE_INDIVIDUAL) &&
+		    (point != signal_pt->value))
+			continue;
+		return dma_fence_get(&signal_pt->base->base);
+	}
+	return NULL;
+}
+
+static int drm_syncobj_create_signal_pt(struct drm_syncobj *syncobj,
+					struct dma_fence *fence,
+					u64 point)
+{
+	struct drm_syncobj_signal_pt *signal_pt =
+		kzalloc(sizeof(struct drm_syncobj_signal_pt), GFP_KERNEL);
+	struct drm_syncobj_signal_pt *tail_pt;
+	struct dma_fence **fences;
+	int num_fences = 0;
+	int ret = 0, i;
+
+	if (!signal_pt)
+		return -ENOMEM;
+	if (!fence)
+		goto out;
+
+	fences = kmalloc_array(sizeof(void *), 2, GFP_KERNEL);
+	if (!fences) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	fences[num_fences++] = dma_fence_get(fence);
+	/* timeline syncobj must take this dependency */
+	if (syncobj->type == DRM_SYNCOBJ_TYPE_TIMELINE) {
+		spin_lock(&syncobj->lock);
+		if (!list_empty(&syncobj->signal_pt_list)) {
+			tail_pt = list_last_entry(&syncobj->signal_pt_list,
+						  struct drm_syncobj_signal_pt, list);
+			fences[num_fences++] = dma_fence_get(&tail_pt->base->base);
+		}
+		spin_unlock(&syncobj->lock);
+	}
+	signal_pt->base = dma_fence_array_create(num_fences, fences,
+						 syncobj->timeline_context,
+						 point, false);
+	if (!signal_pt->base) {
+		ret = -ENOMEM;
+		goto fail;
+	}
+
+	spin_lock(&syncobj->lock);
+	if (syncobj->signal_point >= point) {
+		DRM_WARN("A later signal is ready!");
+		spin_unlock(&syncobj->lock);
+		goto out;
+	}
+	signal_pt->value = point;
+	list_add_tail(&signal_pt->list, &syncobj->signal_pt_list);
+	syncobj->signal_point = point;
+	spin_unlock(&syncobj->lock);
+	wake_up_all(&syncobj->wq);
+
+	return 0;
+fail:
+	for (i = 0; i < num_fences; i++)
+		dma_fence_put(fences[i]);
+	kfree(fences);
+out:
+	kfree(signal_pt);
+	return ret;
+}
+
+static void drm_syncobj_garbage_collection(struct drm_syncobj *syncobj)
+{
+	struct drm_syncobj_signal_pt *signal_pt, *tmp, *tail_pt;
+
+	spin_lock(&syncobj->lock);
+	tail_pt = list_last_entry(&syncobj->signal_pt_list,
+				  struct drm_syncobj_signal_pt,
+				  list);
+	list_for_each_entry_safe(signal_pt, tmp,
+				 &syncobj->signal_pt_list, list) {
+		if (syncobj->type == DRM_SYNCOBJ_TYPE_INDIVIDUAL &&
+		    signal_pt == tail_pt)
+			continue;
+		if (dma_fence_is_signaled(&signal_pt->base->base)) {
+			syncobj->timeline = signal_pt->value;
+			list_del(&signal_pt->list);
+			dma_fence_put(&signal_pt->base->base);
+			kfree(signal_pt);
+		} else {
+			/*signal_pt is in order in list, from small to big, so
+			 * the later must not be signal either */
+			break;
+		}
+	}
+
+	spin_unlock(&syncobj->lock);
+}
 /**
  * drm_syncobj_replace_fence - replace fence in a sync object.
  * @syncobj: Sync object to replace fence in
@@ -176,28 +337,29 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
 			       u64 point,
 			       struct dma_fence *fence)
 {
-	struct dma_fence *old_fence;
-	struct drm_syncobj_cb *cur, *tmp;
-
-	if (fence)
-		dma_fence_get(fence);
-
-	spin_lock(&syncobj->lock);
-
-	old_fence = rcu_dereference_protected(syncobj->fence,
-					      lockdep_is_held(&syncobj->lock));
-	rcu_assign_pointer(syncobj->fence, fence);
+	u64 pt_value = point;
+
+	drm_syncobj_garbage_collection(syncobj);
+	if (syncobj->type == DRM_SYNCOBJ_TYPE_INDIVIDUAL) {
+		if (!fence) {
+			drm_syncobj_fini(syncobj);
+			drm_syncobj_init(syncobj);
+			return;
+		}
+		pt_value = syncobj->signal_point +
+			DRM_SYNCOBJ_INDIVIDUAL_POINT;
+	}
+	drm_syncobj_create_signal_pt(syncobj, fence, pt_value);
+	if (fence) {
+		struct drm_syncobj_cb *cur, *tmp;
 
-	if (fence != old_fence) {
+		spin_lock(&syncobj->lock);
 		list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
 			list_del_init(&cur->node);
 			cur->func(syncobj, cur);
 		}
+		spin_unlock(&syncobj->lock);
 	}
-
-	spin_unlock(&syncobj->lock);
-
-	dma_fence_put(old_fence);
 }
 EXPORT_SYMBOL(drm_syncobj_replace_fence);
 
@@ -220,6 +382,52 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
 	return 0;
 }
 
+#define WAIT_FOR_SUBMIT_MSECS 10000
+
+static struct dma_fence *
+drm_syncobj_point_get(struct drm_syncobj *syncobj, u64 point, u64 flags)
+{
+	struct dma_fence *fence;
+	int ret = 0;
+
+	if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
+		ret = wait_event_timeout(syncobj->wq,
+					 point <= syncobj->signal_point,
+					 msecs_to_jiffies(WAIT_FOR_SUBMIT_MSECS));
+		if (ret <= 0)
+			return NULL;
+	}
+	spin_lock(&syncobj->lock);
+	fence = drm_syncobj_find_signal_pt_for_point(syncobj, point);
+	spin_unlock(&syncobj->lock);
+	return fence;
+}
+
+int drm_syncobj_search_fence(struct drm_syncobj *syncobj, u64 point,
+			     u64 flags, struct dma_fence **fence)
+{
+	u64 pt_value = point;
+	int ret = 0;
+
+	if (!syncobj)
+		return -ENOENT;
+
+	drm_syncobj_garbage_collection(syncobj);
+	if (syncobj->type == DRM_SYNCOBJ_TYPE_INDIVIDUAL) {
+		/*INDIVIDUAL syncobj always wait on last pt */
+		pt_value = syncobj->signal_point;
+
+		if (pt_value == 0)
+			pt_value += DRM_SYNCOBJ_INDIVIDUAL_POINT;
+	}
+	*fence = drm_syncobj_point_get(syncobj, pt_value, flags);
+	if (!*fence) {
+		ret = -EINVAL;
+	}
+	return ret;
+}
+EXPORT_SYMBOL(drm_syncobj_search_fence);
+
 /**
  * drm_syncobj_find_fence - lookup and reference the fence in a sync object
  * @file_private: drm file private pointer
@@ -228,7 +436,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
  * @fence: out parameter for the fence
  *
  * This is just a convenience function that combines drm_syncobj_find() and
- * drm_syncobj_fence_get().
+ * drm_syncobj_lookup_fence().
  *
  * Returns 0 on success or a negative error value on failure. On success @fence
  * contains a reference to the fence, which must be released by calling
@@ -239,15 +447,9 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
 			   struct dma_fence **fence)
 {
 	struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
-	int ret = 0;
-
-	if (!syncobj)
-		return -ENOENT;
+	int ret;
 
-	*fence = drm_syncobj_fence_get(syncobj);
-	if (!*fence) {
-		ret = -EINVAL;
-	}
+	ret = drm_syncobj_search_fence(syncobj, point, flags, fence);
 	drm_syncobj_put(syncobj);
 	return ret;
 }
@@ -264,7 +466,7 @@ void drm_syncobj_free(struct kref *kref)
 	struct drm_syncobj *syncobj = container_of(kref,
 						   struct drm_syncobj,
 						   refcount);
-	drm_syncobj_replace_fence(syncobj, 0, NULL);
+	drm_syncobj_fini(syncobj);
 	kfree(syncobj);
 }
 EXPORT_SYMBOL(drm_syncobj_free);
@@ -294,6 +496,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
 	kref_init(&syncobj->refcount);
 	INIT_LIST_HEAD(&syncobj->cb_list);
 	spin_lock_init(&syncobj->lock);
+	if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)
+		syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE;
+	else
+		syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL;
+	drm_syncobj_init(syncobj);
 
 	if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) {
 		ret = drm_syncobj_assign_null_handle(syncobj);
@@ -576,7 +783,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data,
 		return -ENODEV;
 
 	/* no valid flags yet */
-	if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED)
+	if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED |
+			    DRM_SYNCOBJ_CREATE_TYPE_TIMELINE))
 		return -EINVAL;
 
 	return drm_syncobj_create_as_handle(file_private,
@@ -669,9 +877,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,
 	struct syncobj_wait_entry *wait =
 		container_of(cb, struct syncobj_wait_entry, syncobj_cb);
 
-	/* This happens inside the syncobj lock */
-	wait->fence = dma_fence_get(rcu_dereference_protected(syncobj->fence,
-							      lockdep_is_held(&syncobj->lock)));
+	drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
+
 	wake_up_process(wait->task);
 }
 
@@ -698,7 +905,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 	signaled_count = 0;
 	for (i = 0; i < count; ++i) {
 		entries[i].task = current;
-		entries[i].fence = drm_syncobj_fence_get(syncobjs[i]);
+		ret = drm_syncobj_search_fence(syncobjs[i], 0, 0,
+					       &entries[i].fence);
 		if (!entries[i].fence) {
 			if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
 				continue;
@@ -970,12 +1178,13 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 	if (ret < 0)
 		return ret;
 
-	for (i = 0; i < args->count_handles; i++)
-		drm_syncobj_replace_fence(syncobjs[i], 0, NULL);
-
+	for (i = 0; i < args->count_handles; i++) {
+		drm_syncobj_fini(syncobjs[i]);
+		drm_syncobj_init(syncobjs[i]);
+	}
 	drm_syncobj_array_free(syncobjs, args->count_handles);
 
-	return 0;
+	return ret;
 }
 
 int
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 0a8d2d64f380..8a8d21b24119 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb,
 		if (!(flags & I915_EXEC_FENCE_WAIT))
 			continue;
 
-		fence = drm_syncobj_fence_get(syncobj);
+		drm_syncobj_search_fence(syncobj, 0, 0, &fence);
 		if (!fence)
 			return -EINVAL;
 
diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h
index 2eda44def639..acf1c3a46d95 100644
--- a/include/drm/drm_syncobj.h
+++ b/include/drm/drm_syncobj.h
@@ -30,6 +30,11 @@
 
 struct drm_syncobj_cb;
 
+enum drm_syncobj_type {
+	DRM_SYNCOBJ_TYPE_INDIVIDUAL,
+	DRM_SYNCOBJ_TYPE_TIMELINE
+};
+
 /**
  * struct drm_syncobj - sync object.
  *
@@ -41,19 +46,36 @@ struct drm_syncobj {
 	 */
 	struct kref refcount;
 	/**
-	 * @fence:
-	 * NULL or a pointer to the fence bound to this object.
-	 *
-	 * This field should not be used directly. Use drm_syncobj_fence_get()
-	 * and drm_syncobj_replace_fence() instead.
+	 * @type: indicate syncobj type
+	 */
+	enum drm_syncobj_type type;
+	/**
+	 * @wq: wait signal operation work queue
+	 */
+	wait_queue_head_t	wq;
+	/**
+	 * @timeline_context: fence context used by timeline
 	 */
-	struct dma_fence __rcu *fence;
+	u64 timeline_context;
 	/**
-	 * @cb_list: List of callbacks to call when the &fence gets replaced.
+	 * @timeline: syncobj timeline value, which indicates point is signaled.
 	 */
+	u64 timeline;
+	/**
+	 * @signal_point: which indicates the latest signaler point.
+	 */
+	u64 signal_point;
+	/**
+	 * @signal_pt_list: signaler point list.
+	 */
+	struct list_head signal_pt_list;
+
+	/**
+         * @cb_list: List of callbacks to call when the &fence gets replaced.
+         */
 	struct list_head cb_list;
 	/**
-	 * @lock: Protects &cb_list and write-locks &fence.
+	 * @lock: Protects syncobj list and write-locks &fence.
 	 */
 	spinlock_t lock;
 	/**
@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,
 /**
  * struct drm_syncobj_cb - callback for drm_syncobj_add_callback
  * @node: used by drm_syncob_add_callback to append this struct to
- *	  &drm_syncobj.cb_list
+ *       &drm_syncobj.cb_list
  * @func: drm_syncobj_func_t to call
  *
  * This struct will be initialized by drm_syncobj_add_callback, additional
@@ -106,29 +128,6 @@ drm_syncobj_put(struct drm_syncobj *obj)
 	kref_put(&obj->refcount, drm_syncobj_free);
 }
 
-/**
- * drm_syncobj_fence_get - get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */
-static inline struct dma_fence *
-drm_syncobj_fence_get(struct drm_syncobj *syncobj)
-{
-	struct dma_fence *fence;
-
-	rcu_read_lock();
-	fence = dma_fence_get_rcu_safe(&syncobj->fence);
-	rcu_read_unlock();
-
-	return fence;
-}
-
 struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private,
 				     u32 handle);
 void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, u64 point,
@@ -142,5 +141,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,
 int drm_syncobj_get_handle(struct drm_file *file_private,
 			   struct drm_syncobj *syncobj, u32 *handle);
 int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);
+int drm_syncobj_search_fence(struct drm_syncobj *syncobj, u64 point, u64 flags,
+			     struct dma_fence **fence);
 
 #endif
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 300f336633f2..cebdb2541eb7 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -717,6 +717,7 @@ struct drm_prime_handle {
 struct drm_syncobj_create {
 	__u32 handle;
 #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0)
+#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1)
 	__u32 flags;
 };
 
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/6] drm: add support of syncobj timeline point wait v2
  2018-09-19  9:04 [PATCH 1/6] drm: add flags to drm_syncobj_find_fence Chunming Zhou
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-19  9:04 ` Chunming Zhou
  2018-09-19  9:04 ` [PATCH 4/6] drm: add timeline syncobj payload query ioctl Chunming Zhou
  2 siblings, 0 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel; +Cc: amd-gfx

points array is one-to-one match with syncobjs array.
v2:
add seperate ioctl for timeline point wait, otherwise break uapi.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/drm_internal.h |  2 +
 drivers/gpu/drm/drm_ioctl.c    |  2 +
 drivers/gpu/drm/drm_syncobj.c  | 99 +++++++++++++++++++++++++++++-----
 include/uapi/drm/drm.h         | 14 +++++
 4 files changed, 103 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index 0c4eb4a9ab31..566d44e3c782 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -183,6 +183,8 @@ int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data,
 				   struct drm_file *file_private);
 int drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
 			   struct drm_file *file_private);
+int drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
+				    struct drm_file *file_private);
 int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 6b4a633b4240..c0891614f516 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -669,6 +669,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index d69126b690c2..251d48a18999 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -126,13 +126,14 @@ static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,
 }
 
 static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
+						 u64 point,
 						 struct dma_fence **fence,
 						 struct drm_syncobj_cb *cb,
 						 drm_syncobj_func_t func)
 {
 	int ret;
 
-	ret = drm_syncobj_search_fence(syncobj, 0, 0, fence);
+	ret = drm_syncobj_search_fence(syncobj, point, 0, fence);
 	if (!ret)
 		return 1;
 
@@ -143,7 +144,7 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,
 	 */
 	if (!list_empty(&syncobj->signal_pt_list)) {
 		spin_unlock(&syncobj->lock);
-		drm_syncobj_search_fence(syncobj, 0, 0, fence);
+		drm_syncobj_search_fence(syncobj, point, 0, fence);
 		if (*fence)
 			return 1;
 		spin_lock(&syncobj->lock);
@@ -356,7 +357,9 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,
 		spin_lock(&syncobj->lock);
 		list_for_each_entry_safe(cur, tmp, &syncobj->cb_list, node) {
 			list_del_init(&cur->node);
+			spin_unlock(&syncobj->lock);
 			cur->func(syncobj, cur);
+			spin_lock(&syncobj->lock);
 		}
 		spin_unlock(&syncobj->lock);
 	}
@@ -860,6 +863,7 @@ struct syncobj_wait_entry {
 	struct dma_fence *fence;
 	struct dma_fence_cb fence_cb;
 	struct drm_syncobj_cb syncobj_cb;
+	u64    point;
 };
 
 static void syncobj_wait_fence_func(struct dma_fence *fence,
@@ -877,12 +881,13 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,
 	struct syncobj_wait_entry *wait =
 		container_of(cb, struct syncobj_wait_entry, syncobj_cb);
 
-	drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
+	drm_syncobj_search_fence(syncobj, wait->point, 0, &wait->fence);
 
 	wake_up_process(wait->task);
 }
 
 static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
+						  void __user *user_points,
 						  uint32_t count,
 						  uint32_t flags,
 						  signed long timeout,
@@ -890,13 +895,27 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 {
 	struct syncobj_wait_entry *entries;
 	struct dma_fence *fence;
+	uint64_t *points;
 	signed long ret;
 	uint32_t signaled_count, i;
 
-	entries = kcalloc(count, sizeof(*entries), GFP_KERNEL);
-	if (!entries)
+	points = kmalloc_array(count, sizeof(*points), GFP_KERNEL);
+	if (points == NULL)
 		return -ENOMEM;
 
+	if (!user_points) {
+		memset(points, 0, count * sizeof(uint64_t));
+	} else if (copy_from_user(points, user_points, sizeof(uint64_t) * count)) {
+		ret = -EFAULT;
+		goto err_free_points;
+	}
+
+
+	entries = kcalloc(count, sizeof(*entries), GFP_KERNEL);
+	if (!entries) {
+		ret = -ENOMEM;
+		goto err_free_points;
+	}
 	/* Walk the list of sync objects and initialize entries.  We do
 	 * this up-front so that we can properly return -EINVAL if there is
 	 * a syncobj with a missing fence and then never have the chance of
@@ -905,7 +924,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 	signaled_count = 0;
 	for (i = 0; i < count; ++i) {
 		entries[i].task = current;
-		ret = drm_syncobj_search_fence(syncobjs[i], 0, 0,
+		entries[i].point = points[i];
+		ret = drm_syncobj_search_fence(syncobjs[i], points[i], 0,
 					       &entries[i].fence);
 		if (!entries[i].fence) {
 			if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
@@ -944,6 +964,7 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 	if (flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
 		for (i = 0; i < count; ++i) {
 			drm_syncobj_fence_get_or_add_callback(syncobjs[i],
+							      entries[i].point,
 							      &entries[i].fence,
 							      &entries[i].syncobj_cb,
 							      syncobj_wait_syncobj_func);
@@ -1007,6 +1028,9 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
 	}
 	kfree(entries);
 
+err_free_points:
+	kfree(points);
+
 	return ret;
 }
 
@@ -1045,20 +1069,33 @@ static signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec)
 static int drm_syncobj_array_wait(struct drm_device *dev,
 				  struct drm_file *file_private,
 				  struct drm_syncobj_wait *wait,
-				  struct drm_syncobj **syncobjs)
+				  struct drm_syncobj_timeline_wait *timeline_wait,
+				  struct drm_syncobj **syncobjs, bool timeline)
 {
-	signed long timeout = drm_timeout_abs_to_jiffies(wait->timeout_nsec);
+	signed long timeout = 0;
 	signed long ret = 0;
 	uint32_t first = ~0;
 
-	ret = drm_syncobj_array_wait_timeout(syncobjs,
-					     wait->count_handles,
-					     wait->flags,
-					     timeout, &first);
+	if (!timeline) {
+		timeout = drm_timeout_abs_to_jiffies(wait->timeout_nsec);
+		ret = drm_syncobj_array_wait_timeout(syncobjs,
+						     NULL,
+						     wait->count_handles,
+						     wait->flags,
+						     timeout, &first);
+		wait->first_signaled = first;
+	} else {
+		timeout = drm_timeout_abs_to_jiffies(timeline_wait->timeout_nsec);
+		ret = drm_syncobj_array_wait_timeout(syncobjs,
+						     u64_to_user_ptr(timeline_wait->points),
+						     timeline_wait->count_handles,
+						     timeline_wait->flags,
+						     timeout, &first);
+		timeline_wait->first_signaled = first;
+	}
 	if (ret < 0)
 		return ret;
 
-	wait->first_signaled = first;
 	if (ret == 0)
 		return -ETIME;
 	return 0;
@@ -1146,13 +1183,47 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
 		return ret;
 
 	ret = drm_syncobj_array_wait(dev, file_private,
-				     args, syncobjs);
+				     args, NULL, syncobjs, false);
 
 	drm_syncobj_array_free(syncobjs, args->count_handles);
 
 	return ret;
 }
 
+int
+drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
+				struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_wait *args = data;
+	struct drm_syncobj **syncobjs;
+	int ret = 0;
+
+	if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
+		return -ENODEV;
+
+	if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |
+			    DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
+		return -EINVAL;
+
+	if (args->count_handles == 0)
+		return -EINVAL;
+
+	ret = drm_syncobj_array_find(file_private,
+				     u64_to_user_ptr(args->handles),
+				     args->count_handles,
+				     &syncobjs);
+	if (ret < 0)
+		return ret;
+
+	ret = drm_syncobj_array_wait(dev, file_private,
+				     NULL, args, syncobjs, true);
+
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
+
+
 int
 drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			struct drm_file *file_private)
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index cebdb2541eb7..501e86d81f47 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -748,6 +748,19 @@ struct drm_syncobj_wait {
 	__u32 pad;
 };
 
+struct drm_syncobj_timeline_wait {
+	__u64 handles;
+	/* wait on specific timeline point for every handles*/
+	__u64 points;
+	/* absolute timeout */
+	__s64 timeout_nsec;
+	__u32 count_handles;
+	__u32 flags;
+	__u32 first_signaled; /* only valid when not waiting all */
+	__u32 pad;
+};
+
+
 struct drm_syncobj_array {
 	__u64 handles;
 	__u32 count_handles;
@@ -910,6 +923,7 @@ extern "C" {
 #define DRM_IOCTL_MODE_GET_LEASE	DRM_IOWR(0xC8, struct drm_mode_get_lease)
 #define DRM_IOCTL_MODE_REVOKE_LEASE	DRM_IOWR(0xC9, struct drm_mode_revoke_lease)
 
+#define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/6] drm: add timeline syncobj payload query ioctl
  2018-09-19  9:04 [PATCH 1/6] drm: add flags to drm_syncobj_find_fence Chunming Zhou
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  2018-09-19  9:04 ` [PATCH 3/6] drm: add support of syncobj timeline point wait v2 Chunming Zhou
@ 2018-09-19  9:04 ` Chunming Zhou
  2 siblings, 0 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel; +Cc: amd-gfx

user mode can query timeline payload.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/drm_internal.h |  2 ++
 drivers/gpu/drm/drm_ioctl.c    |  2 ++
 drivers/gpu/drm/drm_syncobj.c  | 53 ++++++++++++++++++++++++++++++++++
 include/uapi/drm/drm.h         | 11 +++++++
 4 files changed, 68 insertions(+)

diff --git a/drivers/gpu/drm/drm_internal.h b/drivers/gpu/drm/drm_internal.h
index 566d44e3c782..9c4826411a3c 100644
--- a/drivers/gpu/drm/drm_internal.h
+++ b/drivers/gpu/drm/drm_internal.h
@@ -189,6 +189,8 @@ int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
 			    struct drm_file *file_private);
 int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
 			     struct drm_file *file_private);
+int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
+			    struct drm_file *file_private);
 
 /* drm_framebuffer.c */
 void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index c0891614f516..c3c0617e6372 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -675,6 +675,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
 		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl,
+		      DRM_UNLOCKED|DRM_RENDER_ALLOW),
 	DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, DRM_UNLOCKED),
 	DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER|DRM_UNLOCKED),
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 251d48a18999..831e64da4339 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -1293,3 +1293,56 @@ drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
 
 	return ret;
 }
+
+static void drm_syncobj_timeline_query_payload(struct drm_syncobj *syncobj,
+					       uint64_t *point)
+{
+	if (syncobj->type != DRM_SYNCOBJ_TYPE_TIMELINE) {
+		DRM_ERROR("Normal syncobj cann't be queried!");
+		*point = 0;
+		return;
+	}
+	*point = syncobj->signal_point;
+}
+
+int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
+			    struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_query *args = data;
+	struct drm_syncobj **syncobjs;
+	uint64_t *points;
+	uint32_t i;
+	int ret;
+
+	if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
+		return -ENODEV;
+
+	if (args->count_handles == 0)
+		return -EINVAL;
+
+	ret = drm_syncobj_array_find(file_private,
+				     u64_to_user_ptr(args->handles),
+				     args->count_handles,
+				     &syncobjs);
+	if (ret < 0)
+		return ret;
+
+
+	points = kmalloc_array(args->count_handles, sizeof(*points),
+			       GFP_KERNEL);
+	if (points == NULL) {
+		ret = -ENOMEM;
+		goto out;
+	}
+	for (i = 0; i < args->count_handles; i++) {
+		drm_syncobj_timeline_query_payload(syncobjs[i], &points[i]);
+		copy_to_user(u64_to_user_ptr(args->points), points,
+			     sizeof(uint64_t) * args->count_handles);
+	}
+
+	kfree(points);
+out:
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 501e86d81f47..188b63f1975b 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -767,6 +767,15 @@ struct drm_syncobj_array {
 	__u32 pad;
 };
 
+struct drm_syncobj_timeline_query {
+	__u64 handles;
+	/* points are timeline syncobjs payloads returned by query ioctl */
+	__u64 points;
+	__u32 count_handles;
+	__u32 pad;
+};
+
+
 /* Query current scanout sequence number */
 struct drm_crtc_get_sequence {
 	__u32 crtc_id;		/* requested crtc_id */
@@ -924,6 +933,8 @@ extern "C" {
 #define DRM_IOCTL_MODE_REVOKE_LEASE	DRM_IOWR(0xC9, struct drm_mode_revoke_lease)
 
 #define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT	DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)
+#define DRM_IOCTL_SYNCOBJ_QUERY		DRM_IOWR(0xCB, struct drm_syncobj_timeline_query)
+
 /**
  * Device specific ioctls should only be in their respective headers
  * The device specific ioctl range is from 0x40 to 0x9f.
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  2018-09-19  9:04   ` [PATCH 2/6] [RFC]drm: add syncobj timeline support v7 Chunming Zhou
@ 2018-09-19  9:04   ` Chunming Zhou
  2018-09-19  9:04   ` [PATCH 6/6] drm/amdgpu: update version for timeline syncobj support in amdgpu Chunming Zhou
  2 siblings, 0 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

syncobj wait/signal operation is appending in command submission.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |   8 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 114 +++++++++++++++++++------
 include/uapi/drm/amdgpu_drm.h          |  10 +++
 3 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 447c4c7a36d6..6e4a3db56833 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -975,6 +975,11 @@ struct amdgpu_cs_chunk {
 	void			*kdata;
 };
 
+struct amdgpu_cs_syncobj_post_dep {
+	struct drm_syncobj *post_dep_syncobj;
+	u64 point;
+};
+
 struct amdgpu_cs_parser {
 	struct amdgpu_device	*adev;
 	struct drm_file		*filp;
@@ -1003,9 +1008,8 @@ struct amdgpu_cs_parser {
 
 	/* user fence */
 	struct amdgpu_bo_list_entry	uf_entry;
-
+	struct amdgpu_cs_syncobj_post_dep *post_dep_syncobjs;
 	unsigned num_post_dep_syncobjs;
-	struct drm_syncobj **post_dep_syncobjs;
 };
 
 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 412fac238575..0efe75bf2f03 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -204,6 +204,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 		case AMDGPU_CHUNK_ID_DEPENDENCIES:
 		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
 		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
 			break;
 
 		default:
@@ -783,7 +785,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 					   &parser->validated);
 
 	for (i = 0; i < parser->num_post_dep_syncobjs; i++)
-		drm_syncobj_put(parser->post_dep_syncobjs[i]);
+		drm_syncobj_put(parser->post_dep_syncobjs[i].post_dep_syncobj);
 	kfree(parser->post_dep_syncobjs);
 
 	dma_fence_put(parser->fence);
@@ -1098,11 +1100,13 @@ static int amdgpu_cs_process_fence_dep(struct amdgpu_cs_parser *p,
 }
 
 static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
-						 uint32_t handle)
+						 uint32_t handle, u64 point,
+						 u64 flags)
 {
 	int r;
 	struct dma_fence *fence;
-	r = drm_syncobj_find_fence(p->filp, handle, 0, 0, &fence);
+
+	r = drm_syncobj_find_fence(p->filp, handle, point, flags, &fence);
 	if (r)
 		return r;
 
@@ -1113,48 +1117,91 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
 }
 
 static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser *p,
-					    struct amdgpu_cs_chunk *chunk)
+					    struct amdgpu_cs_chunk *chunk,
+					    bool timeline)
 {
 	unsigned num_deps;
 	int i, r;
-	struct drm_amdgpu_cs_chunk_sem *deps;
 
-	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
-	num_deps = chunk->length_dw * 4 /
-		sizeof(struct drm_amdgpu_cs_chunk_sem);
+	if (!timeline) {
+		struct drm_amdgpu_cs_chunk_sem *deps;
 
-	for (i = 0; i < num_deps; ++i) {
-		r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle);
+		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_sem);
+		for (i = 0; i < num_deps; ++i) {
+			r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle,
+								  0, 0);
 		if (r)
 			return r;
+		}
+	} else {
+		struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
+
+		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
+		for (i = 0; i < num_deps; ++i) {
+			r = amdgpu_syncobj_lookup_and_add_to_sync(p, syncobj_deps[i].handle,
+								  syncobj_deps[i].point,
+								  syncobj_deps[i].flags);
+		if (r)
+			return r;
+		}
 	}
+
 	return 0;
 }
 
 static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p,
-					     struct amdgpu_cs_chunk *chunk)
+					     struct amdgpu_cs_chunk *chunk,
+					     bool timeline)
 {
 	unsigned num_deps;
 	int i;
 	struct drm_amdgpu_cs_chunk_sem *deps;
-	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
-	num_deps = chunk->length_dw * 4 /
-		sizeof(struct drm_amdgpu_cs_chunk_sem);
+	struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
+
+	if (!timeline) {
+		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_sem);
+	} else {
+		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
+	}
+
 
 	p->post_dep_syncobjs = kmalloc_array(num_deps,
-					     sizeof(struct drm_syncobj *),
+					     sizeof(struct amdgpu_cs_syncobj_post_dep),
 					     GFP_KERNEL);
 	p->num_post_dep_syncobjs = 0;
 
 	if (!p->post_dep_syncobjs)
 		return -ENOMEM;
 
-	for (i = 0; i < num_deps; ++i) {
-		p->post_dep_syncobjs[i] = drm_syncobj_find(p->filp, deps[i].handle);
-		if (!p->post_dep_syncobjs[i])
-			return -EINVAL;
-		p->num_post_dep_syncobjs++;
+
+	if (!timeline) {
+		for (i = 0; i < num_deps; ++i) {
+			p->post_dep_syncobjs[i].post_dep_syncobj =
+				drm_syncobj_find(p->filp, deps[i].handle);
+			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
+				return -EINVAL;
+			p->post_dep_syncobjs[i].point = 0;
+			p->num_post_dep_syncobjs++;
+		}
+	} else {
+		for (i = 0; i < num_deps; ++i) {
+			p->post_dep_syncobjs[i].post_dep_syncobj =
+				drm_syncobj_find(p->filp, syncobj_deps[i].handle);
+			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
+				return -EINVAL;
+			p->post_dep_syncobjs[i].point = syncobj_deps[i].point;
+			p->num_post_dep_syncobjs++;
+		}
 	}
+
 	return 0;
 }
 
@@ -1168,18 +1215,32 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 
 		chunk = &p->chunks[i];
 
-		if (chunk->chunk_id == AMDGPU_CHUNK_ID_DEPENDENCIES) {
+		switch (chunk->chunk_id) {
+		case AMDGPU_CHUNK_ID_DEPENDENCIES:
 			r = amdgpu_cs_process_fence_dep(p, chunk);
 			if (r)
 				return r;
-		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_IN) {
-			r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
+			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, false);
+			if (r)
+				return r;
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
+			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, false);
 			if (r)
 				return r;
-		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_OUT) {
-			r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
+			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, true);
 			if (r)
 				return r;
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
+			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, true);
+			if (r)
+				return r;
+			break;
 		}
 	}
 
@@ -1191,7 +1252,8 @@ static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
 	int i;
 
 	for (i = 0; i < p->num_post_dep_syncobjs; ++i)
-		drm_syncobj_replace_fence(p->post_dep_syncobjs[i], 0, p->fence);
+		drm_syncobj_replace_fence(p->post_dep_syncobjs[i].post_dep_syncobj,
+					  p->post_dep_syncobjs[i].point, p->fence);
 }
 
 static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 1ceec56de015..412359b446f1 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {
 #define AMDGPU_CHUNK_ID_SYNCOBJ_IN      0x04
 #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
 #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x07
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x08
 
 struct drm_amdgpu_cs_chunk {
 	__u32		chunk_id;
@@ -592,6 +594,14 @@ struct drm_amdgpu_cs_chunk_sem {
 	__u32 handle;
 };
 
+struct drm_amdgpu_cs_chunk_syncobj {
+       __u32 handle;
+       __u32 pad;
+       __u64 point;
+       __u64 flags;
+};
+
+
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/6] drm/amdgpu: update version for timeline syncobj support in amdgpu
       [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  2018-09-19  9:04   ` [PATCH 2/6] [RFC]drm: add syncobj timeline support v7 Chunming Zhou
  2018-09-19  9:04   ` [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS Chunming Zhou
@ 2018-09-19  9:04   ` Chunming Zhou
  2 siblings, 0 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-19  9:04 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 6870909da926..58cba492ba55 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -70,9 +70,10 @@
  * - 3.25.0 - Add support for sensor query info (stable pstate sclk/mclk).
  * - 3.26.0 - GFX9: Process AMDGPU_IB_FLAG_TC_WB_NOT_INVALIDATE.
  * - 3.27.0 - Add new chunk to to AMDGPU_CS to enable BO_LIST creation.
+ * - 3.28.0 - Add syncobj timeline support to AMDGPU_CS.
  */
 #define KMS_DRIVER_MAJOR	3
-#define KMS_DRIVER_MINOR	27
+#define KMS_DRIVER_MINOR	28
 #define KMS_DRIVER_PATCHLEVEL	0
 
 int amdgpu_vram_limit = 0;
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* RE: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found]         ` <c5c3e0c6-1f6d-e3a3-f9bb-0c7cef10b0f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-08  3:45           ` Zhou, David(ChunMing)
  0 siblings, 0 replies; 12+ messages in thread
From: Zhou, David(ChunMing) @ 2018-10-08  3:45 UTC (permalink / raw)
  To: Nicolai Hähnle, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



> -----Original Message-----
> From: Nicolai Hähnle <nhaehnle@gmail.com>
> Sent: Wednesday, September 26, 2018 4:44 PM
> To: Zhou, David(ChunMing) <David1.Zhou@amd.com>; dri-
> devel@lists.freedesktop.org
> Cc: amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
> 
> >   static int amdgpu_cs_submit(struct amdgpu_cs_parser *p, diff --git
> > a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index
> > 1ceec56de015..412359b446f1 100644
> > --- a/include/uapi/drm/amdgpu_drm.h
> > +++ b/include/uapi/drm/amdgpu_drm.h
> > @@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {
> >   #define AMDGPU_CHUNK_ID_SYNCOBJ_IN      0x04
> >   #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
> >   #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
> > +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x07
> > +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x08
> >
> >   struct drm_amdgpu_cs_chunk {
> >   	__u32		chunk_id;
> > @@ -592,6 +594,14 @@ struct drm_amdgpu_cs_chunk_sem {
> >   	__u32 handle;
> >   };
> >
> > +struct drm_amdgpu_cs_chunk_syncobj {
> > +       __u32 handle;
> > +       __u32 pad;
> > +       __u64 point;
> > +       __u64 flags;
> > +};
> 
> Sure it's nice to be forward-looking, but can't we just put the flags into the
> padding?

Will change.

Thanks,
David
> 
> Cheers,
> Nicolai
> 
> 
> > +
> > +
> >   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
> >   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
> >   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2
> >
> 
> 
> --
> Lerne, wie die Welt wirklich ist,
> Aber vergiss niemals, wie sie sein sollte.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found]         ` <3577a9cb-dd33-6014-eb01-248af91df97f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2018-10-08  3:38           ` Zhou, David(ChunMing)
  0 siblings, 0 replies; 12+ messages in thread
From: Zhou, David(ChunMing) @ 2018-10-08  3:38 UTC (permalink / raw)
  To: Nicolai Hähnle, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



> -----Original Message-----
> From: Nicolai Hähnle <nhaehnle@gmail.com>
> Sent: Wednesday, September 26, 2018 5:06 PM
> To: Zhou, David(ChunMing) <David1.Zhou@amd.com>; dri-
> devel@lists.freedesktop.org
> Cc: amd-gfx@lists.freedesktop.org
> Subject: Re: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
> 
> Hey Chunming,
> 
> On 20.09.2018 13:03, Chunming Zhou wrote:
> > @@ -1113,48 +1117,91 @@ static int
> amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
> >   }
> >
> >   static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser
> *p,
> > -					    struct amdgpu_cs_chunk *chunk)
> > +					    struct amdgpu_cs_chunk *chunk,
> > +					    bool timeline)
> >   {
> >   	unsigned num_deps;
> >   	int i, r;
> > -	struct drm_amdgpu_cs_chunk_sem *deps;
> >
> > -	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> > -	num_deps = chunk->length_dw * 4 /
> > -		sizeof(struct drm_amdgpu_cs_chunk_sem);
> > +	if (!timeline) {
> > +		struct drm_amdgpu_cs_chunk_sem *deps;
> >
> > -	for (i = 0; i < num_deps; ++i) {
> > -		r = amdgpu_syncobj_lookup_and_add_to_sync(p,
> deps[i].handle);
> > +		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> > +		num_deps = chunk->length_dw * 4 /
> > +			sizeof(struct drm_amdgpu_cs_chunk_sem);
> > +		for (i = 0; i < num_deps; ++i) {
> > +			r = amdgpu_syncobj_lookup_and_add_to_sync(p,
> deps[i].handle,
> > +								  0, 0);
> >   		if (r)
> >   			return r;
> 
> The indentation looks wrong.
> 
> 
> > +		}
> > +	} else {
> > +		struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
> > +
> > +		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj
> *)chunk->kdata;
> > +		num_deps = chunk->length_dw * 4 /
> > +			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
> > +		for (i = 0; i < num_deps; ++i) {
> > +			r = amdgpu_syncobj_lookup_and_add_to_sync(p,
> syncobj_deps[i].handle,
> > +
> syncobj_deps[i].point,
> > +
> syncobj_deps[i].flags);
> > +		if (r)
> > +			return r;
> 
> Here as well.
> 
> So I'm wondering a bit about this uapi. Specifically, what happens if you try to
> use timeline syncobjs here as dependencies _without_
> DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT?
> 
> My understanding is, it'll just return -EINVAL without any indication as to
> which syncobj actually failed. What's the caller supposed to do then?

How about adding a print to indicate which syncobj failed?

Thanks,
David Zhou
> 
> Cheers,
> Nicolai
> --
> Lerne, wie die Welt wirklich ist,
> Aber vergiss niemals, wie sie sein sollte.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found]     ` <20180920110353.16114-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  2018-09-26  8:44       ` Nicolai Hähnle
@ 2018-09-26  9:06       ` Nicolai Hähnle
       [not found]         ` <3577a9cb-dd33-6014-eb01-248af91df97f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Nicolai Hähnle @ 2018-09-26  9:06 UTC (permalink / raw)
  To: Chunming Zhou, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Hey Chunming,

On 20.09.2018 13:03, Chunming Zhou wrote:
> @@ -1113,48 +1117,91 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
>   }
>   
>   static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser *p,
> -					    struct amdgpu_cs_chunk *chunk)
> +					    struct amdgpu_cs_chunk *chunk,
> +					    bool timeline)
>   {
>   	unsigned num_deps;
>   	int i, r;
> -	struct drm_amdgpu_cs_chunk_sem *deps;
>   
> -	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> -	num_deps = chunk->length_dw * 4 /
> -		sizeof(struct drm_amdgpu_cs_chunk_sem);
> +	if (!timeline) {
> +		struct drm_amdgpu_cs_chunk_sem *deps;
>   
> -	for (i = 0; i < num_deps; ++i) {
> -		r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle);
> +		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_sem);
> +		for (i = 0; i < num_deps; ++i) {
> +			r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle,
> +								  0, 0);
>   		if (r)
>   			return r;

The indentation looks wrong.


> +		}
> +	} else {
> +		struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
> +
> +		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
> +		for (i = 0; i < num_deps; ++i) {
> +			r = amdgpu_syncobj_lookup_and_add_to_sync(p, syncobj_deps[i].handle,
> +								  syncobj_deps[i].point,
> +								  syncobj_deps[i].flags);
> +		if (r)
> +			return r;

Here as well.

So I'm wondering a bit about this uapi. Specifically, what happens if 
you try to use timeline syncobjs here as dependencies _without_ 
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT?

My understanding is, it'll just return -EINVAL without any indication as 
to which syncobj actually failed. What's the caller supposed to do then?

Cheers,
Nicolai
-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found]     ` <20180920110353.16114-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-26  8:44       ` Nicolai Hähnle
       [not found]         ` <c5c3e0c6-1f6d-e3a3-f9bb-0c7cef10b0f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2018-09-26  9:06       ` Nicolai Hähnle
  1 sibling, 1 reply; 12+ messages in thread
From: Nicolai Hähnle @ 2018-09-26  8:44 UTC (permalink / raw)
  To: Chunming Zhou, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

>   static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index 1ceec56de015..412359b446f1 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {
>   #define AMDGPU_CHUNK_ID_SYNCOBJ_IN      0x04
>   #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
>   #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
> +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x07
> +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x08
>   
>   struct drm_amdgpu_cs_chunk {
>   	__u32		chunk_id;
> @@ -592,6 +594,14 @@ struct drm_amdgpu_cs_chunk_sem {
>   	__u32 handle;
>   };
>   
> +struct drm_amdgpu_cs_chunk_syncobj {
> +       __u32 handle;
> +       __u32 pad;
> +       __u64 point;
> +       __u64 flags;
> +};

Sure it's nice to be forward-looking, but can't we just put the flags 
into the padding?

Cheers,
Nicolai


> +
> +
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2
> 


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
  2018-09-20 11:03   ` [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS Chunming Zhou
@ 2018-09-24 10:25     ` Christian König
       [not found]     ` <20180920110353.16114-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  1 sibling, 0 replies; 12+ messages in thread
From: Christian König @ 2018-09-24 10:25 UTC (permalink / raw)
  To: Chunming Zhou, dri-devel; +Cc: amd-gfx

Am 20.09.2018 um 13:03 schrieb Chunming Zhou:
> syncobj wait/signal operation is appending in command submission.
>
> Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu.h    |   8 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 114 +++++++++++++++++++------
>   include/uapi/drm/amdgpu_drm.h          |  10 +++
>   3 files changed, 104 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 447c4c7a36d6..6e4a3db56833 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -975,6 +975,11 @@ struct amdgpu_cs_chunk {
>   	void			*kdata;
>   };
>   
> +struct amdgpu_cs_syncobj_post_dep {
> +	struct drm_syncobj *post_dep_syncobj;
> +	u64 point;
> +};
> +
>   struct amdgpu_cs_parser {
>   	struct amdgpu_device	*adev;
>   	struct drm_file		*filp;
> @@ -1003,9 +1008,8 @@ struct amdgpu_cs_parser {
>   
>   	/* user fence */
>   	struct amdgpu_bo_list_entry	uf_entry;
> -
> +	struct amdgpu_cs_syncobj_post_dep *post_dep_syncobjs;
>   	unsigned num_post_dep_syncobjs;
> -	struct drm_syncobj **post_dep_syncobjs;
>   };
>   
>   static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index 412fac238575..0efe75bf2f03 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -204,6 +204,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
>   		case AMDGPU_CHUNK_ID_DEPENDENCIES:
>   		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
>   		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
>   			break;
>   
>   		default:
> @@ -783,7 +785,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
>   					   &parser->validated);
>   
>   	for (i = 0; i < parser->num_post_dep_syncobjs; i++)
> -		drm_syncobj_put(parser->post_dep_syncobjs[i]);
> +		drm_syncobj_put(parser->post_dep_syncobjs[i].post_dep_syncobj);
>   	kfree(parser->post_dep_syncobjs);
>   
>   	dma_fence_put(parser->fence);
> @@ -1098,11 +1100,13 @@ static int amdgpu_cs_process_fence_dep(struct amdgpu_cs_parser *p,
>   }
>   
>   static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
> -						 uint32_t handle)
> +						 uint32_t handle, u64 point,
> +						 u64 flags)
>   {
>   	int r;
>   	struct dma_fence *fence;
> -	r = drm_syncobj_find_fence(p->filp, handle, 0, 0, &fence);
> +
> +	r = drm_syncobj_find_fence(p->filp, handle, point, flags, &fence);
>   	if (r)
>   		return r;
>   
> @@ -1113,48 +1117,91 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
>   }
>   
>   static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser *p,
> -					    struct amdgpu_cs_chunk *chunk)
> +					    struct amdgpu_cs_chunk *chunk,
> +					    bool timeline)

You should really just duplicate the function. The only think you have 
in common here is allocating the post_dep_sync objects.

Would also prevent that we need to make the two chunk types mutual 
exclusive.

Christian.

>   {
>   	unsigned num_deps;
>   	int i, r;
> -	struct drm_amdgpu_cs_chunk_sem *deps;
>   
> -	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> -	num_deps = chunk->length_dw * 4 /
> -		sizeof(struct drm_amdgpu_cs_chunk_sem);
> +	if (!timeline) {
> +		struct drm_amdgpu_cs_chunk_sem *deps;
>   
> -	for (i = 0; i < num_deps; ++i) {
> -		r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle);
> +		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_sem);
> +		for (i = 0; i < num_deps; ++i) {
> +			r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle,
> +								  0, 0);
>   		if (r)
>   			return r;
> +		}
> +	} else {
> +		struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
> +
> +		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
> +		for (i = 0; i < num_deps; ++i) {
> +			r = amdgpu_syncobj_lookup_and_add_to_sync(p, syncobj_deps[i].handle,
> +								  syncobj_deps[i].point,
> +								  syncobj_deps[i].flags);
> +		if (r)
> +			return r;
> +		}
>   	}
> +
>   	return 0;
>   }
>   
>   static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p,
> -					     struct amdgpu_cs_chunk *chunk)
> +					     struct amdgpu_cs_chunk *chunk,
> +					     bool timeline)
>   {
>   	unsigned num_deps;
>   	int i;
>   	struct drm_amdgpu_cs_chunk_sem *deps;
> -	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> -	num_deps = chunk->length_dw * 4 /
> -		sizeof(struct drm_amdgpu_cs_chunk_sem);
> +	struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
> +
> +	if (!timeline) {
> +		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_sem);
> +	} else {
> +		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
> +		num_deps = chunk->length_dw * 4 /
> +			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
> +	}
> +
>   
>   	p->post_dep_syncobjs = kmalloc_array(num_deps,
> -					     sizeof(struct drm_syncobj *),
> +					     sizeof(struct amdgpu_cs_syncobj_post_dep),
>   					     GFP_KERNEL);
>   	p->num_post_dep_syncobjs = 0;
>   
>   	if (!p->post_dep_syncobjs)
>   		return -ENOMEM;
>   
> -	for (i = 0; i < num_deps; ++i) {
> -		p->post_dep_syncobjs[i] = drm_syncobj_find(p->filp, deps[i].handle);
> -		if (!p->post_dep_syncobjs[i])
> -			return -EINVAL;
> -		p->num_post_dep_syncobjs++;
> +
> +	if (!timeline) {
> +		for (i = 0; i < num_deps; ++i) {
> +			p->post_dep_syncobjs[i].post_dep_syncobj =
> +				drm_syncobj_find(p->filp, deps[i].handle);
> +			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
> +				return -EINVAL;
> +			p->post_dep_syncobjs[i].point = 0;
> +			p->num_post_dep_syncobjs++;
> +		}
> +	} else {
> +		for (i = 0; i < num_deps; ++i) {
> +			p->post_dep_syncobjs[i].post_dep_syncobj =
> +				drm_syncobj_find(p->filp, syncobj_deps[i].handle);
> +			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
> +				return -EINVAL;
> +			p->post_dep_syncobjs[i].point = syncobj_deps[i].point;
> +			p->num_post_dep_syncobjs++;
> +		}
>   	}
> +
>   	return 0;
>   }
>   
> @@ -1168,18 +1215,32 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
>   
>   		chunk = &p->chunks[i];
>   
> -		if (chunk->chunk_id == AMDGPU_CHUNK_ID_DEPENDENCIES) {
> +		switch (chunk->chunk_id) {
> +		case AMDGPU_CHUNK_ID_DEPENDENCIES:
>   			r = amdgpu_cs_process_fence_dep(p, chunk);
>   			if (r)
>   				return r;
> -		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_IN) {
> -			r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
> +			break;
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
> +			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, false);
> +			if (r)
> +				return r;
> +			break;
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
> +			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, false);
>   			if (r)
>   				return r;
> -		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_OUT) {
> -			r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
> +			break;
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
> +			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, true);
>   			if (r)
>   				return r;
> +			break;
> +		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
> +			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, true);
> +			if (r)
> +				return r;
> +			break;
>   		}
>   	}
>   
> @@ -1191,7 +1252,8 @@ static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
>   	int i;
>   
>   	for (i = 0; i < p->num_post_dep_syncobjs; ++i)
> -		drm_syncobj_replace_fence(p->post_dep_syncobjs[i], 0, p->fence);
> +		drm_syncobj_replace_fence(p->post_dep_syncobjs[i].post_dep_syncobj,
> +					  p->post_dep_syncobjs[i].point, p->fence);
>   }
>   
>   static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index 1ceec56de015..412359b446f1 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {
>   #define AMDGPU_CHUNK_ID_SYNCOBJ_IN      0x04
>   #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
>   #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
> +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x07
> +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x08
>   
>   struct drm_amdgpu_cs_chunk {
>   	__u32		chunk_id;
> @@ -592,6 +594,14 @@ struct drm_amdgpu_cs_chunk_sem {
>   	__u32 handle;
>   };
>   
> +struct drm_amdgpu_cs_chunk_syncobj {
> +       __u32 handle;
> +       __u32 pad;
> +       __u64 point;
> +       __u64 flags;
> +};
> +
> +
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
>   #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS
       [not found] ` <20180920110353.16114-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
@ 2018-09-20 11:03   ` Chunming Zhou
  2018-09-24 10:25     ` Christian König
       [not found]     ` <20180920110353.16114-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
  0 siblings, 2 replies; 12+ messages in thread
From: Chunming Zhou @ 2018-09-20 11:03 UTC (permalink / raw)
  To: dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: Chunming Zhou, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

syncobj wait/signal operation is appending in command submission.

Signed-off-by: Chunming Zhou <david1.zhou@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h    |   8 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 114 +++++++++++++++++++------
 include/uapi/drm/amdgpu_drm.h          |  10 +++
 3 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 447c4c7a36d6..6e4a3db56833 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -975,6 +975,11 @@ struct amdgpu_cs_chunk {
 	void			*kdata;
 };
 
+struct amdgpu_cs_syncobj_post_dep {
+	struct drm_syncobj *post_dep_syncobj;
+	u64 point;
+};
+
 struct amdgpu_cs_parser {
 	struct amdgpu_device	*adev;
 	struct drm_file		*filp;
@@ -1003,9 +1008,8 @@ struct amdgpu_cs_parser {
 
 	/* user fence */
 	struct amdgpu_bo_list_entry	uf_entry;
-
+	struct amdgpu_cs_syncobj_post_dep *post_dep_syncobjs;
 	unsigned num_post_dep_syncobjs;
-	struct drm_syncobj **post_dep_syncobjs;
 };
 
 static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 412fac238575..0efe75bf2f03 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -204,6 +204,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 		case AMDGPU_CHUNK_ID_DEPENDENCIES:
 		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
 		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
 			break;
 
 		default:
@@ -783,7 +785,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,
 					   &parser->validated);
 
 	for (i = 0; i < parser->num_post_dep_syncobjs; i++)
-		drm_syncobj_put(parser->post_dep_syncobjs[i]);
+		drm_syncobj_put(parser->post_dep_syncobjs[i].post_dep_syncobj);
 	kfree(parser->post_dep_syncobjs);
 
 	dma_fence_put(parser->fence);
@@ -1098,11 +1100,13 @@ static int amdgpu_cs_process_fence_dep(struct amdgpu_cs_parser *p,
 }
 
 static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
-						 uint32_t handle)
+						 uint32_t handle, u64 point,
+						 u64 flags)
 {
 	int r;
 	struct dma_fence *fence;
-	r = drm_syncobj_find_fence(p->filp, handle, 0, 0, &fence);
+
+	r = drm_syncobj_find_fence(p->filp, handle, point, flags, &fence);
 	if (r)
 		return r;
 
@@ -1113,48 +1117,91 @@ static int amdgpu_syncobj_lookup_and_add_to_sync(struct amdgpu_cs_parser *p,
 }
 
 static int amdgpu_cs_process_syncobj_in_dep(struct amdgpu_cs_parser *p,
-					    struct amdgpu_cs_chunk *chunk)
+					    struct amdgpu_cs_chunk *chunk,
+					    bool timeline)
 {
 	unsigned num_deps;
 	int i, r;
-	struct drm_amdgpu_cs_chunk_sem *deps;
 
-	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
-	num_deps = chunk->length_dw * 4 /
-		sizeof(struct drm_amdgpu_cs_chunk_sem);
+	if (!timeline) {
+		struct drm_amdgpu_cs_chunk_sem *deps;
 
-	for (i = 0; i < num_deps; ++i) {
-		r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle);
+		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_sem);
+		for (i = 0; i < num_deps; ++i) {
+			r = amdgpu_syncobj_lookup_and_add_to_sync(p, deps[i].handle,
+								  0, 0);
 		if (r)
 			return r;
+		}
+	} else {
+		struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
+
+		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
+		for (i = 0; i < num_deps; ++i) {
+			r = amdgpu_syncobj_lookup_and_add_to_sync(p, syncobj_deps[i].handle,
+								  syncobj_deps[i].point,
+								  syncobj_deps[i].flags);
+		if (r)
+			return r;
+		}
 	}
+
 	return 0;
 }
 
 static int amdgpu_cs_process_syncobj_out_dep(struct amdgpu_cs_parser *p,
-					     struct amdgpu_cs_chunk *chunk)
+					     struct amdgpu_cs_chunk *chunk,
+					     bool timeline)
 {
 	unsigned num_deps;
 	int i;
 	struct drm_amdgpu_cs_chunk_sem *deps;
-	deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
-	num_deps = chunk->length_dw * 4 /
-		sizeof(struct drm_amdgpu_cs_chunk_sem);
+	struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps;
+
+	if (!timeline) {
+		deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_sem);
+	} else {
+		syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata;
+		num_deps = chunk->length_dw * 4 /
+			sizeof(struct drm_amdgpu_cs_chunk_syncobj);
+	}
+
 
 	p->post_dep_syncobjs = kmalloc_array(num_deps,
-					     sizeof(struct drm_syncobj *),
+					     sizeof(struct amdgpu_cs_syncobj_post_dep),
 					     GFP_KERNEL);
 	p->num_post_dep_syncobjs = 0;
 
 	if (!p->post_dep_syncobjs)
 		return -ENOMEM;
 
-	for (i = 0; i < num_deps; ++i) {
-		p->post_dep_syncobjs[i] = drm_syncobj_find(p->filp, deps[i].handle);
-		if (!p->post_dep_syncobjs[i])
-			return -EINVAL;
-		p->num_post_dep_syncobjs++;
+
+	if (!timeline) {
+		for (i = 0; i < num_deps; ++i) {
+			p->post_dep_syncobjs[i].post_dep_syncobj =
+				drm_syncobj_find(p->filp, deps[i].handle);
+			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
+				return -EINVAL;
+			p->post_dep_syncobjs[i].point = 0;
+			p->num_post_dep_syncobjs++;
+		}
+	} else {
+		for (i = 0; i < num_deps; ++i) {
+			p->post_dep_syncobjs[i].post_dep_syncobj =
+				drm_syncobj_find(p->filp, syncobj_deps[i].handle);
+			if (!p->post_dep_syncobjs[i].post_dep_syncobj)
+				return -EINVAL;
+			p->post_dep_syncobjs[i].point = syncobj_deps[i].point;
+			p->num_post_dep_syncobjs++;
+		}
 	}
+
 	return 0;
 }
 
@@ -1168,18 +1215,32 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,
 
 		chunk = &p->chunks[i];
 
-		if (chunk->chunk_id == AMDGPU_CHUNK_ID_DEPENDENCIES) {
+		switch (chunk->chunk_id) {
+		case AMDGPU_CHUNK_ID_DEPENDENCIES:
 			r = amdgpu_cs_process_fence_dep(p, chunk);
 			if (r)
 				return r;
-		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_IN) {
-			r = amdgpu_cs_process_syncobj_in_dep(p, chunk);
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
+			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, false);
+			if (r)
+				return r;
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
+			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, false);
 			if (r)
 				return r;
-		} else if (chunk->chunk_id == AMDGPU_CHUNK_ID_SYNCOBJ_OUT) {
-			r = amdgpu_cs_process_syncobj_out_dep(p, chunk);
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
+			r = amdgpu_cs_process_syncobj_in_dep(p, chunk, true);
 			if (r)
 				return r;
+			break;
+		case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
+			r = amdgpu_cs_process_syncobj_out_dep(p, chunk, true);
+			if (r)
+				return r;
+			break;
 		}
 	}
 
@@ -1191,7 +1252,8 @@ static void amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
 	int i;
 
 	for (i = 0; i < p->num_post_dep_syncobjs; ++i)
-		drm_syncobj_replace_fence(p->post_dep_syncobjs[i], 0, p->fence);
+		drm_syncobj_replace_fence(p->post_dep_syncobjs[i].post_dep_syncobj,
+					  p->post_dep_syncobjs[i].point, p->fence);
 }
 
 static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 1ceec56de015..412359b446f1 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {
 #define AMDGPU_CHUNK_ID_SYNCOBJ_IN      0x04
 #define AMDGPU_CHUNK_ID_SYNCOBJ_OUT     0x05
 #define AMDGPU_CHUNK_ID_BO_HANDLES      0x06
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT    0x07
+#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL  0x08
 
 struct drm_amdgpu_cs_chunk {
 	__u32		chunk_id;
@@ -592,6 +594,14 @@ struct drm_amdgpu_cs_chunk_sem {
 	__u32 handle;
 };
 
+struct drm_amdgpu_cs_chunk_syncobj {
+       __u32 handle;
+       __u32 pad;
+       __u64 point;
+       __u64 flags;
+};
+
+
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ	0
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD	1
 #define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD	2
-- 
2.17.1

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-10-08  3:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19  9:04 [PATCH 1/6] drm: add flags to drm_syncobj_find_fence Chunming Zhou
     [not found] ` <20180919090407.24111-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-09-19  9:04   ` [PATCH 2/6] [RFC]drm: add syncobj timeline support v7 Chunming Zhou
2018-09-19  9:04   ` [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS Chunming Zhou
2018-09-19  9:04   ` [PATCH 6/6] drm/amdgpu: update version for timeline syncobj support in amdgpu Chunming Zhou
2018-09-19  9:04 ` [PATCH 3/6] drm: add support of syncobj timeline point wait v2 Chunming Zhou
2018-09-19  9:04 ` [PATCH 4/6] drm: add timeline syncobj payload query ioctl Chunming Zhou
2018-09-20 11:03 [PATCH 1/6] drm: add flags to drm_syncobj_find_fence Chunming Zhou
     [not found] ` <20180920110353.16114-1-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-09-20 11:03   ` [PATCH 5/6] drm/amdgpu: add timeline support in amdgpu CS Chunming Zhou
2018-09-24 10:25     ` Christian König
     [not found]     ` <20180920110353.16114-5-david1.zhou-5C7GfCeVMHo@public.gmane.org>
2018-09-26  8:44       ` Nicolai Hähnle
     [not found]         ` <c5c3e0c6-1f6d-e3a3-f9bb-0c7cef10b0f5-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-08  3:45           ` Zhou, David(ChunMing)
2018-09-26  9:06       ` Nicolai Hähnle
     [not found]         ` <3577a9cb-dd33-6014-eb01-248af91df97f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-10-08  3:38           ` Zhou, David(ChunMing)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.