v3dv: Use util/os_time helpers
authorJason Ekstrand <jason.ekstrand@collabora.com>
Mon, 4 Apr 2022 15:22:45 +0000 (10:22 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 13 Apr 2022 17:22:14 +0000 (17:22 +0000)
Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15704>

src/broadcom/vulkan/v3dv_limits.h
src/broadcom/vulkan/v3dv_queue.c

index 52bf2dd..9cda9f0 100644 (file)
@@ -23,8 +23,6 @@
 #ifndef V3DV_LIMITS_H
 #define V3DV_LIMITS_H
 
-#define NSEC_PER_SEC 1000000000ull
-
 /* From vulkan spec "If the multiple viewports feature is not enabled,
  * scissorCount must be 1", ditto for viewportCount. For now we don't support
  * that feature.
index f88c7ce..cd1018e 100644 (file)
@@ -25,6 +25,7 @@
 #include "drm-uapi/v3d_drm.h"
 
 #include "broadcom/clif/clif_dump.h"
+#include "util/os_time.h"
 
 #include <errno.h>
 #include <time.h>
@@ -67,25 +68,6 @@ v3dv_clif_dump(struct v3dv_device *device,
    clif_dump_destroy(clif);
 }
 
-static uint64_t
-gettime_ns()
-{
-   struct timespec current;
-   clock_gettime(CLOCK_MONOTONIC, &current);
-   return (uint64_t)current.tv_sec * NSEC_PER_SEC + current.tv_nsec;
-}
-
-static uint64_t
-get_absolute_timeout(uint64_t timeout)
-{
-   uint64_t current_time = gettime_ns();
-   uint64_t max_timeout = (uint64_t) INT64_MAX - current_time;
-
-   timeout = MIN2(max_timeout, timeout);
-
-   return (current_time + timeout);
-}
-
 static VkResult
 queue_submit_job(struct v3dv_queue *queue,
                  struct v3dv_job *job,
@@ -2056,7 +2038,7 @@ v3dv_WaitForFences(VkDevice _device,
    if (vk_device_is_lost(&device->vk))
       return VK_ERROR_DEVICE_LOST;
 
-   const uint64_t abs_timeout = get_absolute_timeout(timeout);
+   const uint64_t abs_timeout = os_time_get_absolute_timeout(timeout);
 
    uint32_t *syncobjs = vk_alloc(&device->vk.alloc,
                                  sizeof(*syncobjs) * fenceCount, 8,
@@ -2077,7 +2059,7 @@ v3dv_WaitForFences(VkDevice _device,
    do {
       ret = drmSyncobjWait(device->pdevice->render_fd, syncobjs, fenceCount,
                            timeout, flags, NULL);
-   } while (ret == -ETIME && gettime_ns() < abs_timeout);
+   } while (ret == -ETIME && os_time_get_nano() < abs_timeout);
 
    vk_free(&device->vk.alloc, syncobjs);