From 7ee7b0ecbc0de098cba631b2ca0b3291c3817665 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Thu, 22 Aug 2019 16:08:16 -0700 Subject: [PATCH] iris: Fix large timeout handling in rel2abs() ...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 Reviewed-by: Eric Engestrom --- src/gallium/drivers/iris/iris_fence.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/gallium/drivers/iris/iris_fence.c b/src/gallium/drivers/iris/iris_fence.c index d4ce3c16728..3aaa0af2281 100644 --- a/src/gallium/drivers/iris/iris_fence.c +++ b/src/gallium/drivers/iris/iris_fence.c @@ -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, ¤t); + 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; -- 2.30.2