Commit 8570c279 authored by Rob Clark's avatar Rob Clark Committed by Dmitry Baryshkov

drm/syncobj: Add deadline support for syncobj waits

Add a new flag to let userspace provide a deadline as a hint for syncobj
and timeline waits.  This gives a hint to the driver signaling the
backing fences about how soon userspace needs it to compete work, so it
can adjust GPU frequency accordingly.  An immediate deadline can be
given to provide something equivalent to i915 "wait boost".

v2: Use absolute u64 ns value for deadline hint, drop cap and driver
    feature flag in favor of allowing count_handles==0 as a way for
    userspace to probe kernel for support of new flag
v3: More verbose comments about UAPI
v4: Fix negative zero, s/deadline_ns/deadline_nsec/ for consistency with
    existing ioctl struct fields
v5: Comment/description typo fixes
Signed-off-by: default avatarRob Clark <robdclark@chromium.org>
Reviewed-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
[DB: fixed checkpatch warnings]
Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20230823215458.203366-2-robdclark@gmail.com
parent 5f0a0ebc
...@@ -126,6 +126,11 @@ ...@@ -126,6 +126,11 @@
* synchronize between the two. * synchronize between the two.
* This requirement is inherited from the Vulkan fence API. * This requirement is inherited from the Vulkan fence API.
* *
* If &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE is set, the ioctl will also set
* a fence deadline hint on the backing fences before waiting, to provide the
* fence signaler with an appropriate sense of urgency. The deadline is
* specified as an absolute &CLOCK_MONOTONIC value in units of ns.
*
* Similarly, &DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT takes an array of syncobj * Similarly, &DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT takes an array of syncobj
* handles as well as an array of u64 points and does a host-side wait on all * handles as well as an array of u64 points and does a host-side wait on all
* of syncobj fences at the given points simultaneously. * of syncobj fences at the given points simultaneously.
...@@ -1027,7 +1032,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, ...@@ -1027,7 +1032,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
uint32_t count, uint32_t count,
uint32_t flags, uint32_t flags,
signed long timeout, signed long timeout,
uint32_t *idx) uint32_t *idx,
ktime_t *deadline)
{ {
struct syncobj_wait_entry *entries; struct syncobj_wait_entry *entries;
struct dma_fence *fence; struct dma_fence *fence;
...@@ -1108,6 +1114,15 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, ...@@ -1108,6 +1114,15 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,
drm_syncobj_fence_add_wait(syncobjs[i], &entries[i]); drm_syncobj_fence_add_wait(syncobjs[i], &entries[i]);
} }
if (deadline) {
for (i = 0; i < count; ++i) {
fence = entries[i].fence;
if (!fence)
continue;
dma_fence_set_deadline(fence, *deadline);
}
}
do { do {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
...@@ -1206,7 +1221,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, ...@@ -1206,7 +1221,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
struct drm_file *file_private, struct drm_file *file_private,
struct drm_syncobj_wait *wait, struct drm_syncobj_wait *wait,
struct drm_syncobj_timeline_wait *timeline_wait, struct drm_syncobj_timeline_wait *timeline_wait,
struct drm_syncobj **syncobjs, bool timeline) struct drm_syncobj **syncobjs, bool timeline,
ktime_t *deadline)
{ {
signed long timeout = 0; signed long timeout = 0;
uint32_t first = ~0; uint32_t first = ~0;
...@@ -1217,7 +1233,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, ...@@ -1217,7 +1233,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
NULL, NULL,
wait->count_handles, wait->count_handles,
wait->flags, wait->flags,
timeout, &first); timeout, &first,
deadline);
if (timeout < 0) if (timeout < 0)
return timeout; return timeout;
wait->first_signaled = first; wait->first_signaled = first;
...@@ -1227,7 +1244,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev, ...@@ -1227,7 +1244,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,
u64_to_user_ptr(timeline_wait->points), u64_to_user_ptr(timeline_wait->points),
timeline_wait->count_handles, timeline_wait->count_handles,
timeline_wait->flags, timeline_wait->flags,
timeout, &first); timeout, &first,
deadline);
if (timeout < 0) if (timeout < 0)
return timeout; return timeout;
timeline_wait->first_signaled = first; timeline_wait->first_signaled = first;
...@@ -1298,17 +1316,22 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, ...@@ -1298,17 +1316,22 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
{ {
struct drm_syncobj_wait *args = data; struct drm_syncobj_wait *args = data;
struct drm_syncobj **syncobjs; struct drm_syncobj **syncobjs;
unsigned int possible_flags;
ktime_t t, *tp = NULL;
int ret = 0; int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ)) if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT)) DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE;
if (args->flags & ~possible_flags)
return -EINVAL; return -EINVAL;
if (args->count_handles == 0) if (args->count_handles == 0)
return -EINVAL; return 0;
ret = drm_syncobj_array_find(file_private, ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles), u64_to_user_ptr(args->handles),
...@@ -1317,8 +1340,13 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data, ...@@ -1317,8 +1340,13 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) {
t = ns_to_ktime(args->deadline_nsec);
tp = &t;
}
ret = drm_syncobj_array_wait(dev, file_private, ret = drm_syncobj_array_wait(dev, file_private,
args, NULL, syncobjs, false); args, NULL, syncobjs, false, tp);
drm_syncobj_array_free(syncobjs, args->count_handles); drm_syncobj_array_free(syncobjs, args->count_handles);
...@@ -1331,18 +1359,23 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data, ...@@ -1331,18 +1359,23 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
{ {
struct drm_syncobj_timeline_wait *args = data; struct drm_syncobj_timeline_wait *args = data;
struct drm_syncobj **syncobjs; struct drm_syncobj **syncobjs;
unsigned int possible_flags;
ktime_t t, *tp = NULL;
int ret = 0; int ret = 0;
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE))
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL | possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT | DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE)) DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE |
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE;
if (args->flags & ~possible_flags)
return -EINVAL; return -EINVAL;
if (args->count_handles == 0) if (args->count_handles == 0)
return -EINVAL; return 0;
ret = drm_syncobj_array_find(file_private, ret = drm_syncobj_array_find(file_private,
u64_to_user_ptr(args->handles), u64_to_user_ptr(args->handles),
...@@ -1351,8 +1384,13 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data, ...@@ -1351,8 +1384,13 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) {
t = ns_to_ktime(args->deadline_nsec);
tp = &t;
}
ret = drm_syncobj_array_wait(dev, file_private, ret = drm_syncobj_array_wait(dev, file_private,
NULL, args, syncobjs, true); NULL, args, syncobjs, true, tp);
drm_syncobj_array_free(syncobjs, args->count_handles); drm_syncobj_array_free(syncobjs, args->count_handles);
......
...@@ -926,6 +926,7 @@ struct drm_syncobj_transfer { ...@@ -926,6 +926,7 @@ struct drm_syncobj_transfer {
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0) #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1) #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */ #define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE (1 << 3) /* set fence deadline to deadline_nsec */
struct drm_syncobj_wait { struct drm_syncobj_wait {
__u64 handles; __u64 handles;
/* absolute timeout */ /* absolute timeout */
...@@ -934,6 +935,14 @@ struct drm_syncobj_wait { ...@@ -934,6 +935,14 @@ struct drm_syncobj_wait {
__u32 flags; __u32 flags;
__u32 first_signaled; /* only valid when not waiting all */ __u32 first_signaled; /* only valid when not waiting all */
__u32 pad; __u32 pad;
/**
* @deadline_nsec - fence deadline hint
*
* Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing
* fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is
* set.
*/
__u64 deadline_nsec;
}; };
struct drm_syncobj_timeline_wait { struct drm_syncobj_timeline_wait {
...@@ -946,6 +955,14 @@ struct drm_syncobj_timeline_wait { ...@@ -946,6 +955,14 @@ struct drm_syncobj_timeline_wait {
__u32 flags; __u32 flags;
__u32 first_signaled; /* only valid when not waiting all */ __u32 first_signaled; /* only valid when not waiting all */
__u32 pad; __u32 pad;
/**
* @deadline_nsec - fence deadline hint
*
* Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing
* fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is
* set.
*/
__u64 deadline_nsec;
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment