diff options
author | Timothy Arceri <[email protected]> | 2017-03-13 11:07:30 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-03-15 11:15:11 +1100 |
commit | 50989f87e62e0b9a4796c565a103ce45c684c673 (patch) | |
tree | 27f6aa8b87beebc07438485bb683ed3da8d2423d /src/compiler/glsl | |
parent | fc5ec64ba3bb0e337127443a85e2a3f23abba34b (diff) |
util/disk_cache: use a thread queue to write to shader cache
This should help reduce any overhead added by the shader cache
when programs are not found in the cache.
To avoid creating any special function just for the sake of the
tests we add a one second delay whenever we call dick_cache_put()
to give it time to finish.
V2: poll for file when waiting for thread in test
V3: fix poll delay to really be 100ms, and simplify the wait function
Reviewed-by: Grazvydas Ignotas <[email protected]>
Diffstat (limited to 'src/compiler/glsl')
-rw-r--r-- | src/compiler/glsl/tests/cache_test.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/compiler/glsl/tests/cache_test.c b/src/compiler/glsl/tests/cache_test.c index 7a1ff0ac5bc..61ee630395a 100644 --- a/src/compiler/glsl/tests/cache_test.c +++ b/src/compiler/glsl/tests/cache_test.c @@ -32,6 +32,7 @@ #include <stdarg.h> #include <inttypes.h> #include <limits.h> +#include <time.h> #include <unistd.h> #include "util/mesa-sha1.h" @@ -231,6 +232,26 @@ does_cache_contain(struct disk_cache *cache, cache_key key) } static void +wait_until_file_written(struct disk_cache *cache, cache_key key) +{ + struct timespec req; + struct timespec rem; + + /* Set 100ms delay */ + req.tv_sec = 0; + req.tv_nsec = 100000000; + + unsigned retries = 0; + while (retries++ < 20) { + if (does_cache_contain(cache, key)) { + break; + } + + nanosleep(&req, &rem); + } +} + +static void test_put_and_get(void) { struct disk_cache *cache; @@ -260,6 +281,11 @@ test_put_and_get(void) /* Simple test of put and get. */ disk_cache_put(cache, blob_key, blob, sizeof(blob)); + /* disk_cache_put() hands things off to a thread give it some time to + * finish. + */ + wait_until_file_written(cache, blob_key); + result = disk_cache_get(cache, blob_key, &size); expect_equal_str(blob, result, "disk_cache_get of existing item (pointer)"); expect_equal(size, sizeof(blob), "disk_cache_get of existing item (size)"); @@ -270,6 +296,11 @@ test_put_and_get(void) _mesa_sha1_compute(string, sizeof(string), string_key); 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, string_key); + 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)"); @@ -308,6 +339,11 @@ test_put_and_get(void) free(one_KB); + /* disk_cache_put() hands things off to a thread give it some time to + * finish. + */ + wait_until_file_written(cache, one_KB_key); + result = disk_cache_get(cache, one_KB_key, &size); expect_non_null(result, "3rd disk_cache_get of existing item (pointer)"); expect_equal(size, 1024, "3rd disk_cache_get of existing item (size)"); @@ -337,6 +373,12 @@ test_put_and_get(void) 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); + count = 0; if (does_cache_contain(cache, blob_key)) count++; @@ -359,6 +401,11 @@ test_put_and_get(void) free(one_MB); + /* disk_cache_put() hands things off to a thread give it some time to + * finish. + */ + wait_until_file_written(cache, one_MB_key); + count = 0; if (does_cache_contain(cache, blob_key)) count++; |