Mesa (master): panfrost: Move BO cache related fields to a sub-struct

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 8 10:43:53 UTC 2019


Module: Mesa
Branch: master
Commit: 25059cc41ff17ae2b04e44fef2c1d4863bc104c2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=25059cc41ff17ae2b04e44fef2c1d4863bc104c2

Author: Boris Brezillon <boris.brezillon at collabora.com>
Date:   Thu Nov  7 08:42:09 2019 +0100

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 at collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>

---

 src/gallium/drivers/panfrost/pan_bo.c     | 18 +++++++++---------
 src/gallium/drivers/panfrost/pan_screen.c |  8 ++++----
 src/gallium/drivers/panfrost/pan_screen.h | 13 ++++++++-----
 3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_bo.c b/src/gallium/drivers/panfrost/pan_bo.c
index aa60620ccdf..1fe7e225b8a 100644
--- a/src/gallium/drivers/panfrost/pan_bo.c
+++ b/src/gallium/drivers/panfrost/pan_bo.c
@@ -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
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c
index 8d54f8c0aa1..9e98cf3375c 100644
--- a/src/gallium/drivers/panfrost/pan_screen.c
+++ b/src/gallium/drivers/panfrost/pan_screen.c
@@ -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();
diff --git a/src/gallium/drivers/panfrost/pan_screen.h b/src/gallium/drivers/panfrost/pan_screen.h
index 2e613fbe60f..dde745fb0ed 100644
--- a/src/gallium/drivers/panfrost/pan_screen.h
+++ b/src/gallium/drivers/panfrost/pan_screen.h
@@ -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 *




More information about the mesa-commit mailing list