All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 02/20] drm/i915: prepare for fair lru eviction
Date: Sat,  7 Aug 2010 11:01:21 +0100	[thread overview]
Message-ID: <1281175299-1379-3-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1281175299-1379-1-git-send-email-chris@chris-wilson.co.uk>

From: Daniel Vetter <daniel.vetter@ffwll.ch>

This does two little changes:

- Add an alignment parameter for evict_something. It's not really great to
  whack a carefully sized hole into the gtt with the wrong alignment.
  Especially since the fallback path is a full evict.

- With the inactive scan stuff we need to evict more that one object, so
  move the unbind call into the helper function that scans for the object
  to be evicted, too.  And adjust its name.

No functional changes in this patch, just preparation.

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c |   67 ++++++++++++++++++++++++---------------
 1 files changed, 41 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 75e7b89..f150bfd 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -35,6 +35,7 @@
 #include <linux/swap.h>
 #include <linux/pci.h>
 
+static uint32_t i915_gem_get_gtt_alignment(struct drm_gem_object *obj);
 static int i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj);
 static void i915_gem_object_flush_gtt_write_domain(struct drm_gem_object *obj);
 static void i915_gem_object_flush_cpu_write_domain(struct drm_gem_object *obj);
@@ -48,7 +49,8 @@ static int i915_gem_object_wait_rendering(struct drm_gem_object *obj);
 static int i915_gem_object_bind_to_gtt(struct drm_gem_object *obj,
 					   unsigned alignment);
 static void i915_gem_clear_fence_reg(struct drm_gem_object *obj);
-static int i915_gem_evict_something(struct drm_device *dev, int min_size);
+static int i915_gem_evict_something(struct drm_device *dev, int min_size,
+				    unsigned alignment);
 static int i915_gem_evict_from_inactive_list(struct drm_device *dev);
 static int i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
 				struct drm_i915_gem_pwrite *args,
@@ -313,7 +315,8 @@ i915_gem_object_get_pages_or_evict(struct drm_gem_object *obj)
 	if (ret == -ENOMEM) {
 		struct drm_device *dev = obj->dev;
 
-		ret = i915_gem_evict_something(dev, obj->size);
+		ret = i915_gem_evict_something(dev, obj->size,
+					       i915_gem_get_gtt_alignment(obj));
 		if (ret)
 			return ret;
 
@@ -2005,10 +2008,12 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
 	return ret;
 }
 
-static struct drm_gem_object *
-i915_gem_find_inactive_object(struct drm_device *dev, int min_size)
+static int
+i915_gem_scan_inactive_list_and_evict(struct drm_device *dev, int min_size,
+				      unsigned alignment, int *found)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct drm_gem_object *obj;
 	struct drm_i915_gem_object *obj_priv;
 	struct drm_gem_object *best = NULL;
 	struct drm_gem_object *first = NULL;
@@ -2022,14 +2027,31 @@ i915_gem_find_inactive_object(struct drm_device *dev, int min_size)
 			    (!best || obj->size < best->size)) {
 				best = obj;
 				if (best->size == min_size)
-					return best;
+					break;
 			}
 			if (!first)
 			    first = obj;
 		}
 	}
 
-	return best ? best : first;
+	obj = best ? best : first;
+
+	if (!obj) {
+		*found = 0;
+		return 0;
+	}
+
+	*found = 1;
+
+#if WATCH_LRU
+	DRM_INFO("%s: evicting %p\n", __func__, obj);
+#endif
+	obj_priv = to_intel_bo(obj);
+	BUG_ON(obj_priv->pin_count != 0);
+	BUG_ON(obj_priv->active);
+
+	/* Wait on the rendering and unbind the buffer. */
+	return i915_gem_object_unbind(obj);
 }
 
 static int
@@ -2115,11 +2137,11 @@ i915_gem_evict_everything(struct drm_device *dev)
 }
 
 static int
-i915_gem_evict_something(struct drm_device *dev, int min_size)
+i915_gem_evict_something(struct drm_device *dev,
+			 int min_size, unsigned alignment)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
-	struct drm_gem_object *obj;
-	int ret;
+	int ret, found;
 
 	struct intel_ring_buffer *render_ring = &dev_priv->render_ring;
 	struct intel_ring_buffer *bsd_ring = &dev_priv->bsd_ring;
@@ -2129,20 +2151,11 @@ i915_gem_evict_something(struct drm_device *dev, int min_size)
 		/* If there's an inactive buffer available now, grab it
 		 * and be done.
 		 */
-		obj = i915_gem_find_inactive_object(dev, min_size);
-		if (obj) {
-			struct drm_i915_gem_object *obj_priv;
-
-#if WATCH_LRU
-			DRM_INFO("%s: evicting %p\n", __func__, obj);
-#endif
-			obj_priv = to_intel_bo(obj);
-			BUG_ON(obj_priv->pin_count != 0);
-			BUG_ON(obj_priv->active);
-
-			/* Wait on the rendering and unbind the buffer. */
-			return i915_gem_object_unbind(obj);
-		}
+		ret = i915_gem_scan_inactive_list_and_evict(dev, min_size,
+							    alignment,
+							    &found);
+		if (found)
+			return ret;
 
 		/* If we didn't get anything, but the ring is still processing
 		 * things, wait for the next to finish and hopefully leave us
@@ -2184,6 +2197,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size)
 		 * will get moved to inactive.
 		 */
 		if (!list_empty(&dev_priv->mm.flushing_list)) {
+			struct drm_gem_object *obj = NULL;
 			struct drm_i915_gem_object *obj_priv;
 
 			/* Find an object that we can immediately reuse */
@@ -2661,7 +2675,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
 #if WATCH_LRU
 		DRM_INFO("%s: GTT full, evicting something\n", __func__);
 #endif
-		ret = i915_gem_evict_something(dev, obj->size);
+		ret = i915_gem_evict_something(dev, obj->size, alignment);
 		if (ret)
 			return ret;
 
@@ -2679,7 +2693,8 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
 
 		if (ret == -ENOMEM) {
 			/* first try to clear up some space from the GTT */
-			ret = i915_gem_evict_something(dev, obj->size);
+			ret = i915_gem_evict_something(dev, obj->size,
+						       alignment);
 			if (ret) {
 				/* now try to shrink everyone else */
 				if (gfpmask) {
@@ -2709,7 +2724,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
 		drm_mm_put_block(obj_priv->gtt_space);
 		obj_priv->gtt_space = NULL;
 
-		ret = i915_gem_evict_something(dev, obj->size);
+		ret = i915_gem_evict_something(dev, obj->size, alignment);
 		if (ret)
 			return ret;
 
-- 
1.7.1

  parent reply	other threads:[~2010-08-07 10:03 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-07 10:01 Rebased series on drm-intel-next Chris Wilson
2010-08-07 10:01 ` [PATCH 01/20] drm/i915: Append the object onto the inactive list on binding Chris Wilson
2010-08-07 10:01 ` Chris Wilson [this message]
2010-08-07 10:01 ` [PATCH 03/20] drm/i915: Use a common seqno for all rings Chris Wilson
2010-08-07 10:01 ` [PATCH 04/20] drm/i915: Move the eviction logic to its own file Chris Wilson
2010-08-07 10:01 ` [PATCH 05/20] drm/i915: Implement fair lru eviction across both rings. (v2) Chris Wilson
2010-08-07 10:01 ` [PATCH 06/20] drm/i915: Maintain LRU order of inactive objects upon access by CPU Chris Wilson
2010-08-07 19:34   ` Daniel Vetter
2010-08-07 20:45     ` [PATCH] drm/i915: Maintain LRU order of inactive objects upon access by CPU (v2) Chris Wilson
2010-08-07 10:01 ` [PATCH 07/20] drm/i915: Record error batch buffers using iomem Chris Wilson
2010-08-07 10:01 ` [PATCH 08/20] drm/i915/sdvo: Markup a few constant strings Chris Wilson
2010-08-07 10:01 ` [PATCH 09/20] drm/i915: Enable aspect/centering panel fitting for Ironlake Chris Wilson
2010-08-07 10:01 ` [PATCH 10/20] drm/i915: Write to display base last Chris Wilson
2010-08-07 10:01 ` [PATCH 11/20] drm/i915: Truncate the shmem backing pages on purge Chris Wilson
2010-08-07 10:01 ` [PATCH 12/20] drm/i915/display: Add pipe/plane information to dpms debugging Chris Wilson
2010-08-07 10:01 ` [PATCH 13/20] drm/i915/opregion: Use ASLE response codes defined in 0.1 Chris Wilson
2010-08-07 10:01 ` [PATCH 14/20] drm/i915: Update watermarks for Ironlake after dpms changes Chris Wilson
2010-08-07 10:01 ` [PATCH 15/20] drm/i915/ringbuffer: Set ring->gem_buffer = NULL on init unwind Chris Wilson
2010-08-07 10:01 ` [PATCH 16/20] drm/i915: Ensure that while(INREG()) are bounded (v2) Chris Wilson
2010-09-21 14:22   ` Carlos R. Mafra
2010-09-21 14:35     ` Chris Wilson
2010-09-21 15:55       ` Jesse Barnes
2010-09-22  8:32         ` Carlos R. Mafra
2010-09-22  8:43           ` Chris Wilson
2010-09-22 10:48             ` Carlos R. Mafra
2010-09-22 10:57               ` Chris Wilson
2010-09-22 13:42                 ` Carlos R. Mafra
2010-09-22 14:29                   ` Chris Wilson
2010-09-22 15:26                     ` Carlos R. Mafra
2010-09-22 15:47                       ` Chris Wilson
2010-08-07 10:01 ` [PATCH 17/20] drm/i915/edp: Flush the write before waiting for PLLs Chris Wilson
2010-08-07 10:01 ` [PATCH 18/20] drm/i915: FBC is updated within set_base() so remove second call in mode_set() Chris Wilson
2010-08-07 10:01 ` [PATCH 19/20] drm/i915: Only update i845/i865 CURBASE when disabled (v2) Chris Wilson
2010-08-07 10:01 ` [PATCH 20/20] drm/i915: Apply i830 errata for cursor alignment Chris Wilson
2010-08-08 18:31   ` Eric Anholt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1281175299-1379-3-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.