Skip to content

Commit 2cbb8d4

Browse files
drm/i915: use new iterator in i915_gem_object_wait_reservation
Simplifying the code a bit. Signed-off-by: Christian König <[email protected]> [mlankhorst: Handle timeout = 0 correctly, use new i915_request_wait_timeout.] Signed-off-by: Maarten Lankhorst <[email protected]> Acked-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 7e2e69e commit 2cbb8d4

File tree

1 file changed

+19
-44
lines changed

1 file changed

+19
-44
lines changed

drivers/gpu/drm/i915/gem/i915_gem_wait.c

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ i915_gem_object_wait_fence(struct dma_fence *fence,
2525
return timeout;
2626

2727
if (dma_fence_is_i915(fence))
28-
return i915_request_wait(to_request(fence), flags, timeout);
28+
return i915_request_wait_timeout(to_request(fence), flags, timeout);
2929

3030
return dma_fence_wait_timeout(fence,
3131
flags & I915_WAIT_INTERRUPTIBLE,
@@ -37,58 +37,29 @@ i915_gem_object_wait_reservation(struct dma_resv *resv,
3737
unsigned int flags,
3838
long timeout)
3939
{
40-
struct dma_fence *excl;
41-
bool prune_fences = false;
42-
43-
if (flags & I915_WAIT_ALL) {
44-
struct dma_fence **shared;
45-
unsigned int count, i;
46-
int ret;
47-
48-
ret = dma_resv_get_fences(resv, &excl, &count, &shared);
49-
if (ret)
50-
return ret;
51-
52-
for (i = 0; i < count; i++) {
53-
timeout = i915_gem_object_wait_fence(shared[i],
54-
flags, timeout);
55-
if (timeout < 0)
56-
break;
57-
58-
dma_fence_put(shared[i]);
59-
}
40+
struct dma_resv_iter cursor;
41+
struct dma_fence *fence;
42+
long ret = timeout ?: 1;
6043

61-
for (; i < count; i++)
62-
dma_fence_put(shared[i]);
63-
kfree(shared);
44+
dma_resv_iter_begin(&cursor, resv, flags & I915_WAIT_ALL);
45+
dma_resv_for_each_fence_unlocked(&cursor, fence) {
46+
ret = i915_gem_object_wait_fence(fence, flags, timeout);
47+
if (ret <= 0)
48+
break;
6449

65-
/*
66-
* If both shared fences and an exclusive fence exist,
67-
* then by construction the shared fences must be later
68-
* than the exclusive fence. If we successfully wait for
69-
* all the shared fences, we know that the exclusive fence
70-
* must all be signaled. If all the shared fences are
71-
* signaled, we can prune the array and recover the
72-
* floating references on the fences/requests.
73-
*/
74-
prune_fences = count && timeout >= 0;
75-
} else {
76-
excl = dma_resv_get_excl_unlocked(resv);
50+
if (timeout)
51+
timeout = ret;
7752
}
78-
79-
if (excl && timeout >= 0)
80-
timeout = i915_gem_object_wait_fence(excl, flags, timeout);
81-
82-
dma_fence_put(excl);
53+
dma_resv_iter_end(&cursor);
8354

8455
/*
8556
* Opportunistically prune the fences iff we know they have *all* been
8657
* signaled.
8758
*/
88-
if (prune_fences)
59+
if (timeout > 0)
8960
dma_resv_prune(resv);
9061

91-
return timeout;
62+
return ret;
9263
}
9364

9465
static void fence_set_priority(struct dma_fence *fence,
@@ -177,7 +148,11 @@ i915_gem_object_wait(struct drm_i915_gem_object *obj,
177148

178149
timeout = i915_gem_object_wait_reservation(obj->base.resv,
179150
flags, timeout);
180-
return timeout < 0 ? timeout : 0;
151+
152+
if (timeout < 0)
153+
return timeout;
154+
155+
return !timeout ? -ETIME : 0;
181156
}
182157

183158
static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)

0 commit comments

Comments
 (0)