From: "Christian König" <ckoenig.leichtzumerken@gmail.com>
To: dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk,
daniel.vetter@ffwll.ch, sumit.semwal@linaro.org,
linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: [PATCH 4/9] dma-buf: add dma_fence_array_recycle v2
Date: Mon, 26 Aug 2019 16:57:26 +0200 [thread overview]
Message-ID: <20190826145731.1725-5-christian.koenig@amd.com> (raw)
In-Reply-To: <20190826145731.1725-1-christian.koenig@amd.com>
Try to recycle an dma_fence_array object by dropping the last
reference to it without freeing it.
v2: fix the WARN_ON_ONCE recycle test after rebase
Signed-off-by: Christian König <christian.koenig@amd.com>
---
drivers/dma-buf/dma-fence-array.c | 28 ++++++++++++++++++++++++++++
include/linux/dma-fence-array.h | 1 +
2 files changed, 29 insertions(+)
diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
index 4664607f0abc..ea7713b40514 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -198,6 +198,34 @@ void dma_fence_array_init(struct dma_fence_array *array, u64 context,
}
EXPORT_SYMBOL(dma_fence_array_init);
+/**
+ * dma_fence_array_reuse - dummy for dma_fence_array_recycle
+ */
+static void dma_fence_array_reuse(struct kref *kref)
+{
+ struct dma_fence_array *array = container_of(kref, typeof(*array),
+ base.refcount);
+
+ if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &array->base.flags))
+ WARN_ON_ONCE(!list_empty(&array->base.cb_list));
+}
+
+/**
+ * dma_fence_array_try_reuse - try to reuse a dma_fence_array object
+ * @array: array which we should try to reuse
+ *
+ * Try to drop the last reference to an dma_fence_array and so allow it to be
+ * reused.
+ *
+ * Returns true if this was the last reference then caller can reuse the array.
+ * In this case the array is reset into a state where it can be used with
+ * dma_fence_array_init again.
+ */
+bool dma_fence_array_recycle(struct dma_fence_array *array)
+{
+ return kref_put(&array->base.refcount, dma_fence_array_reuse);
+}
+
/**
* dma_fence_array_free - free a dma_fence_array object
* @array: the object to free
diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h
index be85c06b524d..35d1d1e7c93b 100644
--- a/include/linux/dma-fence-array.h
+++ b/include/linux/dma-fence-array.h
@@ -93,6 +93,7 @@ struct dma_fence_array *dma_fence_array_alloc(int num_fences,
struct dma_fence **fences);
void dma_fence_array_init(struct dma_fence_array *array, u64 context,
unsigned int seqno, bool signal_on_any);
+bool dma_fence_array_recycle(struct dma_fence_array *array);
void dma_fence_array_free(struct dma_fence_array *array);
/**
--
2.17.1
next prev parent reply other threads:[~2019-08-26 14:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 14:57 Use dma_fence_array for implementing shared dma_resv fences Christian König
2019-08-26 14:57 ` [PATCH 1/9] dma-buf: fix dma_fence_array_signaled Christian König
2019-08-27 11:44 ` Chris Wilson
2019-08-26 14:57 ` [PATCH 2/9] dma-buf: make to_dma_fence_array NULL safe Christian König
2019-08-30 16:07 ` Ruhl, Michael J
2019-08-26 14:57 ` [PATCH 3/9] dma-buf: add dma_fence_array_alloc/free Christian König
2019-08-26 14:57 ` Christian König [this message]
2019-08-26 14:57 ` [PATCH 5/9] dma-buf: add dma_fence_array_for_each Christian König
2019-08-26 14:57 ` [PATCH 6/9] dma-buf/resv: add dma_resv_prune_fences v2 Christian König
2019-08-26 14:57 ` [PATCH 7/9] dma-buf/resv: add new fences container implementation Christian König
2019-08-26 14:57 ` [PATCH 8/9] dma-buf/resv: use new dma_fence_array based implementation Christian König
2019-08-26 14:57 ` [PATCH 9/9] dma-buf/resv: drop the sequence count Christian König
2019-08-27 16:37 ` Use dma_fence_array for implementing shared dma_resv fences Daniel Vetter
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=20190826145731.1725-5-christian.koenig@amd.com \
--to=ckoenig.leichtzumerken@gmail.com \
--cc=chris@chris-wilson.co.uk \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-media@vger.kernel.org \
--cc=sumit.semwal@linaro.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