[Mesa-dev] [PATCH] util/radv/adv: move *_get_function_timestamp() to utils

Timothy Arceri tarceri at itsqueeze.com
Fri Feb 10 02:03:05 UTC 2017


---
 src/amd/vulkan/radv_device.c  | 22 +++-------------------
 src/intel/vulkan/anv_device.c | 20 ++------------------
 src/util/disk_cache.h         | 17 +++++++++++++++++
 3 files changed, 22 insertions(+), 37 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 8a54a2a..b5a3435 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -25,14 +25,13 @@
  * IN THE SOFTWARE.
  */
 
-#include <dlfcn.h>
 #include <stdbool.h>
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include <sys/stat.h>
 #include "radv_private.h"
 #include "radv_cs.h"
+#include "util/disk_cache.h"
 #include "util/strtod.h"
 
 #include <xf86drm.h>
@@ -47,28 +46,13 @@
 struct radv_dispatch_table dtable;
 
 static int
-radv_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
 radv_device_get_cache_uuid(enum radeon_family family, void *uuid)
 {
 	uint32_t mesa_timestamp, llvm_timestamp;
 	uint16_t f = family;
 	memset(uuid, 0, VK_UUID_SIZE);
-	if (radv_get_function_timestamp(radv_device_get_cache_uuid, &mesa_timestamp) ||
-	    radv_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo, &llvm_timestamp))
+	if (disk_cache_get_function_timestamp(radv_device_get_cache_uuid, &mesa_timestamp) ||
+	    disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo, &llvm_timestamp))
 		return -1;
 
 	memcpy(uuid, &mesa_timestamp, 4);
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 91ee67f..607fc4f 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -21,18 +21,17 @@
  * 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 "util/strtod.h"
 #include "util/debug.h"
+#include "util/disk_cache.h"
 
 #include "genxml/gen7_pack.h"
 
@@ -55,27 +54,12 @@ compiler_perf_log(void *data, const char *fmt, ...)
 }
 
 static bool
-anv_get_function_timestamp(void *ptr, uint32_t* timestamp)
-{
-   Dl_info info;
-   struct stat st;
-   if (!dladdr(ptr, &info) || !info.dli_fname)
-      return false;
-
-   if (stat(info.dli_fname, &st))
-      return false;
-
-   *timestamp = st.st_mtim.tv_sec;
-   return true;
-}
-
-static bool
 anv_device_get_cache_uuid(void *uuid)
 {
    uint32_t timestamp;
 
    memset(uuid, 0, VK_UUID_SIZE);
-   if (!anv_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
+   if (!disk_cache_get_function_timestamp(anv_device_get_cache_uuid, &timestamp))
       return false;
 
    snprintf(uuid, VK_UUID_SIZE, "anv-%d", timestamp);
diff --git a/src/util/disk_cache.h b/src/util/disk_cache.h
index 4ff1da5..6fbc07b 100644
--- a/src/util/disk_cache.h
+++ b/src/util/disk_cache.h
@@ -24,8 +24,10 @@
 #ifndef DISK_CACHE_H
 #define DISK_CACHE_H
 
+#include <dlfcn.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <sys/stat.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -133,6 +135,21 @@ disk_cache_put_key(struct disk_cache *cache, cache_key key);
 bool
 disk_cache_has_key(struct disk_cache *cache, cache_key key);
 
+static inline int
+disk_cache_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;
+}
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.9.3



More information about the mesa-dev mailing list