diff mbox series

[5/9] drm/syncobj: use the timeline point in drm_syncobj_find_fence v3

Message ID 20190315120959.25489-5-david1.zhou@amd.com (mailing list archive)
State New, archived
Headers show
Series [1/9] dma-buf: add new dma_fence_chain container v5 | expand

Commit Message

Chunming Zhou March 15, 2019, 12:09 p.m. UTC
From: Christian König <ckoenig.leichtzumerken@gmail.com>

Implement finding the right timeline point in drm_syncobj_find_fence.

v2: return -EINVAL when the point is not submitted yet.
v3: fix reference counting bug, add flags handling as well
v4: add timeout for find fence

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/gpu/drm/drm_syncobj.c | 50 ++++++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 3 deletions(-)

Comments

kernel test robot March 16, 2019, 1:10 a.m. UTC | #1
Hi Chunming,

I love your patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on next-20190306]
[cannot apply to v5.0]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Chunming-Zhou/dma-buf-add-new-dma_fence_chain-container-v5/20190316-055452
reproduce:
        # apt-get install sparse
        make ARCH=x86_64 allmodconfig
        make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'


sparse warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/drm_syncobj.c:239:42: sparse: constant 5000000000 is so big it is long
   include/linux/slab.h:664:13: sparse: undefined identifier '__builtin_mul_overflow'
   include/linux/slab.h:664:13: sparse: not a function <noident>
   include/linux/slab.h:664:13: sparse: not a function <noident>
   include/linux/slab.h:664:13: sparse: not a function <noident>
   include/linux/slab.h:664:13: sparse: call with no type!

vim +239 drivers/gpu/drm/drm_syncobj.c

   215	
   216	/* 5s */
   217	#define DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT 5000000000
   218	/**
   219	 * drm_syncobj_find_fence - lookup and reference the fence in a sync object
   220	 * @file_private: drm file private pointer
   221	 * @handle: sync object handle to lookup.
   222	 * @point: timeline point
   223	 * @flags: DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT or not
   224	 * @fence: out parameter for the fence
   225	 *
   226	 * This is just a convenience function that combines drm_syncobj_find() and
   227	 * drm_syncobj_fence_get().
   228	 *
   229	 * Returns 0 on success or a negative error value on failure. On success @fence
   230	 * contains a reference to the fence, which must be released by calling
   231	 * dma_fence_put().
   232	 */
   233	int drm_syncobj_find_fence(struct drm_file *file_private,
   234				   u32 handle, u64 point, u64 flags,
   235				   struct dma_fence **fence)
   236	{
   237		struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
   238		struct syncobj_wait_entry wait;
 > 239		u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT);
   240		int ret;
   241	
   242		if (!syncobj)
   243			return -ENOENT;
   244	
   245		*fence = drm_syncobj_fence_get(syncobj);
   246		drm_syncobj_put(syncobj);
   247	
   248		if (*fence) {
   249			ret = dma_fence_chain_find_seqno(fence, point);
   250			if (!ret)
   251				return 0;
   252			dma_fence_put(*fence);
   253		} else {
   254			ret = -EINVAL;
   255		}
   256	
   257		if (!(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
   258			return ret;
   259	
   260		memset(&wait, 0, sizeof(wait));
   261		wait.task = current;
   262		wait.point = point;
   263		drm_syncobj_fence_add_wait(syncobj, &wait);
   264	
   265		do {
   266			set_current_state(TASK_INTERRUPTIBLE);
   267			if (wait.fence) {
   268				ret = 0;
   269				break;
   270			}
   271	                if (timeout == 0) {
   272	                        ret = -ETIME;
   273	                        break;
   274	                }
   275	
   276			if (signal_pending(current)) {
   277				ret = -ERESTARTSYS;
   278				break;
   279			}
   280	
   281	                timeout = schedule_timeout(timeout);
   282		} while (1);
   283	
   284		__set_current_state(TASK_RUNNING);
   285		*fence = wait.fence;
   286	
   287		if (wait.node.next)
   288			drm_syncobj_remove_wait(syncobj, &wait);
   289	
   290		return ret;
   291	}
   292	EXPORT_SYMBOL(drm_syncobj_find_fence);
   293	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c
index 0e62a793c8dd..dd19c47d0b44 100644
--- a/drivers/gpu/drm/drm_syncobj.c
+++ b/drivers/gpu/drm/drm_syncobj.c
@@ -213,6 +213,8 @@  static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
 	dma_fence_put(fence);
 }
 
+/* 5s */
+#define DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT 5000000000
 /**
  * drm_syncobj_find_fence - lookup and reference the fence in a sync object
  * @file_private: drm file private pointer
@@ -233,16 +235,58 @@  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;
+	struct syncobj_wait_entry wait;
+	u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT);
+	int ret;
 
 	if (!syncobj)
 		return -ENOENT;
 
 	*fence = drm_syncobj_fence_get(syncobj);
-	if (!*fence) {
+	drm_syncobj_put(syncobj);
+
+	if (*fence) {
+		ret = dma_fence_chain_find_seqno(fence, point);
+		if (!ret)
+			return 0;
+		dma_fence_put(*fence);
+	} else {
 		ret = -EINVAL;
 	}
-	drm_syncobj_put(syncobj);
+
+	if (!(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
+		return ret;
+
+	memset(&wait, 0, sizeof(wait));
+	wait.task = current;
+	wait.point = point;
+	drm_syncobj_fence_add_wait(syncobj, &wait);
+
+	do {
+		set_current_state(TASK_INTERRUPTIBLE);
+		if (wait.fence) {
+			ret = 0;
+			break;
+		}
+                if (timeout == 0) {
+                        ret = -ETIME;
+                        break;
+                }
+
+		if (signal_pending(current)) {
+			ret = -ERESTARTSYS;
+			break;
+		}
+
+                timeout = schedule_timeout(timeout);
+	} while (1);
+
+	__set_current_state(TASK_RUNNING);
+	*fence = wait.fence;
+
+	if (wait.node.next)
+		drm_syncobj_remove_wait(syncobj, &wait);
+
 	return ret;
 }
 EXPORT_SYMBOL(drm_syncobj_find_fence);