[PATCH 09/11] drm/i915: dont perform a ttm move if creating in place
Robert Beckett
bob.beckett at collabora.com
Mon Mar 21 20:28:29 UTC 2022
skip moving if we create the buffer in place
Signed-off-by: Robert Beckett <bob.beckett at collabora.com>
---
drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 40 +++++++++++++++++++++----
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index b26bde6a4bb9..ce09eb4aca0d 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -1136,7 +1136,8 @@ static int __i915_gem_ttm_object_init_with_placement(struct intel_memory_region
resource_size_t size,
resource_size_t page_size,
unsigned int flags,
- struct ttm_placement *placement)
+ struct ttm_placement *placement,
+ bool allow_move)
{
static struct lock_class_key lock_class;
struct drm_i915_private *i915 = mem->i915;
@@ -1145,6 +1146,8 @@ static int __i915_gem_ttm_object_init_with_placement(struct intel_memory_region
.no_wait_gpu = false,
};
enum ttm_bo_type bo_type;
+ struct ttm_buffer_object * ttm_bo = i915_gem_to_ttm(obj);
+ struct ttm_placement *init_placement = placement;
int ret;
drm_gem_private_object_init(&i915->drm, &obj->base, size);
@@ -1159,7 +1162,16 @@ static int __i915_gem_ttm_object_init_with_placement(struct intel_memory_region
bo_type = (obj->flags & I915_BO_ALLOC_USER) ? ttm_bo_type_device :
ttm_bo_type_kernel;
- obj->base.vma_node.driver_private = i915_gem_to_ttm(obj);
+ obj->base.vma_node.driver_private = ttm_bo;
+
+ /*
+ * default ttm behaviour is to allocate in system, then move the buffer
+ * to the desired placement. If !allow_move, we allocate in system so that it
+ * does not move the buffer, then directly replace the resource with one
+ * allocted from the desired placement.
+ */
+ if (!allow_move)
+ init_placement = &i915_sys_placement;
/* Forcing the page size is kernel internal only */
GEM_BUG_ON(page_size && obj->mm.n_placements);
@@ -1179,13 +1191,22 @@ static int __i915_gem_ttm_object_init_with_placement(struct intel_memory_region
* Similarly, in delayed_destroy, we can't call ttm_bo_put()
* until successful initialization.
*/
- ret = ttm_bo_init_reserved(&i915->bdev, i915_gem_to_ttm(obj), size,
- bo_type, placement,
+ ret = ttm_bo_init_reserved(&i915->bdev, ttm_bo, size,
+ bo_type, init_placement,
page_size >> PAGE_SHIFT,
&ctx, NULL, NULL, i915_ttm_bo_destroy);
if (ret)
return i915_ttm_err_to_gem(ret);
+ if (!allow_move) {
+ struct ttm_resource *res;
+ ret = ttm_bo_mem_space(ttm_bo, placement, &res, &ctx);
+ if (ret)
+ goto err_res;
+ ttm_resource_free(ttm_bo, &ttm_bo->resource);
+ ttm_bo->resource = res;
+ }
+
obj->ttm.created = true;
i915_gem_object_release_memory_region(obj);
i915_gem_object_init_memory_region(obj, mem);
@@ -1194,6 +1215,11 @@ static int __i915_gem_ttm_object_init_with_placement(struct intel_memory_region
i915_gem_object_unlock(obj);
return 0;
+
+err_res:
+ ttm_bo_unreserve(ttm_bo);
+ ttm_bo_put(ttm_bo);
+ return ret;
}
/**
@@ -1213,7 +1239,8 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
{
return __i915_gem_ttm_object_init_with_placement(mem, obj, size,
page_size, flags,
- &i915_sys_placement);
+ &i915_sys_placement,
+ true);
}
/**
@@ -1254,7 +1281,8 @@ int i915_gem_ttm_object_init_in_place(struct intel_memory_region *mem,
return __i915_gem_ttm_object_init_with_placement(mem, obj, size,
page_size, flags,
- &placement);
+ &placement,
+ false);
}
static const struct intel_memory_region_ops ttm_system_region_ops = {
--
2.25.1
More information about the Intel-gfx-trybot
mailing list