drm: add syncobj timeline support v6
Subsystems (4)
RFC PATCH 1/4 drm: add syncobj timeline support v6
This patch is for VK_KHR_timeline_semaphore extension, semaphore is called syncobj in kernel side:
This extension introduces a new type of syncobj that has an integer payload identifying a point in a timeline. Such timeline syncobjs support the
following operations:
* CPU query - A host operation that allows querying the payload of the
timeline syncobj.
* CPU wait - A host operation that allows a blocking wait for a
timeline syncobj to reach a specified value.
* Device wait - A device operation that allows waiting for a
timeline syncobj to reach a specified value.
* Device signal - A device operation that allows advancing the
timeline syncobj to a specified value.
v1:
Since it's a timeline, that means the front time point(PT) always is signaled before the late PT. a. signal PT design:
Signal PT fence N depends on PT[N-1] fence and signal opertion fence, when PT[N] fence is signaled, the timeline will increase to value of PT[N].
b. wait PT design:
Wait PT fence is signaled by reaching timeline point value, when timeline is increasing, will compare wait PTs value with new timeline value, if PT value is lower than timeline value, then wait PT will be signaled, otherwise keep in list. syncobj wait operation can wait on any point of timeline, so need a RB tree to order them. And wait PT could ahead of signal PT, we need a sumission fence to perform that.
v2:
1. remove unused DRM_SYNCOBJ_CREATE_TYPE_NORMAL. (Christian)
2. move unexposed denitions to .c file. (Daniel Vetter)
3. split up the change to drm_syncobj_find_fence() in a separate patch. (Christian)
4. split up the change to drm_syncobj_replace_fence() in a separate patch.
5. drop the submission_fence implementation and instead use wait_event() for that. (Christian)
6. WARN_ON(point != 0) for NORMAL type syncobj case. (Daniel Vetter)
v3:
1. replace normal syncobj with timeline implemenation. (Vetter and Christian)
a. normal syncobj signal op will create a signal PT to tail of signal pt list.
b. normal syncobj wait op will create a wait pt with last signal point, and this wait PT is only signaled by related signal point PT.
2. many bug fix and clean up
3. stub fence moving is moved to other patch.
v4:
1. fix RB tree loop with while(node=rb_first(...)). (Christian)
2. fix syncobj lifecycle. (Christian)
3. only enable_signaling when there is wait_pt. (Christian)
4. fix timeline path issues.
5. write a timeline test in libdrm
v5: (Christian)
1. semaphore is called syncobj in kernel side.
2. don't need 'timeline' characters in some function name.
3. keep syncobj cb
v6: (Christian)
1. merge syncobj_timeline to syncobj structure
2. simplify some check sentences.
3. some misc change.
4. fix CTS failed issue
normal syncobj is tested by ./deqp-vk -n dEQP-VK*semaphore* timeline syncobj is tested by ./amdgpu_test -s 9
--- drivers/gpu/drm/drm_syncobj.c | 307 ++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 2 +- include/drm/drm_syncobj.h | 65 ++--- include/uapi/drm/drm.h | 1 + 4 files changed, 299 insertions(+), 76 deletions(-)
drivers/gpu/drm/drm_syncobj.c +264 -43
@@ -56,6 +56,9 @@#include "drm_internal.h" #include <drm/drm_syncobj.h> +/* merge normal syncobj to timeline syncobj, the point interval is 1 */ +#define DRM_SYNCOBJ_INDIVIDUAL_POINT 1 +struct drm_syncobj_stub_fence {struct dma_fence base;spinlock_t lock;
@@ -82,6 +85,11 @@ static const struct dma_fence_ops drm_syncobj_stub_fence_ops = { .release = drm_syncobj_stub_fence_release, }; +struct drm_syncobj_signal_pt { +struct dma_fence_array *base; +u64 value; +struct list_head list; +};/** * drm_syncobj_find - lookup and reference a sync object.
@@ -117,6 +125,9 @@ static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,list_add_tail (&cb->node, &syncobj->cb_list); } +static int drm_syncobj_search_fence (struct drm_syncobj *syncobj,u64 point, +u64 flags,struct dma_fence **fence); + static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, struct dma_fence **fence, struct drm_syncobj_cb *cb,
@@ -124,8 +135,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, {int ret; - *fence =drm_syncobj_fence_get (syncobj); -if (*fence) + ret =drm_syncobj_search_fence (syncobj,0 ,0 , fence); +if (!ret)return 1 ;spin_lock (&syncobj->lock);
@@ -133,10 +144,12 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,* have the lock, try one more time just to be sure we don't add a * callback when a fence has already been set. */ -if (syncobj->fence) { - *fence =dma_fence_get (rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock))); - ret =1 ; +if (fence && !list_empty (&syncobj->signal_pt_list)) { +spin_unlock (&syncobj->lock); +drm_syncobj_search_fence (syncobj,0 ,0 , fence); +if (*fence) + ret =1 ; +spin_lock (&syncobj->lock); }else { *fence =NULL ;drm_syncobj_add_callback_locked (syncobj, cb, func);
@@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,spin_unlock (&syncobj->lock); } +static void drm_syncobj_timeline_init (struct drm_syncobj *syncobj) +{ +spin_lock (&syncobj->lock); + syncobj->timeline_context =dma_fence_context_alloc (1 ); + syncobj->timeline =0 ; + syncobj->signal_point =0 ; +init_waitqueue_head (&syncobj->wq); + +INIT_LIST_HEAD (&syncobj->signal_pt_list); +spin_unlock (&syncobj->lock); +} + +static void drm_syncobj_timeline_fini (struct drm_syncobj *syncobj) +{ +struct drm_syncobj_signal_pt *signal_pt =NULL , *tmp; + +spin_lock (&syncobj->lock); +list_for_each_entry_safe (signal_pt, tmp, + &syncobj->signal_pt_list, list) { +list_del (&signal_pt->list); +dma_fence_put (&signal_pt->base->base); +kfree (signal_pt); + } +spin_unlock (&syncobj->lock); +} + +static struct dma_fence +*drm_syncobj_find_signal_pt_for_point (struct drm_syncobj *syncobj, +uint64_t point) +{ +struct drm_syncobj_signal_pt *signal_pt; + +if ((syncobj->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) && + (point <= syncobj->timeline)) { +struct drm_syncobj_stub_fence *fence = +kzalloc (sizeof (struct drm_syncobj_stub_fence ), +GFP_KERNEL ); + +if (!fence) +return NULL ; +spin_lock_init (&fence->lock); +dma_fence_init (&fence->base, + &drm_syncobj_stub_fence_ops, + &fence->lock, + syncobj->timeline_context, + point); + +dma_fence_signal (&fence->base); +return &fence->base; + } + +list_for_each_entry (signal_pt, &syncobj->signal_pt_list, list) { +if (point > signal_pt->value) +continue ; +if ((syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) && + (point != signal_pt->value)) +continue ; +return dma_fence_get (&signal_pt->base->base); + } +return NULL ; +} + +static int drm_syncobj_create_signal_pt (struct drm_syncobj *syncobj, +struct dma_fence *fence, +u64 point) +{ +struct drm_syncobj_signal_pt *signal_pt = +kzalloc (sizeof (struct drm_syncobj_signal_pt ),GFP_KERNEL ); +struct drm_syncobj_signal_pt *tail_pt; +struct dma_fence **fences; +int num_fences =0 ; +int ret =0 , i; + +if (!signal_pt) +return -ENOMEM ; +if (syncobj->signal_point >= point) { +DRM_WARN ("A later signal is ready!" ); + goto out; + } +if (!fence) + goto out; + + fences =kmalloc_array (sizeof (void *),2 ,GFP_KERNEL ); +if (!fences) + goto out; + fences[num_fences++] =dma_fence_get (fence); +/* timeline syncobj must take this dependency */ +if (syncobj->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) { +spin_lock (&syncobj->lock); +if (!list_empty (&syncobj->signal_pt_list)) { + tail_pt =list_last_entry (&syncobj->signal_pt_list, + struct drm_syncobj_signal_pt, list); + fences[num_fences++] =dma_fence_get (&tail_pt->base->base); + } +spin_unlock (&syncobj->lock); + } + signal_pt->base =dma_fence_array_create (num_fences, fences, + syncobj->timeline_context, + point, false); +if (!signal_pt->base) + goto fail; + +spin_lock (&syncobj->lock); + signal_pt->value = point; +INIT_LIST_HEAD (&signal_pt->list); +list_add_tail (&signal_pt->list, &syncobj->signal_pt_list); + syncobj->signal_point = point; +spin_unlock (&syncobj->lock); +wake_up_all (&syncobj->wq); + +return 0 ; +fail: +for (i =0 ; i < num_fences; i++) +dma_fence_put (fences[i]); +kfree (fences); +out: +kfree (signal_pt); +return ret; +} + +static void drm_syncobj_garbage_collection (struct drm_syncobj *syncobj) +{ +struct drm_syncobj_signal_pt *signal_pt, *tmp, *tail_pt; + +spin_lock (&syncobj->lock); + tail_pt =list_last_entry (&syncobj->signal_pt_list, + struct drm_syncobj_signal_pt, + list); +list_for_each_entry_safe (signal_pt, tmp, + &syncobj->signal_pt_list, list) { +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL && + signal_pt == tail_pt) +continue ; +if (dma_fence_is_signaled (&signal_pt->base->base)) { + syncobj->timeline = signal_pt->value; +list_del (&signal_pt->list); +dma_fence_put (&signal_pt->base->base); +kfree (signal_pt); + }else { +/*signal_pt is in order in list, from small to big, so +* the later must not be signal either */ +break ; + } + } + +spin_unlock (&syncobj->lock); +}/** * drm_syncobj_replace_fence - replace fence in a sync object. * @syncobj: Sync object to replace fence in
@@ -176,28 +336,29 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,u64 point, struct dma_fence *fence) { - struct dma_fence *old_fence; -struct drm_syncobj_cb *cur, *tmp; - -if (fence) -dma_fence_get (fence); - -spin_lock (&syncobj->lock); - - old_fence =rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock)); -rcu_assign_pointer (syncobj->fence, fence); + u64 pt_value = point; + +drm_syncobj_garbage_collection (syncobj); +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) { +if (!fence) { +drm_syncobj_timeline_fini (syncobj); +drm_syncobj_timeline_init (syncobj); +return ; + } + pt_value = syncobj->signal_point + +DRM_SYNCOBJ_INDIVIDUAL_POINT ; + } +drm_syncobj_create_signal_pt (syncobj, fence, pt_value); +if (fence) { +struct drm_syncobj_cb *cur, *tmp; -if (fence != old_fence) { +spin_lock (&syncobj->lock);list_for_each_entry_safe (cur, tmp, &syncobj->cb_list, node) {list_del_init (&cur->node); cur->func (syncobj, cur); } +spin_unlock (&syncobj->lock); } - -spin_unlock (&syncobj->lock); - -dma_fence_put (old_fence); }EXPORT_SYMBOL (drm_syncobj_replace_fence);
@@ -220,6 +381,60 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)return 0 ; } +#define WAIT_FOR_SUBMIT_MSECS 10000 + +static struct dma_fence * +drm_syncobj_point_get (struct drm_syncobj *syncobj,u64 point,u64 flags) +{ +struct dma_fence *fence; +int ret =0 ; + +if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT ) { + ret =wait_event_timeout (syncobj->wq, + point <= syncobj->signal_point, +msecs_to_jiffies (WAIT_FOR_SUBMIT_MSECS )); +if (ret <=0 ) +return NULL ; + } +spin_lock (&syncobj->lock); + fence =drm_syncobj_find_signal_pt_for_point (syncobj, point); +spin_unlock (&syncobj->lock); +return fence; +} + +static int drm_syncobj_search_fence (struct drm_syncobj *syncobj,u64 point, +u64 flags,struct dma_fence **fence) +{ +u64 pt_value = point; +int ret =0 ; + +if (!syncobj) +return -ENOENT ; + +drm_syncobj_garbage_collection (syncobj); +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) { +/*INDIVIDUAL syncobj always wait on last pt */ + pt_value = syncobj->signal_point; + +if (pt_value ==0 ) + pt_value +=DRM_SYNCOBJ_INDIVIDUAL_POINT ; + } + *fence =drm_syncobj_point_get (syncobj, pt_value, flags); +if (!*fence) { + ret = -EINVAL ; + } +return ret; +} + +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, +struct dma_fence **fence) { + +return drm_syncobj_search_fence (syncobj, point, +DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT , + fence); +} +EXPORT_SYMBOL (drm_syncobj_lookup_fence); +/** * drm_syncobj_find_fence - lookup and reference the fence in a sync object * @file_private: drm file private pointer
@@ -228,7 +443,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)* @fence: out parameter for the fence * * This is just a convenience function that combines drm_syncobj_find() and -* drm_syncobj_fence_get(). +* drm_syncobj_lookup_fence(). * * Returns 0 on success or a negative error value on failure. On success @fence * contains a reference to the fence, which must be released by calling
@@ -236,18 +451,11 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)*/ int drm_syncobj_find_fence (struct drm_file *file_private,u32 handle,u64 point, -struct dma_fence **fence) -{ +struct dma_fence **fence) {struct drm_syncobj *syncobj =drm_syncobj_find (file_private, handle); -int ret =0 ; - -if (!syncobj) -return -ENOENT ; +int ret; - *fence =drm_syncobj_fence_get (syncobj); -if (!*fence) { - ret = -EINVAL ; - } + ret =drm_syncobj_lookup_fence (syncobj, point, fence);drm_syncobj_put (syncobj);return ret; }
@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref)struct drm_syncobj *syncobj =container_of (kref, struct drm_syncobj, refcount); -drm_syncobj_replace_fence (syncobj,0 ,NULL ); +drm_syncobj_timeline_fini (syncobj);kfree (syncobj); }EXPORT_SYMBOL (drm_syncobj_free);
@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,kref_init (&syncobj->refcount);INIT_LIST_HEAD (&syncobj->cb_list);spin_lock_init (&syncobj->lock); +if (flags &DRM_SYNCOBJ_CREATE_TYPE_TIMELINE ) + syncobj->type =DRM_SYNCOBJ_TYPE_TIMELINE ; +else + syncobj->type =DRM_SYNCOBJ_TYPE_INDIVIDUAL ; +drm_syncobj_timeline_init (syncobj);if (flags &DRM_SYNCOBJ_CREATE_SIGNALED ) { ret =drm_syncobj_assign_null_handle (syncobj);
@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data,return -ENODEV ;/* no valid flags yet */ -if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED ) +if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | +DRM_SYNCOBJ_CREATE_TYPE_TIMELINE ))return -EINVAL ; return drm_syncobj_create_as_handle(file_private,
@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct syncobj_wait_entry *wait = container_of(cb, struct syncobj_wait_entry, syncobj_cb); -/* This happens inside the syncobj lock */ - wait->fence =dma_fence_get (rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock))); +drm_syncobj_search_fence (syncobj,0 ,0 , &wait->fence); +wake_up_process (wait->task); }
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, signaled_count =0 ;for (i =0 ; i < count; ++i) { entries[i].task = current; - entries[i].fence =drm_syncobj_fence_get (syncobjs[i]); + ret =drm_syncobj_search_fence (syncobjs[i],0 ,0 , + &entries[i].fence);if (!entries[i].fence) {if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT ) {continue ;
@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,if (ret <0 )return ret; -for (i =0 ; i < args->count_handles; i++) -drm_syncobj_replace_fence (syncobjs[i],0 ,NULL ); - +for (i =0 ; i < args->count_handles; i++) { +if (syncobjs[i]->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) { +DRM_ERROR ("timeline syncobj cannot reset!\n" ); + ret = -EINVAL ; + goto out; + } +drm_syncobj_timeline_fini (syncobjs[i]); +drm_syncobj_timeline_init (syncobjs[i]); + } +out:drm_syncobj_array_free (syncobjs, args->count_handles); -return 0 ; +return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1 -1
@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb,if (!(flags &I915_EXEC_FENCE_WAIT ))continue ; - fence =drm_syncobj_fence_get (syncobj); +drm_syncobj_lookup_fence (syncobj,0 , &fence);if (!fence)return -EINVAL ;
include/drm/drm_syncobj.h +33 -32
99 lines not on this page · raw message
include/uapi/drm/drm.h +1 -0
@@ -717,6 +717,7 @@ struct drm_prime_handle {struct drm_syncobj_create {__u32 handle;#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1)__u32 flags; };
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/4 drm: add support of syncobj timeline point wait v2
points array is one-to-one match with syncobjs array. v2:
add seperate ioctl for timeline point wait, otherwise break uapi.
--- drivers/gpu/drm/drm_internal.h | 2 + drivers/gpu/drm/drm_ioctl.c | 2 + drivers/gpu/drm/drm_syncobj.c | 99 +++++++++++++++++++++++++++++----- include/uapi/drm/drm.h | 14 +++++ 4 files changed, 103 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_internal.h +2 -0
@@ -183,6 +183,8 @@ int drm_syncobj_fd_to_handle_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private);int drm_syncobj_wait_ioctl (struct drm_device *dev,void *data,struct drm_file *file_private); +int drm_syncobj_timeline_wait_ioctl (struct drm_device *dev,void *data, +struct drm_file *file_private);int drm_syncobj_reset_ioctl (struct drm_device *dev,void *data,struct drm_file *file_private); int drm_syncobj_signal_ioctl(struct drm_device *dev, void *data,
drivers/gpu/drm/drm_ioctl.c +2 -0
@@ -669,6 +669,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_UNLOCKED|DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_WAIT , drm_syncobj_wait_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT , drm_syncobj_timeline_wait_ioctl, +DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_RESET , drm_syncobj_reset_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
drivers/gpu/drm/drm_syncobj.c +85 -14
195 lines not on this page · raw message
include/uapi/drm/drm.h +14 -0
@@ -748,6 +748,19 @@ struct drm_syncobj_wait {__u32 pad; }; +struct drm_syncobj_timeline_wait { +__u64 handles; +/* wait on specific timeline point for every handles*/ +__u64 points; +/* absolute timeout */ +__s64 timeout_nsec; +__u32 count_handles; +__u32 flags; +__u32 first_signaled;/* only valid when not waiting all */ +__u32 pad; +}; + +struct drm_syncobj_array {__u64 handles;__u32 count_handles;
@@ -910,6 +923,7 @@ extern "C" {#define DRM_IOCTL_MODE_GET_LEASE DRM_IOWR(0xC8, struct drm_mode_get_lease)#define DRM_IOCTL_MODE_REVOKE_LEASE DRM_IOWR(0xC9, struct drm_mode_revoke_lease) +#define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait)/** * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f.
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/4 drm: add timeline syncobj payload query ioctl
In reply to a message not in the archiveuser mode can query timeline payload.
--- drivers/gpu/drm/drm_internal.h | 2 ++ drivers/gpu/drm/drm_ioctl.c | 2 ++ drivers/gpu/drm/drm_syncobj.c | 53 ++++++++++++++++++++++++++++++++++ include/uapi/drm/drm.h | 11 +++++++ 4 files changed, 68 insertions(+)
drivers/gpu/drm/drm_internal.h +2 -0
@@ -189,6 +189,8 @@ int drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, struct drm_file *file_private);int drm_syncobj_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);/* drm_framebuffer.c */ void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
drivers/gpu/drm/drm_ioctl.c +2 -0
@@ -675,6 +675,8 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_UNLOCKED|DRM_RENDER_ALLOW),DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_SIGNAL , drm_syncobj_signal_ioctl,DRM_UNLOCKED |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF (DRM_IOCTL_SYNCOBJ_QUERY , drm_syncobj_query_ioctl, +DRM_UNLOCKED |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_GET_SEQUENCE , drm_crtc_get_sequence_ioctl,DRM_UNLOCKED ),DRM_IOCTL_DEF (DRM_IOCTL_CRTC_QUEUE_SEQUENCE , drm_crtc_queue_sequence_ioctl,DRM_UNLOCKED ), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER|DRM_UNLOCKED),
drivers/gpu/drm/drm_syncobj.c +53 -0
56 lines not on this page · raw message
include/uapi/drm/drm.h +11 -0
@@ -767,6 +767,15 @@ struct drm_syncobj_array {__u32 pad; }; +struct drm_syncobj_timeline_query { +__u64 handles; +/* points are timeline syncobjs payloads returned by query ioctl */ +__u64 points; +__u32 count_handles; +__u32 pad; +}; + +/* Query current scanout sequence number */ struct drm_crtc_get_sequence {__u32 crtc_id;/* requested crtc_id */
@@ -924,6 +933,8 @@ extern "C" {#define DRM_IOCTL_MODE_REVOKE_LEASE DRM_IOWR(0xC9, struct drm_mode_revoke_lease)#define DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT DRM_IOWR(0xCA, struct drm_syncobj_timeline_wait) +#define DRM_IOCTL_SYNCOBJ_QUERY DRM_IOWR(0xCB, struct drm_syncobj_timeline_query) +/** * Device specific ioctls should only be in their respective headers * The device specific ioctl range is from 0x40 to 0x9f.
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/4 drm/amdgpu: add timeline support in amdgpu CS
In reply to a message not in the archive--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 111 +++++++++++++++++++------ include/uapi/drm/amdgpu_drm.h | 9 ++ 3 files changed, 100 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -2
@@ -975,6 +975,11 @@ struct amdgpu_cs_chunk {void *kdata; }; +struct amdgpu_cs_syncobj_post_dep { +struct drm_syncobj *post_dep_syncobj; +u64 point; +}; +struct amdgpu_cs_parser {struct amdgpu_device *adev;struct drm_file *filp;
@@ -1003,9 +1008,8 @@ struct amdgpu_cs_parser {/* user fence */ struct amdgpu_bo_list_entry uf_entry; - +struct amdgpu_cs_syncobj_post_dep *post_dep_syncobjs;unsigned num_post_dep_syncobjs; -struct drm_syncobj **post_dep_syncobjs; }; static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +85 -26
182 lines not on this page · raw message
include/uapi/drm/amdgpu_drm.h +9 -0
@@ -517,6 +517,8 @@ struct drm_amdgpu_gem_va {#define AMDGPU_CHUNK_ID_SYNCOBJ_IN 0x04#define AMDGPU_CHUNK_ID_SYNCOBJ_OUT 0x05#define AMDGPU_CHUNK_ID_BO_HANDLES 0x06 +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT 0x07 +#define AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL 0x08struct drm_amdgpu_cs_chunk {__u32 chunk_id;
@@ -592,6 +594,13 @@ struct drm_amdgpu_cs_chunk_sem {__u32 handle; }; +struct drm_amdgpu_cs_chunk_syncobj { +__u32 handle; +__u32 pad; +__u64 point; +}; + +#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ 0#define AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD 1#define AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD 2
Signature · 6 lines
2.17.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
Quoted 121 lines
This patch is for
VK_KHR_timeline_semaphoreextension, semaphore is called syncobj in kernel side:
This extension introduces a new type of syncobj that has an integer payload identifying a point in a timeline. Such timeline syncobjs support the
following operations:
* CPU query - A host operation that allows querying the payload of the timeline syncobj.
* CPU wait - A host operation that allows a blocking wait for a
timeline syncobj to reach a specified value.
* Device wait - A device operation that allows waiting for a
timeline syncobj to reach a specified value.
* Device signal - A device operation that allows advancing the
timeline syncobj to a specified value.v1:
Since it's a timeline, that means the front time point(PT) always is signaled before the late PT. a. signal PT design:
Signal PT fence N depends on PT[N-1] fence and signal opertion fence, when PT[N] fence is signaled, the timeline will increase to value of PT[N].
b. wait PT design:
Wait PT fence is signaled by reaching timeline point value, when timeline is increasing, will compare wait PTs value with new timeline value, if PT value is lower than timeline value, then wait PT will be signaled, otherwise keep in list. syncobj wait operation can wait on any point of timeline, so need a RB tree to order them. And wait PT could ahead of signal PT, we need a sumission fence to perform that.v2:
1. remove unusedDRM_SYNCOBJ_CREATE_TYPE_NORMAL. (Christian)
2. move unexposed denitions to .c file. (Daniel Vetter)
3. split up the change todrm_syncobj_find_fence()in a separate patch. (Christian)
4. split up the change todrm_syncobj_replace_fence()in a separate patch.
5. drop thesubmission_fenceimplementation and instead usewait_event()for that. (Christian)
6.WARN_ON(point != 0)for NORMAL type syncobj case. (Daniel Vetter)v3:
1. replace normal syncobj with timeline implemenation. (Vetter and Christian)
a. normal syncobj signal op will create a signal PT to tail of signal pt list.
b. normal syncobj wait op will create a wait pt with last signal point, and this wait PT is only signaled by related signal point PT.
2. many bug fix and clean up
3. stub fence moving is moved to other patch.v4:
1. fix RB tree loop with while(node=rb_first(...)). (Christian)
2. fix syncobj lifecycle. (Christian)
3. onlyenable_signalingwhen there iswait_pt. (Christian)
4. fix timeline path issues.
5. write a timeline test in libdrmv5: (Christian)
1. semaphore is called syncobj in kernel side.
2. don't need 'timeline' characters in some function name.
3. keep syncobj cbv6: (Christian)
1. mergesyncobj_timelineto syncobj structure
2. simplify some check sentences.
3. some misc change.
4. fix CTS failed issuenormal syncobj is tested by ./deqp-vk -n dEQP-VK*semaphore* timeline syncobj is tested by ./amdgpu_test -s 9
Signed-off-by Chunming Zhou <[email protected]>Cc Christian Konig <[email protected]>Cc Dave Airlie <[email protected]>Cc Daniel Rakos <[email protected]>Cc Daniel Vetter <[email protected]>--- drivers/gpu/drm/drm_syncobj.c | 307 ++++++++++++++++++--- drivers/gpu/drm/i915/i915_gem_execbuffer.c | 2 +- include/drm/drm_syncobj.h | 65 ++--- include/uapi/drm/drm.h | 1 + 4 files changed, 299 insertions(+), 76 deletions(-)drivers/gpu/drm/drm_syncobj.c +13
-2@@ -56,6 +56,9 @@#include "drm_internal.h" #include <drm/drm_syncobj.h> +/* merge normal syncobj to timeline syncobj, the point interval is 1 */ +#define DRM_SYNCOBJ_INDIVIDUAL_POINT 1 +struct drm_syncobj_stub_fence {struct dma_fence base;spinlock_t lock;@@ -82,6 +85,11 @@ static const struct dma_fence_ops drm_syncobj_stub_fence_ops = { .release = drm_syncobj_stub_fence_release, }; +struct drm_syncobj_signal_pt { +struct dma_fence_array *base; +u64 value; +struct list_head list; +};/** * drm_syncobj_find - lookup and reference a sync object. @@ -117,6 +125,9 @@ static void drm_syncobj_add_callback_locked(struct drm_syncobj *syncobj,list_add_tail (&cb->node, &syncobj->cb_list); } +static int drm_syncobj_search_fence (struct drm_syncobj *syncobj,u64 point, +u64 flags,struct dma_fence **fence); + static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, struct dma_fence **fence, struct drm_syncobj_cb *cb,@@ -124,8 +135,8 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, {int ret; - *fence =drm_syncobj_fence_get (syncobj); -if (*fence) + ret =drm_syncobj_search_fence (syncobj,0 ,0 , fence); +if (!ret)return 1 ;spin_lock (&syncobj->lock);
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, · line 147
Quoted 8 lines
drivers/gpu/drm/drm_syncobj.c +1
-4@@ -133,10 +144,12 @@ static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj,* have the lock, try one more time just to be sure we don't add a * callback when a fence has already been set. */ -if (syncobj->fence) { - *fence =dma_fence_get (rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock))); - ret =1 ; +if (fence && !list_empty (&syncobj->signal_pt_list)) {
I think the "fence" condition is superfluous here, if the fence pointer isn't provided we would have already crashed before.
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_fence_get_or_add_callback(struct drm_syncobj *syncobj, · line 152
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +5
-0+spin_unlock (&syncobj->lock); +drm_syncobj_search_fence (syncobj,0 ,0 , fence); +if (*fence) + ret =1 ; +spin_lock (&syncobj->lock);
Can't we just use "return 1;" here?
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, · line 180
Quoted 8 lines
drivers/gpu/drm/drm_syncobj.c +1
-0}else { *fence =NULL ;drm_syncobj_add_callback_locked (syncobj, cb, func);@@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(struct drm_syncobj *syncobj,spin_unlock (&syncobj->lock); } +static void drm_syncobj_timeline_init (struct drm_syncobj *syncobj)
We still have _timeline_ in the name here.
Quoted 90 lines
drivers/gpu/drm/drm_syncobj.c +90
-0+{ +spin_lock (&syncobj->lock); + syncobj->timeline_context =dma_fence_context_alloc (1 ); + syncobj->timeline =0 ; + syncobj->signal_point =0 ; +init_waitqueue_head (&syncobj->wq); + +INIT_LIST_HEAD (&syncobj->signal_pt_list); +spin_unlock (&syncobj->lock); +} + +static void drm_syncobj_timeline_fini (struct drm_syncobj *syncobj) +{ +struct drm_syncobj_signal_pt *signal_pt =NULL , *tmp; + +spin_lock (&syncobj->lock); +list_for_each_entry_safe (signal_pt, tmp, + &syncobj->signal_pt_list, list) { +list_del (&signal_pt->list); +dma_fence_put (&signal_pt->base->base); +kfree (signal_pt); + } +spin_unlock (&syncobj->lock); +} + +static struct dma_fence +*drm_syncobj_find_signal_pt_for_point (struct drm_syncobj *syncobj, +uint64_t point) +{ +struct drm_syncobj_signal_pt *signal_pt; + +if ((syncobj->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) && + (point <= syncobj->timeline)) { +struct drm_syncobj_stub_fence *fence = +kzalloc (sizeof (struct drm_syncobj_stub_fence ), +GFP_KERNEL ); + +if (!fence) +return NULL ; +spin_lock_init (&fence->lock); +dma_fence_init (&fence->base, + &drm_syncobj_stub_fence_ops, + &fence->lock, + syncobj->timeline_context, + point); + +dma_fence_signal (&fence->base); +return &fence->base; + } + +list_for_each_entry (signal_pt, &syncobj->signal_pt_list, list) { +if (point > signal_pt->value) +continue ; +if ((syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) && + (point != signal_pt->value)) +continue ; +return dma_fence_get (&signal_pt->base->base); + } +return NULL ; +} + +static int drm_syncobj_create_signal_pt (struct drm_syncobj *syncobj, +struct dma_fence *fence, +u64 point) +{ +struct drm_syncobj_signal_pt *signal_pt = +kzalloc (sizeof (struct drm_syncobj_signal_pt ),GFP_KERNEL ); +struct drm_syncobj_signal_pt *tail_pt; +struct dma_fence **fences; +int num_fences =0 ; +int ret =0 , i; + +if (!signal_pt) +return -ENOMEM ; +if (syncobj->signal_point >= point) { +DRM_WARN ("A later signal is ready!" ); + goto out; + } +if (!fence) + goto out; + + fences =kmalloc_array (sizeof (void *),2 ,GFP_KERNEL ); +if (!fences) + goto out; + fences[num_fences++] =dma_fence_get (fence); +/* timeline syncobj must take this dependency */ +if (syncobj->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) { +spin_lock (&syncobj->lock); +if (!list_empty (&syncobj->signal_pt_list)) { + tail_pt = list_last_entry(&syncobj->signal_pt_list,
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, · line 280
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +10
-0+ struct drm_syncobj_signal_pt, list); + fences[num_fences++] =dma_fence_get (&tail_pt->base->base); + } +spin_unlock (&syncobj->lock); + } + signal_pt->base =dma_fence_array_create (num_fences, fences, + syncobj->timeline_context, + point, false); +if (!signal_pt->base) + goto fail;
ret need to be set to an error code here.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, · line 282
Quoted 2 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+ +spin_lock (&syncobj->lock);
Mhm, what happens if the functions is called by two threads at the same time?
I think what we need to do is move the "if (syncobj->signal_point >= point) {" here and double check if the previous fence is still the same.
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct drm_syncobj *syncobj, · line 284
Quoted 2 lines
drivers/gpu/drm/drm_syncobj.c +2
-0+ signal_pt->value = point; +INIT_LIST_HEAD (&signal_pt->list);
That is superfluous, will be overwritten by the following list_add_tail anyway.
Quoted 135 lines
drivers/gpu/drm/drm_syncobj.c +99
-16+list_add_tail (&signal_pt->list, &syncobj->signal_pt_list); + syncobj->signal_point = point; +spin_unlock (&syncobj->lock); +wake_up_all (&syncobj->wq); + +return 0 ; +fail: +for (i =0 ; i < num_fences; i++) +dma_fence_put (fences[i]); +kfree (fences); +out: +kfree (signal_pt); +return ret; +} + +static void drm_syncobj_garbage_collection (struct drm_syncobj *syncobj) +{ +struct drm_syncobj_signal_pt *signal_pt, *tmp, *tail_pt; + +spin_lock (&syncobj->lock); + tail_pt =list_last_entry (&syncobj->signal_pt_list, + struct drm_syncobj_signal_pt, + list); +list_for_each_entry_safe (signal_pt, tmp, + &syncobj->signal_pt_list, list) { +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL && + signal_pt == tail_pt) +continue ; +if (dma_fence_is_signaled (&signal_pt->base->base)) { + syncobj->timeline = signal_pt->value; +list_del (&signal_pt->list); +dma_fence_put (&signal_pt->base->base); +kfree (signal_pt); + }else { +/*signal_pt is in order in list, from small to big, so +* the later must not be signal either */ +break ; + } + } + +spin_unlock (&syncobj->lock); +}/** * drm_syncobj_replace_fence - replace fence in a sync object. * @syncobj: Sync object to replace fence in @@ -176,28 +336,29 @@ void drm_syncobj_replace_fence(struct drm_syncobj *syncobj,u64 point, struct dma_fence *fence) { - struct dma_fence *old_fence; -struct drm_syncobj_cb *cur, *tmp; - -if (fence) -dma_fence_get (fence); - -spin_lock (&syncobj->lock); - - old_fence =rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock)); -rcu_assign_pointer (syncobj->fence, fence); + u64 pt_value = point; + +drm_syncobj_garbage_collection (syncobj); +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) { +if (!fence) { +drm_syncobj_timeline_fini (syncobj); +drm_syncobj_timeline_init (syncobj); +return ; + } + pt_value = syncobj->signal_point + +DRM_SYNCOBJ_INDIVIDUAL_POINT ; + } +drm_syncobj_create_signal_pt (syncobj, fence, pt_value); +if (fence) { +struct drm_syncobj_cb *cur, *tmp; -if (fence != old_fence) { +spin_lock (&syncobj->lock);list_for_each_entry_safe (cur, tmp, &syncobj->cb_list, node) {list_del_init (&cur->node); cur->func (syncobj, cur); } +spin_unlock (&syncobj->lock); } - -spin_unlock (&syncobj->lock); - -dma_fence_put (old_fence); }EXPORT_SYMBOL (drm_syncobj_replace_fence);@@ -220,6 +381,60 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)return 0 ; } +#define WAIT_FOR_SUBMIT_MSECS 10000 + +static struct dma_fence * +drm_syncobj_point_get (struct drm_syncobj *syncobj,u64 point,u64 flags) +{ +struct dma_fence *fence; +int ret =0 ; + +if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT ) { + ret =wait_event_timeout (syncobj->wq, + point <= syncobj->signal_point, +msecs_to_jiffies (WAIT_FOR_SUBMIT_MSECS )); +if (ret <=0 ) +return NULL ; + } +spin_lock (&syncobj->lock); + fence =drm_syncobj_find_signal_pt_for_point (syncobj, point); +spin_unlock (&syncobj->lock); +return fence; +} + +static int drm_syncobj_search_fence (struct drm_syncobj *syncobj,u64 point, +u64 flags,struct dma_fence **fence) +{ +u64 pt_value = point; +int ret =0 ; + +if (!syncobj) +return -ENOENT ; + +drm_syncobj_garbage_collection (syncobj); +if (syncobj->type ==DRM_SYNCOBJ_TYPE_INDIVIDUAL ) { +/*INDIVIDUAL syncobj always wait on last pt */ + pt_value = syncobj->signal_point; + +if (pt_value ==0 ) + pt_value +=DRM_SYNCOBJ_INDIVIDUAL_POINT ; + } + *fence =drm_syncobj_point_get (syncobj, pt_value, flags); +if (!*fence) {
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) · line 433
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c +10
-0+ ret = -EINVAL ; + } +return ret; +} + +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, +struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,
I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Maybe export drm_syncobj_search_fence directly? E.g. with the flags parameter.
Regards,
Christian.
Quoted 241 lines
drivers/gpu/drm/drm_syncobj.c +31
-21+ fence); +} +EXPORT_SYMBOL (drm_syncobj_lookup_fence); +/** * drm_syncobj_find_fence - lookup and reference the fence in a sync object * @file_private: drm file private pointer @@ -228,7 +443,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)* @fence: out parameter for the fence * * This is just a convenience function that combines drm_syncobj_find() and -* drm_syncobj_fence_get(). +* drm_syncobj_lookup_fence(). * * Returns 0 on success or a negative error value on failure. On success @fence * contains a reference to the fence, which must be released by calling @@ -236,18 +451,11 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)*/ int drm_syncobj_find_fence (struct drm_file *file_private,u32 handle,u64 point, -struct dma_fence **fence) -{ +struct dma_fence **fence) {struct drm_syncobj *syncobj =drm_syncobj_find (file_private, handle); -int ret =0 ; - -if (!syncobj) -return -ENOENT ; +int ret; - *fence =drm_syncobj_fence_get (syncobj); -if (!*fence) { - ret = -EINVAL ; - } + ret =drm_syncobj_lookup_fence (syncobj, point, fence);drm_syncobj_put (syncobj);return ret; }@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref)struct drm_syncobj *syncobj =container_of (kref, struct drm_syncobj, refcount); -drm_syncobj_replace_fence (syncobj,0 ,NULL ); +drm_syncobj_timeline_fini (syncobj);kfree (syncobj); }EXPORT_SYMBOL (drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,kref_init (&syncobj->refcount);INIT_LIST_HEAD (&syncobj->cb_list);spin_lock_init (&syncobj->lock); +if (flags &DRM_SYNCOBJ_CREATE_TYPE_TIMELINE ) + syncobj->type =DRM_SYNCOBJ_TYPE_TIMELINE ; +else + syncobj->type =DRM_SYNCOBJ_TYPE_INDIVIDUAL ; +drm_syncobj_timeline_init (syncobj);if (flags &DRM_SYNCOBJ_CREATE_SIGNALED ) { ret =drm_syncobj_assign_null_handle (syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev, void *data,return -ENODEV ;/* no valid flags yet */ -if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED ) +if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | +DRM_SYNCOBJ_CREATE_TYPE_TIMELINE ))return -EINVAL ; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct syncobj_wait_entry *wait = container_of(cb, struct syncobj_wait_entry, syncobj_cb); -/* This happens inside the syncobj lock */ - wait->fence =dma_fence_get (rcu_dereference_protected (syncobj->fence, -lockdep_is_held (&syncobj->lock))); +drm_syncobj_search_fence (syncobj,0 ,0 , &wait->fence); +wake_up_process (wait->task); }@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(struct drm_syncobj **syncobjs, signaled_count =0 ;for (i =0 ; i < count; ++i) { entries[i].task = current; - entries[i].fence =drm_syncobj_fence_get (syncobjs[i]); + ret =drm_syncobj_search_fence (syncobjs[i],0 ,0 , + &entries[i].fence);if (!entries[i].fence) {if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT ) {continue ;@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data,if (ret <0 )return ret; -for (i =0 ; i < args->count_handles; i++) -drm_syncobj_replace_fence (syncobjs[i],0 ,NULL ); - +for (i =0 ; i < args->count_handles; i++) { +if (syncobjs[i]->type ==DRM_SYNCOBJ_TYPE_TIMELINE ) { +DRM_ERROR ("timeline syncobj cannot reset!\n" ); + ret = -EINVAL ; + goto out; + } +drm_syncobj_timeline_fini (syncobjs[i]); +drm_syncobj_timeline_init (syncobjs[i]); + } +out:drm_syncobj_array_free (syncobjs, args->count_handles); -return 0 ; +return ret; }int drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-1@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb,if (!(flags &I915_EXEC_FENCE_WAIT ))continue ; - fence =drm_syncobj_fence_get (syncobj); +drm_syncobj_lookup_fence (syncobj,0 , &fence);if (!fence)return -EINVAL ;include/drm/drm_syncobj.h +33
-32@@ -30,6 +30,11 @@struct drm_syncobj_cb ; +enum drm_syncobj_type { +DRM_SYNCOBJ_TYPE_INDIVIDUAL , +DRM_SYNCOBJ_TYPE_TIMELINE +}; +/** * struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount;/** -* @fence: -* NULL or a pointer to the fence bound to this object. -* -* This field should not be used directly. Use drm_syncobj_fence_get() -* and drm_syncobj_replace_fence() instead. +* @type: indicate syncobj type +*/ +enum drm_syncobj_type type; +/** +* @wq: wait signal operation work queue +*/ +wait_queue_head_t wq; +/** +* @timeline_context: fence context used by timeline */ -struct dma_fence __rcu *fence; +u64 timeline_context;/** -* @cb_list: List of callbacks to call when the &fence gets replaced. +* @timeline: syncobj timeline value, which indicates point is signaled. */ +u64 timeline; +/** +* @signal_point: which indicates the latest signaler point. +*/ +u64 signal_point; +/** +* @signal_pt_list: signaler point list. +*/ +struct list_head signal_pt_list; + +/** +* @cb_list: List of callbacks to call when the &fence gets replaced. +*/ struct list_head cb_list;/** -* @lock: Protects &cb_list and write-locks &fence. +* @lock: Protects syncobj list and write-locks &fence. */ spinlock_t lock;/** @@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj,/** * struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by drm_syncobj_add_callback, additional @@ -106,29 +128,6 @@ drm_syncobj_put(struct drm_syncobj *obj)kref_put (&obj->refcount, drm_syncobj_free); } -/** -* drm_syncobj_fence_get - get a reference to a fence in a sync object -* @syncobj: sync object. -* -* This acquires additional reference to &drm_syncobj.fence contained in @obj, -* if not NULL. It is illegal to call this without already holding a reference. -* No locks required. -* -* Returns: -* Either the fence of @obj or NULL if there's none. -*/ -static inline struct dma_fence * -drm_syncobj_fence_get (struct drm_syncobj *syncobj) -{ -struct dma_fence *fence; - -rcu_read_lock (); - fence =dma_fence_get_rcu_safe (&syncobj->fence); -rcu_read_unlock (); - -return fence; -} -struct drm_syncobj *drm_syncobj_find (struct drm_file *file_private,u32 handle); void drm_syncobj_replace_fence(struct drm_syncobj *syncobj, u64 point,@@ -142,5 +141,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags,int drm_syncobj_get_handle (struct drm_file *file_private,struct drm_syncobj *syncobj,u32 *handle);int drm_syncobj_get_fd (struct drm_syncobj *syncobj,int *p_fd); +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, +struct dma_fence **fence);#endif include/uapi/drm/drm.h +0
-0
include/uapi/drm/drm.h struct drm_prime_handle { · line 723
Quoted 7 lines
include/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle {struct drm_syncobj_create {__u32 handle;#define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1)__u32 flags; };
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 04e91247-387c-ed5d-0793-9eb1d37d12bd-5C7GfCeVMHo@public.gmane.org
Quoted 1 line · Christian König
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 9 lines
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct · line 180
Quoted 7 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func);drivers/gpu/drm/drm_syncobj.c +0
-0@@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj *syncobj, spin_unlock(&syncobj->lock); } +static void drm_syncobj_timeline_init(struct drm_syncobj *syncobj)We still have _timeline_ in the name here.
the func is relevant to timeline members, or which name is proper?
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +3
-0+{ + spin_lock(&syncobj->lock); + syncobj->timeline_context = dma_fence_context_alloc(1);
[snip]
Quoted 11 lines
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) · line 433
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c +7
-0+} + +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.
previous v5 indeed do this, you let me wrap it, need change back?
Regards,
David Zhou
Quoted 243 lines
Regards,
Christian.Quoted 239 lines
+ fence);
drivers/gpu/drm/drm_syncobj.c +3
-0+} +EXPORT_SYMBOL (drm_syncobj_lookup_fence); +/**
*drm_syncobj_find_fence- lookup and reference the fence in a sync object
* @file_private: drm file private pointerdrivers/gpu/drm/drm_syncobj.c +1
-1@@ -228,7 +443,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) * @fence: out parameter for the fence * * This is just a convenience function that combines drm_syncobj_find() and - * drm_syncobj_fence_get(). + * drm_syncobj_lookup_fence(). * * Returns 0 on success or a negative error value on failure. On success @fence* contains a reference to the fence, which must be released by calling
drivers/gpu/drm/drm_syncobj.c +3
-9@@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) */ int drm_syncobj_find_fence(struct drm_file *file_private, u32 handle, u64 point, - struct dma_fence **fence) -{ + struct dma_fence **fence) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); - int ret = 0; - - if (!syncobj) - return -ENOENT; + int ret; - *fence = drm_syncobj_fence_get(syncobj); - if (!*fence) { - ret = -EINVAL; - } + ret = drm_syncobj_lookup_fence(syncobj, point, fence); drm_syncobj_put(syncobj); return ret;}
drivers/gpu/drm/drm_syncobj.c +8
-2@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); + if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev,void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct
syncobj_wait_entry*wait =
container_of(cb, struct syncobj_wait_entry, syncobj_cb);
- /* This happens inside the syncobj lock */
-wait->fence=
dma_fence_get(rcu_dereference_protected(syncobj->fence,
-lockdep_is_held(&syncobj->lock)));
+drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
+
wake_up_process(wait->task);
}
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(structdrm_syncobj**syncobjs,signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]);
+ ret = drm_syncobj_search_fence(syncobjs[i], 0, 0,
+ &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
continue;drivers/gpu/drm/drm_syncobj.c +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL;diff --git
a/include/drm/drm_syncobj.hb/include/drm/drm_syncobj.hindex425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence. */
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback, additionalinclude/drm/drm_syncobj.h +0
-0@@ -106,29 +128,6 @@ drm_syncobj_put(struct drm_syncobj *obj) kref_put(&obj->refcount, drm_syncobj_free); }-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-12-static inline struct dma_fence * -drm_syncobj_fence_get (struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); - - return fence; -} -struct
drm_syncobj*drm_syncobj_find(structdrm_file*file_private, u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64 point,include/drm/drm_syncobj.h +2
-0@@ -142,5 +141,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, int drm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd); +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence); #endifinclude/uapi/drm/drm.h +0
-1--- a/include/uapi/drm/drm.h
Quoted 9 lines
include/uapi/drm/drm.h struct drm_prime_handle { · line 722
Quoted 8 lines
+++
b/include/uapi/drm/drm.hinclude/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 1 line · Christian König
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 9 lines
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct · line 180
Quoted 7 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func);drivers/gpu/drm/drm_syncobj.c +0
-0@@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj *syncobj, spin_unlock(&syncobj->lock); } +static void drm_syncobj_timeline_init(struct drm_syncobj *syncobj)We still have _timeline_ in the name here.
the func is relevant to timeline members, or which name is proper?
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/drm_syncobj.c +3
-0+{ + spin_lock(&syncobj->lock); + syncobj->timeline_context = dma_fence_context_alloc(1);
[snip]
Quoted 11 lines
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) · line 433
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c +7
-0+} + +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.
previous v5 indeed do this, you let me wrap it, need change back?
Regards,
David Zhou
Quoted 243 lines
Regards,
Christian.Quoted 239 lines
+ fence);
drivers/gpu/drm/drm_syncobj.c +3
-0+} +EXPORT_SYMBOL (drm_syncobj_lookup_fence); +/**
*drm_syncobj_find_fence- lookup and reference the fence in a sync object
* @file_private: drm file private pointerdrivers/gpu/drm/drm_syncobj.c +1
-1@@ -228,7 +443,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) * @fence: out parameter for the fence * * This is just a convenience function that combines drm_syncobj_find() and - * drm_syncobj_fence_get(). + * drm_syncobj_lookup_fence(). * * Returns 0 on success or a negative error value on failure. On success @fence* contains a reference to the fence, which must be released by calling
drivers/gpu/drm/drm_syncobj.c +3
-9@@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) */ int drm_syncobj_find_fence(struct drm_file *file_private, u32 handle, u64 point, - struct dma_fence **fence) -{ + struct dma_fence **fence) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); - int ret = 0; - - if (!syncobj) - return -ENOENT; + int ret; - *fence = drm_syncobj_fence_get(syncobj); - if (!*fence) { - ret = -EINVAL; - } + ret = drm_syncobj_lookup_fence(syncobj, point, fence); drm_syncobj_put(syncobj); return ret;}
drivers/gpu/drm/drm_syncobj.c +8
-2@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); + if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev,void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct
syncobj_wait_entry*wait =
container_of(cb, struct syncobj_wait_entry, syncobj_cb);
- /* This happens inside the syncobj lock */
-wait->fence=
dma_fence_get(rcu_dereference_protected(syncobj->fence,
-lockdep_is_held(&syncobj->lock)));
+drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
+
wake_up_process(wait->task);
}
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(structdrm_syncobj**syncobjs,signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]);
+ ret = drm_syncobj_search_fence(syncobjs[i], 0, 0,
+ &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
continue;drivers/gpu/drm/drm_syncobj.c +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL;diff --git
a/include/drm/drm_syncobj.hb/include/drm/drm_syncobj.hindex425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence. */
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback, additionalinclude/drm/drm_syncobj.h +0
-0@@ -106,29 +128,6 @@ drm_syncobj_put(struct drm_syncobj *obj) kref_put(&obj->refcount, drm_syncobj_free); }-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-12-static inline struct dma_fence * -drm_syncobj_fence_get (struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); - - return fence; -} -struct
drm_syncobj*drm_syncobj_find(structdrm_file*file_private, u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64 point,include/drm/drm_syncobj.h +2
-0@@ -142,5 +141,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, int drm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd); +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence); #endifinclude/uapi/drm/drm.h +0
-1--- a/include/uapi/drm/drm.h
Quoted 9 lines
include/uapi/drm/drm.h struct drm_prime_handle { · line 722
Quoted 8 lines
+++
b/include/uapi/drm/drm.hinclude/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 392512eb-271d-3d16-263b-f2429dedfffc-5C7GfCeVMHo@public.gmane.org
Am 19.09.2018 um 09:32 schrieb zhoucm1:
Quoted 14 lines · Christian König
Quoted 1 line
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 9 lines
drivers/gpu/drm/drm_syncobj.c void drm_syncobj_remove_callback(struct · line 180
Quoted 7 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func);drivers/gpu/drm/drm_syncobj.c +0
-0@@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj *syncobj, spin_unlock(&syncobj->lock); } +static void drm_syncobj_timeline_init(struct drm_syncobj *syncobj)We still have _timeline_ in the name here.
Quoted 1 line
the func is relevant to timeline members, or which name is proper?
Yeah, but we now use the timeline implementation for the individual syncobj as well.
Not a big issue, but I would just name it drm_syncobj_init()/drm_syncobj_fini.
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/drm_syncobj.c +3
-0+{ + spin_lock(&syncobj->lock); + syncobj->timeline_context = dma_fence_context_alloc(1);[snip]
Quoted 10 lines
drivers/gpu/drm/drm_syncobj.c static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) · line 433
Quoted 7 lines
drivers/gpu/drm/drm_syncobj.c +7
-0+} + +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Quoted 2 lines
Quoted 1 line
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.previous v5 indeed do this, you let me wrap it, need change back?
No, the problem is that drm_syncobj_find_fence() is still using drm_syncobj_lookup_fence() which sets the flag instead of drm_syncobj_search_fence() without the flag.
That changes the UAPI behavior because previously we would have returned an error code and now we block for a fence to appear.
So I think the right solution would be to add the flags parameter to drm_syncobj_find_fence() and let the driver decide if we need to block or get -ENOENT.
Regards,
Christian.
Quoted 256 lines
Regards,
David ZhouQuoted 252 lines
Regards,
Christian.Quoted 247 lines
+ fence);
drivers/gpu/drm/drm_syncobj.c +3
-0+} +EXPORT_SYMBOL (drm_syncobj_lookup_fence); +/**
*drm_syncobj_find_fence- lookup and reference the fence in a sync object
* @file_private: drm file private pointerdrivers/gpu/drm/drm_syncobj.c +1
-1@@ -228,7 +443,7 @@ static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) * @fence: out parameter for the fence * * This is just a convenience function that combines drm_syncobj_find() and - * drm_syncobj_fence_get(). + * drm_syncobj_lookup_fence(). * * Returns 0 on success or a negative error value on failure. On success @fence* contains a reference to the fence, which must be released by calling
drivers/gpu/drm/drm_syncobj.c +3
-9@@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj) */ int drm_syncobj_find_fence(struct drm_file *file_private, u32 handle, u64 point, - struct dma_fence **fence) -{ + struct dma_fence **fence) { struct drm_syncobj *syncobj = drm_syncobj_find(file_private, handle); - int ret = 0; - - if (!syncobj) - return -ENOENT; + int ret; - *fence = drm_syncobj_fence_get(syncobj); - if (!*fence) { - ret = -EINVAL; - } + ret = drm_syncobj_lookup_fence(syncobj, point, fence); drm_syncobj_put(syncobj); return ret;}
drivers/gpu/drm/drm_syncobj.c +8
-2@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock); + if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device *dev,void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct
syncobj_wait_entry*wait =
container_of(cb, struct syncobj_wait_entry, syncobj_cb);
- /* This happens inside the syncobj lock */
-wait->fence=
dma_fence_get(rcu_dereference_protected(syncobj->fence,
-lockdep_is_held(&syncobj->lock)));
+drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence);
+
wake_up_process(wait->task);
}
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(structdrm_syncobj**syncobjs,signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]);
+ ret = drm_syncobj_search_fence(syncobjs[i], 0, 0,
+ &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) {
continue;drivers/gpu/drm/drm_syncobj.c +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL;diff --git
a/include/drm/drm_syncobj.hb/include/drm/drm_syncobj.hindex425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence. */
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback, additionalinclude/drm/drm_syncobj.h +0
-0@@ -106,29 +128,6 @@ drm_syncobj_put(struct drm_syncobj *obj) kref_put(&obj->refcount, drm_syncobj_free); }-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-12-static inline struct dma_fence * -drm_syncobj_fence_get (struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); - - return fence; -} -struct
drm_syncobj*drm_syncobj_find(structdrm_file*file_private, u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64 point,include/drm/drm_syncobj.h +2
-0@@ -142,5 +141,7 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, int drm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); int drm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd); +int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 point, + struct dma_fence **fence); #endifinclude/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 9bdce2dd-2129-3ed9-56f0-db4b14005194-5C7GfCeVMHo@public.gmane.org
Quoted 29 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian K?nig
Sent: Wednesday, September 19, 2018 3:45 PM
To: Zhou, David(ChunMing) <[email protected]>; Zhou, David(ChunMing) <[email protected]>; dri- [email protected]
Cc: Dave Airlie <[email protected]>; Rakos, Daniel <[email protected]>; Daniel Vetter <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 1/4] [RFC]drm: add syncobj timeline support v6Am 19.09.2018 um 09:32 schrieb zhoucm1:
Quoted 14 lines · Christian König
Quoted 1 line
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 9 lines
Quoted 8 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func); @@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj*syncobj,
spin_unlock(&syncobj->lock);
}
+static voiddrm_syncobj_timeline_init(struct drm_syncobj *syncobj)
Quoted 8 lines
Quoted 2 lines
Quoted 1 line
We still have _timeline_ in the name here.
the func is relevant to timeline members, or which name is proper?
Yeah, but we now use the timeline implementation for the individual syncobj as well.
Not a big issue, but I would just name it
drm_syncobj_init()/drm_syncobj_fini.
There is already drm_syncobj_init/fini in drm_syncboj.c , any other name can be suggested?
Quoted 27 lines
Quoted 19 lines
Quoted 6 lines
Quoted 6 lines
+{
+spin_lock(&syncobj->lock);
+syncobj->timeline_context=dma_fence_context_alloc(1);[snip]
Quoted 12 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+} + +int drm_syncobj_lookup_fence(struct drm_syncobj *syncobj, u64 +point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Quoted 3 lines
Quoted 2 lines
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.previous v5 indeed do this, you let me wrap it, need change back?
No, the problem is that
drm_syncobj_find_fence()is still usingdrm_syncobj_lookup_fence()which sets the flag instead ofdrm_syncobj_search_fence()without the flag.
Quoted 6 lines
That changes the UAPI behavior because previously we would have returned an error code and now we block for a fence to appear.
So I think the right solution would be to add the flags parameter to
drm_syncobj_find_fence()and let the driver decide if we need to block or get-ENOENT.
Got your means,
Exporting flag in func is easy,
but driver doesn't pass flag, which flag is proper by default? We still need to give a default flag in patch, don't we?
Thanks,
David Zhou
Quoted 271 lines
Regards,
Christian.Quoted 63 lines
Regards,
David ZhouQuoted 60 lines
Regards,
Christian.Quoted 56 lines
+ fence);
(quoted diff) +3
-0+} +EXPORT_SYMBOL(drm_syncobj_lookup_fence); +/**
*drm_syncobj_find_fence- lookup and reference the fence in a sync object
* @file_private: drm file private pointer @@ -228,7 +443,7 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
* @fence: out parameter for the fence
*
* This is just a convenience function that combinesdrm_syncobj_find()and
- *drm_syncobj_fence_get().
+ *drm_syncobj_lookup_fence().
*
* Returns 0 on success or a negative error value on failure. On success @fence
* contains a reference to the fence, which must be released by calling @@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)*/
int drm_syncobj_find_fence(structdrm_file*file_private, u32 handle, u64 point,
- structdma_fence**fence) -{
+ structdma_fence**fence) {
structdrm_syncobj*syncobj =drm_syncobj_find(file_private, handle);
- int ret = 0;
-
- if (!syncobj)
- return-ENOENT;
+ int ret;
- *fence =drm_syncobj_fence_get(syncobj);
- if (!*fence) {
- ret =-EINVAL;
- }
+ ret =drm_syncobj_lookup_fence(syncobj, point, fence);drm_syncobj_put(syncobj);
return ret;
}(quoted diff) +1
-1@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock);Quoted 8 lines
Quoted 8 lines
Review drm_syncobj_create_ioctl(struct drm_device
Quoted 8 lines
(quoted diff) +5
-0+ if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device*dev,
Quoted 164 lines
Quoted 164 lines
Quoted 164 lines
(quoted diff) +2
-1void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct
syncobj_wait_entry*wait =
container_of(cb, struct syncobj_wait_entry, syncobj_cb); - /* This happens inside the syncobj lock */
-wait->fence= dma_fence_get(rcu_dereference_protected(syncobj->fence,
-lockdep_is_held(&syncobj->lock)));
+drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence); +
wake_up_process(wait->task);
}
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(structdrm_syncobj**syncobjs,signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]); + ret =drm_syncobj_search_fence(syncobjs[i], 0, 0, + &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) { continue;(quoted diff) +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL;diff --git
a/include/drm/drm_syncobj.hb/include/drm/drm_syncobj.hindex425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence. */
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback, additional @@ -106,29 +128,6 @@drm_syncobj_put(struct drm_syncobj *obj)
kref_put(&obj->refcount, drm_syncobj_free);
}
-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-8-static inline struct dma_fence * -drm_syncobj_fence_get(struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); -Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- return fence;
include/drm/drm_syncobj.h +0
-2-} -struct
drm_syncobj*drm_syncobj_find(structdrm_file*file_private,
u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64 point, @@ -142,5 +141,7 @@ int drm_syncobj_create(struct
drm_syncobjQuoted 12 lines
Quoted 12 lines
Quoted 12 lines
**out_syncobj,
uint32_tflags,
intdrm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); intdrm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);include/drm/drm_syncobj.h +3
-0+int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 +point, + struct dma_fence **fence);#endif
include/uapi/drm/drm.h index renamed from include/uapi/drm/drm.h +0
-0
300f336633f2..cebdb2541eb7100644include/uapi/drm/drm.h +0
-0Quoted 9 lines
Quoted 8 lines
include/uapi/drm/drm.h struct drm_prime_handle { · line 722
Quoted 7 lines
include/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): BY1PR12MB05021AF8F3FD552CC133BCC6B41C0-PicGAnIBOobrCwm+z9iKNgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Am 19.09.2018 um 10:03 schrieb Zhou, David(ChunMing):
Quoted 26 lines
Quoted 26 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian K?nig
Sent: Wednesday, September 19, 2018 3:45 PM
To: Zhou, David(ChunMing) <[email protected]>; Zhou, David(ChunMing) <[email protected]>; dri- [email protected]
Cc: Dave Airlie <[email protected]>; Rakos, Daniel <[email protected]>; Daniel Vetter <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 1/4] [RFC]drm: add syncobj timeline support v6Am 19.09.2018 um 09:32 schrieb zhoucm1:
Quoted 12 lines · Christian König
Quoted 1 line
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 8 lines
Quoted 8 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func); @@
-164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj*syncobj,
spin_unlock(&syncobj->lock);
}
+static void drm_syncobj_timeline_init(structdrm_syncobj
*syncobj)
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
We still have _timeline_ in the name here.
the func is relevant to timeline members, or which name is proper?
Yeah, but we now use the timeline implementation for the individual syncobj as well.
Not a big issue, but I would just name it
drm_syncobj_init()/drm_syncobj_fini.There is already drm_syncobj_init/fini in
drm_syncboj.c, any other name can be suggested?
Hui what? I actually checked that there is no drm_syncobj_init()/drm_syncobj_fini() in drm_syncobj.c before suggesting it. Am I missing something?
Quoted 25 lines
Quoted 25 lines
Quoted 15 lines
Quoted 3 lines
Quoted 3 lines
+{
+spin_lock(&syncobj->lock);
+syncobj->timeline_context=dma_fence_context_alloc(1);[snip]
Quoted 11 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+} + +int drm_syncobj_lookup_fence(struct drm_syncobj *syncobj, u64 +point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Quoted 3 lines
Quoted 2 lines
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.previous v5 indeed do this, you let me wrap it, need change back?
No, the problem is that
drm_syncobj_find_fence()is still usingdrm_syncobj_lookup_fence()which sets the flag instead ofdrm_syncobj_search_fence()without the flag.That changes the UAPI behavior because previously we would have returned an error code and now we block for a fence to appear.
Quoted 6 lines
Quoted 3 lines
So I think the right solution would be to add the flags parameter to
drm_syncobj_find_fence()and let the driver decide if we need to block or get-ENOENT.Got your means,
Exporting flag in func is easy,
but driver doesn't pass flag, which flag is proper by default? We still need to give a default flag in patch, don't we?
Well proper solution is to keep the old behavior as it is for now.
So passing 0 as flag by default and making sure we get a -ENOENT in that case sounds like the right approach to me.
Adding the DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT flag can happen when the driver starts to provide a proper point as well.
Christian.
Quoted 273 lines
Thanks,
David ZhouQuoted 269 lines
Regards,
Christian.Quoted 61 lines
Regards,
David ZhouQuoted 59 lines
Regards,
Christian.Quoted 56 lines
+ fence);
(quoted diff) +3
-0+} +EXPORT_SYMBOL(drm_syncobj_lookup_fence); + /** * drm_syncobj_find_fence - lookup and reference the fence in async object
* @file_private: drm file private pointer @@ -228,7 +443,7 @@
static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
* @fence: out parameter for the fence
*
* This is just a convenience function that combinesdrm_syncobj_find()and
- *drm_syncobj_fence_get().
+ *drm_syncobj_lookup_fence().
*
* Returns 0 on success or a negative error value on failure. On
success @fence
* contains a reference to the fence, which must be released by
calling @@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
*/
int drm_syncobj_find_fence(structdrm_file*file_private, u32 handle, u64 point,
- structdma_fence**fence) -{
+ structdma_fence**fence) {
structdrm_syncobj*syncobj = drm_syncobj_find(file_private,
handle);
- int ret = 0;(quoted diff) +3
-7- - if (!syncobj) - return -ENOENT; + int ret; - *fence = drm_syncobj_fence_get(syncobj); - if (!*fence) { - ret = -EINVAL; - } + ret = drm_syncobj_lookup_fence(syncobj, point, fence); drm_syncobj_put(syncobj); return ret; }@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock);Quoted 8 lines
Quoted 8 lines
Review drm_syncobj_create_ioctl(struct drm_device
Quoted 8 lines
(quoted diff) +5
-0+ if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device*dev,
Quoted 164 lines
Quoted 164 lines
Quoted 164 lines
(quoted diff) +4
-3void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj, struct syncobj_wait_entry *wait = container_of(cb, struct syncobj_wait_entry, syncobj_cb); - /* This happens inside the syncobj lock */ - wait->fence = dma_fence_get(rcu_dereference_protected(syncobj->fence, - lockdep_is_held(&syncobj->lock))); + drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence); + wake_up_process(wait->task); } @@ -698,7 +911,8 @@ static signed longdrm_syncobj_array_wait_timeout(struct
drm_syncobj**syncobjs,
signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]); + ret =drm_syncobj_search_fence(syncobjs[i], 0, 0, + &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) { continue;(quoted diff) +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; } intdrivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL; diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.hindex
425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence.
*/
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback,
additional @@ -106,29 +128,6 @@drm_syncobj_put(struct drm_syncobj *obj)
kref_put(&obj->refcount, drm_syncobj_free);
}
-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-8-static inline struct dma_fence * -drm_syncobj_fence_get(struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); -Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- return fence;
include/drm/drm_syncobj.h +0
-2-} - struct drm_syncobj *drm_syncobj_find(struct drm_file
*file_private,
u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64
point, @@ -142,5 +141,7 @@ int drm_syncobj_create(struct
drm_syncobjQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
**out_syncobj,
uint32_tflags,
intdrm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); intdrm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);include/drm/drm_syncobj.h +3
-0+int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 +point, + struct dma_fence **fence); #endifinclude/uapi/drm/drm.h index renamed from include/uapi/drm/drm.h +0
-0
300f336633f2..cebdb2541eb7100644
---a/include/uapi/drm/drm.hQuoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h index struct drm_prime_handle { · line 722
Quoted 8 lines
+++
b/include/uapi/drm/drm.hinclude/uapi/drm/drm.h index renamed from include/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 3ed55b7b-5a61-5001-e767-96039dc07bbe-5C7GfCeVMHo@public.gmane.org
Quoted 29 lines · Christian König
Am 19.09.2018 um 10:03 schrieb Zhou, David(ChunMing):
Quoted 28 lines
Quoted 28 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian K?nig
Sent: Wednesday, September 19, 2018 3:45 PM
To: Zhou, David(ChunMing) <[email protected]>; Zhou, David(ChunMing) <[email protected]>; dri- [email protected]
Cc: Dave Airlie <[email protected]>; Rakos, Daniel <[email protected]>; Daniel Vetter <[email protected]>; amd- [email protected]
Subject: Re: [PATCH 1/4] [RFC]drm: add syncobj timeline support v6Am 19.09.2018 um 09:32 schrieb zhoucm1:
Quoted 14 lines · Christian König
Quoted 1 line
Am 19.09.2018 um 06:26 schrieb Chunming Zhou:
[snip]
Quoted 9 lines
Quoted 8 lines
*fence = NULL;
drm_syncobj_add_callback_locked(syncobj, cb, func); @@ -164,6 +177,153 @@ void drm_syncobj_remove_callback(structdrm_syncobj*syncobj,
spin_unlock(&syncobj->lock);
}
+static voiddrm_syncobj_timeline_init(struct drm_syncobj *syncobj)We still have _timeline_ in the name here.
the func is relevant to timeline members, or which name is proper?
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
Yeah, but we now use the timeline implementation for the individual syncobj as well.
Not a big issue, but I would just name it
drm_syncobj_init()/drm_syncobj_fini.There is already drm_syncobj_init/fini in
drm_syncboj.c, any other name can be suggested?Hui what? I actually checked that there is no drm_syncobj_init()/drm_syncobj_fini() in
drm_syncobj.cbefore suggesting it. Am I missing something?
messed syncobj_create/destroy in brain :(
Quoted 33 lines
Quoted 26 lines
Quoted 26 lines
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
+{
+spin_lock(&syncobj->lock);
+syncobj->timeline_context=dma_fence_context_alloc(1);[snip]
Quoted 11 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+} + +int drm_syncobj_lookup_fence(struct drm_syncobj *syncobj, u64 +point, + struct dma_fence **fence) { + + return drm_syncobj_search_fence(syncobj, point, + DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT,I still have a bad feeling setting that flag as default cause it might change the behavior for the UAPI.
Quoted 3 lines
Quoted 2 lines
Maybe export
drm_syncobj_search_fencedirectly? E.g. with the flags parameter.previous v5 indeed do this, you let me wrap it, need change back?
No, the problem is that
drm_syncobj_find_fence()is still usingdrm_syncobj_lookup_fence()which sets the flag instead ofdrm_syncobj_search_fence()without the flag.That changes the UAPI behavior because previously we would have returned an error code and now we block for a fence to appear.
Quoted 6 lines
Quoted 3 lines
So I think the right solution would be to add the flags parameter to
drm_syncobj_find_fence()and let the driver decide if we need to block or get-ENOENT.Got your means,
Exporting flag in func is easy,
but driver doesn't pass flag, which flag is proper by default? We still need to give a default flag in patch, don't we?
Quoted 5 lines
Well proper solution is to keep the old behavior as it is for now.
So passing 0 as flag by default and making sure we get a
-ENOENTin that case sounds like the right approach to me.Adding the
DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMITflag can happen when the driver starts to provide a proper point as well.
Sounds more flexible.
v7 will come soon.
thanks,
David Zhou
Quoted 277 lines
Christian.
Quoted 273 lines
Thanks,
David ZhouQuoted 269 lines
Regards,
Christian.Quoted 61 lines
Regards,
David ZhouQuoted 59 lines
Regards,
Christian.Quoted 56 lines
+ fence);
(quoted diff) +3
-0+} +EXPORT_SYMBOL(drm_syncobj_lookup_fence); +/**
*drm_syncobj_find_fence- lookup and reference the fence in a sync object
* @file_private: drm file private pointer @@ -228,7 +443,7 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
* @fence: out parameter for the fence
*
* This is just a convenience function that combinesdrm_syncobj_find()and
- *drm_syncobj_fence_get().
+ *drm_syncobj_lookup_fence().
*
* Returns 0 on success or a negative error value on failure. On success @fence
* contains a reference to the fence, which must be released by calling @@ -236,18 +451,11 @@ static intdrm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)*/
int drm_syncobj_find_fence(structdrm_file*file_private, u32 handle, u64 point,
- structdma_fence**fence) -{
+ structdma_fence**fence) {
structdrm_syncobj*syncobj =drm_syncobj_find(file_private, handle);
- int ret = 0;
-
- if (!syncobj)
- return-ENOENT;
+ int ret;
- *fence =drm_syncobj_fence_get(syncobj);
- if (!*fence) {
- ret =-EINVAL;
- }
+ ret =drm_syncobj_lookup_fence(syncobj, point, fence);drm_syncobj_put(syncobj);
return ret;
}(quoted diff) +1
-1@@ -264,7 +472,7 @@ void drm_syncobj_free(struct kref *kref) struct drm_syncobj *syncobj = container_of(kref, struct drm_syncobj, refcount); - drm_syncobj_replace_fence(syncobj, 0, NULL); + drm_syncobj_timeline_fini(syncobj); kfree(syncobj); } EXPORT_SYMBOL(drm_syncobj_free);@@ -294,6 +502,11 @@ int drm_syncobj_create(struct drm_syncobj **out_syncobj, uint32_t flags, kref_init(&syncobj->refcount); INIT_LIST_HEAD(&syncobj->cb_list); spin_lock_init(&syncobj->lock);Quoted 8 lines
Quoted 8 lines
Review drm_syncobj_create_ioctl(struct drm_device
Quoted 8 lines
(quoted diff) +5
-0+ if (flags & DRM_SYNCOBJ_CREATE_TYPE_TIMELINE) + syncobj->type = DRM_SYNCOBJ_TYPE_TIMELINE; + else + syncobj->type = DRM_SYNCOBJ_TYPE_INDIVIDUAL; + drm_syncobj_timeline_init(syncobj); if (flags & DRM_SYNCOBJ_CREATE_SIGNALED) { ret = drm_syncobj_assign_null_handle(syncobj);@@ -576,7 +789,8 @@ drm_syncobj_create_ioctl(struct drm_device*dev,
Quoted 164 lines
Quoted 164 lines
Quoted 164 lines
(quoted diff) +2
-1void *data, return -ENODEV; /* no valid flags yet */ - if (args->flags & ~DRM_SYNCOBJ_CREATE_SIGNALED) + if (args->flags & ~(DRM_SYNCOBJ_CREATE_SIGNALED | + DRM_SYNCOBJ_CREATE_TYPE_TIMELINE)) return -EINVAL; return drm_syncobj_create_as_handle(file_private,@@ -669,9 +883,8 @@ static void syncobj_wait_syncobj_func(struct drm_syncobj *syncobj,struct
syncobj_wait_entry*wait =
container_of(cb, struct syncobj_wait_entry, syncobj_cb); - /* This happens inside the syncobj lock */
-wait->fence= dma_fence_get(rcu_dereference_protected(syncobj->fence,
-lockdep_is_held(&syncobj->lock)));
+drm_syncobj_search_fence(syncobj, 0, 0, &wait->fence); +
wake_up_process(wait->task);
}
@@ -698,7 +911,8 @@ static signed long drm_syncobj_array_wait_timeout(structdrm_syncobj**syncobjs,signaled_count= 0;
for (i = 0; i < count; ++i) {
entries[i].task = current;
- entries[i].fence =drm_syncobj_fence_get(syncobjs[i]); + ret =drm_syncobj_search_fence(syncobjs[i], 0, 0, + &entries[i].fence);
if (!entries[i].fence) {
if (flags &DRM_SYNCOBJ_WAIT_FLAGS_WAIT_FOR_SUBMIT) { continue;(quoted diff) +11
-2@@ -970,12 +1184,19 @@ drm_syncobj_reset_ioctl(struct drm_device *dev, void *data, if (ret < 0) return ret; - for (i = 0; i < args->count_handles; i++) - drm_syncobj_replace_fence(syncobjs[i], 0, NULL); - + for (i = 0; i < args->count_handles; i++) { + if (syncobjs[i]->type == DRM_SYNCOBJ_TYPE_TIMELINE) { + DRM_ERROR("timeline syncobj cannot reset!\n"); + ret = -EINVAL; + goto out; + } + drm_syncobj_timeline_fini(syncobjs[i]); + drm_syncobj_timeline_init(syncobjs[i]); + } +out: drm_syncobj_array_free(syncobjs, args->count_handles); - return 0; + return ret; }int
drivers/gpu/drm/i915/i915_gem_execbuffer.c +1
-0@@ -2137,7 +2137,7 @@ await_fence_array(struct i915_execbuffer *eb, if (!(flags & I915_EXEC_FENCE_WAIT)) continue; - fence = drm_syncobj_fence_get(syncobj); + drm_syncobj_lookup_fence(syncobj, 0, &fence); if (!fence) return -EINVAL;diff --git
a/include/drm/drm_syncobj.hb/include/drm/drm_syncobj.hindex425432b85a87..6dac479fedfe100644include/drm/drm_syncobj.h +14
-7@@ -30,6 +30,11 @@ struct drm_syncobj_cb; +enum drm_syncobj_type { + DRM_SYNCOBJ_TYPE_INDIVIDUAL, + DRM_SYNCOBJ_TYPE_TIMELINE +}; + /*** struct drm_syncobj - sync object. * @@ -41,19 +46,36 @@ struct drm_syncobj {*/ struct kref refcount; /** - * @fence: - * NULL or a pointer to the fence bound to this object. - * - * This field should not be used directly. Use drm_syncobj_fence_get() - * and drm_syncobj_replace_fence() instead. + * @type: indicate syncobj type + */ + enum drm_syncobj_type type; + /** + * @wq: wait signal operation work queue + */ + wait_queue_head_t wq; + /** + * @timeline_context: fence context used by timeline */ - struct dma_fence __rcu *fence; + u64 timeline_context; /** -* @cb_list: List of callbacks to call when the &fence gets replaced.
+ * @timeline: syncobj timeline value, which indicates point is signaled.
*/
+ u64 timeline;
+ /**
+ * @signal_point: which indicates the latest signaler point. + */
+ u64signal_point;
+ /**
+ * @signal_pt_list: signaler point list.
+ */
+ structlist_headsignal_pt_list;
+
+ /**
+ * @cb_list: List of callbacks to call when the &fence gets replaced.
+ */
structlist_headcb_list;
/**
- * @lock: Protects&cb_listand write-locks &fence. + * @lock: Protects syncobj list and write-locks &fence. */
spinlock_tlock;
/**include/drm/drm_syncobj.h +1
-1@@ -68,7 +90,7 @@ typedef void (*drm_syncobj_func_t)(struct drm_syncobj *syncobj, /*** struct drm_syncobj_cb - callback for drm_syncobj_add_callback * @node: used by drm_syncob_add_callback to append this struct to -* &drm_syncobj.cb_list +* &drm_syncobj.cb_list * @func: drm_syncobj_func_t to call * * This struct will be initialized by
drm_syncobj_add_callback, additional @@ -106,29 +128,6 @@drm_syncobj_put(struct drm_syncobj *obj)
kref_put(&obj->refcount, drm_syncobj_free);
}
-/**
- *drm_syncobj_fence_get- get a reference to a fence in a sync object
- * @syncobj: sync object.
- *
- * This acquires additional reference to &drm_syncobj.fence contained in @obj,
- * if not NULL. It is illegal to call this without already holding a reference.
- * No locks required.
- *
- * Returns:
- * Either the fence of @obj or NULL if there's none.
- */include/drm/drm_syncobj.h +0
-8-static inline struct dma_fence * -drm_syncobj_fence_get(struct drm_syncobj *syncobj) -{ - struct dma_fence *fence; - - rcu_read_lock(); - fence = dma_fence_get_rcu_safe(&syncobj->fence); - rcu_read_unlock(); -Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
- return fence;
include/drm/drm_syncobj.h +0
-2-} -struct
drm_syncobj*drm_syncobj_find(structdrm_file*file_private,
u32 handle);
void drm_syncobj_replace_fence(structdrm_syncobj*syncobj, u64 point, @@ -142,5 +141,7 @@ int drm_syncobj_create(struct
drm_syncobjQuoted 11 lines
Quoted 11 lines
Quoted 11 lines
**out_syncobj,
uint32_tflags,
intdrm_syncobj_get_handle(struct drm_file *file_private, struct drm_syncobj *syncobj, u32 *handle); intdrm_syncobj_get_fd(struct drm_syncobj *syncobj, int *p_fd);include/drm/drm_syncobj.h +3
-0+int drm_syncobj_lookup_fence (struct drm_syncobj *syncobj,u64 +point, + struct dma_fence **fence);#endif
include/uapi/drm/drm.h index renamed from include/uapi/drm/drm.h +0
-0
300f336633f2..cebdb2541eb7100644
---a/include/uapi/drm/drm.hQuoted 8 lines
Quoted 8 lines
include/uapi/drm/drm.h index struct drm_prime_handle { · line 722
Quoted 8 lines
+++
b/include/uapi/drm/drm.hinclude/uapi/drm/drm.h index renamed from include/uapi/drm/drm.h +1
-0@@ -717,6 +717,7 @@ struct drm_prime_handle { struct drm_syncobj_create { __u32 handle; #define DRM_SYNCOBJ_CREATE_SIGNALED (1 << 0) +#define DRM_SYNCOBJ_CREATE_TYPE_TIMELINE (1 << 1) __u32 flags; };_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx