drm/syncobj: add syncobj sideband payload for threaded submission
Subsystems (2)
v4 cover drm/syncobj: add syncobj sideband payload for threaded submission
Now with a single ioctl().
Cheers,
Lionel Landwerlin (1):
drm/syncobj: add sideband payload
drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_ioctl.c | 3 ++ drivers/gpu/drm/drm_syncobj.c | 55 +++++++++++++++++++++++++++++++++- include/drm/drm_syncobj.h | 9 ++++++ include/uapi/drm/drm.h | 17 +++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-)
--
2.23.0.rc1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 1/1 drm/syncobj: add sideband payload
The Vulkan timeline semaphores allow signaling to happen on the point of the timeline without all of the its dependencies to be created.
The current 2 implementations (AMD/Intel) of the Vulkan spec on top of the Linux kernel are using a thread to wait on the dependencies of a given point to materialize and delay actual submission to the kernel driver until the wait completes.
If a binary semaphore is submitted for signaling along the side of a timeline semaphore waiting for completion that means that the drm syncobj associated with that binary semaphore will not have a DMA fence associated with it by the time vkQueueSubmit() returns. This and the fact that a binary semaphore can be signaled and unsignaled as before its DMA fences materialize mean that we cannot just rely on the fence within the syncobj but we also need a sideband payload verifying that the fence in the syncobj matches the last submission from the Vulkan API point of view.
This change adds a sideband payload that is incremented with signaled syncobj when vkQueueSubmit() is called. The next vkQueueSubmit() waiting on a the syncobj will read the sideband payload and wait for a fence chain element with a seqno superior or equal to the sideband payload value to be added into the fence chain and use that fence to trigger the submission on the kernel driver.
v2: Use a separate ioctl to get/set the sideband value (Christian)
v3: Use 2 ioctls for get/set (Christian)
v4: Use a single new ioctl
--- drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_ioctl.c | 3 ++ drivers/gpu/drm/drm_syncobj.c | 55 +++++++++++++++++++++++++++++++++- include/drm/drm_syncobj.h | 9 ++++++ include/uapi/drm/drm.h | 17 +++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +2 -0
@@ -208,6 +208,8 @@ int drm_syncobj_timeline_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); +int drm_syncobj_binary_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,
drivers/gpu/drm/drm_ioctl.c +3 -0
@@ -703,6 +703,9 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_QUERY , drm_syncobj_query_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_BINARY , drm_syncobj_binary_ioctl, +DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_CRTC_GET_SEQUENCE , drm_crtc_get_sequence_ioctl,0 ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_QUEUE_SEQUENCE , drm_crtc_queue_sequence_ioctl,0 ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),
drivers/gpu/drm/drm_syncobj.c +54 -1
68 lines not on this page · raw message
include/drm/drm_syncobj.h +9 -0
@@ -61,6 +61,15 @@ struct drm_syncobj {* @file: A file backing for this syncobj. */ struct file *file; +/** +* @binary_payload: A 64bit payload for binary syncobjs. +* +* We use the payload value to wait on binary syncobj fences to +* materialize. It is a reservation mechanism for the signaler to +* express that at some point in the future a dma fence with the same +* seqno will be put into the syncobj. +*/ +u64 binary_payload; };void drm_syncobj_free (struct kref *kref);
include/uapi/drm/drm.h +17 -0
@@ -785,6 +785,22 @@ struct drm_syncobj_timeline_array {__u32 pad; }; +struct drm_syncobj_binary_array { +/* A pointer to an array of u32 syncobj handles. */ +__u64 handles; +/* A pointer to an array of u32 access flags for each handle. */ +__u64 access_flags; +/* The binary value of a syncobj is read before it is incremented. */ +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ (1u << 0) +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC (1u << 1) +/* A pointer to an array of u64 values written to by the kernel if the +* handle is flagged for reading. +*/ +__u64 values; +/* The length of the 3 arrays above. */ +__u32 count_handles; +__u32 pad; +};/* Query current scanout sequence number */ struct drm_crtc_get_sequence {
@@ -946,6 +962,7 @@ extern "C" {#define DRM_IOCTL_SYNCOBJ_QUERY DRM_IOWR(0xCB, struct drm_syncobj_timeline_array)#define DRM_IOCTL_SYNCOBJ_TRANSFER DRM_IOWR(0xCC, struct drm_syncobj_transfer)#define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD, struct drm_syncobj_timeline_array) +#define DRM_IOCTL_SYNCOBJ_BINARY DRM_IOWR(0xCE, struct drm_syncobj_binary_array)/** * Device specific ioctls should only be in their respective headers
Signature · 6 lines
2.23.0.rc1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 6 lines
include/uapi/drm/drm.h +0
-0@@ -785,6 +785,22 @@ struct drm_syncobj_timeline_array {__u32 pad;
include/uapi/drm/drm.h struct drm_syncobj_timeline_array { · line 795
Quoted 10 lines
include/uapi/drm/drm.h +8
-0}; +struct drm_syncobj_binary_array { +/* A pointer to an array of u32 syncobj handles. */ +__u64 handles; +/* A pointer to an array of u32 access flags for each handle. */ +__u64 access_flags; +/* The binary value of a syncobj is read before it is incremented. */ +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ (1u << 0) +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC (1u << 1)
You're not in Kansas anymore ;)
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Quoted 9 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 8 lines
include/uapi/drm/drm.h +0
-0@@ -785,6 +785,22 @@ struct drm_syncobj_timeline_array {__u32 pad; };
Quoted 11 lines
include/uapi/drm/drm.h struct drm_syncobj_timeline_array { · line 795
Quoted 8 lines
include/uapi/drm/drm.h +8
-0+struct drm_syncobj_binary_array { +/* A pointer to an array of u32 syncobj handles. */ +__u64 handles; +/* A pointer to an array of u32 access flags for each handle. */ +__u64 access_flags; +/* The binary value of a syncobj is read before it is incremented. */ +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ (1u << 0) +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC (1u << 1)You're not in Kansas anymore ;)
-Chris
Which means? :)
-Lionel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Am 09.08.19 um 14:26 schrieb Lionel Landwerlin:
Quoted 22 lines · Chris Wilson
Quoted 12 lines
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 11 lines
include/uapi/drm/drm.h +3
-0@@ -785,6 +785,22 @@ struct drm_syncobj_timeline_array { __u32 pad; }; +struct drm_syncobj_binary_array { + /* A pointer to an array of u32 syncobj handles. */ + __u64 handles; + /* A pointer to an array of u32 access flags for eachQuoted 9 lines
include/uapi/drm/drm.h struct drm_syncobj_timeline_array { · line 795
Quoted 6 lines
handle. */
+__u64access_flags;
+ /* The binary value of a syncobj is read before it is incremented. */include/uapi/drm/drm.h +2
-0+#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ (1u << 0) +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC (1u << 1)You're not in Kansas anymore ;)
-Chris
Quoted 1 line
Which means? :)
You are in common DRM code, but the new defines start with I915_....
Cheers,
Christian.
Quoted 4 lines
-Lionel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Quoted 23 lines · Christian
Am 09.08.19 um 14:26 schrieb Lionel Landwerlin:
Quoted 22 lines · Chris Wilson
Quoted 21 lines
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 15 lines
include/uapi/drm/drm.h +3
-0@@ -785,6 +785,22 @@ struct drm_syncobj_timeline_array { __u32 pad; }; +struct drm_syncobj_binary_array { + /* A pointer to an array of u32 syncobj handles. */ + __u64 handles; + /* A pointer to an array of u32 access flags for eachhandle. */
+__u64access_flags;
+ /* The binary value of a syncobj is read before it is incremented. */include/uapi/drm/drm.h struct drm_syncobj_timeline_array { · line 795
Quoted 2 lines
include/uapi/drm/drm.h +2
-0+#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ (1u << 0) +#define I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC (1u << 1)You're not in Kansas anymore ;)
-Chris
Quoted 5 lines
Quoted 1 line
Which means? :)
You are in common DRM code, but the new defines start with
I915_....Cheers,
Christian.
Oh dear...
-Lionel
Quoted 4 lines
Quoted 4 lines
-Lionel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
In reply to Lionel LandwerlinQuoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 8 lines
drivers/gpu/drm/drm_syncobj.c +8
-0+int drm_syncobj_binary_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_binary_array *args = data; +struct drm_syncobj **syncobjs; +u32 __user *access_flags =u64_to_user_ptr (args->access_flags); +u64 __user *values =u64_to_user_ptr (args->values); +u32 i;
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1349
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +10
-0+int ret; + +if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ; + +if (args->pad !=0 ) +return -EINVAL ; + +if (args->count_handles ==0 ) +return -EINVAL ;
You may find it easier to just return success for 0 handles. Slightly less obnoxious error handling?
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1362
Quoted 12 lines
drivers/gpu/drm/drm_syncobj.c +12
-0+ ret =drm_syncobj_array_find (file_private, +u64_to_user_ptr (args->handles), + args->count_handles, + &syncobjs); +if (ret <0 ) +return ret; + +for (i =0 ; i < args->count_handles; i++) { +u32 flags; + +copy_from_user (&flags, &access_flags[i],sizeof (flags)); + ret = ret ? -EFAULT :0 ;
Magic?
if (get_user(flags, &access_flags[i[))
return -EFAULT;
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1368
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +6
-0+if (ret) +break ; + +if (flags &I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ ) { +copy_to_user (&values[i], &syncobjs[i]->binary_payload,sizeof (values[i])); + ret = ret ? -EFAULT :0 ;
More magic.
if (put_user(&syncobjs[i]->binary_payload, &values[i]))
return -EFAULT;
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1374
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +6
-0+if (ret) +break ; + } + +if (flags &I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC ) + syncobjs[i]->binary_payload++;
So if an error occurs how does the user know which syncobj were advanced before the error? (Or explain why it doesn't actually matter) The clue I guess is with read/inc, but confirmation of design would be nice.
Not atomic (the u64 write should really be to avoid total corruption) and nothing prevents userspace from racing. How safe is that in the overall design?
What would happen if the binary_payload was initialised to -1?
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1379
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+ } +drm_syncobj_array_free (syncobjs, args->count_handles);return ret;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Quoting Chris Wilson (2019-08-09 12:58:51)
Quoted 9 lines
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1368
Quoted 3 lines
drivers/gpu/drm/drm_syncobj.c +3
-0+if (flags &I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ ) { +copy_to_user (&values[i], &syncobjs[i]->binary_payload,sizeof (values[i])); + ret = ret ? -EFAULT :0 ;More magic.
if (
put_user(&syncobjs[i]->binary_payload, &values[i]))return -EFAULT;
(break not yet)
Should just be put_user(syncobjs[i]->binary_payload, &values[i]) The value of, not its address.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
In reply to Chris WilsonQuoted 13 lines · Chris Wilson
Quoting Lionel Landwerlin (2019-08-09 12:30:30)
Quoted 12 lines
drivers/gpu/drm/drm_syncobj.c +12
-0+int drm_syncobj_binary_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private) +{ +struct drm_syncobj_binary_array *args = data; +struct drm_syncobj **syncobjs; +u32 __user *access_flags =u64_to_user_ptr (args->access_flags); +u64 __user *values =u64_to_user_ptr (args->values); +u32 i; +int ret; + +if (!drm_core_check_feature (dev,DRIVER_SYNCOBJ_TIMELINE )) +return -EOPNOTSUPP ;
Quoted 8 lines
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1349
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +6
-0+ +if (args->pad !=0 ) +return -EINVAL ; + +if (args->count_handles ==0 ) +return -EINVAL ;You may find it easier to just return success for 0 handles. Slightly less obnoxious error handling?
All the other ioctls in this file return EINVAL in that case. I'm just going for consistency.
It's also a good indication for the application it can save itself an ioctl really :)
Quoted 15 lines
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1362
Quoted 13 lines
drivers/gpu/drm/drm_syncobj.c +12
-0+ ret =drm_syncobj_array_find (file_private, +u64_to_user_ptr (args->handles), + args->count_handles, + &syncobjs); +if (ret <0 ) +return ret; + +for (i =0 ; i < args->count_handles; i++) { +u32 flags; + +copy_from_user (&flags, &access_flags[i],sizeof (flags)); + ret = ret ? -EFAULT :0 ;Magic?
Quoted 2 lines
if (
get_user(flags, &access_flags[i[))return -EFAULT;
I give this no testing, I'm just trying to get some feedback about the direction.
Thanks though :)
Quoted 18 lines
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1368
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c +6
-0+if (ret) +break ; + +if (flags &I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_READ ) { +copy_to_user (&values[i], &syncobjs[i]->binary_payload,sizeof (values[i])); + ret = ret ? -EFAULT :0 ;More magic.
if (
put_user(&syncobjs[i]->binary_payload, &values[i]))return -EFAULT;drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1374
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +6
-0+if (ret) +break ; + } + +if (flags &I915_DRM_SYNCOBJ_BINARY_ITEM_VALUE_INC ) + syncobjs[i]->binary_payload++;
Quoted 4 lines
So if an error occurs how does the user know which syncobj were advanced before the error? (Or explain why it doesn't actually matter) The clue I guess is with read/inc, but confirmation of design would be nice.
I guess we could toggle the access flag bits to notify that the actions were completed.
Quoted 4 lines
Not atomic (the u64 write should really be to avoid total corruption) and nothing prevents userspace from racing. How safe is that in the overall design?
Atomic would prevent issue related to 2 processes/threads seeing different values because of caching?
If not then it's not really interesting for the use case. The increment should happen during the vkQueueSubmit() call and the value is only valid upon returning.
The application is responsible for not having vkQueueSubmit()/vkWaitForFences() race.
Not opposed to switch to atomic though.
Quoted 2 lines
What would happen if the
binary_payloadwas initialised to -1?
The 0 value is problematic because it's also used for "whatever fence in the syncobj".
I think we need to stick to the same rules as the timeline values : 0 is always signaled
Thanks,
-Lionel
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c int drm_syncobj_query_ioctl(struct drm_device *dev, void *data, · line 1379
Quoted 6 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+ } +drm_syncobj_array_free (syncobjs, args->count_handles);return ret;
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 1/1] drm/syncobj: add sideband payload
Quoting Lionel Landwerlin (2019-08-09 13:38:57)
Quoted 8 lines · Chris Wilson
Quoted 3 lines
Not atomic (the u64 write should really be to avoid total corruption) and nothing prevents userspace from racing. How safe is that in the overall design?
Atomic would prevent issue related to 2 processes/threads seeing different values because of caching?
No, the kernel atomics themselves do not guarantee memory barriers in all cases. The issue I see here is that we can not safely do a u64 increment on all platforms without write tearing. E.g. two clients simultaneously incrementing from U32_MAX becomes 0x1 (both would report U32_MAX)
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel