diff options
author | Christian König <christian.koenig@amd.com> | 2016-06-01 09:10:04 -0400 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-06-02 03:28:04 -0400 |
commit | f71045689656e307166f6d625fa13d8b75fb0523 (patch) | |
tree | 5a5cdce5a8628c0234b8a5af2cc012033f631423 | |
parent | b3dfbdf261e076a997f812323edfdba84ba80256 (diff) |
dma-buf/fence: add signal_on_any to the fence array v2
If @signal_on_any is true the fence array signals if any fence in the array
signals, otherwise it signals when all fences in the array signal.
v2: fix signaled test and add comment suggested by Chris Wilson.
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1464786612-5010-4-git-send-email-deathsimple@vodafone.de
-rw-r--r-- | drivers/dma-buf/fence-array.c | 33 | ||||
-rw-r--r-- | include/linux/fence-array.h | 3 |
2 files changed, 27 insertions, 9 deletions
diff --git a/drivers/dma-buf/fence-array.c b/drivers/dma-buf/fence-array.c index 81412175a420..a8731c853da6 100644 --- a/drivers/dma-buf/fence-array.c +++ b/drivers/dma-buf/fence-array.c | |||
@@ -41,6 +41,7 @@ static void fence_array_cb_func(struct fence *f, struct fence_cb *cb) | |||
41 | 41 | ||
42 | if (atomic_dec_and_test(&array->num_pending)) | 42 | if (atomic_dec_and_test(&array->num_pending)) |
43 | fence_signal(&array->base); | 43 | fence_signal(&array->base); |
44 | fence_put(&array->base); | ||
44 | } | 45 | } |
45 | 46 | ||
46 | static bool fence_array_enable_signaling(struct fence *fence) | 47 | static bool fence_array_enable_signaling(struct fence *fence) |
@@ -51,10 +52,21 @@ static bool fence_array_enable_signaling(struct fence *fence) | |||
51 | 52 | ||
52 | for (i = 0; i < array->num_fences; ++i) { | 53 | for (i = 0; i < array->num_fences; ++i) { |
53 | cb[i].array = array; | 54 | cb[i].array = array; |
55 | /* | ||
56 | * As we may report that the fence is signaled before all | ||
57 | * callbacks are complete, we need to take an additional | ||
58 | * reference count on the array so that we do not free it too | ||
59 | * early. The core fence handling will only hold the reference | ||
60 | * until we signal the array as complete (but that is now | ||
61 | * insufficient). | ||
62 | */ | ||
63 | fence_get(&array->base); | ||
54 | if (fence_add_callback(array->fences[i], &cb[i].cb, | 64 | if (fence_add_callback(array->fences[i], &cb[i].cb, |
55 | fence_array_cb_func)) | 65 | fence_array_cb_func)) { |
66 | fence_put(&array->base); | ||
56 | if (atomic_dec_and_test(&array->num_pending)) | 67 | if (atomic_dec_and_test(&array->num_pending)) |
57 | return false; | 68 | return false; |
69 | } | ||
58 | } | 70 | } |
59 | 71 | ||
60 | return true; | 72 | return true; |
@@ -64,7 +76,7 @@ static bool fence_array_signaled(struct fence *fence) | |||
64 | { | 76 | { |
65 | struct fence_array *array = to_fence_array(fence); | 77 | struct fence_array *array = to_fence_array(fence); |
66 | 78 | ||
67 | return atomic_read(&array->num_pending) == 0; | 79 | return atomic_read(&array->num_pending) <= 0; |
68 | } | 80 | } |
69 | 81 | ||
70 | static void fence_array_release(struct fence *fence) | 82 | static void fence_array_release(struct fence *fence) |
@@ -90,10 +102,11 @@ const struct fence_ops fence_array_ops = { | |||
90 | 102 | ||
91 | /** | 103 | /** |
92 | * fence_array_create - Create a custom fence array | 104 | * fence_array_create - Create a custom fence array |
93 | * @num_fences: [in] number of fences to add in the array | 105 | * @num_fences: [in] number of fences to add in the array |
94 | * @fences: [in] array containing the fences | 106 | * @fences: [in] array containing the fences |
95 | * @context: [in] fence context to use | 107 | * @context: [in] fence context to use |
96 | * @seqno: [in] sequence number to use | 108 | * @seqno: [in] sequence number to use |
109 | * @signal_on_any [in] signal on any fence in the array | ||
97 | * | 110 | * |
98 | * Allocate a fence_array object and initialize the base fence with fence_init(). | 111 | * Allocate a fence_array object and initialize the base fence with fence_init(). |
99 | * In case of error it returns NULL. | 112 | * In case of error it returns NULL. |
@@ -101,9 +114,13 @@ const struct fence_ops fence_array_ops = { | |||
101 | * The caller should allocte the fences array with num_fences size | 114 | * The caller should allocte the fences array with num_fences size |
102 | * and fill it with the fences it wants to add to the object. Ownership of this | 115 | * and fill it with the fences it wants to add to the object. Ownership of this |
103 | * array is take and fence_put() is used on each fence on release. | 116 | * array is take and fence_put() is used on each fence on release. |
117 | * | ||
118 | * If @signal_on_any is true the fence array signals if any fence in the array | ||
119 | * signals, otherwise it signals when all fences in the array signal. | ||
104 | */ | 120 | */ |
105 | struct fence_array *fence_array_create(int num_fences, struct fence **fences, | 121 | struct fence_array *fence_array_create(int num_fences, struct fence **fences, |
106 | u64 context, unsigned seqno) | 122 | u64 context, unsigned seqno, |
123 | bool signal_on_any) | ||
107 | { | 124 | { |
108 | struct fence_array *array; | 125 | struct fence_array *array; |
109 | size_t size = sizeof(*array); | 126 | size_t size = sizeof(*array); |
@@ -119,7 +136,7 @@ struct fence_array *fence_array_create(int num_fences, struct fence **fences, | |||
119 | context, seqno); | 136 | context, seqno); |
120 | 137 | ||
121 | array->num_fences = num_fences; | 138 | array->num_fences = num_fences; |
122 | atomic_set(&array->num_pending, num_fences); | 139 | atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences); |
123 | array->fences = fences; | 140 | array->fences = fences; |
124 | 141 | ||
125 | return array; | 142 | return array; |
diff --git a/include/linux/fence-array.h b/include/linux/fence-array.h index 593ab983129e..86baaa45567c 100644 --- a/include/linux/fence-array.h +++ b/include/linux/fence-array.h | |||
@@ -67,6 +67,7 @@ static inline struct fence_array *to_fence_array(struct fence *fence) | |||
67 | } | 67 | } |
68 | 68 | ||
69 | struct fence_array *fence_array_create(int num_fences, struct fence **fences, | 69 | struct fence_array *fence_array_create(int num_fences, struct fence **fences, |
70 | u64 context, unsigned seqno); | 70 | u64 context, unsigned seqno, |
71 | bool signal_on_any); | ||
71 | 72 | ||
72 | #endif /* __LINUX_FENCE_ARRAY_H */ | 73 | #endif /* __LINUX_FENCE_ARRAY_H */ |