Skip to content

Commit bc9c80f

Browse files
Christian KönigChristianKoenigAMD
authored andcommitted
drm/syncobj: use the timeline point in drm_syncobj_find_fence v4
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> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Link: https://patchwork.freedesktop.org/patch/295786/?series=58813&rev=1
1 parent 27b575a commit bc9c80f

1 file changed

Lines changed: 47 additions & 3 deletions

File tree

‎drivers/gpu/drm/drm_syncobj.c‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ static void drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
214214
dma_fence_put(fence);
215215
}
216216

217+
/* 5s default for wait submission */
218+
#define DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT 5000000000ULL
217219
/**
218220
* drm_syncobj_find_fence - lookup and reference the fence in a sync object
219221
* @file_private: drm file private pointer
@@ -234,16 +236,58 @@ int drm_syncobj_find_fence(struct drm_file *file_private,
234236
struct dma_fence **fence)
235237
{
236238
struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle);
237-
int ret = 0;
239+
struct syncobj_wait_entry wait;
240+
u64 timeout = nsecs_to_jiffies64(DRM_SYNCOBJ_WAIT_FOR_SUBMIT_TIMEOUT);
241+
int ret;
238242

239243
if (!syncobj)
240244
return -ENOENT;
241245

242246
*fence = drm_syncobj_fence_get(syncobj);
243-
if (!*fence) {
247+
drm_syncobj_put(syncobj);
248+
249+
if (*fence) {
250+
ret = dma_fence_chain_find_seqno(fence, point);
251+
if (!ret)
252+
return 0;
253+
dma_fence_put(*fence);
254+
} else {
244255
ret = -EINVAL;
245256
}
246-
drm_syncobj_put(syncobj);
257+
258+
if (!(flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))
259+
return ret;
260+
261+
memset(&wait, 0, sizeof(wait));
262+
wait.task = current;
263+
wait.point = point;
264+
drm_syncobj_fence_add_wait(syncobj, &wait);
265+
266+
do {
267+
set_current_state(TASK_INTERRUPTIBLE);
268+
if (wait.fence) {
269+
ret = 0;
270+
break;
271+
}
272+
if (timeout == 0) {
273+
ret = -ETIME;
274+
break;
275+
}
276+
277+
if (signal_pending(current)) {
278+
ret = -ERESTARTSYS;
279+
break;
280+
}
281+
282+
timeout = schedule_timeout(timeout);
283+
} while (1);
284+
285+
__set_current_state(TASK_RUNNING);
286+
*fence = wait.fence;
287+
288+
if (wait.node.next)
289+
drm_syncobj_remove_wait(syncobj, &wait);
290+
247291
return ret;
248292
}
249293
EXPORT_SYMBOL(drm_syncobj_find_fence);

0 commit comments

Comments
 (0)