freedreno/drm: Inline the fence-table

In the common case, a bo will have no more than a single fence attached.
We can inline the storage to avoid a separate allocation in this case.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10444>
This commit is contained in:
Rob Clark 2021-04-26 13:39:04 -07:00 committed by Marge Bot
parent 7dabd62464
commit 49852ace2a
2 changed files with 22 additions and 1 deletions

View file

@ -106,6 +106,9 @@ bo_new(struct fd_device *dev, uint32_t size, uint32_t flags,
bo = bo_from_handle(dev, size, handle);
simple_mtx_unlock(&table_lock);
bo->max_fences = 1;
bo->fences = &bo->_inline_fence;
VG_BO_ALLOC(bo);
return bo;
@ -332,7 +335,8 @@ bo_del(struct fd_bo *bo)
simple_mtx_assert_locked(&table_lock);
cleanup_fences(bo, false);
free(bo->fences);
if (bo->fences != &bo->_inline_fence)
free(bo->fences);
if (bo->map)
os_munmap(bo->map, bo->size);
@ -485,6 +489,17 @@ fd_bo_add_fence(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t fence)
cleanup_fences(bo, true);
/* The first time we grow past a single fence, we need some special
* handling, as we've been using the embedded _inline_fence to avoid
* a separate allocation:
*/
if (unlikely((bo->nr_fences == 1) &&
(bo->fences == &bo->_inline_fence))) {
bo->nr_fences = bo->max_fences = 0;
bo->fences = NULL;
APPEND(bo, fences, bo->_inline_fence);
}
APPEND(bo, fences, (struct fd_bo_fence){
.pipe = fd_pipe_ref_locked(pipe),
.fence = fence,

View file

@ -253,6 +253,12 @@ struct fd_bo {
time_t free_time; /* time when added to bucket-list */
DECLARE_ARRAY(struct fd_bo_fence, fences);
/* In the common case, there is no more than one fence attached.
* This provides storage for the fences table until it grows to
* be larger than a single element.
*/
struct fd_bo_fence _inline_fence;
};
void fd_bo_add_fence(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t fence);