All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC 00/29] De-stage android's sync framework
@ 2016-01-15 14:55 Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                   ` (31 more replies)
  0 siblings, 32 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

This patch series de-stage the sync framework, and in order to accomplish that
a bunch of cleanups/improvements on the sync and fence were made.

The sync framework contained some abstractions around struct fence and those
were removed in the de-staging process among other changes:

Userspace visible changes
-------------------------

 * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
 other change.

Kernel API changes
------------------

 * struct sync_timeline is now struct fence_timeline
 * sync_timeline_ops is now fence_timeline_ops and they now carry struct
 fence as parameter instead of struct sync_pt
 * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
 the fence_timeline is destroyed
 * added fence_add_used_data() to pass a private point to struct fence. This
 pointer is sent back on the .cleanup op.
 * The sync timeline function were moved to be fence_timeline functions:
	 - sync_timeline_create()	-> fence_timeline_create()
	 - sync_timeline_get()		-> fence_timeline_get()
	 - sync_timeline_put()		-> fence_timeline_put()
	 - sync_timeline_destroy()	-> fence_timeline_destroy()
	 - sync_timeline_signal()	-> fence_timeline_signal()

  * sync_pt_create() was replaced be fence_create_on_timeline()

Internal changes
----------------

 * fence_timeline_ops was removed in favor of direct use fence_ops
 * fence default functions were created for fence_ops
 * removed structs sync_pt, sw_sync_timeline and sw_sync_pt

Gustavo Padovan (29):
  staging/android: fix sync framework documentation
  staging/android: fix checkpatch warning
  staging/android: rename sync_fence_release
  staging/android: rename 'android_fence' to 'sync_fence'
  staging/android: remove not used sync_timeline ops
  staging/android: create a 'sync' dir for debugfs information
  staging/android: move sw_sync file to debugfs file
  staging/android: Remove WARN_ON_ONCE when releasing sync_fence
  staging/android: rename struct sync_fence's variables to 'sync_fence'
  staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
  dma-buf/fence: move sync_timeline to fence_timeline
  staging/android: remove struct sync_pt
  dma-buf/fence: create fence_default_enable_signaling()
  dma-buf/fence: create fence_default_release()
  dma-buf/fence: create fence_default_get_driver_name()
  dma-buf/fence: create fence_default_timeline_name()
  dma-buf/fence: store last signaled value on fence timeline
  dma-buf/fence: create default .fence_value_str() and
    .timeline_value_str()
  dma-buf/fence: create fence_default_fill_driver_data()
  dma-buf/fence: remove fence_timeline_ops
  dma-buf/fence: add fence_create_on_timeline()
  staging/android: remove sync_pt_create()
  staging/android: remove sw_sync_timeline and sw_sync_pt
  dma-buf/fence: add debug to fence timeline
  dma-buf/fence: remove unused var from fence_timeline_signal()
  dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  dma-buf/fence: add .cleanup() callback
  staging/android: use .cleanup() to interrupt any sync_fence waiter
  dma-buf/fence: de-stage sync framework

 drivers/Kconfig                                    |   2 +
 drivers/dma-buf/Kconfig                            |  22 +
 drivers/dma-buf/Makefile                           |   4 +-
 drivers/dma-buf/fence.c                            | 333 ++++++++++
 drivers/dma-buf/fence_debug.c                      | 128 ++++
 drivers/dma-buf/sw_sync.c                          |  65 ++
 drivers/dma-buf/sync.c                             | 527 +++++++++++++++
 drivers/dma-buf/sync_debug.c                       | 279 ++++++++
 drivers/staging/android/Kconfig                    |  28 -
 drivers/staging/android/Makefile                   |   2 -
 drivers/staging/android/sw_sync.c                  | 260 --------
 drivers/staging/android/sync.c                     | 732 ---------------------
 drivers/staging/android/sync.h                     | 366 -----------
 drivers/staging/android/sync_debug.c               | 256 -------
 include/linux/fence.h                              |  77 +++
 .../staging/android => include/linux}/sw_sync.h    |  30 +-
 include/linux/sync.h                               | 201 ++++++
 include/trace/events/fence.h                       |  18 +
 .../android/trace => include/trace/events}/sync.h  |  41 +-
 .../android/uapi => include/uapi/linux}/sw_sync.h  |   0
 .../android/uapi => include/uapi/linux}/sync.h     |   0
 21 files changed, 1672 insertions(+), 1699 deletions(-)
 create mode 100644 drivers/dma-buf/Kconfig
 create mode 100644 drivers/dma-buf/fence_debug.c
 create mode 100644 drivers/dma-buf/sw_sync.c
 create mode 100644 drivers/dma-buf/sync.c
 create mode 100644 drivers/dma-buf/sync_debug.c
 delete mode 100644 drivers/staging/android/sw_sync.c
 delete mode 100644 drivers/staging/android/sync.c
 delete mode 100644 drivers/staging/android/sync.h
 delete mode 100644 drivers/staging/android/sync_debug.c
 rename {drivers/staging/android => include/linux}/sw_sync.h (55%)
 create mode 100644 include/linux/sync.h
 rename {drivers/staging/android/trace => include/trace/events}/sync.h (53%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sw_sync.h (100%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sync.h (100%)

-- 
2.5.0

^ permalink raw reply	[flat|nested] 94+ messages in thread

* [RFC 01/29] staging/android: fix sync framework documentation
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 01/29] staging/android: fix sync framework documentation
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, Rob Clark, daniels, Daniel Vetter, Riley Andrews,
	dri-devel, linux-kernel, Arve Hjønnevåg, Greg Hackmann,
	Maarten Lankhorst, Gustavo Padovan, John Harrison

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);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 02/29] staging/android: fix checkpatch warning
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Trivial indentation fix.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 7a4d820..f3d4f75 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -358,6 +358,6 @@ void sync_dump(void);
 # define sync_dump()
 #endif
 int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode,
-				 int wake_flags, void *key);
+			  int wake_flags, void *key);
 
 #endif /* _LINUX_SYNC_H */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 02/29] staging/android: fix checkpatch warning
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Trivial indentation fix.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 7a4d820..f3d4f75 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -358,6 +358,6 @@ void sync_dump(void);
 # define sync_dump()
 #endif
 int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode,
-				 int wake_flags, void *key);
+			  int wake_flags, void *key);
 
 #endif /* _LINUX_SYNC_H */
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 03/29] staging/android: rename sync_fence_release
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

To avoid collision with an upcoming rename change the name of
sync_fence_release() to sync_fence_release_file()

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index ed43796..4926bb0 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -534,7 +534,7 @@ static void sync_fence_free(struct kref *kref)
 	kfree(fence);
 }
 
-static int sync_fence_release(struct inode *inode, struct file *file)
+static int sync_fence_file_release(struct inode *inode, struct file *file)
 {
 	struct sync_fence *fence = file->private_data;
 
@@ -724,7 +724,7 @@ static long sync_fence_ioctl(struct file *file, unsigned int cmd,
 }
 
 static const struct file_operations sync_fence_fops = {
-	.release = sync_fence_release,
+	.release = sync_fence_file_release,
 	.poll = sync_fence_poll,
 	.unlocked_ioctl = sync_fence_ioctl,
 	.compat_ioctl = sync_fence_ioctl,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 03/29] staging/android: rename sync_fence_release
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

To avoid collision with an upcoming rename change the name of
sync_fence_release() to sync_fence_release_file()

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index ed43796..4926bb0 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -534,7 +534,7 @@ static void sync_fence_free(struct kref *kref)
 	kfree(fence);
 }
 
-static int sync_fence_release(struct inode *inode, struct file *file)
+static int sync_fence_file_release(struct inode *inode, struct file *file)
 {
 	struct sync_fence *fence = file->private_data;
 
@@ -724,7 +724,7 @@ static long sync_fence_ioctl(struct file *file, unsigned int cmd,
 }
 
 static const struct file_operations sync_fence_fops = {
-	.release = sync_fence_release,
+	.release = sync_fence_file_release,
 	.poll = sync_fence_poll,
 	.unlocked_ioctl = sync_fence_ioctl,
 	.compat_ioctl = sync_fence_ioctl,
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 04/29] staging/android: rename 'android_fence' to 'sync_fence'
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

As we are de-staging it rename it to a name that is not related to
android.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 4926bb0..fa756ef 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -31,7 +31,7 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops android_fence_ops;
+static const struct fence_ops sync_fence_ops;
 static const struct file_operations sync_fence_fops;
 
 struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
@@ -135,7 +135,7 @@ struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size)
 
 	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(&pt->base, &sync_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);
@@ -411,7 +411,7 @@ int sync_fence_wait(struct sync_fence *fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *android_fence_get_driver_name(struct fence *fence)
+static const char *sync_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);
@@ -419,7 +419,7 @@ static const char *android_fence_get_driver_name(struct fence *fence)
 	return parent->ops->driver_name;
 }
 
-static const char *android_fence_get_timeline_name(struct fence *fence)
+static const char *sync_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);
@@ -427,7 +427,7 @@ static const char *android_fence_get_timeline_name(struct fence *fence)
 	return parent->name;
 }
 
-static void android_fence_release(struct fence *fence)
+static void sync_fence_release(struct fence *fence)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
 	struct sync_timeline *parent = sync_pt_parent(pt);
@@ -446,7 +446,7 @@ static void android_fence_release(struct fence *fence)
 	fence_free(&pt->base);
 }
 
-static bool android_fence_signaled(struct fence *fence)
+static bool sync_fence_signaled(struct fence *fence)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
 	struct sync_timeline *parent = sync_pt_parent(pt);
@@ -458,19 +458,19 @@ static bool android_fence_signaled(struct fence *fence)
 	return ret;
 }
 
-static bool android_fence_enable_signaling(struct fence *fence)
+static bool sync_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);
 
-	if (android_fence_signaled(fence))
+	if (sync_fence_signaled(fence))
 		return false;
 
 	list_add_tail(&pt->active_list, &parent->active_list_head);
 	return true;
 }
 
-static int android_fence_fill_driver_data(struct fence *fence,
+static int sync_fence_fill_driver_data(struct fence *fence,
 					  void *data, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -481,7 +481,7 @@ static int android_fence_fill_driver_data(struct fence *fence,
 	return parent->ops->fill_driver_data(pt, data, size);
 }
 
-static void android_fence_value_str(struct fence *fence,
+static void sync_fence_value_str(struct fence *fence,
 				    char *str, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -495,7 +495,7 @@ static void android_fence_value_str(struct fence *fence,
 	parent->ops->pt_value_str(pt, str, size);
 }
 
-static void android_fence_timeline_value_str(struct fence *fence,
+static void sync_fence_timeline_value_str(struct fence *fence,
 					     char *str, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -509,16 +509,16 @@ static void android_fence_timeline_value_str(struct fence *fence,
 	parent->ops->timeline_value_str(parent, str, size);
 }
 
-static const struct fence_ops android_fence_ops = {
-	.get_driver_name = android_fence_get_driver_name,
-	.get_timeline_name = android_fence_get_timeline_name,
-	.enable_signaling = android_fence_enable_signaling,
-	.signaled = android_fence_signaled,
+static const struct fence_ops sync_fence_ops = {
+	.get_driver_name = sync_fence_get_driver_name,
+	.get_timeline_name = sync_fence_get_timeline_name,
+	.enable_signaling = sync_fence_enable_signaling,
+	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
-	.release = android_fence_release,
-	.fill_driver_data = android_fence_fill_driver_data,
-	.fence_value_str = android_fence_value_str,
-	.timeline_value_str = android_fence_timeline_value_str,
+	.release = sync_fence_release,
+	.fill_driver_data = sync_fence_fill_driver_data,
+	.fence_value_str = sync_fence_value_str,
+	.timeline_value_str = sync_fence_timeline_value_str,
 };
 
 static void sync_fence_free(struct kref *kref)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 04/29] staging/android: rename 'android_fence' to 'sync_fence'
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

As we are de-staging it rename it to a name that is not related to
android.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 4926bb0..fa756ef 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -31,7 +31,7 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-static const struct fence_ops android_fence_ops;
+static const struct fence_ops sync_fence_ops;
 static const struct file_operations sync_fence_fops;
 
 struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
@@ -135,7 +135,7 @@ struct sync_pt *sync_pt_create(struct sync_timeline *obj, int size)
 
 	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(&pt->base, &sync_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);
@@ -411,7 +411,7 @@ int sync_fence_wait(struct sync_fence *fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *android_fence_get_driver_name(struct fence *fence)
+static const char *sync_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);
@@ -419,7 +419,7 @@ static const char *android_fence_get_driver_name(struct fence *fence)
 	return parent->ops->driver_name;
 }
 
-static const char *android_fence_get_timeline_name(struct fence *fence)
+static const char *sync_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);
@@ -427,7 +427,7 @@ static const char *android_fence_get_timeline_name(struct fence *fence)
 	return parent->name;
 }
 
-static void android_fence_release(struct fence *fence)
+static void sync_fence_release(struct fence *fence)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
 	struct sync_timeline *parent = sync_pt_parent(pt);
@@ -446,7 +446,7 @@ static void android_fence_release(struct fence *fence)
 	fence_free(&pt->base);
 }
 
-static bool android_fence_signaled(struct fence *fence)
+static bool sync_fence_signaled(struct fence *fence)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
 	struct sync_timeline *parent = sync_pt_parent(pt);
@@ -458,19 +458,19 @@ static bool android_fence_signaled(struct fence *fence)
 	return ret;
 }
 
-static bool android_fence_enable_signaling(struct fence *fence)
+static bool sync_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);
 
-	if (android_fence_signaled(fence))
+	if (sync_fence_signaled(fence))
 		return false;
 
 	list_add_tail(&pt->active_list, &parent->active_list_head);
 	return true;
 }
 
-static int android_fence_fill_driver_data(struct fence *fence,
+static int sync_fence_fill_driver_data(struct fence *fence,
 					  void *data, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -481,7 +481,7 @@ static int android_fence_fill_driver_data(struct fence *fence,
 	return parent->ops->fill_driver_data(pt, data, size);
 }
 
-static void android_fence_value_str(struct fence *fence,
+static void sync_fence_value_str(struct fence *fence,
 				    char *str, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -495,7 +495,7 @@ static void android_fence_value_str(struct fence *fence,
 	parent->ops->pt_value_str(pt, str, size);
 }
 
-static void android_fence_timeline_value_str(struct fence *fence,
+static void sync_fence_timeline_value_str(struct fence *fence,
 					     char *str, int size)
 {
 	struct sync_pt *pt = container_of(fence, struct sync_pt, base);
@@ -509,16 +509,16 @@ static void android_fence_timeline_value_str(struct fence *fence,
 	parent->ops->timeline_value_str(parent, str, size);
 }
 
-static const struct fence_ops android_fence_ops = {
-	.get_driver_name = android_fence_get_driver_name,
-	.get_timeline_name = android_fence_get_timeline_name,
-	.enable_signaling = android_fence_enable_signaling,
-	.signaled = android_fence_signaled,
+static const struct fence_ops sync_fence_ops = {
+	.get_driver_name = sync_fence_get_driver_name,
+	.get_timeline_name = sync_fence_get_timeline_name,
+	.enable_signaling = sync_fence_enable_signaling,
+	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
-	.release = android_fence_release,
-	.fill_driver_data = android_fence_fill_driver_data,
-	.fence_value_str = android_fence_value_str,
-	.timeline_value_str = android_fence_timeline_value_str,
+	.release = sync_fence_release,
+	.fill_driver_data = sync_fence_fill_driver_data,
+	.fence_value_str = sync_fence_value_str,
+	.timeline_value_str = sync_fence_timeline_value_str,
 };
 
 static void sync_fence_free(struct kref *kref)
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 05/29] staging/android: remove not used sync_timeline ops
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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 fa756ef..5028847 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);
 }
 
@@ -439,9 +436,6 @@ static void sync_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 f3d4f75..ad45659 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);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 05/29] staging/android: remove not used sync_timeline ops
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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 fa756ef..5028847 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);
 }
 
@@ -439,9 +436,6 @@ static void sync_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 f3d4f75..ad45659 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);
 
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 06/29] staging/android: create a 'sync' dir for debugfs information
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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 f45d13c..86d683b 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);
@@ -208,13 +211,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,
@@ -222,11 +225,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)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 06/29] staging/android: create a 'sync' dir for debugfs information
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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 f45d13c..86d683b 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);
@@ -208,13 +211,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,
@@ -222,11 +225,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)
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 07/29] staging/android: move sw_sync file to debugfs file
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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 86d683b..0a2df3f 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
 
@@ -223,11 +223,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;
 }
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 07/29] staging/android: move sw_sync file to debugfs file
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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 86d683b..0a2df3f 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
 
@@ -223,11 +223,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;
 }
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 08/29] staging/android: Remove WARN_ON_ONCE when releasing sync_fence
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

There isn't any problem on removing the sync_pts from the active_list
when the fence is released. If the user decides to close the fence before
it is signaled we should do it and not warn about anything.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 5028847..273aa4b 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -432,8 +432,9 @@ static void sync_fence_release(struct fence *fence)
 
 	spin_lock_irqsave(fence->lock, flags);
 	list_del(&pt->child_list);
-	if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+	if (!list_empty(&pt->active_list))
 		list_del(&pt->active_list);
+
 	spin_unlock_irqrestore(fence->lock, flags);
 
 	sync_timeline_put(parent);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 08/29] staging/android: Remove WARN_ON_ONCE when releasing sync_fence
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

There isn't any problem on removing the sync_pts from the active_list
when the fence is released. If the user decides to close the fence before
it is signaled we should do it and not warn about anything.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 5028847..273aa4b 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -432,8 +432,9 @@ static void sync_fence_release(struct fence *fence)
 
 	spin_lock_irqsave(fence->lock, flags);
 	list_del(&pt->child_list);
-	if (WARN_ON_ONCE(!list_empty(&pt->active_list)))
+	if (!list_empty(&pt->active_list))
 		list_del(&pt->active_list);
+
 	spin_unlock_irqrestore(fence->lock, flags);
 
 	sync_timeline_put(parent);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 09/29] staging/android: rename struct sync_fence's variables to 'sync_fence'
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

To avoid confusion with struct fence vars that are most of the time called
'fence' as well we should rename all struct sync_fence's to sync_fence.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c       | 192 ++++++++++++++++++-----------------
 drivers/staging/android/sync.h       |   2 +-
 drivers/staging/android/sync_debug.c |  39 +++----
 3 files changed, 120 insertions(+), 113 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 273aa4b..c47b68d 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -149,61 +149,62 @@ EXPORT_SYMBOL(sync_pt_free);
 
 static struct sync_fence *sync_fence_alloc(int size, const char *name)
 {
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 
-	fence = kzalloc(size, GFP_KERNEL);
-	if (!fence)
+	sync_fence = kzalloc(size, GFP_KERNEL);
+	if (!sync_fence)
 		return NULL;
 
-	fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops,
-					 fence, 0);
-	if (IS_ERR(fence->file))
+	sync_fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops,
+					      sync_fence, 0);
+	if (IS_ERR(sync_fence->file))
 		goto err;
 
-	kref_init(&fence->kref);
-	strlcpy(fence->name, name, sizeof(fence->name));
+	kref_init(&sync_fence->kref);
+	strlcpy(sync_fence->name, name, sizeof(sync_fence->name));
 
-	init_waitqueue_head(&fence->wq);
+	init_waitqueue_head(&sync_fence->wq);
 
-	return fence;
+	return sync_fence;
 
 err:
-	kfree(fence);
+	kfree(sync_fence);
 	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_fence *sync_fence;
 
 	check = container_of(cb, struct sync_fence_cb, cb);
-	fence = check->fence;
+	sync_fence = check->sync_fence;
 
-	if (atomic_dec_and_test(&fence->status))
-		wake_up_all(&fence->wq);
+	if (atomic_dec_and_test(&sync_fence->status))
+		wake_up_all(&sync_fence->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_fence *fence;
+	struct sync_fence *sync_fence;
 
-	fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]), name);
-	if (!fence)
+	sync_fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]),
+				      name);
+	if (!sync_fence)
 		return NULL;
 
-	fence->num_fences = 1;
-	atomic_set(&fence->status, 1);
+	sync_fence->num_fences = 1;
+	atomic_set(&sync_fence->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_fence->cbs[0].sync_pt = pt;
+	sync_fence->cbs[0].sync_fence = sync_fence;
+	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
+		atomic_dec(&sync_fence->status);
 
-	sync_fence_debug_add(fence);
+	sync_fence_debug_add(sync_fence);
 
-	return fence;
+	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
 
@@ -231,25 +232,26 @@ err:
 }
 EXPORT_SYMBOL(sync_fence_fdget);
 
-void sync_fence_put(struct sync_fence *fence)
+void sync_fence_put(struct sync_fence *sync_fence)
 {
-	fput(fence->file);
+	fput(sync_fence->file);
 }
 EXPORT_SYMBOL(sync_fence_put);
 
-void sync_fence_install(struct sync_fence *fence, int fd)
+void sync_fence_install(struct sync_fence *sync_fence, int fd)
 {
-	fd_install(fd, fence->file);
+	fd_install(fd, sync_fence->file);
 }
 EXPORT_SYMBOL(sync_fence_install);
 
-static void sync_fence_add_pt(struct sync_fence *fence,
+static void sync_fence_add_pt(struct sync_fence *sync_fence,
 			      int *i, struct fence *pt)
 {
-	fence->cbs[*i].sync_pt = pt;
-	fence->cbs[*i].fence = fence;
+	sync_fence->cbs[*i].sync_pt = pt;
+	sync_fence->cbs[*i].sync_fence = sync_fence;
 
-	if (!fence_add_callback(pt, &fence->cbs[*i].cb, fence_check_cb_func)) {
+	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
+				fence_check_cb_func)) {
 		fence_get(pt);
 		(*i)++;
 	}
@@ -259,15 +261,15 @@ struct sync_fence *sync_fence_merge(const char *name,
 				    struct sync_fence *a, struct sync_fence *b)
 {
 	int num_fences = a->num_fences + b->num_fences;
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 	int i, i_a, i_b;
 	unsigned long size = offsetof(struct sync_fence, cbs[num_fences]);
 
-	fence = sync_fence_alloc(size, name);
-	if (!fence)
+	sync_fence = sync_fence_alloc(size, name);
+	if (!sync_fence)
 		return NULL;
 
-	atomic_set(&fence->status, num_fences);
+	atomic_set(&sync_fence->status, num_fences);
 
 	/*
 	 * Assume sync_fence a and b are both ordered and have no
@@ -281,18 +283,18 @@ struct sync_fence *sync_fence_merge(const char *name,
 		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_fence_add_pt(sync_fence, &i, pt_a);
 
 			i_a++;
 		} else if (pt_a->context > pt_b->context) {
-			sync_fence_add_pt(fence, &i, pt_b);
+			sync_fence_add_pt(sync_fence, &i, pt_b);
 
 			i_b++;
 		} else {
 			if (pt_a->seqno - pt_b->seqno <= INT_MAX)
-				sync_fence_add_pt(fence, &i, pt_a);
+				sync_fence_add_pt(sync_fence, &i, pt_a);
 			else
-				sync_fence_add_pt(fence, &i, pt_b);
+				sync_fence_add_pt(sync_fence, &i, pt_b);
 
 			i_a++;
 			i_b++;
@@ -300,17 +302,17 @@ 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_fence_add_pt(sync_fence, &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_fence_add_pt(sync_fence, &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_fence->status);
+	sync_fence->num_fences = i;
 
-	sync_fence_debug_add(fence);
-	return fence;
+	sync_fence_debug_add(sync_fence);
+	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_merge);
 
@@ -326,10 +328,10 @@ int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode,
 	return 1;
 }
 
-int sync_fence_wait_async(struct sync_fence *fence,
+int sync_fence_wait_async(struct sync_fence *sync_fence,
 			  struct sync_fence_waiter *waiter)
 {
-	int err = atomic_read(&fence->status);
+	int err = atomic_read(&sync_fence->status);
 	unsigned long flags;
 
 	if (err < 0)
@@ -339,13 +341,13 @@ int sync_fence_wait_async(struct sync_fence *fence,
 		return 1;
 
 	init_waitqueue_func_entry(&waiter->work, sync_fence_wake_up_wq);
-	waiter->work.private = fence;
+	waiter->work.private = sync_fence;
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
-	err = atomic_read(&fence->status);
+	spin_lock_irqsave(&sync_fence->wq.lock, flags);
+	err = atomic_read(&sync_fence->status);
 	if (err > 0)
-		__add_wait_queue_tail(&fence->wq, &waiter->work);
-	spin_unlock_irqrestore(&fence->wq.lock, flags);
+		__add_wait_queue_tail(&sync_fence->wq, &waiter->work);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 
 	if (err < 0)
 		return err;
@@ -354,23 +356,23 @@ int sync_fence_wait_async(struct sync_fence *fence,
 }
 EXPORT_SYMBOL(sync_fence_wait_async);
 
-int sync_fence_cancel_async(struct sync_fence *fence,
+int sync_fence_cancel_async(struct sync_fence *sync_fence,
 			    struct sync_fence_waiter *waiter)
 {
 	unsigned long flags;
 	int ret = 0;
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
+	spin_lock_irqsave(&sync_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);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 	return ret;
 }
 EXPORT_SYMBOL(sync_fence_cancel_async);
 
-int sync_fence_wait(struct sync_fence *fence, long timeout)
+int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 {
 	long ret;
 	int i;
@@ -380,28 +382,28 @@ 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_fence, 1);
+	for (i = 0; i < sync_fence->num_fences; ++i)
+		trace_sync_pt(sync_fence->cbs[i].sync_pt);
+	ret = wait_event_interruptible_timeout(sync_fence->wq,
+					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
-	trace_sync_wait(fence, 0);
+	trace_sync_wait(sync_fence, 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_fence timeout on [%p] after %dms\n",
+				sync_fence, jiffies_to_msecs(timeout));
 			sync_dump();
 		}
 		return -ETIME;
 	}
 
-	ret = atomic_read(&fence->status);
+	ret = atomic_read(&sync_fence->status);
 	if (ret) {
-		pr_info("fence error %ld on [%p]\n", ret, fence);
+		pr_info("sync_fence error %ld on [%p]\n", ret, sync_fence);
 		sync_dump();
 	}
 	return ret;
@@ -518,35 +520,37 @@ static const struct fence_ops sync_fence_ops = {
 
 static void sync_fence_free(struct kref *kref)
 {
-	struct sync_fence *fence = container_of(kref, struct sync_fence, kref);
+	struct sync_fence *sync_fence = container_of(kref, struct sync_fence,
+						     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_fence->num_fences; ++i) {
+		fence_remove_callback(sync_fence->cbs[i].sync_pt,
+				      &sync_fence->cbs[i].cb);
+		fence_put(sync_fence->cbs[i].sync_pt);
 	}
 
-	kfree(fence);
+	kfree(sync_fence);
 }
 
 static int sync_fence_file_release(struct inode *inode, struct file *file)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 
-	sync_fence_debug_remove(fence);
+	sync_fence_debug_remove(sync_fence);
 
-	kref_put(&fence->kref, sync_fence_free);
+	kref_put(&sync_fence->kref, sync_fence_free);
 	return 0;
 }
 
 static unsigned int sync_fence_poll(struct file *file, poll_table *wait)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 	int status;
 
-	poll_wait(file, &fence->wq, wait);
+	poll_wait(file, &sync_fence->wq, wait);
 
-	status = atomic_read(&fence->status);
+	status = atomic_read(&sync_fence->status);
 
 	if (!status)
 		return POLLIN;
@@ -555,17 +559,19 @@ 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_fence_ioctl_wait(struct sync_fence *sync_fence,
+				  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_fence_wait(sync_fence, value);
 }
 
-static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
+static long sync_fence_ioctl_merge(struct sync_fence *sync_fence,
+				   unsigned long arg)
 {
 	int fd = get_unused_fd_flags(O_CLOEXEC);
 	int err;
@@ -587,7 +593,7 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
 	}
 
 	data.name[sizeof(data.name) - 1] = '\0';
-	fence3 = sync_fence_merge(data.name, fence, fence2);
+	fence3 = sync_fence_merge(data.name, sync_fence, fence2);
 	if (!fence3) {
 		err = -ENOMEM;
 		goto err_put_fence2;
@@ -646,7 +652,7 @@ 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_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 					unsigned long arg)
 {
 	struct sync_fence_info_data *data;
@@ -667,15 +673,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_fence->name, sizeof(data->name));
+	data->status = atomic_read(&sync_fence->status);
 	if (data->status >= 0)
 		data->status = !data->status;
 
 	len = sizeof(struct sync_fence_info_data);
 
-	for (i = 0; i < fence->num_fences; ++i) {
-		struct fence *pt = fence->cbs[i].sync_pt;
+	for (i = 0; i < sync_fence->num_fences; ++i) {
+		struct fence *pt = sync_fence->cbs[i].sync_pt;
 
 		ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len);
 
@@ -701,17 +707,17 @@ out:
 static long sync_fence_ioctl(struct file *file, unsigned int cmd,
 			     unsigned long arg)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 
 	switch (cmd) {
 	case SYNC_IOC_WAIT:
-		return sync_fence_ioctl_wait(fence, arg);
+		return sync_fence_ioctl_wait(sync_fence, arg);
 
 	case SYNC_IOC_MERGE:
-		return sync_fence_ioctl_merge(fence, arg);
+		return sync_fence_ioctl_merge(sync_fence, arg);
 
 	case SYNC_IOC_FENCE_INFO:
-		return sync_fence_ioctl_fence_info(fence, arg);
+		return sync_fence_ioctl_fence_info(sync_fence, arg);
 
 	default:
 		return -ENOTTY;
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index ad45659..0fed642 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -111,7 +111,7 @@ static inline struct sync_timeline *sync_pt_parent(struct sync_pt *pt)
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *sync_pt;
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 };
 
 /**
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 0a2df3f..cfa92d2 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -56,21 +56,21 @@ 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_fence_debug_add(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
-	list_add_tail(&fence->sync_fence_list, &sync_fence_list_head);
+	list_add_tail(&sync_fence->sync_fence_list, &sync_fence_list_head);
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
-void sync_fence_debug_remove(struct sync_fence *fence)
+void sync_fence_debug_remove(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
-	list_del(&fence->sync_fence_list);
+	list_del(&sync_fence->sync_fence_list);
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
@@ -152,21 +152,22 @@ 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_fence(struct seq_file *s,
+				  struct sync_fence *sync_fence)
 {
 	wait_queue_t *pos;
 	unsigned long flags;
 	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_fence, sync_fence->name,
+		   sync_status_str(atomic_read(&sync_fence->status)));
 
-	for (i = 0; i < fence->num_fences; ++i) {
-		sync_print_pt(s, fence->cbs[i].sync_pt, true);
+	for (i = 0; i < sync_fence->num_fences; ++i) {
+		sync_print_pt(s, sync_fence->cbs[i].sync_pt, true);
 	}
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
-	list_for_each_entry(pos, &fence->wq.task_list, task_list) {
+	spin_lock_irqsave(&sync_fence->wq.lock, flags);
+	list_for_each_entry(pos, &sync_fence->wq.task_list, task_list) {
 		struct sync_fence_waiter *waiter;
 
 		if (pos->func != &sync_fence_wake_up_wq)
@@ -176,7 +177,7 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence)
 
 		seq_printf(s, "waiter %pF\n", waiter->callback);
 	}
-	spin_unlock_irqrestore(&fence->wq.lock, flags);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 }
 
 static int sync_debugfs_show(struct seq_file *s, void *unused)
@@ -201,10 +202,10 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
 	list_for_each(pos, &sync_fence_list_head) {
-		struct sync_fence *fence =
+		struct sync_fence *sync_fence =
 			container_of(pos, struct sync_fence, sync_fence_list);
 
-		sync_print_fence(s, fence);
+		sync_print_sync_fence(s, sync_fence);
 		seq_puts(s, "\n");
 	}
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
@@ -260,7 +261,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_fence *sync_fence;
 	struct sw_sync_create_fence_data data;
 
 	if (fd < 0)
@@ -278,8 +279,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_fence = sync_fence_create(data.name, pt);
+	if (!sync_fence) {
 		sync_pt_free(pt);
 		err = -ENOMEM;
 		goto err;
@@ -287,12 +288,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_fence_put(sync_fence);
 		err = -EFAULT;
 		goto err;
 	}
 
-	sync_fence_install(fence, fd);
+	sync_fence_install(sync_fence, fd);
 
 	return 0;
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 09/29] staging/android: rename struct sync_fence's variables to 'sync_fence'
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

To avoid confusion with struct fence vars that are most of the time called
'fence' as well we should rename all struct sync_fence's to sync_fence.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sync.c       | 192 ++++++++++++++++++-----------------
 drivers/staging/android/sync.h       |   2 +-
 drivers/staging/android/sync_debug.c |  39 +++----
 3 files changed, 120 insertions(+), 113 deletions(-)

diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 273aa4b..c47b68d 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -149,61 +149,62 @@ EXPORT_SYMBOL(sync_pt_free);
 
 static struct sync_fence *sync_fence_alloc(int size, const char *name)
 {
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 
-	fence = kzalloc(size, GFP_KERNEL);
-	if (!fence)
+	sync_fence = kzalloc(size, GFP_KERNEL);
+	if (!sync_fence)
 		return NULL;
 
-	fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops,
-					 fence, 0);
-	if (IS_ERR(fence->file))
+	sync_fence->file = anon_inode_getfile("sync_fence", &sync_fence_fops,
+					      sync_fence, 0);
+	if (IS_ERR(sync_fence->file))
 		goto err;
 
-	kref_init(&fence->kref);
-	strlcpy(fence->name, name, sizeof(fence->name));
+	kref_init(&sync_fence->kref);
+	strlcpy(sync_fence->name, name, sizeof(sync_fence->name));
 
-	init_waitqueue_head(&fence->wq);
+	init_waitqueue_head(&sync_fence->wq);
 
-	return fence;
+	return sync_fence;
 
 err:
-	kfree(fence);
+	kfree(sync_fence);
 	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_fence *sync_fence;
 
 	check = container_of(cb, struct sync_fence_cb, cb);
-	fence = check->fence;
+	sync_fence = check->sync_fence;
 
-	if (atomic_dec_and_test(&fence->status))
-		wake_up_all(&fence->wq);
+	if (atomic_dec_and_test(&sync_fence->status))
+		wake_up_all(&sync_fence->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_fence *fence;
+	struct sync_fence *sync_fence;
 
-	fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]), name);
-	if (!fence)
+	sync_fence = sync_fence_alloc(offsetof(struct sync_fence, cbs[1]),
+				      name);
+	if (!sync_fence)
 		return NULL;
 
-	fence->num_fences = 1;
-	atomic_set(&fence->status, 1);
+	sync_fence->num_fences = 1;
+	atomic_set(&sync_fence->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_fence->cbs[0].sync_pt = pt;
+	sync_fence->cbs[0].sync_fence = sync_fence;
+	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
+		atomic_dec(&sync_fence->status);
 
-	sync_fence_debug_add(fence);
+	sync_fence_debug_add(sync_fence);
 
-	return fence;
+	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
 
@@ -231,25 +232,26 @@ err:
 }
 EXPORT_SYMBOL(sync_fence_fdget);
 
-void sync_fence_put(struct sync_fence *fence)
+void sync_fence_put(struct sync_fence *sync_fence)
 {
-	fput(fence->file);
+	fput(sync_fence->file);
 }
 EXPORT_SYMBOL(sync_fence_put);
 
-void sync_fence_install(struct sync_fence *fence, int fd)
+void sync_fence_install(struct sync_fence *sync_fence, int fd)
 {
-	fd_install(fd, fence->file);
+	fd_install(fd, sync_fence->file);
 }
 EXPORT_SYMBOL(sync_fence_install);
 
-static void sync_fence_add_pt(struct sync_fence *fence,
+static void sync_fence_add_pt(struct sync_fence *sync_fence,
 			      int *i, struct fence *pt)
 {
-	fence->cbs[*i].sync_pt = pt;
-	fence->cbs[*i].fence = fence;
+	sync_fence->cbs[*i].sync_pt = pt;
+	sync_fence->cbs[*i].sync_fence = sync_fence;
 
-	if (!fence_add_callback(pt, &fence->cbs[*i].cb, fence_check_cb_func)) {
+	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
+				fence_check_cb_func)) {
 		fence_get(pt);
 		(*i)++;
 	}
@@ -259,15 +261,15 @@ struct sync_fence *sync_fence_merge(const char *name,
 				    struct sync_fence *a, struct sync_fence *b)
 {
 	int num_fences = a->num_fences + b->num_fences;
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 	int i, i_a, i_b;
 	unsigned long size = offsetof(struct sync_fence, cbs[num_fences]);
 
-	fence = sync_fence_alloc(size, name);
-	if (!fence)
+	sync_fence = sync_fence_alloc(size, name);
+	if (!sync_fence)
 		return NULL;
 
-	atomic_set(&fence->status, num_fences);
+	atomic_set(&sync_fence->status, num_fences);
 
 	/*
 	 * Assume sync_fence a and b are both ordered and have no
@@ -281,18 +283,18 @@ struct sync_fence *sync_fence_merge(const char *name,
 		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_fence_add_pt(sync_fence, &i, pt_a);
 
 			i_a++;
 		} else if (pt_a->context > pt_b->context) {
-			sync_fence_add_pt(fence, &i, pt_b);
+			sync_fence_add_pt(sync_fence, &i, pt_b);
 
 			i_b++;
 		} else {
 			if (pt_a->seqno - pt_b->seqno <= INT_MAX)
-				sync_fence_add_pt(fence, &i, pt_a);
+				sync_fence_add_pt(sync_fence, &i, pt_a);
 			else
-				sync_fence_add_pt(fence, &i, pt_b);
+				sync_fence_add_pt(sync_fence, &i, pt_b);
 
 			i_a++;
 			i_b++;
@@ -300,17 +302,17 @@ 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_fence_add_pt(sync_fence, &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_fence_add_pt(sync_fence, &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_fence->status);
+	sync_fence->num_fences = i;
 
-	sync_fence_debug_add(fence);
-	return fence;
+	sync_fence_debug_add(sync_fence);
+	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_merge);
 
@@ -326,10 +328,10 @@ int sync_fence_wake_up_wq(wait_queue_t *curr, unsigned mode,
 	return 1;
 }
 
-int sync_fence_wait_async(struct sync_fence *fence,
+int sync_fence_wait_async(struct sync_fence *sync_fence,
 			  struct sync_fence_waiter *waiter)
 {
-	int err = atomic_read(&fence->status);
+	int err = atomic_read(&sync_fence->status);
 	unsigned long flags;
 
 	if (err < 0)
@@ -339,13 +341,13 @@ int sync_fence_wait_async(struct sync_fence *fence,
 		return 1;
 
 	init_waitqueue_func_entry(&waiter->work, sync_fence_wake_up_wq);
-	waiter->work.private = fence;
+	waiter->work.private = sync_fence;
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
-	err = atomic_read(&fence->status);
+	spin_lock_irqsave(&sync_fence->wq.lock, flags);
+	err = atomic_read(&sync_fence->status);
 	if (err > 0)
-		__add_wait_queue_tail(&fence->wq, &waiter->work);
-	spin_unlock_irqrestore(&fence->wq.lock, flags);
+		__add_wait_queue_tail(&sync_fence->wq, &waiter->work);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 
 	if (err < 0)
 		return err;
@@ -354,23 +356,23 @@ int sync_fence_wait_async(struct sync_fence *fence,
 }
 EXPORT_SYMBOL(sync_fence_wait_async);
 
-int sync_fence_cancel_async(struct sync_fence *fence,
+int sync_fence_cancel_async(struct sync_fence *sync_fence,
 			    struct sync_fence_waiter *waiter)
 {
 	unsigned long flags;
 	int ret = 0;
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
+	spin_lock_irqsave(&sync_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);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 	return ret;
 }
 EXPORT_SYMBOL(sync_fence_cancel_async);
 
-int sync_fence_wait(struct sync_fence *fence, long timeout)
+int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 {
 	long ret;
 	int i;
@@ -380,28 +382,28 @@ 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_fence, 1);
+	for (i = 0; i < sync_fence->num_fences; ++i)
+		trace_sync_pt(sync_fence->cbs[i].sync_pt);
+	ret = wait_event_interruptible_timeout(sync_fence->wq,
+					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
-	trace_sync_wait(fence, 0);
+	trace_sync_wait(sync_fence, 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_fence timeout on [%p] after %dms\n",
+				sync_fence, jiffies_to_msecs(timeout));
 			sync_dump();
 		}
 		return -ETIME;
 	}
 
-	ret = atomic_read(&fence->status);
+	ret = atomic_read(&sync_fence->status);
 	if (ret) {
-		pr_info("fence error %ld on [%p]\n", ret, fence);
+		pr_info("sync_fence error %ld on [%p]\n", ret, sync_fence);
 		sync_dump();
 	}
 	return ret;
@@ -518,35 +520,37 @@ static const struct fence_ops sync_fence_ops = {
 
 static void sync_fence_free(struct kref *kref)
 {
-	struct sync_fence *fence = container_of(kref, struct sync_fence, kref);
+	struct sync_fence *sync_fence = container_of(kref, struct sync_fence,
+						     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_fence->num_fences; ++i) {
+		fence_remove_callback(sync_fence->cbs[i].sync_pt,
+				      &sync_fence->cbs[i].cb);
+		fence_put(sync_fence->cbs[i].sync_pt);
 	}
 
-	kfree(fence);
+	kfree(sync_fence);
 }
 
 static int sync_fence_file_release(struct inode *inode, struct file *file)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 
-	sync_fence_debug_remove(fence);
+	sync_fence_debug_remove(sync_fence);
 
-	kref_put(&fence->kref, sync_fence_free);
+	kref_put(&sync_fence->kref, sync_fence_free);
 	return 0;
 }
 
 static unsigned int sync_fence_poll(struct file *file, poll_table *wait)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 	int status;
 
-	poll_wait(file, &fence->wq, wait);
+	poll_wait(file, &sync_fence->wq, wait);
 
-	status = atomic_read(&fence->status);
+	status = atomic_read(&sync_fence->status);
 
 	if (!status)
 		return POLLIN;
@@ -555,17 +559,19 @@ 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_fence_ioctl_wait(struct sync_fence *sync_fence,
+				  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_fence_wait(sync_fence, value);
 }
 
-static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
+static long sync_fence_ioctl_merge(struct sync_fence *sync_fence,
+				   unsigned long arg)
 {
 	int fd = get_unused_fd_flags(O_CLOEXEC);
 	int err;
@@ -587,7 +593,7 @@ static long sync_fence_ioctl_merge(struct sync_fence *fence, unsigned long arg)
 	}
 
 	data.name[sizeof(data.name) - 1] = '\0';
-	fence3 = sync_fence_merge(data.name, fence, fence2);
+	fence3 = sync_fence_merge(data.name, sync_fence, fence2);
 	if (!fence3) {
 		err = -ENOMEM;
 		goto err_put_fence2;
@@ -646,7 +652,7 @@ 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_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 					unsigned long arg)
 {
 	struct sync_fence_info_data *data;
@@ -667,15 +673,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_fence->name, sizeof(data->name));
+	data->status = atomic_read(&sync_fence->status);
 	if (data->status >= 0)
 		data->status = !data->status;
 
 	len = sizeof(struct sync_fence_info_data);
 
-	for (i = 0; i < fence->num_fences; ++i) {
-		struct fence *pt = fence->cbs[i].sync_pt;
+	for (i = 0; i < sync_fence->num_fences; ++i) {
+		struct fence *pt = sync_fence->cbs[i].sync_pt;
 
 		ret = sync_fill_pt_info(pt, (u8 *)data + len, size - len);
 
@@ -701,17 +707,17 @@ out:
 static long sync_fence_ioctl(struct file *file, unsigned int cmd,
 			     unsigned long arg)
 {
-	struct sync_fence *fence = file->private_data;
+	struct sync_fence *sync_fence = file->private_data;
 
 	switch (cmd) {
 	case SYNC_IOC_WAIT:
-		return sync_fence_ioctl_wait(fence, arg);
+		return sync_fence_ioctl_wait(sync_fence, arg);
 
 	case SYNC_IOC_MERGE:
-		return sync_fence_ioctl_merge(fence, arg);
+		return sync_fence_ioctl_merge(sync_fence, arg);
 
 	case SYNC_IOC_FENCE_INFO:
-		return sync_fence_ioctl_fence_info(fence, arg);
+		return sync_fence_ioctl_fence_info(sync_fence, arg);
 
 	default:
 		return -ENOTTY;
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index ad45659..0fed642 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -111,7 +111,7 @@ static inline struct sync_timeline *sync_pt_parent(struct sync_pt *pt)
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *sync_pt;
-	struct sync_fence *fence;
+	struct sync_fence *sync_fence;
 };
 
 /**
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 0a2df3f..cfa92d2 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -56,21 +56,21 @@ 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_fence_debug_add(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
-	list_add_tail(&fence->sync_fence_list, &sync_fence_list_head);
+	list_add_tail(&sync_fence->sync_fence_list, &sync_fence_list_head);
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
-void sync_fence_debug_remove(struct sync_fence *fence)
+void sync_fence_debug_remove(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
-	list_del(&fence->sync_fence_list);
+	list_del(&sync_fence->sync_fence_list);
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
@@ -152,21 +152,22 @@ 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_fence(struct seq_file *s,
+				  struct sync_fence *sync_fence)
 {
 	wait_queue_t *pos;
 	unsigned long flags;
 	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_fence, sync_fence->name,
+		   sync_status_str(atomic_read(&sync_fence->status)));
 
-	for (i = 0; i < fence->num_fences; ++i) {
-		sync_print_pt(s, fence->cbs[i].sync_pt, true);
+	for (i = 0; i < sync_fence->num_fences; ++i) {
+		sync_print_pt(s, sync_fence->cbs[i].sync_pt, true);
 	}
 
-	spin_lock_irqsave(&fence->wq.lock, flags);
-	list_for_each_entry(pos, &fence->wq.task_list, task_list) {
+	spin_lock_irqsave(&sync_fence->wq.lock, flags);
+	list_for_each_entry(pos, &sync_fence->wq.task_list, task_list) {
 		struct sync_fence_waiter *waiter;
 
 		if (pos->func != &sync_fence_wake_up_wq)
@@ -176,7 +177,7 @@ static void sync_print_fence(struct seq_file *s, struct sync_fence *fence)
 
 		seq_printf(s, "waiter %pF\n", waiter->callback);
 	}
-	spin_unlock_irqrestore(&fence->wq.lock, flags);
+	spin_unlock_irqrestore(&sync_fence->wq.lock, flags);
 }
 
 static int sync_debugfs_show(struct seq_file *s, void *unused)
@@ -201,10 +202,10 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	spin_lock_irqsave(&sync_fence_list_lock, flags);
 	list_for_each(pos, &sync_fence_list_head) {
-		struct sync_fence *fence =
+		struct sync_fence *sync_fence =
 			container_of(pos, struct sync_fence, sync_fence_list);
 
-		sync_print_fence(s, fence);
+		sync_print_sync_fence(s, sync_fence);
 		seq_puts(s, "\n");
 	}
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
@@ -260,7 +261,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_fence *sync_fence;
 	struct sw_sync_create_fence_data data;
 
 	if (fd < 0)
@@ -278,8 +279,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_fence = sync_fence_create(data.name, pt);
+	if (!sync_fence) {
 		sync_pt_free(pt);
 		err = -ENOMEM;
 		goto err;
@@ -287,12 +288,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_fence_put(sync_fence);
 		err = -EFAULT;
 		goto err;
 	}
 
-	sync_fence_install(fence, fd);
+	sync_fence_install(sync_fence, fd);
 
 	return 0;
 
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 10/29] staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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 c47b68d..decff9e 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -197,7 +197,7 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 	sync_fence->num_fences = 1;
 	atomic_set(&sync_fence->status, 1);
 
-	sync_fence->cbs[0].sync_pt = pt;
+	sync_fence->cbs[0].fence = pt;
 	sync_fence->cbs[0].sync_fence = sync_fence;
 	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
 		atomic_dec(&sync_fence->status);
@@ -247,7 +247,7 @@ EXPORT_SYMBOL(sync_fence_install);
 static void sync_fence_add_pt(struct sync_fence *sync_fence,
 			      int *i, struct fence *pt)
 {
-	sync_fence->cbs[*i].sync_pt = pt;
+	sync_fence->cbs[*i].fence = pt;
 	sync_fence->cbs[*i].sync_fence = sync_fence;
 
 	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
@@ -279,8 +279,8 @@ struct sync_fence *sync_fence_merge(const char *name,
 	 * and sync_fence_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_fence_add_pt(sync_fence, &i, pt_a);
@@ -302,10 +302,10 @@ struct sync_fence *sync_fence_merge(const char *name,
 	}
 
 	for (; i_a < a->num_fences; i_a++)
-		sync_fence_add_pt(sync_fence, &i, a->cbs[i_a].sync_pt);
+		sync_fence_add_pt(sync_fence, &i, a->cbs[i_a].fence);
 
 	for (; i_b < b->num_fences; i_b++)
-		sync_fence_add_pt(sync_fence, &i, b->cbs[i_b].sync_pt);
+		sync_fence_add_pt(sync_fence, &i, b->cbs[i_b].fence);
 
 	if (num_fences > i)
 		atomic_sub(num_fences - i, &sync_fence->status);
@@ -384,7 +384,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_sync_pt(sync_fence->cbs[i].sync_pt);
+		trace_sync_pt(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -525,9 +525,9 @@ static void sync_fence_free(struct kref *kref)
 	int i;
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		fence_remove_callback(sync_fence->cbs[i].sync_pt,
+		fence_remove_callback(sync_fence->cbs[i].fence,
 				      &sync_fence->cbs[i].cb);
-		fence_put(sync_fence->cbs[i].sync_pt);
+		fence_put(sync_fence->cbs[i].fence);
 	}
 
 	kfree(sync_fence);
@@ -681,7 +681,7 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 	len = sizeof(struct sync_fence_info_data);
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		struct fence *pt = sync_fence->cbs[i].sync_pt;
+		struct fence *pt = sync_fence->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 0fed642..43f72a7 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_fence_cb {
 	struct fence_cb cb;
-	struct fence *sync_pt;
+	struct fence *fence;
 	struct sync_fence *sync_fence;
 };
 
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index cfa92d2..78e9147 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -163,7 +163,7 @@ static void sync_print_sync_fence(struct seq_file *s,
 		   sync_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_pt(s, sync_fence->cbs[i].sync_pt, true);
+		sync_print_pt(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 10/29] staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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 c47b68d..decff9e 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -197,7 +197,7 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 	sync_fence->num_fences = 1;
 	atomic_set(&sync_fence->status, 1);
 
-	sync_fence->cbs[0].sync_pt = pt;
+	sync_fence->cbs[0].fence = pt;
 	sync_fence->cbs[0].sync_fence = sync_fence;
 	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
 		atomic_dec(&sync_fence->status);
@@ -247,7 +247,7 @@ EXPORT_SYMBOL(sync_fence_install);
 static void sync_fence_add_pt(struct sync_fence *sync_fence,
 			      int *i, struct fence *pt)
 {
-	sync_fence->cbs[*i].sync_pt = pt;
+	sync_fence->cbs[*i].fence = pt;
 	sync_fence->cbs[*i].sync_fence = sync_fence;
 
 	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
@@ -279,8 +279,8 @@ struct sync_fence *sync_fence_merge(const char *name,
 	 * and sync_fence_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_fence_add_pt(sync_fence, &i, pt_a);
@@ -302,10 +302,10 @@ struct sync_fence *sync_fence_merge(const char *name,
 	}
 
 	for (; i_a < a->num_fences; i_a++)
-		sync_fence_add_pt(sync_fence, &i, a->cbs[i_a].sync_pt);
+		sync_fence_add_pt(sync_fence, &i, a->cbs[i_a].fence);
 
 	for (; i_b < b->num_fences; i_b++)
-		sync_fence_add_pt(sync_fence, &i, b->cbs[i_b].sync_pt);
+		sync_fence_add_pt(sync_fence, &i, b->cbs[i_b].fence);
 
 	if (num_fences > i)
 		atomic_sub(num_fences - i, &sync_fence->status);
@@ -384,7 +384,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_sync_pt(sync_fence->cbs[i].sync_pt);
+		trace_sync_pt(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -525,9 +525,9 @@ static void sync_fence_free(struct kref *kref)
 	int i;
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		fence_remove_callback(sync_fence->cbs[i].sync_pt,
+		fence_remove_callback(sync_fence->cbs[i].fence,
 				      &sync_fence->cbs[i].cb);
-		fence_put(sync_fence->cbs[i].sync_pt);
+		fence_put(sync_fence->cbs[i].fence);
 	}
 
 	kfree(sync_fence);
@@ -681,7 +681,7 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 	len = sizeof(struct sync_fence_info_data);
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		struct fence *pt = sync_fence->cbs[i].sync_pt;
+		struct fence *pt = sync_fence->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 0fed642..43f72a7 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_fence_cb {
 	struct fence_cb cb;
-	struct fence *sync_pt;
+	struct fence *fence;
 	struct sync_fence *sync_fence;
 };
 
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index cfa92d2..78e9147 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -163,7 +163,7 @@ static void sync_print_sync_fence(struct seq_file *s,
 		   sync_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_pt(s, sync_fence->cbs[i].sync_pt, true);
+		sync_print_pt(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 11/29] dma-buf/fence: move sync_timeline to fence_timeline
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add the sync timeline from sync framework to fence synchronization system.
This is an attempt to remove some duplication between sync.c and fence.c

The sync_timeline was no more than a wrapper on top of the fence
framework to be used by sw_sync. It simplifies some accesses, for example,
when you have a struct fence you don't need get the sync_pt related to it
to know the parent timeline, it is just a matter of calling
fence_parent() now.

This is just the initial step, the idea is to connect sw_sync direct
with fences removing some abstractions in between.

The sync API changes here are:

 * struct sync_timeline is now struct fence_timeline
 * sync_timeline_ops is now fence_timeline_ops and they now carry struct
 fence as parameter instead of struct sync_pt
 * sync_timeline_create()	-> fence_timeline_create()
 * sync_timeline_get()		-> fence_timeline_get()
 * sync_timeline_put()		-> fence_timeline_put()
 * sync_timeline_destroy()	-> fence_timeline_destroy()
 * sync_timeline_signal()	-> fence_timeline_signal()

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 125 +++++++++++++++++++++++++++++
 drivers/staging/android/sw_sync.c    |  27 ++++---
 drivers/staging/android/sw_sync.h    |   2 +-
 drivers/staging/android/sync.c       | 150 +++++++----------------------------
 drivers/staging/android/sync.h       | 130 +-----------------------------
 drivers/staging/android/sync_debug.c |  26 +++---
 drivers/staging/android/trace/sync.h |  24 ------
 include/linux/fence.h                |  75 ++++++++++++++++++
 include/trace/events/fence.h         |  24 ++++++
 9 files changed, 285 insertions(+), 298 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 7b05dbe..5dcb94c 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -52,6 +52,131 @@ unsigned fence_context_alloc(unsigned num)
 EXPORT_SYMBOL(fence_context_alloc);
 
 /**
+ * fence_timeline_create - create a new fence_timeline
+ * @num:	[in]	amount of contexts to allocate
+ * @ops:	[in]	timeline ops of the caller
+ * @size:	[in]	size to allocate struct fence_timeline
+ * @name:	[in]	name of the timeline
+ *
+ * This function will return the new fence_timeline or NULL in case of error.
+ * It allocs and initializes a new fence_timeline with a proper fence context
+ * number assigned to it.
+ */
+struct fence_timeline *fence_timeline_create(unsigned num,
+					     struct fence_timeline_ops *ops,
+					     int size, const char *name)
+{
+	struct fence_timeline *timeline;
+
+	if (size < sizeof(*timeline))
+		return NULL;
+
+	timeline = kzalloc(size, GFP_KERNEL);
+	if (!timeline)
+		return NULL;
+
+	kref_init(&timeline->kref);
+	timeline->ops = ops;
+	timeline->context = fence_context_alloc(1);
+	strlcpy(timeline->name, name, sizeof(timeline->name));
+
+	INIT_LIST_HEAD(&timeline->child_list_head);
+	INIT_LIST_HEAD(&timeline->active_list_head);
+	spin_lock_init(&timeline->lock);
+
+	return timeline;
+}
+EXPORT_SYMBOL(fence_timeline_create);
+
+/**
+ * fence_timeline_free - free resources of fence_timeline
+ * @kref	[in]	the kref of the fence_timeline to be freed
+ *
+ * This function frees a fence_timeline which is matter of a simple
+ * call to kfree()
+ */
+static void fence_timeline_free(struct kref *kref)
+{
+	struct fence_timeline *timeline =
+		container_of(kref, struct fence_timeline, kref);
+
+	kfree(timeline);
+}
+
+/**
+ * fence_timeline_get - get a reference to the timeline
+ * @timeline	[in]	the fence_timeline to get a reference
+ *
+ * This function increase the refcnt for the given timeline.
+ */
+void fence_timeline_get(struct fence_timeline *timeline)
+{
+	kref_get(&timeline->kref);
+}
+EXPORT_SYMBOL(fence_timeline_get);
+
+/**
+ * fence_timeline_put - put a reference to the timeline
+ * @timeline	[in]	the fence_timeline to put a reference
+ *
+ * This function decreases the refcnt for the given timeline
+ * and frees it if gets to zero.
+ */
+void fence_timeline_put(struct fence_timeline *timeline)
+{
+	kref_put(&timeline->kref, fence_timeline_free);
+}
+EXPORT_SYMBOL(fence_timeline_put);
+
+/**
+ * fence_timeline_destroy - destroy a fence_timeline
+ * @timeline	[in]	the fence_timeline to destroy
+ *
+ * This function destroys a timeline. It signals any active fence first.
+ */
+void fence_timeline_destroy(struct fence_timeline *timeline)
+{
+	timeline->destroyed = true;
+	/*
+	 * Ensure timeline is marked as destroyed before
+	 * changing timeline's fences status.
+	 */
+	smp_wmb();
+
+	/*
+	 * signal any children that their parent is going away.
+	 */
+	fence_timeline_signal(timeline);
+	fence_timeline_put(timeline);
+}
+EXPORT_SYMBOL(fence_timeline_destroy);
+
+/**
+ * fence_timeline_signal - signal fences on a fence_timeline
+ * @timeline	[in]	the fence_timeline to signal fences
+ *
+ * This function signal fences on a given timeline and remove
+ * those from the active_list.
+ */
+void fence_timeline_signal(struct fence_timeline *timeline)
+{
+	unsigned long flags;
+	LIST_HEAD(signaled_pts);
+	struct fence *fence, *next;
+
+	spin_lock_irqsave(&timeline->lock, flags);
+
+	list_for_each_entry_safe(fence, next, &timeline->active_list_head,
+				 active_list) {
+		if (fence_is_signaled_locked(fence))
+			list_del_init(&fence->active_list);
+	}
+
+	spin_unlock_irqrestore(&timeline->lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_signal);
+
+/**
  * fence_signal_locked - signal completion of a fence
  * @fence: the fence to signal
  *
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index f491dbc..98f9a29 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,18 +38,19 @@ struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
 }
 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 sync_pt *sync_pt = (struct sync_pt *)fence;
 	struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt;
 
 	if (size < sizeof(pt->value))
@@ -60,34 +61,34 @@ static int sw_sync_fill_driver_data(struct sync_pt *sync_pt,
 	return sizeof(pt->value);
 }
 
-static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
+static void sw_sync_timeline_value_str(struct fence_timeline *fence_timeline,
 				       char *str, int size)
 {
 	struct sw_sync_timeline *timeline =
-		(struct sw_sync_timeline *)sync_timeline;
+		(struct sw_sync_timeline *)fence_timeline;
 	snprintf(str, size, "%d", timeline->value);
 }
 
-static void sw_sync_pt_value_str(struct sync_pt *sync_pt,
+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 = {
+static struct fence_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)
 {
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		sync_timeline_create(&sw_sync_timeline_ops,
+		fence_timeline_create(1, &sw_sync_timeline_ops,
 				     sizeof(struct sw_sync_timeline),
 				     name);
 
@@ -99,6 +100,6 @@ void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
 {
 	obj->value += inc;
 
-	sync_timeline_signal(&obj->obj);
+	fence_timeline_signal(&obj->obj);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index c87ae9e..cb62298 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -23,7 +23,7 @@
 #include "uapi/sw_sync.h"
 
 struct sw_sync_timeline {
-	struct	sync_timeline	obj;
+	struct	fence_timeline	obj;
 
 	u32			value;
 };
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index decff9e..b07bc24 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -34,110 +34,26 @@
 static const struct fence_ops sync_fence_ops;
 static const struct file_operations sync_fence_fops;
 
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
-					   int size, const char *name)
-{
-	struct sync_timeline *obj;
-
-	if (size < sizeof(struct sync_timeline))
-		return NULL;
-
-	obj = kzalloc(size, GFP_KERNEL);
-	if (!obj)
-		return NULL;
-
-	kref_init(&obj->kref);
-	obj->ops = ops;
-	obj->context = fence_context_alloc(1);
-	strlcpy(obj->name, name, sizeof(obj->name));
-
-	INIT_LIST_HEAD(&obj->child_list_head);
-	INIT_LIST_HEAD(&obj->active_list_head);
-	spin_lock_init(&obj->child_list_lock);
-
-	sync_timeline_debug_add(obj);
-
-	return obj;
-}
-EXPORT_SYMBOL(sync_timeline_create);
-
-static void sync_timeline_free(struct kref *kref)
-{
-	struct sync_timeline *obj =
-		container_of(kref, struct sync_timeline, kref);
-
-	sync_timeline_debug_remove(obj);
-
-	kfree(obj);
-}
-
-static void sync_timeline_get(struct sync_timeline *obj)
-{
-	kref_get(&obj->kref);
-}
-
-static void sync_timeline_put(struct sync_timeline *obj)
-{
-	kref_put(&obj->kref, sync_timeline_free);
-}
-
-void sync_timeline_destroy(struct sync_timeline *obj)
-{
-	obj->destroyed = true;
-	/*
-	 * Ensure timeline is marked as destroyed before
-	 * changing timeline's fences status.
-	 */
-	smp_wmb();
-
-	/*
-	 * signal any children that their parent is going away.
-	 */
-	sync_timeline_signal(obj);
-	sync_timeline_put(obj);
-}
-EXPORT_SYMBOL(sync_timeline_destroy);
-
-void sync_timeline_signal(struct sync_timeline *obj)
-{
-	unsigned long flags;
-	LIST_HEAD(signaled_pts);
-	struct sync_pt *pt, *next;
-
-	trace_sync_timeline(obj);
-
-	spin_lock_irqsave(&obj->child_list_lock, flags);
-
-	list_for_each_entry_safe(pt, next, &obj->active_list_head,
-				 active_list) {
-		if (fence_is_signaled_locked(&pt->base))
-			list_del_init(&pt->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 fence_timeline *obj, int size)
 {
 	unsigned long flags;
-	struct sync_pt *pt;
+	struct fence *fence;
 
 	if (size < sizeof(struct sync_pt))
 		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, &sync_fence_ops, &obj->child_list_lock,
+	spin_lock_irqsave(&obj->lock, flags);
+	fence_timeline_get(obj);
+	fence_init(fence, &sync_fence_ops, &obj->lock,
 		   obj->context, ++obj->value);
-	list_add_tail(&pt->child_list, &obj->child_list_head);
-	INIT_LIST_HEAD(&pt->active_list);
-	spin_unlock_irqrestore(&obj->child_list_lock, flags);
-	return pt;
+	list_add_tail(&fence->child_list, &obj->child_list_head);
+	INIT_LIST_HEAD(&fence->active_list);
+	spin_unlock_irqrestore(&obj->lock, flags);
+	return fence;
 }
 EXPORT_SYMBOL(sync_pt_create);
 
@@ -412,44 +328,40 @@ EXPORT_SYMBOL(sync_fence_wait);
 
 static const char *sync_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 fence_timeline *parent = fence_parent(fence);
 
 	return parent->ops->driver_name;
 }
 
 static const char *sync_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 fence_timeline *parent = fence_parent(fence);
 
 	return parent->name;
 }
 
 static void sync_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 fence_timeline *parent = fence_parent(fence);
 	unsigned long flags;
 
 	spin_lock_irqsave(fence->lock, flags);
-	list_del(&pt->child_list);
-	if (!list_empty(&pt->active_list))
-		list_del(&pt->active_list);
+	list_del(&fence->child_list);
+	if (!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_timeline_put(parent);
+	fence_free(fence);
 }
 
 static bool sync_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 fence_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;
@@ -457,46 +369,42 @@ static bool sync_fence_signaled(struct fence *fence)
 
 static bool sync_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 fence_timeline *parent = fence_parent(fence);
 
 	if (sync_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 sync_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 fence_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 sync_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 fence_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 sync_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 fence_timeline *parent = fence_parent(fence);
 
 	if (!parent->ops->timeline_value_str) {
 		if (size)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 43f72a7..53658cc 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -23,91 +23,12 @@
 
 #include "uapi/sync.h"
 
-struct sync_timeline;
-struct sync_pt;
 struct sync_fence;
 
-/**
- * struct sync_timeline_ops - sync object implementation ops
- * @driver_name:	name of the implementation
- * @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
- *			  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
- */
-struct sync_timeline_ops {
-	const char *driver_name;
-
-	/* required */
-	int (*has_signaled)(struct sync_pt *pt);
-
-	/* optional */
-	int (*fill_driver_data)(struct sync_pt *syncpt, 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);
-};
-
-/**
- * struct sync_timeline - sync object
- * @kref:		reference count on fence.
- * @ops:		ops that define the implementation of the sync_timeline
- * @name:		name of the sync_timeline. Useful for debugging
- * @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
- * @active_list_head:	list of active (unsignaled/errored) sync_pts
- * @sync_timeline_list:	membership in global sync_timeline_list
- */
-struct sync_timeline {
-	struct kref		kref;
-	const struct sync_timeline_ops	*ops;
-	char			name[32];
-
-	/* protected by child_list_lock */
-	bool			destroyed;
-	int			context, value;
-
-	struct list_head	child_list_head;
-	spinlock_t		child_list_lock;
-
-	struct list_head	active_list_head;
-
-#ifdef CONFIG_DEBUG_FS
-	struct list_head	sync_timeline_list;
-#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)
-{
-	return container_of(pt->base.lock, struct sync_timeline,
-			    child_list_lock);
-}
-
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *fence;
@@ -162,53 +83,10 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 }
 
 /*
- * API for sync_timeline implementers
+ * API for fence_timeline implementers
  */
 
-/**
- * sync_timeline_create() - creates a sync object
- * @ops:	specifies the implementation ops for the object
- * @size:	size to allocate for this obj
- * @name:	sync_timeline name
- *
- * 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. 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);
-
-/**
- * sync_timeline_destroy() - destroys a sync object
- * @obj:	sync_timeline to destroy
- *
- * 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.
- */
-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
- * 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
- * @size:	size to allocate for this pt
- *
- * 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. Returns the sync_pt 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 fence_timeline *parent, int size);
 
 /**
  * sync_pt_free() - frees a sync pt
@@ -325,8 +203,8 @@ int sync_fence_wait(struct sync_fence *fence, 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_timeline_debug_add(struct fence_timeline *obj);
+void sync_timeline_debug_remove(struct fence_timeline *obj);
 void sync_fence_debug_add(struct sync_fence *fence);
 void sync_fence_debug_remove(struct sync_fence *fence);
 void sync_dump(void);
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 78e9147..f5fd8c3 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -38,21 +38,21 @@ static DEFINE_SPINLOCK(sync_timeline_list_lock);
 static LIST_HEAD(sync_fence_list_head);
 static DEFINE_SPINLOCK(sync_fence_list_lock);
 
-void sync_timeline_debug_add(struct sync_timeline *obj)
+void sync_timeline_debug_add(struct fence_timeline *obj)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head);
+	list_add_tail(&obj->fence_timeline_list, &sync_timeline_list_head);
 	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
 }
 
-void sync_timeline_debug_remove(struct sync_timeline *obj)
+void sync_timeline_debug_remove(struct fence_timeline *obj)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_del(&obj->sync_timeline_list);
+	list_del(&obj->fence_timeline_list);
 	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
 }
 
@@ -127,7 +127,7 @@ static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence)
 	seq_puts(s, "\n");
 }
 
-static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
+static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 {
 	struct list_head *pos;
 	unsigned long flags;
@@ -143,13 +143,13 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
 
 	seq_puts(s, "\n");
 
-	spin_lock_irqsave(&obj->child_list_lock, flags);
+	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
-		struct sync_pt *pt =
-			container_of(pos, struct sync_pt, child_list);
+		struct sync_pt *pt = (struct sync_pt *)
+			container_of(pos, struct fence, child_list);
 		sync_print_pt(s, &pt->base, false);
 	}
-	spin_unlock_irqrestore(&obj->child_list_lock, flags);
+	spin_unlock_irqrestore(&obj->lock, flags);
 }
 
 static void sync_print_sync_fence(struct seq_file *s,
@@ -189,9 +189,9 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
 	list_for_each(pos, &sync_timeline_list_head) {
-		struct sync_timeline *obj =
-			container_of(pos, struct sync_timeline,
-				     sync_timeline_list);
+		struct fence_timeline *obj =
+			container_of(pos, struct fence_timeline,
+				     fence_timeline_list);
 
 		sync_print_obj(s, obj);
 		seq_puts(s, "\n");
@@ -251,7 +251,7 @@ 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);
+	fence_timeline_destroy(&obj->obj);
 	return 0;
 }
 
diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h
index 77edb97..59c337f 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -8,30 +8,6 @@
 #include "../sync.h"
 #include <linux/tracepoint.h>
 
-TRACE_EVENT(sync_timeline,
-	TP_PROTO(struct sync_timeline *timeline),
-
-	TP_ARGS(timeline),
-
-	TP_STRUCT__entry(
-			__string(name, timeline->name)
-			__array(char, value, 32)
-	),
-
-	TP_fast_assign(
-			__assign_str(name, timeline->name);
-			if (timeline->ops->timeline_value_str) {
-				timeline->ops->timeline_value_str(timeline,
-							__entry->value,
-							sizeof(__entry->value));
-			} else {
-				__entry->value[0] = '\0';
-			}
-	),
-
-	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
-);
-
 TRACE_EVENT(sync_wait,
 	TP_PROTO(struct sync_fence *fence, int begin),
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index bb52201..a333bf37 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -30,9 +30,75 @@
 #include <linux/printk.h>
 #include <linux/rcupdate.h>
 
+struct fence_timeline;
 struct fence;
 struct fence_ops;
 struct fence_cb;
+/**
+ * struct fence_timeline_ops - fence context implementation ops
+ * @driver_name:	name of the implementation
+ * @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
+ *			  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
+ */
+struct fence_timeline_ops {
+	const char *driver_name;
+
+	/* required */
+	int (*has_signaled)(struct fence *fence);
+
+	/* optional */
+	int (*fill_driver_data)(struct fence *fence, void *data, int size);
+
+	/* optional */
+	void (*timeline_value_str)(struct fence_timeline *timeline, char *str,
+				   int size);
+
+	/* optional */
+	void (*fence_value_str)(struct fence *fence, char *str, int size);
+};
+
+/**
+ * struct fence_timeline - timeline for software synchronization primitive
+ * @kref: refcount for timeline lifetime
+ * @name: name of the timeline
+ * @ops: pointer to fence_timeline_ops of users
+ * @detroyed: if true, the destroy process has started
+ * @value: value of the last signaled fence
+ * @child_list_head: list of child fences
+ * @active_list_head: list of active(not signaled) fences
+ * @lock: to protect lists access
+ * @fences: list of all timelines created
+ */
+struct fence_timeline {
+	struct kref		kref;
+	char			name[32];
+	const struct fence_timeline_ops *ops;
+	bool			destroyed;
+	int			value;
+	int			context;
+	struct list_head	child_list_head;
+	struct list_head	active_list_head;
+	spinlock_t		lock;
+#ifdef CONFIG_DEBUG_FS
+	struct list_head        fence_timeline_list;
+#endif
+};
+
+struct fence_timeline *fence_timeline_create(unsigned num,
+					     struct fence_timeline_ops *ops,
+					     int size, const char *name);
+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);
 
 /**
  * struct fence - software synchronization primitive
@@ -79,6 +145,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 {
@@ -181,6 +249,13 @@ void fence_init(struct fence *fence, const struct fence_ops *ops,
 void fence_release(struct kref *kref);
 void fence_free(struct fence *fence);
 
+
+static inline struct fence_timeline *fence_parent(struct fence *fence)
+{
+	return container_of(fence->lock, struct fence_timeline,
+			    lock);
+}
+
 /**
  * fence_get - increases refcount of the fence
  * @fence:	[in]	fence to increase refcount of
diff --git a/include/trace/events/fence.h b/include/trace/events/fence.h
index 98feb1b..c4d01de 100644
--- a/include/trace/events/fence.h
+++ b/include/trace/events/fence.h
@@ -48,6 +48,30 @@ TRACE_EVENT(fence_annotate_wait_on,
 		  __entry->waiting_context, __entry->waiting_seqno)
 );
 
+TRACE_EVENT(fence_timeline,
+	TP_PROTO(struct fence_timeline *timeline),
+
+	TP_ARGS(timeline),
+
+	TP_STRUCT__entry(
+			__string(name, timeline->name)
+			__array(char, value, 32)
+	),
+
+	TP_fast_assign(
+			__assign_str(name, timeline->name);
+			if (timeline->ops->timeline_value_str) {
+				timeline->ops->timeline_value_str(timeline,
+							__entry->value,
+							sizeof(__entry->value));
+			} else {
+				__entry->value[0] = '\0';
+			}
+	),
+
+	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
+);
+
 DECLARE_EVENT_CLASS(fence,
 
 	TP_PROTO(struct fence *fence),
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 11/29] dma-buf/fence: move sync_timeline to fence_timeline
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add the sync timeline from sync framework to fence synchronization system.
This is an attempt to remove some duplication between sync.c and fence.c

The sync_timeline was no more than a wrapper on top of the fence
framework to be used by sw_sync. It simplifies some accesses, for example,
when you have a struct fence you don't need get the sync_pt related to it
to know the parent timeline, it is just a matter of calling
fence_parent() now.

This is just the initial step, the idea is to connect sw_sync direct
with fences removing some abstractions in between.

The sync API changes here are:

 * struct sync_timeline is now struct fence_timeline
 * sync_timeline_ops is now fence_timeline_ops and they now carry struct
 fence as parameter instead of struct sync_pt
 * sync_timeline_create()	-> fence_timeline_create()
 * sync_timeline_get()		-> fence_timeline_get()
 * sync_timeline_put()		-> fence_timeline_put()
 * sync_timeline_destroy()	-> fence_timeline_destroy()
 * sync_timeline_signal()	-> fence_timeline_signal()

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 125 +++++++++++++++++++++++++++++
 drivers/staging/android/sw_sync.c    |  27 ++++---
 drivers/staging/android/sw_sync.h    |   2 +-
 drivers/staging/android/sync.c       | 150 +++++++----------------------------
 drivers/staging/android/sync.h       | 130 +-----------------------------
 drivers/staging/android/sync_debug.c |  26 +++---
 drivers/staging/android/trace/sync.h |  24 ------
 include/linux/fence.h                |  75 ++++++++++++++++++
 include/trace/events/fence.h         |  24 ++++++
 9 files changed, 285 insertions(+), 298 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 7b05dbe..5dcb94c 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -52,6 +52,131 @@ unsigned fence_context_alloc(unsigned num)
 EXPORT_SYMBOL(fence_context_alloc);
 
 /**
+ * fence_timeline_create - create a new fence_timeline
+ * @num:	[in]	amount of contexts to allocate
+ * @ops:	[in]	timeline ops of the caller
+ * @size:	[in]	size to allocate struct fence_timeline
+ * @name:	[in]	name of the timeline
+ *
+ * This function will return the new fence_timeline or NULL in case of error.
+ * It allocs and initializes a new fence_timeline with a proper fence context
+ * number assigned to it.
+ */
+struct fence_timeline *fence_timeline_create(unsigned num,
+					     struct fence_timeline_ops *ops,
+					     int size, const char *name)
+{
+	struct fence_timeline *timeline;
+
+	if (size < sizeof(*timeline))
+		return NULL;
+
+	timeline = kzalloc(size, GFP_KERNEL);
+	if (!timeline)
+		return NULL;
+
+	kref_init(&timeline->kref);
+	timeline->ops = ops;
+	timeline->context = fence_context_alloc(1);
+	strlcpy(timeline->name, name, sizeof(timeline->name));
+
+	INIT_LIST_HEAD(&timeline->child_list_head);
+	INIT_LIST_HEAD(&timeline->active_list_head);
+	spin_lock_init(&timeline->lock);
+
+	return timeline;
+}
+EXPORT_SYMBOL(fence_timeline_create);
+
+/**
+ * fence_timeline_free - free resources of fence_timeline
+ * @kref	[in]	the kref of the fence_timeline to be freed
+ *
+ * This function frees a fence_timeline which is matter of a simple
+ * call to kfree()
+ */
+static void fence_timeline_free(struct kref *kref)
+{
+	struct fence_timeline *timeline =
+		container_of(kref, struct fence_timeline, kref);
+
+	kfree(timeline);
+}
+
+/**
+ * fence_timeline_get - get a reference to the timeline
+ * @timeline	[in]	the fence_timeline to get a reference
+ *
+ * This function increase the refcnt for the given timeline.
+ */
+void fence_timeline_get(struct fence_timeline *timeline)
+{
+	kref_get(&timeline->kref);
+}
+EXPORT_SYMBOL(fence_timeline_get);
+
+/**
+ * fence_timeline_put - put a reference to the timeline
+ * @timeline	[in]	the fence_timeline to put a reference
+ *
+ * This function decreases the refcnt for the given timeline
+ * and frees it if gets to zero.
+ */
+void fence_timeline_put(struct fence_timeline *timeline)
+{
+	kref_put(&timeline->kref, fence_timeline_free);
+}
+EXPORT_SYMBOL(fence_timeline_put);
+
+/**
+ * fence_timeline_destroy - destroy a fence_timeline
+ * @timeline	[in]	the fence_timeline to destroy
+ *
+ * This function destroys a timeline. It signals any active fence first.
+ */
+void fence_timeline_destroy(struct fence_timeline *timeline)
+{
+	timeline->destroyed = true;
+	/*
+	 * Ensure timeline is marked as destroyed before
+	 * changing timeline's fences status.
+	 */
+	smp_wmb();
+
+	/*
+	 * signal any children that their parent is going away.
+	 */
+	fence_timeline_signal(timeline);
+	fence_timeline_put(timeline);
+}
+EXPORT_SYMBOL(fence_timeline_destroy);
+
+/**
+ * fence_timeline_signal - signal fences on a fence_timeline
+ * @timeline	[in]	the fence_timeline to signal fences
+ *
+ * This function signal fences on a given timeline and remove
+ * those from the active_list.
+ */
+void fence_timeline_signal(struct fence_timeline *timeline)
+{
+	unsigned long flags;
+	LIST_HEAD(signaled_pts);
+	struct fence *fence, *next;
+
+	spin_lock_irqsave(&timeline->lock, flags);
+
+	list_for_each_entry_safe(fence, next, &timeline->active_list_head,
+				 active_list) {
+		if (fence_is_signaled_locked(fence))
+			list_del_init(&fence->active_list);
+	}
+
+	spin_unlock_irqrestore(&timeline->lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_signal);
+
+/**
  * fence_signal_locked - signal completion of a fence
  * @fence: the fence to signal
  *
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index f491dbc..98f9a29 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,18 +38,19 @@ struct sync_pt *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
 }
 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 sync_pt *sync_pt = (struct sync_pt *)fence;
 	struct sw_sync_pt *pt = (struct sw_sync_pt *)sync_pt;
 
 	if (size < sizeof(pt->value))
@@ -60,34 +61,34 @@ static int sw_sync_fill_driver_data(struct sync_pt *sync_pt,
 	return sizeof(pt->value);
 }
 
-static void sw_sync_timeline_value_str(struct sync_timeline *sync_timeline,
+static void sw_sync_timeline_value_str(struct fence_timeline *fence_timeline,
 				       char *str, int size)
 {
 	struct sw_sync_timeline *timeline =
-		(struct sw_sync_timeline *)sync_timeline;
+		(struct sw_sync_timeline *)fence_timeline;
 	snprintf(str, size, "%d", timeline->value);
 }
 
-static void sw_sync_pt_value_str(struct sync_pt *sync_pt,
+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 = {
+static struct fence_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)
 {
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		sync_timeline_create(&sw_sync_timeline_ops,
+		fence_timeline_create(1, &sw_sync_timeline_ops,
 				     sizeof(struct sw_sync_timeline),
 				     name);
 
@@ -99,6 +100,6 @@ void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
 {
 	obj->value += inc;
 
-	sync_timeline_signal(&obj->obj);
+	fence_timeline_signal(&obj->obj);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index c87ae9e..cb62298 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -23,7 +23,7 @@
 #include "uapi/sw_sync.h"
 
 struct sw_sync_timeline {
-	struct	sync_timeline	obj;
+	struct	fence_timeline	obj;
 
 	u32			value;
 };
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index decff9e..b07bc24 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -34,110 +34,26 @@
 static const struct fence_ops sync_fence_ops;
 static const struct file_operations sync_fence_fops;
 
-struct sync_timeline *sync_timeline_create(const struct sync_timeline_ops *ops,
-					   int size, const char *name)
-{
-	struct sync_timeline *obj;
-
-	if (size < sizeof(struct sync_timeline))
-		return NULL;
-
-	obj = kzalloc(size, GFP_KERNEL);
-	if (!obj)
-		return NULL;
-
-	kref_init(&obj->kref);
-	obj->ops = ops;
-	obj->context = fence_context_alloc(1);
-	strlcpy(obj->name, name, sizeof(obj->name));
-
-	INIT_LIST_HEAD(&obj->child_list_head);
-	INIT_LIST_HEAD(&obj->active_list_head);
-	spin_lock_init(&obj->child_list_lock);
-
-	sync_timeline_debug_add(obj);
-
-	return obj;
-}
-EXPORT_SYMBOL(sync_timeline_create);
-
-static void sync_timeline_free(struct kref *kref)
-{
-	struct sync_timeline *obj =
-		container_of(kref, struct sync_timeline, kref);
-
-	sync_timeline_debug_remove(obj);
-
-	kfree(obj);
-}
-
-static void sync_timeline_get(struct sync_timeline *obj)
-{
-	kref_get(&obj->kref);
-}
-
-static void sync_timeline_put(struct sync_timeline *obj)
-{
-	kref_put(&obj->kref, sync_timeline_free);
-}
-
-void sync_timeline_destroy(struct sync_timeline *obj)
-{
-	obj->destroyed = true;
-	/*
-	 * Ensure timeline is marked as destroyed before
-	 * changing timeline's fences status.
-	 */
-	smp_wmb();
-
-	/*
-	 * signal any children that their parent is going away.
-	 */
-	sync_timeline_signal(obj);
-	sync_timeline_put(obj);
-}
-EXPORT_SYMBOL(sync_timeline_destroy);
-
-void sync_timeline_signal(struct sync_timeline *obj)
-{
-	unsigned long flags;
-	LIST_HEAD(signaled_pts);
-	struct sync_pt *pt, *next;
-
-	trace_sync_timeline(obj);
-
-	spin_lock_irqsave(&obj->child_list_lock, flags);
-
-	list_for_each_entry_safe(pt, next, &obj->active_list_head,
-				 active_list) {
-		if (fence_is_signaled_locked(&pt->base))
-			list_del_init(&pt->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 fence_timeline *obj, int size)
 {
 	unsigned long flags;
-	struct sync_pt *pt;
+	struct fence *fence;
 
 	if (size < sizeof(struct sync_pt))
 		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, &sync_fence_ops, &obj->child_list_lock,
+	spin_lock_irqsave(&obj->lock, flags);
+	fence_timeline_get(obj);
+	fence_init(fence, &sync_fence_ops, &obj->lock,
 		   obj->context, ++obj->value);
-	list_add_tail(&pt->child_list, &obj->child_list_head);
-	INIT_LIST_HEAD(&pt->active_list);
-	spin_unlock_irqrestore(&obj->child_list_lock, flags);
-	return pt;
+	list_add_tail(&fence->child_list, &obj->child_list_head);
+	INIT_LIST_HEAD(&fence->active_list);
+	spin_unlock_irqrestore(&obj->lock, flags);
+	return fence;
 }
 EXPORT_SYMBOL(sync_pt_create);
 
@@ -412,44 +328,40 @@ EXPORT_SYMBOL(sync_fence_wait);
 
 static const char *sync_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 fence_timeline *parent = fence_parent(fence);
 
 	return parent->ops->driver_name;
 }
 
 static const char *sync_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 fence_timeline *parent = fence_parent(fence);
 
 	return parent->name;
 }
 
 static void sync_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 fence_timeline *parent = fence_parent(fence);
 	unsigned long flags;
 
 	spin_lock_irqsave(fence->lock, flags);
-	list_del(&pt->child_list);
-	if (!list_empty(&pt->active_list))
-		list_del(&pt->active_list);
+	list_del(&fence->child_list);
+	if (!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_timeline_put(parent);
+	fence_free(fence);
 }
 
 static bool sync_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 fence_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;
@@ -457,46 +369,42 @@ static bool sync_fence_signaled(struct fence *fence)
 
 static bool sync_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 fence_timeline *parent = fence_parent(fence);
 
 	if (sync_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 sync_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 fence_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 sync_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 fence_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 sync_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 fence_timeline *parent = fence_parent(fence);
 
 	if (!parent->ops->timeline_value_str) {
 		if (size)
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 43f72a7..53658cc 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -23,91 +23,12 @@
 
 #include "uapi/sync.h"
 
-struct sync_timeline;
-struct sync_pt;
 struct sync_fence;
 
-/**
- * struct sync_timeline_ops - sync object implementation ops
- * @driver_name:	name of the implementation
- * @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
- *			  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
- */
-struct sync_timeline_ops {
-	const char *driver_name;
-
-	/* required */
-	int (*has_signaled)(struct sync_pt *pt);
-
-	/* optional */
-	int (*fill_driver_data)(struct sync_pt *syncpt, 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);
-};
-
-/**
- * struct sync_timeline - sync object
- * @kref:		reference count on fence.
- * @ops:		ops that define the implementation of the sync_timeline
- * @name:		name of the sync_timeline. Useful for debugging
- * @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
- * @active_list_head:	list of active (unsignaled/errored) sync_pts
- * @sync_timeline_list:	membership in global sync_timeline_list
- */
-struct sync_timeline {
-	struct kref		kref;
-	const struct sync_timeline_ops	*ops;
-	char			name[32];
-
-	/* protected by child_list_lock */
-	bool			destroyed;
-	int			context, value;
-
-	struct list_head	child_list_head;
-	spinlock_t		child_list_lock;
-
-	struct list_head	active_list_head;
-
-#ifdef CONFIG_DEBUG_FS
-	struct list_head	sync_timeline_list;
-#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)
-{
-	return container_of(pt->base.lock, struct sync_timeline,
-			    child_list_lock);
-}
-
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *fence;
@@ -162,53 +83,10 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 }
 
 /*
- * API for sync_timeline implementers
+ * API for fence_timeline implementers
  */
 
-/**
- * sync_timeline_create() - creates a sync object
- * @ops:	specifies the implementation ops for the object
- * @size:	size to allocate for this obj
- * @name:	sync_timeline name
- *
- * 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. 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);
-
-/**
- * sync_timeline_destroy() - destroys a sync object
- * @obj:	sync_timeline to destroy
- *
- * 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.
- */
-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
- * 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
- * @size:	size to allocate for this pt
- *
- * 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. Returns the sync_pt 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 fence_timeline *parent, int size);
 
 /**
  * sync_pt_free() - frees a sync pt
@@ -325,8 +203,8 @@ int sync_fence_wait(struct sync_fence *fence, 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_timeline_debug_add(struct fence_timeline *obj);
+void sync_timeline_debug_remove(struct fence_timeline *obj);
 void sync_fence_debug_add(struct sync_fence *fence);
 void sync_fence_debug_remove(struct sync_fence *fence);
 void sync_dump(void);
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 78e9147..f5fd8c3 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -38,21 +38,21 @@ static DEFINE_SPINLOCK(sync_timeline_list_lock);
 static LIST_HEAD(sync_fence_list_head);
 static DEFINE_SPINLOCK(sync_fence_list_lock);
 
-void sync_timeline_debug_add(struct sync_timeline *obj)
+void sync_timeline_debug_add(struct fence_timeline *obj)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_add_tail(&obj->sync_timeline_list, &sync_timeline_list_head);
+	list_add_tail(&obj->fence_timeline_list, &sync_timeline_list_head);
 	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
 }
 
-void sync_timeline_debug_remove(struct sync_timeline *obj)
+void sync_timeline_debug_remove(struct fence_timeline *obj)
 {
 	unsigned long flags;
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_del(&obj->sync_timeline_list);
+	list_del(&obj->fence_timeline_list);
 	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
 }
 
@@ -127,7 +127,7 @@ static void sync_print_pt(struct seq_file *s, struct fence *pt, bool fence)
 	seq_puts(s, "\n");
 }
 
-static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
+static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 {
 	struct list_head *pos;
 	unsigned long flags;
@@ -143,13 +143,13 @@ static void sync_print_obj(struct seq_file *s, struct sync_timeline *obj)
 
 	seq_puts(s, "\n");
 
-	spin_lock_irqsave(&obj->child_list_lock, flags);
+	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
-		struct sync_pt *pt =
-			container_of(pos, struct sync_pt, child_list);
+		struct sync_pt *pt = (struct sync_pt *)
+			container_of(pos, struct fence, child_list);
 		sync_print_pt(s, &pt->base, false);
 	}
-	spin_unlock_irqrestore(&obj->child_list_lock, flags);
+	spin_unlock_irqrestore(&obj->lock, flags);
 }
 
 static void sync_print_sync_fence(struct seq_file *s,
@@ -189,9 +189,9 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	spin_lock_irqsave(&sync_timeline_list_lock, flags);
 	list_for_each(pos, &sync_timeline_list_head) {
-		struct sync_timeline *obj =
-			container_of(pos, struct sync_timeline,
-				     sync_timeline_list);
+		struct fence_timeline *obj =
+			container_of(pos, struct fence_timeline,
+				     fence_timeline_list);
 
 		sync_print_obj(s, obj);
 		seq_puts(s, "\n");
@@ -251,7 +251,7 @@ 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);
+	fence_timeline_destroy(&obj->obj);
 	return 0;
 }
 
diff --git a/drivers/staging/android/trace/sync.h b/drivers/staging/android/trace/sync.h
index 77edb97..59c337f 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -8,30 +8,6 @@
 #include "../sync.h"
 #include <linux/tracepoint.h>
 
-TRACE_EVENT(sync_timeline,
-	TP_PROTO(struct sync_timeline *timeline),
-
-	TP_ARGS(timeline),
-
-	TP_STRUCT__entry(
-			__string(name, timeline->name)
-			__array(char, value, 32)
-	),
-
-	TP_fast_assign(
-			__assign_str(name, timeline->name);
-			if (timeline->ops->timeline_value_str) {
-				timeline->ops->timeline_value_str(timeline,
-							__entry->value,
-							sizeof(__entry->value));
-			} else {
-				__entry->value[0] = '\0';
-			}
-	),
-
-	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
-);
-
 TRACE_EVENT(sync_wait,
 	TP_PROTO(struct sync_fence *fence, int begin),
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index bb52201..a333bf37 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -30,9 +30,75 @@
 #include <linux/printk.h>
 #include <linux/rcupdate.h>
 
+struct fence_timeline;
 struct fence;
 struct fence_ops;
 struct fence_cb;
+/**
+ * struct fence_timeline_ops - fence context implementation ops
+ * @driver_name:	name of the implementation
+ * @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
+ *			  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
+ */
+struct fence_timeline_ops {
+	const char *driver_name;
+
+	/* required */
+	int (*has_signaled)(struct fence *fence);
+
+	/* optional */
+	int (*fill_driver_data)(struct fence *fence, void *data, int size);
+
+	/* optional */
+	void (*timeline_value_str)(struct fence_timeline *timeline, char *str,
+				   int size);
+
+	/* optional */
+	void (*fence_value_str)(struct fence *fence, char *str, int size);
+};
+
+/**
+ * struct fence_timeline - timeline for software synchronization primitive
+ * @kref: refcount for timeline lifetime
+ * @name: name of the timeline
+ * @ops: pointer to fence_timeline_ops of users
+ * @detroyed: if true, the destroy process has started
+ * @value: value of the last signaled fence
+ * @child_list_head: list of child fences
+ * @active_list_head: list of active(not signaled) fences
+ * @lock: to protect lists access
+ * @fences: list of all timelines created
+ */
+struct fence_timeline {
+	struct kref		kref;
+	char			name[32];
+	const struct fence_timeline_ops *ops;
+	bool			destroyed;
+	int			value;
+	int			context;
+	struct list_head	child_list_head;
+	struct list_head	active_list_head;
+	spinlock_t		lock;
+#ifdef CONFIG_DEBUG_FS
+	struct list_head        fence_timeline_list;
+#endif
+};
+
+struct fence_timeline *fence_timeline_create(unsigned num,
+					     struct fence_timeline_ops *ops,
+					     int size, const char *name);
+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);
 
 /**
  * struct fence - software synchronization primitive
@@ -79,6 +145,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 {
@@ -181,6 +249,13 @@ void fence_init(struct fence *fence, const struct fence_ops *ops,
 void fence_release(struct kref *kref);
 void fence_free(struct fence *fence);
 
+
+static inline struct fence_timeline *fence_parent(struct fence *fence)
+{
+	return container_of(fence->lock, struct fence_timeline,
+			    lock);
+}
+
 /**
  * fence_get - increases refcount of the fence
  * @fence:	[in]	fence to increase refcount of
diff --git a/include/trace/events/fence.h b/include/trace/events/fence.h
index 98feb1b..c4d01de 100644
--- a/include/trace/events/fence.h
+++ b/include/trace/events/fence.h
@@ -48,6 +48,30 @@ TRACE_EVENT(fence_annotate_wait_on,
 		  __entry->waiting_context, __entry->waiting_seqno)
 );
 
+TRACE_EVENT(fence_timeline,
+	TP_PROTO(struct fence_timeline *timeline),
+
+	TP_ARGS(timeline),
+
+	TP_STRUCT__entry(
+			__string(name, timeline->name)
+			__array(char, value, 32)
+	),
+
+	TP_fast_assign(
+			__assign_str(name, timeline->name);
+			if (timeline->ops->timeline_value_str) {
+				timeline->ops->timeline_value_str(timeline,
+							__entry->value,
+							sizeof(__entry->value));
+			} else {
+				__entry->value[0] = '\0';
+			}
+	),
+
+	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
+);
+
 DECLARE_EVENT_CLASS(fence,
 
 	TP_PROTO(struct fence *fence),
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 12/29] staging/android: remove struct sync_pt
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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    |  7 +++---
 drivers/staging/android/sw_sync.h    |  8 +++----
 drivers/staging/android/sync.c       | 33 ++++++++++++-----------------
 drivers/staging/android/sync.h       | 21 ++++--------------
 drivers/staging/android/sync_debug.c | 41 ++++++++++++++++++------------------
 drivers/staging/android/trace/sync.h | 14 ++++++------
 6 files changed, 53 insertions(+), 71 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index 98f9a29..9d6a5bd 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,7 +34,7 @@ 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);
 
@@ -50,8 +50,7 @@ static int sw_sync_fence_has_signaled(struct fence *fence)
 static int sw_sync_fill_driver_data(struct fence *fence,
 				    void *data, int size)
 {
-	struct sync_pt *sync_pt = (struct sync_pt *)fence;
-	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;
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index cb62298..85ef780 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 b07bc24..417cf9f 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -39,7 +39,7 @@ struct fence *sync_pt_create(struct fence_timeline *obj, int size)
 	unsigned long flags;
 	struct fence *fence;
 
-	if (size < sizeof(struct sync_pt))
+	if (size < sizeof(*fence))
 		return NULL;
 
 	fence = kzalloc(size, GFP_KERNEL);
@@ -57,12 +57,6 @@ struct fence *sync_pt_create(struct fence_timeline *obj, int size)
 }
 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_fence *sync_fence_alloc(int size, const char *name)
 {
 	struct sync_fence *sync_fence;
@@ -101,7 +95,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
 }
 
 /* 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_fence *sync_fence_create_dma(const char *name, struct fence *fence)
 {
 	struct sync_fence *sync_fence;
 
@@ -113,9 +107,10 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 	sync_fence->num_fences = 1;
 	atomic_set(&sync_fence->status, 1);
 
-	sync_fence->cbs[0].fence = pt;
+	sync_fence->cbs[0].fence = fence;
 	sync_fence->cbs[0].sync_fence = sync_fence;
-	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
+	if (fence_add_callback(fence, &sync_fence->cbs[0].cb,
+			       fence_check_cb_func))
 		atomic_dec(&sync_fence->status);
 
 	sync_fence_debug_add(sync_fence);
@@ -124,9 +119,9 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
 
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
+struct sync_fence *sync_fence_create(const char *name, struct fence *fence)
 {
-	return sync_fence_create_dma(name, &pt->base);
+	return sync_fence_create_dma(name, fence);
 }
 EXPORT_SYMBOL(sync_fence_create);
 
@@ -161,14 +156,14 @@ void sync_fence_install(struct sync_fence *sync_fence, int fd)
 EXPORT_SYMBOL(sync_fence_install);
 
 static void sync_fence_add_pt(struct sync_fence *sync_fence,
-			      int *i, struct fence *pt)
+			      int *i, struct fence *fence)
 {
-	sync_fence->cbs[*i].fence = pt;
+	sync_fence->cbs[*i].fence = fence;
 	sync_fence->cbs[*i].sync_fence = sync_fence;
 
-	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
+	if (!fence_add_callback(fence, &sync_fence->cbs[*i].cb,
 				fence_check_cb_func)) {
-		fence_get(pt);
+		fence_get(fence);
 		(*i)++;
 	}
 }
@@ -300,7 +295,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_sync_pt(sync_fence->cbs[i].fence);
+		trace_fence(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -589,9 +584,9 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 	len = sizeof(struct sync_fence_info_data);
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		struct fence *pt = sync_fence->cbs[i].fence;
+		struct fence *fence = sync_fence->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 53658cc..e011111 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -25,10 +25,6 @@
 
 struct sync_fence;
 
-struct sync_pt {
-	struct fence base;
-};
-
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *fence;
@@ -89,23 +85,14 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 struct fence *sync_pt_create(struct fence_timeline *parent, int size);
 
 /**
- * sync_pt_free() - frees a sync pt
- * @pt:		sync_pt to free
- *
- * 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_fence_create() - creates a sync fence
  * @name:	name of fence to create
- * @pt:		sync_pt to add to the fence
+ * @fence:	fence to add to the sync_fence
  *
- * Creates a fence containg @pt.  Once this is called, the fence takes
- * ownership of @pt.
+ * Creates a fence containg @fence.  Once this is called, the fence takes
+ * ownership of @fence.
  */
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt);
+struct sync_fence *sync_fence_create(const char *name, struct fence *fence);
 
 /**
  * sync_fence_create_dma() - creates a sync fence from dma-fence
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index f5fd8c3..b8602d2 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 fence_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 fence_timeline *obj)
 
 	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
-		struct sync_pt *pt = (struct sync_pt *)
+		struct fence *fence =
 			container_of(pos, struct fence, child_list);
-		sync_print_pt(s, &pt->base, false);
+		sync_print_fence(s, fence, false);
 	}
 	spin_unlock_irqrestore(&obj->lock, flags);
 }
@@ -163,7 +164,7 @@ static void sync_print_sync_fence(struct seq_file *s,
 		   sync_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_pt(s, sync_fence->cbs[i].fence, true);
+		sync_print_fence(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
@@ -260,7 +261,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_fence *sync_fence;
 	struct sw_sync_create_fence_data data;
 
@@ -272,16 +273,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_fence = sync_fence_create(data.name, pt);
+	sync_fence = sync_fence_create(data.name, fence);
 	if (!sync_fence) {
-		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 59c337f..4f68515 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -29,20 +29,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';
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 12/29] staging/android: remove struct sync_pt
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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    |  7 +++---
 drivers/staging/android/sw_sync.h    |  8 +++----
 drivers/staging/android/sync.c       | 33 ++++++++++++-----------------
 drivers/staging/android/sync.h       | 21 ++++--------------
 drivers/staging/android/sync_debug.c | 41 ++++++++++++++++++------------------
 drivers/staging/android/trace/sync.h | 14 ++++++------
 6 files changed, 53 insertions(+), 71 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index 98f9a29..9d6a5bd 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,7 +34,7 @@ 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);
 
@@ -50,8 +50,7 @@ static int sw_sync_fence_has_signaled(struct fence *fence)
 static int sw_sync_fill_driver_data(struct fence *fence,
 				    void *data, int size)
 {
-	struct sync_pt *sync_pt = (struct sync_pt *)fence;
-	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;
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index cb62298..85ef780 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 b07bc24..417cf9f 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -39,7 +39,7 @@ struct fence *sync_pt_create(struct fence_timeline *obj, int size)
 	unsigned long flags;
 	struct fence *fence;
 
-	if (size < sizeof(struct sync_pt))
+	if (size < sizeof(*fence))
 		return NULL;
 
 	fence = kzalloc(size, GFP_KERNEL);
@@ -57,12 +57,6 @@ struct fence *sync_pt_create(struct fence_timeline *obj, int size)
 }
 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_fence *sync_fence_alloc(int size, const char *name)
 {
 	struct sync_fence *sync_fence;
@@ -101,7 +95,7 @@ static void fence_check_cb_func(struct fence *f, struct fence_cb *cb)
 }
 
 /* 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_fence *sync_fence_create_dma(const char *name, struct fence *fence)
 {
 	struct sync_fence *sync_fence;
 
@@ -113,9 +107,10 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 	sync_fence->num_fences = 1;
 	atomic_set(&sync_fence->status, 1);
 
-	sync_fence->cbs[0].fence = pt;
+	sync_fence->cbs[0].fence = fence;
 	sync_fence->cbs[0].sync_fence = sync_fence;
-	if (fence_add_callback(pt, &sync_fence->cbs[0].cb, fence_check_cb_func))
+	if (fence_add_callback(fence, &sync_fence->cbs[0].cb,
+			       fence_check_cb_func))
 		atomic_dec(&sync_fence->status);
 
 	sync_fence_debug_add(sync_fence);
@@ -124,9 +119,9 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt)
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
 
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt)
+struct sync_fence *sync_fence_create(const char *name, struct fence *fence)
 {
-	return sync_fence_create_dma(name, &pt->base);
+	return sync_fence_create_dma(name, fence);
 }
 EXPORT_SYMBOL(sync_fence_create);
 
@@ -161,14 +156,14 @@ void sync_fence_install(struct sync_fence *sync_fence, int fd)
 EXPORT_SYMBOL(sync_fence_install);
 
 static void sync_fence_add_pt(struct sync_fence *sync_fence,
-			      int *i, struct fence *pt)
+			      int *i, struct fence *fence)
 {
-	sync_fence->cbs[*i].fence = pt;
+	sync_fence->cbs[*i].fence = fence;
 	sync_fence->cbs[*i].sync_fence = sync_fence;
 
-	if (!fence_add_callback(pt, &sync_fence->cbs[*i].cb,
+	if (!fence_add_callback(fence, &sync_fence->cbs[*i].cb,
 				fence_check_cb_func)) {
-		fence_get(pt);
+		fence_get(fence);
 		(*i)++;
 	}
 }
@@ -300,7 +295,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_sync_pt(sync_fence->cbs[i].fence);
+		trace_fence(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -589,9 +584,9 @@ static long sync_fence_ioctl_fence_info(struct sync_fence *sync_fence,
 	len = sizeof(struct sync_fence_info_data);
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		struct fence *pt = sync_fence->cbs[i].fence;
+		struct fence *fence = sync_fence->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 53658cc..e011111 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -25,10 +25,6 @@
 
 struct sync_fence;
 
-struct sync_pt {
-	struct fence base;
-};
-
 struct sync_fence_cb {
 	struct fence_cb cb;
 	struct fence *fence;
@@ -89,23 +85,14 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 struct fence *sync_pt_create(struct fence_timeline *parent, int size);
 
 /**
- * sync_pt_free() - frees a sync pt
- * @pt:		sync_pt to free
- *
- * 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_fence_create() - creates a sync fence
  * @name:	name of fence to create
- * @pt:		sync_pt to add to the fence
+ * @fence:	fence to add to the sync_fence
  *
- * Creates a fence containg @pt.  Once this is called, the fence takes
- * ownership of @pt.
+ * Creates a fence containg @fence.  Once this is called, the fence takes
+ * ownership of @fence.
  */
-struct sync_fence *sync_fence_create(const char *name, struct sync_pt *pt);
+struct sync_fence *sync_fence_create(const char *name, struct fence *fence);
 
 /**
  * sync_fence_create_dma() - creates a sync fence from dma-fence
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index f5fd8c3..b8602d2 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 fence_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 fence_timeline *obj)
 
 	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
-		struct sync_pt *pt = (struct sync_pt *)
+		struct fence *fence =
 			container_of(pos, struct fence, child_list);
-		sync_print_pt(s, &pt->base, false);
+		sync_print_fence(s, fence, false);
 	}
 	spin_unlock_irqrestore(&obj->lock, flags);
 }
@@ -163,7 +164,7 @@ static void sync_print_sync_fence(struct seq_file *s,
 		   sync_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_pt(s, sync_fence->cbs[i].fence, true);
+		sync_print_fence(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
@@ -260,7 +261,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_fence *sync_fence;
 	struct sw_sync_create_fence_data data;
 
@@ -272,16 +273,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_fence = sync_fence_create(data.name, pt);
+	sync_fence = sync_fence_create(data.name, fence);
 	if (!sync_fence) {
-		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 59c337f..4f68515 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/drivers/staging/android/trace/sync.h
@@ -29,20 +29,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';
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 13/29] dma-buf/fence: create fence_default_enable_signaling()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add a default .enable_signaling() op to be used on fence_ops vtable.
fence_default_enable_signaling() checks if the was not signaled yet
and adds it to the active_list.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 22 ++++++++++++++++++++++
 drivers/staging/android/sync.c | 13 +------------
 include/linux/fence.h          |  1 +
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 5dcb94c..51b77ed 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -438,6 +438,28 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb)
 }
 EXPORT_SYMBOL(fence_remove_callback);
 
+/**
+ * fence_default_enable_signaling - default op for .enable_signaling
+ * @fence:	[in]	the fence to enable signaling
+ *
+ * This function checks if the fence was already signaled and if not
+ * adds it to the list of active fences.
+ */
+bool fence_default_enable_signaling(struct fence *fence)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+
+	if (!timeline)
+		return false;
+
+	if (fence->ops->signaled && fence->ops->signaled(fence))
+		return false;
+
+	list_add_tail(&fence->active_list, &timeline->active_list_head);
+	return true;
+}
+EXPORT_SYMBOL(fence_default_enable_signaling);
+
 struct default_wait_cb {
 	struct fence_cb base;
 	struct task_struct *task;
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 417cf9f..87fb93c 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -362,17 +362,6 @@ static bool sync_fence_signaled(struct fence *fence)
 	return ret;
 }
 
-static bool sync_fence_enable_signaling(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (sync_fence_signaled(fence))
-		return false;
-
-	list_add_tail(&fence->active_list, &parent->active_list_head);
-	return true;
-}
-
 static int sync_fence_fill_driver_data(struct fence *fence,
 					  void *data, int size)
 {
@@ -412,7 +401,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = sync_fence_get_driver_name,
 	.get_timeline_name = sync_fence_get_timeline_name,
-	.enable_signaling = sync_fence_enable_signaling,
+	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
 	.release = sync_fence_release,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index a333bf37..73b8c9f 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -295,6 +295,7 @@ static inline void fence_put(struct fence *fence)
 
 int fence_signal(struct fence *fence);
 int fence_signal_locked(struct fence *fence);
+bool fence_default_enable_signaling(struct fence *fence);
 signed long fence_default_wait(struct fence *fence, bool intr, signed long timeout);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 13/29] dma-buf/fence: create fence_default_enable_signaling()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add a default .enable_signaling() op to be used on fence_ops vtable.
fence_default_enable_signaling() checks if the was not signaled yet
and adds it to the active_list.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 22 ++++++++++++++++++++++
 drivers/staging/android/sync.c | 13 +------------
 include/linux/fence.h          |  1 +
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 5dcb94c..51b77ed 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -438,6 +438,28 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb)
 }
 EXPORT_SYMBOL(fence_remove_callback);
 
+/**
+ * fence_default_enable_signaling - default op for .enable_signaling
+ * @fence:	[in]	the fence to enable signaling
+ *
+ * This function checks if the fence was already signaled and if not
+ * adds it to the list of active fences.
+ */
+bool fence_default_enable_signaling(struct fence *fence)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+
+	if (!timeline)
+		return false;
+
+	if (fence->ops->signaled && fence->ops->signaled(fence))
+		return false;
+
+	list_add_tail(&fence->active_list, &timeline->active_list_head);
+	return true;
+}
+EXPORT_SYMBOL(fence_default_enable_signaling);
+
 struct default_wait_cb {
 	struct fence_cb base;
 	struct task_struct *task;
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 417cf9f..87fb93c 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -362,17 +362,6 @@ static bool sync_fence_signaled(struct fence *fence)
 	return ret;
 }
 
-static bool sync_fence_enable_signaling(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (sync_fence_signaled(fence))
-		return false;
-
-	list_add_tail(&fence->active_list, &parent->active_list_head);
-	return true;
-}
-
 static int sync_fence_fill_driver_data(struct fence *fence,
 					  void *data, int size)
 {
@@ -412,7 +401,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = sync_fence_get_driver_name,
 	.get_timeline_name = sync_fence_get_timeline_name,
-	.enable_signaling = sync_fence_enable_signaling,
+	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
 	.release = sync_fence_release,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index a333bf37..73b8c9f 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -295,6 +295,7 @@ static inline void fence_put(struct fence *fence)
 
 int fence_signal(struct fence *fence);
 int fence_signal_locked(struct fence *fence);
+bool fence_default_enable_signaling(struct fence *fence);
 signed long fence_default_wait(struct fence *fence, bool intr, signed long timeout);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 14/29] dma-buf/fence: create fence_default_release()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add a default .release() op to be used on fence_ops vtable.
It removes the fences from any list it was added, removes a timeline ref
and free the fence.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 28 ++++++++++++++++++++++++++++
 drivers/staging/android/sync.c | 18 +-----------------
 include/linux/fence.h          |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 51b77ed..e17397d 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -544,6 +544,34 @@ out:
 }
 EXPORT_SYMBOL(fence_default_wait);
 
+/**
+ * fence_default_release - default .release op
+ * @fence:	[in]	the fence to release
+ *
+ * This function removes the fence from the child_list * and active_list
+ * (if it was active) and drops its timeline ref. Finally it frees the
+ * fence.
+ */
+void fence_default_release(struct fence *fence)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+	unsigned long flags;
+
+	if (!timeline)
+		return;
+
+	spin_lock_irqsave(fence->lock, flags);
+	list_del(&fence->child_list);
+	if (!list_empty(&fence->active_list))
+		list_del(&fence->active_list);
+
+	spin_unlock_irqrestore(fence->lock, flags);
+
+	fence_timeline_put(timeline);
+	fence_free(fence);
+}
+EXPORT_SYMBOL(fence_default_release);
+
 static bool
 fence_test_signaled_any(struct fence **fences, uint32_t count)
 {
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 87fb93c..6cddec9 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -335,22 +335,6 @@ static const char *sync_fence_get_timeline_name(struct fence *fence)
 	return parent->name;
 }
 
-static void sync_fence_release(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-	unsigned long flags;
-
-	spin_lock_irqsave(fence->lock, flags);
-	list_del(&fence->child_list);
-	if (!list_empty(&fence->active_list))
-		list_del(&fence->active_list);
-
-	spin_unlock_irqrestore(fence->lock, flags);
-
-	fence_timeline_put(parent);
-	fence_free(fence);
-}
-
 static bool sync_fence_signaled(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -404,7 +388,7 @@ static const struct fence_ops sync_fence_ops = {
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
-	.release = sync_fence_release,
+	.release = fence_default_release,
 	.fill_driver_data = sync_fence_fill_driver_data,
 	.fence_value_str = sync_fence_value_str,
 	.timeline_value_str = sync_fence_timeline_value_str,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 73b8c9f..0c97014 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -297,6 +297,7 @@ int fence_signal(struct fence *fence);
 int fence_signal_locked(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);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
 bool fence_remove_callback(struct fence *fence, struct fence_cb *cb);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 14/29] dma-buf/fence: create fence_default_release()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Add a default .release() op to be used on fence_ops vtable.
It removes the fences from any list it was added, removes a timeline ref
and free the fence.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 28 ++++++++++++++++++++++++++++
 drivers/staging/android/sync.c | 18 +-----------------
 include/linux/fence.h          |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 51b77ed..e17397d 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -544,6 +544,34 @@ out:
 }
 EXPORT_SYMBOL(fence_default_wait);
 
+/**
+ * fence_default_release - default .release op
+ * @fence:	[in]	the fence to release
+ *
+ * This function removes the fence from the child_list * and active_list
+ * (if it was active) and drops its timeline ref. Finally it frees the
+ * fence.
+ */
+void fence_default_release(struct fence *fence)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+	unsigned long flags;
+
+	if (!timeline)
+		return;
+
+	spin_lock_irqsave(fence->lock, flags);
+	list_del(&fence->child_list);
+	if (!list_empty(&fence->active_list))
+		list_del(&fence->active_list);
+
+	spin_unlock_irqrestore(fence->lock, flags);
+
+	fence_timeline_put(timeline);
+	fence_free(fence);
+}
+EXPORT_SYMBOL(fence_default_release);
+
 static bool
 fence_test_signaled_any(struct fence **fences, uint32_t count)
 {
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 87fb93c..6cddec9 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -335,22 +335,6 @@ static const char *sync_fence_get_timeline_name(struct fence *fence)
 	return parent->name;
 }
 
-static void sync_fence_release(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-	unsigned long flags;
-
-	spin_lock_irqsave(fence->lock, flags);
-	list_del(&fence->child_list);
-	if (!list_empty(&fence->active_list))
-		list_del(&fence->active_list);
-
-	spin_unlock_irqrestore(fence->lock, flags);
-
-	fence_timeline_put(parent);
-	fence_free(fence);
-}
-
 static bool sync_fence_signaled(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -404,7 +388,7 @@ static const struct fence_ops sync_fence_ops = {
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
-	.release = sync_fence_release,
+	.release = fence_default_release,
 	.fill_driver_data = sync_fence_fill_driver_data,
 	.fence_value_str = sync_fence_value_str,
 	.timeline_value_str = sync_fence_timeline_value_str,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 73b8c9f..0c97014 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -297,6 +297,7 @@ int fence_signal(struct fence *fence);
 int fence_signal_locked(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);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
 bool fence_remove_callback(struct fence *fence, struct fence_cb *cb);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 15/29] dma-buf/fence: create fence_default_get_driver_name()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Move driver name handling to fence and create a default function for it.
Returns the driver which the fence belongs.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 19 ++++++++++++++++++-
 drivers/staging/android/sw_sync.c    |  3 +--
 drivers/staging/android/sync.c       |  9 +--------
 drivers/staging/android/sync_debug.c |  2 +-
 include/linux/fence.h                |  8 ++++----
 5 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index e17397d..85b5074 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -56,6 +56,7 @@ EXPORT_SYMBOL(fence_context_alloc);
  * @num:	[in]	amount of contexts to allocate
  * @ops:	[in]	timeline ops of the caller
  * @size:	[in]	size to allocate struct fence_timeline
+ * @drv_name:	[in]	name of the driver
  * @name:	[in]	name of the timeline
  *
  * This function will return the new fence_timeline or NULL in case of error.
@@ -64,7 +65,8 @@ EXPORT_SYMBOL(fence_context_alloc);
  */
 struct fence_timeline *fence_timeline_create(unsigned num,
 					     struct fence_timeline_ops *ops,
-					     int size, const char *name)
+					     int size, const char *drv_name,
+					     const char *name)
 {
 	struct fence_timeline *timeline;
 
@@ -79,6 +81,7 @@ struct fence_timeline *fence_timeline_create(unsigned num,
 	timeline->ops = ops;
 	timeline->context = fence_context_alloc(1);
 	strlcpy(timeline->name, name, sizeof(timeline->name));
+	strlcpy(timeline->drv_name, drv_name, sizeof(timeline->drv_name));
 
 	INIT_LIST_HEAD(&timeline->child_list_head);
 	INIT_LIST_HEAD(&timeline->active_list_head);
@@ -439,6 +442,20 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb)
 EXPORT_SYMBOL(fence_remove_callback);
 
 /**
+ * fence_default_get_driver_name - default .get_driver_name op
+ * @fence:	[in]	the fence to get driver name
+ *
+ * This function returns the name of the driver that the fence belongs.
+ */
+const char *fence_default_get_driver_name(struct fence *fence)
+{
+	struct fence_timeline *parent = fence_parent(fence);
+
+	return parent->drv_name;
+}
+EXPORT_SYMBOL(fence_default_get_driver_name);
+
+/**
  * 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 9d6a5bd..9720267 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -77,7 +77,6 @@ static void sw_sync_fence_value_str(struct fence *fence,
 }
 
 static struct fence_timeline_ops sw_sync_timeline_ops = {
-	.driver_name = "sw_sync",
 	.has_signaled = sw_sync_fence_has_signaled,
 	.fill_driver_data = sw_sync_fill_driver_data,
 	.timeline_value_str = sw_sync_timeline_value_str,
@@ -89,7 +88,7 @@ struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
 		fence_timeline_create(1, &sw_sync_timeline_ops,
 				     sizeof(struct sw_sync_timeline),
-				     name);
+				     "sw_sync", name);
 
 	return obj;
 }
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 6cddec9..c3386a6 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,13 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *sync_fence_get_driver_name(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	return parent->ops->driver_name;
-}
-
 static const char *sync_fence_get_timeline_name(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -383,7 +376,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 }
 
 static const struct fence_ops sync_fence_ops = {
-	.get_driver_name = sync_fence_get_driver_name,
+	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = sync_fence_get_timeline_name,
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index b8602d2..db618ca 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,7 +133,7 @@ static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 	struct list_head *pos;
 	unsigned long flags;
 
-	seq_printf(s, "%s %s", obj->name, obj->ops->driver_name);
+	seq_printf(s, "%s %s", obj->name, obj->drv_name);
 
 	if (obj->ops->timeline_value_str) {
 		char value[64];
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 0c97014..f355c28a 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -36,7 +36,6 @@ struct fence_ops;
 struct fence_cb;
 /**
  * struct fence_timeline_ops - fence context implementation ops
- * @driver_name:	name of the implementation
  * @has_signaled:	returns:
  *			  1 if pt has signaled
  *			  0 if pt has not signaled
@@ -49,8 +48,6 @@ struct fence_cb;
  * @pt_value_str:	fill str with the value of the sync_pt
  */
 struct fence_timeline_ops {
-	const char *driver_name;
-
 	/* required */
 	int (*has_signaled)(struct fence *fence);
 
@@ -80,6 +77,7 @@ struct fence_timeline_ops {
 struct fence_timeline {
 	struct kref		kref;
 	char			name[32];
+	char			drv_name[32];
 	const struct fence_timeline_ops *ops;
 	bool			destroyed;
 	int			value;
@@ -94,7 +92,8 @@ struct fence_timeline {
 
 struct fence_timeline *fence_timeline_create(unsigned num,
 					     struct fence_timeline_ops *ops,
-					     int size, const char *name);
+					     int size, const char *drv_name,
+					     const char *name);
 void fence_timeline_get(struct fence_timeline *timeline);
 void fence_timeline_put(struct fence_timeline *timeline);
 void fence_timeline_destroy(struct fence_timeline *timeline);
@@ -295,6 +294,7 @@ static inline void fence_put(struct fence *fence)
 
 int fence_signal(struct fence *fence);
 int fence_signal_locked(struct fence *fence);
+const char *fence_default_get_driver_name(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

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 15/29] dma-buf/fence: create fence_default_get_driver_name()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Move driver name handling to fence and create a default function for it.
Returns the driver which the fence belongs.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 19 ++++++++++++++++++-
 drivers/staging/android/sw_sync.c    |  3 +--
 drivers/staging/android/sync.c       |  9 +--------
 drivers/staging/android/sync_debug.c |  2 +-
 include/linux/fence.h                |  8 ++++----
 5 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index e17397d..85b5074 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -56,6 +56,7 @@ EXPORT_SYMBOL(fence_context_alloc);
  * @num:	[in]	amount of contexts to allocate
  * @ops:	[in]	timeline ops of the caller
  * @size:	[in]	size to allocate struct fence_timeline
+ * @drv_name:	[in]	name of the driver
  * @name:	[in]	name of the timeline
  *
  * This function will return the new fence_timeline or NULL in case of error.
@@ -64,7 +65,8 @@ EXPORT_SYMBOL(fence_context_alloc);
  */
 struct fence_timeline *fence_timeline_create(unsigned num,
 					     struct fence_timeline_ops *ops,
-					     int size, const char *name)
+					     int size, const char *drv_name,
+					     const char *name)
 {
 	struct fence_timeline *timeline;
 
@@ -79,6 +81,7 @@ struct fence_timeline *fence_timeline_create(unsigned num,
 	timeline->ops = ops;
 	timeline->context = fence_context_alloc(1);
 	strlcpy(timeline->name, name, sizeof(timeline->name));
+	strlcpy(timeline->drv_name, drv_name, sizeof(timeline->drv_name));
 
 	INIT_LIST_HEAD(&timeline->child_list_head);
 	INIT_LIST_HEAD(&timeline->active_list_head);
@@ -439,6 +442,20 @@ fence_remove_callback(struct fence *fence, struct fence_cb *cb)
 EXPORT_SYMBOL(fence_remove_callback);
 
 /**
+ * fence_default_get_driver_name - default .get_driver_name op
+ * @fence:	[in]	the fence to get driver name
+ *
+ * This function returns the name of the driver that the fence belongs.
+ */
+const char *fence_default_get_driver_name(struct fence *fence)
+{
+	struct fence_timeline *parent = fence_parent(fence);
+
+	return parent->drv_name;
+}
+EXPORT_SYMBOL(fence_default_get_driver_name);
+
+/**
  * 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 9d6a5bd..9720267 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -77,7 +77,6 @@ static void sw_sync_fence_value_str(struct fence *fence,
 }
 
 static struct fence_timeline_ops sw_sync_timeline_ops = {
-	.driver_name = "sw_sync",
 	.has_signaled = sw_sync_fence_has_signaled,
 	.fill_driver_data = sw_sync_fill_driver_data,
 	.timeline_value_str = sw_sync_timeline_value_str,
@@ -89,7 +88,7 @@ struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
 		fence_timeline_create(1, &sw_sync_timeline_ops,
 				     sizeof(struct sw_sync_timeline),
-				     name);
+				     "sw_sync", name);
 
 	return obj;
 }
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 6cddec9..c3386a6 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,13 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *sync_fence_get_driver_name(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	return parent->ops->driver_name;
-}
-
 static const char *sync_fence_get_timeline_name(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -383,7 +376,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 }
 
 static const struct fence_ops sync_fence_ops = {
-	.get_driver_name = sync_fence_get_driver_name,
+	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = sync_fence_get_timeline_name,
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index b8602d2..db618ca 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,7 +133,7 @@ static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 	struct list_head *pos;
 	unsigned long flags;
 
-	seq_printf(s, "%s %s", obj->name, obj->ops->driver_name);
+	seq_printf(s, "%s %s", obj->name, obj->drv_name);
 
 	if (obj->ops->timeline_value_str) {
 		char value[64];
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 0c97014..f355c28a 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -36,7 +36,6 @@ struct fence_ops;
 struct fence_cb;
 /**
  * struct fence_timeline_ops - fence context implementation ops
- * @driver_name:	name of the implementation
  * @has_signaled:	returns:
  *			  1 if pt has signaled
  *			  0 if pt has not signaled
@@ -49,8 +48,6 @@ struct fence_cb;
  * @pt_value_str:	fill str with the value of the sync_pt
  */
 struct fence_timeline_ops {
-	const char *driver_name;
-
 	/* required */
 	int (*has_signaled)(struct fence *fence);
 
@@ -80,6 +77,7 @@ struct fence_timeline_ops {
 struct fence_timeline {
 	struct kref		kref;
 	char			name[32];
+	char			drv_name[32];
 	const struct fence_timeline_ops *ops;
 	bool			destroyed;
 	int			value;
@@ -94,7 +92,8 @@ struct fence_timeline {
 
 struct fence_timeline *fence_timeline_create(unsigned num,
 					     struct fence_timeline_ops *ops,
-					     int size, const char *name);
+					     int size, const char *drv_name,
+					     const char *name);
 void fence_timeline_get(struct fence_timeline *timeline);
 void fence_timeline_put(struct fence_timeline *timeline);
 void fence_timeline_destroy(struct fence_timeline *timeline);
@@ -295,6 +294,7 @@ static inline void fence_put(struct fence *fence)
 
 int fence_signal(struct fence *fence);
 int fence_signal_locked(struct fence *fence);
+const char *fence_default_get_driver_name(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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 16/29] dma-buf/fence: create fence_default_timeline_name()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The fence timeline struct already receives the name of the timeline so
we can use a default function to return the timeline name.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 14 ++++++++++++++
 drivers/staging/android/sync.c |  9 +--------
 include/linux/fence.h          |  1 +
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 85b5074..f77d6a9 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -456,6 +456,20 @@ const char *fence_default_get_driver_name(struct fence *fence)
 EXPORT_SYMBOL(fence_default_get_driver_name);
 
 /**
+ * fence_default_get_timeline_name - default get_timeline_name op
+ * @fence:	[in]	the fence to retrieve timeline name
+ *
+ * This function returns the name of the timeline which the fence belongs to.
+ */
+const char *fence_default_get_timeline_name(struct fence *fence)
+{
+	struct fence_timeline *parent = fence_parent(fence);
+
+	return parent->name;
+}
+EXPORT_SYMBOL(fence_default_get_timeline_name);
+
+/**
  * fence_default_enable_signaling - default op for .enable_signaling
  * @fence:	[in]	the fence to enable signaling
  *
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c3386a6..f8b3c6b 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,13 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *sync_fence_get_timeline_name(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	return parent->name;
-}
-
 static bool sync_fence_signaled(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -377,7 +370,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
-	.get_timeline_name = sync_fence_get_timeline_name,
+	.get_timeline_name = fence_default_get_timeline_name,
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index f355c28a..e8f9f12 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -295,6 +295,7 @@ static inline void fence_put(struct fence *fence)
 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_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

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 16/29] dma-buf/fence: create fence_default_timeline_name()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The fence timeline struct already receives the name of the timeline so
we can use a default function to return the timeline name.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 14 ++++++++++++++
 drivers/staging/android/sync.c |  9 +--------
 include/linux/fence.h          |  1 +
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 85b5074..f77d6a9 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -456,6 +456,20 @@ const char *fence_default_get_driver_name(struct fence *fence)
 EXPORT_SYMBOL(fence_default_get_driver_name);
 
 /**
+ * fence_default_get_timeline_name - default get_timeline_name op
+ * @fence:	[in]	the fence to retrieve timeline name
+ *
+ * This function returns the name of the timeline which the fence belongs to.
+ */
+const char *fence_default_get_timeline_name(struct fence *fence)
+{
+	struct fence_timeline *parent = fence_parent(fence);
+
+	return parent->name;
+}
+EXPORT_SYMBOL(fence_default_get_timeline_name);
+
+/**
  * fence_default_enable_signaling - default op for .enable_signaling
  * @fence:	[in]	the fence to enable signaling
  *
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index c3386a6..f8b3c6b 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,13 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static const char *sync_fence_get_timeline_name(struct fence *fence)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	return parent->name;
-}
-
 static bool sync_fence_signaled(struct fence *fence)
 {
 	struct fence_timeline *parent = fence_parent(fence);
@@ -377,7 +370,7 @@ static void sync_fence_timeline_value_str(struct fence *fence,
 
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
-	.get_timeline_name = sync_fence_get_timeline_name,
+	.get_timeline_name = fence_default_get_timeline_name,
 	.enable_signaling = fence_default_enable_signaling,
 	.signaled = sync_fence_signaled,
 	.wait = fence_default_wait,
diff --git a/include/linux/fence.h b/include/linux/fence.h
index f355c28a..e8f9f12 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -295,6 +295,7 @@ static inline void fence_put(struct fence *fence)
 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_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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 17/29] dma-buf/fence: store last signaled value on fence timeline
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
                   ` (15 preceding siblings ...)
  2016-01-15 14:55   ` Gustavo Padovan
@ 2016-01-15 14:55 ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                   ` (14 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

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@collabora.co.uk>
---
 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

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 18/29] dma-buf/fence: create default .fence_value_str() and .timeline_value_str()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Provide simple default functions to help users retrieve the values of the
fence and the timeline.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 31 +++++++++++++++++++++++++++++++
 drivers/staging/android/sw_sync.c    | 18 ------------------
 drivers/staging/android/sync.c       | 30 ++----------------------------
 drivers/staging/android/sync_debug.c | 11 +----------
 include/linux/fence.h                | 10 ++--------
 include/trace/events/fence.h         | 12 +++---------
 6 files changed, 39 insertions(+), 73 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 786c987..9fdeae8 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -620,6 +620,37 @@ void fence_default_release(struct fence *fence)
 }
 EXPORT_SYMBOL(fence_default_release);
 
+/**
+ * fence_default_value_str - default .fence_value_str fence ops
+ * @fence:	[in]	the fence to get the value from
+ * @str:	[out]	the string pointer to write the value
+ * @size:	[in]	the size of the allocated string
+ *
+ * This functions returns a string containing the value of the fence.
+ */
+void fence_default_value_str(struct fence *fence, char *str, int size)
+{
+	snprintf(str, size, "%d", fence->seqno);
+}
+EXPORT_SYMBOL(fence_default_value_str);
+
+/**
+ * fence_default_timeline_value_str - default .timeline_value_str fence ops
+ * @fence:	[in]	the timeline child fence
+ * @str:	[out]	the string pointer to write the value
+ * @size:	[in]	the size of the allocated string
+ *
+ * This functions returns a string containing the value of the last signaled
+ * fence in this timeline.
+ */
+void fence_default_timeline_value_str(struct fence *fence, char *str, int size)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+
+	snprintf(str, size, "%d", timeline->value);
+}
+EXPORT_SYMBOL(fence_default_timeline_value_str);
+
 static bool
 fence_test_signaled_any(struct fence **fences, uint32_t count)
 {
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index bed6801..cfd7a18 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -51,26 +51,8 @@ static int sw_sync_fill_driver_data(struct fence *fence,
 	return sizeof(pt->value);
 }
 
-static void sw_sync_timeline_value_str(struct fence_timeline *fence_timeline,
-				       char *str, int size)
-{
-	struct sw_sync_timeline *timeline =
-		(struct sw_sync_timeline *)fence_timeline;
-	snprintf(str, size, "%d", timeline->value);
-}
-
-static void sw_sync_fence_value_str(struct fence *fence,
-				 char *str, int size)
-{
-	struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-	snprintf(str, size, "%d", pt->value);
-}
-
 static struct fence_timeline_ops sw_sync_timeline_ops = {
 	.fill_driver_data = sw_sync_fill_driver_data,
-	.timeline_value_str = sw_sync_timeline_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/sync.c b/drivers/staging/android/sync.c
index 8216635..147a494 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -331,32 +331,6 @@ static int sync_fence_fill_driver_data(struct fence *fence,
 	return parent->ops->fill_driver_data(fence, data, size);
 }
 
-static void sync_fence_value_str(struct fence *fence,
-				    char *str, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->fence_value_str) {
-		if (size)
-			*str = 0;
-		return;
-	}
-	parent->ops->fence_value_str(fence, str, size);
-}
-
-static void sync_fence_timeline_value_str(struct fence *fence,
-					     char *str, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->timeline_value_str) {
-		if (size)
-			*str = 0;
-		return;
-	}
-	parent->ops->timeline_value_str(parent, str, size);
-}
-
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -365,8 +339,8 @@ static const struct fence_ops sync_fence_ops = {
 	.wait = fence_default_wait,
 	.release = fence_default_release,
 	.fill_driver_data = sync_fence_fill_driver_data,
-	.fence_value_str = sync_fence_value_str,
-	.timeline_value_str = sync_fence_timeline_value_str,
+	.fence_value_str = fence_default_value_str,
+	.timeline_value_str = fence_default_timeline_value_str,
 };
 
 static void sync_fence_free(struct kref *kref)
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index db618ca..89b334c 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,16 +133,7 @@ static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 	struct list_head *pos;
 	unsigned long flags;
 
-	seq_printf(s, "%s %s", obj->name, obj->drv_name);
-
-	if (obj->ops->timeline_value_str) {
-		char value[64];
-
-		obj->ops->timeline_value_str(obj, value, sizeof(value));
-		seq_printf(s, ": %s", value);
-	}
-
-	seq_puts(s, "\n");
+	seq_printf(s, "%s %s: %d\n", obj->name, obj->drv_name, obj->value);
 
 	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
diff --git a/include/linux/fence.h b/include/linux/fence.h
index e71545e..5371beb 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -40,19 +40,11 @@ struct fence_cb;
  *			  should return an error if there is not enough room
  *			  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
  */
 struct fence_timeline_ops {
 	/* optional */
 	int (*fill_driver_data)(struct fence *fence, void *data, int size);
-
-	/* optional */
-	void (*timeline_value_str)(struct fence_timeline *timeline, char *str,
-				   int size);
-
-	/* optional */
-	void (*fence_value_str)(struct fence *fence, char *str, int size);
 };
 
 /**
@@ -293,6 +285,8 @@ 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);
+void fence_default_value_str(struct fence *fence, char *str, int size);
+void fence_default_timeline_value_str(struct fence *fence, char *str, int size);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
 bool fence_remove_callback(struct fence *fence, struct fence_cb *cb);
diff --git a/include/trace/events/fence.h b/include/trace/events/fence.h
index c4d01de..e1ca808 100644
--- a/include/trace/events/fence.h
+++ b/include/trace/events/fence.h
@@ -55,21 +55,15 @@ TRACE_EVENT(fence_timeline,
 
 	TP_STRUCT__entry(
 			__string(name, timeline->name)
-			__array(char, value, 32)
+			__field(unsigned int, value)
 	),
 
 	TP_fast_assign(
 			__assign_str(name, timeline->name);
-			if (timeline->ops->timeline_value_str) {
-				timeline->ops->timeline_value_str(timeline,
-							__entry->value,
-							sizeof(__entry->value));
-			} else {
-				__entry->value[0] = '\0';
-			}
+			__entry->value = timeline->value;
 	),
 
-	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
+	TP_printk("name=%s value=%u", __get_str(name), __entry->value)
 );
 
 DECLARE_EVENT_CLASS(fence,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 18/29] dma-buf/fence: create default .fence_value_str() and .timeline_value_str()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Provide simple default functions to help users retrieve the values of the
fence and the timeline.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c              | 31 +++++++++++++++++++++++++++++++
 drivers/staging/android/sw_sync.c    | 18 ------------------
 drivers/staging/android/sync.c       | 30 ++----------------------------
 drivers/staging/android/sync_debug.c | 11 +----------
 include/linux/fence.h                | 10 ++--------
 include/trace/events/fence.h         | 12 +++---------
 6 files changed, 39 insertions(+), 73 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 786c987..9fdeae8 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -620,6 +620,37 @@ void fence_default_release(struct fence *fence)
 }
 EXPORT_SYMBOL(fence_default_release);
 
+/**
+ * fence_default_value_str - default .fence_value_str fence ops
+ * @fence:	[in]	the fence to get the value from
+ * @str:	[out]	the string pointer to write the value
+ * @size:	[in]	the size of the allocated string
+ *
+ * This functions returns a string containing the value of the fence.
+ */
+void fence_default_value_str(struct fence *fence, char *str, int size)
+{
+	snprintf(str, size, "%d", fence->seqno);
+}
+EXPORT_SYMBOL(fence_default_value_str);
+
+/**
+ * fence_default_timeline_value_str - default .timeline_value_str fence ops
+ * @fence:	[in]	the timeline child fence
+ * @str:	[out]	the string pointer to write the value
+ * @size:	[in]	the size of the allocated string
+ *
+ * This functions returns a string containing the value of the last signaled
+ * fence in this timeline.
+ */
+void fence_default_timeline_value_str(struct fence *fence, char *str, int size)
+{
+	struct fence_timeline *timeline = fence_parent(fence);
+
+	snprintf(str, size, "%d", timeline->value);
+}
+EXPORT_SYMBOL(fence_default_timeline_value_str);
+
 static bool
 fence_test_signaled_any(struct fence **fences, uint32_t count)
 {
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index bed6801..cfd7a18 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -51,26 +51,8 @@ static int sw_sync_fill_driver_data(struct fence *fence,
 	return sizeof(pt->value);
 }
 
-static void sw_sync_timeline_value_str(struct fence_timeline *fence_timeline,
-				       char *str, int size)
-{
-	struct sw_sync_timeline *timeline =
-		(struct sw_sync_timeline *)fence_timeline;
-	snprintf(str, size, "%d", timeline->value);
-}
-
-static void sw_sync_fence_value_str(struct fence *fence,
-				 char *str, int size)
-{
-	struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-	snprintf(str, size, "%d", pt->value);
-}
-
 static struct fence_timeline_ops sw_sync_timeline_ops = {
 	.fill_driver_data = sw_sync_fill_driver_data,
-	.timeline_value_str = sw_sync_timeline_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/sync.c b/drivers/staging/android/sync.c
index 8216635..147a494 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -331,32 +331,6 @@ static int sync_fence_fill_driver_data(struct fence *fence,
 	return parent->ops->fill_driver_data(fence, data, size);
 }
 
-static void sync_fence_value_str(struct fence *fence,
-				    char *str, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->fence_value_str) {
-		if (size)
-			*str = 0;
-		return;
-	}
-	parent->ops->fence_value_str(fence, str, size);
-}
-
-static void sync_fence_timeline_value_str(struct fence *fence,
-					     char *str, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->timeline_value_str) {
-		if (size)
-			*str = 0;
-		return;
-	}
-	parent->ops->timeline_value_str(parent, str, size);
-}
-
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -365,8 +339,8 @@ static const struct fence_ops sync_fence_ops = {
 	.wait = fence_default_wait,
 	.release = fence_default_release,
 	.fill_driver_data = sync_fence_fill_driver_data,
-	.fence_value_str = sync_fence_value_str,
-	.timeline_value_str = sync_fence_timeline_value_str,
+	.fence_value_str = fence_default_value_str,
+	.timeline_value_str = fence_default_timeline_value_str,
 };
 
 static void sync_fence_free(struct kref *kref)
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index db618ca..89b334c 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -133,16 +133,7 @@ static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
 	struct list_head *pos;
 	unsigned long flags;
 
-	seq_printf(s, "%s %s", obj->name, obj->drv_name);
-
-	if (obj->ops->timeline_value_str) {
-		char value[64];
-
-		obj->ops->timeline_value_str(obj, value, sizeof(value));
-		seq_printf(s, ": %s", value);
-	}
-
-	seq_puts(s, "\n");
+	seq_printf(s, "%s %s: %d\n", obj->name, obj->drv_name, obj->value);
 
 	spin_lock_irqsave(&obj->lock, flags);
 	list_for_each(pos, &obj->child_list_head) {
diff --git a/include/linux/fence.h b/include/linux/fence.h
index e71545e..5371beb 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -40,19 +40,11 @@ struct fence_cb;
  *			  should return an error if there is not enough room
  *			  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
  */
 struct fence_timeline_ops {
 	/* optional */
 	int (*fill_driver_data)(struct fence *fence, void *data, int size);
-
-	/* optional */
-	void (*timeline_value_str)(struct fence_timeline *timeline, char *str,
-				   int size);
-
-	/* optional */
-	void (*fence_value_str)(struct fence *fence, char *str, int size);
 };
 
 /**
@@ -293,6 +285,8 @@ 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);
+void fence_default_value_str(struct fence *fence, char *str, int size);
+void fence_default_timeline_value_str(struct fence *fence, char *str, int size);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
 		       fence_func_t func);
 bool fence_remove_callback(struct fence *fence, struct fence_cb *cb);
diff --git a/include/trace/events/fence.h b/include/trace/events/fence.h
index c4d01de..e1ca808 100644
--- a/include/trace/events/fence.h
+++ b/include/trace/events/fence.h
@@ -55,21 +55,15 @@ TRACE_EVENT(fence_timeline,
 
 	TP_STRUCT__entry(
 			__string(name, timeline->name)
-			__array(char, value, 32)
+			__field(unsigned int, value)
 	),
 
 	TP_fast_assign(
 			__assign_str(name, timeline->name);
-			if (timeline->ops->timeline_value_str) {
-				timeline->ops->timeline_value_str(timeline,
-							__entry->value,
-							sizeof(__entry->value));
-			} else {
-				__entry->value[0] = '\0';
-			}
+			__entry->value = timeline->value;
 	),
 
-	TP_printk("name=%s value=%s", __get_str(name), __entry->value)
+	TP_printk("name=%s value=%u", __get_str(name), __entry->value)
 );
 
 DECLARE_EVENT_CLASS(fence,
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 19/29] dma-buf/fence: create fence_default_fill_driver_data()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The value needed by sw_sync is now inside struct fence so we create a
default ops to reply that value for us.
---
 drivers/dma-buf/fence.c        | 21 +++++++++++++++++++++
 drivers/staging/android/sync.c | 12 +-----------
 include/linux/fence.h          |  1 +
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 9fdeae8..d9089a0 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -621,6 +621,27 @@ void fence_default_release(struct fence *fence)
 EXPORT_SYMBOL(fence_default_release);
 
 /**
+ * fence_default_fill_driver_data - fence default .fill_driver_data ops
+ * @fence:	[in]	the fence to get the data from
+ * @data:	[out]	the data pointer to write the data
+ * @size:	[in]	the size of the allocated data
+ *
+ * This function return a driver data. In the case the fence seqno value.
+ * It is used at least by the sw_sync to send fence information to the
+ * userspace.
+ */
+int fence_default_fill_driver_data(struct fence *fence, void *data, int size)
+{
+	if (size < sizeof(fence->seqno))
+		return -ENOMEM;
+
+	memcpy(data, &fence->seqno, sizeof(fence->seqno));
+
+	return sizeof(fence->seqno);
+}
+EXPORT_SYMBOL(fence_default_fill_driver_data);
+
+/**
  * fence_default_value_str - default .fence_value_str fence ops
  * @fence:	[in]	the fence to get the value from
  * @str:	[out]	the string pointer to write the value
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 147a494..a275108 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,16 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static int sync_fence_fill_driver_data(struct fence *fence,
-					  void *data, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->fill_driver_data)
-		return 0;
-	return parent->ops->fill_driver_data(fence, data, size);
-}
-
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -338,7 +328,7 @@ static const struct fence_ops sync_fence_ops = {
 	.signaled = fence_default_signaled,
 	.wait = fence_default_wait,
 	.release = fence_default_release,
-	.fill_driver_data = sync_fence_fill_driver_data,
+	.fill_driver_data = fence_default_fill_driver_data,
 	.fence_value_str = fence_default_value_str,
 	.timeline_value_str = fence_default_timeline_value_str,
 };
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 5371beb..04438c3 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -285,6 +285,7 @@ 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);
+int fence_default_fill_driver_data(struct fence *fence, void *data, int size);
 void fence_default_value_str(struct fence *fence, char *str, int size);
 void fence_default_timeline_value_str(struct fence *fence, char *str, int size);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 19/29] dma-buf/fence: create fence_default_fill_driver_data()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The value needed by sw_sync is now inside struct fence so we create a
default ops to reply that value for us.
---
 drivers/dma-buf/fence.c        | 21 +++++++++++++++++++++
 drivers/staging/android/sync.c | 12 +-----------
 include/linux/fence.h          |  1 +
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 9fdeae8..d9089a0 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -621,6 +621,27 @@ void fence_default_release(struct fence *fence)
 EXPORT_SYMBOL(fence_default_release);
 
 /**
+ * fence_default_fill_driver_data - fence default .fill_driver_data ops
+ * @fence:	[in]	the fence to get the data from
+ * @data:	[out]	the data pointer to write the data
+ * @size:	[in]	the size of the allocated data
+ *
+ * This function return a driver data. In the case the fence seqno value.
+ * It is used at least by the sw_sync to send fence information to the
+ * userspace.
+ */
+int fence_default_fill_driver_data(struct fence *fence, void *data, int size)
+{
+	if (size < sizeof(fence->seqno))
+		return -ENOMEM;
+
+	memcpy(data, &fence->seqno, sizeof(fence->seqno));
+
+	return sizeof(fence->seqno);
+}
+EXPORT_SYMBOL(fence_default_fill_driver_data);
+
+/**
  * fence_default_value_str - default .fence_value_str fence ops
  * @fence:	[in]	the fence to get the value from
  * @str:	[out]	the string pointer to write the value
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 147a494..a275108 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -321,16 +321,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-static int sync_fence_fill_driver_data(struct fence *fence,
-					  void *data, int size)
-{
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (!parent->ops->fill_driver_data)
-		return 0;
-	return parent->ops->fill_driver_data(fence, data, size);
-}
-
 static const struct fence_ops sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -338,7 +328,7 @@ static const struct fence_ops sync_fence_ops = {
 	.signaled = fence_default_signaled,
 	.wait = fence_default_wait,
 	.release = fence_default_release,
-	.fill_driver_data = sync_fence_fill_driver_data,
+	.fill_driver_data = fence_default_fill_driver_data,
 	.fence_value_str = fence_default_value_str,
 	.timeline_value_str = fence_default_timeline_value_str,
 };
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 5371beb..04438c3 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -285,6 +285,7 @@ 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);
+int fence_default_fill_driver_data(struct fence *fence, void *data, int size);
 void fence_default_value_str(struct fence *fence, char *str, int size);
 void fence_default_timeline_value_str(struct fence *fence, char *str, int size);
 int fence_add_callback(struct fence *fence, struct fence_cb *cb,
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 20/29] dma-buf/fence: remove fence_timeline_ops
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

fence_timeline_ops was just workarounding over fence_ops and was used
chained in the fence ops. So remove it all to simplify the fence code
flow.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c           |  7 ++-----
 drivers/staging/android/sw_sync.c | 20 +-------------------
 include/linux/fence.h             | 19 ++-----------------
 3 files changed, 5 insertions(+), 41 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index d9089a0..ec51146 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -54,7 +54,6 @@ EXPORT_SYMBOL(fence_context_alloc);
 /**
  * fence_timeline_create - create a new fence_timeline
  * @num:	[in]	amount of contexts to allocate
- * @ops:	[in]	timeline ops of the caller
  * @size:	[in]	size to allocate struct fence_timeline
  * @drv_name:	[in]	name of the driver
  * @name:	[in]	name of the timeline
@@ -63,9 +62,8 @@ EXPORT_SYMBOL(fence_context_alloc);
  * It allocs and initializes a new fence_timeline with a proper fence context
  * number assigned to it.
  */
-struct fence_timeline *fence_timeline_create(unsigned num,
-					     struct fence_timeline_ops *ops,
-					     int size, const char *drv_name,
+struct fence_timeline *fence_timeline_create(unsigned num, int size,
+					     const char *drv_name,
 					     const char *name)
 {
 	struct fence_timeline *timeline;
@@ -78,7 +76,6 @@ struct fence_timeline *fence_timeline_create(unsigned num,
 		return NULL;
 
 	kref_init(&timeline->kref);
-	timeline->ops = ops;
 	timeline->context = fence_context_alloc(1);
 	strlcpy(timeline->name, name, sizeof(timeline->name));
 	strlcpy(timeline->drv_name, drv_name, sizeof(timeline->drv_name));
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index cfd7a18..b9f8c51 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,28 +38,10 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static int sw_sync_fill_driver_data(struct fence *fence,
-				    void *data, int size)
-{
-	struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-	if (size < sizeof(pt->value))
-		return -ENOMEM;
-
-	memcpy(data, &pt->value, sizeof(pt->value));
-
-	return sizeof(pt->value);
-}
-
-static struct fence_timeline_ops sw_sync_timeline_ops = {
-	.fill_driver_data = sw_sync_fill_driver_data,
-};
-
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 {
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		fence_timeline_create(1, &sw_sync_timeline_ops,
-				     sizeof(struct sw_sync_timeline),
+		fence_timeline_create(1, sizeof(struct sw_sync_timeline),
 				     "sw_sync", name);
 
 	return obj;
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 04438c3..8908433 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -30,22 +30,9 @@
 #include <linux/printk.h>
 #include <linux/rcupdate.h>
 
-struct fence_timeline;
 struct fence;
 struct fence_ops;
 struct fence_cb;
-/**
- * struct fence_timeline_ops - fence context implementation ops
- * @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
- *			  to userspace by SYNC_IOC_FENCE_INFO.
- * @pt_value_str:	fill str with the value of the sync_pt
- */
-struct fence_timeline_ops {
-	/* optional */
-	int (*fill_driver_data)(struct fence *fence, void *data, int size);
-};
 
 /**
  * struct fence_timeline - timeline for software synchronization primitive
@@ -63,7 +50,6 @@ struct fence_timeline {
 	struct kref		kref;
 	char			name[32];
 	char			drv_name[32];
-	const struct fence_timeline_ops *ops;
 	bool			destroyed;
 	unsigned int		value;
 	int			context;
@@ -75,9 +61,8 @@ struct fence_timeline {
 #endif
 };
 
-struct fence_timeline *fence_timeline_create(unsigned num,
-					     struct fence_timeline_ops *ops,
-					     int size, const char *drv_name,
+struct fence_timeline *fence_timeline_create(unsigned num, int size,
+					     const char *drv_name,
 					     const char *name);
 void fence_timeline_get(struct fence_timeline *timeline);
 void fence_timeline_put(struct fence_timeline *timeline);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 20/29] dma-buf/fence: remove fence_timeline_ops
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

fence_timeline_ops was just workarounding over fence_ops and was used
chained in the fence ops. So remove it all to simplify the fence code
flow.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c           |  7 ++-----
 drivers/staging/android/sw_sync.c | 20 +-------------------
 include/linux/fence.h             | 19 ++-----------------
 3 files changed, 5 insertions(+), 41 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index d9089a0..ec51146 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -54,7 +54,6 @@ EXPORT_SYMBOL(fence_context_alloc);
 /**
  * fence_timeline_create - create a new fence_timeline
  * @num:	[in]	amount of contexts to allocate
- * @ops:	[in]	timeline ops of the caller
  * @size:	[in]	size to allocate struct fence_timeline
  * @drv_name:	[in]	name of the driver
  * @name:	[in]	name of the timeline
@@ -63,9 +62,8 @@ EXPORT_SYMBOL(fence_context_alloc);
  * It allocs and initializes a new fence_timeline with a proper fence context
  * number assigned to it.
  */
-struct fence_timeline *fence_timeline_create(unsigned num,
-					     struct fence_timeline_ops *ops,
-					     int size, const char *drv_name,
+struct fence_timeline *fence_timeline_create(unsigned num, int size,
+					     const char *drv_name,
 					     const char *name)
 {
 	struct fence_timeline *timeline;
@@ -78,7 +76,6 @@ struct fence_timeline *fence_timeline_create(unsigned num,
 		return NULL;
 
 	kref_init(&timeline->kref);
-	timeline->ops = ops;
 	timeline->context = fence_context_alloc(1);
 	strlcpy(timeline->name, name, sizeof(timeline->name));
 	strlcpy(timeline->drv_name, drv_name, sizeof(timeline->drv_name));
diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index cfd7a18..b9f8c51 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -38,28 +38,10 @@ struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-static int sw_sync_fill_driver_data(struct fence *fence,
-				    void *data, int size)
-{
-	struct sw_sync_pt *pt = (struct sw_sync_pt *)fence;
-
-	if (size < sizeof(pt->value))
-		return -ENOMEM;
-
-	memcpy(data, &pt->value, sizeof(pt->value));
-
-	return sizeof(pt->value);
-}
-
-static struct fence_timeline_ops sw_sync_timeline_ops = {
-	.fill_driver_data = sw_sync_fill_driver_data,
-};
-
 struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
 {
 	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		fence_timeline_create(1, &sw_sync_timeline_ops,
-				     sizeof(struct sw_sync_timeline),
+		fence_timeline_create(1, sizeof(struct sw_sync_timeline),
 				     "sw_sync", name);
 
 	return obj;
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 04438c3..8908433 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -30,22 +30,9 @@
 #include <linux/printk.h>
 #include <linux/rcupdate.h>
 
-struct fence_timeline;
 struct fence;
 struct fence_ops;
 struct fence_cb;
-/**
- * struct fence_timeline_ops - fence context implementation ops
- * @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
- *			  to userspace by SYNC_IOC_FENCE_INFO.
- * @pt_value_str:	fill str with the value of the sync_pt
- */
-struct fence_timeline_ops {
-	/* optional */
-	int (*fill_driver_data)(struct fence *fence, void *data, int size);
-};
 
 /**
  * struct fence_timeline - timeline for software synchronization primitive
@@ -63,7 +50,6 @@ struct fence_timeline {
 	struct kref		kref;
 	char			name[32];
 	char			drv_name[32];
-	const struct fence_timeline_ops *ops;
 	bool			destroyed;
 	unsigned int		value;
 	int			context;
@@ -75,9 +61,8 @@ struct fence_timeline {
 #endif
 };
 
-struct fence_timeline *fence_timeline_create(unsigned num,
-					     struct fence_timeline_ops *ops,
-					     int size, const char *drv_name,
+struct fence_timeline *fence_timeline_create(unsigned num, int size,
+					     const char *drv_name,
 					     const char *name);
 void fence_timeline_get(struct fence_timeline *timeline);
 void fence_timeline_put(struct fence_timeline *timeline);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 21/29] dma-buf/fence: add fence_create_on_timeline()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

This functions in intended to replace sync_pt_create() and it does
exactly the same thing sync_pt_create() did.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/staging/android/sync.c | 20 ++------------------
 include/linux/fence.h          |  3 +++
 3 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index ec51146..0a07fcb 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -768,6 +768,44 @@ err_free_cb:
 EXPORT_SYMBOL(fence_wait_any_timeout);
 
 /**
+ * fence_create_on_timeline - create a fence and add it to the timeline
+ * or until timeout elapses
+ * @obj:	[in]	timeline object
+ * @ops:	[in]	fence_ops to use
+ * @size:	[in]	size to allocate struct fence
+ * @value:	[in]	value of this fence
+ *
+ * This function allocates a new fence and initialize it as a child of the
+ * fence_timeline provided. The value received is the seqno used to know
+ * when the fence is signaled.
+ *
+ * Returns NULL if fails to allocate memory or size is too small.
+ */
+struct fence *fence_create_on_timeline(struct fence_timeline *obj,
+				       const struct fence_ops *ops, int size,
+				       unsigned int value)
+{
+	unsigned long flags;
+	struct fence *fence;
+
+	if (size < sizeof(*fence))
+		return NULL;
+
+	fence = kzalloc(size, GFP_KERNEL);
+	if (!fence)
+		return NULL;
+
+	spin_lock_irqsave(&obj->lock, flags);
+	fence_timeline_get(obj);
+	fence_init(fence, ops, &obj->lock, 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);
+	return fence;
+}
+EXPORT_SYMBOL(fence_create_on_timeline);
+
+/**
  * fence_init - Initialize a custom fence.
  * @fence:	[in]	the fence to initialize
  * @ops:	[in]	the fence_ops for operations on this fence
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index a275108..2365db7 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -36,24 +36,8 @@ static const struct file_operations sync_fence_fops;
 
 struct fence *sync_pt_create(struct fence_timeline *obj, int size, u32 value)
 {
-	unsigned long flags;
-	struct fence *fence;
-
-	if (size < sizeof(*fence))
-		return NULL;
-
-	fence = kzalloc(size, GFP_KERNEL);
-	if (!fence)
-		return NULL;
-
-	spin_lock_irqsave(&obj->lock, flags);
-	fence_timeline_get(obj);
-	fence_init(fence, &sync_fence_ops, &obj->lock,
-		   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);
-	return fence;
+	return fence_create_on_timeline(obj, &sync_fence_ops,
+					sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sync_pt_create);
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 8908433..adece43 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -212,6 +212,9 @@ struct fence_ops {
 	void (*timeline_value_str)(struct fence *fence, char *str, int size);
 };
 
+struct fence *fence_create_on_timeline(struct fence_timeline *obj,
+				       const struct fence_ops *ops, int size,
+				       unsigned int value);
 void fence_init(struct fence *fence, const struct fence_ops *ops,
 		spinlock_t *lock, unsigned context, unsigned seqno);
 
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 21/29] dma-buf/fence: add fence_create_on_timeline()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

This functions in intended to replace sync_pt_create() and it does
exactly the same thing sync_pt_create() did.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c        | 38 ++++++++++++++++++++++++++++++++++++++
 drivers/staging/android/sync.c | 20 ++------------------
 include/linux/fence.h          |  3 +++
 3 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index ec51146..0a07fcb 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -768,6 +768,44 @@ err_free_cb:
 EXPORT_SYMBOL(fence_wait_any_timeout);
 
 /**
+ * fence_create_on_timeline - create a fence and add it to the timeline
+ * or until timeout elapses
+ * @obj:	[in]	timeline object
+ * @ops:	[in]	fence_ops to use
+ * @size:	[in]	size to allocate struct fence
+ * @value:	[in]	value of this fence
+ *
+ * This function allocates a new fence and initialize it as a child of the
+ * fence_timeline provided. The value received is the seqno used to know
+ * when the fence is signaled.
+ *
+ * Returns NULL if fails to allocate memory or size is too small.
+ */
+struct fence *fence_create_on_timeline(struct fence_timeline *obj,
+				       const struct fence_ops *ops, int size,
+				       unsigned int value)
+{
+	unsigned long flags;
+	struct fence *fence;
+
+	if (size < sizeof(*fence))
+		return NULL;
+
+	fence = kzalloc(size, GFP_KERNEL);
+	if (!fence)
+		return NULL;
+
+	spin_lock_irqsave(&obj->lock, flags);
+	fence_timeline_get(obj);
+	fence_init(fence, ops, &obj->lock, 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);
+	return fence;
+}
+EXPORT_SYMBOL(fence_create_on_timeline);
+
+/**
  * fence_init - Initialize a custom fence.
  * @fence:	[in]	the fence to initialize
  * @ops:	[in]	the fence_ops for operations on this fence
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index a275108..2365db7 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -36,24 +36,8 @@ static const struct file_operations sync_fence_fops;
 
 struct fence *sync_pt_create(struct fence_timeline *obj, int size, u32 value)
 {
-	unsigned long flags;
-	struct fence *fence;
-
-	if (size < sizeof(*fence))
-		return NULL;
-
-	fence = kzalloc(size, GFP_KERNEL);
-	if (!fence)
-		return NULL;
-
-	spin_lock_irqsave(&obj->lock, flags);
-	fence_timeline_get(obj);
-	fence_init(fence, &sync_fence_ops, &obj->lock,
-		   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);
-	return fence;
+	return fence_create_on_timeline(obj, &sync_fence_ops,
+					sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sync_pt_create);
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 8908433..adece43 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -212,6 +212,9 @@ struct fence_ops {
 	void (*timeline_value_str)(struct fence *fence, char *str, int size);
 };
 
+struct fence *fence_create_on_timeline(struct fence_timeline *obj,
+				       const struct fence_ops *ops, int size,
+				       unsigned int value);
 void fence_init(struct fence *fence, const struct fence_ops *ops,
 		spinlock_t *lock, unsigned context, unsigned seqno);
 
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 22/29] staging/android: remove sync_pt_create()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

get sw_sync_pt_create() to use fence_create_on_timeline() directly and
remove an abstractions layers between fences and its users.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c | 22 ++++++++++++++--------
 drivers/staging/android/sync.c    | 20 --------------------
 drivers/staging/android/sync.h    |  7 -------
 3 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index b9f8c51..7250f1b 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,16 +25,22 @@
 
 #include "sw_sync.h"
 
+static const struct fence_ops sw_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 = fence_default_signaled,
+	.wait = fence_default_wait,
+	.release = fence_default_release,
+	.fill_driver_data = fence_default_fill_driver_data,
+	.fence_value_str = fence_default_value_str,
+	.timeline_value_str = fence_default_timeline_value_str,
+};
+
 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), value);
-
-	pt->value = value;
-
-	return (struct fence *)pt;
+	return fence_create_on_timeline(&obj->obj, &sw_sync_fence_ops,
+					 sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 2365db7..956b4e9 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -31,16 +31,8 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-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, u32 value)
-{
-	return fence_create_on_timeline(obj, &sync_fence_ops,
-					sizeof(struct fence), value);
-}
-EXPORT_SYMBOL(sync_pt_create);
-
 static struct sync_fence *sync_fence_alloc(int size, const char *name)
 {
 	struct sync_fence *sync_fence;
@@ -305,18 +297,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-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 = fence_default_signaled,
-	.wait = fence_default_wait,
-	.release = fence_default_release,
-	.fill_driver_data = fence_default_fill_driver_data,
-	.fence_value_str = fence_default_value_str,
-	.timeline_value_str = fence_default_timeline_value_str,
-};
-
 static void sync_fence_free(struct kref *kref)
 {
 	struct sync_fence *sync_fence = container_of(kref, struct sync_fence,
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 569873f..256315c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -78,13 +78,6 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 	waiter->callback = callback;
 }
 
-/*
- * API for fence_timeline implementers
- */
-
-struct fence *sync_pt_create(struct fence_timeline *parent, int size,
-			     u32 value);
-
 /**
  * sync_fence_create() - creates a sync fence
  * @name:	name of fence to create
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 22/29] staging/android: remove sync_pt_create()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

get sw_sync_pt_create() to use fence_create_on_timeline() directly and
remove an abstractions layers between fences and its users.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c | 22 ++++++++++++++--------
 drivers/staging/android/sync.c    | 20 --------------------
 drivers/staging/android/sync.h    |  7 -------
 3 files changed, 14 insertions(+), 35 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index b9f8c51..7250f1b 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,16 +25,22 @@
 
 #include "sw_sync.h"
 
+static const struct fence_ops sw_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 = fence_default_signaled,
+	.wait = fence_default_wait,
+	.release = fence_default_release,
+	.fill_driver_data = fence_default_fill_driver_data,
+	.fence_value_str = fence_default_value_str,
+	.timeline_value_str = fence_default_timeline_value_str,
+};
+
 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), value);
-
-	pt->value = value;
-
-	return (struct fence *)pt;
+	return fence_create_on_timeline(&obj->obj, &sw_sync_fence_ops,
+					 sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 2365db7..956b4e9 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -31,16 +31,8 @@
 #define CREATE_TRACE_POINTS
 #include "trace/sync.h"
 
-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, u32 value)
-{
-	return fence_create_on_timeline(obj, &sync_fence_ops,
-					sizeof(struct fence), value);
-}
-EXPORT_SYMBOL(sync_pt_create);
-
 static struct sync_fence *sync_fence_alloc(int size, const char *name)
 {
 	struct sync_fence *sync_fence;
@@ -305,18 +297,6 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 }
 EXPORT_SYMBOL(sync_fence_wait);
 
-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 = fence_default_signaled,
-	.wait = fence_default_wait,
-	.release = fence_default_release,
-	.fill_driver_data = fence_default_fill_driver_data,
-	.fence_value_str = fence_default_value_str,
-	.timeline_value_str = fence_default_timeline_value_str,
-};
-
 static void sync_fence_free(struct kref *kref)
 {
 	struct sync_fence *sync_fence = container_of(kref, struct sync_fence,
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 569873f..256315c 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -78,13 +78,6 @@ static inline void sync_fence_waiter_init(struct sync_fence_waiter *waiter,
 	waiter->callback = callback;
 }
 
-/*
- * API for fence_timeline implementers
- */
-
-struct fence *sync_pt_create(struct fence_timeline *parent, int size,
-			     u32 value);
-
 /**
  * sync_fence_create() - creates a sync fence
  * @name:	name of fence to create
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 23/29] staging/android: remove sw_sync_timeline and sw_sync_pt
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

As we moved value storage to fence_timeline and fence those two structs
became useless and can be removed now.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c    | 15 ++++++---------
 drivers/staging/android/sw_sync.h    | 24 ++++++------------------
 drivers/staging/android/sync_debug.c | 12 ++++++------
 3 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index 7250f1b..ee7a942 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -37,25 +37,22 @@ static const struct fence_ops sw_sync_fence_ops = {
 	.timeline_value_str = fence_default_timeline_value_str,
 };
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
+struct fence *sw_sync_pt_create(struct fence_timeline *obj, u32 value)
 {
-	return fence_create_on_timeline(&obj->obj, &sw_sync_fence_ops,
+	return fence_create_on_timeline(obj, &sw_sync_fence_ops,
 					 sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+struct fence_timeline *sw_sync_timeline_create(const char *name)
 {
-	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		fence_timeline_create(1, sizeof(struct sw_sync_timeline),
+	return fence_timeline_create(1, sizeof(struct fence_timeline),
 				     "sw_sync", name);
-
-	return obj;
 }
 EXPORT_SYMBOL(sw_sync_timeline_create);
 
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc)
 {
-	fence_timeline_signal(&obj->obj, inc);
+	fence_timeline_signal(obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index 85ef780..f912888 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -22,34 +22,22 @@
 #include "sync.h"
 #include "uapi/sw_sync.h"
 
-struct sw_sync_timeline {
-	struct	fence_timeline	obj;
-
-	u32			value;
-};
-
-struct sw_sync_pt {
-	struct fence		pt;
-
-	u32			value;
-};
-
 #if IS_ENABLED(CONFIG_SW_SYNC)
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
+struct fence_timeline *sw_sync_timeline_create(const char *name);
+void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc);
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
+struct fence *sw_sync_pt_create(struct fence_timeline *obj, u32 value);
 #else
-static inline struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+static inline struct fence_timeline *sw_sync_timeline_create(const char *name)
 {
 	return NULL;
 }
 
-static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+static inline void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc)
 {
 }
 
-static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj,
+static inline struct fence *sw_sync_pt_create(struct fence_timeline *obj,
 					      u32 value)
 {
 	return NULL;
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 89b334c..13d225f 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -225,7 +225,7 @@ static const struct file_operations sync_info_debugfs_fops = {
 /* 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;
+	struct fence_timeline *obj;
 	char task_comm[TASK_COMM_LEN];
 
 	get_task_comm(task_comm, current);
@@ -241,13 +241,13 @@ static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
 
 static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
 {
-	struct sw_sync_timeline *obj = file->private_data;
+	struct fence_timeline *obj = file->private_data;
 
-	fence_timeline_destroy(&obj->obj);
+	fence_timeline_destroy(obj);
 	return 0;
 }
 
-static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
+static long sw_sync_ioctl_create_fence(struct fence_timeline *obj,
 				       unsigned long arg)
 {
 	int fd = get_unused_fd_flags(O_CLOEXEC);
@@ -294,7 +294,7 @@ err:
 	return err;
 }
 
-static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
+static long sw_sync_ioctl_inc(struct fence_timeline *obj, unsigned long arg)
 {
 	u32 value;
 
@@ -309,7 +309,7 @@ static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
 static long sw_sync_ioctl(struct file *file, unsigned int cmd,
 			  unsigned long arg)
 {
-	struct sw_sync_timeline *obj = file->private_data;
+	struct fence_timeline *obj = file->private_data;
 
 	switch (cmd) {
 	case SW_SYNC_IOC_CREATE_FENCE:
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 23/29] staging/android: remove sw_sync_timeline and sw_sync_pt
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

As we moved value storage to fence_timeline and fence those two structs
became useless and can be removed now.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c    | 15 ++++++---------
 drivers/staging/android/sw_sync.h    | 24 ++++++------------------
 drivers/staging/android/sync_debug.c | 12 ++++++------
 3 files changed, 18 insertions(+), 33 deletions(-)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index 7250f1b..ee7a942 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -37,25 +37,22 @@ static const struct fence_ops sw_sync_fence_ops = {
 	.timeline_value_str = fence_default_timeline_value_str,
 };
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value)
+struct fence *sw_sync_pt_create(struct fence_timeline *obj, u32 value)
 {
-	return fence_create_on_timeline(&obj->obj, &sw_sync_fence_ops,
+	return fence_create_on_timeline(obj, &sw_sync_fence_ops,
 					 sizeof(struct fence), value);
 }
 EXPORT_SYMBOL(sw_sync_pt_create);
 
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+struct fence_timeline *sw_sync_timeline_create(const char *name)
 {
-	struct sw_sync_timeline *obj = (struct sw_sync_timeline *)
-		fence_timeline_create(1, sizeof(struct sw_sync_timeline),
+	return fence_timeline_create(1, sizeof(struct fence_timeline),
 				     "sw_sync", name);
-
-	return obj;
 }
 EXPORT_SYMBOL(sw_sync_timeline_create);
 
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc)
 {
-	fence_timeline_signal(&obj->obj, inc);
+	fence_timeline_signal(obj, inc);
 }
 EXPORT_SYMBOL(sw_sync_timeline_inc);
diff --git a/drivers/staging/android/sw_sync.h b/drivers/staging/android/sw_sync.h
index 85ef780..f912888 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/drivers/staging/android/sw_sync.h
@@ -22,34 +22,22 @@
 #include "sync.h"
 #include "uapi/sw_sync.h"
 
-struct sw_sync_timeline {
-	struct	fence_timeline	obj;
-
-	u32			value;
-};
-
-struct sw_sync_pt {
-	struct fence		pt;
-
-	u32			value;
-};
-
 #if IS_ENABLED(CONFIG_SW_SYNC)
-struct sw_sync_timeline *sw_sync_timeline_create(const char *name);
-void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc);
+struct fence_timeline *sw_sync_timeline_create(const char *name);
+void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc);
 
-struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj, u32 value);
+struct fence *sw_sync_pt_create(struct fence_timeline *obj, u32 value);
 #else
-static inline struct sw_sync_timeline *sw_sync_timeline_create(const char *name)
+static inline struct fence_timeline *sw_sync_timeline_create(const char *name)
 {
 	return NULL;
 }
 
-static inline void sw_sync_timeline_inc(struct sw_sync_timeline *obj, u32 inc)
+static inline void sw_sync_timeline_inc(struct fence_timeline *obj, u32 inc)
 {
 }
 
-static inline struct fence *sw_sync_pt_create(struct sw_sync_timeline *obj,
+static inline struct fence *sw_sync_pt_create(struct fence_timeline *obj,
 					      u32 value)
 {
 	return NULL;
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 89b334c..13d225f 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -225,7 +225,7 @@ static const struct file_operations sync_info_debugfs_fops = {
 /* 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;
+	struct fence_timeline *obj;
 	char task_comm[TASK_COMM_LEN];
 
 	get_task_comm(task_comm, current);
@@ -241,13 +241,13 @@ static int sw_sync_debugfs_open(struct inode *inode, struct file *file)
 
 static int sw_sync_debugfs_release(struct inode *inode, struct file *file)
 {
-	struct sw_sync_timeline *obj = file->private_data;
+	struct fence_timeline *obj = file->private_data;
 
-	fence_timeline_destroy(&obj->obj);
+	fence_timeline_destroy(obj);
 	return 0;
 }
 
-static long sw_sync_ioctl_create_fence(struct sw_sync_timeline *obj,
+static long sw_sync_ioctl_create_fence(struct fence_timeline *obj,
 				       unsigned long arg)
 {
 	int fd = get_unused_fd_flags(O_CLOEXEC);
@@ -294,7 +294,7 @@ err:
 	return err;
 }
 
-static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
+static long sw_sync_ioctl_inc(struct fence_timeline *obj, unsigned long arg)
 {
 	u32 value;
 
@@ -309,7 +309,7 @@ static long sw_sync_ioctl_inc(struct sw_sync_timeline *obj, unsigned long arg)
 static long sw_sync_ioctl(struct file *file, unsigned int cmd,
 			  unsigned long arg)
 {
-	struct sw_sync_timeline *obj = file->private_data;
+	struct fence_timeline *obj = file->private_data;
 
 	switch (cmd) {
 	case SW_SYNC_IOC_CREATE_FENCE:
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 24/29] dma-buf/fence: add debug to fence timeline
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Bring the debug information that belonged to sync_timeline and sync_pt
back.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/Makefile             |   2 +-
 drivers/dma-buf/fence.c              |   4 ++
 drivers/dma-buf/fence_debug.c        | 128 +++++++++++++++++++++++++++++++++++
 drivers/staging/android/sync.h       |   4 --
 drivers/staging/android/sync_debug.c | 105 +---------------------------
 include/linux/fence.h                |  18 +++++
 6 files changed, 154 insertions(+), 107 deletions(-)
 create mode 100644 drivers/dma-buf/fence_debug.c

diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 57a675f..fb03696 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1 @@
-obj-y := dma-buf.o fence.o reservation.o seqno-fence.o
+obj-y := dma-buf.o fence.o fence_debug.o reservation.o seqno-fence.o
diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 0a07fcb..09faf2e 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -84,6 +84,8 @@ struct fence_timeline *fence_timeline_create(unsigned num, int size,
 	INIT_LIST_HEAD(&timeline->active_list_head);
 	spin_lock_init(&timeline->lock);
 
+	fence_timeline_debug_add(timeline);
+
 	return timeline;
 }
 EXPORT_SYMBOL(fence_timeline_create);
@@ -100,6 +102,8 @@ static void fence_timeline_free(struct kref *kref)
 	struct fence_timeline *timeline =
 		container_of(kref, struct fence_timeline, kref);
 
+	fence_timeline_debug_remove(timeline);
+
 	kfree(timeline);
 }
 
diff --git a/drivers/dma-buf/fence_debug.c b/drivers/dma-buf/fence_debug.c
new file mode 100644
index 0000000..c7529c6
--- /dev/null
+++ b/drivers/dma-buf/fence_debug.c
@@ -0,0 +1,128 @@
+/*
+ * drivers/dma-buf/fence_debug.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/seq_file.h>
+#include <linux/fence.h>
+
+#ifdef CONFIG_DEBUG_FS
+
+static LIST_HEAD(fence_timeline_list_head);
+static DEFINE_SPINLOCK(fence_timeline_list_lock);
+
+void fence_timeline_debug_add(struct fence_timeline *obj)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_add_tail(&obj->fence_timeline_list, &fence_timeline_list_head);
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_debug_add);
+
+void fence_timeline_debug_remove(struct fence_timeline *obj)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_del(&obj->fence_timeline_list);
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_debug_remove);
+
+const char *fence_status_str(int status)
+{
+	if (status == 0)
+		return "signaled";
+
+	if (status > 0)
+		return "active";
+
+	return "error";
+}
+EXPORT_SYMBOL(fence_status_str);
+
+void fence_print(struct seq_file *s, struct fence *fence, bool show)
+{
+	int status = 1;
+	struct fence_timeline *parent = fence_parent(fence);
+
+	if (fence_is_signaled_locked(fence))
+		status = fence->status;
+
+	seq_printf(s, "  %s%sfence %s",
+		   show ? parent->name : "",
+		   show ? "_" : "",
+		   fence_status_str(status));
+
+	if (status <= 0) {
+		struct timespec64 ts64 =
+			ktime_to_timespec64(fence->timestamp);
+
+		seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
+	}
+
+	if (fence->ops->timeline_value_str &&
+	    fence->ops->fence_value_str) {
+		char value[64];
+
+		fence->ops->fence_value_str(fence, value, sizeof(value));
+		seq_printf(s, ": %s", value);
+		if (show) {
+			fence->ops->timeline_value_str(fence, value,
+						       sizeof(value));
+			seq_printf(s, " / %s", value);
+		}
+	}
+
+	seq_puts(s, "\n");
+}
+EXPORT_SYMBOL(fence_print);
+
+void fence_timeline_print(struct seq_file *s, struct fence_timeline *obj)
+{
+	struct list_head *pos;
+	unsigned long flags;
+
+	seq_printf(s, "%s %s: %u\n", obj->name, obj->drv_name, obj->value);
+
+	spin_lock_irqsave(&obj->lock, flags);
+	list_for_each(pos, &obj->child_list_head) {
+		struct fence *fence =
+			container_of(pos, struct fence, child_list);
+		fence_print(s, fence, false);
+	}
+	spin_unlock_irqrestore(&obj->lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_print);
+
+void fence_timeline_print_all(struct seq_file* s)
+{
+	unsigned long flags;
+	struct list_head *pos;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_for_each(pos, &fence_timeline_list_head) {
+		struct fence_timeline *obj =
+			container_of(pos, struct fence_timeline,
+				     fence_timeline_list);
+
+		fence_timeline_print(s, obj);
+		seq_puts(s, "\n");
+	}
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_print_all);
+#endif
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 256315c..8e6827b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -184,15 +184,11 @@ int sync_fence_wait(struct sync_fence *fence, long timeout);
 
 #ifdef CONFIG_DEBUG_FS
 
-void sync_timeline_debug_add(struct fence_timeline *obj);
-void sync_timeline_debug_remove(struct fence_timeline *obj);
 void sync_fence_debug_add(struct sync_fence *fence);
 void sync_fence_debug_remove(struct sync_fence *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_dump()
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 13d225f..8e2ca57 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -33,29 +33,9 @@
 
 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);
 
-void sync_timeline_debug_add(struct fence_timeline *obj)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_add_tail(&obj->fence_timeline_list, &sync_timeline_list_head);
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
-}
-
-void sync_timeline_debug_remove(struct fence_timeline *obj)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_del(&obj->fence_timeline_list);
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
-}
-
 void sync_fence_debug_add(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
@@ -74,76 +54,6 @@ void sync_fence_debug_remove(struct sync_fence *sync_fence)
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
-static const char *sync_status_str(int status)
-{
-	if (status == 0)
-		return "signaled";
-
-	if (status > 0)
-		return "active";
-
-	return "error";
-}
-
-static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show)
-{
-	int status = 1;
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (fence_is_signaled_locked(fence))
-		status = fence->status;
-
-	seq_printf(s, "  %s%sfence %s",
-		   show ? parent->name : "",
-		   show ? "_" : "",
-		   sync_status_str(status));
-
-	if (status <= 0) {
-		struct timespec64 ts64 =
-			ktime_to_timespec64(fence->timestamp);
-
-		seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
-	}
-
-	if ((!fence || fence->ops->timeline_value_str) &&
-		fence->ops->fence_value_str) {
-		char value[64];
-		bool success;
-
-		fence->ops->fence_value_str(fence, value, sizeof(value));
-		success = strlen(value);
-
-		if (success)
-			seq_printf(s, ": %s", value);
-
-		if (success && fence) {
-			fence->ops->timeline_value_str(fence, value,
-						       sizeof(value));
-
-			if (strlen(value))
-				seq_printf(s, " / %s", value);
-		}
-	}
-
-	seq_puts(s, "\n");
-}
-
-static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
-{
-	struct list_head *pos;
-	unsigned long flags;
-
-	seq_printf(s, "%s %s: %d\n", obj->name, obj->drv_name, obj->value);
-
-	spin_lock_irqsave(&obj->lock, flags);
-	list_for_each(pos, &obj->child_list_head) {
-		struct fence *fence =
-			container_of(pos, struct fence, child_list);
-		sync_print_fence(s, fence, false);
-	}
-	spin_unlock_irqrestore(&obj->lock, flags);
-}
-
 static void sync_print_sync_fence(struct seq_file *s,
 				  struct sync_fence *sync_fence)
 {
@@ -152,10 +62,10 @@ static void sync_print_sync_fence(struct seq_file *s,
 	int i;
 
 	seq_printf(s, "[%p] %s: %s\n", sync_fence, sync_fence->name,
-		   sync_status_str(atomic_read(&sync_fence->status)));
+		   fence_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_fence(s, sync_fence->cbs[i].fence, true);
+		fence_print(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
@@ -179,16 +89,7 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	seq_puts(s, "objs:\n--------------\n");
 
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_for_each(pos, &sync_timeline_list_head) {
-		struct fence_timeline *obj =
-			container_of(pos, struct fence_timeline,
-				     fence_timeline_list);
-
-		sync_print_obj(s, obj);
-		seq_puts(s, "\n");
-	}
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
+	fence_timeline_print_all(s);
 
 	seq_puts(s, "fences:\n--------------\n");
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index adece43..32a26ab 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -407,6 +407,24 @@ static inline signed long fence_wait(struct fence *fence, bool intr)
 
 unsigned fence_context_alloc(unsigned num);
 
+#ifdef CONFIG_DEBUG_FS
+
+void fence_timeline_debug_add(struct fence_timeline *obj);
+void fence_timeline_debug_remove(struct fence_timeline *obj);
+const char *fence_status_str(int status);
+void fence_print(struct seq_file *s, struct fence *fence, bool show);
+void fence_timeline_print(struct seq_file *s, struct fence_timeline *obj);
+void fence_timeline_print_all(struct seq_file* s);
+
+#else
+#define fence_timeline_debug_add(obj)
+#define fence_timeline_debug_remove(obj)
+#define fence_status_str(status)
+#define fence_print(s, fence, show)
+#define fence_timeline_print(s, obj)
+#define fence_timeline_print_all(s)
+#endif
+
 #define FENCE_TRACE(f, fmt, args...) \
 	do {								\
 		struct fence *__ff = (f);				\
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 24/29] dma-buf/fence: add debug to fence timeline
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Bring the debug information that belonged to sync_timeline and sync_pt
back.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/Makefile             |   2 +-
 drivers/dma-buf/fence.c              |   4 ++
 drivers/dma-buf/fence_debug.c        | 128 +++++++++++++++++++++++++++++++++++
 drivers/staging/android/sync.h       |   4 --
 drivers/staging/android/sync_debug.c | 105 +---------------------------
 include/linux/fence.h                |  18 +++++
 6 files changed, 154 insertions(+), 107 deletions(-)
 create mode 100644 drivers/dma-buf/fence_debug.c

diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index 57a675f..fb03696 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1 @@
-obj-y := dma-buf.o fence.o reservation.o seqno-fence.o
+obj-y := dma-buf.o fence.o fence_debug.o reservation.o seqno-fence.o
diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 0a07fcb..09faf2e 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -84,6 +84,8 @@ struct fence_timeline *fence_timeline_create(unsigned num, int size,
 	INIT_LIST_HEAD(&timeline->active_list_head);
 	spin_lock_init(&timeline->lock);
 
+	fence_timeline_debug_add(timeline);
+
 	return timeline;
 }
 EXPORT_SYMBOL(fence_timeline_create);
@@ -100,6 +102,8 @@ static void fence_timeline_free(struct kref *kref)
 	struct fence_timeline *timeline =
 		container_of(kref, struct fence_timeline, kref);
 
+	fence_timeline_debug_remove(timeline);
+
 	kfree(timeline);
 }
 
diff --git a/drivers/dma-buf/fence_debug.c b/drivers/dma-buf/fence_debug.c
new file mode 100644
index 0000000..c7529c6
--- /dev/null
+++ b/drivers/dma-buf/fence_debug.c
@@ -0,0 +1,128 @@
+/*
+ * drivers/dma-buf/fence_debug.c
+ *
+ * Copyright (C) 2012 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include <linux/seq_file.h>
+#include <linux/fence.h>
+
+#ifdef CONFIG_DEBUG_FS
+
+static LIST_HEAD(fence_timeline_list_head);
+static DEFINE_SPINLOCK(fence_timeline_list_lock);
+
+void fence_timeline_debug_add(struct fence_timeline *obj)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_add_tail(&obj->fence_timeline_list, &fence_timeline_list_head);
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_debug_add);
+
+void fence_timeline_debug_remove(struct fence_timeline *obj)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_del(&obj->fence_timeline_list);
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_debug_remove);
+
+const char *fence_status_str(int status)
+{
+	if (status == 0)
+		return "signaled";
+
+	if (status > 0)
+		return "active";
+
+	return "error";
+}
+EXPORT_SYMBOL(fence_status_str);
+
+void fence_print(struct seq_file *s, struct fence *fence, bool show)
+{
+	int status = 1;
+	struct fence_timeline *parent = fence_parent(fence);
+
+	if (fence_is_signaled_locked(fence))
+		status = fence->status;
+
+	seq_printf(s, "  %s%sfence %s",
+		   show ? parent->name : "",
+		   show ? "_" : "",
+		   fence_status_str(status));
+
+	if (status <= 0) {
+		struct timespec64 ts64 =
+			ktime_to_timespec64(fence->timestamp);
+
+		seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
+	}
+
+	if (fence->ops->timeline_value_str &&
+	    fence->ops->fence_value_str) {
+		char value[64];
+
+		fence->ops->fence_value_str(fence, value, sizeof(value));
+		seq_printf(s, ": %s", value);
+		if (show) {
+			fence->ops->timeline_value_str(fence, value,
+						       sizeof(value));
+			seq_printf(s, " / %s", value);
+		}
+	}
+
+	seq_puts(s, "\n");
+}
+EXPORT_SYMBOL(fence_print);
+
+void fence_timeline_print(struct seq_file *s, struct fence_timeline *obj)
+{
+	struct list_head *pos;
+	unsigned long flags;
+
+	seq_printf(s, "%s %s: %u\n", obj->name, obj->drv_name, obj->value);
+
+	spin_lock_irqsave(&obj->lock, flags);
+	list_for_each(pos, &obj->child_list_head) {
+		struct fence *fence =
+			container_of(pos, struct fence, child_list);
+		fence_print(s, fence, false);
+	}
+	spin_unlock_irqrestore(&obj->lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_print);
+
+void fence_timeline_print_all(struct seq_file* s)
+{
+	unsigned long flags;
+	struct list_head *pos;
+
+	spin_lock_irqsave(&fence_timeline_list_lock, flags);
+	list_for_each(pos, &fence_timeline_list_head) {
+		struct fence_timeline *obj =
+			container_of(pos, struct fence_timeline,
+				     fence_timeline_list);
+
+		fence_timeline_print(s, obj);
+		seq_puts(s, "\n");
+	}
+	spin_unlock_irqrestore(&fence_timeline_list_lock, flags);
+}
+EXPORT_SYMBOL(fence_timeline_print_all);
+#endif
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 256315c..8e6827b 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -184,15 +184,11 @@ int sync_fence_wait(struct sync_fence *fence, long timeout);
 
 #ifdef CONFIG_DEBUG_FS
 
-void sync_timeline_debug_add(struct fence_timeline *obj);
-void sync_timeline_debug_remove(struct fence_timeline *obj);
 void sync_fence_debug_add(struct sync_fence *fence);
 void sync_fence_debug_remove(struct sync_fence *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_dump()
diff --git a/drivers/staging/android/sync_debug.c b/drivers/staging/android/sync_debug.c
index 13d225f..8e2ca57 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/staging/android/sync_debug.c
@@ -33,29 +33,9 @@
 
 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);
 
-void sync_timeline_debug_add(struct fence_timeline *obj)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_add_tail(&obj->fence_timeline_list, &sync_timeline_list_head);
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
-}
-
-void sync_timeline_debug_remove(struct fence_timeline *obj)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_del(&obj->fence_timeline_list);
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
-}
-
 void sync_fence_debug_add(struct sync_fence *sync_fence)
 {
 	unsigned long flags;
@@ -74,76 +54,6 @@ void sync_fence_debug_remove(struct sync_fence *sync_fence)
 	spin_unlock_irqrestore(&sync_fence_list_lock, flags);
 }
 
-static const char *sync_status_str(int status)
-{
-	if (status == 0)
-		return "signaled";
-
-	if (status > 0)
-		return "active";
-
-	return "error";
-}
-
-static void sync_print_fence(struct seq_file *s, struct fence *fence, bool show)
-{
-	int status = 1;
-	struct fence_timeline *parent = fence_parent(fence);
-
-	if (fence_is_signaled_locked(fence))
-		status = fence->status;
-
-	seq_printf(s, "  %s%sfence %s",
-		   show ? parent->name : "",
-		   show ? "_" : "",
-		   sync_status_str(status));
-
-	if (status <= 0) {
-		struct timespec64 ts64 =
-			ktime_to_timespec64(fence->timestamp);
-
-		seq_printf(s, "@%lld.%09ld", (s64)ts64.tv_sec, ts64.tv_nsec);
-	}
-
-	if ((!fence || fence->ops->timeline_value_str) &&
-		fence->ops->fence_value_str) {
-		char value[64];
-		bool success;
-
-		fence->ops->fence_value_str(fence, value, sizeof(value));
-		success = strlen(value);
-
-		if (success)
-			seq_printf(s, ": %s", value);
-
-		if (success && fence) {
-			fence->ops->timeline_value_str(fence, value,
-						       sizeof(value));
-
-			if (strlen(value))
-				seq_printf(s, " / %s", value);
-		}
-	}
-
-	seq_puts(s, "\n");
-}
-
-static void sync_print_obj(struct seq_file *s, struct fence_timeline *obj)
-{
-	struct list_head *pos;
-	unsigned long flags;
-
-	seq_printf(s, "%s %s: %d\n", obj->name, obj->drv_name, obj->value);
-
-	spin_lock_irqsave(&obj->lock, flags);
-	list_for_each(pos, &obj->child_list_head) {
-		struct fence *fence =
-			container_of(pos, struct fence, child_list);
-		sync_print_fence(s, fence, false);
-	}
-	spin_unlock_irqrestore(&obj->lock, flags);
-}
-
 static void sync_print_sync_fence(struct seq_file *s,
 				  struct sync_fence *sync_fence)
 {
@@ -152,10 +62,10 @@ static void sync_print_sync_fence(struct seq_file *s,
 	int i;
 
 	seq_printf(s, "[%p] %s: %s\n", sync_fence, sync_fence->name,
-		   sync_status_str(atomic_read(&sync_fence->status)));
+		   fence_status_str(atomic_read(&sync_fence->status)));
 
 	for (i = 0; i < sync_fence->num_fences; ++i) {
-		sync_print_fence(s, sync_fence->cbs[i].fence, true);
+		fence_print(s, sync_fence->cbs[i].fence, true);
 	}
 
 	spin_lock_irqsave(&sync_fence->wq.lock, flags);
@@ -179,16 +89,7 @@ static int sync_debugfs_show(struct seq_file *s, void *unused)
 
 	seq_puts(s, "objs:\n--------------\n");
 
-	spin_lock_irqsave(&sync_timeline_list_lock, flags);
-	list_for_each(pos, &sync_timeline_list_head) {
-		struct fence_timeline *obj =
-			container_of(pos, struct fence_timeline,
-				     fence_timeline_list);
-
-		sync_print_obj(s, obj);
-		seq_puts(s, "\n");
-	}
-	spin_unlock_irqrestore(&sync_timeline_list_lock, flags);
+	fence_timeline_print_all(s);
 
 	seq_puts(s, "fences:\n--------------\n");
 
diff --git a/include/linux/fence.h b/include/linux/fence.h
index adece43..32a26ab 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -407,6 +407,24 @@ static inline signed long fence_wait(struct fence *fence, bool intr)
 
 unsigned fence_context_alloc(unsigned num);
 
+#ifdef CONFIG_DEBUG_FS
+
+void fence_timeline_debug_add(struct fence_timeline *obj);
+void fence_timeline_debug_remove(struct fence_timeline *obj);
+const char *fence_status_str(int status);
+void fence_print(struct seq_file *s, struct fence *fence, bool show);
+void fence_timeline_print(struct seq_file *s, struct fence_timeline *obj);
+void fence_timeline_print_all(struct seq_file* s);
+
+#else
+#define fence_timeline_debug_add(obj)
+#define fence_timeline_debug_remove(obj)
+#define fence_status_str(status)
+#define fence_print(s, fence, show)
+#define fence_timeline_print(s, obj)
+#define fence_timeline_print_all(s)
+#endif
+
 #define FENCE_TRACE(f, fmt, args...) \
 	do {								\
 		struct fence *__ff = (f);				\
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 25/29] dma-buf/fence: remove unused var from fence_timeline_signal()
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

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/dma-buf/fence.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 09faf2e..7a5fc9b 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -166,7 +166,6 @@ EXPORT_SYMBOL(fence_timeline_destroy);
 void fence_timeline_signal(struct fence_timeline *timeline, unsigned int inc)
 {
 	unsigned long flags;
-	LIST_HEAD(signaled_pts);
 	struct fence *fence, *next;
 
 	spin_lock_irqsave(&timeline->lock, flags);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 25/29] dma-buf/fence: remove unused var from fence_timeline_signal()
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

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/dma-buf/fence.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 09faf2e..7a5fc9b 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -166,7 +166,6 @@ EXPORT_SYMBOL(fence_timeline_destroy);
 void fence_timeline_signal(struct fence_timeline *timeline, unsigned int inc)
 {
 	unsigned long flags;
-	LIST_HEAD(signaled_pts);
 	struct fence *fence, *next;
 
 	spin_lock_irqsave(&timeline->lock, flags);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

All changes to timeline value come through the user via
fence_timeline_signal() calls. When fence_timeline_destroy() is called no
changes on timeline->value happens hence call fence_timeline_signal() with
no increment is pointless.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 7a5fc9b..26f5f0f 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -136,7 +136,7 @@ EXPORT_SYMBOL(fence_timeline_put);
  * fence_timeline_destroy - destroy a fence_timeline
  * @timeline	[in]	the fence_timeline to destroy
  *
- * This function destroys a timeline. It signals any active fence first.
+ * This function destroys a timeline.
  */
 void fence_timeline_destroy(struct fence_timeline *timeline)
 {
@@ -147,10 +147,6 @@ void fence_timeline_destroy(struct fence_timeline *timeline)
 	 */
 	smp_wmb();
 
-	/*
-	 * signal any children that their parent is going away.
-	 */
-	fence_timeline_signal(timeline, 0);
 	fence_timeline_put(timeline);
 }
 EXPORT_SYMBOL(fence_timeline_destroy);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

All changes to timeline value come through the user via
fence_timeline_signal() calls. When fence_timeline_destroy() is called no
changes on timeline->value happens hence call fence_timeline_signal() with
no increment is pointless.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 7a5fc9b..26f5f0f 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -136,7 +136,7 @@ EXPORT_SYMBOL(fence_timeline_put);
  * fence_timeline_destroy - destroy a fence_timeline
  * @timeline	[in]	the fence_timeline to destroy
  *
- * This function destroys a timeline. It signals any active fence first.
+ * This function destroys a timeline.
  */
 void fence_timeline_destroy(struct fence_timeline *timeline)
 {
@@ -147,10 +147,6 @@ void fence_timeline_destroy(struct fence_timeline *timeline)
 	 */
 	smp_wmb();
 
-	/*
-	 * signal any children that their parent is going away.
-	 */
-	fence_timeline_signal(timeline, 0);
 	fence_timeline_put(timeline);
 }
 EXPORT_SYMBOL(fence_timeline_destroy);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 27/29] dma-buf/fence: add .cleanup() callback
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Called when the fence_timeline is destroyed so users can cleanup routines
on fences.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c | 24 ++++++++++++++++++++++++
 include/linux/fence.h   |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 26f5f0f..3973b35 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -140,6 +140,9 @@ EXPORT_SYMBOL(fence_timeline_put);
  */
 void fence_timeline_destroy(struct fence_timeline *timeline)
 {
+	unsigned long flags;
+	struct fence *fence, *next;
+
 	timeline->destroyed = true;
 	/*
 	 * Ensure timeline is marked as destroyed before
@@ -147,6 +150,15 @@ void fence_timeline_destroy(struct fence_timeline *timeline)
 	 */
 	smp_wmb();
 
+	spin_lock_irqsave(&timeline->lock, flags);
+	list_for_each_entry_safe(fence, next, &timeline->active_list_head,
+				 active_list) {
+		if (fence->ops->cleanup)
+			fence->ops->cleanup(fence, fence->priv);
+		list_del_init(&fence->active_list);
+	}
+	spin_unlock_irqrestore(&timeline->lock, flags);
+
 	fence_timeline_put(timeline);
 }
 EXPORT_SYMBOL(fence_timeline_destroy);
@@ -839,3 +851,15 @@ fence_init(struct fence *fence, const struct fence_ops *ops,
 	trace_fence_init(fence);
 }
 EXPORT_SYMBOL(fence_init);
+
+/**
+ * fence_add_user_data - add private user data
+ * @fence:	[in]	the fence to use
+ * @user_data:	[in]	the private data to store
+ *
+ * This function adds a private user data point to struct fence.
+ */
+void fence_add_user_data(struct fence *fence, void *user_data)
+{
+	fence->priv = user_data;
+}
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 32a26ab..59eabe3 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -116,6 +116,7 @@ struct fence {
 	int status;
 	struct list_head child_list;
 	struct list_head active_list;
+	void *priv;
 };
 
 enum fence_flag_bits {
@@ -146,6 +147,7 @@ struct fence_cb {
  * @enable_signaling: enable software signaling of fence.
  * @signaled: [optional] peek whether the fence is signaled, can be null.
  * @wait: custom wait implementation, or fence_default_wait.
+ * @cleanup: [optional] called when the timeline is destroyed
  * @release: [optional] called on destruction of fence, can be null
  * @fill_driver_data: [optional] callback to fill in free-form debug info
  * Returns amount of bytes filled, or -errno.
@@ -205,6 +207,7 @@ struct fence_ops {
 	bool (*enable_signaling)(struct fence *fence);
 	bool (*signaled)(struct fence *fence);
 	signed long (*wait)(struct fence *fence, bool intr, signed long timeout);
+	void (*cleanup)(struct fence *fence, void *user_data);
 	void (*release)(struct fence *fence);
 
 	int (*fill_driver_data)(struct fence *fence, void *data, int size);
@@ -217,6 +220,7 @@ struct fence *fence_create_on_timeline(struct fence_timeline *obj,
 				       unsigned int value);
 void fence_init(struct fence *fence, const struct fence_ops *ops,
 		spinlock_t *lock, unsigned context, unsigned seqno);
+void fence_add_user_data(struct fence *fence, void *user_data);
 
 void fence_release(struct kref *kref);
 void fence_free(struct fence *fence);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 27/29] dma-buf/fence: add .cleanup() callback
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

Called when the fence_timeline is destroyed so users can cleanup routines
on fences.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/dma-buf/fence.c | 24 ++++++++++++++++++++++++
 include/linux/fence.h   |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
index 26f5f0f..3973b35 100644
--- a/drivers/dma-buf/fence.c
+++ b/drivers/dma-buf/fence.c
@@ -140,6 +140,9 @@ EXPORT_SYMBOL(fence_timeline_put);
  */
 void fence_timeline_destroy(struct fence_timeline *timeline)
 {
+	unsigned long flags;
+	struct fence *fence, *next;
+
 	timeline->destroyed = true;
 	/*
 	 * Ensure timeline is marked as destroyed before
@@ -147,6 +150,15 @@ void fence_timeline_destroy(struct fence_timeline *timeline)
 	 */
 	smp_wmb();
 
+	spin_lock_irqsave(&timeline->lock, flags);
+	list_for_each_entry_safe(fence, next, &timeline->active_list_head,
+				 active_list) {
+		if (fence->ops->cleanup)
+			fence->ops->cleanup(fence, fence->priv);
+		list_del_init(&fence->active_list);
+	}
+	spin_unlock_irqrestore(&timeline->lock, flags);
+
 	fence_timeline_put(timeline);
 }
 EXPORT_SYMBOL(fence_timeline_destroy);
@@ -839,3 +851,15 @@ fence_init(struct fence *fence, const struct fence_ops *ops,
 	trace_fence_init(fence);
 }
 EXPORT_SYMBOL(fence_init);
+
+/**
+ * fence_add_user_data - add private user data
+ * @fence:	[in]	the fence to use
+ * @user_data:	[in]	the private data to store
+ *
+ * This function adds a private user data point to struct fence.
+ */
+void fence_add_user_data(struct fence *fence, void *user_data)
+{
+	fence->priv = user_data;
+}
diff --git a/include/linux/fence.h b/include/linux/fence.h
index 32a26ab..59eabe3 100644
--- a/include/linux/fence.h
+++ b/include/linux/fence.h
@@ -116,6 +116,7 @@ struct fence {
 	int status;
 	struct list_head child_list;
 	struct list_head active_list;
+	void *priv;
 };
 
 enum fence_flag_bits {
@@ -146,6 +147,7 @@ struct fence_cb {
  * @enable_signaling: enable software signaling of fence.
  * @signaled: [optional] peek whether the fence is signaled, can be null.
  * @wait: custom wait implementation, or fence_default_wait.
+ * @cleanup: [optional] called when the timeline is destroyed
  * @release: [optional] called on destruction of fence, can be null
  * @fill_driver_data: [optional] callback to fill in free-form debug info
  * Returns amount of bytes filled, or -errno.
@@ -205,6 +207,7 @@ struct fence_ops {
 	bool (*enable_signaling)(struct fence *fence);
 	bool (*signaled)(struct fence *fence);
 	signed long (*wait)(struct fence *fence, bool intr, signed long timeout);
+	void (*cleanup)(struct fence *fence, void *user_data);
 	void (*release)(struct fence *fence);
 
 	int (*fill_driver_data)(struct fence *fence, void *data, int size);
@@ -217,6 +220,7 @@ struct fence *fence_create_on_timeline(struct fence_timeline *obj,
 				       unsigned int value);
 void fence_init(struct fence *fence, const struct fence_ops *ops,
 		spinlock_t *lock, unsigned context, unsigned seqno);
+void fence_add_user_data(struct fence *fence, void *user_data);
 
 void fence_release(struct kref *kref);
 void fence_free(struct fence *fence);
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 28/29] staging/android: use .cleanup() to interrupt any sync_fence waiter
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

When the timeline is being destroyed all the waiters waiting for the
sync_fence to signal need to be woken up and finished as well.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c | 8 ++++++++
 drivers/staging/android/sync.c    | 9 +++++++++
 drivers/staging/android/sync.h    | 2 ++
 3 files changed, 19 insertions(+)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index ee7a942..8c83bad 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,6 +25,13 @@
 
 #include "sw_sync.h"
 
+static void sw_sync_cleanup(struct fence *fence, void *user_data)
+{
+	struct sync_fence *sync_fence = user_data;
+
+	sync_fence_cleanup(sync_fence);
+}
+
 static const struct fence_ops sw_sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -32,6 +39,7 @@ static const struct fence_ops sw_sync_fence_ops = {
 	.signaled = fence_default_signaled,
 	.wait = fence_default_wait,
 	.release = fence_default_release,
+	.cleanup = sw_sync_cleanup,
 	.fill_driver_data = fence_default_fill_driver_data,
 	.fence_value_str = fence_default_value_str,
 	.timeline_value_str = fence_default_timeline_value_str,
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 956b4e9..aafecf4 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -91,6 +91,8 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *fence)
 
 	sync_fence_debug_add(sync_fence);
 
+	fence_add_user_data(fence, sync_fence);
+
 	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
@@ -101,6 +103,13 @@ struct sync_fence *sync_fence_create(const char *name, struct fence *fence)
 }
 EXPORT_SYMBOL(sync_fence_create);
 
+void sync_fence_cleanup(struct sync_fence *sync_fence)
+{
+	atomic_set(&sync_fence->status, -ENOENT);
+	wake_up_all(&sync_fence->wq);
+}
+EXPORT_SYMBOL(sync_fence_cleanup);
+
 struct sync_fence *sync_fence_fdget(int fd)
 {
 	struct file *file = fget(fd);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 8e6827b..d60d9c2 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -98,6 +98,8 @@ struct sync_fence *sync_fence_create(const char *name, struct fence *fence);
  */
 struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt);
 
+void sync_fence_cleanup(struct sync_fence *sync_fence);
+
 /*
  * API for sync_fence consumers
  */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 28/29] staging/android: use .cleanup() to interrupt any sync_fence waiter
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

When the timeline is being destroyed all the waiters waiting for the
sync_fence to signal need to be woken up and finished as well.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/staging/android/sw_sync.c | 8 ++++++++
 drivers/staging/android/sync.c    | 9 +++++++++
 drivers/staging/android/sync.h    | 2 ++
 3 files changed, 19 insertions(+)

diff --git a/drivers/staging/android/sw_sync.c b/drivers/staging/android/sw_sync.c
index ee7a942..8c83bad 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/staging/android/sw_sync.c
@@ -25,6 +25,13 @@
 
 #include "sw_sync.h"
 
+static void sw_sync_cleanup(struct fence *fence, void *user_data)
+{
+	struct sync_fence *sync_fence = user_data;
+
+	sync_fence_cleanup(sync_fence);
+}
+
 static const struct fence_ops sw_sync_fence_ops = {
 	.get_driver_name = fence_default_get_driver_name,
 	.get_timeline_name = fence_default_get_timeline_name,
@@ -32,6 +39,7 @@ static const struct fence_ops sw_sync_fence_ops = {
 	.signaled = fence_default_signaled,
 	.wait = fence_default_wait,
 	.release = fence_default_release,
+	.cleanup = sw_sync_cleanup,
 	.fill_driver_data = fence_default_fill_driver_data,
 	.fence_value_str = fence_default_value_str,
 	.timeline_value_str = fence_default_timeline_value_str,
diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c
index 956b4e9..aafecf4 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/staging/android/sync.c
@@ -91,6 +91,8 @@ struct sync_fence *sync_fence_create_dma(const char *name, struct fence *fence)
 
 	sync_fence_debug_add(sync_fence);
 
+	fence_add_user_data(fence, sync_fence);
+
 	return sync_fence;
 }
 EXPORT_SYMBOL(sync_fence_create_dma);
@@ -101,6 +103,13 @@ struct sync_fence *sync_fence_create(const char *name, struct fence *fence)
 }
 EXPORT_SYMBOL(sync_fence_create);
 
+void sync_fence_cleanup(struct sync_fence *sync_fence)
+{
+	atomic_set(&sync_fence->status, -ENOENT);
+	wake_up_all(&sync_fence->wq);
+}
+EXPORT_SYMBOL(sync_fence_cleanup);
+
 struct sync_fence *sync_fence_fdget(int fd)
 {
 	struct file *file = fget(fd);
diff --git a/drivers/staging/android/sync.h b/drivers/staging/android/sync.h
index 8e6827b..d60d9c2 100644
--- a/drivers/staging/android/sync.h
+++ b/drivers/staging/android/sync.h
@@ -98,6 +98,8 @@ struct sync_fence *sync_fence_create(const char *name, struct fence *fence);
  */
 struct sync_fence *sync_fence_create_dma(const char *name, struct fence *pt);
 
+void sync_fence_cleanup(struct sync_fence *sync_fence);
+
 /*
  * API for sync_fence consumers
  */
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 29/29] dma-buf/fence: de-stage sync framework
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-15 14:55   ` Gustavo Padovan
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The sync framework is ready for mainline inclusion. Here we move it to
drivers/dma-buf and the header files to the appropiated places.

The sync framework contained some abstractions around struct fence and those
were removed in the de-staging process among other changes:

Userspace visible changes
-------------------------

 * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
  other change.

Kernel API changes
------------------

 * struct sync_timeline is now struct fence_timeline
 * sync_timeline_ops is now fence_timeline_ops and they now carry struct
 fence as parameter instead of struct sync_pt
 * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
 the fence_timeline is destroyed
 * added fence_add_used_data() to pass a private point to struct fence.
 This pointer is sent back on the .cleanup op.
 * The sync timeline function were moved to be fence_timeline functions:
         - sync_timeline_create()       -> fence_timeline_create()
         - sync_timeline_get()          -> fence_timeline_get()
         - sync_timeline_put()          -> fence_timeline_put()
         - sync_timeline_destroy()      -> fence_timeline_destroy()
         - sync_timeline_signal()       -> fence_timeline_signal()

  * sync_pt_create() was replaced be fence_create_on_timeline()

Internal changes
----------------

 * fence_timeline_ops was removed in favor of direct use fence_ops
 * fence default functions were created for fence_ops
 * removed structs sync_pt, sw_sync_timeline and sw_sync_pt

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/Kconfig                                    |  2 ++
 drivers/dma-buf/Kconfig                            | 22 ++++++++++++++++++++++
 drivers/dma-buf/Makefile                           |  2 ++
 drivers/{staging/android => dma-buf}/sw_sync.c     |  3 +--
 drivers/{staging/android => dma-buf}/sync.c        |  7 ++++---
 drivers/{staging/android => dma-buf}/sync_debug.c  |  2 +-
 drivers/staging/android/Kconfig                    | 19 -------------------
 drivers/staging/android/Makefile                   |  2 --
 .../staging/android => include/linux}/sw_sync.h    |  4 ++--
 {drivers/staging/android => include/linux}/sync.h  |  4 ++--
 .../android/trace => include/trace/events}/sync.h  |  5 ++---
 .../android/uapi => include/uapi/linux}/sw_sync.h  |  0
 .../android/uapi => include/uapi/linux}/sync.h     |  0
 13 files changed, 38 insertions(+), 34 deletions(-)
 create mode 100644 drivers/dma-buf/Kconfig
 rename drivers/{staging/android => dma-buf}/sw_sync.c (98%)
 rename drivers/{staging/android => dma-buf}/sync.c (99%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (99%)
 rename {drivers/staging/android => include/linux}/sw_sync.h (95%)
 rename {drivers/staging/android => include/linux}/sync.h (99%)
 rename {drivers/staging/android/trace => include/trace/events}/sync.h (92%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sw_sync.h (100%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sync.h (100%)

diff --git a/drivers/Kconfig b/drivers/Kconfig
index d2ac339..430f761 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -114,6 +114,8 @@ source "drivers/rtc/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/dma-buf/Kconfig"
+
 source "drivers/dca/Kconfig"
 
 source "drivers/auxdisplay/Kconfig"
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
new file mode 100644
index 0000000..4168f89
--- /dev/null
+++ b/drivers/dma-buf/Kconfig
@@ -0,0 +1,22 @@
+menu "DMABUF options"
+
+config SYNC
+	bool "Synchronization framework"
+	default n
+	select ANON_INODES
+	select DMA_SHARED_BUFFER
+	---help---
+	  This option enables the framework for synchronization between multiple
+	  drivers.  Sync implementations can take advantage of hardware
+	  synchronization built into devices like GPUs.
+
+config SW_SYNC
+	bool "Software synchronization objects"
+	default n
+	depends on SYNC
+	---help---
+	  A sync object driver that uses a 32bit counter to coordinate
+	  synchronization.  Useful when there is no hardware primitive backing
+	  the synchronization.
+
+endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index fb03696..b870923 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1,3 @@
 obj-y := dma-buf.o fence.o fence_debug.o reservation.o seqno-fence.o
+obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/dma-buf/sw_sync.c
similarity index 98%
rename from drivers/staging/android/sw_sync.c
rename to drivers/dma-buf/sw_sync.c
index 8c83bad..32d0800 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -22,8 +22,7 @@
 #include <linux/miscdevice.h>
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
-
-#include "sw_sync.h"
+#include <linux/sw_sync.h>
 
 static void sw_sync_cleanup(struct fence *fence, void *user_data)
 {
diff --git a/drivers/staging/android/sync.c b/drivers/dma-buf/sync.c
similarity index 99%
rename from drivers/staging/android/sync.c
rename to drivers/dma-buf/sync.c
index aafecf4..248aa44 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/dma-buf/sync.c
@@ -26,10 +26,10 @@
 #include <linux/uaccess.h>
 #include <linux/anon_inodes.h>
 
-#include "sync.h"
+#include <linux/sync.h>
 
 #define CREATE_TRACE_POINTS
-#include "trace/sync.h"
+#include <trace/events/sync.h>
 
 static const struct file_operations sync_fence_fops;
 
@@ -280,7 +280,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_fence(sync_fence->cbs[i].fence);
+		trace_sync_fence(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -395,6 +395,7 @@ static long sync_fence_ioctl_merge(struct sync_fence *sync_fence,
 
 	sync_fence_install(fence3, fd);
 	sync_fence_put(fence2);
+
 	return 0;
 
 err_put_fence3:
diff --git a/drivers/staging/android/sync_debug.c b/drivers/dma-buf/sync_debug.c
similarity index 99%
rename from drivers/staging/android/sync_debug.c
rename to drivers/dma-buf/sync_debug.c
index 8e2ca57..294786b 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/dma-buf/sync_debug.c
@@ -27,7 +27,7 @@
 #include <linux/uaccess.h>
 #include <linux/anon_inodes.h>
 #include <linux/time64.h>
-#include "sw_sync.h"
+#include <linux/sw_sync.h>
 
 #ifdef CONFIG_DEBUG_FS
 
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index bd90d20..4b18fee 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -38,25 +38,6 @@ config ANDROID_LOW_MEMORY_KILLER
 	  scripts (/init.rc), and it defines priority values with minimum free memory size
 	  for each priority.
 
-config SYNC
-	bool "Synchronization framework"
-	default n
-	select ANON_INODES
-	select DMA_SHARED_BUFFER
-	---help---
-	  This option enables the framework for synchronization between multiple
-	  drivers.  Sync implementations can take advantage of hardware
-	  synchronization built into devices like GPUs.
-
-config SW_SYNC
-	bool "Software synchronization objects"
-	default n
-	depends on SYNC
-	---help---
-	  A sync object driver that uses a 32bit counter to coordinate
-	  synchronization.  Useful when there is no hardware primitive backing
-	  the synchronization.
-
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index c7b6c99..355ad0e 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -6,5 +6,3 @@ obj-$(CONFIG_ASHMEM)			+= ashmem.o
 obj-$(CONFIG_ANDROID_TIMED_OUTPUT)	+= timed_output.o
 obj-$(CONFIG_ANDROID_TIMED_GPIO)	+= timed_gpio.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)	+= lowmemorykiller.o
-obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
diff --git a/drivers/staging/android/sw_sync.h b/include/linux/sw_sync.h
similarity index 95%
rename from drivers/staging/android/sw_sync.h
rename to include/linux/sw_sync.h
index f912888..68cb3d9 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/include/linux/sw_sync.h
@@ -19,8 +19,8 @@
 
 #include <linux/types.h>
 #include <linux/kconfig.h>
-#include "sync.h"
-#include "uapi/sw_sync.h"
+#include <linux/sync.h>
+#include <uapi/linux/sw_sync.h>
 
 #if IS_ENABLED(CONFIG_SW_SYNC)
 struct fence_timeline *sw_sync_timeline_create(const char *name);
diff --git a/drivers/staging/android/sync.h b/include/linux/sync.h
similarity index 99%
rename from drivers/staging/android/sync.h
rename to include/linux/sync.h
index d60d9c2..ecefed5 100644
--- a/drivers/staging/android/sync.h
+++ b/include/linux/sync.h
@@ -20,8 +20,8 @@
 #include <linux/spinlock.h>
 #include <linux/wait.h>
 #include <linux/fence.h>
-
-#include "uapi/sync.h"
+#include <linux/sync.h>
+#include <uapi/linux/sync.h>
 
 struct sync_fence;
 
diff --git a/drivers/staging/android/trace/sync.h b/include/trace/events/sync.h
similarity index 92%
rename from drivers/staging/android/trace/sync.h
rename to include/trace/events/sync.h
index 4f68515..fa19962 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/include/trace/events/sync.h
@@ -1,11 +1,10 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
 #define TRACE_SYSTEM sync
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_SYNC_H
 
-#include "../sync.h"
+#include <linux/sync.h>
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(sync_wait,
@@ -29,7 +28,7 @@ TRACE_EVENT(sync_wait,
 			__get_str(name), __entry->status)
 );
 
-TRACE_EVENT(fence,
+TRACE_EVENT(sync_fence,
 	TP_PROTO(struct fence *fence),
 
 	TP_ARGS(fence),
diff --git a/drivers/staging/android/uapi/sw_sync.h b/include/uapi/linux/sw_sync.h
similarity index 100%
rename from drivers/staging/android/uapi/sw_sync.h
rename to include/uapi/linux/sw_sync.h
diff --git a/drivers/staging/android/uapi/sync.h b/include/uapi/linux/sync.h
similarity index 100%
rename from drivers/staging/android/uapi/sync.h
rename to include/uapi/linux/sync.h
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* [RFC 29/29] dma-buf/fence: de-stage sync framework
@ 2016-01-15 14:55   ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 14:55 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>

The sync framework is ready for mainline inclusion. Here we move it to
drivers/dma-buf and the header files to the appropiated places.

The sync framework contained some abstractions around struct fence and those
were removed in the de-staging process among other changes:

Userspace visible changes
-------------------------

 * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
  other change.

Kernel API changes
------------------

 * struct sync_timeline is now struct fence_timeline
 * sync_timeline_ops is now fence_timeline_ops and they now carry struct
 fence as parameter instead of struct sync_pt
 * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
 the fence_timeline is destroyed
 * added fence_add_used_data() to pass a private point to struct fence.
 This pointer is sent back on the .cleanup op.
 * The sync timeline function were moved to be fence_timeline functions:
         - sync_timeline_create()       -> fence_timeline_create()
         - sync_timeline_get()          -> fence_timeline_get()
         - sync_timeline_put()          -> fence_timeline_put()
         - sync_timeline_destroy()      -> fence_timeline_destroy()
         - sync_timeline_signal()       -> fence_timeline_signal()

  * sync_pt_create() was replaced be fence_create_on_timeline()

Internal changes
----------------

 * fence_timeline_ops was removed in favor of direct use fence_ops
 * fence default functions were created for fence_ops
 * removed structs sync_pt, sw_sync_timeline and sw_sync_pt

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
---
 drivers/Kconfig                                    |  2 ++
 drivers/dma-buf/Kconfig                            | 22 ++++++++++++++++++++++
 drivers/dma-buf/Makefile                           |  2 ++
 drivers/{staging/android => dma-buf}/sw_sync.c     |  3 +--
 drivers/{staging/android => dma-buf}/sync.c        |  7 ++++---
 drivers/{staging/android => dma-buf}/sync_debug.c  |  2 +-
 drivers/staging/android/Kconfig                    | 19 -------------------
 drivers/staging/android/Makefile                   |  2 --
 .../staging/android => include/linux}/sw_sync.h    |  4 ++--
 {drivers/staging/android => include/linux}/sync.h  |  4 ++--
 .../android/trace => include/trace/events}/sync.h  |  5 ++---
 .../android/uapi => include/uapi/linux}/sw_sync.h  |  0
 .../android/uapi => include/uapi/linux}/sync.h     |  0
 13 files changed, 38 insertions(+), 34 deletions(-)
 create mode 100644 drivers/dma-buf/Kconfig
 rename drivers/{staging/android => dma-buf}/sw_sync.c (98%)
 rename drivers/{staging/android => dma-buf}/sync.c (99%)
 rename drivers/{staging/android => dma-buf}/sync_debug.c (99%)
 rename {drivers/staging/android => include/linux}/sw_sync.h (95%)
 rename {drivers/staging/android => include/linux}/sync.h (99%)
 rename {drivers/staging/android/trace => include/trace/events}/sync.h (92%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sw_sync.h (100%)
 rename {drivers/staging/android/uapi => include/uapi/linux}/sync.h (100%)

diff --git a/drivers/Kconfig b/drivers/Kconfig
index d2ac339..430f761 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -114,6 +114,8 @@ source "drivers/rtc/Kconfig"
 
 source "drivers/dma/Kconfig"
 
+source "drivers/dma-buf/Kconfig"
+
 source "drivers/dca/Kconfig"
 
 source "drivers/auxdisplay/Kconfig"
diff --git a/drivers/dma-buf/Kconfig b/drivers/dma-buf/Kconfig
new file mode 100644
index 0000000..4168f89
--- /dev/null
+++ b/drivers/dma-buf/Kconfig
@@ -0,0 +1,22 @@
+menu "DMABUF options"
+
+config SYNC
+	bool "Synchronization framework"
+	default n
+	select ANON_INODES
+	select DMA_SHARED_BUFFER
+	---help---
+	  This option enables the framework for synchronization between multiple
+	  drivers.  Sync implementations can take advantage of hardware
+	  synchronization built into devices like GPUs.
+
+config SW_SYNC
+	bool "Software synchronization objects"
+	default n
+	depends on SYNC
+	---help---
+	  A sync object driver that uses a 32bit counter to coordinate
+	  synchronization.  Useful when there is no hardware primitive backing
+	  the synchronization.
+
+endmenu
diff --git a/drivers/dma-buf/Makefile b/drivers/dma-buf/Makefile
index fb03696..b870923 100644
--- a/drivers/dma-buf/Makefile
+++ b/drivers/dma-buf/Makefile
@@ -1 +1,3 @@
 obj-y := dma-buf.o fence.o fence_debug.o reservation.o seqno-fence.o
+obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
+obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
diff --git a/drivers/staging/android/sw_sync.c b/drivers/dma-buf/sw_sync.c
similarity index 98%
rename from drivers/staging/android/sw_sync.c
rename to drivers/dma-buf/sw_sync.c
index 8c83bad..32d0800 100644
--- a/drivers/staging/android/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -22,8 +22,7 @@
 #include <linux/miscdevice.h>
 #include <linux/syscalls.h>
 #include <linux/uaccess.h>
-
-#include "sw_sync.h"
+#include <linux/sw_sync.h>
 
 static void sw_sync_cleanup(struct fence *fence, void *user_data)
 {
diff --git a/drivers/staging/android/sync.c b/drivers/dma-buf/sync.c
similarity index 99%
rename from drivers/staging/android/sync.c
rename to drivers/dma-buf/sync.c
index aafecf4..248aa44 100644
--- a/drivers/staging/android/sync.c
+++ b/drivers/dma-buf/sync.c
@@ -26,10 +26,10 @@
 #include <linux/uaccess.h>
 #include <linux/anon_inodes.h>
 
-#include "sync.h"
+#include <linux/sync.h>
 
 #define CREATE_TRACE_POINTS
-#include "trace/sync.h"
+#include <trace/events/sync.h>
 
 static const struct file_operations sync_fence_fops;
 
@@ -280,7 +280,7 @@ int sync_fence_wait(struct sync_fence *sync_fence, long timeout)
 
 	trace_sync_wait(sync_fence, 1);
 	for (i = 0; i < sync_fence->num_fences; ++i)
-		trace_fence(sync_fence->cbs[i].fence);
+		trace_sync_fence(sync_fence->cbs[i].fence);
 	ret = wait_event_interruptible_timeout(sync_fence->wq,
 					       atomic_read(&sync_fence->status) <= 0,
 					       timeout);
@@ -395,6 +395,7 @@ static long sync_fence_ioctl_merge(struct sync_fence *sync_fence,
 
 	sync_fence_install(fence3, fd);
 	sync_fence_put(fence2);
+
 	return 0;
 
 err_put_fence3:
diff --git a/drivers/staging/android/sync_debug.c b/drivers/dma-buf/sync_debug.c
similarity index 99%
rename from drivers/staging/android/sync_debug.c
rename to drivers/dma-buf/sync_debug.c
index 8e2ca57..294786b 100644
--- a/drivers/staging/android/sync_debug.c
+++ b/drivers/dma-buf/sync_debug.c
@@ -27,7 +27,7 @@
 #include <linux/uaccess.h>
 #include <linux/anon_inodes.h>
 #include <linux/time64.h>
-#include "sw_sync.h"
+#include <linux/sw_sync.h>
 
 #ifdef CONFIG_DEBUG_FS
 
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index bd90d20..4b18fee 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -38,25 +38,6 @@ config ANDROID_LOW_MEMORY_KILLER
 	  scripts (/init.rc), and it defines priority values with minimum free memory size
 	  for each priority.
 
-config SYNC
-	bool "Synchronization framework"
-	default n
-	select ANON_INODES
-	select DMA_SHARED_BUFFER
-	---help---
-	  This option enables the framework for synchronization between multiple
-	  drivers.  Sync implementations can take advantage of hardware
-	  synchronization built into devices like GPUs.
-
-config SW_SYNC
-	bool "Software synchronization objects"
-	default n
-	depends on SYNC
-	---help---
-	  A sync object driver that uses a 32bit counter to coordinate
-	  synchronization.  Useful when there is no hardware primitive backing
-	  the synchronization.
-
 source "drivers/staging/android/ion/Kconfig"
 
 endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index c7b6c99..355ad0e 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -6,5 +6,3 @@ obj-$(CONFIG_ASHMEM)			+= ashmem.o
 obj-$(CONFIG_ANDROID_TIMED_OUTPUT)	+= timed_output.o
 obj-$(CONFIG_ANDROID_TIMED_GPIO)	+= timed_gpio.o
 obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER)	+= lowmemorykiller.o
-obj-$(CONFIG_SYNC)			+= sync.o sync_debug.o
-obj-$(CONFIG_SW_SYNC)			+= sw_sync.o
diff --git a/drivers/staging/android/sw_sync.h b/include/linux/sw_sync.h
similarity index 95%
rename from drivers/staging/android/sw_sync.h
rename to include/linux/sw_sync.h
index f912888..68cb3d9 100644
--- a/drivers/staging/android/sw_sync.h
+++ b/include/linux/sw_sync.h
@@ -19,8 +19,8 @@
 
 #include <linux/types.h>
 #include <linux/kconfig.h>
-#include "sync.h"
-#include "uapi/sw_sync.h"
+#include <linux/sync.h>
+#include <uapi/linux/sw_sync.h>
 
 #if IS_ENABLED(CONFIG_SW_SYNC)
 struct fence_timeline *sw_sync_timeline_create(const char *name);
diff --git a/drivers/staging/android/sync.h b/include/linux/sync.h
similarity index 99%
rename from drivers/staging/android/sync.h
rename to include/linux/sync.h
index d60d9c2..ecefed5 100644
--- a/drivers/staging/android/sync.h
+++ b/include/linux/sync.h
@@ -20,8 +20,8 @@
 #include <linux/spinlock.h>
 #include <linux/wait.h>
 #include <linux/fence.h>
-
-#include "uapi/sync.h"
+#include <linux/sync.h>
+#include <uapi/linux/sync.h>
 
 struct sync_fence;
 
diff --git a/drivers/staging/android/trace/sync.h b/include/trace/events/sync.h
similarity index 92%
rename from drivers/staging/android/trace/sync.h
rename to include/trace/events/sync.h
index 4f68515..fa19962 100644
--- a/drivers/staging/android/trace/sync.h
+++ b/include/trace/events/sync.h
@@ -1,11 +1,10 @@
 #undef TRACE_SYSTEM
-#define TRACE_INCLUDE_PATH ../../drivers/staging/android/trace
 #define TRACE_SYSTEM sync
 
 #if !defined(_TRACE_SYNC_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_SYNC_H
 
-#include "../sync.h"
+#include <linux/sync.h>
 #include <linux/tracepoint.h>
 
 TRACE_EVENT(sync_wait,
@@ -29,7 +28,7 @@ TRACE_EVENT(sync_wait,
 			__get_str(name), __entry->status)
 );
 
-TRACE_EVENT(fence,
+TRACE_EVENT(sync_fence,
 	TP_PROTO(struct fence *fence),
 
 	TP_ARGS(fence),
diff --git a/drivers/staging/android/uapi/sw_sync.h b/include/uapi/linux/sw_sync.h
similarity index 100%
rename from drivers/staging/android/uapi/sw_sync.h
rename to include/uapi/linux/sw_sync.h
diff --git a/drivers/staging/android/uapi/sync.h b/include/uapi/linux/sync.h
similarity index 100%
rename from drivers/staging/android/uapi/sync.h
rename to include/uapi/linux/sync.h
-- 
2.5.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-01-15 14:55   ` Gustavo Padovan
  (?)
@ 2016-01-15 17:48   ` John Harrison
  2016-01-15 18:02     ` Gustavo Padovan
  -1 siblings, 1 reply; 94+ messages in thread
From: John Harrison @ 2016-01-15 17:48 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, Maarten Lankhorst, Gustavo Padovan

On 15/01/2016 14:55, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> All changes to timeline value come through the user via
> fence_timeline_signal() calls. When fence_timeline_destroy() is called no
> changes on timeline->value happens hence call fence_timeline_signal() with
> no increment is pointless.
>
> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> ---
>   drivers/dma-buf/fence.c | 6 +-----
>   1 file changed, 1 insertion(+), 5 deletions(-)
>
> diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
> index 7a5fc9b..26f5f0f 100644
> --- a/drivers/dma-buf/fence.c
> +++ b/drivers/dma-buf/fence.c
> @@ -136,7 +136,7 @@ EXPORT_SYMBOL(fence_timeline_put);
>    * fence_timeline_destroy - destroy a fence_timeline
>    * @timeline	[in]	the fence_timeline to destroy
>    *
> - * This function destroys a timeline. It signals any active fence first.
> + * This function destroys a timeline.

The implementation for this was certainly broken but I would say it 
should be fixed to match the comment rather than just abandoned 
completely. That is, what happens if a timeline owner destroys their 
timeline while there are outstanding fences which other drivers are 
waiting on? That is presumably a bug in the code that called destroy 
prematurely, but bugs happen.

The old implementation simply leaked the fences. Doing a debugfs dump 
would show the timeline with all its outstanding fences still floating 
around forever after. Worse, anything waiting on them would never be 
signalled and is therefore potentially deadlocked.

Note that I haven't had chance to look through the entire patch series 
yet so maybe this has been fixed up elsewhere. If not, then I think it 
definitely needs looking into.


>    */
>   void fence_timeline_destroy(struct fence_timeline *timeline)
>   {
> @@ -147,10 +147,6 @@ void fence_timeline_destroy(struct fence_timeline *timeline)
>   	 */
>   	smp_wmb();
>   
> -	/*
> -	 * signal any children that their parent is going away.
> -	 */
> -	fence_timeline_signal(timeline, 0);
>   	fence_timeline_put(timeline);
>   }
>   EXPORT_SYMBOL(fence_timeline_destroy);

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-01-15 17:48   ` John Harrison
@ 2016-01-15 18:02     ` Gustavo Padovan
  2016-01-15 23:42         ` Greg Hackmann
  0 siblings, 1 reply; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-15 18:02 UTC (permalink / raw)
  To: John Harrison
  Cc: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Daniel Vetter, Rob Clark, Greg Hackmann, Maarten Lankhorst

2016-01-15 John Harrison <John.C.Harrison@Intel.com>:

> On 15/01/2016 14:55, Gustavo Padovan wrote:
> >From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >
> >All changes to timeline value come through the user via
> >fence_timeline_signal() calls. When fence_timeline_destroy() is called no
> >changes on timeline->value happens hence call fence_timeline_signal() with
> >no increment is pointless.
> >
> >Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >---
> >  drivers/dma-buf/fence.c | 6 +-----
> >  1 file changed, 1 insertion(+), 5 deletions(-)
> >
> >diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c
> >index 7a5fc9b..26f5f0f 100644
> >--- a/drivers/dma-buf/fence.c
> >+++ b/drivers/dma-buf/fence.c
> >@@ -136,7 +136,7 @@ EXPORT_SYMBOL(fence_timeline_put);
> >   * fence_timeline_destroy - destroy a fence_timeline
> >   * @timeline	[in]	the fence_timeline to destroy
> >   *
> >- * This function destroys a timeline. It signals any active fence first.
> >+ * This function destroys a timeline.
> 
> The implementation for this was certainly broken but I would say it should
> be fixed to match the comment rather than just abandoned completely. That
> is, what happens if a timeline owner destroys their timeline while there are
> outstanding fences which other drivers are waiting on? That is presumably a
> bug in the code that called destroy prematurely, but bugs happen.
> 
> The old implementation simply leaked the fences. Doing a debugfs dump would
> show the timeline with all its outstanding fences still floating around
> forever after. Worse, anything waiting on them would never be signalled and
> is therefore potentially deadlocked.
> 
> Note that I haven't had chance to look through the entire patch series yet
> so maybe this has been fixed up elsewhere. If not, then I think it
> definitely needs looking into.
> 

Patches 27 and 28 are attempt to fix that. I assumed that if some code is
calling fence_timeline_destroy() it wants to stop everything so I
worked on a solution that stops any waiter and allows the timeline to be
destroyed.

No one is using fence_timeline_destroy() in mainline now, so it is
definately a behaviour we can discuss.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
                   ` (28 preceding siblings ...)
  2016-01-15 14:55   ` Gustavo Padovan
@ 2016-01-15 19:11 ` Joe Perches
  2016-01-19 11:00   ` Daniel Vetter
  2016-01-20 10:28 ` Maarten Lankhorst
  31 siblings, 0 replies; 94+ messages in thread
From: Joe Perches @ 2016-01-15 19:11 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

On Fri, 2016-01-15 at 12:55 -0200, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> 
> This patch series de-stage the sync framework, and in order to accomplish that
> a bunch of cleanups/improvements on the sync and fence were made.

Perhaps add/update a MAINTAINERS entry too?

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-01-15 18:02     ` Gustavo Padovan
@ 2016-01-15 23:42         ` Greg Hackmann
  0 siblings, 0 replies; 94+ messages in thread
From: Greg Hackmann @ 2016-01-15 23:42 UTC (permalink / raw)
  To: Gustavo Padovan, John Harrison
  Cc: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Daniel Vetter, Rob Clark, Maarten Lankhorst, tomcherry, dtor

On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
> calling fence_timeline_destroy() it wants to stop everything so I
> worked on a solution that stops any waiter and allows the timeline to be
> destroyed.
>
> No one is using fence_timeline_destroy() in mainline now, so it is
> definately a behaviour we can discuss.
>
> 	Gustavo
>

+Tom Cherry and Dmitry Torokhov recently discovered that this was broken 
by the refactoring of Android sync on top of dma-buf fences.

Tom and Dmitry, did you send the proposed fix upstream?

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
@ 2016-01-15 23:42         ` Greg Hackmann
  0 siblings, 0 replies; 94+ messages in thread
From: Greg Hackmann @ 2016-01-15 23:42 UTC (permalink / raw)
  To: Gustavo Padovan, John Harrison
  Cc: devel, daniels, tomcherry, linux-kernel, dri-devel,
	Daniel Vetter, Maarten Lankhorst, Arve Hjønnevåg,
	Greg Kroah-Hartman, Riley Andrews, dtor

On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
> calling fence_timeline_destroy() it wants to stop everything so I
> worked on a solution that stops any waiter and allows the timeline to be
> destroyed.
>
> No one is using fence_timeline_destroy() in mainline now, so it is
> definately a behaviour we can discuss.
>
> 	Gustavo
>

+Tom Cherry and Dmitry Torokhov recently discovered that this was broken 
by the refactoring of Android sync on top of dma-buf fences.

Tom and Dmitry, did you send the proposed fix upstream?
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
@ 2016-01-19 11:00   ` Daniel Vetter
  2016-01-15 14:55   ` Gustavo Padovan
                     ` (30 subsequent siblings)
  31 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 11:00 UTC (permalink / raw)
  To: Gustavo Padovan
  Cc: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Greg Hackmann, John Harrison, Maarten Lankhorst,
	Gustavo Padovan

On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> 
> This patch series de-stage the sync framework, and in order to accomplish that
> a bunch of cleanups/improvements on the sync and fence were made.
> 
> The sync framework contained some abstractions around struct fence and those
> were removed in the de-staging process among other changes:
> 
> Userspace visible changes
> -------------------------
> 
>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>  other change.
> 
> Kernel API changes
> ------------------
> 
>  * struct sync_timeline is now struct fence_timeline
>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>  fence as parameter instead of struct sync_pt
>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>  the fence_timeline is destroyed
>  * added fence_add_used_data() to pass a private point to struct fence. This
>  pointer is sent back on the .cleanup op.
>  * The sync timeline function were moved to be fence_timeline functions:
> 	 - sync_timeline_create()	-> fence_timeline_create()
> 	 - sync_timeline_get()		-> fence_timeline_get()
> 	 - sync_timeline_put()		-> fence_timeline_put()
> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> 
>   * sync_pt_create() was replaced be fence_create_on_timeline()
> 
> Internal changes
> ----------------
> 
>  * fence_timeline_ops was removed in favor of direct use fence_ops
>  * fence default functions were created for fence_ops
>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt

Bunch of fairly random comments all over:

- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
  debugfs interface between fence fds and the testsuite. Since the plan is
  to have the testcases integrated into the kernel tree too we don't need
  a public header.

- similar for include/linux/sw_sync.h Imo that should all be moved into
  sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
  imo, and made optional with a Kconfig option. At least we should reuse
  CONFIG_DEBUGFS.

- fence_context and fence_timeline are really the same. timeline has some
  super-basic support for doing sw-only fence timelines, but imo that's
  not really worth keeping (and if so better to keep seperate in a
  sw-fence.c or similar, like seqno-fence.c). The other main thing
  timeline provides is support to clean up fences on a timeline. And imo
  that cleanup should be done by the core fence support, not by the add-on
  stuff.

Interlude about fence cleanup on driver unload:

Working drivers imo should never call timeline_destroy when there's still
an unsignalled fence around for that timeline/context. That just means
they're broken and failed to clean up all the pending work. So the problem
really is only what to do with fences where the driver disappeared, and
for that we essentially need a fence_revoke() function (which could be
called internally from timeline_free). So here's what I think
timeline_free should do:

for_each_fence_on_timel() {
	WARN_ON(!fence_is_signalled());

	fence_revoke(fence);
}

Implementing fence_revoke is a bit tricky since we need to make sure the
memory contained ->ops and similar stuff doesn't disappear. Simplest
option might be to grab a temporary reference (using
kref_get_unless_zero), and then exchange ->ops with one that has only a
release function. We don't need anything else as long as all fence_*
functions the kernel might call check for signalling correctly first
(fence_wait is broken at least).

Or we just give up (for now) and declare module unload as slightly racy.
dma-buf is similar. An intermediate option might be to at least add a
THIS_MODULE reference to each fence (but that's a bit expensive ...).

- back to timeline vs. context: I have no idea how to best clean up this
  mess, but least painful option long-term is probably to switch over all
  current users of fence_context_alloc to timelines and remove the plain
  context interface.

- Imo the interface in include/linux/sync.h is duplicating too much of
  fence.h. I think the only bits we need are the refcounting, creating,
  fd-install and that's it. Plus a macro to loop over all the fences in a
  sync_fence. With that drivers will only ever deal with a pile of
  struct fence, making implicit fencing (using the fence list in dma-buf)
  and explicit fencing (using the fence list in sync_fence) much more
  similar.

  And we can easily do that since no internal users ;-)

- get_timeline_name and get_driver_name are imo too much indirection, just
  add ->(drv_)name field to each of these.

- struct sync_fence is a major confusion imo against struct fence. It
  made much more sense in the pure-android world where fence == sync_pt.
  Maybe we can rename sync_fence to sync_fence_fd (a bit long, and fd is a
  bit inaccurate), sync_file (like this best), fence_file (sounds silly
  imo), or something else?

- I guess just not yet part of this rfc, but moving the testsuite and
  adding kerneldoc for this is planned I guess? If you feel like I think
  it'd be best. We pull the current dma-buf stuff into
  device-drivers.tmpl, but it's completely lacking overview docs and all
  that. And I'd like to duplicate at least the dma-buf/fence sections into
  the gpu.tmpl docbook.

- If we make timelines first class objects I think we could move some of
  the fields from struct fence to struct fence_timeline. E.g. the ops
  struct. That also makes it clearer that some of the vfuncs really should
  be taking a struct fence_timeline *timeline instead of a struct fence
  *fence as their primary parameter.

Cheers, Daniel

> 
> Gustavo Padovan (29):
>   staging/android: fix sync framework documentation
>   staging/android: fix checkpatch warning
>   staging/android: rename sync_fence_release
>   staging/android: rename 'android_fence' to 'sync_fence'
>   staging/android: remove not used sync_timeline ops
>   staging/android: create a 'sync' dir for debugfs information
>   staging/android: move sw_sync file to debugfs file
>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
>   staging/android: rename struct sync_fence's variables to 'sync_fence'
>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
>   dma-buf/fence: move sync_timeline to fence_timeline
>   staging/android: remove struct sync_pt
>   dma-buf/fence: create fence_default_enable_signaling()
>   dma-buf/fence: create fence_default_release()
>   dma-buf/fence: create fence_default_get_driver_name()
>   dma-buf/fence: create fence_default_timeline_name()
>   dma-buf/fence: store last signaled value on fence timeline
>   dma-buf/fence: create default .fence_value_str() and
>     .timeline_value_str()
>   dma-buf/fence: create fence_default_fill_driver_data()
>   dma-buf/fence: remove fence_timeline_ops
>   dma-buf/fence: add fence_create_on_timeline()
>   staging/android: remove sync_pt_create()
>   staging/android: remove sw_sync_timeline and sw_sync_pt
>   dma-buf/fence: add debug to fence timeline
>   dma-buf/fence: remove unused var from fence_timeline_signal()
>   dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
>   dma-buf/fence: add .cleanup() callback
>   staging/android: use .cleanup() to interrupt any sync_fence waiter
>   dma-buf/fence: de-stage sync framework
> 
>  drivers/Kconfig                                    |   2 +
>  drivers/dma-buf/Kconfig                            |  22 +
>  drivers/dma-buf/Makefile                           |   4 +-
>  drivers/dma-buf/fence.c                            | 333 ++++++++++
>  drivers/dma-buf/fence_debug.c                      | 128 ++++
>  drivers/dma-buf/sw_sync.c                          |  65 ++
>  drivers/dma-buf/sync.c                             | 527 +++++++++++++++
>  drivers/dma-buf/sync_debug.c                       | 279 ++++++++
>  drivers/staging/android/Kconfig                    |  28 -
>  drivers/staging/android/Makefile                   |   2 -
>  drivers/staging/android/sw_sync.c                  | 260 --------
>  drivers/staging/android/sync.c                     | 732 ---------------------
>  drivers/staging/android/sync.h                     | 366 -----------
>  drivers/staging/android/sync_debug.c               | 256 -------
>  include/linux/fence.h                              |  77 +++
>  .../staging/android => include/linux}/sw_sync.h    |  30 +-
>  include/linux/sync.h                               | 201 ++++++
>  include/trace/events/fence.h                       |  18 +
>  .../android/trace => include/trace/events}/sync.h  |  41 +-
>  .../android/uapi => include/uapi/linux}/sw_sync.h  |   0
>  .../android/uapi => include/uapi/linux}/sync.h     |   0
>  21 files changed, 1672 insertions(+), 1699 deletions(-)
>  create mode 100644 drivers/dma-buf/Kconfig
>  create mode 100644 drivers/dma-buf/fence_debug.c
>  create mode 100644 drivers/dma-buf/sw_sync.c
>  create mode 100644 drivers/dma-buf/sync.c
>  create mode 100644 drivers/dma-buf/sync_debug.c
>  delete mode 100644 drivers/staging/android/sw_sync.c
>  delete mode 100644 drivers/staging/android/sync.c
>  delete mode 100644 drivers/staging/android/sync.h
>  delete mode 100644 drivers/staging/android/sync_debug.c
>  rename {drivers/staging/android => include/linux}/sw_sync.h (55%)
>  create mode 100644 include/linux/sync.h
>  rename {drivers/staging/android/trace => include/trace/events}/sync.h (53%)
>  rename {drivers/staging/android/uapi => include/uapi/linux}/sw_sync.h (100%)
>  rename {drivers/staging/android/uapi => include/uapi/linux}/sync.h (100%)
> 
> -- 
> 2.5.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 11:00   ` Daniel Vetter
  0 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 11:00 UTC (permalink / raw)
  To: Gustavo Padovan
  Cc: devel, Rob Clark, daniels, Greg Kroah-Hartman, linux-kernel,
	dri-devel, Maarten Lankhorst, Arve Hjønnevåg,
	Greg Hackmann, Daniel Vetter, Riley Andrews, Gustavo Padovan,
	John Harrison

On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> 
> This patch series de-stage the sync framework, and in order to accomplish that
> a bunch of cleanups/improvements on the sync and fence were made.
> 
> The sync framework contained some abstractions around struct fence and those
> were removed in the de-staging process among other changes:
> 
> Userspace visible changes
> -------------------------
> 
>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>  other change.
> 
> Kernel API changes
> ------------------
> 
>  * struct sync_timeline is now struct fence_timeline
>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>  fence as parameter instead of struct sync_pt
>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>  the fence_timeline is destroyed
>  * added fence_add_used_data() to pass a private point to struct fence. This
>  pointer is sent back on the .cleanup op.
>  * The sync timeline function were moved to be fence_timeline functions:
> 	 - sync_timeline_create()	-> fence_timeline_create()
> 	 - sync_timeline_get()		-> fence_timeline_get()
> 	 - sync_timeline_put()		-> fence_timeline_put()
> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> 
>   * sync_pt_create() was replaced be fence_create_on_timeline()
> 
> Internal changes
> ----------------
> 
>  * fence_timeline_ops was removed in favor of direct use fence_ops
>  * fence default functions were created for fence_ops
>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt

Bunch of fairly random comments all over:

- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
  debugfs interface between fence fds and the testsuite. Since the plan is
  to have the testcases integrated into the kernel tree too we don't need
  a public header.

- similar for include/linux/sw_sync.h Imo that should all be moved into
  sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
  imo, and made optional with a Kconfig option. At least we should reuse
  CONFIG_DEBUGFS.

- fence_context and fence_timeline are really the same. timeline has some
  super-basic support for doing sw-only fence timelines, but imo that's
  not really worth keeping (and if so better to keep seperate in a
  sw-fence.c or similar, like seqno-fence.c). The other main thing
  timeline provides is support to clean up fences on a timeline. And imo
  that cleanup should be done by the core fence support, not by the add-on
  stuff.

Interlude about fence cleanup on driver unload:

Working drivers imo should never call timeline_destroy when there's still
an unsignalled fence around for that timeline/context. That just means
they're broken and failed to clean up all the pending work. So the problem
really is only what to do with fences where the driver disappeared, and
for that we essentially need a fence_revoke() function (which could be
called internally from timeline_free). So here's what I think
timeline_free should do:

for_each_fence_on_timel() {
	WARN_ON(!fence_is_signalled());

	fence_revoke(fence);
}

Implementing fence_revoke is a bit tricky since we need to make sure the
memory contained ->ops and similar stuff doesn't disappear. Simplest
option might be to grab a temporary reference (using
kref_get_unless_zero), and then exchange ->ops with one that has only a
release function. We don't need anything else as long as all fence_*
functions the kernel might call check for signalling correctly first
(fence_wait is broken at least).

Or we just give up (for now) and declare module unload as slightly racy.
dma-buf is similar. An intermediate option might be to at least add a
THIS_MODULE reference to each fence (but that's a bit expensive ...).

- back to timeline vs. context: I have no idea how to best clean up this
  mess, but least painful option long-term is probably to switch over all
  current users of fence_context_alloc to timelines and remove the plain
  context interface.

- Imo the interface in include/linux/sync.h is duplicating too much of
  fence.h. I think the only bits we need are the refcounting, creating,
  fd-install and that's it. Plus a macro to loop over all the fences in a
  sync_fence. With that drivers will only ever deal with a pile of
  struct fence, making implicit fencing (using the fence list in dma-buf)
  and explicit fencing (using the fence list in sync_fence) much more
  similar.

  And we can easily do that since no internal users ;-)

- get_timeline_name and get_driver_name are imo too much indirection, just
  add ->(drv_)name field to each of these.

- struct sync_fence is a major confusion imo against struct fence. It
  made much more sense in the pure-android world where fence == sync_pt.
  Maybe we can rename sync_fence to sync_fence_fd (a bit long, and fd is a
  bit inaccurate), sync_file (like this best), fence_file (sounds silly
  imo), or something else?

- I guess just not yet part of this rfc, but moving the testsuite and
  adding kerneldoc for this is planned I guess? If you feel like I think
  it'd be best. We pull the current dma-buf stuff into
  device-drivers.tmpl, but it's completely lacking overview docs and all
  that. And I'd like to duplicate at least the dma-buf/fence sections into
  the gpu.tmpl docbook.

- If we make timelines first class objects I think we could move some of
  the fields from struct fence to struct fence_timeline. E.g. the ops
  struct. That also makes it clearer that some of the vfuncs really should
  be taking a struct fence_timeline *timeline instead of a struct fence
  *fence as their primary parameter.

Cheers, Daniel

> 
> Gustavo Padovan (29):
>   staging/android: fix sync framework documentation
>   staging/android: fix checkpatch warning
>   staging/android: rename sync_fence_release
>   staging/android: rename 'android_fence' to 'sync_fence'
>   staging/android: remove not used sync_timeline ops
>   staging/android: create a 'sync' dir for debugfs information
>   staging/android: move sw_sync file to debugfs file
>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
>   staging/android: rename struct sync_fence's variables to 'sync_fence'
>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
>   dma-buf/fence: move sync_timeline to fence_timeline
>   staging/android: remove struct sync_pt
>   dma-buf/fence: create fence_default_enable_signaling()
>   dma-buf/fence: create fence_default_release()
>   dma-buf/fence: create fence_default_get_driver_name()
>   dma-buf/fence: create fence_default_timeline_name()
>   dma-buf/fence: store last signaled value on fence timeline
>   dma-buf/fence: create default .fence_value_str() and
>     .timeline_value_str()
>   dma-buf/fence: create fence_default_fill_driver_data()
>   dma-buf/fence: remove fence_timeline_ops
>   dma-buf/fence: add fence_create_on_timeline()
>   staging/android: remove sync_pt_create()
>   staging/android: remove sw_sync_timeline and sw_sync_pt
>   dma-buf/fence: add debug to fence timeline
>   dma-buf/fence: remove unused var from fence_timeline_signal()
>   dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
>   dma-buf/fence: add .cleanup() callback
>   staging/android: use .cleanup() to interrupt any sync_fence waiter
>   dma-buf/fence: de-stage sync framework
> 
>  drivers/Kconfig                                    |   2 +
>  drivers/dma-buf/Kconfig                            |  22 +
>  drivers/dma-buf/Makefile                           |   4 +-
>  drivers/dma-buf/fence.c                            | 333 ++++++++++
>  drivers/dma-buf/fence_debug.c                      | 128 ++++
>  drivers/dma-buf/sw_sync.c                          |  65 ++
>  drivers/dma-buf/sync.c                             | 527 +++++++++++++++
>  drivers/dma-buf/sync_debug.c                       | 279 ++++++++
>  drivers/staging/android/Kconfig                    |  28 -
>  drivers/staging/android/Makefile                   |   2 -
>  drivers/staging/android/sw_sync.c                  | 260 --------
>  drivers/staging/android/sync.c                     | 732 ---------------------
>  drivers/staging/android/sync.h                     | 366 -----------
>  drivers/staging/android/sync_debug.c               | 256 -------
>  include/linux/fence.h                              |  77 +++
>  .../staging/android => include/linux}/sw_sync.h    |  30 +-
>  include/linux/sync.h                               | 201 ++++++
>  include/trace/events/fence.h                       |  18 +
>  .../android/trace => include/trace/events}/sync.h  |  41 +-
>  .../android/uapi => include/uapi/linux}/sw_sync.h  |   0
>  .../android/uapi => include/uapi/linux}/sync.h     |   0
>  21 files changed, 1672 insertions(+), 1699 deletions(-)
>  create mode 100644 drivers/dma-buf/Kconfig
>  create mode 100644 drivers/dma-buf/fence_debug.c
>  create mode 100644 drivers/dma-buf/sw_sync.c
>  create mode 100644 drivers/dma-buf/sync.c
>  create mode 100644 drivers/dma-buf/sync_debug.c
>  delete mode 100644 drivers/staging/android/sw_sync.c
>  delete mode 100644 drivers/staging/android/sync.c
>  delete mode 100644 drivers/staging/android/sync.h
>  delete mode 100644 drivers/staging/android/sync_debug.c
>  rename {drivers/staging/android => include/linux}/sw_sync.h (55%)
>  create mode 100644 include/linux/sync.h
>  rename {drivers/staging/android/trace => include/trace/events}/sync.h (53%)
>  rename {drivers/staging/android/uapi => include/uapi/linux}/sw_sync.h (100%)
>  rename {drivers/staging/android/uapi => include/uapi/linux}/sync.h (100%)
> 
> -- 
> 2.5.0
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 11:00   ` Daniel Vetter
@ 2016-01-19 15:23     ` Gustavo Padovan
  -1 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 15:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Rob Clark,
	Greg Hackmann, John Harrison, Maarten Lankhorst, Gustavo Padovan

Hi Daniel, 

2016-01-19 Daniel Vetter <daniel@ffwll.ch>:

> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > 
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> > 
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> > 
> > Userspace visible changes
> > -------------------------
> > 
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> > 
> > Kernel API changes
> > ------------------
> > 
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> > 
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> > 
> > Internal changes
> > ----------------
> > 
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> 
> Bunch of fairly random comments all over:
> 
> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>   debugfs interface between fence fds and the testsuite. Since the plan is
>   to have the testcases integrated into the kernel tree too we don't need
>   a public header.
> 
> - similar for include/linux/sw_sync.h Imo that should all be moved into
>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>   imo, and made optional with a Kconfig option. At least we should reuse
>   CONFIG_DEBUGFS.

These two items sounds reasonable to me.

> 
> - fence_context and fence_timeline are really the same. timeline has some
>   super-basic support for doing sw-only fence timelines, but imo that's
>   not really worth keeping (and if so better to keep seperate in a
>   sw-fence.c or similar, like seqno-fence.c). The other main thing
>   timeline provides is support to clean up fences on a timeline. And imo
>   that cleanup should be done by the core fence support, not by the add-on
>   stuff.

Yes, they are. But I currently doesn't know how to merge them best, so I
decided to go for a RFC instead of trying some crazy solution touching
all fence_context users.

> 
> Interlude about fence cleanup on driver unload:
> 
> Working drivers imo should never call timeline_destroy when there's still
> an unsignalled fence around for that timeline/context. That just means
> they're broken and failed to clean up all the pending work. So the problem
> really is only what to do with fences where the driver disappeared, and
> for that we essentially need a fence_revoke() function (which could be
> called internally from timeline_free). So here's what I think
> timeline_free should do:
> 
> for_each_fence_on_timel() {
> 	WARN_ON(!fence_is_signalled());
> 
> 	fence_revoke(fence);
> }
> 
> Implementing fence_revoke is a bit tricky since we need to make sure the
> memory contained ->ops and similar stuff doesn't disappear. Simplest
> option might be to grab a temporary reference (using
> kref_get_unless_zero), and then exchange ->ops with one that has only a
> release function. We don't need anything else as long as all fence_*
> functions the kernel might call check for signalling correctly first
> (fence_wait is broken at least).
> 
> Or we just give up (for now) and declare module unload as slightly racy.
> dma-buf is similar. An intermediate option might be to at least add a
> THIS_MODULE reference to each fence (but that's a bit expensive ...).

I'd say we just give up for now as we don't have any driver using
timeline_destroy for now. So we could go for other improvements first.

> - back to timeline vs. context: I have no idea how to best clean up this
>   mess, but least painful option long-term is probably to switch over all
>   current users of fence_context_alloc to timelines and remove the plain
>   context interface.

Agreed.

> 
> - Imo the interface in include/linux/sync.h is duplicating too much of
>   fence.h. I think the only bits we need are the refcounting, creating,
>   fd-install and that's it. Plus a macro to loop over all the fences in a
>   sync_fence. With that drivers will only ever deal with a pile of
>   struct fence, making implicit fencing (using the fence list in dma-buf)
>   and explicit fencing (using the fence list in sync_fence) much more
>   similar.

Yes, most of the sync_fence waiting should not be exported. Drivers
should only wait for fence imo, not sync_fences.

> 
>   And we can easily do that since no internal users ;-)
> 
> - get_timeline_name and get_driver_name are imo too much indirection, just
>   add ->(drv_)name field to each of these.
> 
> - struct sync_fence is a major confusion imo against struct fence. It
>   made much more sense in the pure-android world where fence == sync_pt.
>   Maybe we can rename sync_fence to sync_fence_fd (a bit long, and fd is a
>   bit inaccurate), sync_file (like this best), fence_file (sounds silly
>   imo), or something else?

sync_file sounds good for me. fence_file feels like it a file for a
single fence but we may have many fences on one sync_file.

> 
> - I guess just not yet part of this rfc, but moving the testsuite and
>   adding kerneldoc for this is planned I guess? If you feel like I think
>   it'd be best. We pull the current dma-buf stuff into
>   device-drivers.tmpl, but it's completely lacking overview docs and all
>   that. And I'd like to duplicate at least the dma-buf/fence sections into
>   the gpu.tmpl docbook.

We have converted testsuite from android's libsync but we need to wait
for Google to re-license it to send it upstream.

kerneldoc is planned for sure, but I'd say it will be better to have
some users first, DRM for example.

> 
> - If we make timelines first class objects I think we could move some of
>   the fields from struct fence to struct fence_timeline. E.g. the ops
>   struct. That also makes it clearer that some of the vfuncs really should
>   be taking a struct fence_timeline *timeline instead of a struct fence
>   *fence as their primary parameter.

I'll keep that as a final goal and work RFC v2 and see how far we can
get.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 15:23     ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 15:23 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Rob Clark,
	Greg Hackmann, John Harrison, Maarten Lankhorst, Gustavo Padovan

Hi Daniel, 

2016-01-19 Daniel Vetter <daniel@ffwll.ch>:

> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > 
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> > 
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> > 
> > Userspace visible changes
> > -------------------------
> > 
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> > 
> > Kernel API changes
> > ------------------
> > 
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> > 
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> > 
> > Internal changes
> > ----------------
> > 
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> 
> Bunch of fairly random comments all over:
> 
> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>   debugfs interface between fence fds and the testsuite. Since the plan is
>   to have the testcases integrated into the kernel tree too we don't need
>   a public header.
> 
> - similar for include/linux/sw_sync.h Imo that should all be moved into
>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>   imo, and made optional with a Kconfig option. At least we should reuse
>   CONFIG_DEBUGFS.

These two items sounds reasonable to me.

> 
> - fence_context and fence_timeline are really the same. timeline has some
>   super-basic support for doing sw-only fence timelines, but imo that's
>   not really worth keeping (and if so better to keep seperate in a
>   sw-fence.c or similar, like seqno-fence.c). The other main thing
>   timeline provides is support to clean up fences on a timeline. And imo
>   that cleanup should be done by the core fence support, not by the add-on
>   stuff.

Yes, they are. But I currently doesn't know how to merge them best, so I
decided to go for a RFC instead of trying some crazy solution touching
all fence_context users.

> 
> Interlude about fence cleanup on driver unload:
> 
> Working drivers imo should never call timeline_destroy when there's still
> an unsignalled fence around for that timeline/context. That just means
> they're broken and failed to clean up all the pending work. So the problem
> really is only what to do with fences where the driver disappeared, and
> for that we essentially need a fence_revoke() function (which could be
> called internally from timeline_free). So here's what I think
> timeline_free should do:
> 
> for_each_fence_on_timel() {
> 	WARN_ON(!fence_is_signalled());
> 
> 	fence_revoke(fence);
> }
> 
> Implementing fence_revoke is a bit tricky since we need to make sure the
> memory contained ->ops and similar stuff doesn't disappear. Simplest
> option might be to grab a temporary reference (using
> kref_get_unless_zero), and then exchange ->ops with one that has only a
> release function. We don't need anything else as long as all fence_*
> functions the kernel might call check for signalling correctly first
> (fence_wait is broken at least).
> 
> Or we just give up (for now) and declare module unload as slightly racy.
> dma-buf is similar. An intermediate option might be to at least add a
> THIS_MODULE reference to each fence (but that's a bit expensive ...).

I'd say we just give up for now as we don't have any driver using
timeline_destroy for now. So we could go for other improvements first.

> - back to timeline vs. context: I have no idea how to best clean up this
>   mess, but least painful option long-term is probably to switch over all
>   current users of fence_context_alloc to timelines and remove the plain
>   context interface.

Agreed.

> 
> - Imo the interface in include/linux/sync.h is duplicating too much of
>   fence.h. I think the only bits we need are the refcounting, creating,
>   fd-install and that's it. Plus a macro to loop over all the fences in a
>   sync_fence. With that drivers will only ever deal with a pile of
>   struct fence, making implicit fencing (using the fence list in dma-buf)
>   and explicit fencing (using the fence list in sync_fence) much more
>   similar.

Yes, most of the sync_fence waiting should not be exported. Drivers
should only wait for fence imo, not sync_fences.

> 
>   And we can easily do that since no internal users ;-)
> 
> - get_timeline_name and get_driver_name are imo too much indirection, just
>   add ->(drv_)name field to each of these.
> 
> - struct sync_fence is a major confusion imo against struct fence. It
>   made much more sense in the pure-android world where fence == sync_pt.
>   Maybe we can rename sync_fence to sync_fence_fd (a bit long, and fd is a
>   bit inaccurate), sync_file (like this best), fence_file (sounds silly
>   imo), or something else?

sync_file sounds good for me. fence_file feels like it a file for a
single fence but we may have many fences on one sync_file.

> 
> - I guess just not yet part of this rfc, but moving the testsuite and
>   adding kerneldoc for this is planned I guess? If you feel like I think
>   it'd be best. We pull the current dma-buf stuff into
>   device-drivers.tmpl, but it's completely lacking overview docs and all
>   that. And I'd like to duplicate at least the dma-buf/fence sections into
>   the gpu.tmpl docbook.

We have converted testsuite from android's libsync but we need to wait
for Google to re-license it to send it upstream.

kerneldoc is planned for sure, but I'd say it will be better to have
some users first, DRM for example.

> 
> - If we make timelines first class objects I think we could move some of
>   the fields from struct fence to struct fence_timeline. E.g. the ops
>   struct. That also makes it clearer that some of the vfuncs really should
>   be taking a struct fence_timeline *timeline instead of a struct fence
>   *fence as their primary parameter.

I'll keep that as a final goal and work RFC v2 and see how far we can
get.

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 15:23     ` Gustavo Padovan
  (?)
@ 2016-01-19 16:12     ` John Harrison
  2016-01-19 17:52         ` Gustavo Padovan
  2016-03-23 15:07         ` Tomeu Vizoso
  -1 siblings, 2 replies; 94+ messages in thread
From: John Harrison @ 2016-01-19 16:12 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Rob Clark, Greg Hackmann, Maarten Lankhorst, Gustavo Padovan

On 19/01/2016 15:23, Gustavo Padovan wrote:
> Hi Daniel,
>
> 2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
>
>> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
>>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>
>>> This patch series de-stage the sync framework, and in order to accomplish that
>>> a bunch of cleanups/improvements on the sync and fence were made.
>>>
>>> The sync framework contained some abstractions around struct fence and those
>>> were removed in the de-staging process among other changes:
>>>
>>> Userspace visible changes
>>> -------------------------
>>>
>>>   * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>>>   other change.
>>>
>>> Kernel API changes
>>> ------------------
>>>
>>>   * struct sync_timeline is now struct fence_timeline
>>>   * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>>>   fence as parameter instead of struct sync_pt
>>>   * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>>>   the fence_timeline is destroyed
>>>   * added fence_add_used_data() to pass a private point to struct fence. This
>>>   pointer is sent back on the .cleanup op.
>>>   * The sync timeline function were moved to be fence_timeline functions:
>>> 	 - sync_timeline_create()	-> fence_timeline_create()
>>> 	 - sync_timeline_get()		-> fence_timeline_get()
>>> 	 - sync_timeline_put()		-> fence_timeline_put()
>>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
>>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
>>>
>>>    * sync_pt_create() was replaced be fence_create_on_timeline()
>>>
>>> Internal changes
>>> ----------------
>>>
>>>   * fence_timeline_ops was removed in favor of direct use fence_ops
>>>   * fence default functions were created for fence_ops
>>>   * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>> Bunch of fairly random comments all over:
>>
>> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>>    debugfs interface between fence fds and the testsuite. Since the plan is
>>    to have the testcases integrated into the kernel tree too we don't need
>>    a public header.
>>
>> - similar for include/linux/sw_sync.h Imo that should all be moved into
>>    sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>>    imo, and made optional with a Kconfig option. At least we should reuse
>>    CONFIG_DEBUGFS.
> These two items sounds reasonable to me.

I have just posted our in-progress IGT for testing i915 syncs (with a CC 
of Gustavo). It uses the sw_sync mechanisms. Can you take a quick look 
and see if it is the kind of thing you would expect us to be doing? Or 
is it using interfaces that you are planning to remove and/or make 
kernel only?

I'm not sure having a kernel only test is the best way to go. Having 
user land tests like IGT would be much more versatile.


>> - fence_context and fence_timeline are really the same. timeline has some
>>    super-basic support for doing sw-only fence timelines, but imo that's
>>    not really worth keeping (and if so better to keep seperate in a
>>    sw-fence.c or similar, like seqno-fence.c). The other main thing
>>    timeline provides is support to clean up fences on a timeline. And imo
>>    that cleanup should be done by the core fence support, not by the add-on
>>    stuff.
> Yes, they are. But I currently doesn't know how to merge them best, so I
> decided to go for a RFC instead of trying some crazy solution touching
> all fence_context users.
>
>> Interlude about fence cleanup on driver unload:
>>
>> Working drivers imo should never call timeline_destroy when there's still
>> an unsignalled fence around for that timeline/context. That just means
>> they're broken and failed to clean up all the pending work. So the problem
>> really is only what to do with fences where the driver disappeared, and
>> for that we essentially need a fence_revoke() function (which could be
>> called internally from timeline_free). So here's what I think
>> timeline_free should do:
>>
>> for_each_fence_on_timel() {
>> 	WARN_ON(!fence_is_signalled());
>>
>> 	fence_revoke(fence);
>> }
>>
>> Implementing fence_revoke is a bit tricky since we need to make sure the
>> memory contained ->ops and similar stuff doesn't disappear. Simplest
>> option might be to grab a temporary reference (using
>> kref_get_unless_zero), and then exchange ->ops with one that has only a
>> release function. We don't need anything else as long as all fence_*
>> functions the kernel might call check for signalling correctly first
>> (fence_wait is broken at least).
>>
>> Or we just give up (for now) and declare module unload as slightly racy.
>> dma-buf is similar. An intermediate option might be to at least add a
>> THIS_MODULE reference to each fence (but that's a bit expensive ...).
> I'd say we just give up for now as we don't have any driver using
> timeline_destroy for now. So we could go for other improvements first.
>
>> - back to timeline vs. context: I have no idea how to best clean up this
>>    mess, but least painful option long-term is probably to switch over all
>>    current users of fence_context_alloc to timelines and remove the plain
>>    context interface.
> Agreed.
>
>> - Imo the interface in include/linux/sync.h is duplicating too much of
>>    fence.h. I think the only bits we need are the refcounting, creating,
>>    fd-install and that's it. Plus a macro to loop over all the fences in a
>>    sync_fence. With that drivers will only ever deal with a pile of
>>    struct fence, making implicit fencing (using the fence list in dma-buf)
>>    and explicit fencing (using the fence list in sync_fence) much more
>>    similar.
> Yes, most of the sync_fence waiting should not be exported. Drivers
> should only wait for fence imo, not sync_fences.
>
>>    And we can easily do that since no internal users ;-)
>>
>> - get_timeline_name and get_driver_name are imo too much indirection, just
>>    add ->(drv_)name field to each of these.
>>
>> - struct sync_fence is a major confusion imo against struct fence. It
>>    made much more sense in the pure-android world where fence == sync_pt.
>>    Maybe we can rename sync_fence to sync_fence_fd (a bit long, and fd is a
>>    bit inaccurate), sync_file (like this best), fence_file (sounds silly
>>    imo), or something else?
> sync_file sounds good for me. fence_file feels like it a file for a
> single fence but we may have many fences on one sync_file.
>
>> - I guess just not yet part of this rfc, but moving the testsuite and
>>    adding kerneldoc for this is planned I guess? If you feel like I think
>>    it'd be best. We pull the current dma-buf stuff into
>>    device-drivers.tmpl, but it's completely lacking overview docs and all
>>    that. And I'd like to duplicate at least the dma-buf/fence sections into
>>    the gpu.tmpl docbook.
> We have converted testsuite from android's libsync but we need to wait
> for Google to re-license it to send it upstream.
>
> kerneldoc is planned for sure, but I'd say it will be better to have
> some users first, DRM for example.
>
>> - If we make timelines first class objects I think we could move some of
>>    the fields from struct fence to struct fence_timeline. E.g. the ops
>>    struct. That also makes it clearer that some of the vfuncs really should
>>    be taking a struct fence_timeline *timeline instead of a struct fence
>>    *fence as their primary parameter.
> I'll keep that as a final goal and work RFC v2 and see how far we can
> get.
>
> 	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 16:12     ` John Harrison
@ 2016-01-19 17:52         ` Gustavo Padovan
  2016-03-23 15:07         ` Tomeu Vizoso
  1 sibling, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 17:52 UTC (permalink / raw)
  To: John Harrison
  Cc: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Rob Clark,
	Greg Hackmann, Maarten Lankhorst, Gustavo Padovan

2016-01-19 John Harrison <John.C.Harrison@Intel.com>:

> On 19/01/2016 15:23, Gustavo Padovan wrote:
> >Hi Daniel,
> >
> >2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> >
> >>On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> >>>From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>>This patch series de-stage the sync framework, and in order to accomplish that
> >>>a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>>The sync framework contained some abstractions around struct fence and those
> >>>were removed in the de-staging process among other changes:
> >>>
> >>>Userspace visible changes
> >>>-------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>>Kernel API changes
> >>>------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>>	 - sync_timeline_create()	-> fence_timeline_create()
> >>>	 - sync_timeline_get()		-> fence_timeline_get()
> >>>	 - sync_timeline_put()		-> fence_timeline_put()
> >>>	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>>	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>>Internal changes
> >>>----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>Bunch of fairly random comments all over:
> >>
> >>- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
> >>   debugfs interface between fence fds and the testsuite. Since the plan is
> >>   to have the testcases integrated into the kernel tree too we don't need
> >>   a public header.
> >>
> >>- similar for include/linux/sw_sync.h Imo that should all be moved into
> >>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
> >>   imo, and made optional with a Kconfig option. At least we should reuse
> >>   CONFIG_DEBUGFS.
> >These two items sounds reasonable to me.
> 
> I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> if it is the kind of thing you would expect us to be doing? Or is it using
> interfaces that you are planning to remove and/or make kernel only?
> 
> I'm not sure having a kernel only test is the best way to go. Having user
> land tests like IGT would be much more versatile.

I agree with you, we should allow IGT and other test tools to access
sw_sync. include/linux/sw_sync.h can be kept private, but the uapi one
needs wil be needed for testing, unless we replicate the header file
inside IGT, but not sure if it is a good idea.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 17:52         ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 17:52 UTC (permalink / raw)
  To: John Harrison
  Cc: devel, daniels, Greg Kroah-Hartman, linux-kernel, dri-devel,
	Maarten Lankhorst, Arve Hjønnevåg, Riley Andrews,
	Gustavo Padovan

2016-01-19 John Harrison <John.C.Harrison@Intel.com>:

> On 19/01/2016 15:23, Gustavo Padovan wrote:
> >Hi Daniel,
> >
> >2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> >
> >>On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> >>>From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>>This patch series de-stage the sync framework, and in order to accomplish that
> >>>a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>>The sync framework contained some abstractions around struct fence and those
> >>>were removed in the de-staging process among other changes:
> >>>
> >>>Userspace visible changes
> >>>-------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>>Kernel API changes
> >>>------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>>	 - sync_timeline_create()	-> fence_timeline_create()
> >>>	 - sync_timeline_get()		-> fence_timeline_get()
> >>>	 - sync_timeline_put()		-> fence_timeline_put()
> >>>	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>>	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>>Internal changes
> >>>----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>Bunch of fairly random comments all over:
> >>
> >>- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
> >>   debugfs interface between fence fds and the testsuite. Since the plan is
> >>   to have the testcases integrated into the kernel tree too we don't need
> >>   a public header.
> >>
> >>- similar for include/linux/sw_sync.h Imo that should all be moved into
> >>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
> >>   imo, and made optional with a Kconfig option. At least we should reuse
> >>   CONFIG_DEBUGFS.
> >These two items sounds reasonable to me.
> 
> I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> if it is the kind of thing you would expect us to be doing? Or is it using
> interfaces that you are planning to remove and/or make kernel only?
> 
> I'm not sure having a kernel only test is the best way to go. Having user
> land tests like IGT would be much more versatile.

I agree with you, we should allow IGT and other test tools to access
sw_sync. include/linux/sw_sync.h can be kept private, but the uapi one
needs wil be needed for testing, unless we replicate the header file
inside IGT, but not sure if it is a good idea.

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 17:52         ` Gustavo Padovan
@ 2016-01-19 18:04           ` Daniel Vetter
  -1 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 18:04 UTC (permalink / raw)
  To: Gustavo Padovan, John Harrison, Greg Kroah-Hartman, linux-kernel,
	devel, dri-devel, daniels, Arve Hjønnevåg,
	Riley Andrews, Rob Clark, Greg Hackmann, Maarten Lankhorst,
	Gustavo Padovan

On Tue, Jan 19, 2016 at 03:52:26PM -0200, Gustavo Padovan wrote:
> 2016-01-19 John Harrison <John.C.Harrison@Intel.com>:
> 
> > On 19/01/2016 15:23, Gustavo Padovan wrote:
> > >Hi Daniel,
> > >
> > >2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> > >
> > >>On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > >>>From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > >>>
> > >>>This patch series de-stage the sync framework, and in order to accomplish that
> > >>>a bunch of cleanups/improvements on the sync and fence were made.
> > >>>
> > >>>The sync framework contained some abstractions around struct fence and those
> > >>>were removed in the de-staging process among other changes:
> > >>>
> > >>>Userspace visible changes
> > >>>-------------------------
> > >>>
> > >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> > >>>  other change.
> > >>>
> > >>>Kernel API changes
> > >>>------------------
> > >>>
> > >>>  * struct sync_timeline is now struct fence_timeline
> > >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> > >>>  fence as parameter instead of struct sync_pt
> > >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> > >>>  the fence_timeline is destroyed
> > >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> > >>>  pointer is sent back on the .cleanup op.
> > >>>  * The sync timeline function were moved to be fence_timeline functions:
> > >>>	 - sync_timeline_create()	-> fence_timeline_create()
> > >>>	 - sync_timeline_get()		-> fence_timeline_get()
> > >>>	 - sync_timeline_put()		-> fence_timeline_put()
> > >>>	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > >>>	 - sync_timeline_signal()	-> fence_timeline_signal()
> > >>>
> > >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> > >>>
> > >>>Internal changes
> > >>>----------------
> > >>>
> > >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> > >>>  * fence default functions were created for fence_ops
> > >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> > >>Bunch of fairly random comments all over:
> > >>
> > >>- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
> > >>   debugfs interface between fence fds and the testsuite. Since the plan is
> > >>   to have the testcases integrated into the kernel tree too we don't need
> > >>   a public header.
> > >>
> > >>- similar for include/linux/sw_sync.h Imo that should all be moved into
> > >>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
> > >>   imo, and made optional with a Kconfig option. At least we should reuse
> > >>   CONFIG_DEBUGFS.
> > >These two items sounds reasonable to me.
> > 
> > I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> > Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> > if it is the kind of thing you would expect us to be doing? Or is it using
> > interfaces that you are planning to remove and/or make kernel only?
> > 
> > I'm not sure having a kernel only test is the best way to go. Having user
> > land tests like IGT would be much more versatile.
> 
> I agree with you, we should allow IGT and other test tools to access
> sw_sync. include/linux/sw_sync.h can be kept private, but the uapi one
> needs wil be needed for testing, unless we replicate the header file
> inside IGT, but not sure if it is a good idea.

We replicate all the debugfs stuff in igt that igt needs. uapi really only
should be stuff that's guaranteed to stick around, not debug interfaces we
are ok with breaking (if needed).
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 18:04           ` Daniel Vetter
  0 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 18:04 UTC (permalink / raw)
  To: Gustavo Padovan, John Harrison, Greg Kroah-Hartman, linux-kernel,
	devel, dri-devel, daniels, Arve Hjønnevåg,
	Riley Andrews, Rob Clark, Greg Hackmann, Maarten Lankhorst,
	Gustavo Padovan

On Tue, Jan 19, 2016 at 03:52:26PM -0200, Gustavo Padovan wrote:
> 2016-01-19 John Harrison <John.C.Harrison@Intel.com>:
> 
> > On 19/01/2016 15:23, Gustavo Padovan wrote:
> > >Hi Daniel,
> > >
> > >2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> > >
> > >>On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > >>>From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > >>>
> > >>>This patch series de-stage the sync framework, and in order to accomplish that
> > >>>a bunch of cleanups/improvements on the sync and fence were made.
> > >>>
> > >>>The sync framework contained some abstractions around struct fence and those
> > >>>were removed in the de-staging process among other changes:
> > >>>
> > >>>Userspace visible changes
> > >>>-------------------------
> > >>>
> > >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> > >>>  other change.
> > >>>
> > >>>Kernel API changes
> > >>>------------------
> > >>>
> > >>>  * struct sync_timeline is now struct fence_timeline
> > >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> > >>>  fence as parameter instead of struct sync_pt
> > >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> > >>>  the fence_timeline is destroyed
> > >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> > >>>  pointer is sent back on the .cleanup op.
> > >>>  * The sync timeline function were moved to be fence_timeline functions:
> > >>>	 - sync_timeline_create()	-> fence_timeline_create()
> > >>>	 - sync_timeline_get()		-> fence_timeline_get()
> > >>>	 - sync_timeline_put()		-> fence_timeline_put()
> > >>>	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > >>>	 - sync_timeline_signal()	-> fence_timeline_signal()
> > >>>
> > >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> > >>>
> > >>>Internal changes
> > >>>----------------
> > >>>
> > >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> > >>>  * fence default functions were created for fence_ops
> > >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> > >>Bunch of fairly random comments all over:
> > >>
> > >>- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
> > >>   debugfs interface between fence fds and the testsuite. Since the plan is
> > >>   to have the testcases integrated into the kernel tree too we don't need
> > >>   a public header.
> > >>
> > >>- similar for include/linux/sw_sync.h Imo that should all be moved into
> > >>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
> > >>   imo, and made optional with a Kconfig option. At least we should reuse
> > >>   CONFIG_DEBUGFS.
> > >These two items sounds reasonable to me.
> > 
> > I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> > Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> > if it is the kind of thing you would expect us to be doing? Or is it using
> > interfaces that you are planning to remove and/or make kernel only?
> > 
> > I'm not sure having a kernel only test is the best way to go. Having user
> > land tests like IGT would be much more versatile.
> 
> I agree with you, we should allow IGT and other test tools to access
> sw_sync. include/linux/sw_sync.h can be kept private, but the uapi one
> needs wil be needed for testing, unless we replicate the header file
> inside IGT, but not sure if it is a good idea.

We replicate all the debugfs stuff in igt that igt needs. uapi really only
should be stuff that's guaranteed to stick around, not debug interfaces we
are ok with breaking (if needed).
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 18:04           ` Daniel Vetter
  (?)
@ 2016-01-19 18:15           ` Gustavo Padovan
  -1 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 18:15 UTC (permalink / raw)
  To: John Harrison, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Rob Clark, Greg Hackmann, Maarten Lankhorst, Gustavo Padovan

2016-01-19 Daniel Vetter <daniel@ffwll.ch>:

> On Tue, Jan 19, 2016 at 03:52:26PM -0200, Gustavo Padovan wrote:
> > 2016-01-19 John Harrison <John.C.Harrison@Intel.com>:
> > 
> > > On 19/01/2016 15:23, Gustavo Padovan wrote:
> > > >Hi Daniel,
> > > >
> > > >2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> > > >
> > > >>On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > > >>>From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > > >>>
> > > >>>This patch series de-stage the sync framework, and in order to accomplish that
> > > >>>a bunch of cleanups/improvements on the sync and fence were made.
> > > >>>
> > > >>>The sync framework contained some abstractions around struct fence and those
> > > >>>were removed in the de-staging process among other changes:
> > > >>>
> > > >>>Userspace visible changes
> > > >>>-------------------------
> > > >>>
> > > >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> > > >>>  other change.
> > > >>>
> > > >>>Kernel API changes
> > > >>>------------------
> > > >>>
> > > >>>  * struct sync_timeline is now struct fence_timeline
> > > >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> > > >>>  fence as parameter instead of struct sync_pt
> > > >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> > > >>>  the fence_timeline is destroyed
> > > >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> > > >>>  pointer is sent back on the .cleanup op.
> > > >>>  * The sync timeline function were moved to be fence_timeline functions:
> > > >>>	 - sync_timeline_create()	-> fence_timeline_create()
> > > >>>	 - sync_timeline_get()		-> fence_timeline_get()
> > > >>>	 - sync_timeline_put()		-> fence_timeline_put()
> > > >>>	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > > >>>	 - sync_timeline_signal()	-> fence_timeline_signal()
> > > >>>
> > > >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> > > >>>
> > > >>>Internal changes
> > > >>>----------------
> > > >>>
> > > >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> > > >>>  * fence default functions were created for fence_ops
> > > >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> > > >>Bunch of fairly random comments all over:
> > > >>
> > > >>- include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
> > > >>   debugfs interface between fence fds and the testsuite. Since the plan is
> > > >>   to have the testcases integrated into the kernel tree too we don't need
> > > >>   a public header.
> > > >>
> > > >>- similar for include/linux/sw_sync.h Imo that should all be moved into
> > > >>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
> > > >>   imo, and made optional with a Kconfig option. At least we should reuse
> > > >>   CONFIG_DEBUGFS.
> > > >These two items sounds reasonable to me.
> > > 
> > > I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> > > Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> > > if it is the kind of thing you would expect us to be doing? Or is it using
> > > interfaces that you are planning to remove and/or make kernel only?
> > > 
> > > I'm not sure having a kernel only test is the best way to go. Having user
> > > land tests like IGT would be much more versatile.
> > 
> > I agree with you, we should allow IGT and other test tools to access
> > sw_sync. include/linux/sw_sync.h can be kept private, but the uapi one
> > needs wil be needed for testing, unless we replicate the header file
> > inside IGT, but not sure if it is a good idea.
> 
> We replicate all the debugfs stuff in igt that igt needs. uapi really only
> should be stuff that's guaranteed to stick around, not debug interfaces we
> are ok with breaking (if needed).

Okay, that sounds quite good for me.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 11:00   ` Daniel Vetter
@ 2016-01-19 20:10     ` Gustavo Padovan
  -1 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 20:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Rob Clark,
	Greg Hackmann, John Harrison, Gustavo Padovan

2016-01-19 Daniel Vetter <daniel@ffwll.ch>:

> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > 
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> > 
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> > 
> > Userspace visible changes
> > -------------------------
> > 
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> > 
> > Kernel API changes
> > ------------------
> > 
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> > 
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> > 
> > Internal changes
> > ----------------
> > 
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> 
> Bunch of fairly random comments all over:
> 
> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>   debugfs interface between fence fds and the testsuite. Since the plan is
>   to have the testcases integrated into the kernel tree too we don't need
>   a public header.
> 
> - similar for include/linux/sw_sync.h Imo that should all be moved into
>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>   imo, and made optional with a Kconfig option. At least we should reuse
>   CONFIG_DEBUGFS.
> 
> - fence_context and fence_timeline are really the same. timeline has some
>   super-basic support for doing sw-only fence timelines, but imo that's
>   not really worth keeping (and if so better to keep seperate in a
>   sw-fence.c or similar, like seqno-fence.c). The other main thing
>   timeline provides is support to clean up fences on a timeline. And imo
>   that cleanup should be done by the core fence support, not by the add-on
>   stuff.
> 
> Interlude about fence cleanup on driver unload:
> 
> Working drivers imo should never call timeline_destroy when there's still
> an unsignalled fence around for that timeline/context. That just means
> they're broken and failed to clean up all the pending work. So the problem
> really is only what to do with fences where the driver disappeared, and
> for that we essentially need a fence_revoke() function (which could be
> called internally from timeline_free). So here's what I think
> timeline_free should do:
> 
> for_each_fence_on_timel() {
> 	WARN_ON(!fence_is_signalled());
> 
> 	fence_revoke(fence);
> }
> 
> Implementing fence_revoke is a bit tricky since we need to make sure the
> memory contained ->ops and similar stuff doesn't disappear. Simplest
> option might be to grab a temporary reference (using
> kref_get_unless_zero), and then exchange ->ops with one that has only a
> release function. We don't need anything else as long as all fence_*
> functions the kernel might call check for signalling correctly first
> (fence_wait is broken at least).
> 
> Or we just give up (for now) and declare module unload as slightly racy.
> dma-buf is similar. An intermediate option might be to at least add a
> THIS_MODULE reference to each fence (but that's a bit expensive ...).
> 
> - back to timeline vs. context: I have no idea how to best clean up this
>   mess, but least painful option long-term is probably to switch over all
>   current users of fence_context_alloc to timelines and remove the plain
>   context interface.
> 
> - Imo the interface in include/linux/sync.h is duplicating too much of
>   fence.h. I think the only bits we need are the refcounting, creating,
>   fd-install and that's it. Plus a macro to loop over all the fences in a
>   sync_fence. With that drivers will only ever deal with a pile of
>   struct fence, making implicit fencing (using the fence list in dma-buf)
>   and explicit fencing (using the fence list in sync_fence) much more
>   similar.
> 
>   And we can easily do that since no internal users ;-)
> 
> - get_timeline_name and get_driver_name are imo too much indirection, just
>   add ->(drv_)name field to each of these.

I don't think is a good idea to change that now as there are other fence
users in the kernel using get_timeline_name and get_driver_name. What I
propose is try get rid of this when moving ops from fences to
fence_timeline.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 20:10     ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-19 20:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Rob Clark,
	Greg Hackmann, John Harrison, Gustavo Padovan

2016-01-19 Daniel Vetter <daniel@ffwll.ch>:

> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> > 
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> > 
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> > 
> > Userspace visible changes
> > -------------------------
> > 
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> > 
> > Kernel API changes
> > ------------------
> > 
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> > 
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> > 
> > Internal changes
> > ----------------
> > 
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> 
> Bunch of fairly random comments all over:
> 
> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>   debugfs interface between fence fds and the testsuite. Since the plan is
>   to have the testcases integrated into the kernel tree too we don't need
>   a public header.
> 
> - similar for include/linux/sw_sync.h Imo that should all be moved into
>   sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>   imo, and made optional with a Kconfig option. At least we should reuse
>   CONFIG_DEBUGFS.
> 
> - fence_context and fence_timeline are really the same. timeline has some
>   super-basic support for doing sw-only fence timelines, but imo that's
>   not really worth keeping (and if so better to keep seperate in a
>   sw-fence.c or similar, like seqno-fence.c). The other main thing
>   timeline provides is support to clean up fences on a timeline. And imo
>   that cleanup should be done by the core fence support, not by the add-on
>   stuff.
> 
> Interlude about fence cleanup on driver unload:
> 
> Working drivers imo should never call timeline_destroy when there's still
> an unsignalled fence around for that timeline/context. That just means
> they're broken and failed to clean up all the pending work. So the problem
> really is only what to do with fences where the driver disappeared, and
> for that we essentially need a fence_revoke() function (which could be
> called internally from timeline_free). So here's what I think
> timeline_free should do:
> 
> for_each_fence_on_timel() {
> 	WARN_ON(!fence_is_signalled());
> 
> 	fence_revoke(fence);
> }
> 
> Implementing fence_revoke is a bit tricky since we need to make sure the
> memory contained ->ops and similar stuff doesn't disappear. Simplest
> option might be to grab a temporary reference (using
> kref_get_unless_zero), and then exchange ->ops with one that has only a
> release function. We don't need anything else as long as all fence_*
> functions the kernel might call check for signalling correctly first
> (fence_wait is broken at least).
> 
> Or we just give up (for now) and declare module unload as slightly racy.
> dma-buf is similar. An intermediate option might be to at least add a
> THIS_MODULE reference to each fence (but that's a bit expensive ...).
> 
> - back to timeline vs. context: I have no idea how to best clean up this
>   mess, but least painful option long-term is probably to switch over all
>   current users of fence_context_alloc to timelines and remove the plain
>   context interface.
> 
> - Imo the interface in include/linux/sync.h is duplicating too much of
>   fence.h. I think the only bits we need are the refcounting, creating,
>   fd-install and that's it. Plus a macro to loop over all the fences in a
>   sync_fence. With that drivers will only ever deal with a pile of
>   struct fence, making implicit fencing (using the fence list in dma-buf)
>   and explicit fencing (using the fence list in sync_fence) much more
>   similar.
> 
>   And we can easily do that since no internal users ;-)
> 
> - get_timeline_name and get_driver_name are imo too much indirection, just
>   add ->(drv_)name field to each of these.

I don't think is a good idea to change that now as there are other fence
users in the kernel using get_timeline_name and get_driver_name. What I
propose is try get rid of this when moving ops from fences to
fence_timeline.

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 20:10     ` Gustavo Padovan
@ 2016-01-19 20:32       ` Daniel Vetter
  -1 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 20:32 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Rob Clark, Greg Hackmann, John Harrison, Gustavo Padovan

On Tue, Jan 19, 2016 at 06:10:40PM -0200, Gustavo Padovan wrote:
> 2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> > - get_timeline_name and get_driver_name are imo too much indirection, just
> >   add ->(drv_)name field to each of these.
> 
> I don't think is a good idea to change that now as there are other fence
> users in the kernel using get_timeline_name and get_driver_name. What I
> propose is try get rid of this when moving ops from fences to
> fence_timeline.

Makes sense. And yeah I only realized after sending that this wasn't added
by your patches, just that your patches added the (core) users for it.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-19 20:32       ` Daniel Vetter
  0 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-19 20:32 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, daniels, Arve Hjønnevåg, Riley Andrews,
	Rob Clark, Greg Hackmann, John Harrison, Gustavo Padovan

On Tue, Jan 19, 2016 at 06:10:40PM -0200, Gustavo Padovan wrote:
> 2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
> > - get_timeline_name and get_driver_name are imo too much indirection, just
> >   add ->(drv_)name field to each of these.
> 
> I don't think is a good idea to change that now as there are other fence
> users in the kernel using get_timeline_name and get_driver_name. What I
> propose is try get rid of this when moving ops from fences to
> fence_timeline.

Makes sense. And yeah I only realized after sending that this wasn't added
by your patches, just that your patches added the (core) users for it.
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 11/29] dma-buf/fence: move sync_timeline to fence_timeline
  2016-01-15 14:55   ` Gustavo Padovan
@ 2016-01-20  0:56     ` Greg Hackmann
  -1 siblings, 0 replies; 94+ messages in thread
From: Greg Hackmann @ 2016-01-20  0:56 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman
  Cc: linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, John Harrison, Maarten Lankhorst, Gustavo Padovan

On 01/15/2016 06:55 AM, Gustavo Padovan wrote:
>   /**
> + * fence_timeline_create - create a new fence_timeline
> + * @num:	[in]	amount of contexts to allocate
[...]
> + */
> +struct fence_timeline *fence_timeline_create(unsigned num,
> +					     struct fence_timeline_ops *ops,
> +					     int size, const char *name)
> +{
[...]
> +	timeline->context = fence_context_alloc(1);

fence_context_alloc(num)

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 11/29] dma-buf/fence: move sync_timeline to fence_timeline
@ 2016-01-20  0:56     ` Greg Hackmann
  0 siblings, 0 replies; 94+ messages in thread
From: Greg Hackmann @ 2016-01-20  0:56 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

On 01/15/2016 06:55 AM, Gustavo Padovan wrote:
>   /**
> + * fence_timeline_create - create a new fence_timeline
> + * @num:	[in]	amount of contexts to allocate
[...]
> + */
> +struct fence_timeline *fence_timeline_create(unsigned num,
> +					     struct fence_timeline_ops *ops,
> +					     int size, const char *name)
> +{
[...]
> +	timeline->context = fence_context_alloc(1);

fence_context_alloc(num)

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
                   ` (30 preceding siblings ...)
  2016-01-19 11:00   ` Daniel Vetter
@ 2016-01-20 10:28 ` Maarten Lankhorst
  2016-01-20 14:32     ` Gustavo Padovan
  31 siblings, 1 reply; 94+ messages in thread
From: Maarten Lankhorst @ 2016-01-20 10:28 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman
  Cc: devel, daniels, Daniel Vetter, Riley Andrews, dri-devel,
	linux-kernel, Arve Hjønnevåg, Maarten Lankhorst,
	Gustavo Padovan, John Harrison

Hey,

Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>
> This patch series de-stage the sync framework, and in order to accomplish that
> a bunch of cleanups/improvements on the sync and fence were made.
>
> The sync framework contained some abstractions around struct fence and those
> were removed in the de-staging process among other changes:
>
> Userspace visible changes
> -------------------------
>
>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>  other change.
>
> Kernel API changes
> ------------------
>
>  * struct sync_timeline is now struct fence_timeline
>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>  fence as parameter instead of struct sync_pt
>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>  the fence_timeline is destroyed
>  * added fence_add_used_data() to pass a private point to struct fence. This
>  pointer is sent back on the .cleanup op.
>  * The sync timeline function were moved to be fence_timeline functions:
> 	 - sync_timeline_create()	-> fence_timeline_create()
> 	 - sync_timeline_get()		-> fence_timeline_get()
> 	 - sync_timeline_put()		-> fence_timeline_put()
> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> 	 - sync_timeline_signal()	-> fence_timeline_signal()
>
>   * sync_pt_create() was replaced be fence_create_on_timeline()
>
> Internal changes
> ----------------
>
>  * fence_timeline_ops was removed in favor of direct use fence_ops
>  * fence default functions were created for fence_ops
>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>
> Gustavo Padovan (29):
>   staging/android: fix sync framework documentation
>   staging/android: fix checkpatch warning
>   staging/android: rename sync_fence_release
>   staging/android: rename 'android_fence' to 'sync_fence'
>   staging/android: remove not used sync_timeline ops
>   staging/android: create a 'sync' dir for debugfs information
>   staging/android: move sw_sync file to debugfs file
>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
>   staging/android: rename struct sync_fence's variables to 'sync_fence'
>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
>   dma-buf/fence: move sync_timeline to fence_timeline
>   staging/android: remove struct sync_pt
>   dma-buf/fence: create fence_default_enable_signaling()
>   dma-buf/fence: create fence_default_release()
>   dma-buf/fence: create fence_default_get_driver_name()
>   dma-buf/fence: create fence_default_timeline_name()
This is misleading. I think timeline_fence prefix would be more appropriate here.

I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
>   dma-buf/fence: store last signaled value on fence timeline
>   dma-buf/fence: create default .fence_value_str() and
>     .timeline_value_str()
>   dma-buf/fence: create fence_default_fill_driver_data()
>   dma-buf/fence: remove fence_timeline_ops
>   dma-buf/fence: add fence_create_on_timeline()
>   staging/android: remove sync_pt_create()
>   staging/android: remove sw_sync_timeline and sw_sync_pt
>   dma-buf/fence: add debug to fence timeline
>   dma-buf/fence: remove unused var from fence_timeline_signal()
>   dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
>   dma-buf/fence: add .cleanup() callback
>   staging/android: use .cleanup() to interrupt any sync_fence waiter
>   dma-buf/fence: de-stage sync framework
>

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-20 10:28 ` Maarten Lankhorst
@ 2016-01-20 14:32     ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-20 14:32 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: Greg Kroah-Hartman, devel, daniels, Daniel Vetter, Riley Andrews,
	dri-devel, linux-kernel, Arve Hjønnevåg,
	Gustavo Padovan, John Harrison

2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Hey,
> 
> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> >
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> >
> > Userspace visible changes
> > -------------------------
> >
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> >
> > Kernel API changes
> > ------------------
> >
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> >
> > Internal changes
> > ----------------
> >
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >
> > Gustavo Padovan (29):
> >   staging/android: fix sync framework documentation
> >   staging/android: fix checkpatch warning
> >   staging/android: rename sync_fence_release
> >   staging/android: rename 'android_fence' to 'sync_fence'
> >   staging/android: remove not used sync_timeline ops
> >   staging/android: create a 'sync' dir for debugfs information
> >   staging/android: move sw_sync file to debugfs file
> >   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >   dma-buf/fence: move sync_timeline to fence_timeline
> >   staging/android: remove struct sync_pt
> >   dma-buf/fence: create fence_default_enable_signaling()
> >   dma-buf/fence: create fence_default_release()
> >   dma-buf/fence: create fence_default_get_driver_name()
> >   dma-buf/fence: create fence_default_timeline_name()
> This is misleading. I think timeline_fence prefix would be more appropriate here.

Why? These fence_default_.. functions are fence_ops and not related to
fence_timeline in any way.

> 
> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?

Sure. I've been thinking on how to split this properly. I'm trying to
add a bunch of clean up/renaming first, eg the sync_fence rename to
sync_file that Daniel Vetter and I discussed. 

Next my plan would be move sync_timeline to fence_timeline, add the
fence_default.. fence_ops, clean up sw_sync and finally merge
fence_context and fence_timeline.

Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
fence.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-20 14:32     ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-20 14:32 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: devel, daniels, Greg Kroah-Hartman, linux-kernel, dri-devel,
	Riley Andrews, Arve Hjønnevåg, Daniel Vetter,
	Gustavo Padovan, John Harrison

2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Hey,
> 
> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> > From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >
> > This patch series de-stage the sync framework, and in order to accomplish that
> > a bunch of cleanups/improvements on the sync and fence were made.
> >
> > The sync framework contained some abstractions around struct fence and those
> > were removed in the de-staging process among other changes:
> >
> > Userspace visible changes
> > -------------------------
> >
> >  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >  other change.
> >
> > Kernel API changes
> > ------------------
> >
> >  * struct sync_timeline is now struct fence_timeline
> >  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >  fence as parameter instead of struct sync_pt
> >  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >  the fence_timeline is destroyed
> >  * added fence_add_used_data() to pass a private point to struct fence. This
> >  pointer is sent back on the .cleanup op.
> >  * The sync timeline function were moved to be fence_timeline functions:
> > 	 - sync_timeline_create()	-> fence_timeline_create()
> > 	 - sync_timeline_get()		-> fence_timeline_get()
> > 	 - sync_timeline_put()		-> fence_timeline_put()
> > 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> > 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >
> >   * sync_pt_create() was replaced be fence_create_on_timeline()
> >
> > Internal changes
> > ----------------
> >
> >  * fence_timeline_ops was removed in favor of direct use fence_ops
> >  * fence default functions were created for fence_ops
> >  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >
> > Gustavo Padovan (29):
> >   staging/android: fix sync framework documentation
> >   staging/android: fix checkpatch warning
> >   staging/android: rename sync_fence_release
> >   staging/android: rename 'android_fence' to 'sync_fence'
> >   staging/android: remove not used sync_timeline ops
> >   staging/android: create a 'sync' dir for debugfs information
> >   staging/android: move sw_sync file to debugfs file
> >   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >   dma-buf/fence: move sync_timeline to fence_timeline
> >   staging/android: remove struct sync_pt
> >   dma-buf/fence: create fence_default_enable_signaling()
> >   dma-buf/fence: create fence_default_release()
> >   dma-buf/fence: create fence_default_get_driver_name()
> >   dma-buf/fence: create fence_default_timeline_name()
> This is misleading. I think timeline_fence prefix would be more appropriate here.

Why? These fence_default_.. functions are fence_ops and not related to
fence_timeline in any way.

> 
> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?

Sure. I've been thinking on how to split this properly. I'm trying to
add a bunch of clean up/renaming first, eg the sync_fence rename to
sync_file that Daniel Vetter and I discussed. 

Next my plan would be move sync_timeline to fence_timeline, add the
fence_default.. fence_ops, clean up sw_sync and finally merge
fence_context and fence_timeline.

Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
fence.

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-20 14:32     ` Gustavo Padovan
@ 2016-01-20 15:02       ` Maarten Lankhorst
  -1 siblings, 0 replies; 94+ messages in thread
From: Maarten Lankhorst @ 2016-01-20 15:02 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman, devel, daniels,
	Daniel Vetter, Riley Andrews, dri-devel, linux-kernel,
	Arve Hjønnevåg, Gustavo Padovan, John Harrison

Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
>
>> Hey,
>>
>> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
>>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>
>>> This patch series de-stage the sync framework, and in order to accomplish that
>>> a bunch of cleanups/improvements on the sync and fence were made.
>>>
>>> The sync framework contained some abstractions around struct fence and those
>>> were removed in the de-staging process among other changes:
>>>
>>> Userspace visible changes
>>> -------------------------
>>>
>>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>>>  other change.
>>>
>>> Kernel API changes
>>> ------------------
>>>
>>>  * struct sync_timeline is now struct fence_timeline
>>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>>>  fence as parameter instead of struct sync_pt
>>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>>>  the fence_timeline is destroyed
>>>  * added fence_add_used_data() to pass a private point to struct fence. This
>>>  pointer is sent back on the .cleanup op.
>>>  * The sync timeline function were moved to be fence_timeline functions:
>>> 	 - sync_timeline_create()	-> fence_timeline_create()
>>> 	 - sync_timeline_get()		-> fence_timeline_get()
>>> 	 - sync_timeline_put()		-> fence_timeline_put()
>>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
>>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
>>>
>>>   * sync_pt_create() was replaced be fence_create_on_timeline()
>>>
>>> Internal changes
>>> ----------------
>>>
>>>  * fence_timeline_ops was removed in favor of direct use fence_ops
>>>  * fence default functions were created for fence_ops
>>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>>>
>>> Gustavo Padovan (29):
>>>   staging/android: fix sync framework documentation
>>>   staging/android: fix checkpatch warning
>>>   staging/android: rename sync_fence_release
>>>   staging/android: rename 'android_fence' to 'sync_fence'
>>>   staging/android: remove not used sync_timeline ops
>>>   staging/android: create a 'sync' dir for debugfs information
>>>   staging/android: move sw_sync file to debugfs file
>>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
>>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
>>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
>>>   dma-buf/fence: move sync_timeline to fence_timeline
>>>   staging/android: remove struct sync_pt
>>>   dma-buf/fence: create fence_default_enable_signaling()
>>>   dma-buf/fence: create fence_default_release()
>>>   dma-buf/fence: create fence_default_get_driver_name()
>>>   dma-buf/fence: create fence_default_timeline_name()
>> This is misleading. I think timeline_fence prefix would be more appropriate here.
> Why? These fence_default_.. functions are fence_ops and not related to
> fence_timeline in any way.
Because they're using fence_parent, which should probably be renamed to fence_to_timeline()

The name makes it sound as if they could apply to all type of fences, I don't think this is the case.
>> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> Sure. I've been thinking on how to split this properly. I'm trying to
> add a bunch of clean up/renaming first, eg the sync_fence rename to
> sync_file that Daniel Vetter and I discussed. 
>
> Next my plan would be move sync_timeline to fence_timeline, add the
> fence_default.. fence_ops, clean up sw_sync and finally merge
> fence_context and fence_timeline.
>
> Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> fence.
There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.

sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.

[1] https://patchwork.freedesktop.org/patch/67845/
[2] https://patchwork.freedesktop.org/patch/67846/

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-20 15:02       ` Maarten Lankhorst
  0 siblings, 0 replies; 94+ messages in thread
From: Maarten Lankhorst @ 2016-01-20 15:02 UTC (permalink / raw)
  To: Gustavo Padovan, Greg Kroah-Hartman, devel, daniels,
	Daniel Vetter, Riley Andrews, dri-devel, linux-kernel,
	Arve Hjønnevåg, Gustavo Padovan, John Harrison

Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
>
>> Hey,
>>
>> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
>>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>
>>> This patch series de-stage the sync framework, and in order to accomplish that
>>> a bunch of cleanups/improvements on the sync and fence were made.
>>>
>>> The sync framework contained some abstractions around struct fence and those
>>> were removed in the de-staging process among other changes:
>>>
>>> Userspace visible changes
>>> -------------------------
>>>
>>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
>>>  other change.
>>>
>>> Kernel API changes
>>> ------------------
>>>
>>>  * struct sync_timeline is now struct fence_timeline
>>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
>>>  fence as parameter instead of struct sync_pt
>>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
>>>  the fence_timeline is destroyed
>>>  * added fence_add_used_data() to pass a private point to struct fence. This
>>>  pointer is sent back on the .cleanup op.
>>>  * The sync timeline function were moved to be fence_timeline functions:
>>> 	 - sync_timeline_create()	-> fence_timeline_create()
>>> 	 - sync_timeline_get()		-> fence_timeline_get()
>>> 	 - sync_timeline_put()		-> fence_timeline_put()
>>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
>>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
>>>
>>>   * sync_pt_create() was replaced be fence_create_on_timeline()
>>>
>>> Internal changes
>>> ----------------
>>>
>>>  * fence_timeline_ops was removed in favor of direct use fence_ops
>>>  * fence default functions were created for fence_ops
>>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>>>
>>> Gustavo Padovan (29):
>>>   staging/android: fix sync framework documentation
>>>   staging/android: fix checkpatch warning
>>>   staging/android: rename sync_fence_release
>>>   staging/android: rename 'android_fence' to 'sync_fence'
>>>   staging/android: remove not used sync_timeline ops
>>>   staging/android: create a 'sync' dir for debugfs information
>>>   staging/android: move sw_sync file to debugfs file
>>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
>>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
>>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
>>>   dma-buf/fence: move sync_timeline to fence_timeline
>>>   staging/android: remove struct sync_pt
>>>   dma-buf/fence: create fence_default_enable_signaling()
>>>   dma-buf/fence: create fence_default_release()
>>>   dma-buf/fence: create fence_default_get_driver_name()
>>>   dma-buf/fence: create fence_default_timeline_name()
>> This is misleading. I think timeline_fence prefix would be more appropriate here.
> Why? These fence_default_.. functions are fence_ops and not related to
> fence_timeline in any way.
Because they're using fence_parent, which should probably be renamed to fence_to_timeline()

The name makes it sound as if they could apply to all type of fences, I don't think this is the case.
>> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> Sure. I've been thinking on how to split this properly. I'm trying to
> add a bunch of clean up/renaming first, eg the sync_fence rename to
> sync_file that Daniel Vetter and I discussed. 
>
> Next my plan would be move sync_timeline to fence_timeline, add the
> fence_default.. fence_ops, clean up sw_sync and finally merge
> fence_context and fence_timeline.
>
> Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> fence.
There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.

sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.

[1] https://patchwork.freedesktop.org/patch/67845/
[2] https://patchwork.freedesktop.org/patch/67846/
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-20 15:02       ` Maarten Lankhorst
@ 2016-01-20 16:29         ` Daniel Vetter
  -1 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-20 16:29 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: Gustavo Padovan, Greg Kroah-Hartman, devel, daniels,
	Daniel Vetter, Riley Andrews, dri-devel, linux-kernel,
	Arve Hjønnevåg, Gustavo Padovan, John Harrison

On Wed, Jan 20, 2016 at 04:02:31PM +0100, Maarten Lankhorst wrote:
> Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> > 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Hey,
> >>
> >> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> This patch series de-stage the sync framework, and in order to accomplish that
> >>> a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>> The sync framework contained some abstractions around struct fence and those
> >>> were removed in the de-staging process among other changes:
> >>>
> >>> Userspace visible changes
> >>> -------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>> Kernel API changes
> >>> ------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>> 	 - sync_timeline_create()	-> fence_timeline_create()
> >>> 	 - sync_timeline_get()		-> fence_timeline_get()
> >>> 	 - sync_timeline_put()		-> fence_timeline_put()
> >>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>> Internal changes
> >>> ----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>>
> >>> Gustavo Padovan (29):
> >>>   staging/android: fix sync framework documentation
> >>>   staging/android: fix checkpatch warning
> >>>   staging/android: rename sync_fence_release
> >>>   staging/android: rename 'android_fence' to 'sync_fence'
> >>>   staging/android: remove not used sync_timeline ops
> >>>   staging/android: create a 'sync' dir for debugfs information
> >>>   staging/android: move sw_sync file to debugfs file
> >>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >>>   dma-buf/fence: move sync_timeline to fence_timeline
> >>>   staging/android: remove struct sync_pt
> >>>   dma-buf/fence: create fence_default_enable_signaling()
> >>>   dma-buf/fence: create fence_default_release()
> >>>   dma-buf/fence: create fence_default_get_driver_name()
> >>>   dma-buf/fence: create fence_default_timeline_name()
> >> This is misleading. I think timeline_fence prefix would be more appropriate here.
> > Why? These fence_default_.. functions are fence_ops and not related to
> > fence_timeline in any way.
> Because they're using fence_parent, which should probably be renamed to fence_to_timeline()
> 
> The name makes it sound as if they could apply to all type of fences, I don't think this is the case.
> >> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> > Sure. I've been thinking on how to split this properly. I'm trying to
> > add a bunch of clean up/renaming first, eg the sync_fence rename to
> > sync_file that Daniel Vetter and I discussed. 
> >
> > Next my plan would be move sync_timeline to fence_timeline, add the
> > fence_default.. fence_ops, clean up sw_sync and finally merge
> > fence_context and fence_timeline.
> >
> > Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> > fence.
> There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.
> 
> sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.
> 
> [1] https://patchwork.freedesktop.org/patch/67845/
> [2] https://patchwork.freedesktop.org/patch/67846/

We kinda don't have open-source userspace for this stuf though ...
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-20 16:29         ` Daniel Vetter
  0 siblings, 0 replies; 94+ messages in thread
From: Daniel Vetter @ 2016-01-20 16:29 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: devel, daniels, Greg Kroah-Hartman, linux-kernel, dri-devel,
	Riley Andrews, Arve Hjønnevåg, Daniel Vetter,
	Gustavo Padovan, John Harrison

On Wed, Jan 20, 2016 at 04:02:31PM +0100, Maarten Lankhorst wrote:
> Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> > 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Hey,
> >>
> >> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> This patch series de-stage the sync framework, and in order to accomplish that
> >>> a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>> The sync framework contained some abstractions around struct fence and those
> >>> were removed in the de-staging process among other changes:
> >>>
> >>> Userspace visible changes
> >>> -------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>> Kernel API changes
> >>> ------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>> 	 - sync_timeline_create()	-> fence_timeline_create()
> >>> 	 - sync_timeline_get()		-> fence_timeline_get()
> >>> 	 - sync_timeline_put()		-> fence_timeline_put()
> >>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>> Internal changes
> >>> ----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>>
> >>> Gustavo Padovan (29):
> >>>   staging/android: fix sync framework documentation
> >>>   staging/android: fix checkpatch warning
> >>>   staging/android: rename sync_fence_release
> >>>   staging/android: rename 'android_fence' to 'sync_fence'
> >>>   staging/android: remove not used sync_timeline ops
> >>>   staging/android: create a 'sync' dir for debugfs information
> >>>   staging/android: move sw_sync file to debugfs file
> >>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >>>   dma-buf/fence: move sync_timeline to fence_timeline
> >>>   staging/android: remove struct sync_pt
> >>>   dma-buf/fence: create fence_default_enable_signaling()
> >>>   dma-buf/fence: create fence_default_release()
> >>>   dma-buf/fence: create fence_default_get_driver_name()
> >>>   dma-buf/fence: create fence_default_timeline_name()
> >> This is misleading. I think timeline_fence prefix would be more appropriate here.
> > Why? These fence_default_.. functions are fence_ops and not related to
> > fence_timeline in any way.
> Because they're using fence_parent, which should probably be renamed to fence_to_timeline()
> 
> The name makes it sound as if they could apply to all type of fences, I don't think this is the case.
> >> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> > Sure. I've been thinking on how to split this properly. I'm trying to
> > add a bunch of clean up/renaming first, eg the sync_fence rename to
> > sync_file that Daniel Vetter and I discussed. 
> >
> > Next my plan would be move sync_timeline to fence_timeline, add the
> > fence_default.. fence_ops, clean up sw_sync and finally merge
> > fence_context and fence_timeline.
> >
> > Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> > fence.
> There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.
> 
> sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.
> 
> [1] https://patchwork.freedesktop.org/patch/67845/
> [2] https://patchwork.freedesktop.org/patch/67846/

We kinda don't have open-source userspace for this stuf though ...
-Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-20 15:02       ` Maarten Lankhorst
@ 2016-01-20 18:28         ` Gustavo Padovan
  -1 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-20 18:28 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: Greg Kroah-Hartman, devel, daniels, Daniel Vetter, Riley Andrews,
	dri-devel, linux-kernel, Arve Hjønnevåg,
	Gustavo Padovan, John Harrison

2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> > 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Hey,
> >>
> >> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> This patch series de-stage the sync framework, and in order to accomplish that
> >>> a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>> The sync framework contained some abstractions around struct fence and those
> >>> were removed in the de-staging process among other changes:
> >>>
> >>> Userspace visible changes
> >>> -------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>> Kernel API changes
> >>> ------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>> 	 - sync_timeline_create()	-> fence_timeline_create()
> >>> 	 - sync_timeline_get()		-> fence_timeline_get()
> >>> 	 - sync_timeline_put()		-> fence_timeline_put()
> >>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>> Internal changes
> >>> ----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>>
> >>> Gustavo Padovan (29):
> >>>   staging/android: fix sync framework documentation
> >>>   staging/android: fix checkpatch warning
> >>>   staging/android: rename sync_fence_release
> >>>   staging/android: rename 'android_fence' to 'sync_fence'
> >>>   staging/android: remove not used sync_timeline ops
> >>>   staging/android: create a 'sync' dir for debugfs information
> >>>   staging/android: move sw_sync file to debugfs file
> >>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >>>   dma-buf/fence: move sync_timeline to fence_timeline
> >>>   staging/android: remove struct sync_pt
> >>>   dma-buf/fence: create fence_default_enable_signaling()
> >>>   dma-buf/fence: create fence_default_release()
> >>>   dma-buf/fence: create fence_default_get_driver_name()
> >>>   dma-buf/fence: create fence_default_timeline_name()
> >> This is misleading. I think timeline_fence prefix would be more appropriate here.
> > Why? These fence_default_.. functions are fence_ops and not related to
> > fence_timeline in any way.
> Because they're using fence_parent, which should probably be renamed to fence_to_timeline()
> 
> The name makes it sound as if they could apply to all type of fences, I don't think this is the case.

Fair enough. I can change the naming. Also the final idea is to move
fence_ops to be fence_timeline_ops so the naming makes sense.  

> >> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> > Sure. I've been thinking on how to split this properly. I'm trying to
> > add a bunch of clean up/renaming first, eg the sync_fence rename to
> > sync_file that Daniel Vetter and I discussed. 
> >
> > Next my plan would be move sync_timeline to fence_timeline, add the
> > fence_default.. fence_ops, clean up sw_sync and finally merge
> > fence_context and fence_timeline.
> >
> > Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> > fence.
> There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.
> 
> sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.

One of the first patches of my series is removing struct sync_pt, that
means I am also removing sync_fence_create_dma() because
sync_fence_create() now accepts struct fence as parameter.
I don't sync_pt being useful for any in-kernel driver as it is just a
wrapper on top of struct fence.

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-01-20 18:28         ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-01-20 18:28 UTC (permalink / raw)
  To: Maarten Lankhorst
  Cc: devel, daniels, Greg Kroah-Hartman, linux-kernel, dri-devel,
	Riley Andrews, Arve Hjønnevåg, Daniel Vetter,
	Gustavo Padovan, John Harrison

2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:

> Op 20-01-16 om 15:32 schreef Gustavo Padovan:
> > 2016-01-20 Maarten Lankhorst <maarten.lankhorst@linux.intel.com>:
> >
> >> Hey,
> >>
> >> Op 15-01-16 om 15:55 schreef Gustavo Padovan:
> >>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
> >>>
> >>> This patch series de-stage the sync framework, and in order to accomplish that
> >>> a bunch of cleanups/improvements on the sync and fence were made.
> >>>
> >>> The sync framework contained some abstractions around struct fence and those
> >>> were removed in the de-staging process among other changes:
> >>>
> >>> Userspace visible changes
> >>> -------------------------
> >>>
> >>>  * The sw_sync file was moved from /dev/sw_sync to <debugfs>/sync/sw_sync. No
> >>>  other change.
> >>>
> >>> Kernel API changes
> >>> ------------------
> >>>
> >>>  * struct sync_timeline is now struct fence_timeline
> >>>  * sync_timeline_ops is now fence_timeline_ops and they now carry struct
> >>>  fence as parameter instead of struct sync_pt
> >>>  * a .cleanup() fence op was added to allow sync_fence to run a cleanup when
> >>>  the fence_timeline is destroyed
> >>>  * added fence_add_used_data() to pass a private point to struct fence. This
> >>>  pointer is sent back on the .cleanup op.
> >>>  * The sync timeline function were moved to be fence_timeline functions:
> >>> 	 - sync_timeline_create()	-> fence_timeline_create()
> >>> 	 - sync_timeline_get()		-> fence_timeline_get()
> >>> 	 - sync_timeline_put()		-> fence_timeline_put()
> >>> 	 - sync_timeline_destroy()	-> fence_timeline_destroy()
> >>> 	 - sync_timeline_signal()	-> fence_timeline_signal()
> >>>
> >>>   * sync_pt_create() was replaced be fence_create_on_timeline()
> >>>
> >>> Internal changes
> >>> ----------------
> >>>
> >>>  * fence_timeline_ops was removed in favor of direct use fence_ops
> >>>  * fence default functions were created for fence_ops
> >>>  * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
> >>>
> >>> Gustavo Padovan (29):
> >>>   staging/android: fix sync framework documentation
> >>>   staging/android: fix checkpatch warning
> >>>   staging/android: rename sync_fence_release
> >>>   staging/android: rename 'android_fence' to 'sync_fence'
> >>>   staging/android: remove not used sync_timeline ops
> >>>   staging/android: create a 'sync' dir for debugfs information
> >>>   staging/android: move sw_sync file to debugfs file
> >>>   staging/android: Remove WARN_ON_ONCE when releasing sync_fence
> >>>   staging/android: rename struct sync_fence's variables to 'sync_fence'
> >>>   staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb
> >>>   dma-buf/fence: move sync_timeline to fence_timeline
> >>>   staging/android: remove struct sync_pt
> >>>   dma-buf/fence: create fence_default_enable_signaling()
> >>>   dma-buf/fence: create fence_default_release()
> >>>   dma-buf/fence: create fence_default_get_driver_name()
> >>>   dma-buf/fence: create fence_default_timeline_name()
> >> This is misleading. I think timeline_fence prefix would be more appropriate here.
> > Why? These fence_default_.. functions are fence_ops and not related to
> > fence_timeline in any way.
> Because they're using fence_parent, which should probably be renamed to fence_to_timeline()
> 
> The name makes it sound as if they could apply to all type of fences, I don't think this is the case.

Fair enough. I can change the naming. Also the final idea is to move
fence_ops to be fence_timeline_ops so the naming makes sense.  

> >> I also believe this should be done in multiple series. First series should de-stage the userspace fence framework. The next series should fix up android_fence and maybe rename it to timeline_fence since sync_fence is already used for the userspace fd, which would add more confusion?
> > Sure. I've been thinking on how to split this properly. I'm trying to
> > add a bunch of clean up/renaming first, eg the sync_fence rename to
> > sync_file that Daniel Vetter and I discussed. 
> >
> > Next my plan would be move sync_timeline to fence_timeline, add the
> > fence_default.. fence_ops, clean up sw_sync and finally merge
> > fence_context and fence_timeline.
> >
> > Looking at how sync and fence It looks easier to me to de-stage sync_timeline first than userspace
> > fence.
> There's already code to add a sync_fence_create_dma export [1][2]. So if you want to de-stage it then there will be users for it.
> 
> sync_pt otoh has no upstream in-kernel users. It was a wrapper to keep android drivers api compatible with the fence api.

One of the first patches of my series is removing struct sync_pt, that
means I am also removing sync_fence_create_dma() because
sync_fence_create() now accepts struct fence as parameter.
I don't sync_pt being useful for any in-kernel driver as it is just a
wrapper on top of struct fence.

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-01-15 23:42         ` Greg Hackmann
@ 2016-02-09 22:55           ` Tom Cherry
  -1 siblings, 0 replies; 94+ messages in thread
From: Tom Cherry @ 2016-02-09 22:55 UTC (permalink / raw)
  To: Greg Hackmann
  Cc: Gustavo Padovan, John Harrison, Gustavo Padovan,
	Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Maarten Lankhorst, Dmitry Torokhov

On Fri, Jan 15, 2016 at 3:42 PM, Greg Hackmann <ghackmann@google.com> wrote:
> On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
>>
>> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
>> calling fence_timeline_destroy() it wants to stop everything so I
>> worked on a solution that stops any waiter and allows the timeline to be
>> destroyed.
>>
>> No one is using fence_timeline_destroy() in mainline now, so it is
>> definately a behaviour we can discuss.
>>
>>         Gustavo
>>
>
> +Tom Cherry and Dmitry Torokhov recently discovered that this was broken by
> the refactoring of Android sync on top of dma-buf fences.
>
> Tom and Dmitry, did you send the proposed fix upstream?

There was a similar issue that I had originally thought to be related
to fence_timeline_destroy() but was actually related to
sync_fence_free().  Dmitry sent the patch upstream at
https://lkml.org/lkml/2015/12/14/953, but it does not look like it has
received any feedback.

We saw real panics without this patch.  I didn't see this patch or any
similar changes in the destaging commits, and I would recommend it be
looked at while destaging this driver.

Tom

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
@ 2016-02-09 22:55           ` Tom Cherry
  0 siblings, 0 replies; 94+ messages in thread
From: Tom Cherry @ 2016-02-09 22:55 UTC (permalink / raw)
  To: Greg Hackmann
  Cc: devel, daniels, linux-kernel, dri-devel, Daniel Vetter,
	Maarten Lankhorst, Arve Hjønnevåg, Dmitry Torokhov,
	Greg Kroah-Hartman, Riley Andrews, Gustavo Padovan,
	John Harrison

On Fri, Jan 15, 2016 at 3:42 PM, Greg Hackmann <ghackmann@google.com> wrote:
> On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
>>
>> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
>> calling fence_timeline_destroy() it wants to stop everything so I
>> worked on a solution that stops any waiter and allows the timeline to be
>> destroyed.
>>
>> No one is using fence_timeline_destroy() in mainline now, so it is
>> definately a behaviour we can discuss.
>>
>>         Gustavo
>>
>
> +Tom Cherry and Dmitry Torokhov recently discovered that this was broken by
> the refactoring of Android sync on top of dma-buf fences.
>
> Tom and Dmitry, did you send the proposed fix upstream?

There was a similar issue that I had originally thought to be related
to fence_timeline_destroy() but was actually related to
sync_fence_free().  Dmitry sent the patch upstream at
https://lkml.org/lkml/2015/12/14/953, but it does not look like it has
received any feedback.

We saw real panics without this patch.  I didn't see this patch or any
similar changes in the destaging commits, and I would recommend it be
looked at while destaging this driver.

Tom
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
  2016-02-09 22:55           ` Tom Cherry
@ 2016-02-25 15:26             ` Gustavo Padovan
  -1 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-02-25 15:26 UTC (permalink / raw)
  To: Tom Cherry
  Cc: Greg Hackmann, Gustavo Padovan, John Harrison,
	Greg Kroah-Hartman, linux-kernel, devel, dri-devel, daniels,
	Arve Hjønnevåg, Riley Andrews, Daniel Vetter,
	Rob Clark, Maarten Lankhorst, Dmitry Torokhov

2016-02-09 Tom Cherry <tomcherry@google.com>:

> On Fri, Jan 15, 2016 at 3:42 PM, Greg Hackmann <ghackmann@google.com> wrote:
> > On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
> >>
> >> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
> >> calling fence_timeline_destroy() it wants to stop everything so I
> >> worked on a solution that stops any waiter and allows the timeline to be
> >> destroyed.
> >>
> >> No one is using fence_timeline_destroy() in mainline now, so it is
> >> definately a behaviour we can discuss.
> >>
> >>         Gustavo
> >>
> >
> > +Tom Cherry and Dmitry Torokhov recently discovered that this was broken by
> > the refactoring of Android sync on top of dma-buf fences.
> >
> > Tom and Dmitry, did you send the proposed fix upstream?
> 
> There was a similar issue that I had originally thought to be related
> to fence_timeline_destroy() but was actually related to
> sync_fence_free().  Dmitry sent the patch upstream at
> https://lkml.org/lkml/2015/12/14/953, but it does not look like it has
> received any feedback.
> 
> We saw real panics without this patch.  I didn't see this patch or any
> similar changes in the destaging commits, and I would recommend it be
> looked at while destaging this driver.

This patch is already uptream, Greg pushed it in December. :)

	Gustavo

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase
@ 2016-02-25 15:26             ` Gustavo Padovan
  0 siblings, 0 replies; 94+ messages in thread
From: Gustavo Padovan @ 2016-02-25 15:26 UTC (permalink / raw)
  To: Tom Cherry
  Cc: devel, daniels, Greg Kroah-Hartman, linux-kernel,
	Maarten Lankhorst, Arve Hjønnevåg, Dmitry Torokhov,
	dri-devel, Daniel Vetter, Riley Andrews, Gustavo Padovan,
	John Harrison

2016-02-09 Tom Cherry <tomcherry@google.com>:

> On Fri, Jan 15, 2016 at 3:42 PM, Greg Hackmann <ghackmann@google.com> wrote:
> > On 01/15/2016 10:02 AM, Gustavo Padovan wrote:
> >>
> >> Patches 27 and 28 are attempt to fix that. I assumed that if some code is
> >> calling fence_timeline_destroy() it wants to stop everything so I
> >> worked on a solution that stops any waiter and allows the timeline to be
> >> destroyed.
> >>
> >> No one is using fence_timeline_destroy() in mainline now, so it is
> >> definately a behaviour we can discuss.
> >>
> >>         Gustavo
> >>
> >
> > +Tom Cherry and Dmitry Torokhov recently discovered that this was broken by
> > the refactoring of Android sync on top of dma-buf fences.
> >
> > Tom and Dmitry, did you send the proposed fix upstream?
> 
> There was a similar issue that I had originally thought to be related
> to fence_timeline_destroy() but was actually related to
> sync_fence_free().  Dmitry sent the patch upstream at
> https://lkml.org/lkml/2015/12/14/953, but it does not look like it has
> received any feedback.
> 
> We saw real panics without this patch.  I didn't see this patch or any
> similar changes in the destaging commits, and I would recommend it be
> looked at while destaging this driver.

This patch is already uptream, Greg pushed it in December. :)

	Gustavo
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
  2016-01-19 16:12     ` John Harrison
@ 2016-03-23 15:07         ` Tomeu Vizoso
  2016-03-23 15:07         ` Tomeu Vizoso
  1 sibling, 0 replies; 94+ messages in thread
From: Tomeu Vizoso @ 2016-03-23 15:07 UTC (permalink / raw)
  To: John Harrison
  Cc: Gustavo Padovan, Greg Kroah-Hartman, linux-kernel, devel,
	dri-devel, Daniel Stone, Arve Hjønnevåg, Riley Andrews,
	Rob Clark, Greg Hackmann, Maarten Lankhorst, Gustavo Padovan

On 19 January 2016 at 17:12, John Harrison <John.C.Harrison@intel.com> wrote:
> On 19/01/2016 15:23, Gustavo Padovan wrote:
>>
>> Hi Daniel,
>>
>> 2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
>>
>>> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
>>>>
>>>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>>
>>>> This patch series de-stage the sync framework, and in order to
>>>> accomplish that
>>>> a bunch of cleanups/improvements on the sync and fence were made.
>>>>
>>>> The sync framework contained some abstractions around struct fence and
>>>> those
>>>> were removed in the de-staging process among other changes:
>>>>
>>>> Userspace visible changes
>>>> -------------------------
>>>>
>>>>   * The sw_sync file was moved from /dev/sw_sync to
>>>> <debugfs>/sync/sw_sync. No
>>>>   other change.
>>>>
>>>> Kernel API changes
>>>> ------------------
>>>>
>>>>   * struct sync_timeline is now struct fence_timeline
>>>>   * sync_timeline_ops is now fence_timeline_ops and they now carry
>>>> struct
>>>>   fence as parameter instead of struct sync_pt
>>>>   * a .cleanup() fence op was added to allow sync_fence to run a cleanup
>>>> when
>>>>   the fence_timeline is destroyed
>>>>   * added fence_add_used_data() to pass a private point to struct fence.
>>>> This
>>>>   pointer is sent back on the .cleanup op.
>>>>   * The sync timeline function were moved to be fence_timeline
>>>> functions:
>>>>          - sync_timeline_create()       -> fence_timeline_create()
>>>>          - sync_timeline_get()          -> fence_timeline_get()
>>>>          - sync_timeline_put()          -> fence_timeline_put()
>>>>          - sync_timeline_destroy()      -> fence_timeline_destroy()
>>>>          - sync_timeline_signal()       -> fence_timeline_signal()
>>>>
>>>>    * sync_pt_create() was replaced be fence_create_on_timeline()
>>>>
>>>> Internal changes
>>>> ----------------
>>>>
>>>>   * fence_timeline_ops was removed in favor of direct use fence_ops
>>>>   * fence default functions were created for fence_ops
>>>>   * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>>>
>>> Bunch of fairly random comments all over:
>>>
>>> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>>>    debugfs interface between fence fds and the testsuite. Since the plan
>>> is
>>>    to have the testcases integrated into the kernel tree too we don't
>>> need
>>>    a public header.
>>>
>>> - similar for include/linux/sw_sync.h Imo that should all be moved into
>>>    sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>>>    imo, and made optional with a Kconfig option. At least we should reuse
>>>    CONFIG_DEBUGFS.
>>
>> These two items sounds reasonable to me.
>
>
> I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> if it is the kind of thing you would expect us to be doing? Or is it using
> interfaces that you are planning to remove and/or make kernel only?
>
> I'm not sure having a kernel only test is the best way to go. Having user
> land tests like IGT would be much more versatile.

Hi John,

I'm working on making the tests in igt useful for drivers other than
i915 and would love to have tests for the fence functionality. Have
you made any progress since you posted that RFC?

Thanks,

Tomeu

^ permalink raw reply	[flat|nested] 94+ messages in thread

* Re: [RFC 00/29] De-stage android's sync framework
@ 2016-03-23 15:07         ` Tomeu Vizoso
  0 siblings, 0 replies; 94+ messages in thread
From: Tomeu Vizoso @ 2016-03-23 15:07 UTC (permalink / raw)
  To: John Harrison
  Cc: devel, Daniel Stone, linux-kernel, dri-devel, Maarten Lankhorst,
	Arve Hjønnevåg, Greg Kroah-Hartman, Riley Andrews,
	Gustavo Padovan

On 19 January 2016 at 17:12, John Harrison <John.C.Harrison@intel.com> wrote:
> On 19/01/2016 15:23, Gustavo Padovan wrote:
>>
>> Hi Daniel,
>>
>> 2016-01-19 Daniel Vetter <daniel@ffwll.ch>:
>>
>>> On Fri, Jan 15, 2016 at 12:55:10PM -0200, Gustavo Padovan wrote:
>>>>
>>>> From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
>>>>
>>>> This patch series de-stage the sync framework, and in order to
>>>> accomplish that
>>>> a bunch of cleanups/improvements on the sync and fence were made.
>>>>
>>>> The sync framework contained some abstractions around struct fence and
>>>> those
>>>> were removed in the de-staging process among other changes:
>>>>
>>>> Userspace visible changes
>>>> -------------------------
>>>>
>>>>   * The sw_sync file was moved from /dev/sw_sync to
>>>> <debugfs>/sync/sw_sync. No
>>>>   other change.
>>>>
>>>> Kernel API changes
>>>> ------------------
>>>>
>>>>   * struct sync_timeline is now struct fence_timeline
>>>>   * sync_timeline_ops is now fence_timeline_ops and they now carry
>>>> struct
>>>>   fence as parameter instead of struct sync_pt
>>>>   * a .cleanup() fence op was added to allow sync_fence to run a cleanup
>>>> when
>>>>   the fence_timeline is destroyed
>>>>   * added fence_add_used_data() to pass a private point to struct fence.
>>>> This
>>>>   pointer is sent back on the .cleanup op.
>>>>   * The sync timeline function were moved to be fence_timeline
>>>> functions:
>>>>          - sync_timeline_create()       -> fence_timeline_create()
>>>>          - sync_timeline_get()          -> fence_timeline_get()
>>>>          - sync_timeline_put()          -> fence_timeline_put()
>>>>          - sync_timeline_destroy()      -> fence_timeline_destroy()
>>>>          - sync_timeline_signal()       -> fence_timeline_signal()
>>>>
>>>>    * sync_pt_create() was replaced be fence_create_on_timeline()
>>>>
>>>> Internal changes
>>>> ----------------
>>>>
>>>>   * fence_timeline_ops was removed in favor of direct use fence_ops
>>>>   * fence default functions were created for fence_ops
>>>>   * removed structs sync_pt, sw_sync_timeline and sw_sync_pt
>>>
>>> Bunch of fairly random comments all over:
>>>
>>> - include/uapi/linux/sw_sync.h imo should be dropped, it's just a private
>>>    debugfs interface between fence fds and the testsuite. Since the plan
>>> is
>>>    to have the testcases integrated into the kernel tree too we don't
>>> need
>>>    a public header.
>>>
>>> - similar for include/linux/sw_sync.h Imo that should all be moved into
>>>    sync_debug.c. Same for sw_sync.c, that should all land in sync_debug
>>>    imo, and made optional with a Kconfig option. At least we should reuse
>>>    CONFIG_DEBUGFS.
>>
>> These two items sounds reasonable to me.
>
>
> I have just posted our in-progress IGT for testing i915 syncs (with a CC of
> Gustavo). It uses the sw_sync mechanisms. Can you take a quick look and see
> if it is the kind of thing you would expect us to be doing? Or is it using
> interfaces that you are planning to remove and/or make kernel only?
>
> I'm not sure having a kernel only test is the best way to go. Having user
> land tests like IGT would be much more versatile.

Hi John,

I'm working on making the tests in igt useful for drivers other than
i915 and would love to have tests for the fence functionality. Have
you made any progress since you posted that RFC?

Thanks,

Tomeu
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 94+ messages in thread

end of thread, other threads:[~2016-03-23 15:07 UTC | newest]

Thread overview: 94+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-15 14:55 [RFC 00/29] De-stage android's sync framework Gustavo Padovan
2016-01-15 14:55 ` [RFC 01/29] staging/android: fix sync framework documentation Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 02/29] staging/android: fix checkpatch warning Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 03/29] staging/android: rename sync_fence_release Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 04/29] staging/android: rename 'android_fence' to 'sync_fence' Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 05/29] staging/android: remove not used sync_timeline ops Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 06/29] staging/android: create a 'sync' dir for debugfs information Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 07/29] staging/android: move sw_sync file to debugfs file Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 08/29] staging/android: Remove WARN_ON_ONCE when releasing sync_fence Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 09/29] staging/android: rename struct sync_fence's variables to 'sync_fence' Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 10/29] staging/android: rename 'sync_pt' to 'fence' in struct sync_fence_cb Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 11/29] dma-buf/fence: move sync_timeline to fence_timeline Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-20  0:56   ` Greg Hackmann
2016-01-20  0:56     ` Greg Hackmann
2016-01-15 14:55 ` [RFC 12/29] staging/android: remove struct sync_pt Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 13/29] dma-buf/fence: create fence_default_enable_signaling() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 14/29] dma-buf/fence: create fence_default_release() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 15/29] dma-buf/fence: create fence_default_get_driver_name() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 16/29] dma-buf/fence: create fence_default_timeline_name() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 17/29] dma-buf/fence: store last signaled value on fence timeline Gustavo Padovan
2016-01-15 14:55 ` [RFC 18/29] dma-buf/fence: create default .fence_value_str() and .timeline_value_str() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 19/29] dma-buf/fence: create fence_default_fill_driver_data() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 20/29] dma-buf/fence: remove fence_timeline_ops Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 21/29] dma-buf/fence: add fence_create_on_timeline() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 22/29] staging/android: remove sync_pt_create() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 23/29] staging/android: remove sw_sync_timeline and sw_sync_pt Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 24/29] dma-buf/fence: add debug to fence timeline Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 25/29] dma-buf/fence: remove unused var from fence_timeline_signal() Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 26/29] dma-buf/fence: remove pointless fence_timeline_signal at destroy phase Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 17:48   ` John Harrison
2016-01-15 18:02     ` Gustavo Padovan
2016-01-15 23:42       ` Greg Hackmann
2016-01-15 23:42         ` Greg Hackmann
2016-02-09 22:55         ` Tom Cherry
2016-02-09 22:55           ` Tom Cherry
2016-02-25 15:26           ` Gustavo Padovan
2016-02-25 15:26             ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 27/29] dma-buf/fence: add .cleanup() callback Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 28/29] staging/android: use .cleanup() to interrupt any sync_fence waiter Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 14:55 ` [RFC 29/29] dma-buf/fence: de-stage sync framework Gustavo Padovan
2016-01-15 14:55   ` Gustavo Padovan
2016-01-15 19:11 ` [RFC 00/29] De-stage android's " Joe Perches
2016-01-19 11:00 ` Daniel Vetter
2016-01-19 11:00   ` Daniel Vetter
2016-01-19 15:23   ` Gustavo Padovan
2016-01-19 15:23     ` Gustavo Padovan
2016-01-19 16:12     ` John Harrison
2016-01-19 17:52       ` Gustavo Padovan
2016-01-19 17:52         ` Gustavo Padovan
2016-01-19 18:04         ` Daniel Vetter
2016-01-19 18:04           ` Daniel Vetter
2016-01-19 18:15           ` Gustavo Padovan
2016-03-23 15:07       ` Tomeu Vizoso
2016-03-23 15:07         ` Tomeu Vizoso
2016-01-19 20:10   ` Gustavo Padovan
2016-01-19 20:10     ` Gustavo Padovan
2016-01-19 20:32     ` Daniel Vetter
2016-01-19 20:32       ` Daniel Vetter
2016-01-20 10:28 ` Maarten Lankhorst
2016-01-20 14:32   ` Gustavo Padovan
2016-01-20 14:32     ` Gustavo Padovan
2016-01-20 15:02     ` Maarten Lankhorst
2016-01-20 15:02       ` Maarten Lankhorst
2016-01-20 16:29       ` Daniel Vetter
2016-01-20 16:29         ` Daniel Vetter
2016-01-20 18:28       ` Gustavo Padovan
2016-01-20 18:28         ` Gustavo Padovan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.