dma-buf: keep only not signaled fence in reservation_object_add_shared_replace v2
PATCH 1/2 dma-buf: keep only not signaled fence in reservation_object_add_shared_replace v2
From: Christian König <[email protected]>
The amdgpu issue to also need signaled fences in the reservation objects should be fixed by now.
Optimize the list by keeping only the not signaled yet fences around.
v2: temporary put the signaled fences at the end of the new container
Signed-off-by Christian König <[email protected]>
--- drivers/dma-buf/reservation.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-)
drivers/dma-buf/reservation.c +26 -10
@@ -145,8 +145,8 @@ reservation_object_add_shared_replace(struct reservation_object *obj,struct reservation_object_list *fobj, struct dma_fence *fence) { - unsigned i; struct dma_fence *old_fence = NULL; +unsigned i, j, k;dma_fence_get (fence);
@@ -162,9 +162,7 @@ reservation_object_add_shared_replace(struct reservation_object *obj,* references from the old struct are carried over to * the new. */ - fobj->shared_count = old->shared_count; - -for (i =0 ; i < old->shared_count; ++i) { +for (i =0 , j =0 , k = fobj->shared_max; i < old->shared_count; ++i) {struct dma_fence *check; check = rcu_dereference_protected(old->shared[i],
@@ -172,10 +170,18 @@ reservation_object_add_shared_replace(struct reservation_object *obj,if (!old_fence && check->context == fence->context) { old_fence = check; -RCU_INIT_POINTER (fobj->shared[i], fence); - }else -RCU_INIT_POINTER (fobj->shared[i], check); +RCU_INIT_POINTER (fobj->shared[j++], fence); + }else if (!dma_fence_is_signaled (check)) { +RCU_INIT_POINTER (fobj->shared[j++], check); + }else { +/* +* Temporary save the signaled fences at the end of the +* new container +*/ +RCU_INIT_POINTER (fobj->shared[--k], check); + } } + fobj->shared_count = j;if (!old_fence) {RCU_INIT_POINTER (fobj->shared[fobj->shared_count], fence); fobj->shared_count++;
@@ -192,10 +198,20 @@ reservation_object_add_shared_replace(struct reservation_object *obj,write_seqcount_end (&obj->seq);preempt_enable (); -if (old) -kfree_rcu (old, rcu); -dma_fence_put (old_fence); + +if (!old) +return ; + +/* Drop the references to the signaled fences */ +for (i = k; i < fobj->shared_max; ++i) { +struct dma_fence *f; + + f =rcu_dereference_protected (fobj->shared[i], +reservation_object_held (obj)); +dma_fence_put (f); + } +kfree_rcu (old, rcu); }/**
Signature · 6 lines
2.11.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/2 dma-buf: try to replace a signaled fence in reservation_object_add_shared_inplace
In reply to a message not in the archiveFrom: Christian König <[email protected]>
The amdgpu issue to also need signaled fences in the reservation objects should be fixed by now.
Optimize the handling by replacing a signaled fence when adding a new shared one.
Signed-off-by Christian König <[email protected]>
--- drivers/dma-buf/reservation.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/dma-buf/reservation.c +15 -3
@@ -104,7 +104,8 @@ reservation_object_add_shared_inplace(struct reservation_object *obj,struct reservation_object_list *fobj, struct dma_fence *fence) { - u32 i; + struct dma_fence *signaled = NULL; +u32 i, signaled_idx;dma_fence_get (fence);
@@ -126,17 +127,28 @@ reservation_object_add_shared_inplace(struct reservation_object *obj,dma_fence_put (old_fence);return ; } + +if (!signaled &&dma_fence_is_signaled (old_fence)) { + signaled = old_fence; + signaled_idx = i; + } }/* * memory barrier is added by write_seqcount_begin, * fobj->shared_count is protected by this lock too */ -RCU_INIT_POINTER (fobj->shared[fobj->shared_count], fence); - fobj->shared_count++; +if (signaled) { +RCU_INIT_POINTER (fobj->shared[signaled_idx], fence); + }else { +RCU_INIT_POINTER (fobj->shared[fobj->shared_count], fence); + fobj->shared_count++; + }write_seqcount_end (&obj->seq);preempt_enable (); + +dma_fence_put (signaled); } static void
Signature · 6 lines
2.11.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx