From eaaaa2c41fbb8663d5158183449b202367373954 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Wed, 1 Feb 2012 21:29:31 +0000 Subject: [PATCH 2/2] drm/i915: Record the tail of each request and use it to estimate the head Signed-off-by: Chris Wilson --- drivers/gpu/drm/i915/i915_drv.h | 3 +++ drivers/gpu/drm/i915/i915_gem.c | 10 ++++++---- drivers/gpu/drm/i915/intel_ringbuffer.c | 11 +++++++++++ drivers/gpu/drm/i915/intel_ringbuffer.h | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 4ee0793..b26e951 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -945,6 +945,9 @@ struct drm_i915_gem_request { /** GEM sequence number associated with this request. */ uint32_t seqno; + /** Postion in the ringbuffer of the start of the request */ + u32 acthd; + /** Time at which this request was emitted, in jiffies. */ unsigned long emitted_jiffies; diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index ff998ce..900a93c 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -1785,19 +1785,20 @@ i915_add_request(struct intel_ring_buffer *ring, drm_i915_private_t *dev_priv = ring->dev->dev_private; uint32_t seqno; int was_empty; - int ret; + int acthd; BUG_ON(request == NULL); seqno = i915_gem_next_request_seqno(ring); - ret = ring->add_request(ring, seqno); - if (ret < 0) - return ret; + acthd = ring->add_request(ring, seqno); + if (acthd < 0) + return acthd; trace_i915_gem_request_add(ring, seqno); request->seqno = seqno; request->ring = ring; + request->acthd = acthd; request->emitted_jiffies = jiffies; was_empty = list_empty(&ring->request_list); list_add_tail(&request->list, &ring->request_list); @@ -1962,6 +1963,7 @@ i915_gem_retire_requests_ring(struct intel_ring_buffer *ring) break; trace_i915_gem_request_retire(ring, request->seqno); + ring->last_retired_head = request->acthd; list_del(&request->list); i915_gem_request_remove_from_client(request); diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c index e53dd2d..255245b 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.c +++ b/drivers/gpu/drm/i915/intel_ringbuffer.c @@ -1058,6 +1058,17 @@ int intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n) struct drm_i915_private *dev_priv = dev->dev_private; unsigned long end; + i915_gem_retire_requests(dev); + + if (ring->last_retired_head) { + ring->head = ring->last_retired_head; + ring->last_retired_head = 0; + + ring->space = ring_space(ring); + if (ring->space >= n) + return 0; + } + trace_i915_ring_wait_begin(ring); if (drm_core_check_feature(dev, DRIVER_GEM)) /* With GEM the hangcheck timer should kick us out of the loop, diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h index e1ded68..1921ce8 100644 --- a/drivers/gpu/drm/i915/intel_ringbuffer.h +++ b/drivers/gpu/drm/i915/intel_ringbuffer.h @@ -46,6 +46,8 @@ struct intel_ring_buffer { int effective_size; struct intel_hw_status_page status_page; + u32 last_retired_head; + spinlock_t irq_lock; u32 irq_refcount; u32 irq_mask; -- 1.7.8.3