[Mesa-dev] [PATCH 2/8] anv: Use library mtime for cache UUID.

Emil Velikov emil.l.velikov at gmail.com
Thu Nov 24 20:30:39 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

Inspired by a similar commit for radv.

Rather than recomputing the timestamp on each make invocation, just
fetch it at runtime.

Thus we no longer get the constant rebuild of anv_device.c and the
follow-up libvulkan_intel.so link, when nothing has changed.

I.e. using make && make install is a little bit faster.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/intel/vulkan/anv_device.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 58c6b3f..4711501 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -21,15 +21,16 @@
  * IN THE SOFTWARE.
  */
 
+#include <dlfcn.h>
 #include <assert.h>
 #include <stdbool.h>
 #include <string.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 
 #include "anv_private.h"
-#include "anv_timestamp.h"
 #include "util/strtod.h"
 #include "util/debug.h"
 
@@ -53,11 +54,32 @@ compiler_perf_log(void *data, const char *fmt, ...)
    va_end(args);
 }
 
-static void
+static int
+anv_get_function_timestamp(void *ptr, uint32_t* timestamp)
+{
+   Dl_info info;
+   struct stat st;
+   if (!dladdr(ptr, &info) || !info.dli_fname)
+      return -1;
+
+   if (stat(info.dli_fname, &st))
+      return -1;
+
+   *timestamp = st.st_mtim.tv_sec;
+   return 0;
+}
+
+static int
 anv_device_get_cache_uuid(void *uuid)
 {
+   uint32_t timestamp;
+
    memset(uuid, 0, VK_UUID_SIZE);
-   snprintf(uuid, VK_UUID_SIZE, "anv-%s", ANV_TIMESTAMP);
+   if (anv_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
+         return -1;
+
+   snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);
+   return 0;
 }
 
 static VkResult
@@ -186,7 +208,14 @@ anv_physical_device_init(struct anv_physical_device *device,
    if (result != VK_SUCCESS)
        goto fail;
 
-   anv_device_get_cache_uuid(device->uuid);
+   if (anv_device_get_cache_uuid(device->uuid)) {
+      anv_finish_wsi(device);
+      ralloc_free(device->compiler);
+      result = vk_errorf(VK_ERROR_INITIALIZATION_FAILED,
+                         "cannot generate UUID");
+      goto fail;
+   }
+
 
    /* XXX: Actually detect bit6 swizzling */
    isl_device_init(&device->isl_dev, &device->info, swizzled);
-- 
2.10.2



More information about the mesa-dev mailing list