History

dma-buf: add new dma_fence_chain container v7

Lockless container implementation similar to a dma_fence_array, but with only two elements per node and automatic garbage collection. v2: properly document dma_fence_chain_for_each, add dma_fence_chain_find_seqno, drop prev reference during garbage collection if it's not a chain fence. v3: use head and iterator for dma_fence_chain_for_each v4: fix reference count in dma_fence_chain_enable_signaling v5: fix iteration when walking each chain node v6: add __rcu for member 'prev' of struct chain node v7: fix rcu warnings from kernel robot

Christian König committed 7 years ago

Commit 7bf60c51 parent 64e1f833 files · +324 −1Browse files

Showing the changes to include/linux (1 of 3 files). Show all

Unified · Split

include/linux/dma-fence-chain.h+81−0
@@ -0,0 +1,81 @@
1+/*
2+ * fence-chain: chain fences together in a timeline
3+ *
4+ * Copyright (C) 2018 Advanced Micro Devices, Inc.
5+ * Authors:
6+ * Christian König <christian.koenig@amd.com>
7+ *
8+ * This program is free software; you can redistribute it and/or modify it
9+ * under the terms of the GNU General Public License version 2 as published by
10+ * the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful, but WITHOUT
13+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15+ * more details.
16+ */
17+
18+#ifndef __LINUX_DMA_FENCE_CHAIN_H
19+#define __LINUX_DMA_FENCE_CHAIN_H
20+
21+#include <linux/dma-fence.h>
22+#include <linux/irq_work.h>
23+
24+/**
25+ * struct dma_fence_chain - fence to represent an node of a fence chain
26+ * @base: fence base class
27+ * @lock: spinlock for fence handling
28+ * @prev: previous fence of the chain
29+ * @prev_seqno: original previous seqno before garbage collection
30+ * @fence: encapsulated fence
31+ * @cb: callback structure for signaling
32+ * @work: irq work item for signaling
33+ */
34+struct dma_fence_chain {
35+ struct dma_fence base;
36+ spinlock_t lock;
37+ struct dma_fence __rcu *prev;
38+ u64 prev_seqno;
39+ struct dma_fence *fence;
40+ struct dma_fence_cb cb;
41+ struct irq_work work;
42+};
43+
44+extern const struct dma_fence_ops dma_fence_chain_ops;
45+
46+/**
47+ * to_dma_fence_chain - cast a fence to a dma_fence_chain
48+ * @fence: fence to cast to a dma_fence_array
49+ *
50+ * Returns NULL if the fence is not a dma_fence_chain,
51+ * or the dma_fence_chain otherwise.
52+ */
53+static inline struct dma_fence_chain *
54+to_dma_fence_chain(struct dma_fence *fence)
55+{
56+ if (!fence || fence->ops != &dma_fence_chain_ops)
57+ return NULL;
58+
59+ return container_of(fence, struct dma_fence_chain, base);
60+}
61+
62+/**
63+ * dma_fence_chain_for_each - iterate over all fences in chain
64+ * @iter: current fence
65+ * @head: starting point
66+ *
67+ * Iterate over all fences in the chain. We keep a reference to the current
68+ * fence while inside the loop which must be dropped when breaking out.
69+ */
70+#define dma_fence_chain_for_each(iter, head) \
71+ for (iter = dma_fence_get(head); iter; \
72+ iter = dma_fence_chain_walk(iter))
73+
74+struct dma_fence *dma_fence_chain_walk(struct dma_fence *fence);
75+int dma_fence_chain_find_seqno(struct dma_fence **pfence, uint64_t seqno);
76+void dma_fence_chain_init(struct dma_fence_chain *chain,
77+ struct dma_fence *prev,
78+ struct dma_fence *fence,
79+ uint64_t seqno);
80+
81+#endif /* __LINUX_DMA_FENCE_CHAIN_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t