[Intel-gfx] [PATCH 169/190] drm/i915: Use vma->exec_entry as our double-entry placeholder
Chris Wilson
chris at chris-wilson.co.uk
Mon Jan 11 03:01:10 PST 2016
This has the benefit of not requiring us to manipulate the
vma->exec_link list when tearing down the execbuffer, and is a
marginally cheaper test to detect the user error.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_gem_evict.c | 23 +++-------
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 73 ++++++++++++++++--------------
drivers/gpu/drm/i915/i915_gem_gtt.c | 1 -
3 files changed, 46 insertions(+), 51 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index b48839fc2996..d40bcb81c922 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -69,9 +69,6 @@ mark_free(struct i915_vma *vma, unsigned flags, struct list_head *unwind)
if (vma->pin_count)
return false;
- if (WARN_ON(!list_empty(&vma->exec_list)))
- return false;
-
if (flags & PIN_NOFAULT && vma->obj->fault_mappable)
return false;
@@ -161,7 +158,7 @@ search_again:
ret = drm_mm_scan_remove_block(&vma->node);
BUG_ON(ret);
- list_del_init(&vma->exec_list);
+ list_del(&vma->exec_list);
}
/* Can we unpin some objects such as idle hw contents,
@@ -208,22 +205,16 @@ found:
if (drm_mm_scan_remove_block(&vma->node))
drm_gem_object_reference(&vma->obj->base);
else
- list_del_init(&vma->exec_list);
+ list_del(&vma->exec_list);
}
/* Unbinding will emit any required flushes */
- while (!list_empty(&eviction_list)) {
- struct drm_gem_object *obj;
- vma = list_first_entry(&eviction_list,
- struct i915_vma,
- exec_list);
-
- obj = &vma->obj->base;
- list_del_init(&vma->exec_list);
+ ret = 0;
+ list_for_each_entry_safe(vma, next, &eviction_list, exec_list) {
+ struct drm_i915_gem_object *obj = vma->obj;
if (ret == 0)
ret = i915_vma_unbind(vma);
-
- drm_gem_object_unreference(obj);
+ drm_gem_object_unreference(&obj->base);
}
return ret;
}
@@ -277,7 +268,7 @@ i915_gem_evict_for_vma(struct i915_vma *target, unsigned flags)
ret = 0;
list_for_each_entry_safe(vma, next, &eviction_list, exec_list) {
struct drm_i915_gem_object *obj = vma->obj;
- list_del_init(&vma->exec_list);
+ list_del(&vma->exec_list);
if (ret == 0)
ret = i915_vma_unbind(vma);
drm_gem_object_unreference(&obj->base);
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 7d758610a095..af55d56ec00a 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -95,13 +95,38 @@ eb_create(struct i915_execbuffer *eb)
} else
eb->and = -eb->args->buffer_count;
- INIT_LIST_HEAD(&eb->vmas);
return 0;
}
+static inline void
+__eb_unreserve_vma(struct i915_vma *vma,
+ const struct drm_i915_gem_exec_object2 *entry)
+{
+ if (unlikely(entry->flags & __EXEC_OBJECT_HAS_FENCE))
+ i915_vma_unpin_fence(vma);
+
+ if (entry->flags & __EXEC_OBJECT_HAS_PIN)
+ __i915_vma_unpin(vma);
+}
+
+static void
+eb_unreserve_vma(struct i915_vma *vma)
+{
+ struct drm_i915_gem_exec_object2 *entry = vma->exec_entry;
+ __eb_unreserve_vma(vma, entry);
+ entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN);
+}
+
static void
eb_reset(struct i915_execbuffer *eb)
{
+ struct i915_vma *vma;
+
+ list_for_each_entry(vma, &eb->vmas, exec_list) {
+ eb_unreserve_vma(vma);
+ vma->exec_entry = NULL;
+ }
+
if (eb->and >= 0)
memset(eb->buckets, 0, (eb->and+1)*sizeof(struct hlist_head));
}
@@ -133,6 +158,8 @@ eb_lookup_vmas(struct i915_execbuffer *eb)
struct list_head objects;
int i, ret;
+ INIT_LIST_HEAD(&eb->vmas);
+
INIT_LIST_HEAD(&objects);
spin_lock(&eb->file->table_lock);
/* Grab a reference to the object and release the lock so we can lookup
@@ -241,36 +268,20 @@ static struct i915_vma *eb_get_vma(struct i915_execbuffer *eb, unsigned long han
}
}
-static void
-eb_unreserve_vma(struct i915_vma *vma)
-{
- struct drm_i915_gem_exec_object2 *entry;
-
- if (!drm_mm_node_allocated(&vma->node))
- return;
-
- entry = vma->exec_entry;
-
- if (entry->flags & __EXEC_OBJECT_HAS_FENCE)
- i915_vma_unpin_fence(vma);
-
- if (entry->flags & __EXEC_OBJECT_HAS_PIN)
- __i915_vma_unpin(vma);
-
- entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN);
-}
-
static void eb_destroy(struct i915_execbuffer *eb)
{
- while (!list_empty(&eb->vmas)) {
- struct i915_vma *vma;
+ struct i915_vma *vma;
- vma = list_first_entry(&eb->vmas,
- struct i915_vma,
- exec_list);
- list_del_init(&vma->exec_list);
- eb_unreserve_vma(vma);
+ list_for_each_entry(vma, &eb->vmas, exec_list) {
+ if (vma->exec_entry == NULL)
+ continue;
+
+ __eb_unreserve_vma(vma, vma->exec_entry);
+ vma->exec_entry = NULL;
}
+
+ if (eb->buckets)
+ kfree(eb->buckets);
}
static inline int use_cpu_reloc(struct drm_i915_gem_object *obj)
@@ -936,12 +947,7 @@ eb_relocate_slow(struct i915_execbuffer *eb)
int i, total, ret;
/* We may process another execbuffer during the unlock... */
- while (!list_empty(&eb->vmas)) {
- vma = list_first_entry(&eb->vmas, struct i915_vma, exec_list);
- list_del_init(&vma->exec_list);
- eb_unreserve_vma(vma);
- }
-
+ eb_reset(eb);
mutex_unlock(&dev->struct_mutex);
total = 0;
@@ -1006,7 +1012,6 @@ eb_relocate_slow(struct i915_execbuffer *eb)
goto err;
/* reacquire the objects */
- eb_reset(eb);
ret = eb_lookup_vmas(eb);
if (ret)
goto err;
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index faee28c807f2..cb3a6e272e22 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -3254,7 +3254,6 @@ __i915_gem_vma_create(struct drm_i915_gem_object *obj,
if (vma == NULL)
return ERR_PTR(-ENOMEM);
- INIT_LIST_HEAD(&vma->exec_list);
for (i = 0; i < ARRAY_SIZE(vma->last_read); i++)
init_request_active(&vma->last_read[i], i915_vma_retire);
init_request_active(&vma->last_fence, i915_vma_retire__fence);
--
2.7.0.rc3
More information about the Intel-gfx
mailing list