From: "Christian König" <deathsimple@vodafone.de>
To: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org, daniel@ffwll.ch,
chris@chris-wilson.co.uk, gustavo@padovan.org
Subject: [PATCH 03/11] dma-buf/fence: add signal_on_any to the fence array v2
Date: Wed, 1 Jun 2016 15:10:04 +0200 [thread overview]
Message-ID: <1464786612-5010-4-git-send-email-deathsimple@vodafone.de> (raw)
In-Reply-To: <1464786612-5010-1-git-send-email-deathsimple@vodafone.de>
From: Christian König <christian.koenig@amd.com>
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>
---
drivers/dma-buf/fence-array.c | 33 +++++++++++++++++++++++++--------
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 8141217..a8731c8 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)
if (atomic_dec_and_test(&array->num_pending))
fence_signal(&array->base);
+ fence_put(&array->base);
}
static bool fence_array_enable_signaling(struct fence *fence)
@@ -51,10 +52,21 @@ static bool fence_array_enable_signaling(struct fence *fence)
for (i = 0; i < array->num_fences; ++i) {
cb[i].array = array;
+ /*
+ * As we may report that the fence is signaled before all
+ * callbacks are complete, we need to take an additional
+ * reference count on the array so that we do not free it too
+ * early. The core fence handling will only hold the reference
+ * until we signal the array as complete (but that is now
+ * insufficient).
+ */
+ fence_get(&array->base);
if (fence_add_callback(array->fences[i], &cb[i].cb,
- fence_array_cb_func))
+ fence_array_cb_func)) {
+ fence_put(&array->base);
if (atomic_dec_and_test(&array->num_pending))
return false;
+ }
}
return true;
@@ -64,7 +76,7 @@ static bool fence_array_signaled(struct fence *fence)
{
struct fence_array *array = to_fence_array(fence);
- return atomic_read(&array->num_pending) == 0;
+ return atomic_read(&array->num_pending) <= 0;
}
static void fence_array_release(struct fence *fence)
@@ -90,10 +102,11 @@ const struct fence_ops fence_array_ops = {
/**
* fence_array_create - Create a custom fence array
- * @num_fences: [in] number of fences to add in the array
- * @fences: [in] array containing the fences
- * @context: [in] fence context to use
- * @seqno: [in] sequence number to use
+ * @num_fences: [in] number of fences to add in the array
+ * @fences: [in] array containing the fences
+ * @context: [in] fence context to use
+ * @seqno: [in] sequence number to use
+ * @signal_on_any [in] signal on any fence in the array
*
* Allocate a fence_array object and initialize the base fence with fence_init().
* In case of error it returns NULL.
@@ -101,9 +114,13 @@ const struct fence_ops fence_array_ops = {
* The caller should allocte the fences array with num_fences size
* and fill it with the fences it wants to add to the object. Ownership of this
* array is take and fence_put() is used on each fence on release.
+ *
+ * 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.
*/
struct fence_array *fence_array_create(int num_fences, struct fence **fences,
- u64 context, unsigned seqno)
+ u64 context, unsigned seqno,
+ bool signal_on_any)
{
struct fence_array *array;
size_t size = sizeof(*array);
@@ -119,7 +136,7 @@ struct fence_array *fence_array_create(int num_fences, struct fence **fences,
context, seqno);
array->num_fences = num_fences;
- atomic_set(&array->num_pending, num_fences);
+ atomic_set(&array->num_pending, signal_on_any ? 1 : num_fences);
array->fences = fences;
return array;
diff --git a/include/linux/fence-array.h b/include/linux/fence-array.h
index 593ab98..86baaa4 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)
}
struct fence_array *fence_array_create(int num_fences, struct fence **fences,
- u64 context, unsigned seqno);
+ u64 context, unsigned seqno,
+ bool signal_on_any);
#endif /* __LINUX_FENCE_ARRAY_H */
--
2.5.0
next prev parent reply other threads:[~2016-06-01 13:10 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-01 13:10 Fence array patchset Christian König
2016-06-01 13:10 ` [PATCH 01/11] dma-buf/fence: make fence context 64 bit v2 Christian König
2016-06-01 15:23 ` Gustavo Padovan
2016-06-01 13:10 ` [PATCH 02/11] dma-buf/fence: add fence_array fences v6 Christian König
2016-06-01 14:01 ` Gustavo Padovan
2016-06-01 15:25 ` Gustavo Padovan
2016-06-01 16:24 ` Sumit Semwal
2016-06-01 22:44 ` Daniel Vetter
2016-06-02 7:20 ` Christian König
2016-06-01 13:10 ` Christian König [this message]
2016-06-01 15:25 ` [PATCH 03/11] dma-buf/fence: add signal_on_any to the fence array v2 Gustavo Padovan
2016-06-01 13:10 ` [PATCH 04/11] drm/amdgpu: document amdgpu_sync_get_fence Christian König
2016-06-01 13:10 ` [PATCH 05/11] drm/amdgpu: generalize the scheduler fence Christian König
2016-06-01 13:10 ` [PATCH 06/11] drm/amdgpu: remove amdgpu_sync_wait Christian König
2016-06-01 13:10 ` [PATCH 07/11] drm/amdgpu: add optional ring to amdgpu_sync_is_idle Christian König
2016-06-01 13:10 ` [PATCH 08/11] drm/amdgpu: prefer VMIDs idle on the current ring Christian König
2016-06-01 13:10 ` [PATCH 09/11] drm/amdgpu: reuse VMIDs assigned to a VM only if there is also a free one Christian König
2016-06-01 13:10 ` [PATCH 10/11] drm/amdgpu: use a fence array for VMID management Christian König
2016-06-01 13:10 ` [PATCH 11/11] drm/amdgpu: remove now unnecessary checks Christian König
2016-06-06 21:14 ` Alex Deucher
2016-06-01 13:42 ` Fence array patchset Alex Deucher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464786612-5010-4-git-send-email-deathsimple@vodafone.de \
--to=deathsimple@vodafone.de \
--cc=chris@chris-wilson.co.uk \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=gustavo@padovan.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).