[Mesa-dev] [PATCH mesa 2/4] vulkan/wsi: deduplicate get_current_time() functions

Eric Engestrom eric.engestrom at intel.com
Sun Oct 28 13:45:06 UTC 2018


Signed-off-by: Eric Engestrom <eric.engestrom at intel.com>
---
 src/vulkan/wsi/wsi_common.c         |  9 +++++++++
 src/vulkan/wsi/wsi_common.h         |  3 +++
 src/vulkan/wsi/wsi_common_display.c | 16 ++++------------
 src/vulkan/wsi/wsi_common_x11.c     | 14 ++------------
 4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index 51d8655a5a9e8df3acf6..fe352b3e05604a51cc5b 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -26,6 +26,7 @@
 #include "util/macros.h"
 #include "vk_util.h"
 
+#include <time.h>
 #include <unistd.h>
 #include <xf86drm.h>
 
@@ -1019,3 +1020,11 @@ wsi_common_queue_present(const struct wsi_device *wsi,
 
    return final_result;
 }
+
+uint64_t
+wsi_common_get_current_time(void)
+{
+   struct timespec current;
+   clock_gettime(CLOCK_MONOTONIC, &current);
+   return current.tv_nsec + current.tv_sec * 1000000000ull;
+}
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index f6ca013c2a88246e89c1..3c8bba28c58494fd21c5 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -241,4 +241,7 @@ wsi_common_queue_present(const struct wsi_device *wsi,
                          int queue_family_index,
                          const VkPresentInfoKHR *pPresentInfo);
 
+uint64_t
+wsi_common_get_current_time(void);
+
 #endif
diff --git a/src/vulkan/wsi/wsi_common_display.c b/src/vulkan/wsi/wsi_common_display.c
index fd0d30ad80ca3587fe2a..a90fb38e0b1d1de1a18b 100644
--- a/src/vulkan/wsi/wsi_common_display.c
+++ b/src/vulkan/wsi/wsi_common_display.c
@@ -171,17 +171,9 @@ wsi_display_mode_refresh(struct wsi_display_mode *wsi)
                                           (double) MAX2(wsi->vscan, 1));
 }
 
-static uint64_t wsi_get_current_monotonic(void)
-{
-   struct timespec tv;
-
-   clock_gettime(CLOCK_MONOTONIC, &tv);
-   return tv.tv_nsec + tv.tv_sec*1000000000ull;
-}
-
 static uint64_t wsi_rel_to_abs_time(uint64_t rel_time)
 {
-   uint64_t current_time = wsi_get_current_monotonic();
+   uint64_t current_time = wsi_common_get_current_time();
 
    /* check for overflow */
    if (rel_time > UINT64_MAX - current_time)
@@ -1428,8 +1420,8 @@ wsi_display_fence_wait(struct wsi_fence *fence_wsi, uint64_t timeout)
 
    wsi_display_debug("%9lu wait fence %lu %ld\n",
                      pthread_self(), fence->sequence,
-                     (int64_t) (timeout - wsi_get_current_monotonic()));
-   wsi_display_debug_code(uint64_t start_ns = wsi_get_current_monotonic());
+                     (int64_t) (timeout - wsi_common_get_current_time()));
+   wsi_display_debug_code(uint64_t start_ns = wsi_common_get_current_time());
    pthread_mutex_lock(&wsi->wait_mutex);
 
    VkResult result;
@@ -1461,7 +1453,7 @@ wsi_display_fence_wait(struct wsi_fence *fence_wsi, uint64_t timeout)
    pthread_mutex_unlock(&wsi->wait_mutex);
    wsi_display_debug("%9lu fence wait %f ms\n",
                      pthread_self(),
-                     ((int64_t) (wsi_get_current_monotonic() - start_ns)) /
+                     ((int64_t) (wsi_common_get_current_time() - start_ns)) /
                      1.0e6);
    return result;
 }
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index c740726fe54746f8bfc3..d84f7b6a60d7583985b9 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -830,19 +830,9 @@ x11_handle_dri3_present_event(struct x11_swapchain *chain,
 }
 
 
-static uint64_t wsi_get_current_time(void)
-{
-   uint64_t current_time;
-   struct timespec tv;
-
-   clock_gettime(CLOCK_MONOTONIC, &tv);
-   current_time = tv.tv_nsec + tv.tv_sec*1000000000ull;
-   return current_time;
-}
-
 static uint64_t wsi_get_absolute_timeout(uint64_t timeout)
 {
-   uint64_t current_time = wsi_get_current_time();
+   uint64_t current_time = wsi_common_get_current_time();
 
    timeout = MIN2(UINT64_MAX - current_time, timeout);
 
@@ -893,7 +883,7 @@ x11_acquire_next_image_poll_x11(struct x11_swapchain *chain,
             /* If a non-special event happens, the fd will still
              * poll. So recalculate the timeout now just in case.
              */
-            uint64_t current_time = wsi_get_current_time();
+            uint64_t current_time = wsi_common_get_current_time();
             if (atimeout > current_time)
                timeout = atimeout - current_time;
             else
-- 
Cheers,
  Eric



More information about the mesa-dev mailing list