diff options
author | Grazvydas Ignotas <[email protected]> | 2017-03-16 01:09:31 +0200 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-03-24 11:20:09 +1100 |
commit | 5136c09e700bea2e1becbc32b073cfbbefdec1ec (patch) | |
tree | 142a6e0398f14058a285db481102f37a95f95ba3 /src/util | |
parent | feb716239e1a318eb844fd3bcaca1ffd6903067c (diff) |
util/disk_cache: hash pointer size and gpu name into cache keys
This allows to get rid of the arch and gpu name directories.
v2: (Timothy Arceri) don't use an opaque data type to store
pointer size and gpu name.
v3: (Timothy Arceri) use blob to store driver keys just make sure
to store null terminator for strings, and make sure blob is
defined by disk_cache and not it's users.
v4: (Timothy Arceri) fix typo, and make ptr_size a uint8_t.
Signed-off-by: Grazvydas Ignotas <[email protected]>
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/disk_cache.c | 41 | ||||
-rw-r--r-- | src/util/disk_cache.h | 17 |
2 files changed, 15 insertions, 43 deletions
diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c index a7f18fcc1f2..5f68fee8d53 100644 --- a/src/util/disk_cache.c +++ b/src/util/disk_cache.c @@ -162,29 +162,6 @@ concatenate_and_mkdir(void *ctx, const char *path, const char *name) return NULL; } -static char * -create_mesa_cache_dir(void *mem_ctx, const char *path, const char *gpu_name) -{ - char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa"); - 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; - - return new_path; -} - struct disk_cache * disk_cache_create(const char *gpu_name, const char *timestamp) { @@ -221,7 +198,7 @@ disk_cache_create(const char *gpu_name, const char *timestamp) if (mkdir_if_needed(path) == -1) goto fail; - path = create_mesa_cache_dir(local, path, gpu_name); + path = concatenate_and_mkdir(local, path, "mesa"); if (path == NULL) goto fail; } @@ -233,7 +210,7 @@ disk_cache_create(const char *gpu_name, const char *timestamp) if (mkdir_if_needed(xdg_cache_home) == -1) goto fail; - path = create_mesa_cache_dir(local, xdg_cache_home, gpu_name); + path = concatenate_and_mkdir(local, xdg_cache_home, "mesa"); if (path == NULL) goto fail; } @@ -269,7 +246,7 @@ disk_cache_create(const char *gpu_name, const char *timestamp) if (path == NULL) goto fail; - path = create_mesa_cache_dir(local, path, gpu_name); + path = concatenate_and_mkdir(local, path, "mesa"); if (path == NULL) goto fail; } @@ -372,7 +349,16 @@ disk_cache_create(const char *gpu_name, const char *timestamp) /* Create driver id keys */ size_t ts_size = strlen(timestamp) + 1; + size_t gpu_name_size = strlen(gpu_name) + 1; cache->driver_keys_blob_size = ts_size; + cache->driver_keys_blob_size += gpu_name_size; + + /* We sometimes store entire structs that contains a pointers in the cache, + * use pointer size as a key to avoid hard to debug issues. + */ + uint8_t ptr_size = sizeof(void *); + size_t ptr_size_size = sizeof(ptr_size); + cache->driver_keys_blob_size += ptr_size_size; cache->driver_keys_blob = ralloc_size(cache, cache->driver_keys_blob_size); @@ -380,6 +366,9 @@ disk_cache_create(const char *gpu_name, const char *timestamp) goto fail; memcpy(cache->driver_keys_blob, timestamp, ts_size); + memcpy(cache->driver_keys_blob + ts_size, gpu_name, gpu_name_size); + memcpy(cache->driver_keys_blob + ts_size + gpu_name_size, &ptr_size, + ptr_size_size); /* Seed our rand function */ s_rand_xorshift128plus(cache->seed_xorshift128plus, true); diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index 965fea1d94f..2bb1cf537d0 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) { |