diff mbox series

dma-buf: add dma_fence_chain_for_each_unwrap helper v2

Message ID 20190731092217.51201-1-christian.koenig@amd.com (mailing list archive)
State New, archived
Headers show
Series dma-buf: add dma_fence_chain_for_each_unwrap helper v2 | expand

Commit Message

Christian König July 31, 2019, 9:22 a.m. UTC
Add another for_each helper to iterate over all the fences in a chain
with unwrapping each chain node.

v2: fix typos, simplify and rename the new helper

Signed-off-by: Christian König <christian.koenig@amd.com>
---
 drivers/dma-buf/dma-fence-chain.c | 11 ++++-------
 include/linux/dma-fence-chain.h   | 33 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 7 deletions(-)

Comments

Michel Dänzer July 31, 2019, 9:27 a.m. UTC | #1
On 2019-07-31 11:22 a.m., Christian König wrote:
> Add another for_each helper to iterate over all the fences in a chain
> with unwrapping each chain node.
> 
> v2: fix typos, simplify and rename the new helper
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  drivers/dma-buf/dma-fence-chain.c | 11 ++++-------
>  include/linux/dma-fence-chain.h   | 33 +++++++++++++++++++++++++++++++
>  2 files changed, 37 insertions(+), 7 deletions(-)

This should probably be sent to a wider audience, per the
scripts/get_maintainer.pl script.
Chris Wilson July 31, 2019, 9:34 a.m. UTC | #2
Quoting Christian König (2019-07-31 10:22:17)
> Add another for_each helper to iterate over all the fences in a chain
> with unwrapping each chain node.
> 
> v2: fix typos, simplify and rename the new helper
> 
> Signed-off-by: Christian König <christian.koenig@amd.com>
> ---
>  static bool dma_fence_chain_signaled(struct dma_fence *fence)
>  {
> -       dma_fence_chain_for_each(fence, fence) {
> -               struct dma_fence_chain *chain = to_dma_fence_chain(fence);
> -               struct dma_fence *f = chain ? chain->fence : fence;
> +       struct dma_fence *f;
>  
> +       dma_fence_chain_for_each_fence(f, fence, fence) {

for_each_fence(fence, fence, fence) :)

No bright ideas, I did look at how consistent it would be to call the
arguments chain, maybe head? But then for_each_fence(f, head, head), so
not much of improvement.

> +/**
> + * dma_fence_chain_for_each_fences - iterate over all unwrapped fences in chain
One last typo, dma_fence_chain_for_each_fence.

> + * @fence: the unwrapped fence
> + * @iter: current fence
> + * @head: starting point
> + *
> + * Iterate over all fences in the chain with unwrapping. We keep a reference to
> + * the current chain node while inside the loop which must be dropped when breaking
> + * out.
> + */
> +#define dma_fence_chain_for_each_fence(fence, iter, head)      \
> +       for (iter = dma_fence_get(head);                        \
> +            (fence = dma_fence_chain_unwrap(iter));            \
> +            iter = dma_fence_chain_walk(iter))

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Christian König July 31, 2019, 11:25 a.m. UTC | #3
Am 31.07.19 um 11:27 schrieb Michel Dänzer:
> On 2019-07-31 11:22 a.m., Christian König wrote:
>> Add another for_each helper to iterate over all the fences in a chain
>> with unwrapping each chain node.
>>
>> v2: fix typos, simplify and rename the new helper
>>
>> Signed-off-by: Christian König <christian.koenig@amd.com>
>> ---
>>   drivers/dma-buf/dma-fence-chain.c | 11 ++++-------
>>   include/linux/dma-fence-chain.h   | 33 +++++++++++++++++++++++++++++++
>>   2 files changed, 37 insertions(+), 7 deletions(-)
> This should probably be sent to a wider audience, per the
> scripts/get_maintainer.pl script.

Well alternatively we could update the MAINTAINERS file :) The 
dma-fence-chain container was added by me recently and so far is only 
used by stuff we maintain.

But yeah for the upcomming reservation object change I should probably 
send it around to more people.

Christian.
diff mbox series

Patch

diff --git a/drivers/dma-buf/dma-fence-chain.c b/drivers/dma-buf/dma-fence-chain.c
index 93c42078cb57..6e64fcb2e6ba 100644
--- a/drivers/dma-buf/dma-fence-chain.c
+++ b/drivers/dma-buf/dma-fence-chain.c
@@ -151,12 +151,10 @@  static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
 static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 {
 	struct dma_fence_chain *head = to_dma_fence_chain(fence);
+	struct dma_fence *f;
 
 	dma_fence_get(&head->base);
-	dma_fence_chain_for_each(fence, &head->base) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
-
+	dma_fence_chain_for_each_fence(f, fence, &head->base) {
 		dma_fence_get(f);
 		if (!dma_fence_add_callback(f, &head->cb, dma_fence_chain_cb)) {
 			dma_fence_put(fence);
@@ -170,10 +168,9 @@  static bool dma_fence_chain_enable_signaling(struct dma_fence *fence)
 
 static bool dma_fence_chain_signaled(struct dma_fence *fence)
 {
-	dma_fence_chain_for_each(fence, fence) {
-		struct dma_fence_chain *chain = to_dma_fence_chain(fence);
-		struct dma_fence *f = chain ? chain->fence : fence;
+	struct dma_fence *f;
 
+	dma_fence_chain_for_each_fence(f, fence, fence) {
 		if (!dma_fence_is_signaled(f)) {
 			dma_fence_put(fence);
 			return false;
diff --git a/include/linux/dma-fence-chain.h b/include/linux/dma-fence-chain.h
index 934a442db8ac..13a65d65bd31 100644
--- a/include/linux/dma-fence-chain.h
+++ b/include/linux/dma-fence-chain.h
@@ -59,6 +59,24 @@  to_dma_fence_chain(struct dma_fence *fence)
 	return container_of(fence, struct dma_fence_chain, base);
 }
 
+/**
+ * dma_fence_chain_unwrap - unwrap chain node
+ * @fence: fence which could be a chain node
+ *
+ * If the parameter is a chain node return the contained fence, otherwise
+ * return the parameter itself.
+ */
+static inline struct dma_fence *
+dma_fence_chain_unwrap(struct dma_fence *fence)
+{
+	struct dma_fence_chain *chain = to_dma_fence_chain(fence);
+
+	if (!chain)
+		return fence;
+
+	return chain->fence;
+}
+
 /**
  * dma_fence_chain_for_each - iterate over all fences in chain
  * @iter: current fence
@@ -71,6 +89,21 @@  to_dma_fence_chain(struct dma_fence *fence)
 	for (iter = dma_fence_get(head); iter; \
 	     iter = dma_fence_chain_walk(iter))
 
+/**
+ * dma_fence_chain_for_each_fences - iterate over all unwrapped fences in chain
+ * @fence: the unwrapped fence
+ * @iter: current fence
+ * @head: starting point
+ *
+ * Iterate over all fences in the chain with unwrapping. We keep a reference to
+ * the current chain node while inside the loop which must be dropped when breaking
+ * out.
+ */
+#define dma_fence_chain_for_each_fence(fence, iter, head)	\
+	for (iter = dma_fence_get(head);			\
+	     (fence = dma_fence_chain_unwrap(iter));		\
+	     iter = dma_fence_chain_walk(iter))
+
 struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
 int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
 void dma_fence_chain_init(struct dma_fence_chain *chain,