Mesa (master): virgl: Return immediately when finding a compatible resource in the cache

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jun 14 11:27:00 UTC 2019


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

Author: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Date:   Thu Jun 13 17:31:50 2019 +0300

virgl: Return immediately when finding a compatible resource in the cache

When searching for resources in the cache, we previously released all
expired resources even after having found a compatible resource.

This commit changes this behavior to return immediately when finding a
compatible resource, so that the operation finishes more quickly.  This
moves more of the burden of releasing expired resources to cache
addition, which, since it happens at resource destruction time, it's
less time critical.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
Reviewed-by: Chia-I Wu <olvaffe at gmail.com>

---

 .../winsys/virgl/common/virgl_resource_cache.c     | 39 ++++++++--------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/src/gallium/winsys/virgl/common/virgl_resource_cache.c b/src/gallium/winsys/virgl/common/virgl_resource_cache.c
index 2ad4906cc3b..8ec7b6b7920 100644
--- a/src/gallium/winsys/virgl/common/virgl_resource_cache.c
+++ b/src/gallium/winsys/virgl/common/virgl_resource_cache.c
@@ -103,28 +103,23 @@ virgl_resource_cache_remove_compatible(struct virgl_resource_cache *cache,
    bool check_expired = true;
 
    /* Iterate through the cache to find a compatible resource, while also
-    * destroying any expired resources.
+    * destroying any expired resources we come across.
     */
    list_for_each_entry_safe(struct virgl_resource_cache_entry,
                             entry, &cache->resources, head) {
-      /* If we haven't yet found a compatible resource, try this one. */
-      if (!compat_entry) {
-         const bool compatible =
-            virgl_resource_cache_entry_is_compatible(entry, size, bind, format);
-
-         if (compatible) {
-            const bool busy = cache->entry_is_busy_func(entry, cache->user_data);
-            if (!busy) {
-               compat_entry = entry;
-               continue;
-            } else {
-               /* If the resource is busy, there is no point checking further,
-                * since any resources later in the cache list will also be
-                * busy.
-                */
-               break;
-            }
-         }
+      const bool compatible =
+         virgl_resource_cache_entry_is_compatible(entry, size, bind, format);
+
+      if (compatible) {
+         if (!cache->entry_is_busy_func(entry, cache->user_data))
+            compat_entry = entry;
+
+         /* We either have found a compatible resource, in which case we are
+          * done, or the resource is busy, which means resources later in
+          * the cache list will also be busy, so there is no point in
+          * searching further.
+          */
+         break;
       }
 
       /* If we aren't using this resource, check to see if it has expired.
@@ -137,12 +132,6 @@ virgl_resource_cache_remove_compatible(struct virgl_resource_cache *cache,
          else
             check_expired = false;
       }
-
-      /* If we have found a compatible entry and there are no remaining expired
-       * resources we can stop.
-       */
-      if (compat_entry && !check_expired)
-         break;
    }
 
    if (compat_entry)




More information about the mesa-commit mailing list