Skip to contentSkip to conversation

drm/syncobj: add syncobj sideband payload for threaded submission

PATCH Superseded Lionel Landwerlin 5 participants 16 messages Aug 8, 2019 – Aug 9, 2019

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover drm/syncobj: add syncobj sideband payload for threaded submission

Hi,

Hopefully all good this time.

Cheers,

Lionel Landwerlin (1):
drm/syncobj: add sideband payload

 drivers/gpu/drm/drm_internal.h |  4 ++
 drivers/gpu/drm/drm_ioctl.c    |  5 +++
 drivers/gpu/drm/drm_syncobj.c  | 79 +++++++++++++++++++++++++++++++++-
 include/drm/drm_syncobj.h      |  9 ++++
 include/uapi/drm/drm.h         |  2 +
 5 files changed, 98 insertions(+), 1 deletion(-)

--
2.23.0.rc1
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#1 lore raw

PATCH v3 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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
 drivers/gpu/drm/drm_internal.h |  4 ++
 drivers/gpu/drm/drm_ioctl.c    |  5 +++
 drivers/gpu/drm/drm_syncobj.c  | 79 +++++++++++++++++++++++++++++++++-
 include/drm/drm_syncobj.h      |  9 ++++
 include/uapi/drm/drm.h         |  2 +
 5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, drm_syncobj_get_sideband_ioctl,
+		      DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, drm_syncobj_set_sideband_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 +78 -1

92 lines not on this page · raw message

include/drm/drm_syncobj.h +9 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
 	 * @file: A file backing for this syncobj.
 	 */
 	struct file *file;
+	/**
+	 * @sideband_payload: A 64bit side band payload.
+	 *
+	 * We use the sideband 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 sideband_payload;
 };
 
 void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +2 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND	DRM_IOR(0xCE, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND	DRM_IOWR(0xCF, struct drm_syncobj_timeline_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
#2 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 195 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
  drivers/gpu/drm/drm_internal.h |  4 ++
  drivers/gpu/drm/drm_ioctl.c    |  5 +++
  drivers/gpu/drm/drm_syncobj.c  | 79 +++++++++++++++++++++++++++++++++-
  include/drm/drm_syncobj.h      |  9 ++++
  include/uapi/drm/drm.h         |  2 +
  5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, drm_syncobj_get_sideband_ioctl,
+		      DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, drm_syncobj_set_sideband_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 +78 -1
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
  	if (ret < 0)
  		return ret;
 
-	for (i = 0; i < args->count_handles; i++)
+	for (i = 0; i < args->count_handles; i++) {
  		drm_syncobj_replace_fence(syncobjs[i], NULL);
+		syncobjs[i]->sideband_payload = 0;
+	}
 
  	drm_syncobj_array_free(syncobjs, args->count_handles);
 
@@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
  		if (ret)
  			break;
  	}
+
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_array *args = data;
+	struct drm_syncobj **syncobjs;
+	uint64_t __user *points = u64_to_user_ptr(args->points);
+	uint32_t i;
+	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;
+
+	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++) {
+		copy_to_user(&points[i], &syncobjs[i]->sideband_payload, sizeof(uint64_t));
+		ret = ret ? -EFAULT : 0;
+		if (ret)
+			break;
+	}
+
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_array *args = data;
+	struct drm_syncobj **syncobjs;
+	uint64_t __user *points = u64_to_user_ptr(args->points);
+	uint32_t i;
+	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;
+
+	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++) {
+		copy_from_user(&syncobjs[i]->sideband_payload, &points[i], sizeof(uint64_t));
+		ret = ret ? -EFAULT : 0;
+		if (ret)
+			break;
+	}
+
  	drm_syncobj_array_free(syncobjs, args->count_handles);
 
  	return ret;
include/drm/drm_syncobj.h +9 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
  	 * @file: A file backing for this syncobj.
  	 */
  	struct file *file;
+	/**
+	 * @sideband_payload: A 64bit side band payload.
+	 *
+	 * We use the sideband 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 sideband_payload;
  };
 
  void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644

include/uapi/drm/drm.h extern "C" { · line 953

Quoted 8 lines
include/uapi/drm/drm.h +2 -0
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND	DRM_IOR(0xCE, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND	DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
 
  /**
   * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 210 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 201 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
   drivers/gpu/drm/drm_internal.h |  4 ++
   drivers/gpu/drm/drm_ioctl.c    |  5 +++
   drivers/gpu/drm/drm_syncobj.c  | 79 +++++++++++++++++++++++++++++++++-
   include/drm/drm_syncobj.h      |  9 ++++
   include/uapi/drm/drm.h         |  2 +
   5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, drm_syncobj_get_sideband_ioctl,
+		      DRM_RENDER_ALLOW),
+	DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, drm_syncobj_set_sideband_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 +78 -1
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,
   	if (ret < 0)
   		return ret;
 
-	for (i = 0; i < args->count_handles; i++)
+	for (i = 0; i < args->count_handles; i++) {
   		drm_syncobj_replace_fence(syncobjs[i], NULL);
+		syncobjs[i]->sideband_payload = 0;
+	}
 
   	drm_syncobj_array_free(syncobjs, args->count_handles);
 
@@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
   		if (ret)
   			break;
   	}
+
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_array *args = data;
+	struct drm_syncobj **syncobjs;
+	uint64_t __user *points = u64_to_user_ptr(args->points);
+	uint32_t i;
+	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;
+
+	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++) {
+		copy_to_user(&points[i], &syncobjs[i]->sideband_payload, sizeof(uint64_t));
+		ret = ret ? -EFAULT : 0;
+		if (ret)
+			break;
+	}
+
+	drm_syncobj_array_free(syncobjs, args->count_handles);
+
+	return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void *data,
+				   struct drm_file *file_private)
+{
+	struct drm_syncobj_timeline_array *args = data;
+	struct drm_syncobj **syncobjs;
+	uint64_t __user *points = u64_to_user_ptr(args->points);
+	uint32_t i;
+	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;
+
+	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++) {
+		copy_from_user(&syncobjs[i]->sideband_payload, &points[i], sizeof(uint64_t));
+		ret = ret ? -EFAULT : 0;
+		if (ret)
+			break;
+	}
+
   	drm_syncobj_array_free(syncobjs, args->count_handles);
 
   	return ret;
include/drm/drm_syncobj.h +9 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
   	 * @file: A file backing for this syncobj.
   	 */
   	struct file *file;
+	/**
+	 * @sideband_payload: A 64bit side band payload.
+	 *
+	 * We use the sideband 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 sideband_payload;
   };
 
   void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +2 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND	DRM_IOR(0xCE, struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND	DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
 
Quoted 2 lines

include/uapi/drm/drm.h extern "C" { · line 953

Quoted 2 lines
include/uapi/drm/drm.h +0 -0
   /**
    * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

No, I just see your comment "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. ".

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous discussing thread.

-DAvid

Quoted 231 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 220 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 211 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>

---
   drivers/gpu/drm/drm_internal.h |  4 ++
   drivers/gpu/drm/drm_ioctl.c    |  5 +++
   drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
   include/drm/drm_syncobj.h      |  9 ++++
   include/uapi/drm/drm.h         |  2 +

   5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, 
 drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, 
 drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device 
 *dev, void *data,
        if (ret < 0)
            return ret;
    -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
            drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
           drm_syncobj_array_free(syncobjs, args->count_handles);

   @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
           if (ret)
               break;
       }

drivers/gpu/drm/drm_syncobj.c +33 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload, 

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +33 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_from_user(&syncobjs[i]->sideband_payload, &points[i], 

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
       drm_syncobj_array_free(syncobjs, args->count_handles); return ret;

include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
         * @file: A file backing for this syncobj.
         */
        struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
   };
      void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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)
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h +1 -0
    #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL    DRM_IOWR(0xCD, 
 struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_GET_SIDEBAND    DRM_IOR(0xCE, struct 

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND    DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
      /**
    * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#5 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 3 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous discussing thread.

In QueueSubmit(), we start by reading the sideband payloads : https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled : https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 245 lines

-DAvid

Quoted 240 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 228 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 219 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
    drivers/gpu/drm/drm_internal.h |  4 ++
    drivers/gpu/drm/drm_ioctl.c    |  5 +++
    drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
    include/drm/drm_syncobj.h      |  9 ++++
    include/uapi/drm/drm.h         |  2 +
    5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
 drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,
 drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
        if (ret < 0)
            return ret;
    -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
            drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
           drm_syncobj_array_free(syncobjs, args->count_handles);
    @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,
           if (ret)
               break;
       }

drivers/gpu/drm/drm_syncobj.c +33 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +33 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +1 -0
+
        drm_syncobj_array_free(syncobjs, args->count_handles);
           return ret;
include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
         * @file: A file backing for this syncobj.
         */
        struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
   };
      void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND    DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND    DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
      /**
    * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#6 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 13 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 6 lines
Quoted 3 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous discussing thread.

In QueueSubmit(), we start by reading the sideband payloads : https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

We only need to read/write sideband payloads for binary semaphores. The behavior for timeline semaphores remains unchanged. :)

-Lionel

Quoted 265 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled : https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 249 lines

-DAvid

Quoted 244 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 232 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 223 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>

---
    drivers/gpu/drm/drm_internal.h |  4 ++
    drivers/gpu/drm/drm_ioctl.c    |  5 +++
    drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
    include/drm/drm_syncobj.h      |  9 ++++
    include/uapi/drm/drm.h         |  2 +

    5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void 
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +5 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
 drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,
 drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
         if (ret < 0)
             return ret;
     -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
             drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
            drm_syncobj_array_free(syncobjs, args->count_handles);

    @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
            if (ret)
                break;
        }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void 

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void 

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
        drm_syncobj_array_free(syncobjs, args->count_handles); return ret;

include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
          * @file: A file backing for this syncobj.
          */
         struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
    };
       void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND    DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND    DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
       /**
     * Device specific ioctls should only be in their respective headers

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#7 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

In reply to Lionel Landwerlin
Quoted 19 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 3 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous discussing thread.

Quoted 8 lines

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

But I don't see how to wait/block in kernel when finding fence for binary sideband payload  values.

-David

Quoted 6 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Quoted 266 lines

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 257 lines

-DAvid

Quoted 252 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 240 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 231 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>

---
    drivers/gpu/drm/drm_internal.h |  4 ++
    drivers/gpu/drm/drm_ioctl.c    |  5 +++
    drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
    include/drm/drm_syncobj.h      |  9 ++++
    include/uapi/drm/drm.h         |  2 +

    5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void 
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
 drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,

drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
         if (ret < 0)
             return ret;
     -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
             drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
            drm_syncobj_array_free(syncobjs, args->count_handles);

    @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
            if (ret)
                break;
        }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void 

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void 

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
        drm_syncobj_array_free(syncobjs, args->count_handles); return ret;

include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
          * @file: A file backing for this syncobj.
          */
         struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
    };
       void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND    DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND    DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
       /**
     * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 21 lines · Chunming Zhou
Quoted 20 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 3 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 6 lines
Quoted 5 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Hmm aren't you waiting in a thread in userspace?

Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload  values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 264 lines

-David

Quoted 260 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 247 lines

-DAvid

Quoted 243 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 232 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 223 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
     drivers/gpu/drm/drm_internal.h |  4 ++
     drivers/gpu/drm/drm_ioctl.c    |  5 +++
     drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
     include/drm/drm_syncobj.h      |  9 ++++
     include/uapi/drm/drm.h         |  2 +
     5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +4 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
 drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,

drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
         if (ret < 0)
             return ret;
     -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
             drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
            drm_syncobj_array_free(syncobjs, args->count_handles);
     @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,
            if (ret)
                break;
        }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +1 -0
+
         drm_syncobj_array_free(syncobjs, args->count_handles);
            return ret;
include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
          * @file: A file backing for this syncobj.
          */
         struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
    };
       void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h +1 -0
 struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_GET_SIDEBAND    DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND    DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
       /**
     * Device specific ioctls should only be in their respective
headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#9 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 27 lines · Lionel Landwerlin
Quoted 26 lines · Chunming Zhou
Quoted 25 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Then build everything for the submission and hand it over to the submission thread.

Quoted 6 lines
Quoted 3 lines
Quoted 2 lines

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband value is

Quoted 1 line

= expected, then do submission, otherwise, loop QueueThread, right?

That sounds the QueueThread will be always busy.

-David

Quoted 299 lines
Quoted 5 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload  values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 274 lines

-David

Quoted 270 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 256 lines

-DAvid

Quoted 252 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 241 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 232 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>

---
     drivers/gpu/drm/drm_internal.h |  4 ++
     drivers/gpu/drm/drm_ioctl.c    |  5 +++
     drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
     include/drm/drm_syncobj.h      |  9 ++++
     include/uapi/drm/drm.h         |  2 +

     5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +0 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+                   struct drm_file *file_private); +int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
          if (ret < 0)
              return ret;
      -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
              drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
             drm_syncobj_array_free(syncobjs, args->count_handles);

     @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
             if (ret)
                 break;
         }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
         drm_syncobj_array_free(syncobjs, args->count_handles); return ret;

include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
           * @file: A file backing for this syncobj.
           */
          struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
     };
        void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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,
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h +1 -0
 struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
        /**
      * Device specific ioctls should only be in their respective headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#10 lore raw

Re: [PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 30 lines · Chunming Zhou
Quoted 29 lines · Lionel Landwerlin
Quoted 27 lines · Chunming Zhou
Quoted 20 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 5 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Quoted 8 lines
Quoted 1 line

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband value is

Quoted 1 line

= expected, then do submission, otherwise, loop QueueThread, right?

Just treat binary semaphores as timelines and waitForSyncobj on the sideband payload value.

It should make the submission thread any busier than currently.

-Lionel

Quoted 306 lines

That sounds the QueueThread will be always busy.

-David

Quoted 300 lines
Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload  values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 281 lines

-David

Quoted 278 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 264 lines

-DAvid

Quoted 260 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 249 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 240 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
      drivers/gpu/drm/drm_internal.h |  4 ++
      drivers/gpu/drm/drm_ioctl.c    |  5 +++
      drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
      include/drm/drm_syncobj.h      |  9 ++++
      include/uapi/drm/drm.h         |  2 +
      5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +3 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND, drm_syncobj_get_sideband_ioctl,
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND, drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
          if (ret < 0)
              return ret;
      -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
              drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
             drm_syncobj_array_free(syncobjs, args->count_handles);
      @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,
             if (ret)
                 break;
         }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,
+                   struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +1 -0
+
          drm_syncobj_array_free(syncobjs, args->count_handles);
             return ret;
include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
           * @file: A file backing for this syncobj.
           */
          struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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 sideband_payload;
     };
        void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
        /**
      * Device specific ioctls should only be in their respective
headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#11 lore raw

回复:[PATCH v3 1/1] drm/syncobj: add sideband payload

Thank you, I got your mean.
when you have sideband payload, you will go into timeline path. Clever!

-David

-------- 原始邮件 --------
主题:Re: [PATCH v3 1/1] drm/syncobj: add sideband payload 发件人:Lionel Landwerlin
收件人:"Zhou, David(ChunMing)" ,[email protected] 抄送:"Koenig, Christian" ,Jason Ekstrand ,"Zhou, David(ChunMing)"

Quoted 30 lines · Chunming Zhou
Quoted 29 lines · Lionel Landwerlin
Quoted 27 lines · Chunming Zhou
Quoted 20 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 5 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Quoted 8 lines
Quoted 1 line

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband value is

Quoted 1 line

= expected, then do submission, otherwise, loop QueueThread, right?

Just treat binary semaphores as timelines and waitForSyncobj on the sideband payload value.

It should make the submission thread any busier than currently.

-Lionel

Quoted 306 lines

That sounds the QueueThread will be always busy.

-David

Quoted 300 lines
Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 281 lines

-David

Quoted 278 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 264 lines

-DAvid

Quoted 260 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 249 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 240 lines · Lionel Landwerlin

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)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>
---
      drivers/gpu/drm/drm_internal.h |  4 ++
      drivers/gpu/drm/drm_ioctl.c    |  5 +++
      drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
      include/drm/drm_syncobj.h      |  9 ++++
      include/uapi/drm/drm.h         |  2 +
      5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +3 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
drm_syncobj_get_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,

drm_syncobj_set_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
          if (ret < 0)
              return ret;
      -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
              drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
             drm_syncobj_array_free(syncobjs, args->count_handles);
      @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,

              if (ret)
                  break;
          }
drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +11 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +5 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
          drm_syncobj_array_free(syncobjs, args->count_handles);
             return ret;
include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
           * @file: A file backing for this syncobj.
           */
          struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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

include/drm/drm_syncobj.h +3 -0
+     * seqno will be put into the syncobj.
+     */
+    u64 sideband_payload;
      };
         void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
/**
* Device specific ioctls should only be in their respective
headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Re: 回复:[PATCH v3 1/1] drm/syncobj: add sideband payload

Yeah, the idea is indeed rather clever. I'm just wondering if we don't need to optimize it even more.

In other words could some IOCTL overhead be saved here if we directly take the value for binary semaphores waits and signals?

Christian.

Am 08.08.19 um 17:23 schrieb Zhou, David(ChunMing):
Thank you, I got your mean.
when you have sideband payload, you will go into timeline path. Clever!

-David

-------- 原始邮件 --------
主题:Re: [PATCH v3 1/1] drm/syncobj: add sideband payload
发件人:Lionel Landwerlin
收件人:"Zhou, David(ChunMing)" ,[email protected]<mailto:[email protected]> 抄送:"Koenig, Christian" ,Jason Ekstrand ,"Zhou, David(ChunMing)"

Quoted 30 lines · Chunming Zhou
Quoted 29 lines · Lionel Landwerlin
Quoted 27 lines · Chunming Zhou
Quoted 20 lines · Lionel Landwerlin
Quoted 5 lines · Chunming Zhou

No, I just see your comment "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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 5 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Quoted 8 lines
Quoted 1 line

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband value is

Quoted 1 line

= expected, then do submission, otherwise, loop QueueThread, right?

Just treat binary semaphores as timelines and waitForSyncobj on the sideband payload value.

It should make the submission thread any busier than currently.

-Lionel

Quoted 306 lines

That sounds the QueueThread will be always busy.

-David

Quoted 300 lines
Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 281 lines

-David

Quoted 278 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :
https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 264 lines

-DAvid

Quoted 260 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the wait value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 249 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 240 lines · Lionel Landwerlin

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)

---
      drivers/gpu/drm/drm_internal.h |  4 ++
      drivers/gpu/drm/drm_ioctl.c    |  5 +++
      drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
      include/drm/drm_syncobj.h      |  9 ++++
      include/uapi/drm/drm.h         |  2 +
      5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +3 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
drm_syncobj_get_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,

drm_syncobj_set_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
          if (ret < 0)
              return ret;
      -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
              drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
             drm_syncobj_array_free(syncobjs, args->count_handles);
      @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,

              if (ret)
                  break;
          }
drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +11 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +5 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
          drm_syncobj_array_free(syncobjs, args->count_handles);
             return ret;
include/drm/drm_syncobj.h +4 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
           * @file: A file backing for this syncobj.
           */
          struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband 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

include/drm/drm_syncobj.h +3 -0
+     * seqno will be put into the syncobj.
+     */
+    u64 sideband_payload;
      };
         void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
/**
* Device specific ioctls should only be in their respective
headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#13 lore raw

Re: 回复:[PATCH v3 1/1] drm/syncobj: add sideband payload

I've got a couple questions that I think go along the lines of what Christian wrote:

1. Should it really be called sideband? It's a very generic term for what is currently a very generic thing. However, maybe we don't want it to be so generic?

2. Do we really want get/set? Or do we want get/increment? We have to do the get/increment during vkQueueSubmit on both the wait and the signal side but get+add+set is a bit heavy. I guess you could do one bit get of all the binary semaphores and then a set for all the signaled ones which sets them to the previous value + 1.

My concern with making it a super-generic thing is that it has an extremely specific use and in order for cross-process sharing to work, all users have to use it exactly the same way. We could call it a "reserved value" or something like that to make it more clear what the intention is. In any case, we should make sure that it's very clearly documented in the design doc.

Quoted 349 lines · Christian

Yeah, the idea is indeed rather clever. I'm just wondering if we don't need to optimize it even more.

In other words could some IOCTL overhead be saved here if we directly take the value for binary semaphores waits and signals?

Christian.

Am 08.08.19 um 17:23 schrieb Zhou, David(ChunMing):

Thank you, I got your mean.
when you have sideband payload, you will go into timeline path. Clever!

-David

-------- 原始邮件 --------
主题:Re: [PATCH v3 1/1] drm/syncobj: add sideband payload 发件人:Lionel Landwerlin
收件人:"Zhou, David(ChunMing)" ,[email protected] 抄送:"Koenig, Christian" ,Jason Ekstrand ,"Zhou, David(ChunMing)"

Quoted 6 lines · Chunming Zhou
Quoted 5 lines · Lionel Landwerlin
Quoted 4 lines · Chunming Zhou
Quoted 3 lines · Lionel Landwerlin
Quoted 2 lines · Chunming Zhou

No, I just see your comment "The next vkQueueSubmit() waiting on a the syncobj will read the sideband payload and wait for

a

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 3 lines

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. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :

https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we also wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Quoted 8 lines
Quoted 1 line

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband value is

Quoted 1 line

= expected, then do submission, otherwise, loop QueueThread, right?

Just treat binary semaphores as timelines and waitForSyncobj on the sideband payload value.

It should make the submission thread any busier than currently.

-Lionel

Quoted 30 lines

That sounds the QueueThread will be always busy.

-David

Quoted 24 lines
Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 6 lines

-David

Quoted 3 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :

https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

-DAvid

Quoted 4 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on the

wait

Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines
Quoted 52 lines

value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 45 lines · Chunming Zhou

The propursal is fine with me.

one question:

how to wait sideband payload? Following patch will show that?

-David

Quoted 36 lines · Lionel Landwerlin

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.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

v2: Use a separate ioctl to get/set the sideband value (Christian)

v3: Use 2 ioctls for get/set (Christian)

<[email protected]>

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Cc Christian Koenig <[email protected]>

<[email protected]>

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Cc David(ChunMing) Zhou <[email protected]>

<[email protected]>

Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
Quoted 62 lines
---
      drivers/gpu/drm/drm_internal.h |  4 ++
      drivers/gpu/drm/drm_ioctl.c    |  5 +++
      drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
      include/drm/drm_syncobj.h      |  9 ++++
      include/uapi/drm/drm.h         |  2 +
      5 files changed, 98 insertions(+), 1 deletion(-)
drivers/gpu/drm/drm_internal.h +3 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device *dev, void
 *data,
+                   struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
drm_syncobj_get_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              DRM_RENDER_ALLOW),
+    DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,

drm_syncobj_set_sideband_ioctl,

drivers/gpu/drm/drm_ioctl.c +2 -0
+              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 +0 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/drm_syncobj.c drm_syncobj_reset_ioctl(struct drm_device · line 1158

Quoted 8 lines
drivers/gpu/drm/drm_syncobj.c +3 -0
          if (ret < 0)
              return ret;
      -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
              drm_syncobj_replace_fence(syncobjs[i], NULL);
+        syncobjs[i]->sideband_payload = 0;
+    }
             drm_syncobj_array_free(syncobjs,

args->count_handles);

Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
Quoted 91 lines
drivers/gpu/drm/drm_syncobj.c +0 -0
      @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct

drm_device *dev, void *data,

              if (ret)
                  break;
          }
drivers/gpu/drm/drm_syncobj.c +7 -0
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+        copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +11 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
+    drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/drm_syncobj.c +26 -0
+                   struct drm_file *file_private)
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));

drivers/gpu/drm/drm_syncobj.c +5 -0
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
          drm_syncobj_array_free(syncobjs, args->count_handles);
             return ret;
include/drm/drm_syncobj.h +0 -0
index 6cf7243a1dc5..b587b8e07547 100644
@@ -61,6 +61,15 @@ struct drm_syncobj {
Quoted 40 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

include/drm/drm_syncobj.h struct drm_syncobj { · line 67

Quoted 7 lines
include/drm/drm_syncobj.h +4 -0
           * @file: A file backing for this syncobj.
           */
          struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband payload value to wait on binary

syncobj

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines

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

include/drm/drm_syncobj.h +3 -0
+     * seqno will be put into the syncobj.
+     */
+    u64 sideband_payload;
      };
         void drm_syncobj_free(struct kref *kref);
include/uapi/drm/drm.h +1 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
/**
* Device specific ioctls should only be in their respective
headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw

Re: 回复:[PATCH v3 1/1] drm/syncobj: add sideband payload

Quoted 5 lines · Jason Ekstrand

I've got a couple questions that I think go along the lines of what Christian wrote:

1. Should it really be called sideband?  It's a very generic term for what is currently a very generic thing. However, maybe we don't want it to be so generic?

2. Do we really want get/set?  Or do we want get/increment?  We have to do the get/increment during vkQueueSubmit on both the wait and the signal side but get+add+set is a bit heavy.  I guess you could do one bit get of all the binary semaphores and then a set for all the signaled ones which sets them to the previous value + 1.

Our last iteration gather all the binary semaphores to read them and write them all back with signaled one incremented by one.

It could be batched into one ioctl with a flag that checks whether a given syncobj needs to be get+inc or just get.

Quoted 2 lines

My concern with making it a super-generic thing is that it has an extremely specific use and in order for cross-process sharing to work, all users have to use it exactly the same way.  We could call it a "reserved value" or something like that to make it more clear what the intention is.  In any case, we should make sure that it's very clearly documented in the design doc.

Agreed, this needs documentation.

I'll add a preceding commit adding timeline documentation and document this.

-Lionel

Quoted 6 lines · On Thu, Aug 8, 2019 at 10:26 AM Koenig, Christian <[email protected]…

Yeah, the idea is indeed rather clever. I'm just wondering if we don't need to optimize it even more.

Quoted 432 lines

In other words could some IOCTL overhead be saved here if we directly take the value for binary semaphores waits and signals?

Christian.

Am 08.08.19 um 17:23 schrieb Zhou, David(ChunMing):

Quoted 425 lines
    Thank you, I got your mean.
    when you have sideband payload, you will go into timeline path.
    Clever!

    -David

    -------- 原始邮件 --------
    主题:Re: [PATCH v3 1/1] drm/syncobj: add sideband payload
    发件人:Lionel Landwerlin
    收件人:"Zhou, David(ChunMing)" ,[email protected]
    <mailto:[email protected]>
    抄送:"Koenig, Christian" ,Jason Ekstrand ,"Zhou, David(ChunMing)"

    On 08/08/2019 17:48, Chunming Zhou wrote:
    > 在 2019/8/8 22:34, Lionel Landwerlin 写道:
    >> On 08/08/2019 17:16, Chunming Zhou wrote:
    >>> 在 2019/8/8 22:01, Lionel Landwerlin 写道:
    >>>> On 08/08/2019 16:42, Chunming Zhou wrote:
    >>>>> No, I just see your comment "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. ".
    >>>> That was meant to say wait on the chain fence to reach the
    sideband
    >>>> payload value.
    >>>>
    >>>> It a bit confusing but I can't see any other way to word it.
    >>>>
    >>>>
    >>>>> In that, you mentioned wait for sideband.
    >>>>> So I want to know we how to use that, maybe I miss something in
    >>>>> previous
    >>>>> discussing thread.
    >>>> In QueueSubmit(), we start by reading the sideband payloads :
    >>>>
    https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655
    >>>>
    >>>>
    >>>> Then build everything for the submission and hand it over to the
    >>>> submission thread.
    >>>>
    >>>> Instead of the just waiting on the timeline semaphore
    values, we also
    >>>> wait on the binary semaphore sideband payload values.
    >>> Waiting on timeline values is when finding fence in kernel.
    >>
    >> Hmm aren't you waiting in a thread in userspace?
    > Yes, For timeline case, we can use waitForSyncobj()..., At begin of
    > QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.
    >
    > But I still didn't get how to wait on sideband for binary Syncobj.
    >
    > Ah, I see, you will compare it in your QueueThread, if sideband
    value is
    >   >= expected, then do submission, otherwise, loop QueueThread,
    right?


    Just treat binary semaphores as timelines and waitForSyncobj on the
    sideband payload value.

    It should make the submission thread any busier than currently.


    -Lionel


    >
    > That sounds the QueueThread will be always busy.
    >
    > -David
    >
    >
    >>
    >>> But I don't see how to wait/block in kernel when finding
    fence for
    >>> binary sideband payload  values.
    >>
    >> Essentially our driver now handles timelines & binary
    semaphore using
    >> dma-fence-chain in both cases.
    >
    >
    >> Only with timelines we take the values submitted by the vulkan
    >> application.
    >
    >> The binary semaphore auto increment on vkQueueSubmit() and that is
    >> managed by the userspace driver.
    >>
    >>
    >> -Lionel
    >>
    >>
    >>>
    >>> -David
    >>>
    >>>> Finally before exiting the QueueSubmit() call, we bump the
    sideband
    >>>> payloads of all the binary semaphores have have been signaled :
    >>>>
    https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806
    >>>>
    >>>>
    >>>>
    >>>> Whoever calls QueueSubmit() after that will pickup the new
    sideband
    >>>> payload values to wait on.
    >>>>
    >>>>
    >>>> -Lionel
    >>>>
    >>>>
    >>>>
    >>>>> -DAvid
    >>>>>
    >>>>>
    >>>>> 在 2019/8/8 21:38, Lionel Landwerlin 写道:
    >>>>>> Interesting question :)
    >>>>>>
    >>>>>> I didn't see any usecase for that.
    >>>>>> This sideband payload value is used for a wait so waiting
    on the wait
    >>>>>> value for another wait is bit meta :)
    >>>>>>
    >>>>>> Do you have a use case for that?
    >>>>>>
    >>>>>> -Lionel
    >>>>>>
    >>>>>> On 08/08/2019 16:23, Chunming Zhou wrote:
    >>>>>>> The propursal is fine with me.
    >>>>>>>
    >>>>>>> one question:
    >>>>>>>
    >>>>>>> how to wait sideband payload? Following patch will show that?
    >>>>>>>
    >>>>>>> -David
    >>>>>>>
    >>>>>>> 在 2019/8/8 21:14, Lionel Landwerlin 写道:
    >>>>>>>> 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)
    >>>>>>>>
    >>>>>>>> Signed-off-by: Lionel Landwerlin
    <[email protected]>
    <mailto:[email protected]>
    >>>>>>>> Cc: Christian Koenig <[email protected]>
    <mailto:[email protected]>
    >>>>>>>> Cc: Jason Ekstrand <[email protected]>
    <mailto:[email protected]>
    >>>>>>>> Cc: David(ChunMing) Zhou <[email protected]>
    <mailto:[email protected]>
    >>>>>>>> ---
    >>>>>>>> drivers/gpu/drm/drm_internal.h |  4 ++
    >>>>>>>> drivers/gpu/drm/drm_ioctl.c    |  5 +++
    >>>>>>>> drivers/gpu/drm/drm_syncobj.c  | 79
    >>>>>>>> +++++++++++++++++++++++++++++++++-
    >>>>>>>> include/drm/drm_syncobj.h      |  9 ++++
    >>>>>>>> include/uapi/drm/drm.h         |  2 +
    >>>>>>>>       5 files changed, 98 insertions(+), 1 deletion(-)
    >>>>>>>>
    >>>>>>>> diff --git a/drivers/gpu/drm/drm_internal.h
    >>>>>>>> b/drivers/gpu/drm/drm_internal.h
    >>>>>>>> index 51a2055c8f18..0c9736199df0 100644
    >>>>>>>> --- a/drivers/gpu/drm/drm_internal.h
    >>>>>>>> +++ b/drivers/gpu/drm/drm_internal.h
    >>>>>>>> @@ -208,6 +208,10 @@ 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_get_sideband_ioctl(struct drm_device
    *dev, void
    >>>>>>>> *data,
    >>>>>>>> +                   struct drm_file *file_private);
    >>>>>>>> +int drm_syncobj_set_sideband_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,
    >>>>>>>> diff --git a/drivers/gpu/drm/drm_ioctl.c
    >>>>>>>> b/drivers/gpu/drm/drm_ioctl.c
    >>>>>>>> index f675a3bb2c88..48500bf62801 100644
    >>>>>>>> --- a/drivers/gpu/drm/drm_ioctl.c
    >>>>>>>> +++ b/drivers/gpu/drm/drm_ioctl.c
    >>>>>>>> @@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
    >>>>>>>> drm_syncobj_get_sideband_ioctl,
    >>>>>>>> + DRM_RENDER_ALLOW),
    >>>>>>>> + DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,
    >>>>>>>> drm_syncobj_set_sideband_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),
    >>>>>>>> diff --git a/drivers/gpu/drm/drm_syncobj.c
    >>>>>>>> b/drivers/gpu/drm/drm_syncobj.c
    >>>>>>>> index b927e482e554..c90ef20b9242 100644
    >>>>>>>> --- a/drivers/gpu/drm/drm_syncobj.c
    >>>>>>>> +++ b/drivers/gpu/drm/drm_syncobj.c
    >>>>>>>> @@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct
    drm_device
    >>>>>>>> *dev, void *data,
    >>>>>>>>           if (ret < 0)
    >>>>>>>> return ret;
    >>>>>>>>       -    for (i = 0; i < args->count_handles; i++)
    >>>>>>>> +    for (i = 0; i < args->count_handles; i++) {
    >>>>>>>> drm_syncobj_replace_fence(syncobjs[i], NULL);
    >>>>>>>> + syncobjs[i]->sideband_payload = 0;
    >>>>>>>> +    }
    >>>>>>>> drm_syncobj_array_free(syncobjs, args->count_handles);
    >>>>>>>>       @@ -1321,6 +1323,81 @@ int
    drm_syncobj_query_ioctl(struct
    >>>>>>>> drm_device *dev, void *data,
    >>>>>>>>               if (ret)
    >>>>>>>> break;
    >>>>>>>>           }
    >>>>>>>> +
    >>>>>>>> + drm_syncobj_array_free(syncobjs, args->count_handles);
    >>>>>>>> +
    >>>>>>>> +    return ret;
    >>>>>>>> +}
    >>>>>>>> +
    >>>>>>>> +int drm_syncobj_get_sideband_ioctl(struct drm_device
    *dev, void
    >>>>>>>> *data,
    >>>>>>>> +                   struct drm_file *file_private)
    >>>>>>>> +{
    >>>>>>>> +    struct drm_syncobj_timeline_array *args = data;
    >>>>>>>> +    struct drm_syncobj **syncobjs;
    >>>>>>>> +    uint64_t __user *points =
    u64_to_user_ptr(args->points);
    >>>>>>>> +    uint32_t i;
    >>>>>>>> +    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;
    >>>>>>>> +
    >>>>>>>> +    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++) {
    >>>>>>>> + copy_to_user(&points[i], &syncobjs[i]->sideband_payload,
    >>>>>>>> sizeof(uint64_t));
    >>>>>>>> +        ret = ret ? -EFAULT : 0;
    >>>>>>>> +        if (ret)
    >>>>>>>> + break;
    >>>>>>>> +    }
    >>>>>>>> +
    >>>>>>>> + drm_syncobj_array_free(syncobjs, args->count_handles);
    >>>>>>>> +
    >>>>>>>> +    return ret;
    >>>>>>>> +}
    >>>>>>>> +
    >>>>>>>> +int drm_syncobj_set_sideband_ioctl(struct drm_device
    *dev, void
    >>>>>>>> *data,
    >>>>>>>> +                   struct drm_file *file_private)
    >>>>>>>> +{
    >>>>>>>> +    struct drm_syncobj_timeline_array *args = data;
    >>>>>>>> +    struct drm_syncobj **syncobjs;
    >>>>>>>> +    uint64_t __user *points =
    u64_to_user_ptr(args->points);
    >>>>>>>> +    uint32_t i;
    >>>>>>>> +    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;
    >>>>>>>> +
    >>>>>>>> +    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++) {
    >>>>>>>> + copy_from_user(&syncobjs[i]->sideband_payload, &points[i],
    >>>>>>>> sizeof(uint64_t));
    >>>>>>>> +        ret = ret ? -EFAULT : 0;
    >>>>>>>> +        if (ret)
    >>>>>>>> + break;
    >>>>>>>> +    }
    >>>>>>>> +
    >>>>>>>> drm_syncobj_array_free(syncobjs, args->count_handles);
    >>>>>>>> return ret;
    >>>>>>>> diff --git a/include/drm/drm_syncobj.h
    b/include/drm/drm_syncobj.h
    >>>>>>>> index 6cf7243a1dc5..b587b8e07547 100644
    >>>>>>>> --- a/include/drm/drm_syncobj.h
    >>>>>>>> +++ b/include/drm/drm_syncobj.h
    >>>>>>>> @@ -61,6 +61,15 @@ struct drm_syncobj {
    >>>>>>>>            * @file: A file backing for this syncobj.
    >>>>>>>>            */
    >>>>>>>>           struct file *file;
    >>>>>>>> +    /**
    >>>>>>>> +     * @sideband_payload: A 64bit side band payload.
    >>>>>>>> +     *
    >>>>>>>> +     * We use the sideband 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 sideband_payload;
    >>>>>>>>       };
    >>>>>>>>          void drm_syncobj_free(struct kref *kref);
    >>>>>>>> diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
    >>>>>>>> index 8a5b2f8f8eb9..cffdc6c9772c 100644
    >>>>>>>> --- a/include/uapi/drm/drm.h
    >>>>>>>> +++ b/include/uapi/drm/drm.h
    >>>>>>>> @@ -946,6 +946,8 @@ 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_GET_SIDEBAND DRM_IOR(0xCE, struct
    >>>>>>>> drm_syncobj_timeline_array)
    >>>>>>>> +#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF,
    struct
    >>>>>>>> drm_syncobj_timeline_array)
    >>>>>>>>          /**
    >>>>>>>>        * Device specific ioctls should only be in their
    respective
    >>>>>>>> headers
    >>

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#15 lore raw

Re: 回复:[PATCH v3 1/1] drm/syncobj: add sideband payload

In reply to Koenig, Christian

Are you talking about the new ioctls or the existing wait?

Because we do not use the signal ioctl for binary semaphores.
On the wait side, it's used only for VkFence and we would save a 64bit copy per fence we wait on.

I can't see that being a perf bottleneck.

On the new sideband ioctls if we can find a way to have only one it would save an ioctl per QueueSubmit.

-Lionel

Quoted 397 lines · Christian

Yeah, the idea is indeed rather clever. I'm just wondering if we don't need to optimize it even more.

In other words could some IOCTL overhead be saved here if we directly take the value for binary semaphores waits and signals?

Christian.

Am 08.08.19 um 17:23 schrieb Zhou, David(ChunMing):

Quoted 389 lines

Thank you, I got your mean.
when you have sideband payload, you will go into timeline path. Clever!

-David

-------- 原始邮件 --------
主题:Re: [PATCH v3 1/1] drm/syncobj: add sideband payload 发件人:Lionel Landwerlin
收件人:"Zhou, David(ChunMing)" ,[email protected] 抄送:"Koenig, Christian" ,Jason Ekstrand ,"Zhou, David(ChunMing)"

Quoted 6 lines · Chunming Zhou
Quoted 5 lines · Lionel Landwerlin
Quoted 4 lines · Chunming Zhou
Quoted 3 lines · Lionel Landwerlin
Quoted 2 lines · Chunming Zhou

No, I just see your comment "The next vkQueueSubmit() waiting on a the syncobj will read the sideband payload and

wait for a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

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

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

trigger the submission on the kernel driver. ".

That was meant to say wait on the chain fence to reach the sideband payload value.

It a bit confusing but I can't see any other way to word it.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

In that, you mentioned wait for sideband.
So I want to know we how to use that, maybe I miss something in previous
discussing thread.

In QueueSubmit(), we start by reading the sideband payloads :

https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L655

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Then build everything for the submission and hand it over to the submission thread.

Instead of the just waiting on the timeline semaphore values, we

also

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines
Quoted 1 line

wait on the binary semaphore sideband payload values.

Waiting on timeline values is when finding fence in kernel.

Hmm aren't you waiting in a thread in userspace?

Yes, For timeline case, we can use waitForSyncobj()..., At begin of QueueThread, I let it wait in cs_ioctl when drm_syncobj_find_fence.

But I still didn't get how to wait on sideband for binary Syncobj.

Ah, I see, you will compare it in your QueueThread, if sideband

value is

Quoted 1 line

   >= expected, then do submission, otherwise, loop QueueThread, right?

Just treat binary semaphores as timelines and waitForSyncobj on the sideband payload value.

It should make the submission thread any busier than currently.

-Lionel

Quoted 30 lines

That sounds the QueueThread will be always busy.

-David

Quoted 24 lines
Quoted 3 lines

But I don't see how to wait/block in kernel when finding fence for binary sideband payload  values.

Essentially our driver now handles timelines & binary semaphore using dma-fence-chain in both cases.

Only with timelines we take the values submitted by the vulkan application.

The binary semaphore auto increment on vkQueueSubmit() and that is managed by the userspace driver.

-Lionel

Quoted 6 lines

-David

Quoted 3 lines

Finally before exiting the QueueSubmit() call, we bump the sideband payloads of all the binary semaphores have have been signaled :

https://gitlab.freedesktop.org/llandwerlin/mesa/blob/review/anv-timeline_semaphore_prep/src/intel/vulkan/anv_queue.c#L806

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Whoever calls QueueSubmit() after that will pickup the new sideband payload values to wait on.

-Lionel

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

-DAvid

Quoted 4 lines · Lionel Landwerlin

Interesting question :)

I didn't see any usecase for that.
This sideband payload value is used for a wait so waiting on

the wait

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

value for another wait is bit meta :)

Do you have a use case for that?

-Lionel

Quoted 4 lines · Chunming Zhou

The propursal is fine with me.

one question:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

how to wait sideband payload? Following patch will show that?

-David

Quoted 3 lines · Lionel Landwerlin

The Vulkan timeline semaphores allow signaling to happen on the point
of the timeline without all of the its dependencies to be

created.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

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.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

If a binary semaphore is submitted for signaling along the side of a
timeline semaphore waiting for completion that means that

the drm

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

syncobj associated with that binary semaphore will not have

a DMA

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

fence associated with it by the time vkQueueSubmit()

returns. This

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

and
the fact that a binary semaphore can be signaled and

unsignaled as

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

before its DMA fences materialize mean that we cannot just

rely on

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

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

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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)

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

v3: Use 2 ioctls for get/set (Christian)

Cc Christian Koenig <[email protected]>
Cc Jason Ekstrand <[email protected]>
Cc David(ChunMing) Zhou <[email protected]>

---
drivers/gpu/drm/drm_internal.h |  4 ++
drivers/gpu/drm/drm_ioctl.c    |  5 +++
drivers/gpu/drm/drm_syncobj.c  | 79
+++++++++++++++++++++++++++++++++-
include/drm/drm_syncobj.h      |  9 ++++
include/uapi/drm/drm.h         |  2 +

       5 files changed, 98 insertions(+), 1 deletion(-)
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/drm_internal.h int

Quoted 6 lines
drivers/gpu/drm/drm_internal.h +0 -0
index 51a2055c8f18..0c9736199df0 100644
@@ -208,6 +208,10 @@ int 

drm_syncobj_timeline_signal_ioctl(struct

Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
Quoted 134 lines
drivers/gpu/drm/drm_internal.h +0 -0
 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_get_sideband_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *file_private);
+int drm_syncobj_set_sideband_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 +0 -0
index f675a3bb2c88..48500bf62801 100644
@@ -703,6 +703,11 @@ 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_GET_SIDEBAND,
drm_syncobj_get_sideband_ioctl,
+ DRM_RENDER_ALLOW),
+ DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SET_SIDEBAND,
drm_syncobj_set_sideband_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 +3 -0
index b927e482e554..c90ef20b9242 100644
@@ -1150,8 +1150,10 @@ drm_syncobj_reset_ioctl(struct drm_device
 *dev, void *data,
            if (ret < 0)
                return ret;
        -    for (i = 0; i < args->count_handles; i++)
+    for (i = 0; i < args->count_handles; i++) {
 drm_syncobj_replace_fence(syncobjs[i], NULL);
+ syncobjs[i]->sideband_payload = 0;
+    }
 drm_syncobj_array_free(syncobjs, args->count_handles);

       @@ -1321,6 +1323,81 @@ int drm_syncobj_query_ioctl(struct drm_device *dev, void *data,
               if (ret)
                   break;
           }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+ drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_get_sideband_ioctl(struct drm_device *dev, void

*data,
+ struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_to_user(&points[i], &syncobjs[i]->sideband_payload,

sizeof(uint64_t));
+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }

drivers/gpu/drm/drm_syncobj.c +7 -0
+
+ drm_syncobj_array_free(syncobjs, args->count_handles);
+
+    return ret;
+}
+
+int drm_syncobj_set_sideband_ioctl(struct drm_device *dev, void

*data,
+ struct drm_file *file_private)

drivers/gpu/drm/drm_syncobj.c +25 -0
+{
+    struct drm_syncobj_timeline_array *args = data;
+    struct drm_syncobj **syncobjs;
+    uint64_t __user *points = u64_to_user_ptr(args->points);
+    uint32_t i;
+    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;
+
+    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++) {
+ copy_from_user(&syncobjs[i]->sideband_payload, &points[i],

sizeof(uint64_t));

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines

+        ret = ret ? -EFAULT : 0;
+        if (ret)
+            break;
+    }
+
drm_syncobj_array_free(syncobjs, args->count_handles); return ret;

(quoted diff) +0 -0

b/include/drm/drm_syncobj.h

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

include/drm/drm_syncobj.h struct drm_syncobj { · line 67

Quoted 11 lines

index 6cf7243a1dc5..b587b8e07547 100644

include/drm/drm_syncobj.h +4 -0
@@ -61,6 +61,15 @@ struct drm_syncobj {
             * @file: A file backing for this syncobj.
             */
            struct file *file;
+    /**
+     * @sideband_payload: A 64bit side band payload.
+     *
+     * We use the sideband payload value to wait on binary 

syncobj

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

fences
+     * to materialize. It is a reservation mechanism for the signaler to
+     * express that at some point in the future a dma fence

with

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

the same
+     * seqno will be put into the syncobj. +     */
+    u64 sideband_payload;
       };
          void drm_syncobj_free(struct kref *kref);

include/uapi/drm/drm.h +0 -0
index 8a5b2f8f8eb9..cffdc6c9772c 100644
@@ -946,6 +946,8 @@ 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)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h +1 -0
        #define DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL DRM_IOWR(0xCD,
 struct drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_GET_SIDEBAND DRM_IOR(0xCE, struct

drm_syncobj_timeline_array)
+#define DRM_IOCTL_SYNCOBJ_SET_SIDEBAND DRM_IOWR(0xCF, struct drm_syncobj_timeline_array)
          /**
        * Device specific ioctls should only be in their

respective

Quoted 2 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

headers

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel