Skip to content

Commit 7e2e69e

Browse files
mlankhorstChristianKoenigAMD
authored andcommitted
drm/i915: Fix i915_request fence wait semantics
The i915_request fence wait behaves differently for timeout = 0 compared to expected dma-fence behavior. i915 behavior: - Unsignaled: -ETIME - Signaled: 0 (= timeout) Expected: - Unsignaled: 0 - Signaled: 1 Signed-off-by: Maarten Lankhorst <[email protected]> Acked-by: Daniel Vetter <[email protected]> Acked-by: Christian König <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]>
1 parent 5e9ddbd commit 7e2e69e

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

drivers/gpu/drm/i915/i915_request.c

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ static signed long i915_fence_wait(struct dma_fence *fence,
9696
bool interruptible,
9797
signed long timeout)
9898
{
99-
return i915_request_wait(to_request(fence),
100-
interruptible | I915_WAIT_PRIORITY,
101-
timeout);
99+
return i915_request_wait_timeout(to_request(fence),
100+
interruptible | I915_WAIT_PRIORITY,
101+
timeout);
102102
}
103103

104104
struct kmem_cache *i915_request_slab_cache(void)
@@ -1857,23 +1857,27 @@ static void request_wait_wake(struct dma_fence *fence, struct dma_fence_cb *cb)
18571857
}
18581858

18591859
/**
1860-
* i915_request_wait - wait until execution of request has finished
1860+
* i915_request_wait_timeout - wait until execution of request has finished
18611861
* @rq: the request to wait upon
18621862
* @flags: how to wait
18631863
* @timeout: how long to wait in jiffies
18641864
*
1865-
* i915_request_wait() waits for the request to be completed, for a
1865+
* i915_request_wait_timeout() waits for the request to be completed, for a
18661866
* maximum of @timeout jiffies (with MAX_SCHEDULE_TIMEOUT implying an
18671867
* unbounded wait).
18681868
*
18691869
* Returns the remaining time (in jiffies) if the request completed, which may
1870-
* be zero or -ETIME if the request is unfinished after the timeout expires.
1870+
* be zero if the request is unfinished after the timeout expires.
1871+
* If the timeout is 0, it will return 1 if the fence is signaled.
1872+
*
18711873
* May return -EINTR is called with I915_WAIT_INTERRUPTIBLE and a signal is
18721874
* pending before the request completes.
1875+
*
1876+
* NOTE: This function has the same wait semantics as dma-fence.
18731877
*/
1874-
long i915_request_wait(struct i915_request *rq,
1875-
unsigned int flags,
1876-
long timeout)
1878+
long i915_request_wait_timeout(struct i915_request *rq,
1879+
unsigned int flags,
1880+
long timeout)
18771881
{
18781882
const int state = flags & I915_WAIT_INTERRUPTIBLE ?
18791883
TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;
@@ -1883,7 +1887,7 @@ long i915_request_wait(struct i915_request *rq,
18831887
GEM_BUG_ON(timeout < 0);
18841888

18851889
if (dma_fence_is_signaled(&rq->fence))
1886-
return timeout;
1890+
return timeout ?: 1;
18871891

18881892
if (!timeout)
18891893
return -ETIME;
@@ -1992,6 +1996,39 @@ long i915_request_wait(struct i915_request *rq,
19921996
return timeout;
19931997
}
19941998

1999+
/**
2000+
* i915_request_wait - wait until execution of request has finished
2001+
* @rq: the request to wait upon
2002+
* @flags: how to wait
2003+
* @timeout: how long to wait in jiffies
2004+
*
2005+
* i915_request_wait() waits for the request to be completed, for a
2006+
* maximum of @timeout jiffies (with MAX_SCHEDULE_TIMEOUT implying an
2007+
* unbounded wait).
2008+
*
2009+
* Returns the remaining time (in jiffies) if the request completed, which may
2010+
* be zero or -ETIME if the request is unfinished after the timeout expires.
2011+
* May return -EINTR is called with I915_WAIT_INTERRUPTIBLE and a signal is
2012+
* pending before the request completes.
2013+
*
2014+
* NOTE: This function behaves differently from dma-fence wait semantics for
2015+
* timeout = 0. It returns 0 on success, and -ETIME if not signaled.
2016+
*/
2017+
long i915_request_wait(struct i915_request *rq,
2018+
unsigned int flags,
2019+
long timeout)
2020+
{
2021+
long ret = i915_request_wait_timeout(rq, flags, timeout);
2022+
2023+
if (!ret)
2024+
return -ETIME;
2025+
2026+
if (ret > 0 && !timeout)
2027+
return 0;
2028+
2029+
return ret;
2030+
}
2031+
19952032
static int print_sched_attr(const struct i915_sched_attr *attr,
19962033
char *buf, int x, int len)
19972034
{

drivers/gpu/drm/i915/i915_request.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,11 @@ void i915_request_unsubmit(struct i915_request *request);
414414

415415
void i915_request_cancel(struct i915_request *rq, int error);
416416

417+
long i915_request_wait_timeout(struct i915_request *rq,
418+
unsigned int flags,
419+
long timeout)
420+
__attribute__((nonnull(1)));
421+
417422
long i915_request_wait(struct i915_request *rq,
418423
unsigned int flags,
419424
long timeout)

0 commit comments

Comments
 (0)