[Mesa-dev] [PATCH 1/2] util/disk_cache: add new driver_flags param to cache keys
Eduardo Lima Mitev
elima at igalia.com
Sun May 21 19:38:12 UTC 2017
Both patches look good to me. Series is:
Reviewed-by: Eduardo Lima Mitev <elima at igalia.com>
On 05/20/2017 03:36 AM, Timothy Arceri wrote:
> This will be used for things such as adding driver specific environment
> variables to the key. Allowing us to set environment vars that change
> the shader and not have the driver ignore them if it finds existing
> shaders in the cache.
> ---
> src/compiler/glsl/tests/cache_test.c | 20 ++++++++++----------
> src/gallium/drivers/nouveau/nouveau_screen.c | 2 +-
> src/gallium/drivers/radeon/r600_pipe_common.c | 2 +-
> src/util/disk_cache.c | 8 +++++++-
> src/util/disk_cache.h | 6 ++++--
> 5 files changed, 23 insertions(+), 15 deletions(-)
>
> diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c
> index bec1d24..af1b66f 100644
> --- a/src/compiler/glsl/tests/cache_test.c
> +++ b/src/compiler/glsl/tests/cache_test.c
> @@ -152,61 +152,61 @@ check_directories_created(const char *cache_dir)
> static void
> test_disk_cache_create(void)
> {
> struct disk_cache *cache;
> int err;
>
> /* Before doing anything else, ensure that with
> * 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", "make_check", 0);
> expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DISABLE set");
>
> unsetenv("MESA_GLSL_CACHE_DISABLE");
>
> /* For the first real disk_cache_create() clear these environment
> * variables to test creation of cache in home directory.
> */
> unsetenv("MESA_GLSL_CACHE_DIR");
> unsetenv("XDG_CACHE_HOME");
>
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
> 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", "make_check", 0);
> expect_null(cache, "disk_cache_create with XDG_CACHE_HOME set with"
> "a non-existing parent directory");
>
> mkdir(CACHE_TEST_TMP, 0755);
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
> expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME set");
>
> check_directories_created(CACHE_TEST_TMP "/xdg-cache-home/mesa");
>
> disk_cache_destroy(cache);
>
> /* Test with MESA_GLSL_CACHE_DIR set */
> err = rmrf_local(CACHE_TEST_TMP);
> 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", "make_check", 0);
> expect_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set with"
> "a non-existing parent directory");
>
> mkdir(CACHE_TEST_TMP, 0755);
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
> expect_non_null(cache, "disk_cache_create with MESA_GLSL_CACHE_DIR set");
>
> check_directories_created(CACHE_TEST_TMP "/mesa-glsl-cache-dir/mesa");
>
> disk_cache_destroy(cache);
> }
>
> static bool
> does_cache_contain(struct disk_cache *cache, const cache_key key)
> {
> @@ -249,21 +249,21 @@ test_put_and_get(void)
> char blob[] = "This is a blob of thirty-seven bytes";
> uint8_t blob_key[20];
> char string[] = "While this string has thirty-four";
> uint8_t string_key[20];
> char *result;
> size_t size;
> uint8_t *one_KB, *one_MB;
> uint8_t one_KB_key[20], one_MB_key[20];
> int count;
>
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
>
> disk_cache_compute_key(cache, blob, sizeof(blob), blob_key);
>
> /* Ensure that disk_cache_get returns nothing before anything is added. */
> result = disk_cache_get(cache, blob_key, &size);
> expect_null(result, "disk_cache_get with non-existent item (pointer)");
> expect_equal(size, 0, "disk_cache_get with non-existent item (size)");
>
> /* Simple test of put and get. */
> disk_cache_put(cache, blob_key, blob, sizeof(blob));
> @@ -291,21 +291,21 @@ test_put_and_get(void)
> result = disk_cache_get(cache, string_key, &size);
> expect_equal_str(result, string, "2nd disk_cache_get of existing item (pointer)");
> expect_equal(size, sizeof(string), "2nd disk_cache_get of existing item (size)");
>
> free(result);
>
> /* Set the cache size to 1KB and add a 1KB item to force an eviction. */
> disk_cache_destroy(cache);
>
> setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
>
> one_KB = calloc(1, 1024);
>
> /* Obviously the SHA-1 hash of 1024 zero bytes isn't particularly
> * interesting. But we do have want to take some special care with
> * the hash we use here. The issue is that in this artificial case,
> * (with only three files in the cache), the probability is good
> * that each of the three files will end up in their own
> * directory. Then, if the directory containing the .tmp file for
> * the new item being added for disk_cache_put() is the chosen victim
> @@ -356,21 +356,21 @@ test_put_and_get(void)
> expect_true(contains_1KB_file,
> "disk_cache_put eviction last file == MAX_SIZE (1KB)");
> expect_equal(count, 1, "disk_cache_put eviction with MAX_SIZE=1K");
>
> /* Now increase the size to 1M, add back both items, and ensure all
> * three that have been added are available via disk_cache_get.
> */
> disk_cache_destroy(cache);
>
> setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
> - cache = disk_cache_create("test", "make_check");
> + cache = disk_cache_create("test", "make_check", 0);
>
> disk_cache_put(cache, blob_key, blob, sizeof(blob));
> disk_cache_put(cache, string_key, string, sizeof(string));
>
> /* disk_cache_put() hands things off to a thread give it some time to
> * finish.
> */
> wait_until_file_written(cache, blob_key);
> wait_until_file_written(cache, string_key);
>
> @@ -431,21 +431,21 @@ test_put_key_and_get_key(void)
> bool result;
>
> uint8_t key_a[20] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
> 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
> uint8_t key_b[20] = { 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
> 30, 33, 32, 33, 34, 35, 36, 37, 38, 39};
> uint8_t key_a_collide[20] =
> { 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", "make_check", 0);
>
> /* First test that disk_cache_has_key returns false before disk_cache_put_key */
> result = disk_cache_has_key(cache, key_a);
> expect_equal(result, 0, "disk_cache_has_key before key added");
>
> /* Then a couple of tests of disk_cache_put_key followed by disk_cache_has_key */
> disk_cache_put_key(cache, key_a);
> result = disk_cache_has_key(cache, key_a);
> expect_equal(result, 1, "disk_cache_has_key after key added");
>
> diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
> index 15cb965..13b76d7 100644
> --- a/src/gallium/drivers/nouveau/nouveau_screen.c
> +++ b/src/gallium/drivers/nouveau/nouveau_screen.c
> @@ -151,21 +151,21 @@ nouveau_disk_cache_create(struct nouveau_screen *screen)
> uint32_t mesa_timestamp;
> char *timestamp_str;
> int res;
>
> if (disk_cache_get_function_timestamp(nouveau_disk_cache_create,
> &mesa_timestamp)) {
> res = asprintf(×tamp_str, "%u", mesa_timestamp);
> if (res != -1) {
> screen->disk_shader_cache =
> disk_cache_create(nouveau_screen_get_name(&screen->base),
> - timestamp_str);
> + timestamp_str, 0);
> free(timestamp_str);
> }
> }
> }
>
> int
> nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
> {
> struct pipe_screen *pscreen = &screen->base;
> struct nv04_fifo nv04_data = { .vram = 0xbeef0201, .gart = 0xbeef0202 };
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
> index ccf90bc..2d8feee 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.c
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
> @@ -861,21 +861,21 @@ static void r600_disk_cache_create(struct r600_common_screen *rscreen)
> if (disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo,
> &llvm_timestamp)) {
> res = asprintf(×tamp_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);
> + timestamp_str, 0);
> free(timestamp_str);
> }
> }
> }
>
> static struct disk_cache *r600_get_disk_shader_cache(struct pipe_screen *pscreen)
> {
> struct r600_common_screen *rscreen = (struct r600_common_screen*)pscreen;
> return rscreen->disk_shader_cache;
> }
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index cf5d518..138d7ec 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -154,21 +154,22 @@ concatenate_and_mkdir(void *ctx, const char *path, const char *name)
>
> new_path = ralloc_asprintf(ctx, "%s/%s", path, name);
>
> if (mkdir_if_needed(new_path) == 0)
> return new_path;
> else
> return NULL;
> }
>
> struct disk_cache *
> -disk_cache_create(const char *gpu_name, const char *timestamp)
> +disk_cache_create(const char *gpu_name, const char *timestamp,
> + uint64_t driver_flags)
> {
> void *local;
> struct disk_cache *cache = NULL;
> char *path, *max_size_str;
> uint64_t max_size;
> int fd = -1;
> struct stat sb;
> size_t size;
>
> /* If running as a users other than the real user disable cache */
> @@ -349,29 +350,34 @@ disk_cache_create(const char *gpu_name, const char *timestamp)
> 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;
>
> + size_t driver_flags_size = sizeof(driver_flags);
> + cache->driver_keys_blob_size += driver_flags_size;
> +
> cache->driver_keys_blob =
> ralloc_size(cache, cache->driver_keys_blob_size);
> if (!cache->driver_keys_blob)
> 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);
> + memcpy(cache->driver_keys_blob + ts_size + gpu_name_size + ptr_size_size,
> + &driver_flags, driver_flags_size);
>
> /* Seed our rand function */
> s_rand_xorshift128plus(cache->seed_xorshift128plus, true);
>
> ralloc_free(local);
>
> return cache;
>
> fail:
> if (fd != -1)
> diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
> index 2bb1cf5..72f4463 100644
> --- a/src/util/disk_cache.h
> +++ b/src/util/disk_cache.h
> @@ -86,21 +86,22 @@ disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp)
> * put()/get() with no data, but are provided separately to allow for
> * a more efficient implementation.
> *
> * In all cases, the keys are sequences of 20 bytes. It is anticipated
> * that callers will compute appropriate SHA-1 signatures for keys,
> * (though nothing in this implementation directly relies on how the
> * names are computed). See mesa-sha1.h and _mesa_sha1_compute for
> * 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 char *timestamp,
> + uint64_t driver_flags);
>
> /**
> * Destroy a cache object, (freeing all associated resources).
> */
> void
> disk_cache_destroy(struct disk_cache *cache);
>
> /**
> * Remove the item in the cache under the name \key.
> */
> @@ -164,21 +165,22 @@ disk_cache_has_key(struct disk_cache *cache, const cache_key key);
> /**
> * Compute the name \key from \data of given \size.
> */
> void
> disk_cache_compute_key(struct disk_cache *cache, const void *data, size_t size,
> cache_key key);
>
> #else
>
> static inline struct disk_cache *
> -disk_cache_create(const char *gpu_name, const char *timestamp)
> +disk_cache_create(const char *gpu_name, const char *timestamp,
> + uint64_t driver_flags)
> {
> return NULL;
> }
>
> static inline void
> disk_cache_destroy(struct disk_cache *cache) {
> return;
> }
>
> static inline void
>
More information about the mesa-dev
mailing list