Commit ebd0fd4b authored by Dave Gordon's avatar Dave Gordon Committed by Daniel Vetter

drm/i915: Consolidate ring freespace calculations

There are numerous places in the code where the driver's idea of
how much space is left in a ring is updated using the driver's
latest notions of the positions of 'head' and 'tail' for the ring.
Among them are some that update one or both of these values before
(re)doing the calculation. In particular, there are four different
places in the code where 'last_retired_head' is copied to 'head'
and then set to -1; and two of these do not have a guard to check
that it has actually been updated since last time it was consumed,
leaving the possibility that the dummy -1 can be transferred from
'last_retired_head' to 'head', causing the space calculation to
produce 'impossible' results (previously seen on Android/VLV).

This code therefore consolidates all the calculation and updating of
these values, such that there is only one place where the ring space
is updated, and it ALWAYS uses (and consumes) 'last_retired_head' if
(and ONLY if) it has been updated since the last call.
Signed-off-by: default avatarDave Gordon <david.s.gordon@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 4f54741e
...@@ -925,14 +925,8 @@ static int logical_ring_wait_request(struct intel_ringbuffer *ringbuf, ...@@ -925,14 +925,8 @@ static int logical_ring_wait_request(struct intel_ringbuffer *ringbuf,
struct drm_i915_gem_request *request; struct drm_i915_gem_request *request;
int ret; int ret;
if (ringbuf->last_retired_head != -1) { if (intel_ring_space(ringbuf) >= bytes)
ringbuf->head = ringbuf->last_retired_head;
ringbuf->last_retired_head = -1;
ringbuf->space = intel_ring_space(ringbuf);
if (ringbuf->space >= bytes)
return 0; return 0;
}
list_for_each_entry(request, &ring->request_list, list) { list_for_each_entry(request, &ring->request_list, list) {
/* /*
...@@ -959,11 +953,8 @@ static int logical_ring_wait_request(struct intel_ringbuffer *ringbuf, ...@@ -959,11 +953,8 @@ static int logical_ring_wait_request(struct intel_ringbuffer *ringbuf,
return ret; return ret;
i915_gem_retire_requests_ring(ring); i915_gem_retire_requests_ring(ring);
ringbuf->head = ringbuf->last_retired_head;
ringbuf->last_retired_head = -1;
ringbuf->space = intel_ring_space(ringbuf); return intel_ring_space(ringbuf) >= bytes ? 0 : -ENOSPC;
return 0;
} }
static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf, static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf,
...@@ -989,12 +980,10 @@ static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf, ...@@ -989,12 +980,10 @@ static int logical_ring_wait_for_space(struct intel_ringbuffer *ringbuf,
* case by choosing an insanely large timeout. */ * case by choosing an insanely large timeout. */
end = jiffies + 60 * HZ; end = jiffies + 60 * HZ;
do {
ringbuf->space = intel_ring_space(ringbuf);
if (ringbuf->space >= bytes) {
ret = 0; ret = 0;
do {
if (intel_ring_space(ringbuf) >= bytes)
break; break;
}
msleep(1); msleep(1);
...@@ -1035,7 +1024,7 @@ static int logical_ring_wrap_buffer(struct intel_ringbuffer *ringbuf) ...@@ -1035,7 +1024,7 @@ static int logical_ring_wrap_buffer(struct intel_ringbuffer *ringbuf)
iowrite32(MI_NOOP, virt++); iowrite32(MI_NOOP, virt++);
ringbuf->tail = 0; ringbuf->tail = 0;
ringbuf->space = intel_ring_space(ringbuf); intel_ring_update_space(ringbuf);
return 0; return 0;
} }
...@@ -1885,8 +1874,8 @@ int intel_lr_context_deferred_create(struct intel_context *ctx, ...@@ -1885,8 +1874,8 @@ int intel_lr_context_deferred_create(struct intel_context *ctx,
ringbuf->effective_size = ringbuf->size; ringbuf->effective_size = ringbuf->size;
ringbuf->head = 0; ringbuf->head = 0;
ringbuf->tail = 0; ringbuf->tail = 0;
ringbuf->space = ringbuf->size;
ringbuf->last_retired_head = -1; ringbuf->last_retired_head = -1;
intel_ring_update_space(ringbuf);
if (ringbuf->obj == NULL) { if (ringbuf->obj == NULL) {
ret = intel_alloc_ringbuffer_obj(dev, ringbuf); ret = intel_alloc_ringbuffer_obj(dev, ringbuf);
......
...@@ -58,12 +58,23 @@ int __intel_ring_space(int head, int tail, int size) ...@@ -58,12 +58,23 @@ int __intel_ring_space(int head, int tail, int size)
return space - I915_RING_FREE_SPACE; return space - I915_RING_FREE_SPACE;
} }
int intel_ring_space(struct intel_ringbuffer *ringbuf) void intel_ring_update_space(struct intel_ringbuffer *ringbuf)
{ {
return __intel_ring_space(ringbuf->head & HEAD_ADDR, if (ringbuf->last_retired_head != -1) {
ringbuf->head = ringbuf->last_retired_head;
ringbuf->last_retired_head = -1;
}
ringbuf->space = __intel_ring_space(ringbuf->head & HEAD_ADDR,
ringbuf->tail, ringbuf->size); ringbuf->tail, ringbuf->size);
} }
int intel_ring_space(struct intel_ringbuffer *ringbuf)
{
intel_ring_update_space(ringbuf);
return ringbuf->space;
}
bool intel_ring_stopped(struct intel_engine_cs *ring) bool intel_ring_stopped(struct intel_engine_cs *ring)
{ {
struct drm_i915_private *dev_priv = ring->dev->dev_private; struct drm_i915_private *dev_priv = ring->dev->dev_private;
...@@ -589,10 +600,10 @@ static int init_ring_common(struct intel_engine_cs *ring) ...@@ -589,10 +600,10 @@ static int init_ring_common(struct intel_engine_cs *ring)
goto out; goto out;
} }
ringbuf->last_retired_head = -1;
ringbuf->head = I915_READ_HEAD(ring); ringbuf->head = I915_READ_HEAD(ring);
ringbuf->tail = I915_READ_TAIL(ring) & TAIL_ADDR; ringbuf->tail = I915_READ_TAIL(ring) & TAIL_ADDR;
ringbuf->space = intel_ring_space(ringbuf); intel_ring_update_space(ringbuf);
ringbuf->last_retired_head = -1;
memset(&ring->hangcheck, 0, sizeof(ring->hangcheck)); memset(&ring->hangcheck, 0, sizeof(ring->hangcheck));
...@@ -1901,14 +1912,8 @@ static int intel_ring_wait_request(struct intel_engine_cs *ring, int n) ...@@ -1901,14 +1912,8 @@ static int intel_ring_wait_request(struct intel_engine_cs *ring, int n)
struct drm_i915_gem_request *request; struct drm_i915_gem_request *request;
int ret; int ret;
if (ringbuf->last_retired_head != -1) { if (intel_ring_space(ringbuf) >= n)
ringbuf->head = ringbuf->last_retired_head;
ringbuf->last_retired_head = -1;
ringbuf->space = intel_ring_space(ringbuf);
if (ringbuf->space >= n)
return 0; return 0;
}
list_for_each_entry(request, &ring->request_list, list) { list_for_each_entry(request, &ring->request_list, list) {
if (__intel_ring_space(request->tail, ringbuf->tail, if (__intel_ring_space(request->tail, ringbuf->tail,
...@@ -1925,10 +1930,7 @@ static int intel_ring_wait_request(struct intel_engine_cs *ring, int n) ...@@ -1925,10 +1930,7 @@ static int intel_ring_wait_request(struct intel_engine_cs *ring, int n)
return ret; return ret;
i915_gem_retire_requests_ring(ring); i915_gem_retire_requests_ring(ring);
ringbuf->head = ringbuf->last_retired_head;
ringbuf->last_retired_head = -1;
ringbuf->space = intel_ring_space(ringbuf);
return 0; return 0;
} }
...@@ -1954,14 +1956,14 @@ static int ring_wait_for_space(struct intel_engine_cs *ring, int n) ...@@ -1954,14 +1956,14 @@ static int ring_wait_for_space(struct intel_engine_cs *ring, int n)
* case by choosing an insanely large timeout. */ * case by choosing an insanely large timeout. */
end = jiffies + 60 * HZ; end = jiffies + 60 * HZ;
ret = 0;
trace_i915_ring_wait_begin(ring); trace_i915_ring_wait_begin(ring);
do { do {
if (intel_ring_space(ringbuf) >= n)
break;
ringbuf->head = I915_READ_HEAD(ring); ringbuf->head = I915_READ_HEAD(ring);
ringbuf->space = intel_ring_space(ringbuf); if (intel_ring_space(ringbuf) >= n)
if (ringbuf->space >= n) {
ret = 0;
break; break;
}
msleep(1); msleep(1);
...@@ -2002,7 +2004,7 @@ static int intel_wrap_ring_buffer(struct intel_engine_cs *ring) ...@@ -2002,7 +2004,7 @@ static int intel_wrap_ring_buffer(struct intel_engine_cs *ring)
iowrite32(MI_NOOP, virt++); iowrite32(MI_NOOP, virt++);
ringbuf->tail = 0; ringbuf->tail = 0;
ringbuf->space = intel_ring_space(ringbuf); intel_ring_update_space(ringbuf);
return 0; return 0;
} }
......
...@@ -407,6 +407,7 @@ static inline void intel_ring_advance(struct intel_engine_cs *ring) ...@@ -407,6 +407,7 @@ static inline void intel_ring_advance(struct intel_engine_cs *ring)
ringbuf->tail &= ringbuf->size - 1; ringbuf->tail &= ringbuf->size - 1;
} }
int __intel_ring_space(int head, int tail, int size); int __intel_ring_space(int head, int tail, int size);
void intel_ring_update_space(struct intel_ringbuffer *ringbuf);
int intel_ring_space(struct intel_ringbuffer *ringbuf); int intel_ring_space(struct intel_ringbuffer *ringbuf);
bool intel_ring_stopped(struct intel_engine_cs *ring); bool intel_ring_stopped(struct intel_engine_cs *ring);
void __intel_ring_advance(struct intel_engine_cs *ring); void __intel_ring_advance(struct intel_engine_cs *ring);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment