From 429986d5aaab0f7357a731523d703364647bb8a3 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 18 Jun 2021 09:58:11 -0700 Subject: [PATCH] freedreno/drm: Consider allocation flags in bo-cache It hasn't really mattered until now, as we keep a separate cache for cmdstream (which is FD_BO_GPU_READONLY), and the only other flag so far is FD_BO_SCANOUT (which the bo cache probably messes up, but it does not matter on most hw, and on hw where it does the scanout buffer will be imported (and therefore won't end up in the bo cache). But when we add cached-coherent (or if we wanted to use GPU_READONLY more) it starts to matter. Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_bo.c | 1 + src/freedreno/drm/freedreno_bo_cache.c | 12 ++++++------ src/freedreno/drm/freedreno_priv.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c index 8ff1070..b9eab54 100644 --- a/src/freedreno/drm/freedreno_bo.c +++ b/src/freedreno/drm/freedreno_bo.c @@ -106,6 +106,7 @@ 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->alloc_flags = flags; bo->max_fences = 1; bo->fences = &bo->_inline_fence; diff --git a/src/freedreno/drm/freedreno_bo_cache.c b/src/freedreno/drm/freedreno_bo_cache.c index 618f4b1..dbc21a6 100644 --- a/src/freedreno/drm/freedreno_bo_cache.c +++ b/src/freedreno/drm/freedreno_bo_cache.c @@ -135,13 +135,13 @@ find_in_bucket(struct fd_bo_bucket *bucket, uint32_t flags) * (MRU, since likely to be in GPU cache), rather than head (LRU).. */ simple_mtx_lock(&table_lock); - if (!list_is_empty(&bucket->list)) { - bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list); - /* TODO check for compatible flags? */ - if (fd_bo_state(bo) == FD_BO_STATE_IDLE) { + list_for_each_entry (struct fd_bo, entry, &bucket->list, list) { + if (fd_bo_state(entry) != FD_BO_STATE_IDLE) + break; + if (entry->alloc_flags == flags) { + bo = entry; list_del(&bo->list); - } else { - bo = NULL; + break; } } simple_mtx_unlock(&table_lock); diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index dab9296..8e8523a 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -285,6 +285,7 @@ struct fd_bo { uint32_t name; int32_t refcnt; uint32_t reloc_flags; /* flags like FD_RELOC_DUMP to use for relocs to this BO */ + uint32_t alloc_flags; /* flags that control allocation/mapping, ie. FD_BO_x */ uint64_t iova; void *map; const struct fd_bo_funcs *funcs; -- 2.7.4