[Mesa-dev] [PATCH 7/7] util/disk_cache: hash pointer size into cache keys

Grazvydas Ignotas notasas at gmail.com
Sun Mar 12 18:32:08 UTC 2017


This allows to get rid of the arch directory. It also hashes
sizeof(long) just in case disk_cache ever ends being up used on Windows.

Signed-off-by: Grazvydas Ignotas <notasas at gmail.com>
---
 src/compiler/glsl/tests/cache_test.c | 13 ++-----------
 src/util/disk_cache.c                | 15 ++++++---------
 src/util/disk_cache.h                | 17 -----------------
 3 files changed, 8 insertions(+), 37 deletions(-)

diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
index 32556c2..02c5c1c 100644
--- a/src/compiler/glsl/tests/cache_test.c
+++ b/src/compiler/glsl/tests/cache_test.c
@@ -180,16 +180,11 @@ test_disk_cache_create(void)
    expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
                "a non-existing parent directory");
 
-   /* Create string with expected directory hierarchy */
-   char expected_dir_h[255];
-   sprintf(expected_dir_h, "%s%s%s", CACHE_TEST_TMP "/xdg-cache-home/mesa/",
-           get_arch_bitness_str(), "/test");
-
    mkdir(CACHE_TEST_TMP, 0755);
    cache = disk_cache_create("test", "make_check");
    expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
 
-   check_directories_created(expected_dir_h);
+   check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/mesa/test");
 
    disk_cache_destroy(cache);
 
@@ -202,15 +197,11 @@ test_disk_cache_create(void)
    expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
                "a non-existing parent directory");
 
-   sprintf(expected_dir_h, "%s%s%s", CACHE_TEST_TMP
-           "/mesa-glsl-cache-dir/mesa/", get_arch_bitness_str(),
-           "/test");
-
    mkdir(CACHE_TEST_TMP, 0755);
    cache = disk_cache_create("test", "make_check");
    expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
 
-   check_directories_created(expected_dir_h);
+   check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/mesa/test");
 
    disk_cache_destroy(cache);
 }
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
index 3055179..d1ec700 100644
--- a/src/util/disk_cache.c
+++ b/src/util/disk_cache.c
@@ -144,15 +144,6 @@ create_mesa_cache_dir(void *mem_ctx, const char *path, const char *gpu_name)
    if (new_path == NULL)
       return NULL;
 
-   /* Create a parent architecture directory so that we don't remove cache
-    * files for other architectures. In theory we could share the cache
-    * between architectures but we have no way of knowing if they were created
-    * by a compatible Mesa version.
-    */
-   new_path = concatenate_and_mkdir(mem_ctx, new_path, get_arch_bitness_str());
-   if (new_path == NULL)
-      return NULL;
-
    new_path = concatenate_and_mkdir(mem_ctx, new_path, gpu_name);
    if (new_path == NULL)
       return NULL;
@@ -258,6 +249,12 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
 
    _mesa_sha1_update(cache->key_hash_base, timestamp, strlen(timestamp));
 
+   /* hash relevant type lengths, the value chosen should also produce
+    * different hash on different endian hosts
+    */
+   uint32_t type_sizes = (sizeof(long) << 8) | sizeof(void *);
+   _mesa_sha1_update(cache->key_hash_base, &type_sizes, sizeof(type_sizes));
+
    cache->path = ralloc_strdup(cache, path);
    if (cache->path == NULL)
       goto fail;
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index e3663a6..8de49dd 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -43,23 +43,6 @@ typedef uint8_t cache_key[CACHE_KEY_SIZE];
 
 struct disk_cache;
 
-static inline const char *
-get_arch_bitness_str(void)
-{
-    if (sizeof(void *) == 4)
-#ifdef __ILP32__
-        return "ilp-32";
-#else
-        return "32";
-#endif
-    if (sizeof(void *) == 8)
-        return "64";
-
-    /* paranoia check which will be dropped by the optimiser */
-    assert(!"unknown_arch");
-    return "unknown_arch";
-}
-
 static inline bool
 disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
 {
-- 
2.7.4



More information about the mesa-dev mailing list