From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Hi,
The following patches are some clean ups on the sync framework before we start the actual de-staging. The main changes here are the move of SW_SYNC_USER to debugfs. Removal of struct sync_pt in favor of direct use of struct fence. And the rename of sync_fence to sync_file, a name to better reflect what it is for, a struct that connects struct fence(s) to a file.
Please review. Thanks.
Gustavo Padovan (11): staging/android: fix sync framework documentation staging/android: sync: remove interfaces that are not used staging/android: remove not used sync_timeline ops staging/android: create a 'sync' dir for debugfs information staging/android: move SW_SYNC_USER to a debugfs file staging/android: rename sync_fence to sync_file staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb staging/android: remove struct sync_pt staging/android: remove unused var from sync_timeline_signal() staging/android: remove pointless sync_timeline_signal at destroy phase staging/android: remove sync_fence_create_dma()
drivers/staging/android/Kconfig | 9 - drivers/staging/android/sw_sync.c | 181 ++-------------- drivers/staging/android/sw_sync.h | 8 +- drivers/staging/android/sync.c | 406 ++++++++++++++--------------------- drivers/staging/android/sync.h | 237 ++++++-------------- drivers/staging/android/sync_debug.c | 228 +++++++++++++++----- drivers/staging/android/trace/sync.h | 24 +-- drivers/staging/android/uapi/sync.h | 14 +- include/linux/fence.h | 2 + 9 files changed, 438 insertions(+), 671 deletions(-)
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Updates comments about functions and structures.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.h | 45 ++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index afa0752..7a4d820 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -110,15 +110,9 @@ struct sync_timeline {
/** * struct sync_pt - sync point - * @fence: base fence class + * @base: base fence class * @child_list: membership in sync_timeline.child_list_head * @active_list: membership in sync_timeline.active_list_head - * @signaled_list: membership in temporary signaled_list on stack - * @fence: sync_fence to which the sync_pt belongs - * @pt_list: membership in sync_fence.pt_list_head - * @status: 1: signaled, 0:active, <0: error - * @timestamp: time which sync_pt status transitioned from active to - * signaled or error. */ struct sync_pt { struct fence base; @@ -144,12 +138,11 @@ struct sync_fence_cb { * @file: file representing this fence * @kref: reference count on fence. * @name: name of sync_fence. Useful for debugging - * @pt_list_head: list of sync_pts in the fence. immutable once fence - * is created - * @status: 0: signaled, >0:active, <0: error - * - * @wq: wait queue for fence signaling * @sync_fence_list: membership in global fence list + * @num_fences number of sync_pts in the fence + * @wq: wait queue for fence signaling + * @status: 0: signaled, >0:active, <0: error + * @cbs: sync_pts callback information */ struct sync_fence { struct file *file; @@ -172,9 +165,8 @@ typedef void (*sync_callback_t)(struct sync_fence *fence,
/** * struct sync_fence_waiter - metadata for asynchronous waiter on a fence - * @waiter_list: membership in sync_fence.waiter_list_head + * @work: wait_queue for the fence waiter * @callback: function pointer to call when fence signals - * @callback_data: pointer to pass to @callback */ struct sync_fence_waiter { wait_queue_t work; @@ -200,7 +192,8 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter, * * Creates a new sync_timeline which will use the implementation specified by * @ops. @size bytes will be allocated allowing for implementation specific - * data to be kept after the generic sync_timeline struct. + * data to be kept after the generic sync_timeline struct. Returns the + * sync_timeline object or NULL in case of error. */ struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, int size, const char *name); @@ -231,7 +224,8 @@ void sync_timeline_signal(struct sync_timeline *obj); * * Creates a new sync_pt as a child of @parent. @size bytes will be * allocated allowing for implementation specific data to be kept after - * the generic sync_timeline struct. + * the generic sync_timeline struct. Returns the sync_pt object or + * NULL in case of error. */ struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size);
@@ -275,7 +269,8 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt); * @b: fence b * * Creates a new fence which contains copies of all the sync_pts in both - * @a and @b. @a and @b remain valid, independent fences. + * @a and @b. @a and @b remain valid, independent fences. Returns the + * new merged fence or NULL in case of error. */ struct sync_fence *sync_fence_merge(const char *name, struct sync_fence *a, struct sync_fence *b); @@ -285,7 +280,7 @@ struct sync_fence *sync_fence_merge(const char *name, * @fd: fd referencing a fence * * Ensures @fd references a valid fence, increments the refcount of the backing - * file, and returns the fence. + * file, and returns the fence. Returns the fence or NULL in case of error. */ struct sync_fence *sync_fence_fdget(int fd);
@@ -313,10 +308,10 @@ void sync_fence_install(struct sync_fence *fence, int fd); * @fence: fence to wait on * @waiter: waiter callback struck * - * Returns 1 if @fence has already signaled. - * * Registers a callback to be called when @fence signals or has an error. * @waiter should be initialized with sync_fence_waiter_init(). + * + * Returns 1 if @fence has already signaled, 0 if not or <0 if error. */ int sync_fence_wait_async(struct sync_fence *fence, struct sync_fence_waiter *waiter); @@ -326,11 +321,11 @@ int sync_fence_wait_async(struct sync_fence *fence, * @fence: fence to wait on * @waiter: waiter callback struck * - * returns 0 if waiter was removed from fence's async waiter list. - * returns -ENOENT if waiter was not found on fence's async waiter list. - * * Cancels a previously registered async wait. Will fail gracefully if * @waiter was never registered or if @fence has already signaled @waiter. + * + * Returns 0 if waiter was removed from fence's async waiter list. + * Returns -ENOENT if waiter was not found on fence's async waiter list. */ int sync_fence_cancel_async(struct sync_fence *fence, struct sync_fence_waiter *waiter); @@ -341,7 +336,9 @@ int sync_fence_cancel_async(struct sync_fence *fence, * @tiemout: timeout in ms * * Wait for @fence to be signaled or have an error. Waits indefinitely - * if @timeout < 0 + * if @timeout < 0. + * + * Returns 0 if fence signaled, > 0 if it is still active and <0 on error */ int sync_fence_wait(struct sync_fence *fence, long timeout);
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
These interfaces are not used nor have plans to be used in the near future so remove them for a cleaner solution before de-staging the sync framework.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 56 ------------------------------------ drivers/staging/android/sync.h | 50 -------------------------------- drivers/staging/android/sync_debug.c | 15 ---------- 3 files changed, 121 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index ed43796..7a84f88 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -317,62 +317,6 @@ struct sync_fence *sync_fence_merge(const char *name, } EXPORT_SYMBOL(sync_fence_merge);
-int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode, - int wake_flags, void *key) -{ - struct sync_fence_waiter *wait; - - wait = container_of(curr, struct sync_fence_waiter, work); - list_del_init(&wait->work.task_list); - - wait->callback(wait->work.private, wait); - return 1; -} - -int sync_fence_wait_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter) -{ - int err = atomic_read(&fence->status); - unsigned long flags; - - if (err < 0) - return err; - - if (!err) - return 1; - - init_waitqueue_func_entry(&waiter->work, sync_fence_wake_up_wq); - waiter->work.private = fence; - - spin_lock_irqsave(&fence->wq.lock, flags); - err = atomic_read(&fence->status); - if (err > 0) - __add_wait_queue_tail(&fence->wq, &waiter->work); - spin_unlock_irqrestore(&fence->wq.lock, flags); - - if (err < 0) - return err; - - return !err; -} -EXPORT_SYMBOL(sync_fence_wait_async); - -int sync_fence_cancel_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter) -{ - unsigned long flags; - int ret = 0; - - spin_lock_irqsave(&fence->wq.lock, flags); - if (!list_empty(&waiter->work.task_list)) - list_del_init(&waiter->work.task_list); - else - ret = -ENOENT; - spin_unlock_irqrestore(&fence->wq.lock, flags); - return ret; -} -EXPORT_SYMBOL(sync_fence_cancel_async); - int sync_fence_wait(struct sync_fence *fence, long timeout) { long ret; diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index 7a4d820..e0865b9 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -159,27 +159,6 @@ struct sync_fence { struct sync_fence_cb cbs[]; };
-struct sync_fence_waiter; -typedef void (*sync_callback_t)(struct sync_fence *fence, - struct sync_fence_waiter *waiter); - -/** - * struct sync_fence_waiter - metadata for asynchronous waiter on a fence - * @work: wait_queue for the fence waiter - * @callback: function pointer to call when fence signals - */ -struct sync_fence_waiter { - wait_queue_t work; - sync_callback_t callback; -}; - -static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter, - sync_callback_t callback) -{ - INIT_LIST_HEAD(&waiter->work.task_list); - waiter->callback = callback; -} - /* * API for sync_timeline implementers */ @@ -304,33 +283,6 @@ void sync_fence_put(struct sync_fence *fence); void sync_fence_install(struct sync_fence *fence, int fd);
/** - * sync_fence_wait_async() - registers and async wait on the fence - * @fence: fence to wait on - * @waiter: waiter callback struck - * - * Registers a callback to be called when @fence signals or has an error. - * @waiter should be initialized with sync_fence_waiter_init(). - * - * Returns 1 if @fence has already signaled, 0 if not or <0 if error. - */ -int sync_fence_wait_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter); - -/** - * sync_fence_cancel_async() - cancels an async wait - * @fence: fence to wait on - * @waiter: waiter callback struck - * - * Cancels a previously registered async wait. Will fail gracefully if - * @waiter was never registered or if @fence has already signaled @waiter. - * - * Returns 0 if waiter was removed from fence's async waiter list. - * Returns -ENOENT if waiter was not found on fence's async waiter list. - */ -int sync_fence_cancel_async(struct sync_fence *fence, - struct sync_fence_waiter *waiter); - -/** * sync_fence_wait() - wait on fence * @fence: fence to wait on * @tiemout: timeout in ms @@ -357,7 +309,5 @@ void sync_dump(void); # define sync_fence_debug_remove(fence) # define sync_dump() #endif -int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode, - int wake_flags, void *key);
#endif /* _LINUX_SYNC_H */ diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index f45d13c..b366461 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -151,8 +151,6 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
static void sync_print_fence(struct seq_file *s, struct sync_fence *fence) { - wait_queue_t *pos; - unsigned long flags; int i;
seq_printf(s, "[%p] %s: %s\n", fence, fence->name, @@ -161,19 +159,6 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence) for (i = 0; i < fence->num_fences; ++i) { sync_print_pt(s, fence->cbs[i].sync_pt, true); } - - spin_lock_irqsave(&fence->wq.lock, flags); - list_for_each_entry(pos, &fence->wq.task_list, task_list) { - struct sync_fence_waiter *waiter; - - if (pos->func != &sync_fence_wake_up_wq) - continue; - - waiter = container_of(pos, struct sync_fence_waiter, work); - - seq_printf(s, "waiter %pF\n", waiter->callback); - } - spin_unlock_irqrestore(&fence->wq.lock, flags); }
static int sync_debugfs_show(struct seq_file *s, void *unused)
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
.dup and .compare are not used by the sync framework, so remove them from sw_sync.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sw_sync.c | 29 +---------------------------- drivers/staging/android/sync.c | 6 ------ drivers/staging/android/sync.h | 19 ------------------- 3 files changed, 1 insertion(+), 53 deletions(-)
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index c4ff167..566dcdc 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -25,14 +25,6 @@
#include "sw_sync.h"
-static int sw_sync_cmp(u32 a, u32 b) -{ - if (a == b) - return 0; - - return ((s32)a - (s32)b) < 0 ? -1 : 1; -} - struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) { struct sw_sync_pt *pt; @@ -46,30 +38,13 @@ struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) } EXPORT_SYMBOL(sw_sync_pt_create);
-static struct sync_pt *sw_sync_pt_dup(struct sync_pt *sync_pt) -{ - struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt; - struct sw_sync_timeline *obj = - (struct sw_sync_timeline *)sync_pt_parent(sync_pt); - - return (struct sync_pt *)sw_sync_pt_create(obj, pt->value); -} - static int sw_sync_pt_has_signaled(struct sync_pt *sync_pt) { struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt; struct sw_sync_timeline *obj = (struct sw_sync_timeline *)sync_pt_parent(sync_pt);
- return sw_sync_cmp(obj->value, pt->value) >= 0; -} - -static int sw_sync_pt_compare(struct sync_pt *a, struct sync_pt *b) -{ - struct sw_sync_pt *pt_a = (struct sw_sync_pt *)a; - struct sw_sync_pt *pt_b = (struct sw_sync_pt *)b; - - return sw_sync_cmp(pt_a->value, pt_b->value); + return (pt->value > obj->value) ? 0 : 1; }
static int sw_sync_fill_driver_data(struct sync_pt *sync_pt, @@ -103,9 +78,7 @@ static void sw_sync_pt_value_str(struct sync_pt *sync_pt,
static struct sync_timeline_ops sw_sync_timeline_ops = { .driver_name = "sw_sync", - .dup = sw_sync_pt_dup, .has_signaled = sw_sync_pt_has_signaled, - .compare = sw_sync_pt_compare, .fill_driver_data = sw_sync_fill_driver_data, .timeline_value_str = sw_sync_timeline_value_str, .pt_value_str = sw_sync_pt_value_str, diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 7a84f88..f4d9bcd 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -68,9 +68,6 @@ static void sync_timeline_free(struct kref *kref)
sync_timeline_debug_remove(obj);
- if (obj->ops->release_obj) - obj->ops->release_obj(obj); - kfree(obj); }
@@ -383,9 +380,6 @@ static void android_fence_release(struct fence *fence) list_del(&pt->active_list); spin_unlock_irqrestore(fence->lock, flags);
- if (parent->ops->free_pt) - parent->ops->free_pt(pt); - sync_timeline_put(parent); fence_free(&pt->base); } diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index e0865b9..b47058f 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -30,17 +30,10 @@ struct sync_fence; /** * struct sync_timeline_ops - sync object implementation ops * @driver_name: name of the implementation - * @dup: duplicate a sync_pt * @has_signaled: returns: * 1 if pt has signaled * 0 if pt has not signaled * <0 on error - * @compare: returns: - * 1 if b will signal before a - * 0 if a and b will signal at the same time - * -1 if a will signal before b - * @free_pt: called before sync_pt is freed - * @release_obj: called before sync_timeline is freed * @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 @@ -52,20 +45,8 @@ struct sync_timeline_ops { const char *driver_name;
/* required */ - struct sync_pt * (*dup)(struct sync_pt *pt); - - /* required */ int (*has_signaled)(struct sync_pt *pt);
- /* required */ - int (*compare)(struct sync_pt *a, struct sync_pt *b); - - /* optional */ - void (*free_pt)(struct sync_pt *sync_pt); - - /* optional */ - void (*release_obj)(struct sync_timeline *sync_timeline); - /* optional */ int (*fill_driver_data)(struct sync_pt *syncpt, void *data, int size);
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Creates the 'sync' dir on debugfs root dir and move the 'sync' file to sync/info. This is the preparation to add more debug info and control.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync_debug.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index b366461..ca35f97 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -15,6 +15,7 @@ */
#include <linux/debugfs.h> +#include <linux/module.h> #include <linux/export.h> #include <linux/file.h> #include <linux/fs.h> @@ -30,6 +31,8 @@
#ifdef CONFIG_DEBUG_FS
+static struct dentry *dbgfs; + static LIST_HEAD(sync_timeline_list_head); static DEFINE_SPINLOCK(sync_timeline_list_lock); static LIST_HEAD(sync_fence_list_head); @@ -193,13 +196,13 @@ static int sync_debugfs_show(struct seq_file *s, void *unused) return 0; }
-static int sync_debugfs_open(struct inode *inode, struct file *file) +static int sync_info_debugfs_open(struct inode *inode, struct file *file) { return single_open(file, sync_debugfs_show, inode->i_private); }
-static const struct file_operations sync_debugfs_fops = { - .open = sync_debugfs_open, +static const struct file_operations sync_info_debugfs_fops = { + .open = sync_info_debugfs_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, @@ -207,11 +210,21 @@ static const struct file_operations sync_debugfs_fops = {
static __init int sync_debugfs_init(void) { - debugfs_create_file("sync", S_IRUGO, NULL, NULL, &sync_debugfs_fops); + dbgfs = debugfs_create_dir("sync", NULL); + + debugfs_create_file("info", 0444, dbgfs, NULL, &sync_info_debugfs_fops); + return 0; } late_initcall(sync_debugfs_init);
+static __exit void sync_debugfs_exit(void) +{ + if (dbgfs) + debugfs_remove_recursive(dbgfs); +} +module_exit(sync_debugfs_exit); + #define DUMP_CHUNK 256 static char sync_dump_buf[64 * 1024]; void sync_dump(void)
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
This remove CONFIG_SW_SYNC_USER and instead compile the sw_sync file into debugpfs under <debugfs>/sync/sw_sync.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/Kconfig | 9 --- drivers/staging/android/sw_sync.c | 129 ----------------------------------- drivers/staging/android/sync_debug.c | 118 +++++++++++++++++++++++++++++++- 3 files changed, 117 insertions(+), 139 deletions(-)
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig index 42b1512..bd90d20 100644 --- a/drivers/staging/android/Kconfig +++ b/drivers/staging/android/Kconfig @@ -57,15 +57,6 @@ config SW_SYNC synchronization. Useful when there is no hardware primitive backing the synchronization.
-config SW_SYNC_USER - bool "Userspace API for SW_SYNC" - default n - depends on SW_SYNC - ---help--- - Provides a user space API to the sw sync object. - *WARNING* improper use of this can result in deadlocking kernel - drivers from userspace. - source "drivers/staging/android/ion/Kconfig"
endif # if ANDROID diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index 566dcdc..f491dbc 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -102,132 +102,3 @@ void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc) sync_timeline_signal(&obj->obj); } EXPORT_SYMBOL(sw_sync_timeline_inc); - -#ifdef CONFIG_SW_SYNC_USER -/* *WARNING* - * - * improper use of this can result in deadlocking kernel drivers from userspace. - */ - -/* opening sw_sync create a new sync obj */ -static int sw_sync_open(struct inode *inode, struct file *file) -{ - struct sw_sync_timeline *obj; - char task_comm[TASK_COMM_LEN]; - - get_task_comm(task_comm, current); - - obj = sw_sync_timeline_create(task_comm); - if (!obj) - return -ENOMEM; - - file->private_data = obj; - - return 0; -} - -static int sw_sync_release(struct inode *inode, struct file *file) -{ - struct sw_sync_timeline *obj = file->private_data; - - sync_timeline_destroy(&obj->obj); - return 0; -} - -static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, - unsigned long arg) -{ - int fd = get_unused_fd_flags(O_CLOEXEC); - int err; - struct sync_pt *pt; - struct sync_fence *fence; - struct sw_sync_create_fence_data data; - - if (fd < 0) - return fd; - - if (copy_from_user(&data, (void __user *)arg, sizeof(data))) { - err = -EFAULT; - goto err; - } - - pt = sw_sync_pt_create(obj, data.value); - if (!pt) { - err = -ENOMEM; - goto err; - } - - data.name[sizeof(data.name) - 1] = '\0'; - fence = sync_fence_create(data.name, pt); - if (!fence) { - sync_pt_free(pt); - err = -ENOMEM; - goto err; - } - - data.fence = fd; - if (copy_to_user((void __user *)arg, &data, sizeof(data))) { - sync_fence_put(fence); - err = -EFAULT; - goto err; - } - - sync_fence_install(fence, fd); - - return 0; - -err: - put_unused_fd(fd); - return err; -} - -static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg) -{ - u32 value; - - if (copy_from_user(&value, (void __user *)arg, sizeof(value))) - return -EFAULT; - - sw_sync_timeline_inc(obj, value); - - return 0; -} - -static long sw_sync_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - struct sw_sync_timeline *obj = file->private_data; - - switch (cmd) { - case SW_SYNC_IOC_CREATE_FENCE: - return sw_sync_ioctl_create_fence(obj, arg); - - case SW_SYNC_IOC_INC: - return sw_sync_ioctl_inc(obj, arg); - - default: - return -ENOTTY; - } -} - -static const struct file_operations sw_sync_fops = { - .owner = THIS_MODULE, - .open = sw_sync_open, - .release = sw_sync_release, - .unlocked_ioctl = sw_sync_ioctl, - .compat_ioctl = sw_sync_ioctl, -}; - -static struct miscdevice sw_sync_dev = { - .minor = MISC_DYNAMIC_MINOR, - .name = "sw_sync", - .fops = &sw_sync_fops, -}; - -static int __init sw_sync_device_init(void) -{ - return misc_register(&sw_sync_dev); -} -device_initcall(sw_sync_device_init); - -#endif /* CONFIG_SW_SYNC_USER */ diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index ca35f97..ae08fc1 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -27,7 +27,7 @@ #include <linux/uaccess.h> #include <linux/anon_inodes.h> #include <linux/time64.h> -#include "sync.h" +#include "sw_sync.h"
#ifdef CONFIG_DEBUG_FS
@@ -208,11 +208,127 @@ static const struct file_operations sync_info_debugfs_fops = { .release = single_release, };
+/* + * *WARNING* + * + * improper use of this can result in deadlocking kernel drivers from userspace. + */ + +/* opening sw_sync create a new sync obj */ +static int sw_sync_debugfs_open(struct inode *inode, struct file *file) +{ + struct sw_sync_timeline *obj; + char task_comm[TASK_COMM_LEN]; + + get_task_comm(task_comm, current); + + obj = sw_sync_timeline_create(task_comm); + if (!obj) + return -ENOMEM; + + file->private_data = obj; + + return 0; +} + +static int sw_sync_debugfs_release(struct inode *inode, struct file *file) +{ + struct sw_sync_timeline *obj = file->private_data; + + sync_timeline_destroy(&obj->obj); + return 0; +} + +static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, + unsigned long arg) +{ + int fd = get_unused_fd_flags(O_CLOEXEC); + int err; + struct sync_pt *pt; + struct sync_fence *fence; + struct sw_sync_create_fence_data data; + + if (fd < 0) + return fd; + + if (copy_from_user(&data, (void __user *)arg, sizeof(data))) { + err = -EFAULT; + goto err; + } + + pt = sw_sync_pt_create(obj, data.value); + if (!pt) { + err = -ENOMEM; + goto err; + } + + data.name[sizeof(data.name) - 1] = '\0'; + fence = sync_fence_create(data.name, pt); + if (!fence) { + sync_pt_free(pt); + err = -ENOMEM; + goto err; + } + + data.fence = fd; + if (copy_to_user((void __user *)arg, &data, sizeof(data))) { + sync_fence_put(fence); + err = -EFAULT; + goto err; + } + + sync_fence_install(fence, fd); + + return 0; + +err: + put_unused_fd(fd); + return err; +} + +static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg) +{ + u32 value; + + if (copy_from_user(&value, (void __user *)arg, sizeof(value))) + return -EFAULT; + + sw_sync_timeline_inc(obj, value); + + return 0; +} + +static long sw_sync_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + struct sw_sync_timeline *obj = file->private_data; + + switch (cmd) { + case SW_SYNC_IOC_CREATE_FENCE: + return sw_sync_ioctl_create_fence(obj, arg); + + case SW_SYNC_IOC_INC: + return sw_sync_ioctl_inc(obj, arg); + + default: + return -ENOTTY; + } +} + +static const struct file_operations sw_sync_debugfs_fops = { + .open = sw_sync_debugfs_open, + .release = sw_sync_debugfs_release, + .unlocked_ioctl = sw_sync_ioctl, + .compat_ioctl = sw_sync_ioctl, +}; + static __init int sync_debugfs_init(void) { dbgfs = debugfs_create_dir("sync", NULL);
debugfs_create_file("info", 0444, dbgfs, NULL, &sync_info_debugfs_fops); + debugfs_create_file("sw_sync", 0644, dbgfs, NULL, + &sw_sync_debugfs_fops);
return 0; }
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
sync_file has a more close meaning to what a sync_fence really, a struct that represent a file that can be used by userspace to get information on a fence, or wait for it to be signaled.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 254 ++++++++++++++++++----------------- drivers/staging/android/sync.h | 98 +++++++------- drivers/staging/android/sync_debug.c | 53 ++++---- drivers/staging/android/trace/sync.h | 10 +- drivers/staging/android/uapi/sync.h | 14 +- 5 files changed, 218 insertions(+), 211 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index f4d9bcd..8cccdf9 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -32,7 +32,7 @@ #include "trace/sync.h"
static const struct fence_ops android_fence_ops; -static const struct file_operations sync_fence_fops; +static const struct file_operations sync_file_fops;
struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, int size, const char *name) @@ -147,80 +147,81 @@ void sync_pt_free(struct sync_pt *pt) } EXPORT_SYMBOL(sync_pt_free);
-static struct sync_fence *sync_fence_alloc(int size, const char *name) +static struct sync_file *sync_file_alloc(int size, const char *name) { - struct sync_fence *fence; + struct sync_file *sync_file;
- fence = kzalloc(size, GFP_KERNEL); - if (!fence) + sync_file = kzalloc(size, GFP_KERNEL); + if (!sync_file) return NULL;
- fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops, - fence, 0); - if (IS_ERR(fence->file)) + sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops, + sync_file, 0); + if (IS_ERR(sync_file->file)) goto err;
- kref_init(&fence->kref); - strlcpy(fence->name, name, sizeof(fence->name)); + kref_init(&sync_file->kref); + strlcpy(sync_file->name, name, sizeof(sync_file->name));
- init_waitqueue_head(&fence->wq); + init_waitqueue_head(&sync_file->wq);
- return fence; + return sync_file;
err: - kfree(fence); + kfree(sync_file); return NULL; }
static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) { - struct sync_fence_cb *check; - struct sync_fence *fence; + struct sync_file_cb *check; + struct sync_file *sync_file;
- check = container_of(cb, struct sync_fence_cb, cb); - fence = check->fence; + check = container_of(cb, struct sync_file_cb, cb); + sync_file = check->sync_file;
- if (atomic_dec_and_test(&fence->status)) - wake_up_all(&fence->wq); + if (atomic_dec_and_test(&sync_file->status)) + wake_up_all(&sync_file->wq); }
/* TODO: implement a create which takes more that one sync_pt */ -struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt) +struct sync_file *sync_file_create_dma(const char *name, struct fence *pt) { - struct sync_fence *fence; + struct sync_file *sync_file;
- fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]), name); - if (!fence) + sync_file = sync_file_alloc(offsetof(struct sync_file, cbs[1]), + name); + if (!sync_file) return NULL;
- fence->num_fences = 1; - atomic_set(&fence->status, 1); + sync_file->num_fences = 1; + atomic_set(&sync_file->status, 1);
- fence->cbs[0].sync_pt = pt; - fence->cbs[0].fence = fence; - if (fence_add_callback(pt, &fence->cbs[0].cb, fence_check_cb_func)) - atomic_dec(&fence->status); + sync_file->cbs[0].sync_pt = pt; + sync_file->cbs[0].sync_file = sync_file; + if (fence_add_callback(pt, &sync_file->cbs[0].cb, fence_check_cb_func)) + atomic_dec(&sync_file->status);
- sync_fence_debug_add(fence); + sync_file_debug_add(sync_file);
- return fence; + return sync_file; } -EXPORT_SYMBOL(sync_fence_create_dma); +EXPORT_SYMBOL(sync_file_create_dma);
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt) +struct sync_file *sync_file_create(const char *name, struct sync_pt *pt) { - return sync_fence_create_dma(name, &pt->base); + return sync_file_create_dma(name, &pt->base); } -EXPORT_SYMBOL(sync_fence_create); +EXPORT_SYMBOL(sync_file_create);
-struct sync_fence *sync_fence_fdget(int fd) +struct sync_file *sync_file_fdget(int fd) { struct file *file = fget(fd);
if (!file) return NULL;
- if (file->f_op != &sync_fence_fops) + if (file->f_op != &sync_file_fops) goto err;
return file->private_data; @@ -229,70 +230,71 @@ err: fput(file); return NULL; } -EXPORT_SYMBOL(sync_fence_fdget); +EXPORT_SYMBOL(sync_file_fdget);
-void sync_fence_put(struct sync_fence *fence) +void sync_file_put(struct sync_file *sync_file) { - fput(fence->file); + fput(sync_file->file); } -EXPORT_SYMBOL(sync_fence_put); +EXPORT_SYMBOL(sync_file_put);
-void sync_fence_install(struct sync_fence *fence, int fd) +void sync_file_install(struct sync_file *sync_file, int fd) { - fd_install(fd, fence->file); + fd_install(fd, sync_file->file); } -EXPORT_SYMBOL(sync_fence_install); +EXPORT_SYMBOL(sync_file_install);
-static void sync_fence_add_pt(struct sync_fence *fence, - int *i, struct fence *pt) +static void sync_file_add_pt(struct sync_file *sync_file, int *i, + struct fence *pt) { - fence->cbs[*i].sync_pt = pt; - fence->cbs[*i].fence = fence; + sync_file->cbs[*i].sync_pt = pt; + sync_file->cbs[*i].sync_file = sync_file;
- if (!fence_add_callback(pt, &fence->cbs[*i].cb, fence_check_cb_func)) { + if (!fence_add_callback(pt, &sync_file->cbs[*i].cb, + fence_check_cb_func)) { fence_get(pt); (*i)++; } }
-struct sync_fence *sync_fence_merge(const char *name, - struct sync_fence *a, struct sync_fence *b) +struct sync_file *sync_file_merge(const char *name, + struct sync_file *a, struct sync_file *b) { int num_fences = a->num_fences + b->num_fences; - struct sync_fence *fence; + struct sync_file *sync_file; int i, i_a, i_b; - unsigned long size = offsetof(struct sync_fence, cbs[num_fences]); + unsigned long size = offsetof(struct sync_file, cbs[num_fences]);
- fence = sync_fence_alloc(size, name); - if (!fence) + sync_file = sync_file_alloc(size, name); + if (!sync_file) return NULL;
- atomic_set(&fence->status, num_fences); + atomic_set(&sync_file->status, num_fences);
/* - * Assume sync_fence a and b are both ordered and have no + * Assume sync_file a and b are both ordered and have no * duplicates with the same context. * - * If a sync_fence can only be created with sync_fence_merge - * and sync_fence_create, this is a reasonable assumption. + * If a sync_file can only be created with sync_file_merge + * and sync_file_create, this is a reasonable assumption. */ for (i = i_a = i_b = 0; i_a < a->num_fences && i_b < b->num_fences; ) { struct fence *pt_a = a->cbs[i_a].sync_pt; struct fence *pt_b = b->cbs[i_b].sync_pt;
if (pt_a->context < pt_b->context) { - sync_fence_add_pt(fence, &i, pt_a); + sync_file_add_pt(sync_file, &i, pt_a);
i_a++; } else if (pt_a->context > pt_b->context) { - sync_fence_add_pt(fence, &i, pt_b); + sync_file_add_pt(sync_file, &i, pt_b);
i_b++; } else { if (pt_a->seqno - pt_b->seqno <= INT_MAX) - sync_fence_add_pt(fence, &i, pt_a); + sync_file_add_pt(sync_file, &i, pt_a); else - sync_fence_add_pt(fence, &i, pt_b); + sync_file_add_pt(sync_file, &i, pt_b);
i_a++; i_b++; @@ -300,21 +302,21 @@ struct sync_fence *sync_fence_merge(const char *name, }
for (; i_a < a->num_fences; i_a++) - sync_fence_add_pt(fence, &i, a->cbs[i_a].sync_pt); + sync_file_add_pt(sync_file, &i, a->cbs[i_a].sync_pt);
for (; i_b < b->num_fences; i_b++) - sync_fence_add_pt(fence, &i, b->cbs[i_b].sync_pt); + sync_file_add_pt(sync_file, &i, b->cbs[i_b].sync_pt);
if (num_fences > i) - atomic_sub(num_fences - i, &fence->status); - fence->num_fences = i; + atomic_sub(num_fences - i, &sync_file->status); + sync_file->num_fences = i;
- sync_fence_debug_add(fence); - return fence; + sync_file_debug_add(sync_file); + return sync_file; } -EXPORT_SYMBOL(sync_fence_merge); +EXPORT_SYMBOL(sync_file_merge);
-int sync_fence_wait(struct sync_fence *fence, long timeout) +int sync_file_wait(struct sync_file *sync_file, long timeout) { long ret; int i; @@ -324,33 +326,33 @@ int sync_fence_wait(struct sync_fence *fence, long timeout) else timeout = msecs_to_jiffies(timeout);
- trace_sync_wait(fence, 1); - for (i = 0; i < fence->num_fences; ++i) - trace_sync_pt(fence->cbs[i].sync_pt); - ret = wait_event_interruptible_timeout(fence->wq, - atomic_read(&fence->status) <= 0, + trace_sync_wait(sync_file, 1); + for (i = 0; i < sync_file->num_fences; ++i) + trace_sync_pt(sync_file->cbs[i].sync_pt); + ret = wait_event_interruptible_timeout(sync_file->wq, + atomic_read(&sync_file->status) <= 0, timeout); - trace_sync_wait(fence, 0); + trace_sync_wait(sync_file, 0);
if (ret < 0) { return ret; } else if (ret == 0) { if (timeout) { - pr_info("fence timeout on [%p] after %dms\n", fence, - jiffies_to_msecs(timeout)); + pr_info("sync_file timeout on [%p] after %dms\n", + sync_file, jiffies_to_msecs(timeout)); sync_dump(); } return -ETIME; }
- ret = atomic_read(&fence->status); + ret = atomic_read(&sync_file->status); if (ret) { - pr_info("fence error %ld on [%p]\n", ret, fence); + pr_info("sync_file error %ld on [%p]\n", ret, sync_file); sync_dump(); } return ret; } -EXPORT_SYMBOL(sync_fence_wait); +EXPORT_SYMBOL(sync_file_wait);
static const char *android_fence_get_driver_name(struct fence *fence) { @@ -459,37 +461,39 @@ static const struct fence_ops android_fence_ops = { .timeline_value_str = android_fence_timeline_value_str, };
-static void sync_fence_free(struct kref *kref) +static void sync_file_free(struct kref *kref) { - struct sync_fence *fence = container_of(kref, struct sync_fence, kref); + struct sync_file *sync_file = container_of(kref, struct sync_file, + kref); int i;
- for (i = 0; i < fence->num_fences; ++i) { - fence_remove_callback(fence->cbs[i].sync_pt, &fence->cbs[i].cb); - fence_put(fence->cbs[i].sync_pt); + for (i = 0; i < sync_file->num_fences; ++i) { + fence_remove_callback(sync_file->cbs[i].sync_pt, + &sync_file->cbs[i].cb); + fence_put(sync_file->cbs[i].sync_pt); }
- kfree(fence); + kfree(sync_file); }
-static int sync_fence_release(struct inode *inode, struct file *file) +static int sync_file_release(struct inode *inode, struct file *file) { - struct sync_fence *fence = file->private_data; + struct sync_file *sync_file = file->private_data;
- sync_fence_debug_remove(fence); + sync_file_debug_remove(sync_file);
- kref_put(&fence->kref, sync_fence_free); + kref_put(&sync_file->kref, sync_file_free); return 0; }
-static unsigned int sync_fence_poll(struct file *file, poll_table *wait) +static unsigned int sync_file_poll(struct file *file, poll_table *wait) { - struct sync_fence *fence = file->private_data; + struct sync_file *sync_file = file->private_data; int status;
- poll_wait(file, &fence->wq, wait); + poll_wait(file, &sync_file->wq, wait);
- status = atomic_read(&fence->status); + status = atomic_read(&sync_file->status);
if (!status) return POLLIN; @@ -498,21 +502,23 @@ static unsigned int sync_fence_poll(struct file *file, poll_table *wait) return 0; }
-static long sync_fence_ioctl_wait(struct sync_fence *fence, unsigned long arg) +static long sync_file_ioctl_wait(struct sync_file *sync_file, + unsigned long arg) { __s32 value;
if (copy_from_user(&value, (void __user *)arg, sizeof(value))) return -EFAULT;
- return sync_fence_wait(fence, value); + return sync_file_wait(sync_file, value); }
-static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg) +static long sync_file_ioctl_merge(struct sync_file *sync_file, + unsigned long arg) { int fd = get_unused_fd_flags(O_CLOEXEC); int err; - struct sync_fence *fence2, *fence3; + struct sync_file *fence2, *fence3; struct sync_merge_data data;
if (fd < 0) @@ -523,14 +529,14 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg) goto err_put_fd; }
- fence2 = sync_fence_fdget(data.fd2); + fence2 = sync_file_fdget(data.fd2); if (!fence2) { err = -ENOENT; goto err_put_fd; }
data.name[sizeof(data.name) - 1] = '\0'; - fence3 = sync_fence_merge(data.name, fence, fence2); + fence3 = sync_file_merge(data.name, sync_file, fence2); if (!fence3) { err = -ENOMEM; goto err_put_fence2; @@ -542,15 +548,15 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg) goto err_put_fence3; }
- sync_fence_install(fence3, fd); - sync_fence_put(fence2); + sync_file_install(fence3, fd); + sync_file_put(fence2); return 0;
err_put_fence3: - sync_fence_put(fence3); + sync_file_put(fence3);
err_put_fence2: - sync_fence_put(fence2); + sync_file_put(fence2);
err_put_fd: put_unused_fd(fd); @@ -589,10 +595,10 @@ static int sync_fill_pt_info(struct fence *fence, void *data, int size) return info->len; }
-static long sync_fence_ioctl_fence_info(struct sync_fence *fence, +static long sync_file_ioctl_fence_info(struct sync_file *sync_file, unsigned long arg) { - struct sync_fence_info_data *data; + struct sync_file_info_data *data; __u32 size; __u32 len = 0; int ret, i; @@ -600,7 +606,7 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence, if (copy_from_user(&size, (void __user *)arg, sizeof(size))) return -EFAULT;
- if (size < sizeof(struct sync_fence_info_data)) + if (size < sizeof(struct sync_file_info_data)) return -EINVAL;
if (size > 4096) @@ -610,15 +616,15 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *fence, if (!data) return -ENOMEM;
- strlcpy(data->name, fence->name, sizeof(data->name)); - data->status = atomic_read(&fence->status); + strlcpy(data->name, sync_file->name, sizeof(data->name)); + data->status = atomic_read(&sync_file->status); if (data->status >= 0) data->status = !data->status;
- len = sizeof(struct sync_fence_info_data); + len = sizeof(struct sync_file_info_data);
- for (i = 0; i < fence->num_fences; ++i) { - struct fence *pt = fence->cbs[i].sync_pt; + for (i = 0; i < sync_file->num_fences; ++i) { + struct fence *pt = sync_file->cbs[i].sync_pt;
ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len);
@@ -641,30 +647,30 @@ out: return ret; }
-static long sync_fence_ioctl(struct file *file, unsigned int cmd, +static long sync_file_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct sync_fence *fence = file->private_data; + struct sync_file *sync_file = file->private_data;
switch (cmd) { case SYNC_IOC_WAIT: - return sync_fence_ioctl_wait(fence, arg); + return sync_file_ioctl_wait(sync_file, arg);
case SYNC_IOC_MERGE: - return sync_fence_ioctl_merge(fence, arg); + return sync_file_ioctl_merge(sync_file, arg);
case SYNC_IOC_FENCE_INFO: - return sync_fence_ioctl_fence_info(fence, arg); + return sync_file_ioctl_fence_info(sync_file, arg);
default: return -ENOTTY; } }
-static const struct file_operations sync_fence_fops = { - .release = sync_fence_release, - .poll = sync_fence_poll, - .unlocked_ioctl = sync_fence_ioctl, - .compat_ioctl = sync_fence_ioctl, +static const struct file_operations sync_file_fops = { + .release = sync_file_release, + .poll = sync_file_poll, + .unlocked_ioctl = sync_file_ioctl, + .compat_ioctl = sync_file_ioctl, };
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index b47058f..bec62c3 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -25,7 +25,7 @@
struct sync_timeline; struct sync_pt; -struct sync_fence; +struct sync_file;
/** * struct sync_timeline_ops - sync object implementation ops @@ -108,36 +108,36 @@ static inline struct sync_timeline *sync_pt_parent(struct sync_pt *pt) child_list_lock); }
-struct sync_fence_cb { +struct sync_file_cb { struct fence_cb cb; struct fence *sync_pt; - struct sync_fence *fence; + struct sync_file *sync_file; };
/** - * struct sync_fence - sync fence + * struct sync_file - sync file to export to the userspace * @file: file representing this fence * @kref: reference count on fence. - * @name: name of sync_fence. Useful for debugging - * @sync_fence_list: membership in global fence list + * @name: name of sync_file. Useful for debugging + * @sync_file_list: membership in global file list * @num_fences number of sync_pts in the fence * @wq: wait queue for fence signaling * @status: 0: signaled, >0:active, <0: error * @cbs: sync_pts callback information */ -struct sync_fence { +struct sync_file { struct file *file; struct kref kref; char name[32]; #ifdef CONFIG_DEBUG_FS - struct list_head sync_fence_list; + struct list_head sync_file_list; #endif int num_fences;
wait_queue_head_t wq; atomic_t status;
- struct sync_fence_cb cbs[]; + struct sync_file_cb cbs[]; };
/* @@ -199,95 +199,95 @@ struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size); void sync_pt_free(struct sync_pt *pt);
/** - * sync_fence_create() - creates a sync fence - * @name: name of fence to create - * @pt: sync_pt to add to the fence + * sync_file_create() - creates a sync file + * @name: name of file to create + * @pt: sync_pt to add to the file * - * Creates a fence containg @pt. Once this is called, the fence takes + * Creates a sync_file containg @pt. Once this is called, the sync_file takes * ownership of @pt. */ -struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt); +struct sync_file *sync_file_create(const char *name, struct sync_pt *pt);
/** - * sync_fence_create_dma() - creates a sync fence from dma-fence - * @name: name of fence to create - * @pt: dma-fence to add to the fence + * sync_file_create_dma() - creates a sync file from dma-fence + * @name: name of file to create + * @pt: dma-fence to add to the file * - * Creates a fence containg @pt. Once this is called, the fence takes + * Creates a sync_file containg @pt. Once this is called, the fence takes * ownership of @pt. */ -struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt); +struct sync_file *sync_file_create_dma(const char *name, struct fence *pt);
/* - * API for sync_fence consumers + * API for sync_file consumers */
/** - * sync_fence_merge() - merge two fences + * sync_file_merge() - merge two sync_files * @name: name of new fence - * @a: fence a - * @b: fence b + * @a: sync_file a + * @b: sync_file b * - * Creates a new fence which contains copies of all the sync_pts in both - * @a and @b. @a and @b remain valid, independent fences. Returns the - * new merged fence or NULL in case of error. + * Creates a new sync_file which contains copies of all the sync_pts in both + * @a and @b. @a and @b remain valid, independent sync_file. Returns the + * new merged sync_file or NULL in case of error. */ -struct sync_fence *sync_fence_merge(const char *name, - struct sync_fence *a, struct sync_fence *b); +struct sync_file *sync_file_merge(const char *name, + struct sync_file *a, struct sync_file *b);
/** - * sync_fence_fdget() - get a fence from an fd + * sync_file_fdget() - get a sync_file from an fd * @fd: fd referencing a fence * - * Ensures @fd references a valid fence, increments the refcount of the backing - * file, and returns the fence. Returns the fence or NULL in case of error. + * Ensures @fd references a valid sync_file, increments the refcount of the + * backing file. Returns the sync_file or NULL in case of error. */ -struct sync_fence *sync_fence_fdget(int fd); +struct sync_file *sync_file_fdget(int fd);
/** - * sync_fence_put() - puts a reference of a sync fence - * @fence: fence to put + * sync_file_put() - puts a reference of a sync_file + * @sync_file: sync_file to put * - * Puts a reference on @fence. If this is the last reference, the fence and - * all it's sync_pts will be freed + * Puts a reference on @sync_fence. If this is the last reference, the + * sync_fil and all it's sync_pts will be freed */ -void sync_fence_put(struct sync_fence *fence); +void sync_file_put(struct sync_file *sync_file);
/** - * sync_fence_install() - installs a fence into a file descriptor - * @fence: fence to install + * sync_file_install() - installs a sync_file into a file descriptor + * @sync_file: sync_file to install * @fd: file descriptor in which to install the fence * - * Installs @fence into @fd. @fd's should be acquired through + * Installs @sync_file into @fd. @fd's should be acquired through * get_unused_fd_flags(O_CLOEXEC). */ -void sync_fence_install(struct sync_fence *fence, int fd); +void sync_file_install(struct sync_file *sync_file, int fd);
/** - * sync_fence_wait() - wait on fence - * @fence: fence to wait on + * sync_file_wait() - wait on sync file + * @sync_file: file to wait on * @tiemout: timeout in ms * - * Wait for @fence to be signaled or have an error. Waits indefinitely + * Wait for @sync_file to be signaled or have an error. Waits indefinitely * if @timeout < 0. * * Returns 0 if fence signaled, > 0 if it is still active and <0 on error */ -int sync_fence_wait(struct sync_fence *fence, long timeout); +int sync_file_wait(struct sync_file *sync_file, long timeout);
#ifdef CONFIG_DEBUG_FS
void sync_timeline_debug_add(struct sync_timeline *obj); void sync_timeline_debug_remove(struct sync_timeline *obj); -void sync_fence_debug_add(struct sync_fence *fence); -void sync_fence_debug_remove(struct sync_fence *fence); +void sync_file_debug_add(struct sync_file *fence); +void sync_file_debug_remove(struct sync_file *fence); void sync_dump(void);
#else # define sync_timeline_debug_add(obj) # define sync_timeline_debug_remove(obj) -# define sync_fence_debug_add(fence) -# define sync_fence_debug_remove(fence) +# define sync_file_debug_add(fence) +# define sync_file_debug_remove(fence) # define sync_dump() #endif
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index ae08fc1..6887ba7 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -35,8 +35,8 @@ static struct dentry *dbgfs;
static LIST_HEAD(sync_timeline_list_head); static DEFINE_SPINLOCK(sync_timeline_list_lock); -static LIST_HEAD(sync_fence_list_head); -static DEFINE_SPINLOCK(sync_fence_list_lock); +static LIST_HEAD(sync_file_list_head); +static DEFINE_SPINLOCK(sync_file_list_lock);
void sync_timeline_debug_add(struct sync_timeline *obj) { @@ -56,22 +56,22 @@ void sync_timeline_debug_remove(struct sync_timeline *obj) spin_unlock_irqrestore(&sync_timeline_list_lock, flags); }
-void sync_fence_debug_add(struct sync_fence *fence) +void sync_file_debug_add(struct sync_file *sync_file) { unsigned long flags;
- spin_lock_irqsave(&sync_fence_list_lock, flags); - list_add_tail(&fence->sync_fence_list, &sync_fence_list_head); - spin_unlock_irqrestore(&sync_fence_list_lock, flags); + spin_lock_irqsave(&sync_file_list_lock, flags); + list_add_tail(&sync_file->sync_file_list, &sync_file_list_head); + spin_unlock_irqrestore(&sync_file_list_lock, flags); }
-void sync_fence_debug_remove(struct sync_fence *fence) +void sync_file_debug_remove(struct sync_file *sync_file) { unsigned long flags;
- spin_lock_irqsave(&sync_fence_list_lock, flags); - list_del(&fence->sync_fence_list); - spin_unlock_irqrestore(&sync_fence_list_lock, flags); + spin_lock_irqsave(&sync_file_list_lock, flags); + list_del(&sync_file->sync_file_list); + spin_unlock_irqrestore(&sync_file_list_lock, flags); }
static const char *sync_status_str(int status) @@ -152,15 +152,16 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj) spin_unlock_irqrestore(&obj->child_list_lock, flags); }
-static void sync_print_fence(struct seq_file *s, struct sync_fence *fence) +static void sync_print_sync_file(struct seq_file *s, + struct sync_file *sync_file) { int i;
- seq_printf(s, "[%p] %s: %s\n", fence, fence->name, - sync_status_str(atomic_read(&fence->status))); + seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name, + sync_status_str(atomic_read(&sync_file->status)));
- for (i = 0; i < fence->num_fences; ++i) { - sync_print_pt(s, fence->cbs[i].sync_pt, true); + for (i = 0; i < sync_file->num_fences; ++i) { + sync_print_pt(s, sync_file->cbs[i].sync_pt, true); } }
@@ -184,15 +185,15 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
seq_puts(s, "fences:\n--------------\n");
- spin_lock_irqsave(&sync_fence_list_lock, flags); - list_for_each(pos, &sync_fence_list_head) { - struct sync_fence *fence = - container_of(pos, struct sync_fence, sync_fence_list); + spin_lock_irqsave(&sync_file_list_lock, flags); + list_for_each(pos, &sync_file_list_head) { + struct sync_file *sync_file = + container_of(pos, struct sync_file, sync_file_list);
- sync_print_fence(s, fence); + sync_print_sync_file(s, sync_file); seq_puts(s, "\n"); } - spin_unlock_irqrestore(&sync_fence_list_lock, flags); + spin_unlock_irqrestore(&sync_file_list_lock, flags); return 0; }
@@ -245,7 +246,7 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, int fd = get_unused_fd_flags(O_CLOEXEC); int err; struct sync_pt *pt; - struct sync_fence *fence; + struct sync_file *sync_file; struct sw_sync_create_fence_data data;
if (fd < 0) @@ -263,8 +264,8 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, }
data.name[sizeof(data.name) - 1] = '\0'; - fence = sync_fence_create(data.name, pt); - if (!fence) { + sync_file = sync_file_create(data.name, pt); + if (!sync_file) { sync_pt_free(pt); err = -ENOMEM; goto err; @@ -272,12 +273,12 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
data.fence = fd; if (copy_to_user((void __user *)arg, &data, sizeof(data))) { - sync_fence_put(fence); + sync_file_put(sync_file); err = -EFAULT; goto err; }
- sync_fence_install(fence, fd); + sync_file_install(sync_file, fd);
return 0;
diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h index 77edb97..80f5da4 100644 --- a/drivers/staging/android/trace/sync.h +++ b/drivers/staging/android/trace/sync.h @@ -33,19 +33,19 @@ TRACE_EVENT(sync_timeline, );
TRACE_EVENT(sync_wait, - TP_PROTO(struct sync_fence *fence, int begin), + TP_PROTO(struct sync_file *sync_file, int begin),
- TP_ARGS(fence, begin), + TP_ARGS(sync_file, begin),
TP_STRUCT__entry( - __string(name, fence->name) + __string(name, sync_file->name) __field(s32, status) __field(u32, begin) ),
TP_fast_assign( - __assign_str(name, fence->name); - __entry->status = atomic_read(&fence->status); + __assign_str(name, sync_file->name); + __entry->status = atomic_read(&sync_file->status); __entry->begin = begin; ),
diff --git a/drivers/staging/android/uapi/sync.h b/drivers/staging/android/uapi/sync.h index e964c75..73deb69 100644 --- a/drivers/staging/android/uapi/sync.h +++ b/drivers/staging/android/uapi/sync.h @@ -46,15 +46,15 @@ struct sync_pt_info { };
/** - * struct sync_fence_info_data - data returned from fence info ioctl + * struct sync_file_info_data - data returned from fence info ioctl * @len: ioctl caller writes the size of the buffer its passing in. - * ioctl returns length of sync_fence_data returned to userspace - * including pt_info. + * ioctl returns length of sync_file_info_data returned to + * userspace including pt_info. * @name: name of fence * @status: status of fence. 1: signaled 0:active <0:error * @pt_info: a sync_pt_info struct for every sync_pt in the fence */ -struct sync_fence_info_data { +struct sync_file_info_data { __u32 len; char name[32]; __s32 status; @@ -83,15 +83,15 @@ struct sync_fence_info_data { /** * DOC: SYNC_IOC_FENCE_INFO - get detailed information on a fence * - * Takes a struct sync_fence_info_data with extra space allocated for pt_info. + * Takes a struct sync_file_info_data with extra space allocated for pt_info. * Caller should write the size of the buffer into len. On return, len is - * updated to reflect the total size of the sync_fence_info_data including + * updated to reflect the total size of the sync_file_info_data including * pt_info. * * pt_info is a buffer containing sync_pt_infos for every sync_pt in the fence. * To iterate over the sync_pt_infos, use the sync_pt_info.len field. */ #define SYNC_IOC_FENCE_INFO _IOWR(SYNC_IOC_MAGIC, 2,\ - struct sync_fence_info_data) + struct sync_file_info_data)
#endif /* _UAPI_LINUX_SYNC_H */
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
'sync_pt' is actually declared as struct fence so to make the name means its type we rename it to 'fence'.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 20 ++++++++++---------- drivers/staging/android/sync.h | 2 +- drivers/staging/android/sync_debug.c | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 8cccdf9..22b1d9b 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -197,7 +197,7 @@ struct sync_file *sync_file_create_dma(const char *name, struct fence *pt) sync_file->num_fences = 1; atomic_set(&sync_file->status, 1);
- sync_file->cbs[0].sync_pt = pt; + sync_file->cbs[0].fence = pt; sync_file->cbs[0].sync_file = sync_file; if (fence_add_callback(pt, &sync_file->cbs[0].cb, fence_check_cb_func)) atomic_dec(&sync_file->status); @@ -247,7 +247,7 @@ EXPORT_SYMBOL(sync_file_install); static void sync_file_add_pt(struct sync_file *sync_file, int *i, struct fence *pt) { - sync_file->cbs[*i].sync_pt = pt; + sync_file->cbs[*i].fence = pt; sync_file->cbs[*i].sync_file = sync_file;
if (!fence_add_callback(pt, &sync_file->cbs[*i].cb, @@ -279,8 +279,8 @@ struct sync_file *sync_file_merge(const char *name, * and sync_file_create, this is a reasonable assumption. */ for (i = i_a = i_b = 0; i_a < a->num_fences && i_b < b->num_fences; ) { - struct fence *pt_a = a->cbs[i_a].sync_pt; - struct fence *pt_b = b->cbs[i_b].sync_pt; + struct fence *pt_a = a->cbs[i_a].fence; + struct fence *pt_b = b->cbs[i_b].fence;
if (pt_a->context < pt_b->context) { sync_file_add_pt(sync_file, &i, pt_a); @@ -302,10 +302,10 @@ struct sync_file *sync_file_merge(const char *name, }
for (; i_a < a->num_fences; i_a++) - sync_file_add_pt(sync_file, &i, a->cbs[i_a].sync_pt); + sync_file_add_pt(sync_file, &i, a->cbs[i_a].fence);
for (; i_b < b->num_fences; i_b++) - sync_file_add_pt(sync_file, &i, b->cbs[i_b].sync_pt); + sync_file_add_pt(sync_file, &i, b->cbs[i_b].fence);
if (num_fences > i) atomic_sub(num_fences - i, &sync_file->status); @@ -328,7 +328,7 @@ int sync_file_wait(struct sync_file *sync_file, long timeout)
trace_sync_wait(sync_file, 1); for (i = 0; i < sync_file->num_fences; ++i) - trace_sync_pt(sync_file->cbs[i].sync_pt); + trace_sync_pt(sync_file->cbs[i].fence); ret = wait_event_interruptible_timeout(sync_file->wq, atomic_read(&sync_file->status) <= 0, timeout); @@ -468,9 +468,9 @@ static void sync_file_free(struct kref *kref) int i;
for (i = 0; i < sync_file->num_fences; ++i) { - fence_remove_callback(sync_file->cbs[i].sync_pt, + fence_remove_callback(sync_file->cbs[i].fence, &sync_file->cbs[i].cb); - fence_put(sync_file->cbs[i].sync_pt); + fence_put(sync_file->cbs[i].fence); }
kfree(sync_file); @@ -624,7 +624,7 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, len = sizeof(struct sync_file_info_data);
for (i = 0; i < sync_file->num_fences; ++i) { - struct fence *pt = sync_file->cbs[i].sync_pt; + struct fence *pt = sync_file->cbs[i].fence;
ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index bec62c3..a18d1e3 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -110,7 +110,7 @@ static inline struct sync_timeline *sync_pt_parent(struct sync_pt *pt)
struct sync_file_cb { struct fence_cb cb; - struct fence *sync_pt; + struct fence *fence; struct sync_file *sync_file; };
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index 6887ba7..1889b5b 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -161,7 +161,7 @@ static void sync_print_sync_file(struct seq_file *s, sync_status_str(atomic_read(&sync_file->status)));
for (i = 0; i < sync_file->num_fences; ++i) { - sync_print_pt(s, sync_file->cbs[i].sync_pt, true); + sync_print_pt(s, sync_file->cbs[i].fence, true); } }
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
struct sync_pt was just wrapping around struct fence and creating an extra abstraction layer. The only two members of struct sync_pt, child_list and active_list, were moved to struct fence in an earlier commit. After removing those two members struct sync_pt is nothing more than struct fence, so remove it all and use struct fence directly.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sw_sync.c | 23 ++++---- drivers/staging/android/sw_sync.h | 8 +-- drivers/staging/android/sync.c | 101 +++++++++++++++-------------------- drivers/staging/android/sync.h | 63 +++++++--------------- drivers/staging/android/sync_debug.c | 43 +++++++-------- drivers/staging/android/trace/sync.h | 14 ++--- include/linux/fence.h | 2 + 7 files changed, 110 insertions(+), 144 deletions(-)
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c index f491dbc..3bee959 100644 --- a/drivers/staging/android/sw_sync.c +++ b/drivers/staging/android/sw_sync.c @@ -25,7 +25,7 @@
#include "sw_sync.h"
-struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) +struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value) { struct sw_sync_pt *pt;
@@ -34,23 +34,23 @@ struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
pt->value = value;
- return (struct sync_pt *)pt; + return (struct fence *)pt; } EXPORT_SYMBOL(sw_sync_pt_create);
-static int sw_sync_pt_has_signaled(struct sync_pt *sync_pt) +static int sw_sync_fence_has_signaled(struct fence *fence) { - struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt; + struct sw_sync_pt *pt = (struct sw_sync_pt *)fence; struct sw_sync_timeline *obj = - (struct sw_sync_timeline *)sync_pt_parent(sync_pt); + (struct sw_sync_timeline *)fence_parent(fence);
return (pt->value > obj->value) ? 0 : 1; }
-static int sw_sync_fill_driver_data(struct sync_pt *sync_pt, +static int sw_sync_fill_driver_data(struct fence *fence, void *data, int size) { - struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt; + struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
if (size < sizeof(pt->value)) return -ENOMEM; @@ -68,20 +68,19 @@ static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline, snprintf(str, size, "%d", timeline->value); }
-static void sw_sync_pt_value_str(struct sync_pt *sync_pt, - char *str, int size) +static void sw_sync_fence_value_str(struct fence *fence, char *str, int size) { - struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt; + struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
snprintf(str, size, "%d", pt->value); }
static struct sync_timeline_ops sw_sync_timeline_ops = { .driver_name = "sw_sync", - .has_signaled = sw_sync_pt_has_signaled, + .has_signaled = sw_sync_fence_has_signaled, .fill_driver_data = sw_sync_fill_driver_data, .timeline_value_str = sw_sync_timeline_value_str, - .pt_value_str = sw_sync_pt_value_str, + .fence_value_str = sw_sync_fence_value_str, };
struct sw_sync_timeline *sw_sync_timeline_create(const char *name) diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h index c87ae9e..e18667b 100644 --- a/drivers/staging/android/sw_sync.h +++ b/drivers/staging/android/sw_sync.h @@ -29,7 +29,7 @@ struct sw_sync_timeline { };
struct sw_sync_pt { - struct sync_pt pt; + struct fence pt;
u32 value; }; @@ -38,7 +38,7 @@ struct sw_sync_pt { struct sw_sync_timeline *sw_sync_timeline_create(const char *name); void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
-struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value); +struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value); #else static inline struct sw_sync_timeline *sw_sync_timeline_create(const char *name) { @@ -49,8 +49,8 @@ static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc) { }
-static inline struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, - u32 value) +static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, + u32 value) { return NULL; } diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 22b1d9b..3c2c8d0 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -102,51 +102,45 @@ void sync_timeline_signal(struct sync_timeline *obj) { unsigned long flags; LIST_HEAD(signaled_pts); - struct sync_pt *pt, *next; + struct fence *fence, *next;
trace_sync_timeline(obj);
spin_lock_irqsave(&obj->child_list_lock, flags);
- list_for_each_entry_safe(pt, next, &obj->active_list_head, + list_for_each_entry_safe(fence, next, &obj->active_list_head, active_list) { - if (fence_is_signaled_locked(&pt->base)) - list_del_init(&pt->active_list); + if (fence_is_signaled_locked(fence)) + list_del_init(&fence->active_list); }
spin_unlock_irqrestore(&obj->child_list_lock, flags); } EXPORT_SYMBOL(sync_timeline_signal);
-struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size) +struct fence *sync_pt_create(struct sync_timeline *obj, int size) { unsigned long flags; - struct sync_pt *pt; + struct fence *fence;
- if (size < sizeof(struct sync_pt)) + if (size < sizeof(*fence)) return NULL;
- pt = kzalloc(size, GFP_KERNEL); - if (!pt) + fence = kzalloc(size, GFP_KERNEL); + if (!fence) return NULL;
spin_lock_irqsave(&obj->child_list_lock, flags); sync_timeline_get(obj); - fence_init(&pt->base, &android_fence_ops, &obj->child_list_lock, + fence_init(fence, &android_fence_ops, &obj->child_list_lock, obj->context, ++obj->value); - list_add_tail(&pt->child_list, &obj->child_list_head); - INIT_LIST_HEAD(&pt->active_list); + list_add_tail(&fence->child_list, &obj->child_list_head); + INIT_LIST_HEAD(&fence->active_list); spin_unlock_irqrestore(&obj->child_list_lock, flags); - return pt; + return fence; } EXPORT_SYMBOL(sync_pt_create);
-void sync_pt_free(struct sync_pt *pt) -{ - fence_put(&pt->base); -} -EXPORT_SYMBOL(sync_pt_free); - static struct sync_file *sync_file_alloc(int size, const char *name) { struct sync_file *sync_file; @@ -184,8 +178,8 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) wake_up_all(&sync_file->wq); }
-/* TODO: implement a create which takes more that one sync_pt */ -struct sync_file *sync_file_create_dma(const char *name, struct fence *pt) +/* TODO: implement a create which takes more that one fence */ +struct sync_file *sync_file_create_dma(const char *name, struct fence *fence) { struct sync_file *sync_file;
@@ -197,9 +191,10 @@ struct sync_file *sync_file_create_dma(const char *name, struct fence *pt) sync_file->num_fences = 1; atomic_set(&sync_file->status, 1);
- sync_file->cbs[0].fence = pt; + sync_file->cbs[0].fence = fence; sync_file->cbs[0].sync_file = sync_file; - if (fence_add_callback(pt, &sync_file->cbs[0].cb, fence_check_cb_func)) + if (fence_add_callback(fence, &sync_file->cbs[0].cb, + fence_check_cb_func)) atomic_dec(&sync_file->status);
sync_file_debug_add(sync_file); @@ -208,9 +203,9 @@ struct sync_file *sync_file_create_dma(const char *name, struct fence *pt) } EXPORT_SYMBOL(sync_file_create_dma);
-struct sync_file *sync_file_create(const char *name, struct sync_pt *pt) +struct sync_file *sync_file_create(const char *name, struct fence *fence) { - return sync_file_create_dma(name, &pt->base); + return sync_file_create_dma(name, fence); } EXPORT_SYMBOL(sync_file_create);
@@ -245,14 +240,14 @@ void sync_file_install(struct sync_file *sync_file, int fd) EXPORT_SYMBOL(sync_file_install);
static void sync_file_add_pt(struct sync_file *sync_file, int *i, - struct fence *pt) + struct fence *fence) { - sync_file->cbs[*i].fence = pt; + sync_file->cbs[*i].fence = fence; sync_file->cbs[*i].sync_file = sync_file;
- if (!fence_add_callback(pt, &sync_file->cbs[*i].cb, + if (!fence_add_callback(fence, &sync_file->cbs[*i].cb, fence_check_cb_func)) { - fence_get(pt); + fence_get(fence); (*i)++; } } @@ -328,7 +323,7 @@ int sync_file_wait(struct sync_file *sync_file, long timeout)
trace_sync_wait(sync_file, 1); for (i = 0; i < sync_file->num_fences; ++i) - trace_sync_pt(sync_file->cbs[i].fence); + trace_fence(sync_file->cbs[i].fence); ret = wait_event_interruptible_timeout(sync_file->wq, atomic_read(&sync_file->status) <= 0, timeout); @@ -356,43 +351,39 @@ EXPORT_SYMBOL(sync_file_wait);
static const char *android_fence_get_driver_name(struct fence *fence) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
return parent->ops->driver_name; }
static const char *android_fence_get_timeline_name(struct fence *fence) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
return parent->name; }
static void android_fence_release(struct fence *fence) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence); unsigned long flags;
spin_lock_irqsave(fence->lock, flags); - list_del(&pt->child_list); - if (WARN_ON_ONCE(!list_empty(&pt->active_list))) - list_del(&pt->active_list); + list_del(&fence->child_list); + if (WARN_ON_ONCE(!list_empty(&fence->active_list))) + list_del(&fence->active_list); spin_unlock_irqrestore(fence->lock, flags);
sync_timeline_put(parent); - fence_free(&pt->base); + fence_free(fence); }
static bool android_fence_signaled(struct fence *fence) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence); int ret;
- ret = parent->ops->has_signaled(pt); + ret = parent->ops->has_signaled(fence); if (ret < 0) fence->status = ret; return ret; @@ -400,46 +391,42 @@ static bool android_fence_signaled(struct fence *fence)
static bool android_fence_enable_signaling(struct fence *fence) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
if (android_fence_signaled(fence)) return false;
- list_add_tail(&pt->active_list, &parent->active_list_head); + list_add_tail(&fence->active_list, &parent->active_list_head); return true; }
static int android_fence_fill_driver_data(struct fence *fence, void *data, int size) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
if (!parent->ops->fill_driver_data) return 0; - return parent->ops->fill_driver_data(pt, data, size); + return parent->ops->fill_driver_data(fence, data, size); }
static void android_fence_value_str(struct fence *fence, char *str, int size) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
- if (!parent->ops->pt_value_str) { + if (!parent->ops->fence_value_str) { if (size) *str = 0; return; } - parent->ops->pt_value_str(pt, str, size); + parent->ops->fence_value_str(fence, str, size); }
static void android_fence_timeline_value_str(struct fence *fence, char *str, int size) { - struct sync_pt *pt = container_of(fence, struct sync_pt, base); - struct sync_timeline *parent = sync_pt_parent(pt); + struct sync_timeline *parent = fence_parent(fence);
if (!parent->ops->timeline_value_str) { if (size) @@ -624,9 +611,9 @@ static long sync_file_ioctl_fence_info(struct sync_file *sync_file, len = sizeof(struct sync_file_info_data);
for (i = 0; i < sync_file->num_fences; ++i) { - struct fence *pt = sync_file->cbs[i].fence; + struct fence *fence = sync_file->cbs[i].fence;
- ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len); + ret = sync_fill_pt_info(fence, (u8 *)data + len, size - len);
if (ret < 0) goto out; diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index a18d1e3..8cdac1a 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -24,7 +24,6 @@ #include "uapi/sync.h"
struct sync_timeline; -struct sync_pt; struct sync_file;
/** @@ -39,23 +38,23 @@ struct sync_file; * as specified by size. This information is returned * to userspace by SYNC_IOC_FENCE_INFO. * @timeline_value_str: fill str with the value of the sync_timeline's counter - * @pt_value_str: fill str with the value of the sync_pt + * @fence_value_str: fill str with the value of the fence */ struct sync_timeline_ops { const char *driver_name;
/* required */ - int (*has_signaled)(struct sync_pt *pt); + int (*has_signaled)(struct fence *fence);
/* optional */ - int (*fill_driver_data)(struct sync_pt *syncpt, void *data, int size); + int (*fill_driver_data)(struct fence *fence, void *data, int size);
/* optional */ void (*timeline_value_str)(struct sync_timeline *timeline, char *str, int size);
/* optional */ - void (*pt_value_str)(struct sync_pt *pt, char *str, int size); + void (*fence_value_str)(struct fence *fence, char *str, int size); };
/** @@ -66,7 +65,7 @@ struct sync_timeline_ops { * @destroyed: set when sync_timeline is destroyed * @child_list_head: list of children sync_pts for this sync_timeline * @child_list_lock: lock protecting @child_list_head, destroyed, and - * sync_pt.status + * fence.status * @active_list_head: list of active (unsignaled/errored) sync_pts * @sync_timeline_list: membership in global sync_timeline_list */ @@ -89,22 +88,9 @@ struct sync_timeline { #endif };
-/** - * struct sync_pt - sync point - * @base: base fence class - * @child_list: membership in sync_timeline.child_list_head - * @active_list: membership in sync_timeline.active_list_head - */ -struct sync_pt { - struct fence base; - - struct list_head child_list; - struct list_head active_list; -}; - -static inline struct sync_timeline *sync_pt_parent(struct sync_pt *pt) +static inline struct sync_timeline *fence_parent(struct fence *fence) { - return container_of(pt->base.lock, struct sync_timeline, + return container_of(fence->lock, struct sync_timeline, child_list_lock); }
@@ -164,7 +150,7 @@ struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops, * * A sync implementation should call this when the @obj is going away * (i.e. module unload.) @obj won't actually be freed until all its children - * sync_pts are freed. + * fences are freed. */ void sync_timeline_destroy(struct sync_timeline *obj);
@@ -172,41 +158,32 @@ void sync_timeline_destroy(struct sync_timeline *obj); * sync_timeline_signal() - signal a status change on a sync_timeline * @obj: sync_timeline to signal * - * A sync implementation should call this any time one of it's sync_pts + * A sync implementation should call this any time one of it's fences * has signaled or has an error condition. */ void sync_timeline_signal(struct sync_timeline *obj);
/** * sync_pt_create() - creates a sync pt - * @parent: sync_pt's parent sync_timeline + * @parent: fence's parent sync_timeline * @size: size to allocate for this pt * - * Creates a new sync_pt as a child of @parent. @size bytes will be + * Creates a new fence as a child of @parent. @size bytes will be * allocated allowing for implementation specific data to be kept after - * the generic sync_timeline struct. Returns the sync_pt object or + * the generic sync_timeline struct. Returns the fence object or * NULL in case of error. */ -struct sync_pt *sync_pt_create(struct sync_timeline *parent, int size); +struct fence *sync_pt_create(struct sync_timeline *parent, int size);
/** - * sync_pt_free() - frees a sync pt - * @pt: sync_pt to free + * sync_fence_create() - creates a sync fence + * @name: name of fence to create + * @fence: fence to add to the sync_fence * - * This should only be called on sync_pts which have been created but - * not added to a fence. - */ -void sync_pt_free(struct sync_pt *pt); - -/** - * sync_file_create() - creates a sync file - * @name: name of file to create - * @pt: sync_pt to add to the file - * - * Creates a sync_file containg @pt. Once this is called, the sync_file takes - * ownership of @pt. + * Creates a sync_file containg @fence. Once this is called, the sync_file + * takes ownership of @fence. */ -struct sync_file *sync_file_create(const char *name, struct sync_pt *pt); +struct sync_file *sync_file_create(const char *name, struct fence *fence);
/** * sync_file_create_dma() - creates a sync file from dma-fence @@ -228,7 +205,7 @@ struct sync_file *sync_file_create_dma(const char *name, struct fence *pt); * @a: sync_file a * @b: sync_file b * - * Creates a new sync_file which contains copies of all the sync_pts in both + * Creates a new sync_file which contains copies of all the fences in both * @a and @b. @a and @b remain valid, independent sync_file. Returns the * new merged sync_file or NULL in case of error. */ diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c index 1889b5b..7e53da7 100644 --- a/drivers/staging/android/sync_debug.c +++ b/drivers/staging/android/sync_debug.c @@ -85,39 +85,40 @@ static const char *sync_status_str(int status) return "error"; }
-static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence) +static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show) { int status = 1; + struct sync_timeline *parent = fence_parent(fence);
- if (fence_is_signaled_locked(pt)) - status = pt->status; + if (fence_is_signaled_locked(fence)) + status = fence->status;
- seq_printf(s, " %s%spt %s", - fence && pt->ops->get_timeline_name ? - pt->ops->get_timeline_name(pt) : "", - fence ? "_" : "", + seq_printf(s, " %s%sfence %s", + show ? parent->name : "", + show ? "_" : "", sync_status_str(status));
if (status <= 0) { struct timespec64 ts64 = - ktime_to_timespec64(pt->timestamp); + ktime_to_timespec64(fence->timestamp);
seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec); }
- if ((!fence || pt->ops->timeline_value_str) && - pt->ops->fence_value_str) { + if ((!fence || fence->ops->timeline_value_str) && + fence->ops->fence_value_str) { char value[64]; bool success;
- pt->ops->fence_value_str(pt, value, sizeof(value)); + fence->ops->fence_value_str(fence, value, sizeof(value)); success = strlen(value);
if (success) seq_printf(s, ": %s", value);
if (success && fence) { - pt->ops->timeline_value_str(pt, value, sizeof(value)); + fence->ops->timeline_value_str(fence, value, + sizeof(value));
if (strlen(value)) seq_printf(s, " / %s", value); @@ -145,9 +146,9 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
spin_lock_irqsave(&obj->child_list_lock, flags); list_for_each(pos, &obj->child_list_head) { - struct sync_pt *pt = - container_of(pos, struct sync_pt, child_list); - sync_print_pt(s, &pt->base, false); + struct fence *fence = + container_of(pos, struct fence, child_list); + sync_print_fence(s, fence, false); } spin_unlock_irqrestore(&obj->child_list_lock, flags); } @@ -161,7 +162,7 @@ static void sync_print_sync_file(struct seq_file *s, sync_status_str(atomic_read(&sync_file->status)));
for (i = 0; i < sync_file->num_fences; ++i) { - sync_print_pt(s, sync_file->cbs[i].fence, true); + sync_print_fence(s, sync_file->cbs[i].fence, true); } }
@@ -245,7 +246,7 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, { int fd = get_unused_fd_flags(O_CLOEXEC); int err; - struct sync_pt *pt; + struct fence *fence; struct sync_file *sync_file; struct sw_sync_create_fence_data data;
@@ -257,16 +258,16 @@ static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj, goto err; }
- pt = sw_sync_pt_create(obj, data.value); - if (!pt) { + fence = sw_sync_pt_create(obj, data.value); + if (!fence) { err = -ENOMEM; goto err; }
data.name[sizeof(data.name) - 1] = '\0'; - sync_file = sync_file_create(data.name, pt); + sync_file = sync_file_create(data.name, fence); if (!sync_file) { - sync_pt_free(pt); + fence_put(fence); err = -ENOMEM; goto err; } diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h index 80f5da4..87c60e9 100644 --- a/drivers/staging/android/trace/sync.h +++ b/drivers/staging/android/trace/sync.h @@ -53,20 +53,20 @@ TRACE_EVENT(sync_wait, __get_str(name), __entry->status) );
-TRACE_EVENT(sync_pt, - TP_PROTO(struct fence *pt), +TRACE_EVENT(fence, + TP_PROTO(struct fence *fence),
- TP_ARGS(pt), + TP_ARGS(fence),
TP_STRUCT__entry( - __string(timeline, pt->ops->get_timeline_name(pt)) + __string(timeline, fence->ops->get_timeline_name(fence)) __array(char, value, 32) ),
TP_fast_assign( - __assign_str(timeline, pt->ops->get_timeline_name(pt)); - if (pt->ops->fence_value_str) { - pt->ops->fence_value_str(pt, __entry->value, + __assign_str(timeline, fence->ops->get_timeline_name(fence)); + if (fence->ops->fence_value_str) { + fence->ops->fence_value_str(fence, __entry->value, sizeof(__entry->value)); } else { __entry->value[0] = '\0'; diff --git a/include/linux/fence.h b/include/linux/fence.h index bb52201..605bd88 100644 --- a/include/linux/fence.h +++ b/include/linux/fence.h @@ -79,6 +79,8 @@ struct fence { unsigned long flags; ktime_t timestamp; int status; + struct list_head child_list; + struct list_head active_list; };
enum fence_flag_bits {
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
signaled_pts is not used in this function.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 1 - 1 file changed, 1 deletion(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 3c2c8d0..9ec55ef 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -101,7 +101,6 @@ EXPORT_SYMBOL(sync_timeline_destroy); void sync_timeline_signal(struct sync_timeline *obj) { unsigned long flags; - LIST_HEAD(signaled_pts); struct fence *fence, *next;
trace_sync_timeline(obj);
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
All changes to timeline value come through the user via sync_timeline_signal() calls. When sync_timeline_destroy() is called no changes on timeline->value happens hence call sync_timeline_signal() with no increment is pointless.
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index 9ec55ef..b9f167f 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -90,10 +90,6 @@ void sync_timeline_destroy(struct sync_timeline *obj) */ smp_wmb();
- /* - * signal any children that their parent is going away. - */ - sync_timeline_signal(obj); sync_timeline_put(obj); } EXPORT_SYMBOL(sync_timeline_destroy);
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
With the removal of struct sync_pt sync_fence_create_dma() now takes the same arguments as sync_fence_create() so let's keep only sync_fence_create().
Signed-off-by: Gustavo Padovan gustavo.padovan@collabora.co.uk --- drivers/staging/android/sync.c | 8 +------- drivers/staging/android/sync.h | 10 ---------- 2 files changed, 1 insertion(+), 17 deletions(-)
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index b9f167f..5fa4779 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -174,7 +174,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb) }
/* TODO: implement a create which takes more that one fence */ -struct sync_file *sync_file_create_dma(const char *name, struct fence *fence) +struct sync_file *sync_file_create(const char *name, struct fence *fence) { struct sync_file *sync_file;
@@ -196,12 +196,6 @@ struct sync_file *sync_file_create_dma(const char *name, struct fence *fence)
return sync_file; } -EXPORT_SYMBOL(sync_file_create_dma); - -struct sync_file *sync_file_create(const char *name, struct fence *fence) -{ - return sync_file_create_dma(name, fence); -} EXPORT_SYMBOL(sync_file_create);
struct sync_file *sync_file_fdget(int fd) diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h index 8cdac1a..8980b55 100644 --- a/drivers/staging/android/sync.h +++ b/drivers/staging/android/sync.h @@ -185,16 +185,6 @@ struct fence *sync_pt_create(struct sync_timeline *parent, int size); */ struct sync_file *sync_file_create(const char *name, struct fence *fence);
-/** - * sync_file_create_dma() - creates a sync file from dma-fence - * @name: name of file to create - * @pt: dma-fence to add to the file - * - * Creates a sync_file containg @pt. Once this is called, the fence takes - * ownership of @pt. - */ -struct sync_file *sync_file_create_dma(const char *name, struct fence *pt); - /* * API for sync_file consumers */
Hey,
Op 21-01-16 om 13:49 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Hi,
The following patches are some clean ups on the sync framework before we start the actual de-staging. The main changes here are the move of SW_SYNC_USER to debugfs. Removal of struct sync_pt in favor of direct use of struct fence. And the rename of sync_fence to sync_file, a name to better reflect what it is for, a struct that connects struct fence(s) to a file.
Please review. Thanks.
Gustavo Padovan (11): staging/android: fix sync framework documentation staging/android: sync: remove interfaces that are not used staging/android: remove not used sync_timeline ops staging/android: create a 'sync' dir for debugfs information staging/android: move SW_SYNC_USER to a debugfs file staging/android: rename sync_fence to sync_file staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb staging/android: remove struct sync_pt staging/android: remove unused var from sync_timeline_signal() staging/android: remove pointless sync_timeline_signal at destroy phase staging/android: remove sync_fence_create_dma()
For whole series: Reviewed-by: Maarten Lankhorst maarten.lankhorst@linux.intel.com
Renaming sync_fence to sync_file makes sense, it should hopefully reduce confusion.
Hi,
2016-01-25 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Hey,
Op 21-01-16 om 13:49 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Hi,
The following patches are some clean ups on the sync framework before we start the actual de-staging. The main changes here are the move of SW_SYNC_USER to debugfs. Removal of struct sync_pt in favor of direct use of struct fence. And the rename of sync_fence to sync_file, a name to better reflect what it is for, a struct that connects struct fence(s) to a file.
Please review. Thanks.
Gustavo Padovan (11): staging/android: fix sync framework documentation staging/android: sync: remove interfaces that are not used staging/android: remove not used sync_timeline ops staging/android: create a 'sync' dir for debugfs information staging/android: move SW_SYNC_USER to a debugfs file staging/android: rename sync_fence to sync_file staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb staging/android: remove struct sync_pt staging/android: remove unused var from sync_timeline_signal() staging/android: remove pointless sync_timeline_signal at destroy phase staging/android: remove sync_fence_create_dma()
For whole series: Reviewed-by: Maarten Lankhorst maarten.lankhorst@linux.intel.com
Renaming sync_fence to sync_file makes sense, it should hopefully reduce confusion.
Poke. What is missing for this to go upstream? Do I need more review here? Thanks.
Gustavo
On Fri, Jan 29, 2016 at 12:47:20PM -0200, Gustavo Padovan wrote:
Hi,
2016-01-25 Maarten Lankhorst maarten.lankhorst@linux.intel.com:
Hey,
Op 21-01-16 om 13:49 schreef Gustavo Padovan:
From: Gustavo Padovan gustavo.padovan@collabora.co.uk
Hi,
The following patches are some clean ups on the sync framework before we start the actual de-staging. The main changes here are the move of SW_SYNC_USER to debugfs. Removal of struct sync_pt in favor of direct use of struct fence. And the rename of sync_fence to sync_file, a name to better reflect what it is for, a struct that connects struct fence(s) to a file.
Please review. Thanks.
Gustavo Padovan (11): staging/android: fix sync framework documentation staging/android: sync: remove interfaces that are not used staging/android: remove not used sync_timeline ops staging/android: create a 'sync' dir for debugfs information staging/android: move SW_SYNC_USER to a debugfs file staging/android: rename sync_fence to sync_file staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb staging/android: remove struct sync_pt staging/android: remove unused var from sync_timeline_signal() staging/android: remove pointless sync_timeline_signal at destroy phase staging/android: remove sync_fence_create_dma()
For whole series: Reviewed-by: Maarten Lankhorst maarten.lankhorst@linux.intel.com
Renaming sync_fence to sync_file makes sense, it should hopefully reduce confusion.
Poke. What is missing for this to go upstream? Do I need more review here? Thanks.
You just sent this, give me a chance to get to it, my staging patch queue is over 1000 patches at the moment :(
greg k-h
dri-devel@lists.freedesktop.org