[Mesa-dev] [PATCH 4/7] util/disk_cache: pass timestamps as a blob

Grazvydas Ignotas notasas at gmail.com
Wed Mar 15 23:09:30 UTC 2017


We no longer need a string, so can just pass the timestamps as a blob to
reduce amount of data that needs to be hashed into the keys. The
argument is also renamed to version_blob because the cache doesn't
really care if it's timestamps, build id or something else.

Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
---
 src/compiler/glsl/tests/cache_test.c          | 21 +++++++-------
 src/gallium/drivers/radeon/r600_pipe_common.c | 41 ++++++++++++---------------
 src/util/disk_cache.c                         |  7 +++--
 src/util/disk_cache.h                         |  6 ++--
 4 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index b604943..f923e8d 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -148,6 +148,7 @@ check_directories_created(char *cache_dir)
 }
 
 #define CACHE_TEST_TMP "./cache-test-tmp"
+static const char version_blob[] = "make_check_version";
 
 static void
 test_disk_cache_create(void)
@@ -159,7 +160,7 @@ test_disk_cache_create(void)
     * MESA_GLSL_CACHE_DISABLE set, that disk_cache_create returns NULL.
     */
    setenv("MESA_GLSL_CACHE_DISABLE", "1", 1);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");
 
    unsetenv("MESA_GLSL_CACHE_DISABLE");
@@ -170,14 +171,14 @@ test_disk_cache_create(void)
    unsetenv("MESA_GLSL_CACHE_DIR");
    unsetenv("XDG_CACHE_HOME");
 
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_non_null(cache, "disk_cache_create with no environment variables");
 
    disk_cache_destroy(cache);
 
    /* Test with XDG_CACHE_HOME set */
    setenv("XDG_CACHE_HOME", CACHE_TEST_TMP "/xdg-cache-home", 1);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
                "a non-existing parent directory");
 
@@ -187,7 +188,7 @@ test_disk_cache_create(void)
            get_arch_bitness_str(), "/test");
 
    mkdir(CACHE_TEST_TMP, 0755);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
 
    check_directories_created(expected_dir_h);
@@ -199,7 +200,7 @@ test_disk_cache_create(void)
    expect_equal(err, 0, "Removing " CACHE_TEST_TMP);
 
    setenv("MESA_GLSL_CACHE_DIR", CACHE_TEST_TMP "/mesa-glsl-cache-dir", 1);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
                "a non-existing parent directory");
 
@@ -208,7 +209,7 @@ test_disk_cache_create(void)
            "/test");
 
    mkdir(CACHE_TEST_TMP, 0755);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
    expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
 
    check_directories_created(expected_dir_h);
@@ -265,7 +266,7 @@ test_put_and_get(void)
    uint8_t one_KB_key[20], one_MB_key[20];
    int count;
 
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
 
    disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
 
@@ -307,7 +308,7 @@ test_put_and_get(void)
    disk_cache_destroy(cache);
 
    setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
 
    one_KB = calloc(1, 1024);
 
@@ -372,7 +373,7 @@ test_put_and_get(void)
    disk_cache_destroy(cache);
 
    setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
 
    disk_cache_put(cache, blob_key, blob, sizeof(blob));
    disk_cache_put(cache, string_key, string, sizeof(string));
@@ -447,7 +448,7 @@ test_put_key_and_get_key(void)
                         { 0,  1, 42, 43, 44, 45, 46, 47, 48, 49,
                          50, 55, 52, 53, 54, 55, 56, 57, 58, 59};
 
-   cache = disk_cache_create("test", "make_check");
+   cache = disk_cache_create("test", version_blob, sizeof(version_blob));
 
    /* First test that disk_cache_has_key returns false before disk_cache_put_key */
    result = disk_cache_has_key(cache, key_a);
diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
index b3b925e..9e21d38 100644
--- a/src/gallium/drivers/radeon/r600_pipe_common.c
+++ b/src/gallium/drivers/radeon/r600_pipe_common.c
@@ -790,31 +790,26 @@ static void r600_disk_cache_create(struct r600_common_screen *rscreen)
 	    (DBG_FS | DBG_VS | DBG_TCS | DBG_TES | DBG_GS | DBG_PS | DBG_CS))
 		return;
 
-	uint32_t mesa_timestamp;
-	if (disk_cache_get_function_timestamp(r600_disk_cache_create,
-					      &mesa_timestamp)) {
-		char *timestamp_str;
-		int res = -1;
-		if (rscreen->chip_class < SI) {
-			res = asprintf(&timestamp_str, "%u",mesa_timestamp);
-		}
+	struct {
+		uint32_t mesa;
+		uint32_t llvm;
+	} timestamps = {};
+	size_t size;
+	if (!disk_cache_get_function_timestamp(r600_disk_cache_create,
+					       &timestamps.mesa))
+		return;
+	size = sizeof(timestamps.mesa);
+
 #if HAVE_LLVM
-		else {
-			uint32_t llvm_timestamp;
-			if (disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo,
-							      &llvm_timestamp)) {
-				res = asprintf(&timestamp_str, "%u_%u",
-					       mesa_timestamp, llvm_timestamp);
-			}
-		}
-#endif
-		if (res != -1) {
-			rscreen->disk_shader_cache =
-				disk_cache_create(r600_get_chip_name(rscreen),
-						  timestamp_str);
-			free(timestamp_str);
-		}
+	if (rscreen->chip_class >= SI) {
+		if (!disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo,
+						       &timestamps.llvm))
+			return;
+		size = sizeof(timestamps);
 	}
+#endif
+	rscreen->disk_shader_cache = disk_cache_create(r600_get_chip_name(rscreen),
+						       &timestamps, size);
 }
 
 static struct disk_cache *r600_get_disk_shader_cache(struct pipe_screen *pscreen)
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 76c2df9..5b249d9 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -182,7 +182,8 @@ create_mesa_cache_dir(void *mem_ctx, const char *path, const char *gpu_name)
 }
 
 struct disk_cache *
-disk_cache_create(const char *gpu_name, const char *timestamp)
+disk_cache_create(const char *gpu_name, const void *version_blob,
+                  size_t version_blob_size)
 {
    void *local;
    struct disk_cache *cache = NULL;
@@ -274,11 +275,11 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
    if (cache == NULL)
       goto fail;
 
-   cache->key_blob_size = strlen(timestamp);
+   cache->key_blob_size = version_blob_size;
    cache->key_blob = ralloc_size(cache, cache->key_blob_size);
    if (cache->key_blob == NULL)
       goto fail;
-   memcpy(cache->key_blob, timestamp, cache->key_blob_size);
+   memcpy(cache->key_blob, version_blob, version_blob_size);
 
    cache->path = ralloc_strdup(cache, path);
    if (cache->path == NULL)
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index e3663a6..98019c1 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -110,7 +110,8 @@ disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
  * assistance in computing SHA-1 signatures.
  */
 struct disk_cache *
-disk_cache_create(const char *gpu_name, const char *timestamp);
+disk_cache_create(const char *gpu_name, const void *version_blob,
+                  size_t version_blob_size);
 
 /**
  * Destroy a cache object, (freeing all associated resources).
@@ -188,7 +189,8 @@ disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
 #else
 
 static inline struct disk_cache *
-disk_cache_create(const char *gpu_name, const char *timestamp)
+disk_cache_create(const char *gpu_name, const void *version_blob,
+                  size_t version_blob_size)
 {
    return NULL;
 }
-- 
2.7.4



More information about the mesa-dev mailing list