panfrost: Move BO cache related fields to a sub-struct
authorBoris Brezillon <boris.brezillon@collabora.com>
Thu, 7 Nov 2019 07:42:09 +0000 (08:42 +0100)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 8 Nov 2019 10:26:47 +0000 (11:26 +0100)
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>
src/gallium/drivers/panfrost/pan_bo.c
src/gallium/drivers/panfrost/pan_screen.c
src/gallium/drivers/panfrost/pan_screen.h

index aa60620ccdf1bb0c2f9d4235853573f9883ff9b1..1fe7e225b8a74890d92c96ddd1d2cf11f6264e5d 100644 (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
index 8d54f8c0aa1a432806b1264a8b40056d24a68660..9e98cf3375c9b569ba670fa7f918a566b7bdbb18 100644 (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();
index 2e613fbe60fbdb7c63a6b567510704473b3aceeb..dde745fb0ed2f7b4c58f01d19b1c47b4733632b2 100644 (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 *