X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Fdisk_cache.h;h=29fb37cea1100f1111fd706cf243288e0f286759;hb=b9e163fa67ea27fffd3d2294f4f1e19b57814aeb;hp=50bd9f41ac4b3097b2af0318f23c936b4d615859;hpb=cc10b34e9ed1104f4ceb88a49a42e1d6a743d52f;p=mesa.git diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h index 50bd9f41ac4..29fb37cea11 100644 --- a/src/util/disk_cache.h +++ b/src/util/disk_cache.h @@ -26,11 +26,14 @@ #ifdef HAVE_DLFCN_H #include +#include +#include "util/build_id.h" #endif #include #include #include #include +#include "util/mesa-sha1.h" #ifdef __cplusplus extern "C" { @@ -88,7 +91,7 @@ disk_cache_format_hex_id(char *buf, const uint8_t *hex_id, unsigned size) return buf; } -#ifdef HAVE_DLFCN_H +#ifdef HAVE_DLADDR static inline bool disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp) { @@ -100,9 +103,41 @@ disk_cache_get_function_timestamp(void *ptr, uint32_t* timestamp) if (stat(info.dli_fname, &st)) { return false; } + + if (!st.st_mtime) { + fprintf(stderr, "Mesa: The provided filesystem timestamp for the cache " + "is bogus! Disabling On-disk cache.\n"); + return false; + } + *timestamp = st.st_mtime; + + return true; +} + +static inline bool +disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) +{ + uint32_t timestamp; + +#ifdef HAVE_DL_ITERATE_PHDR + const struct build_id_note *note = NULL; + if ((note = build_id_find_nhdr_for_addr(ptr))) { + _mesa_sha1_update(ctx, build_id_data(note), build_id_length(note)); + } else +#endif + if (disk_cache_get_function_timestamp(ptr, ×tamp)) { + _mesa_sha1_update(ctx, ×tamp, sizeof(timestamp)); + } else + return false; return true; } +#else +static inline bool +disk_cache_get_function_identifier(void *ptr, struct mesa_sha1 *ctx) +{ + return false; +} #endif /* Provide inlined stub functions if the shader cache is disabled. */ @@ -145,6 +180,12 @@ disk_cache_create(const char *gpu_name, const char *timestamp, void disk_cache_destroy(struct disk_cache *cache); +/* Wait for all previous disk_cache_put() calls to be processed (used for unit + * testing). + */ +void +disk_cache_wait_for_idle(struct disk_cache *cache); + /** * Remove the item in the cache under the name \key. */