panfrost: Move BO cache related fields to a sub-struct

We will soon introduce an LRU list to evict BOs that have been unused
for more than 1 second. Let's first move all BO cache fields to a
sub-struct to clarify which fields are used by the BO caching logic.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
This commit is contained in:
Boris Brezillon
2019-11-07 08:42:09 +01:00
parent 5f768eda43
commit 25059cc41f
3 changed files with 21 additions and 18 deletions
+9 -9
View File
@@ -186,7 +186,7 @@ pan_bucket_index(unsigned size)
static struct list_head *
pan_bucket(struct panfrost_screen *screen, unsigned size)
{
return &screen->bo_cache[pan_bucket_index(size)];
return &screen->bo_cache.buckets[pan_bucket_index(size)];
}
/* Tries to fetch a BO of sufficient size with the appropriate flags from the
@@ -198,7 +198,7 @@ static struct panfrost_bo *
panfrost_bo_cache_fetch(struct panfrost_screen *screen,
size_t size, uint32_t flags, bool dontwait)
{
pthread_mutex_lock(&screen->bo_cache_lock);
pthread_mutex_lock(&screen->bo_cache.lock);
struct list_head *bucket = pan_bucket(screen, size);
struct panfrost_bo *bo = NULL;
@@ -229,7 +229,7 @@ panfrost_bo_cache_fetch(struct panfrost_screen *screen,
bo = entry;
break;
}
pthread_mutex_unlock(&screen->bo_cache_lock);
pthread_mutex_unlock(&screen->bo_cache.lock);
return bo;
}
@@ -245,7 +245,7 @@ panfrost_bo_cache_put(struct panfrost_bo *bo)
if (bo->flags & PAN_BO_DONT_REUSE)
return false;
pthread_mutex_lock(&screen->bo_cache_lock);
pthread_mutex_lock(&screen->bo_cache.lock);
struct list_head *bucket = pan_bucket(screen, bo->size);
struct drm_panfrost_madvise madv;
@@ -257,7 +257,7 @@ panfrost_bo_cache_put(struct panfrost_bo *bo)
/* Add us to the bucket */
list_addtail(&bo->link, bucket);
pthread_mutex_unlock(&screen->bo_cache_lock);
pthread_mutex_unlock(&screen->bo_cache.lock);
return true;
}
@@ -272,16 +272,16 @@ void
panfrost_bo_cache_evict_all(
struct panfrost_screen *screen)
{
pthread_mutex_lock(&screen->bo_cache_lock);
for (unsigned i = 0; i < ARRAY_SIZE(screen->bo_cache); ++i) {
struct list_head *bucket = &screen->bo_cache[i];
pthread_mutex_lock(&screen->bo_cache.lock);
for (unsigned i = 0; i < ARRAY_SIZE(screen->bo_cache.buckets); ++i) {
struct list_head *bucket = &screen->bo_cache.buckets[i];
list_for_each_entry_safe(struct panfrost_bo, entry, bucket, link) {
list_del(&entry->link);
panfrost_bo_free(entry);
}
}
pthread_mutex_unlock(&screen->bo_cache_lock);
pthread_mutex_unlock(&screen->bo_cache.lock);
}
void
+4 -4
View File
@@ -547,7 +547,7 @@ panfrost_destroy_screen(struct pipe_screen *pscreen)
{
struct panfrost_screen *screen = pan_screen(pscreen);
panfrost_bo_cache_evict_all(screen);
pthread_mutex_destroy(&screen->bo_cache_lock);
pthread_mutex_destroy(&screen->bo_cache.lock);
pthread_mutex_destroy(&screen->active_bos_lock);
drmFreeVersion(screen->kernel_version);
ralloc_free(screen);
@@ -754,9 +754,9 @@ panfrost_create_screen(int fd, struct renderonly *ro)
screen->active_bos = _mesa_set_create(screen, panfrost_active_bos_hash,
panfrost_active_bos_cmp);
pthread_mutex_init(&screen->bo_cache_lock, NULL);
for (unsigned i = 0; i < ARRAY_SIZE(screen->bo_cache); ++i)
list_inithead(&screen->bo_cache[i]);
pthread_mutex_init(&screen->bo_cache.lock, NULL);
for (unsigned i = 0; i < ARRAY_SIZE(screen->bo_cache.buckets); ++i)
list_inithead(&screen->bo_cache.buckets[i]);
if (pan_debug & PAN_DBG_TRACE)
pandecode_initialize();
+8 -5
View File
@@ -89,13 +89,16 @@ struct panfrost_screen {
pthread_mutex_t active_bos_lock;
struct set *active_bos;
pthread_mutex_t bo_cache_lock;
struct {
pthread_mutex_t lock;
/* The BO cache is a set of buckets with power-of-two sizes ranging
* from 2^12 (4096, the page size) to 2^(12 + MAX_BO_CACHE_BUCKETS).
* Each bucket is a linked list of free panfrost_bo objects. */
/* The BO cache is a set of buckets with power-of-two sizes
* ranging from 2^12 (4096, the page size) to
* 2^(12 + MAX_BO_CACHE_BUCKETS).
* Each bucket is a linked list of free panfrost_bo objects. */
struct list_head bo_cache[NR_BO_CACHE_BUCKETS];
struct list_head buckets[NR_BO_CACHE_BUCKETS];
} bo_cache;
};
static inline struct panfrost_screen *