From 73ab83d22879e28e0df3375d33f61132fa45ff3f Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Thu, 8 Dec 2022 12:47:51 -0800 Subject: [PATCH] freedreno/drm: Add bo list iterator macros Signed-off-by: Rob Clark Part-of: --- src/freedreno/drm/freedreno_bo.c | 6 +++--- src/freedreno/drm/freedreno_bo_cache.c | 10 +++++----- src/freedreno/drm/freedreno_drmif.h | 2 +- src/freedreno/drm/freedreno_priv.h | 8 ++++++++ src/freedreno/drm/virtio/virtio_bo.c | 8 ++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/freedreno/drm/freedreno_bo.c b/src/freedreno/drm/freedreno_bo.c index a99dd629815..f3279dd805e 100644 --- a/src/freedreno/drm/freedreno_bo.c +++ b/src/freedreno/drm/freedreno_bo.c @@ -52,13 +52,13 @@ lookup_bo(struct hash_table *tbl, uint32_t key) /* found, incr refcnt and return: */ bo = fd_bo_ref(entry->data); - if (!list_is_empty(&bo->list)) { + if (!list_is_empty(&bo->node)) { mesa_logw("bo was in cache, size=%u, alloc_flags=0x%x\n", bo->size, bo->alloc_flags); } /* don't break the bucket if this bo was found in one */ - list_delinit(&bo->list); + list_delinit(&bo->node); } return bo; } @@ -75,7 +75,7 @@ fd_bo_init_common(struct fd_bo *bo, struct fd_device *dev) bo->reloc_flags = FD_RELOC_FLAGS_INIT; p_atomic_set(&bo->refcnt, 1); - list_inithead(&bo->list); + list_inithead(&bo->node); } /* allocate a new buffer object, call w/ table_lock held */ diff --git a/src/freedreno/drm/freedreno_bo_cache.c b/src/freedreno/drm/freedreno_bo_cache.c index 9061cf23edf..3fe1fbf4354 100644 --- a/src/freedreno/drm/freedreno_bo_cache.c +++ b/src/freedreno/drm/freedreno_bo_cache.c @@ -42,7 +42,7 @@ extern simple_mtx_t table_lock; static void bo_remove_from_bucket(struct fd_bo_bucket *bucket, struct fd_bo *bo) { - list_delinit(&bo->list); + list_delinit(&bo->node); bucket->count--; } @@ -69,7 +69,7 @@ dump_cache_stats(struct fd_bo_cache *cache) struct fd_bo_bucket *bucket = &cache->cache_bucket[i]; if (bucket->count > 0) { - struct fd_bo *bo = list_first_entry(&bucket->list, struct fd_bo, list); + struct fd_bo *bo = first_bo(&bucket->list); if (fd_bo_state(bo) == FD_BO_STATE_IDLE) state = " (idle)"; } @@ -158,7 +158,7 @@ fd_bo_cache_cleanup(struct fd_bo_cache *cache, time_t time) struct fd_bo *bo; while (!list_is_empty(&bucket->list)) { - bo = list_entry(bucket->list.next, struct fd_bo, list); + bo = first_bo(&bucket->list); /* keep things in cache for at least 1 second: */ if (time && ((time - bo->free_time) <= 1)) @@ -225,7 +225,7 @@ 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); - list_for_each_entry (struct fd_bo, entry, &bucket->list, list) { + foreach_bo (entry, &bucket->list) { if (fd_bo_state(entry) != FD_BO_STATE_IDLE) { break; } @@ -301,7 +301,7 @@ fd_bo_cache_free(struct fd_bo_cache *cache, struct fd_bo *bo) bo->free_time = time.tv_sec; VG_BO_RELEASE(bo); - list_addtail(&bo->list, &bucket->list); + list_addtail(&bo->node, &bucket->list); bucket->count++; diff --git a/src/freedreno/drm/freedreno_drmif.h b/src/freedreno/drm/freedreno_drmif.h index 27af4df54f7..244b4314403 100644 --- a/src/freedreno/drm/freedreno_drmif.h +++ b/src/freedreno/drm/freedreno_drmif.h @@ -215,7 +215,7 @@ struct fd_bo { */ uint32_t idx; - struct list_head list; /* bucket-list entry */ + struct list_head node; /* bucket-list entry */ time_t free_time; /* time when added to bucket-list */ unsigned short nr_fences, max_fences; diff --git a/src/freedreno/drm/freedreno_priv.h b/src/freedreno/drm/freedreno_priv.h index 9bd9b83b740..a731561bfbd 100644 --- a/src/freedreno/drm/freedreno_priv.h +++ b/src/freedreno/drm/freedreno_priv.h @@ -200,6 +200,14 @@ struct fd_device { #define last_submit(list) \ list_last_entry(list, struct fd_submit, node) +#define foreach_bo(name, list) \ + list_for_each_entry(struct fd_bo, name, list, node) +#define foreach_bo_safe(name, list) \ + list_for_each_entry_safe(struct fd_bo, name, list, node) +#define first_bo(list) \ + list_first_entry(list, struct fd_bo, node) + + void fd_bo_cache_init(struct fd_bo_cache *cache, int coarse, const char *name); void fd_bo_cache_cleanup(struct fd_bo_cache *cache, time_t time); struct fd_bo *fd_bo_cache_alloc(struct fd_bo_cache *cache, uint32_t *size, diff --git a/src/freedreno/drm/virtio/virtio_bo.c b/src/freedreno/drm/virtio/virtio_bo.c index 8f1e5b150b3..5b1d83b7810 100644 --- a/src/freedreno/drm/virtio/virtio_bo.c +++ b/src/freedreno/drm/virtio/virtio_bo.c @@ -451,9 +451,9 @@ virtio_bo_new(struct fd_device *dev, uint32_t size, uint32_t flags) * latency hit of waiting for the host to catch up. */ simple_mtx_lock(&virtio_dev->eb_lock); - list_addtail(&bo->list, &virtio_dev->prealloc_list); - bo = list_first_entry(&virtio_dev->prealloc_list, struct fd_bo, list); - list_delinit(&bo->list); + list_addtail(&bo->node, &virtio_dev->prealloc_list); + bo = first_bo(&virtio_dev->prealloc_list); + list_delinit(&bo->node); simple_mtx_unlock(&virtio_dev->eb_lock); } @@ -468,6 +468,6 @@ void virtio_bo_setup_prealloc(struct fd_device *dev) struct fd_bo *bo = virtio_bo_new_impl(dev, SUBALLOC_SIZE, RING_FLAGS); if (!bo) break; - list_addtail(&bo->list, &virtio_dev->prealloc_list); + list_addtail(&bo->node, &virtio_dev->prealloc_list); } }