util/disk_cache: Move blob_put_cb to the async queue
authorRob Clark <robdclark@chromium.org>
Sat, 1 Apr 2023 14:38:40 +0000 (07:38 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 5 Apr 2023 20:25:04 +0000 (20:25 +0000)
Move deflate and put to the queue for the blob cache case.  This moves
the overhead out of the app thread when storing new shaders.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22248>

src/util/disk_cache.c

index cd338f8..c4872e5 100644 (file)
@@ -427,6 +427,10 @@ destroy_put_job_nocopy(void *job, void *gdata, int thread_index)
 }
 
 static void
+blob_put_compressed(struct disk_cache *cache, const cache_key key,
+         const void *data, size_t size);
+
+static void
 cache_put(void *job, void *gdata, int thread_index)
 {
    assert(job);
@@ -435,7 +439,9 @@ cache_put(void *job, void *gdata, int thread_index)
    char *filename = NULL;
    struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
 
-   if (dc_job->cache->type == DISK_CACHE_SINGLE_FILE) {
+   if (dc_job->cache->blob_put_cb) {
+      blob_put_compressed(dc_job->cache, dc_job->key, dc_job->data, dc_job->size);
+   } else if (dc_job->cache->type == DISK_CACHE_SINGLE_FILE) {
       disk_cache_write_item_to_disk_foz(dc_job);
    } else if (dc_job->cache->type == DISK_CACHE_DATABASE) {
       disk_cache_db_write_item_to_disk(dc_job);
@@ -546,11 +552,6 @@ disk_cache_put(struct disk_cache *cache, const cache_key key,
                const void *data, size_t size,
                struct cache_item_metadata *cache_item_metadata)
 {
-   if (cache->blob_put_cb) {
-      blob_put_compressed(cache, key, data, size);
-      return;
-   }
-
    if (!util_queue_is_initialized(&cache->cache_queue))
       return;
 
@@ -569,12 +570,6 @@ disk_cache_put_nocopy(struct disk_cache *cache, const cache_key key,
                       void *data, size_t size,
                       struct cache_item_metadata *cache_item_metadata)
 {
-   if (cache->blob_put_cb) {
-      blob_put_compressed(cache, key, data, size);
-      free(data);
-      return;
-   }
-
    if (!util_queue_is_initialized(&cache->cache_queue)) {
       free(data);
       return;
@@ -691,6 +686,7 @@ disk_cache_set_callbacks(struct disk_cache *cache, disk_cache_put_cb put,
 {
    cache->blob_put_cb = put;
    cache->blob_get_cb = get;
+   disk_cache_init_queue(cache);
 }
 
 #endif /* ENABLE_SHADER_CACHE */