[Intel-gfx] [PATCH 3/3] drm/i915: Add soft-pinning API for execbuffer
Chris Wilson
chris at chris-wilson.co.uk
Thu May 15 17:55:27 CEST 2014
Userspace can pass in an offset that it presumes the object is located
at. The kernel will then do its utmost to fit the object into that
location. The assumption is that userspace is handling its own object
locations (for example along with full-ppgtt) and that the kernel will
rarely have to make space for the user's requests.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
drivers/gpu/drm/i915/i915_drv.h | 3 ++
drivers/gpu/drm/i915/i915_gem.c | 50 ++++++++++++++++++++--------
drivers/gpu/drm/i915/i915_gem_evict.c | 52 ++++++++++++++++++++++++++++++
drivers/gpu/drm/i915/i915_gem_execbuffer.c | 9 ++++--
include/uapi/drm/i915_drm.h | 3 +-
5 files changed, 100 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 64a1b2340e3a..04fe312df8e4 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2406,6 +2406,9 @@ int __must_check i915_gem_evict_something(struct drm_device *dev,
unsigned long start,
unsigned long end,
unsigned flags);
+int __must_check
+i915_gem_evict_range(struct drm_device *dev, struct i915_address_space *vm,
+ unsigned long start, unsigned long end);
int i915_gem_evict_vm(struct i915_address_space *vm, bool do_idle);
int i915_gem_evict_everything(struct drm_device *dev);
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 79244b911125..ba4f266b5f2e 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -3313,22 +3313,43 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj,
if (IS_ERR(vma))
goto err_unpin;
+ if (flags & PIN_OFFSET_FIXED) {
+ uint64_t offset = flags & PIN_OFFSET_MASK;
+ if (alignment && offset & (alignment - 1)) {
+ vma = ERR_PTR(-EINVAL);
+ goto err_free_vma;
+ }
+ vma->node.start = offset;
+ vma->node.size = size;
+ vma->node.color = obj->cache_level;
+ ret = drm_mm_reserve_node(&vm->mm, &vma->node);
+ if (ret) {
+ ret = i915_gem_evict_range(dev, vm, start, end);
+ if (ret == 0)
+ ret = drm_mm_reserve_node(&vm->mm, &vma->node);
+ }
+ if (ret) {
+ vma = ERR_PTR(ret);
+ goto err_free_vma;
+ }
+ } else {
search_free:
- ret = drm_mm_insert_node_in_range_generic(&vm->mm, &vma->node,
- size, alignment,
- obj->cache_level,
- start, end,
- DRM_MM_SEARCH_DEFAULT,
- DRM_MM_CREATE_DEFAULT);
- if (ret) {
- ret = i915_gem_evict_something(dev, vm, size, alignment,
- obj->cache_level,
- start, end,
- flags);
- if (ret == 0)
- goto search_free;
+ ret = drm_mm_insert_node_in_range_generic(&vm->mm, &vma->node,
+ size, alignment,
+ obj->cache_level,
+ start, end,
+ DRM_MM_SEARCH_DEFAULT,
+ DRM_MM_CREATE_DEFAULT);
+ if (ret) {
+ ret = i915_gem_evict_something(dev, vm, size, alignment,
+ obj->cache_level,
+ start, end,
+ flags);
+ if (ret == 0)
+ goto search_free;
- goto err_free_vma;
+ goto err_free_vma;
+ }
}
if (WARN_ON(!i915_gem_valid_gtt_space(dev, &vma->node,
obj->cache_level))) {
@@ -3911,6 +3932,7 @@ i915_gem_object_pin(struct drm_i915_gem_object *obj,
if ((alignment &&
vma->node.start & (alignment - 1)) ||
(flags & PIN_MAPPABLE && !obj->map_and_fenceable) ||
+ (flags & PIN_OFFSET_FIXED && vma->node.start != (flags & PIN_OFFSET_MASK)) ||
(flags & PIN_OFFSET_BIAS && vma->node.start < (flags & PIN_OFFSET_MASK))) {
WARN(vma->pin_count,
"bo is already pinned with incorrect alignment:"
diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index bbf4b12d842e..bd3020afd363 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -194,6 +194,58 @@ found:
return ret;
}
+int
+i915_gem_evict_range(struct drm_device *dev, struct i915_address_space *vm,
+ unsigned long start, unsigned long end)
+{
+ struct drm_mm_node *node;
+ struct list_head eviction_list;
+ int ret = 0;
+
+ INIT_LIST_HEAD(&eviction_list);
+ drm_mm_for_each_node(node, &vm->mm) {
+ struct i915_vma *vma;
+
+ if (node->start + node->size <= start)
+ continue;
+ if (node->start >= end)
+ break;
+
+ vma = container_of(node, typeof(*vma), node);
+ if (vma->pin_count) {
+ ret = -EBUSY;
+ break;
+ }
+
+ if (WARN_ON(!list_empty(&vma->exec_list))) {
+ ret = -EINVAL;
+ break;
+ }
+
+ drm_gem_object_reference(&vma->obj->base);
+ list_add(&vma->exec_list, &eviction_list);
+ }
+
+ while (!list_empty(&eviction_list)) {
+ struct i915_vma *vma;
+ 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);
+ if (ret == 0)
+ ret = i915_vma_unbind(vma);
+
+ drm_gem_object_unreference(obj);
+ }
+
+ return ret;
+}
+
/**
* i915_gem_evict_vm - Evict all idle vmas from a vm
*
diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
index 15cb3825dfef..31130f14cb49 100644
--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
@@ -553,6 +553,8 @@ i915_gem_execbuffer_reserve_vma(struct i915_vma *vma,
flags |= PIN_GLOBAL;
if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS)
flags |= BIAS | PIN_OFFSET_BIAS;
+ if (entry->flags & EXEC_OBJECT_PINNED)
+ flags |= entry->offset | PIN_OFFSET_FIXED;
ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags);
if (ret)
@@ -677,6 +679,7 @@ i915_gem_execbuffer_reserve(struct intel_ring_buffer *ring,
continue;
if ((entry->alignment && vma->node.start & (entry->alignment - 1)) ||
+ (entry->flags & EXEC_OBJECT_PINNED && vma->node.start != entry->offset) ||
(entry->flags & __EXEC_OBJECT_NEEDS_MAP && !obj->map_and_fenceable) ||
(entry->flags & __EXEC_OBJECT_NEEDS_BIAS && vma->node.start < BIAS))
ret = i915_vma_unbind(vma);
@@ -1045,8 +1048,10 @@ struct drm_i915_gem_object *
eb_get_batch(struct eb_vmas *eb)
{
struct i915_vma *vma = list_entry(eb->vmas.prev, typeof(*vma), exec_list);
- if (INTEL_INFO(vma->obj->base.dev)->gen >= 7)
- vma->exec_entry->flags |= __EXEC_OBJECT_NEEDS_BIAS;
+ if (INTEL_INFO(vma->obj->base.dev)->gen >= 7) {
+ if ((vma->exec_entry->flags & EXEC_OBJECT_PINNED) == 0)
+ vma->exec_entry->flags |= __EXEC_OBJECT_NEEDS_BIAS;
+ }
return vma->obj;
}
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
index 8a3e4ef00c3d..310fb2b602c7 100644
--- a/include/uapi/drm/i915_drm.h
+++ b/include/uapi/drm/i915_drm.h
@@ -660,7 +660,8 @@ struct drm_i915_gem_exec_object2 {
#define EXEC_OBJECT_NEEDS_FENCE (1<<0)
#define EXEC_OBJECT_NEEDS_GTT (1<<1)
#define EXEC_OBJECT_WRITE (1<<2)
-#define __EXEC_OBJECT_UNKNOWN_FLAGS -(EXEC_OBJECT_WRITE<<1)
+#define EXEC_OBJECT_PINNED (1<<4)
+#define __EXEC_OBJECT_UNKNOWN_FLAGS -(EXEC_OBJECT_PINNED<<1)
__u64 flags;
__u64 rsvd1;
--
2.0.0.rc2
More information about the Intel-gfx
mailing list