Skip to contentSkip to conversation

dma-buf: add dma_fence_chain_for_each_unwrap helper v2

PATCH In review Christian König 3 participants 4 messages Jul 31, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dma-buf: add dma_fence_chain_for_each_unwrap helper v2

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

---
 drivers/dma-buf/dma-fence-chain.c | 11 ++++-------
 include/linux/dma-fence-chain.h   | 33 +++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 7 deletions(-)
drivers/dma-buf/dma-fence-chain.c +4 -7
index 93c42078cb57..6e64fcb2e6ba 100644
@@ -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;
include/linux/dma-fence-chain.h +33 -0
index 934a442db8ac..13a65d65bd31 100644
@@ -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,
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 10 lines · Christian König

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

---
 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.

Signature · 6 lines
Earthling Michel Dänzer               |              https://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

Am 31.07.19 um 11:27 schrieb Michel Dänzer:

Quoted 6 lines · Christian König
Quoted 5 lines

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

Quoted 7 lines
Quoted 5 lines
---
  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.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by on v1 1/1
#3 lore raw
In reply to Christian König

Quoting Christian König (2019-07-31 10:22:17)

Quoted 9 lines

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

---
static bool dma_fence_chain_signaled(struct dma_fence *fence) {

drivers/dma-buf/dma-fence-chain.c static bool dma_fence_chain_enable_signaling(struct dma_fence *fence) · line 173

Quoted 6 lines
drivers/dma-buf/dma-fence-chain.c +2 -3
-       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.

Quoted 2 lines

+/**
+ * dma_fence_chain_for_each_fences - iterate over all unwrapped fences in chain

One last typo, dma_fence_chain_for_each_fence.

include/linux/dma-fence-chain.h to_dma_fence_chain(struct dma_fence *fence) · line 105

Quoted 12 lines

+ * @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.
+ */

include/linux/dma-fence-chain.h +4 -0
+#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))

-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel