[Mesa-dev] [PATCH 35/40] util/disk_cache: allow drivers to pass a directory structure

Timothy Arceri tarceri at itsqueeze.com
Tue Feb 7 21:29:29 UTC 2017


On Tue, 7 Feb 2017 11:40:12 -0600
Aaron Watry <awatry at gmail.com> wrote:

> On Mon, Feb 6, 2017 at 9:42 PM, Timothy Arceri <tarceri at itsqueeze.com>
> wrote:
> 
> > In order to avoid costly fallback recompiles when cache items are
> > created with an old version of Mesa or for a different gpu on the
> > same system we want to create directories that look like this:
> >
> > ./{MESA_VERSION_STRING}/{GPU_ID}
> >
> > For llvm based drivers we will probably want an additional
> > {LLVM_VERSION} folder although it looks like there is currently
> > no support for querying this at runtime.
> > ---
> >  src/compiler/glsl/tests/cache_test.c | 20 ++++++++++----------
> >  src/util/disk_cache.c                | 29
> > +++++++++++++++++++++++++---- src/util/disk_cache.h
> > |  4 ++-- 3 files changed, 37 insertions(+), 16 deletions(-)
> >
> > diff --git a/src/compiler/glsl/tests/cache_test.c
> > b/src/compiler/glsl/tests/cache_test.c
> > index 8547141..ba56441 100644
> > --- a/src/compiler/glsl/tests/cache_test.c
> > +++ b/src/compiler/glsl/tests/cache_test.c
> > @@ -126,7 +126,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();
> > +   cache = disk_cache_create("test", "make_check");
> >     expect_null(cache, "disk_cache_create with
> > MESA_GLSL_CACHE_DISABLE set");
> >
> >     unsetenv("MESA_GLSL_CACHE_DISABLE");
> > @@ -137,19 +137,19 @@ test_disk_cache_create(void)
> >     unsetenv("MESA_GLSL_CACHE_DIR");
> >     unsetenv("XDG_CACHE_HOME");
> >
> > -   cache = disk_cache_create();
> > +   cache = disk_cache_create("test", "make_check");
> >     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();
> > +   cache = disk_cache_create("test", "make_check");
> >     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();
> > +   cache = disk_cache_create("test", "make_check");
> >     expect_non_null(cache, "disk_cache_create with XDG_CACHE_HOME
> > set");
> >
> >     disk_cache_destroy(cache);
> > @@ -159,12 +159,12 @@ 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();
> > +   cache = disk_cache_create("test", "make_check");
> >     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();
> > +   cache = disk_cache_create("test", "make_check");
> >     expect_non_null(cache, "disk_cache_create with
> > MESA_GLSL_CACHE_DIR set");
> >
> >     disk_cache_destroy(cache);
> > @@ -203,7 +203,7 @@ test_put_and_get(void)
> >     uint8_t one_KB_key[20], one_MB_key[20];
> >     int count;
> >
> > -   cache = disk_cache_create();
> > +   cache = disk_cache_create("test", "make_check");
> >
> >     _mesa_sha1_compute(blob, sizeof(blob), blob_key);
> >
> > @@ -235,7 +235,7 @@ test_put_and_get(void)
> >     disk_cache_destroy(cache);
> >
> >     setenv("MESA_GLSL_CACHE_MAX_SIZE", "1K", 1);
> > -   cache = disk_cache_create();
> > +   cache = disk_cache_create("test", "make_check");
> >
> >     one_KB = calloc(1, 1024);
> >
> > @@ -287,7 +287,7 @@ test_put_and_get(void)
> >     disk_cache_destroy(cache);
> >
> >     setenv("MESA_GLSL_CACHE_MAX_SIZE", "1M", 1);
> > -   cache = disk_cache_create();
> > +   cache = disk_cache_create("test", "make_check");
> >
> >     disk_cache_put(cache, blob_key, blob, sizeof(blob));
> >     disk_cache_put(cache, string_key, string, sizeof(string));
> > @@ -343,7 +343,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();
> > +   cache = disk_cache_create("test", "make_check");
> >
> >     /* 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/util/disk_cache.c b/src/util/disk_cache.c
> > index 382ac6c..df511e4 100644
> > --- a/src/util/disk_cache.c
> > +++ b/src/util/disk_cache.c
> > @@ -115,7 +115,7 @@ mkdir_if_needed(char *path)
> >   *      <path>/<name> cannot be created as a directory
> >   */
> >  static char *
> > -concatenate_and_mkdir(void *ctx, char *path, char *name)
> > +concatenate_and_mkdir(void *ctx, char *path, const char *name)
> >  {
> >     char *new_path;
> >     struct stat sb;
> > @@ -131,8 +131,27 @@ concatenate_and_mkdir(void *ctx, char *path,
> > char *name)
> >        return NULL;
> >  }
> >
> > +static char *
> > +create_mesa_cache_dir(void *mem_ctx, char *path, const char
> > *mesa_version,
> > +                      const char *gpu_name)
> > +{
> > +   char *new_path = concatenate_and_mkdir(mem_ctx, path, "mesa");
> > +   if (new_path == NULL)
> > +      return NULL;
> > +
> > +   new_path = concatenate_and_mkdir(mem_ctx, new_path,
> > mesa_version);
> > +   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(void)
> > +disk_cache_create(const char *gpu_name, const char *mesa_version)
> >  
> 
> You forgot to update cache_test.c, so make check now fails:
> 
> DIR/src/mesa/src/compiler/glsl/tests/cache_test.c: In function
> ‘test_put_key_and_get_key’:
> DIR/src/mesa/src/compiler/glsl/tests/cache_test.c:346:12: error: too
> few arguments to function ‘disk_cache_create’
>     cache = disk_cache_create();
>             ^
> In file included from
> DIR/src/mesa/src/compiler/glsl/tests/cache_test.c:36:0:
> DIR/src/mesa/src/util/disk_cache.h:72:1: note: declared here
>  disk_cache_create(const char *driver_directory, const char
> *mesa_version); ^
> Makefile:2362: recipe for target
> 'glsl/tests/glsl_tests_cache_test-cache_test.o' failed
> 
> 

Actually I fixed that before sending out, although I've done
something silly. I did git send-email to write the cover letter
then remembered to run make check afterwards and fixed the tests,
however that would have sent the original patch. 

I'll send a v2 thanks.


> 
> 
> >  {
> >     void *local;
> >     struct disk_cache *cache = NULL;
> > @@ -180,7 +199,8 @@ disk_cache_create(void)
> >           if (mkdir_if_needed(xdg_cache_home) == -1)
> >              goto fail;
> >
> > -         path = concatenate_and_mkdir(local, xdg_cache_home,
> > "mesa");
> > +         path = create_mesa_cache_dir(local, xdg_cache_home,
> > mesa_version,
> > +                                      gpu_name);
> >           if (path == NULL)
> >              goto fail;
> >        }
> > @@ -216,7 +236,8 @@ disk_cache_create(void)
> >        if (path == NULL)
> >           goto fail;
> >
> > -      path = concatenate_and_mkdir(local, path, "mesa");
> > +      path = create_mesa_cache_dir(local, path, mesa_version,
> > +                                   gpu_name);
> >        if (path == NULL)
> >           goto fail;
> >     }
> > diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
> > index 1f2bf3d..e429db5 100644
> > --- a/src/util/disk_cache.h
> > +++ b/src/util/disk_cache.h
> > @@ -69,7 +69,7 @@ struct disk_cache;
> >   * assistance in computing SHA-1 signatures.
> >   */
> >  struct disk_cache *
> > -disk_cache_create(void);
> > +disk_cache_create(const char *gpu_name, const char *mesa_version);
> >
> >  /**
> >   * Destroy a cache object, (freeing all associated resources).
> > @@ -140,7 +140,7 @@ disk_cache_has_key(struct disk_cache *cache,
> > cache_key key);
> >  #else
> >
> >  static inline struct disk_cache *
> > -disk_cache_create(void)
> > +disk_cache_create(const char *gpu_name, const char *mesa_version)
> >  {
> >     return NULL;
> >  }
> > --
> > 2.9.3
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> >  



More information about the mesa-dev mailing list