From: Gustavo Padovan <gustavo.padovan@xxxxxxxxxxxxxxx> Now fence timeline is aware of the last signaled fence, as it receives the increment to the current value in fence_timeline_signal(). That allow us to create a fence_default_signaled() using timeline->value and fence->seqno in the comparison. Signed-off-by: Gustavo Padovan <gustavo.padovan@xxxxxxxxxxxxxxx> --- drivers/dma-buf/fence.c | 21 +++++++++++++++++++-- drivers/staging/android/sw_sync.c | 16 ++-------------- drivers/staging/android/sync.c | 17 +++-------------- drivers/staging/android/sync.h | 3 ++- include/linux/fence.h | 12 +++--------- 5 files changed, 29 insertions(+), 40 deletions(-) diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c index f77d6a9..786c987 100644 --- a/drivers/dma-buf/fence.c +++ b/drivers/dma-buf/fence.c @@ -149,7 +149,7 @@ void fence_timeline_destroy(struct fence_timeline *timeline) /* * signal any children that their parent is going away. */ - fence_timeline_signal(timeline); + fence_timeline_signal(timeline, 0); fence_timeline_put(timeline); } EXPORT_SYMBOL(fence_timeline_destroy); @@ -157,11 +157,12 @@ EXPORT_SYMBOL(fence_timeline_destroy); /** * fence_timeline_signal - signal fences on a fence_timeline * @timeline [in] the fence_timeline to signal fences + * @inc [in[ num to increment on timeline->value * * This function signal fences on a given timeline and remove * those from the active_list. */ -void fence_timeline_signal(struct fence_timeline *timeline) +void fence_timeline_signal(struct fence_timeline *timeline, unsigned int inc) { unsigned long flags; LIST_HEAD(signaled_pts); @@ -169,6 +170,8 @@ void fence_timeline_signal(struct fence_timeline *timeline) spin_lock_irqsave(&timeline->lock, flags); + timeline->value += inc; + list_for_each_entry_safe(fence, next, &timeline->active_list_head, active_list) { if (fence_is_signaled_locked(fence)) @@ -470,6 +473,20 @@ const char *fence_default_get_timeline_name(struct fence *fence) EXPORT_SYMBOL(fence_default_get_timeline_name); /** + * fence_default_signaled - default .signaled fence ops + * @fence: [in] the fence to check if signaled or not + * + * This functions checks if a fence was signaled or not. + */ +bool fence_default_signaled(struct fence *fence) +{ + struct fence_timeline *timeline = fence_parent(fence); + + return (fence->seqno > timeline->value) ? false : true; +} +EXPORT_SYMBOL(fence_default_signaled); + +/** * fence_default_enable_signaling - default op for .enable_signaling * @fence: [in] the fence to enable signaling * diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 9720267..bed6801 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -30,7 +30,7 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) struct sw_sync_pt *pt; pt = (struct sw_sync_pt *) - sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt)); + sync_pt_create(&obj->obj, sizeof(struct sw_sync_pt), value); pt->value = value; @@ -38,15 +38,6 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) } EXPORT_SYMBOL(sw_sync_pt_create); -static int sw_sync_fence_has_signaled(struct fence *fence) -{ - struct sw_sync_pt *pt = (struct sw_sync_pt *)fence; - struct sw_sync_timeline *obj = - (struct sw_sync_timeline *)fence_parent(fence); - - return (pt->value > obj->value) ? 0 : 1; -} - static int sw_sync_fill_driver_data(struct fence *fence, void *data, int size) { @@ -77,7 +68,6 @@ static void sw_sync_fence_value_str(struct fence *fence, } static struct fence_timeline_ops sw_sync_timeline_ops = { - .has_signaled = sw_sync_fence_has_signaled, .fill_driver_data = sw_sync_fill_driver_data, .timeline_value_str = sw_sync_timeline_value_str, .fence_value_str = sw_sync_fence_value_str, @@ -96,8 +86,6 @@ EXPORT_SYMBOL(sw_sync_timeline_create); void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc) { - obj->value += inc; - - fence_timeline_signal(&obj->obj); + fence_timeline_signal(&obj->obj, inc); } EXPORT_SYMBOL(sw_sync_timeline_inc); diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index f8b3c6b..8216635 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -34,7 +34,7 @@ static const struct fence_ops sync_fence_ops; static const struct file_operations sync_fence_fops; -struct fence *sync_pt_create(struct fence_timeline *obj, int size) +struct fence *sync_pt_create(struct fence_timeline *obj, int size, u32 value) { unsigned long flags; struct fence *fence; @@ -49,7 +49,7 @@ struct fence *sync_pt_create(struct fence_timeline *obj, int size) spin_lock_irqsave(&obj->lock, flags); fence_timeline_get(obj); fence_init(fence, &sync_fence_ops, &obj->lock, - obj->context, ++obj->value); + obj->context, value); list_add_tail(&fence->child_list, &obj->child_list_head); INIT_LIST_HEAD(&fence->active_list); spin_unlock_irqrestore(&obj->lock, flags); @@ -321,17 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout) } EXPORT_SYMBOL(sync_fence_wait); -static bool sync_fence_signaled(struct fence *fence) -{ - struct fence_timeline *parent = fence_parent(fence); - int ret; - - ret = parent->ops->has_signaled(fence); - if (ret < 0) - fence->status = ret; - return ret; -} - static int sync_fence_fill_driver_data(struct fence *fence, void *data, int size) { @@ -372,7 +361,7 @@ static const struct fence_ops sync_fence_ops = { .get_driver_name = fence_default_get_driver_name, .get_timeline_name = fence_default_get_timeline_name, .enable_signaling = fence_default_enable_signaling, - .signaled = sync_fence_signaled, + .signaled = fence_default_signaled, .wait = fence_default_wait, .release = fence_default_release, .fill_driver_data = sync_fence_fill_driver_data, diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index e011111..569873f 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -82,7 +82,8 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter, * API for fence_timeline implementers */ -struct fence *sync_pt_create(struct fence_timeline *parent, int size); +struct fence *sync_pt_create(struct fence_timeline *parent, int size, + u32 value); /** * sync_fence_create() - creates a sync fence diff --git a/include/linux/fence.h b/include/linux/fence.h index e8f9f12..e71545e 100644 --- a/include/linux/fence.h +++ b/include/linux/fence.h @@ -36,10 +36,6 @@ struct fence_ops; struct fence_cb; /** * struct fence_timeline_ops - fence context implementation ops - * @has_signaled: returns: - * 1 if pt has signaled - * 0 if pt has not signaled - * <0 on error * @fill_driver_data: write implementation specific driver data to data. * should return an error if there is not enough room * as specified by size. This information is returned @@ -48,9 +44,6 @@ struct fence_cb; * @pt_value_str: fill str with the value of the sync_pt */ struct fence_timeline_ops { - /* required */ - int (*has_signaled)(struct fence *fence); - /* optional */ int (*fill_driver_data)(struct fence *fence, void *data, int size); @@ -80,7 +73,7 @@ struct fence_timeline { char drv_name[32]; const struct fence_timeline_ops *ops; bool destroyed; - int value; + unsigned int value; int context; struct list_head child_list_head; struct list_head active_list_head; @@ -97,7 +90,7 @@ struct fence_timeline *fence_timeline_create(unsigned num, void fence_timeline_get(struct fence_timeline *timeline); void fence_timeline_put(struct fence_timeline *timeline); void fence_timeline_destroy(struct fence_timeline *timeline); -void fence_timeline_signal(struct fence_timeline *timeline); +void fence_timeline_signal(struct fence_timeline *timeline, unsigned int inc); /** * struct fence - software synchronization primitive @@ -296,6 +289,7 @@ int fence_signal(struct fence *fence); int fence_signal_locked(struct fence *fence); const char *fence_default_get_driver_name(struct fence *fence); const char *fence_default_get_timeline_name(struct fence *fence); +bool fence_default_signaled(struct fence *fence); bool fence_default_enable_signaling(struct fence *fence); signed long fence_default_wait(struct fence *fence, bool intr, signed long timeout); void fence_default_release(struct fence *fence); -- 2.5.0 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel