<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 8, 2023 at 9:54 AM Rob Clark <<a href="mailto:robdclark@gmail.com">robdclark@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Rob Clark <<a href="mailto:robdclark@chromium.org" target="_blank">robdclark@chromium.org</a>><br>
<br>
Add a new flag to let userspace provide a deadline as a hint for syncobj<br>
and timeline waits. This gives a hint to the driver signaling the<br>
backing fences about how soon userspace needs it to compete work, so it<br>
can addjust GPU frequency accordingly. An immediate deadline can be<br>
given to provide something equivalent to i915 "wait boost".<br>
<br>
v2: Use absolute u64 ns value for deadline hint, drop cap and driver<br>
feature flag in favor of allowing count_handles==0 as a way for<br>
userspace to probe kernel for support of new flag<br>
v3: More verbose comments about UAPI<br>
<br>
Signed-off-by: Rob Clark <<a href="mailto:robdclark@chromium.org" target="_blank">robdclark@chromium.org</a>><br>
---<br>
drivers/gpu/drm/drm_syncobj.c | 64 ++++++++++++++++++++++++++++-------<br>
include/uapi/drm/drm.h | 17 ++++++++++<br>
2 files changed, 68 insertions(+), 13 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c<br>
index 0c2be8360525..a85e9464f07b 100644<br>
--- a/drivers/gpu/drm/drm_syncobj.c<br>
+++ b/drivers/gpu/drm/drm_syncobj.c<br>
@@ -126,6 +126,11 @@<br>
* synchronize between the two.<br>
* This requirement is inherited from the Vulkan fence API.<br>
*<br>
+ * If &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE is set, the ioctl will also set<br>
+ * a fence deadline hint on the backing fences before waiting, to provide the<br>
+ * fence signaler with an appropriate sense of urgency. The deadline is<br>
+ * specified as an absolute &CLOCK_MONOTONIC value in units of ns.<br>
+ *<br>
* Similarly, &DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT takes an array of syncobj<br>
* handles as well as an array of u64 points and does a host-side wait on all<br>
* of syncobj fences at the given points simultaneously.<br>
@@ -973,7 +978,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,<br>
uint32_t count,<br>
uint32_t flags,<br>
signed long timeout,<br>
- uint32_t *idx)<br>
+ uint32_t *idx,<br>
+ ktime_t *deadline)<br>
{<br>
struct syncobj_wait_entry *entries;<br>
struct dma_fence *fence;<br>
@@ -1053,6 +1059,15 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs,<br>
drm_syncobj_fence_add_wait(syncobjs[i], &entries[i]);<br>
}<br>
<br>
+ if (deadline) {<br>
+ for (i = 0; i < count; ++i) {<br>
+ fence = entries[i].fence;<br>
+ if (!fence)<br>
+ continue;<br>
+ dma_fence_set_deadline(fence, *deadline);<br>
+ }<br>
+ }<br>
+<br>
do {<br>
set_current_state(TASK_INTERRUPTIBLE);<br>
<br>
@@ -1151,7 +1166,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,<br>
struct drm_file *file_private,<br>
struct drm_syncobj_wait *wait,<br>
struct drm_syncobj_timeline_wait *timeline_wait,<br>
- struct drm_syncobj **syncobjs, bool timeline)<br>
+ struct drm_syncobj **syncobjs, bool timeline,<br>
+ ktime_t *deadline)<br>
{<br>
signed long timeout = 0;<br>
uint32_t first = ~0;<br>
@@ -1162,7 +1178,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,<br>
NULL,<br>
wait->count_handles,<br>
wait->flags,<br>
- timeout, &first);<br>
+ timeout, &first,<br>
+ deadline);<br>
if (timeout < 0)<br>
return timeout;<br>
wait->first_signaled = first;<br>
@@ -1172,7 +1189,8 @@ static int drm_syncobj_array_wait(struct drm_device *dev,<br>
u64_to_user_ptr(timeline_wait->points),<br>
timeline_wait->count_handles,<br>
timeline_wait->flags,<br>
- timeout, &first);<br>
+ timeout, &first,<br>
+ deadline);<br>
if (timeout < 0)<br>
return timeout;<br>
timeline_wait->first_signaled = first;<br>
@@ -1243,17 +1261,22 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,<br>
{<br>
struct drm_syncobj_wait *args = data;<br>
struct drm_syncobj **syncobjs;<br>
+ unsigned possible_flags;<br>
+ ktime_t t, *tp = NULL;<br>
int ret = 0;<br>
<br>
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ))<br>
return -EOPNOTSUPP;<br>
<br>
- if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |<br>
- DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT))<br>
+ possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |<br>
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |<br>
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE;<br>
+<br>
+ if (args->flags & ~possible_flags)<br>
return -EINVAL;<br>
<br>
if (args->count_handles == 0)<br>
- return -EINVAL;<br>
+ return 0;<br></blockquote><div> </div><div>Did you intend this change? If so, why? What does waiting with no handles gain us? I mean, it's probably fine but it seems unrelated to this change.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
ret = drm_syncobj_array_find(file_private,<br>
u64_to_user_ptr(args->handles),<br>
@@ -1262,8 +1285,13 @@ drm_syncobj_wait_ioctl(struct drm_device *dev, void *data,<br>
if (ret < 0)<br>
return ret;<br>
<br>
+ if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) {<br>
+ t = ns_to_ktime(args->deadline_ns);<br>
+ tp = &t;<br>
+ }<br>
+<br>
ret = drm_syncobj_array_wait(dev, file_private,<br>
- args, NULL, syncobjs, false);<br>
+ args, NULL, syncobjs, false, tp);<br>
<br>
drm_syncobj_array_free(syncobjs, args->count_handles);<br>
<br>
@@ -1276,18 +1304,23 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,<br>
{<br>
struct drm_syncobj_timeline_wait *args = data;<br>
struct drm_syncobj **syncobjs;<br>
+ unsigned possible_flags;<br>
+ ktime_t t, *tp = NULL;<br>
int ret = 0;<br>
<br>
if (!drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE))<br>
return -EOPNOTSUPP;<br>
<br>
- if (args->flags & ~(DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |<br>
- DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |<br>
- DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE))<br>
+ possible_flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL |<br>
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT |<br>
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE |<br>
+ DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE;<br>
+<br>
+ if (args->flags & ~possible_flags)<br>
return -EINVAL;<br>
<br>
if (args->count_handles == 0)<br>
- return -EINVAL;<br>
+ return -0;<br></blockquote><div><br></div><div>Did you intend this change? -0 is a pretty weird integer.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
ret = drm_syncobj_array_find(file_private,<br>
u64_to_user_ptr(args->handles),<br>
@@ -1296,8 +1329,13 @@ drm_syncobj_timeline_wait_ioctl(struct drm_device *dev, void *data,<br>
if (ret < 0)<br>
return ret;<br>
<br>
+ if (args->flags & DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE) {<br>
+ t = ns_to_ktime(args->deadline_ns);<br>
+ tp = &t;<br>
+ }<br>
+<br>
ret = drm_syncobj_array_wait(dev, file_private,<br>
- NULL, args, syncobjs, true);<br>
+ NULL, args, syncobjs, true, tp);<br>
<br>
drm_syncobj_array_free(syncobjs, args->count_handles);<br>
<br>
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h<br>
index 642808520d92..bff0509ac8b6 100644<br>
--- a/include/uapi/drm/drm.h<br>
+++ b/include/uapi/drm/drm.h<br>
@@ -887,6 +887,7 @@ struct drm_syncobj_transfer {<br>
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL (1 << 0)<br>
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT (1 << 1)<br>
#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_AVAILABLE (1 << 2) /* wait for time point to become available */<br>
+#define DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE (1 << 3) /* set fence deadline based to deadline_ns */<br>
struct drm_syncobj_wait {<br>
__u64 handles;<br>
/* absolute timeout */<br>
@@ -895,6 +896,14 @@ struct drm_syncobj_wait {<br>
__u32 flags;<br>
__u32 first_signaled; /* only valid when not waiting all */<br>
__u32 pad;<br>
+ /**<br>
+ * @deadline_ns - fence deadline hint<br>
+ *<br>
+ * Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing<br>
+ * fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is<br>
+ * set.<br>
+ */<br>
+ __u64 deadline_ns;<br>
};<br>
<br>
struct drm_syncobj_timeline_wait {<br>
@@ -907,6 +916,14 @@ struct drm_syncobj_timeline_wait {<br>
__u32 flags;<br>
__u32 first_signaled; /* only valid when not waiting all */<br>
__u32 pad;<br>
+ /**<br>
+ * @deadline_ns - fence deadline hint<br>
+ *<br>
+ * Deadline hint, in absolute CLOCK_MONOTONIC, to set on backing<br>
+ * fence(s) if the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_DEADLINE flag is<br>
+ * set.<br>
+ */<br>
+ __u64 deadline_ns;<br>
};<br>
<br>
<br>
-- <br>
2.39.2<br>
<br>
</blockquote></div></div>