Commit 0108a3ed authored by Daniel Vetter's avatar Daniel Vetter Committed by Eric Anholt

drm/i915: prepare for fair lru eviction

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: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarEric Anholt <eric@anholt.net>
parent bf1a1092
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <linux/swap.h> #include <linux/swap.h>
#include <linux/pci.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 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_gtt_write_domain(struct drm_gem_object *obj);
static void i915_gem_object_flush_cpu_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); ...@@ -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, static int i915_gem_object_bind_to_gtt(struct drm_gem_object *obj,
unsigned alignment); unsigned alignment);
static void i915_gem_clear_fence_reg(struct drm_gem_object *obj); 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_evict_from_inactive_list(struct drm_device *dev);
static int i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj, static int i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
struct drm_i915_gem_pwrite *args, struct drm_i915_gem_pwrite *args,
...@@ -313,7 +315,8 @@ i915_gem_object_get_pages_or_evict(struct drm_gem_object *obj) ...@@ -313,7 +315,8 @@ i915_gem_object_get_pages_or_evict(struct drm_gem_object *obj)
if (ret == -ENOMEM) { if (ret == -ENOMEM) {
struct drm_device *dev = obj->dev; 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) if (ret)
return ret; return ret;
...@@ -2005,10 +2008,12 @@ i915_gem_object_unbind(struct drm_gem_object *obj) ...@@ -2005,10 +2008,12 @@ i915_gem_object_unbind(struct drm_gem_object *obj)
return ret; return ret;
} }
static struct drm_gem_object * static int
i915_gem_find_inactive_object(struct drm_device *dev, int min_size) 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; drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_gem_object *obj;
struct drm_i915_gem_object *obj_priv; struct drm_i915_gem_object *obj_priv;
struct drm_gem_object *best = NULL; struct drm_gem_object *best = NULL;
struct drm_gem_object *first = NULL; struct drm_gem_object *first = NULL;
...@@ -2022,14 +2027,31 @@ i915_gem_find_inactive_object(struct drm_device *dev, int min_size) ...@@ -2022,14 +2027,31 @@ i915_gem_find_inactive_object(struct drm_device *dev, int min_size)
(!best || obj->size < best->size)) { (!best || obj->size < best->size)) {
best = obj; best = obj;
if (best->size == min_size) if (best->size == min_size)
return best; break;
} }
if (!first) if (!first)
first = obj; 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 static int
...@@ -2115,11 +2137,11 @@ i915_gem_evict_everything(struct drm_device *dev) ...@@ -2115,11 +2137,11 @@ i915_gem_evict_everything(struct drm_device *dev)
} }
static int 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; drm_i915_private_t *dev_priv = dev->dev_private;
struct drm_gem_object *obj; int ret, found;
int ret;
struct intel_ring_buffer *render_ring = &dev_priv->render_ring; struct intel_ring_buffer *render_ring = &dev_priv->render_ring;
struct intel_ring_buffer *bsd_ring = &dev_priv->bsd_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) ...@@ -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 /* If there's an inactive buffer available now, grab it
* and be done. * and be done.
*/ */
obj = i915_gem_find_inactive_object(dev, min_size); ret = i915_gem_scan_inactive_list_and_evict(dev, min_size,
if (obj) { alignment,
struct drm_i915_gem_object *obj_priv; &found);
if (found)
#if WATCH_LRU return ret;
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);
}
/* If we didn't get anything, but the ring is still processing /* If we didn't get anything, but the ring is still processing
* things, wait for the next to finish and hopefully leave us * 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) ...@@ -2184,6 +2197,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size)
* will get moved to inactive. * will get moved to inactive.
*/ */
if (!list_empty(&dev_priv->mm.flushing_list)) { if (!list_empty(&dev_priv->mm.flushing_list)) {
struct drm_gem_object *obj = NULL;
struct drm_i915_gem_object *obj_priv; struct drm_i915_gem_object *obj_priv;
/* Find an object that we can immediately reuse */ /* 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) ...@@ -2661,7 +2675,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
#if WATCH_LRU #if WATCH_LRU
DRM_INFO("%s: GTT full, evicting something\n", __func__); DRM_INFO("%s: GTT full, evicting something\n", __func__);
#endif #endif
ret = i915_gem_evict_something(dev, obj->size); ret = i915_gem_evict_something(dev, obj->size, alignment);
if (ret) if (ret)
return ret; return ret;
...@@ -2679,7 +2693,8 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment) ...@@ -2679,7 +2693,8 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
if (ret == -ENOMEM) { if (ret == -ENOMEM) {
/* first try to clear up some space from the GTT */ /* 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) { if (ret) {
/* now try to shrink everyone else */ /* now try to shrink everyone else */
if (gfpmask) { if (gfpmask) {
...@@ -2709,7 +2724,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment) ...@@ -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); drm_mm_put_block(obj_priv->gtt_space);
obj_priv->gtt_space = NULL; obj_priv->gtt_space = NULL;
ret = i915_gem_evict_something(dev, obj->size); ret = i915_gem_evict_something(dev, obj->size, alignment);
if (ret) if (ret)
return ret; return ret;
......
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