summaryrefslogtreecommitdiffstats
path: root/drivers/dma-buf
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2017-06-29 17:12:53 -0400
committerGustavo Padovan <gustavo.padovan@collabora.com>2017-06-29 17:54:07 -0400
commitf1e8c67123cf171e2b0357e885e426328b241d7d (patch)
tree0b5b3e4c46496558bc2f20c2bf91a9f994d569a4 /drivers/dma-buf
parentd3862e44daa7a0c94d2f6193502a8c49379acfce (diff)
dma-buf/sw-sync: Use an rbtree to sort fences in the timeline
Reduce the list iteration when incrementing the timeline by storing the fences in increasing order. v2: Prevent spinlock recursion on free during create v3: Fixup rebase conflict inside comments that escaped the compiler. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Sumit Semwal <sumit.semwal@linaro.org> Cc: Sean Paul <seanpaul@chromium.org> Cc: Gustavo Padovan <gustavo@padovan.org> Reviewed-by: Sean Paul <seanpaul@chromium.org> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.com> Link: http://patchwork.freedesktop.org/patch/msgid/20170629211253.22766-1-chris@chris-wilson.co.uk
Diffstat (limited to 'drivers/dma-buf')
-rw-r--r--drivers/dma-buf/sw_sync.c49
-rw-r--r--drivers/dma-buf/sync_debug.h5
2 files changed, 48 insertions, 6 deletions
diff --git a/drivers/dma-buf/sw_sync.c b/drivers/dma-buf/sw_sync.c
index f20d18c421a3..af1bc84802e5 100644
--- a/drivers/dma-buf/sw_sync.c
+++ b/drivers/dma-buf/sw_sync.c
@@ -96,6 +96,7 @@ static struct sync_timeline *sync_timeline_create(const char *name)
96 obj->context = dma_fence_context_alloc(1); 96 obj->context = dma_fence_context_alloc(1);
97 strlcpy(obj->name, name, sizeof(obj->name)); 97 strlcpy(obj->name, name, sizeof(obj->name));
98 98
99 obj->pt_tree = RB_ROOT;
99 INIT_LIST_HEAD(&obj->pt_list); 100 INIT_LIST_HEAD(&obj->pt_list);
100 spin_lock_init(&obj->lock); 101 spin_lock_init(&obj->lock);
101 102
@@ -142,9 +143,13 @@ static void sync_timeline_signal(struct sync_timeline *obj, unsigned int inc)
142 143
143 obj->value += inc; 144 obj->value += inc;
144 145
145 list_for_each_entry_safe(pt, next, &obj->pt_list, link) 146 list_for_each_entry_safe(pt, next, &obj->pt_list, link) {
146 if (dma_fence_is_signaled_locked(&pt->base)) 147 if (!dma_fence_is_signaled_locked(&pt->base))
147 list_del_init(&pt->link); 148 break;
149
150 list_del_init(&pt->link);
151 rb_erase(&pt->node, &obj->pt_tree);
152 }
148 153
149 spin_unlock_irq(&obj->lock); 154 spin_unlock_irq(&obj->lock);
150} 155}
@@ -174,8 +179,38 @@ static struct sync_pt *sync_pt_create(struct sync_timeline *obj,
174 INIT_LIST_HEAD(&pt->link); 179 INIT_LIST_HEAD(&pt->link);
175 180
176 spin_lock_irq(&obj->lock); 181 spin_lock_irq(&obj->lock);
177 if (!dma_fence_is_signaled_locked(&pt->base)) 182 if (!dma_fence_is_signaled_locked(&pt->base)) {
178 list_add_tail(&pt->link, &obj->pt_list); 183 struct rb_node **p = &obj->pt_tree.rb_node;
184 struct rb_node *parent = NULL;
185
186 while (*p) {
187 struct sync_pt *other;
188 int cmp;
189
190 parent = *p;
191 other = rb_entry(parent, typeof(*pt), node);
192 cmp = value - other->base.seqno;
193 if (cmp > 0) {
194 p = &parent->rb_right;
195 } else if (cmp < 0) {
196 p = &parent->rb_left;
197 } else {
198 if (dma_fence_get_rcu(&other->base)) {
199 dma_fence_put(&pt->base);
200 pt = other;
201 goto unlock;
202 }
203 p = &parent->rb_left;
204 }
205 }
206 rb_link_node(&pt->node, parent, p);
207 rb_insert_color(&pt->node, &obj->pt_tree);
208
209 parent = rb_next(&pt->node);
210 list_add_tail(&pt->link,
211 parent ? &rb_entry(parent, typeof(*pt), node)->link : &obj->pt_list);
212 }
213unlock:
179 spin_unlock_irq(&obj->lock); 214 spin_unlock_irq(&obj->lock);
180 215
181 return pt; 216 return pt;
@@ -202,8 +237,10 @@ static void timeline_fence_release(struct dma_fence *fence)
202 unsigned long flags; 237 unsigned long flags;
203 238
204 spin_lock_irqsave(fence->lock, flags); 239 spin_lock_irqsave(fence->lock, flags);
205 if (!list_empty(&pt->link)) 240 if (!list_empty(&pt->link)) {
206 list_del(&pt->link); 241 list_del(&pt->link);
242 rb_erase(&pt->node, &parent->pt_tree);
243 }
207 spin_unlock_irqrestore(fence->lock, flags); 244 spin_unlock_irqrestore(fence->lock, flags);
208 } 245 }
209 246
diff --git a/drivers/dma-buf/sync_debug.h b/drivers/dma-buf/sync_debug.h
index 6a2a8e69a7d0..d615a89f774c 100644
--- a/drivers/dma-buf/sync_debug.h
+++ b/drivers/dma-buf/sync_debug.h
@@ -14,6 +14,7 @@
14#define _LINUX_SYNC_H 14#define _LINUX_SYNC_H
15 15
16#include <linux/list.h> 16#include <linux/list.h>
17#include <linux/rbtree.h>
17#include <linux/spinlock.h> 18#include <linux/spinlock.h>
18#include <linux/dma-fence.h> 19#include <linux/dma-fence.h>
19 20
@@ -25,6 +26,7 @@
25 * @kref: reference count on fence. 26 * @kref: reference count on fence.
26 * @name: name of the sync_timeline. Useful for debugging 27 * @name: name of the sync_timeline. Useful for debugging
27 * @lock: lock protecting @pt_list and @value 28 * @lock: lock protecting @pt_list and @value
29 * @pt_tree: rbtree of active (unsignaled/errored) sync_pts
28 * @pt_list: list of active (unsignaled/errored) sync_pts 30 * @pt_list: list of active (unsignaled/errored) sync_pts
29 * @sync_timeline_list: membership in global sync_timeline_list 31 * @sync_timeline_list: membership in global sync_timeline_list
30 */ 32 */
@@ -36,6 +38,7 @@ struct sync_timeline {
36 u64 context; 38 u64 context;
37 int value; 39 int value;
38 40
41 struct rb_root pt_tree;
39 struct list_head pt_list; 42 struct list_head pt_list;
40 spinlock_t lock; 43 spinlock_t lock;
41 44
@@ -51,10 +54,12 @@ static inline struct sync_timeline *dma_fence_parent(struct dma_fence *fence)
51 * struct sync_pt - sync_pt object 54 * struct sync_pt - sync_pt object
52 * @base: base fence object 55 * @base: base fence object
53 * @link: link on the sync timeline's list 56 * @link: link on the sync timeline's list
57 * @node: node in the sync timeline's tree
54 */ 58 */
55struct sync_pt { 59struct sync_pt {
56 struct dma_fence base; 60 struct dma_fence base;
57 struct list_head link; 61 struct list_head link;
62 struct rb_node node;
58}; 63};
59 64
60#ifdef CONFIG_SW_SYNC 65#ifdef CONFIG_SW_SYNC