dma-buf/sync_file: refactor fence storage in struct sync_file

Create sync_file->fence to abstract the type of fence we are using for
each sync_file. If only one fence is present we use a normal struct fence
but if there is more fences to be added to the sync_file a fence_array
is created.

This change cleans up sync_file a bit. We don't need to have sync_file_cb
array anymore. Instead, as we always have  one fence, only one fence
callback is registered per sync_file.

v2: Comments from Chris Wilson and Christian König
	- Not using fence_ops anymore
	- fence_is_array() was created to differentiate fence from fence_array
	- fence_array_teardown() is now exported and used under fence_is_array()
	- struct sync_file lost num_fences member

v3: Comments from Chris Wilson and Christian König
	- struct sync_file lost status member in favor of fence_is_signaled()
	- drop use of fence_array_teardown()
	- use sizeof(*fence) to allocate only an array on fence pointers

v4: Comments from Chris Wilson
	- use sizeof(*fence) to reallocate array
	- fix typo in comments
	- protect num_fences sum against overflows
	- use array->base instead of casting the to struct fence

v5: fixes checkpatch warnings

v6: fix case where all fences are signaled.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Christian König <christian.koenig@amd.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
This commit is contained in:
Gustavo Padovan
2016-08-05 10:39:35 -03:00
committed by Sumit Semwal
parent e1aaf311db
commit a02b9dc90d
3 changed files with 129 additions and 74 deletions

View File

@@ -19,12 +19,7 @@
#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/fence.h>
struct sync_file_cb {
struct fence_cb cb;
struct fence *fence;
struct sync_file *sync_file;
};
#include <linux/fence-array.h>
/**
* struct sync_file - sync file to export to the userspace
@@ -32,10 +27,9 @@ struct sync_file_cb {
* @kref: reference count on fence.
* @name: name of sync_file. Useful for debugging
* @sync_file_list: membership in global file list
* @num_fences: number of sync_pts in the fence
* @wq: wait queue for fence signaling
* @status: 0: signaled, >0:active, <0: error
* @cbs: sync_pts callback information
* @fence: fence with the fences in the sync_file
* @cb: fence callback information
*/
struct sync_file {
struct file *file;
@@ -44,12 +38,11 @@ struct sync_file {
#ifdef CONFIG_DEBUG_FS
struct list_head sync_file_list;
#endif
int num_fences;
wait_queue_head_t wq;
atomic_t status;
struct sync_file_cb cbs[];
struct fence *fence;
struct fence_cb cb;
};
struct sync_file *sync_file_create(struct fence *fence);