iris: Fix large timeout handling in rel2abs()
authorKenneth Graunke <kenneth@whitecape.org>
Thu, 22 Aug 2019 23:08:16 +0000 (16:08 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Fri, 23 Aug 2019 17:32:01 +0000 (10:32 -0700)
...by copying the implementation of anv_get_absolute_timeout().

Appears to fix a CTS test with 32-bit builds:
GTF-GL46.gtf32.GL3Tests.sync.sync_functionality_clientwaitsync_flush

Fixes: f459c56be6b ("iris: Add fence support using drm_syncobj")
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Eric Engestrom <eric@engestrom.ch>
src/gallium/drivers/iris/iris_fence.c

index d4ce3c1..3aaa0af 100644 (file)
@@ -206,24 +206,25 @@ iris_fence_await(struct pipe_context *ctx,
 #define MSEC_PER_SEC (1000)
 
 static uint64_t
-rel2abs(uint64_t timeout)
+gettime_ns(void)
 {
-   struct timespec ts;
-   uint64_t now;
+   struct timespec current;
+   clock_gettime(CLOCK_MONOTONIC, &current);
+   return (uint64_t)current.tv_sec * NSEC_PER_SEC + current.tv_nsec;
+}
 
-   if (!timeout)
+static uint64_t
+rel2abs(uint64_t timeout)
+{
+   if (timeout == 0)
       return 0;
 
-   if (timeout == PIPE_TIMEOUT_INFINITE)
-      return INT64_MAX;
-
-   clock_gettime(CLOCK_MONOTONIC, &ts);
-   now = ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
+   uint64_t current_time = gettime_ns();
+   uint64_t max_timeout = (uint64_t) INT64_MAX - current_time;
 
-   if (now > INT64_MAX - timeout)
-      return INT64_MAX;
+   timeout = MIN2(max_timeout, timeout);
 
-   return now + timeout;
+   return current_time + timeout;
 }
 
 static bool
@@ -244,7 +245,7 @@ iris_fence_finish(struct pipe_screen *p_screen,
    struct drm_syncobj_wait args = {
       .handles = (uintptr_t)handles,
       .count_handles = fence->count,
-      .timeout_nsec = rel2abs(timeout), /* XXX */
+      .timeout_nsec = rel2abs(timeout),
       .flags = DRM_SYNCOBJ_WAIT_FLAGS_WAIT_ALL
    };
    return gen_ioctl(screen->fd, DRM_IOCTL_SYNCOBJ_WAIT, &args) == 0;