Skip to contentSkip to conversation

Add back the buddy allocator

PATCH Superseded Matthew Auld 3 participants 13 messages Jun 8, 2021

Subsystems (2)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add back the buddy allocator

Needs to be applied on top of:
https://patchwork.freedesktop.org/series/90681/

Matthew Auld (5):
drm/i915/ttm: add ttm_buddy_man drm/i915/ttm: add i915_sg_from_buddy_resource drm/i915/ttm: pass along the I915_BO_ALLOC_CONTIGUOUS drm/i915/ttm: switch over to ttm_buddy_man drm/i915/ttm: restore min_page_size behaviour

Thomas Hellström (1):
drm/i915/ttm: Calculate the object placement at get_pages time

 drivers/gpu/drm/i915/Makefile                 |   2 +
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 102 ++-
 drivers/gpu/drm/i915/i915_buddy.c             | 412 +++++++++
 drivers/gpu/drm/i915/i915_buddy.h             | 133 +++
 drivers/gpu/drm/i915/i915_scatterlist.c       |  80 ++
 drivers/gpu/drm/i915/i915_scatterlist.h       |   5 +
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 248 ++++++
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  56 ++
 drivers/gpu/drm/i915/intel_memory_region.c    |  55 +-
 drivers/gpu/drm/i915/intel_memory_region.h    |  20 +-
 drivers/gpu/drm/i915/intel_region_ttm.c       | 108 +--
 drivers/gpu/drm/i915/intel_region_ttm.h       |   2 +
 drivers/gpu/drm/i915/selftests/i915_buddy.c   | 789 ++++++++++++++++++
 .../drm/i915/selftests/intel_memory_region.c  | 170 ++--
 drivers/gpu/drm/i915/selftests/mock_region.c  |  17 +-
 15 files changed, 1969 insertions(+), 230 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/i915_buddy.c
 create mode 100644 drivers/gpu/drm/i915/i915_buddy.h
 create mode 100644 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
 create mode 100644 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
 create mode 100644 drivers/gpu/drm/i915/selftests/i915_buddy.c
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v2 1/6 drm/i915/ttm: add ttm_buddy_man

Add back our standalone i915_buddy allocator and integrate it into a ttm_resource_manager. This will plug into our ttm backend for managing device local-memory in the next couple of patches.

v2(Thomas):
- Return -ENOSPC from the buddy; ttm expects this in order to trigger eviction
- Drop the unnecessary inline
- bo->page_alignment is in page units

---
 drivers/gpu/drm/i915/Makefile                 |   2 +
 drivers/gpu/drm/i915/i915_buddy.c             | 412 +++++++++
 drivers/gpu/drm/i915/i915_buddy.h             | 133 +++
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 248 ++++++
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  56 ++
 drivers/gpu/drm/i915/selftests/i915_buddy.c   | 789 ++++++++++++++++++
 6 files changed, 1640 insertions(+)
 create mode 100644 drivers/gpu/drm/i915/i915_buddy.c
 create mode 100644 drivers/gpu/drm/i915/i915_buddy.h
 create mode 100644 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
 create mode 100644 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
 create mode 100644 drivers/gpu/drm/i915/selftests/i915_buddy.c
drivers/gpu/drm/i915/Makefile +2 -0
index f57dfc74d6ce..6c84e96ab26a 100644
@@ -162,6 +162,7 @@ gem-y += \
 i915-y += \
 	  $(gem-y) \
 	  i915_active.o \
+	  i915_buddy.o \
 	  i915_cmd_parser.o \
 	  i915_gem_evict.o \
 	  i915_gem_gtt.o \
@@ -171,6 +172,7 @@ i915-y += \
 	  i915_request.o \
 	  i915_scheduler.o \
 	  i915_trace_points.o \
+	  i915_ttm_buddy_manager.o \
 	  i915_vma.o \
 	  intel_wopcm.o
 
drivers/gpu/drm/i915/i915_buddy.c new file +412 -0

412 lines not on this page · raw message

drivers/gpu/drm/i915/i915_buddy.h new file +133 -0

133 lines not on this page · raw message

drivers/gpu/drm/i915/i915_ttm_buddy_manager.c new file +248 -0

248 lines not on this page · raw message

drivers/gpu/drm/i915/i915_ttm_buddy_manager.h new file +56 -0

56 lines not on this page · raw message

drivers/gpu/drm/i915/selftests/i915_buddy.c new file +789 -0

789 lines not on this page · raw message

Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v2 2/6 drm/i915/ttm: add i915_sg_from_buddy_resource

In reply to Matthew Auld

We need to be able to build an sg table from our list of buddy blocks, so that we can later plug this into our ttm backend, and replace our use of the range manager.

---
 drivers/gpu/drm/i915/i915_scatterlist.c | 80 +++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_scatterlist.h |  5 ++
 2 files changed, 85 insertions(+)
drivers/gpu/drm/i915/i915_scatterlist.c +80 -0
index 69e9e6c3135e..0959fe3efbbb 100644
@@ -6,6 +6,9 @@
 
 #include "i915_scatterlist.h"
 
+#include "i915_buddy.h"
+#include "i915_ttm_buddy_manager.h"
+
 #include <drm/drm_mm.h>
 
 #include <linux/slab.h>
@@ -104,6 +107,83 @@ struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
 	return st;
 }
 
+/**
+ * i915_sg_from_buddy_resource - Create an sg_table from a struct
+ * i915_buddy_block list
+ * @res: The i915_ttm_buddy_resource.
+ * @region_start: An offset to add to the dma addresses of the sg list.
+ *
+ * Create a struct sg_table, initializing it from struct i915_buddy_block list,
+ * taking a maximum segment length into account, splitting into segments
+ * if necessary.
+ *
+ * Return: A pointer to a kmalloced struct sg_table on success, negative
+ * error code cast to an error pointer on failure.
+ */
+struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
+					     u64 region_start)
+{
+	struct i915_ttm_buddy_resource *bman_res = to_ttm_buddy_resource(res);
+	struct i915_buddy_mm *mm = bman_res->mm;
+	const u64 size = res->num_pages << PAGE_SHIFT;
+	const u64 max_segment = UINT_MAX;
+	struct list_head *blocks = &bman_res->blocks;
+	struct i915_buddy_block *block;
+	struct scatterlist *sg;
+	struct sg_table *st;
+	resource_size_t prev_end;
+
+	GEM_BUG_ON(list_empty(blocks));
+
+	st = kmalloc(sizeof(*st), GFP_KERNEL);
+	if (!st)
+		return ERR_PTR(-ENOMEM);
+
+	if (sg_alloc_table(st, size >> PAGE_SHIFT, GFP_KERNEL)) {
+		kfree(st);
+		return ERR_PTR(-ENOMEM);
+	}
+
+	sg = st->sgl;
+	st->nents = 0;
+	prev_end = (resource_size_t)-1;
+
+	list_for_each_entry(block, blocks, link) {
+		u64 block_size, offset;
+
+		block_size = min_t(u64, size, i915_buddy_block_size(mm, block));
+		offset = i915_buddy_block_offset(block);
+
+		while (block_size) {
+			u64 len;
+
+			if (offset != prev_end || sg->length >= max_segment) {
+				if (st->nents)
+					sg = __sg_next(sg);
+
+				sg_dma_address(sg) = region_start + offset;
+				sg_dma_len(sg) = 0;
+				sg->length = 0;
+				st->nents++;
+			}
+
+			len = min(block_size, max_segment - sg->length);
+			sg->length += len;
+			sg_dma_len(sg) += len;
+
+			offset += len;
+			block_size -= len;
+
+			prev_end = offset;
+		}
+	}
+
+	sg_mark_end(sg);
+	i915_sg_trim(st);
+
+	return st;
+}
+
 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
 #include "selftests/scatterlist.c"
 #endif
drivers/gpu/drm/i915/i915_scatterlist.h +5 -0
index 5acca45ea981..b8bd5925b03f 100644
@@ -14,6 +14,7 @@
 #include "i915_gem.h"
 
 struct drm_mm_node;
+struct ttm_resource;
 
 /*
  * Optimised SGL iterator for GEM objects
@@ -145,4 +146,8 @@ bool i915_sg_trim(struct sg_table *orig_st);
 
 struct sg_table *i915_sg_from_mm_node(const struct drm_mm_node *node,
 				      u64 region_start);
+
+struct sg_table *i915_sg_from_buddy_resource(struct ttm_resource *res,
+					     u64 region_start);
+
 #endif
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#3 lore raw

PATCH v2 3/6 drm/i915/ttm: Calculate the object placement at get_pages time

In reply to Matthew Auld

From: Thomas Hellström <[email protected]>

Instead of relying on a static placement, calculate at get_pages() time. This should work for LMEM regions and system for now. For stolen we need to take preallocated range into account. That well be added later.

---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 69 +++++++++++++++++++++----
 drivers/gpu/drm/i915/intel_region_ttm.c |  8 ++-
 drivers/gpu/drm/i915/intel_region_ttm.h |  2 +
 3 files changed, 68 insertions(+), 11 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +60 -9
index 9dd6e4f69d53..73d52df8f2be 100644
@@ -24,6 +24,11 @@
 #define I915_TTM_PRIO_NO_PAGES  1
 #define I915_TTM_PRIO_HAS_PAGES 2
 
+/*
+ * Size of struct ttm_place vector in on-stack struct ttm_placement allocs
+ */
+#define I915_TTM_MAX_PLACEMENTS 10
+
 /**
  * struct i915_ttm_tt - TTM page vector with additional private information
  * @ttm: The base TTM page vector.
@@ -56,13 +61,6 @@ static const struct ttm_place lmem0_sys_placement_flags[] = {
 	}
 };
 
-static struct ttm_placement i915_lmem0_placement = {
-	.num_placement = 1,
-	.placement = &lmem0_sys_placement_flags[0],
-	.num_busy_placement = 1,
-	.busy_placement = &lmem0_sys_placement_flags[0],
-};
-
 static struct ttm_placement i915_sys_placement = {
 	.num_placement = 1,
 	.placement = &lmem0_sys_placement_flags[1],
@@ -72,6 +70,55 @@ static struct ttm_placement i915_sys_placement = {
 
 static void i915_ttm_adjust_lru(struct drm_i915_gem_object *obj);
 
+static enum ttm_caching
+i915_ttm_select_tt_caching(const struct drm_i915_gem_object *obj)
+{
+	/*
+	 * Objects only allowed in system get cached cpu-mappings.
+	 * Other objects get WC mapping for now. Even if in system.
+	 */
+	if (obj->mm.region->type == INTEL_MEMORY_SYSTEM &&
+	    obj->mm.n_placements <= 1)
+		return ttm_cached;
+
+	return ttm_write_combined;
+}
+
+static void
+i915_ttm_place_from_region(const struct intel_memory_region *mr,
+			   struct ttm_place *place)
+{
+	memset(place, 0, sizeof(*place));
+	place->mem_type = intel_region_to_ttm_type(mr);
+}
+
+static void
+i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
+			    struct ttm_place *requested,
+			    struct ttm_place *busy,
+			    struct ttm_placement *placement)
+{
+	unsigned int i;
+	unsigned int num_allowed = obj->mm.n_placements;
+
+	placement->num_placement = 1;
+	i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
+				   obj->mm.region, requested);
+
+	/* Cache this on object? */
+	placement->num_busy_placement = num_allowed;
+	for (i = 0; i < placement->num_busy_placement; ++i)
+		i915_ttm_place_from_region(obj->mm.placements[i], busy + i);
+
+	if (num_allowed == 0) {
+		*busy = *requested;
+		placement->num_busy_placement = 1;
+	}
+
+	placement->placement = requested;
+	placement->busy_placement = busy;
+}
+
 static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
 					 uint32_t page_flags)
 {
@@ -89,7 +136,8 @@ static struct ttm_tt *i915_ttm_tt_create(struct ttm_buffer_object *bo,
 	    man->use_tt)
 		page_flags |= TTM_PAGE_FLAG_ZERO_ALLOC;
 
-	ret = ttm_tt_init(&i915_tt->ttm, bo, page_flags, ttm_write_combined);
+	ret = ttm_tt_init(&i915_tt->ttm, bo, page_flags,
+			  i915_ttm_select_tt_caching(obj));
 	if (ret) {
 		kfree(i915_tt);
 		return NULL;
@@ -414,10 +462,13 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
 		.no_wait_gpu = false,
 	};
 	struct sg_table *st;
+	struct ttm_place requested, busy[I915_TTM_MAX_PLACEMENTS];
+	struct ttm_placement placement;
 	int ret;
 
 	/* Move to the requested placement. */
-	ret = ttm_bo_validate(bo, &i915_lmem0_placement, &ctx);
+	i915_ttm_placement_from_obj(obj, &requested, busy, &placement);
+	ret = ttm_bo_validate(bo, &placement, &ctx);
 	if (ret)
 		return ret == -ENOSPC ? -ENXIO : ret;
 
drivers/gpu/drm/i915/intel_region_ttm.c +6 -2
index 27fe0668d094..5a664f6cc93f 100644
@@ -50,12 +50,16 @@ void intel_region_ttm_device_fini(struct drm_i915_private *dev_priv)
  * driver-private types for now, reserving TTM_PL_VRAM for stolen
  * memory and TTM_PL_TT for GGTT use if decided to implement this.
  */
-static int intel_region_to_ttm_type(struct intel_memory_region *mem)
+int intel_region_to_ttm_type(const struct intel_memory_region *mem)
 {
 	int type;
 
 	GEM_BUG_ON(mem->type != INTEL_MEMORY_LOCAL &&
-		   mem->type != INTEL_MEMORY_MOCK);
+		   mem->type != INTEL_MEMORY_MOCK &&
+		   mem->type != INTEL_MEMORY_SYSTEM);
+
+	if (mem->type == INTEL_MEMORY_SYSTEM)
+		return TTM_PL_SYSTEM;
 
 	type = mem->instance + TTM_PL_PRIV;
 	GEM_BUG_ON(type >= TTM_NUM_MEM_TYPES);
drivers/gpu/drm/i915/intel_region_ttm.h +2 -0
index e8cf830fda6f..5eedcc397bd5 100644
@@ -22,6 +22,8 @@ int intel_region_ttm_init(struct intel_memory_region *mem);
 
 void intel_region_ttm_fini(struct intel_memory_region *mem);
 
+int intel_region_to_ttm_type(const struct intel_memory_region *mem);
+
 struct sg_table *intel_region_ttm_node_to_st(struct intel_memory_region *mem,
 					     struct ttm_resource *res);
 
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v2 4/6 drm/i915/ttm: pass along the I915_BO_ALLOC_CONTIGUOUS

In reply to Matthew Auld

Currently we just ignore the I915_BO_ALLOC_CONTIGUOUS flag, which is fine since everything is already contiguous with the ttm range manager. However in the next patch we want to switch over to the ttm buddy manager, where allocations are by default not contiguous.

v2(Thomas):
- Forward ALLOC_CONTIG for all regions

Cc Thomas Hellström <[email protected]>
---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +8 -3
index 73d52df8f2be..c612275c36c9 100644
@@ -86,10 +86,14 @@ i915_ttm_select_tt_caching(const struct drm_i915_gem_object *obj)
 
 static void
 i915_ttm_place_from_region(const struct intel_memory_region *mr,
-			   struct ttm_place *place)
+			   struct ttm_place *place,
+			   unsigned int flags)
 {
 	memset(place, 0, sizeof(*place));
 	place->mem_type = intel_region_to_ttm_type(mr);
+
+	if (flags & I915_BO_ALLOC_CONTIGUOUS)
+		place->flags = TTM_PL_FLAG_CONTIGUOUS;
 }
 
 static void
@@ -100,15 +104,16 @@ i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj,
 {
 	unsigned int i;
 	unsigned int num_allowed = obj->mm.n_placements;
+	unsigned int flags = obj->flags;
 
 	placement->num_placement = 1;
 	i915_ttm_place_from_region(num_allowed ? obj->mm.placements[0] :
-				   obj->mm.region, requested);
+				   obj->mm.region, requested, flags);
 
 	/* Cache this on object? */
 	placement->num_busy_placement = num_allowed;
 	for (i = 0; i < placement->num_busy_placement; ++i)
-		i915_ttm_place_from_region(obj->mm.placements[i], busy + i);
+		i915_ttm_place_from_region(obj->mm.placements[i], busy + i, flags);
 
 	if (num_allowed == 0) {
 		*busy = *requested;
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v2 4/6
#5 lore raw

Re: [PATCH v2 4/6] drm/i915/ttm: pass along the I915_BO_ALLOC_CONTIGUOUS

Quoted 10 lines · Matthew Auld

Currently we just ignore the I915_BO_ALLOC_CONTIGUOUS flag, which is fine since everything is already contiguous with the ttm range manager. However in the next patch we want to switch over to the ttm buddy manager, where allocations are by default not contiguous.

v2(Thomas):
- Forward ALLOC_CONTIG for all regions

Cc Thomas Hellström <[email protected]>
#6 lore raw

PATCH v2 5/6 drm/i915/ttm: switch over to ttm_buddy_man

In reply to Matthew Auld

Move back to the buddy allocator for managing device local memory, and restore the lost mock selftests. Keep around the range manager related bits, since we likely need this for managing stolen at some point. For stolen we also don't need to reserve anything so no need to support a generic reserve interface.

v2(Thomas):
- bo->page_alignment is in page units, not bytes

---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       |  26 +--
 drivers/gpu/drm/i915/intel_memory_region.c    |  55 +-----
 drivers/gpu/drm/i915/intel_memory_region.h    |  17 --
 drivers/gpu/drm/i915/intel_region_ttm.c       | 100 +++--------
 .../drm/i915/selftests/intel_memory_region.c  | 170 ++++++++++++------
 drivers/gpu/drm/i915/selftests/mock_region.c  |  15 +-
 6 files changed, 168 insertions(+), 215 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +7 -19
index c612275c36c9..5bf1d1945dd6 100644
@@ -181,11 +181,7 @@ static bool i915_ttm_eviction_valuable(struct ttm_buffer_object *bo,
 	struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
 
 	/* Will do for now. Our pinned objects are still on TTM's LRU lists */
-	if (!i915_gem_object_evictable(obj))
-		return false;
-
-	/* This isn't valid with a buddy allocator */
-	return ttm_bo_eviction_valuable(bo, place);
+	return i915_gem_object_evictable(obj);
 }
 
 static void i915_ttm_evict_flags(struct ttm_buffer_object *bo,
@@ -328,11 +324,15 @@ i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
 	struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
 	struct ttm_resource_manager *man =
 		ttm_manager_type(bo->bdev, res->mem_type);
+	struct intel_memory_region *mr = obj->mm.region;
 
 	if (man->use_tt)
 		return i915_ttm_tt_get_st(bo->ttm);
 
-	return intel_region_ttm_node_to_st(obj->mm.region, res->mm_node);
+	if (mr->is_range_manager)
+		return intel_region_ttm_node_to_st(mr, res);
+	else
+		return i915_sg_from_buddy_resource(res, mr->region.start);
 }
 
 static int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
@@ -657,20 +657,8 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
 	static struct lock_class_key lock_class;
 	struct drm_i915_private *i915 = mem->i915;
 	enum ttm_bo_type bo_type;
-	size_t alignment = 0;
 	int ret;
 
-	/* Adjust alignment to GPU- and CPU huge page sizes. */
-
-	if (mem->is_range_manager) {
-		if (size >= SZ_1G)
-			alignment = SZ_1G >> PAGE_SHIFT;
-		else if (size >= SZ_2M)
-			alignment = SZ_2M >> PAGE_SHIFT;
-		else if (size >= SZ_64K)
-			alignment = SZ_64K >> PAGE_SHIFT;
-	}
-
 	drm_gem_private_object_init(&i915->drm, &obj->base, size);
 	i915_gem_object_init(obj, &i915_gem_ttm_obj_ops, &lock_class, flags);
 	i915_gem_object_init_memory_region(obj, mem);
@@ -692,7 +680,7 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
 	 */
 	obj->base.vma_node.driver_private = i915_gem_to_ttm(obj);
 	ret = ttm_bo_init(&i915->bdev, i915_gem_to_ttm(obj), size,
-			  bo_type, &i915_sys_placement, alignment,
+			  bo_type, &i915_sys_placement, 1,
 			  true, NULL, NULL, i915_ttm_bo_destroy);
 
 	if (!ret)
drivers/gpu/drm/i915/intel_memory_region.c +4 -51

96 lines not on this page · raw message

drivers/gpu/drm/i915/intel_memory_region.h +0 -17
index c7e635d62e1a..b04fb22726d9 100644
@@ -59,19 +59,10 @@ struct intel_memory_region_ops {
 			   unsigned int flags);
 };
 
-struct intel_memory_region_private_ops {
-	struct ttm_resource *(*reserve)(struct intel_memory_region *mem,
-					resource_size_t offset,
-					resource_size_t size);
-	void (*free)(struct intel_memory_region *mem,
-		     struct ttm_resource *res);
-};
-
 struct intel_memory_region {
 	struct drm_i915_private *i915;
 
 	const struct intel_memory_region_ops *ops;
-	const struct intel_memory_region_private_ops *priv_ops;
 
 	struct io_mapping iomap;
 	struct resource region;
@@ -79,8 +70,6 @@ struct intel_memory_region {
 	/* For fake LMEM */
 	struct drm_mm_node fake_mappable;
 
-	struct mutex mm_lock;
-
 	struct kref kref;
 
 	resource_size_t io_start;
@@ -94,8 +83,6 @@ struct intel_memory_region {
 	char name[16];
 	bool private; /* not for userspace */
 
-	struct list_head reserved;
-
 	dma_addr_t remap_addr;
 
 	struct {
@@ -103,8 +90,6 @@ struct intel_memory_region {
 		struct list_head list;
 	} objects;
 
-	size_t chunk_size;
-	unsigned int max_order;
 	bool is_range_manager;
 
 	void *region_private;
@@ -138,8 +123,6 @@ __printf(2, 3) void
 intel_memory_region_set_name(struct intel_memory_region *mem,
 			     const char *fmt, ...);
 
-void intel_memory_region_unreserve(struct intel_memory_region *mem);
-
 int intel_memory_region_reserve(struct intel_memory_region *mem,
 				resource_size_t offset,
 				resource_size_t size);
drivers/gpu/drm/i915/intel_region_ttm.c +27 -73

138 lines not on this page · raw message

drivers/gpu/drm/i915/selftests/intel_memory_region.c +119 -51

286 lines not on this page · raw message

drivers/gpu/drm/i915/selftests/mock_region.c +11 -4
index eafc5a04975c..d3e4e6573cb9 100644
@@ -3,6 +3,7 @@
  * Copyright © 2019-2021 Intel Corporation
  */
 
+#include <drm/ttm/ttm_placement.h>
 #include <linux/scatterlist.h>
 
 #include <drm/ttm/ttm_placement.h>
@@ -25,10 +26,11 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)
 {
 	unsigned int flags;
 	struct sg_table *pages;
+	int err;
 
 	flags = I915_ALLOC_MIN_PAGE_SIZE;
 	if (obj->flags & I915_BO_ALLOC_CONTIGUOUS)
-		flags |= I915_ALLOC_CONTIGUOUS;
+		flags |= TTM_PL_FLAG_CONTIGUOUS;
 
 	obj->mm.st_mm_node = intel_region_ttm_node_alloc(obj->mm.region,
 							 obj->base.size,
@@ -36,15 +38,20 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)
 	if (IS_ERR(obj->mm.st_mm_node))
 		return PTR_ERR(obj->mm.st_mm_node);
 
-	pages = intel_region_ttm_node_to_st(obj->mm.region, obj->mm.st_mm_node);
+	pages = i915_sg_from_buddy_resource(obj->mm.st_mm_node,
+					    obj->mm.region->region.start);
 	if (IS_ERR(pages)) {
-		intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node);
-		return PTR_ERR(pages);
+		err = PTR_ERR(pages);
+		goto err_free_mm_node;
 	}
 
 	__i915_gem_object_set_pages(obj, pages, i915_sg_dma_sizes(pages->sgl));
 
 	return 0;
+
+err_free_mm_node:
+	intel_region_ttm_node_free(obj->mm.region, obj->mm.st_mm_node);
+	return err;
 }
 
 static const struct drm_i915_gem_object_ops mock_region_obj_ops = {
Signature · 1 line
2.26.3
#7 lore raw

Re: [PATCH v2 5/6] drm/i915/ttm: switch over to ttm_buddy_man

Quoted 39 lines · Matthew Auld

Move back to the buddy allocator for managing device local memory, and restore the lost mock selftests. Keep around the range manager related bits, since we likely need this for managing stolen at some point. For stolen we also don't need to reserve anything so no need to support a generic reserve interface.

v2(Thomas):
- bo->page_alignment is in page units, not bytes

---
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c       |  26 +--
  drivers/gpu/drm/i915/intel_memory_region.c    |  55 +-----
  drivers/gpu/drm/i915/intel_memory_region.h    |  17 --
  drivers/gpu/drm/i915/intel_region_ttm.c       | 100 +++--------
  .../drm/i915/selftests/intel_memory_region.c  | 170 ++++++++++++------
  drivers/gpu/drm/i915/selftests/mock_region.c  |  15 +-
  6 files changed, 168 insertions(+), 215 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -5
index c612275c36c9..5bf1d1945dd6 100644
@@ -181,11 +181,7 @@ static bool i915_ttm_eviction_valuable(struct ttm_buffer_object *bo,
  	struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
 
  	/* Will do for now. Our pinned objects are still on TTM's LRU lists */
-	if (!i915_gem_object_evictable(obj))
-		return false;
-
-	/* This isn't valid with a buddy allocator */
-	return ttm_bo_eviction_valuable(bo, place);
+	return i915_gem_object_evictable(obj);
  }
 
  static void i915_ttm_evict_flags(struct ttm_buffer_object *bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c i915_ttm_resource_get_st(struct drm_i915_gem_object *obj, · line 332

Quoted 10 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -1
@@ -328,11 +324,15 @@ i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,
  	struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
  	struct ttm_resource_manager *man =
  		ttm_manager_type(bo->bdev, res->mem_type);
+	struct intel_memory_region *mr = obj->mm.region;
 
  	if (man->use_tt)
  		return i915_ttm_tt_get_st(bo->ttm);
 
-	return intel_region_ttm_node_to_st(obj->mm.region, res->mm_node);
+	if (mr->is_range_manager)

Did you look at moving this test into intel_region_ttm_node_to_st())

drivers/gpu/drm/i915/gem/i915_gem_ttm.c i915_ttm_resource_get_st(struct drm_i915_gem_object *obj, · line 336

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +3 -0
+		return intel_region_ttm_node_to_st(mr, res);
+	else
+		return i915_sg_from_buddy_resource(res, mr->region.start);
  }

Thanks,

Thomas

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

Re: [PATCH v2 5/6] drm/i915/ttm: switch over to ttm_buddy_man

Quoted 43 lines · Thomas Hellström
Quoted 41 lines · Matthew Auld

Move back to the buddy allocator for managing device local memory, and restore the lost mock selftests. Keep around the range manager related bits, since we likely need this for managing stolen at some point. For stolen we also don't need to reserve anything so no need to support a generic reserve interface.

v2(Thomas):
     - bo->page_alignment is in page units, not bytes

---
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c       |  26 +-- drivers/gpu/drm/i915/intel_memory_region.c    |  55 +----- drivers/gpu/drm/i915/intel_memory_region.h    |  17 -- drivers/gpu/drm/i915/intel_region_ttm.c       | 100 +++-------- .../drm/i915/selftests/intel_memory_region.c  | 170 ++++++++++++------ drivers/gpu/drm/i915/selftests/mock_region.c  |  15 +-

  6 files changed, 168 insertions(+), 215 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -5
index c612275c36c9..5bf1d1945dd6 100644
@@ -181,11 +181,7 @@ static bool i915_ttm_eviction_valuable(struct 
 ttm_buffer_object *bo,
       struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo);
       /* Will do for now. Our pinned objects are still on TTM's LRU lists */
-    if (!i915_gem_object_evictable(obj))
-        return false;
-
-    /* This isn't valid with a buddy allocator */
-    return ttm_bo_eviction_valuable(bo, place);
+    return i915_gem_object_evictable(obj);
   }
   static void i915_ttm_evict_flags(struct ttm_buffer_object *bo,
@@ -328,11 +324,15 @@ i915_ttm_resource_get_st(struct 
 drm_i915_gem_object *obj,
       struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);

      struct ttm_resource_manager *man =

Quoted 8 lines
Quoted 6 lines

          ttm_manager_type(bo->bdev, res->mem_type);
+    struct intel_memory_region *mr = obj->mm.region;
      if (man->use_tt)
          return i915_ttm_tt_get_st(bo->ttm);
-    return intel_region_ttm_node_to_st(obj->mm.region, res->mm_node); +    if (mr->is_range_manager)

Did you look at moving this test into intel_region_ttm_node_to_st())

I guess I didn't like the _node since that seems to suggest drm_mm_node to me.

What about something like:
i915_ttm_resource_to_st(res, mr)
intel_region_ttm_resource_to_st(mr, res)

?

Quoted 11 lines
Quoted 5 lines

+        return intel_region_ttm_node_to_st(mr, res);
+    else
+        return i915_sg_from_buddy_resource(res, mr->region.start); }

Thanks,

Thomas

#9 lore raw

Re: [PATCH v2 5/6] drm/i915/ttm: switch over to ttm_buddy_man

Quoted 64 lines · Matthew Auld
Quoted 57 lines · Thomas Hellström
Quoted 55 lines · Matthew Auld

Move back to the buddy allocator for managing device local memory, and
restore the lost mock selftests. Keep around the range manager related
bits, since we likely need this for managing stolen at some point. For
stolen we also don't need to reserve anything so no need to support a
generic reserve interface.

v2(Thomas):
     - bo->page_alignment is in page units, not bytes

---
  drivers/gpu/drm/i915/gem/i915_gem_ttm.c       |  26 +-- drivers/gpu/drm/i915/intel_memory_region.c    |  55 +----- drivers/gpu/drm/i915/intel_memory_region.h    |  17 -- drivers/gpu/drm/i915/intel_region_ttm.c       | 100 +++-------- .../drm/i915/selftests/intel_memory_region.c  | 170
++++++++++++------
  drivers/gpu/drm/i915/selftests/mock_region.c  |  15 +-

  6 files changed, 168 insertions(+), 215 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
index c612275c36c9..5bf1d1945dd6 100644
@@ -181,11 +181,7 @@ static bool

i915_ttm_eviction_valuable(struct
ttm_buffer_object *bo,
      struct drm_i915_gem_object *obj = i915_ttm_to_gem(bo); /* Will do for now. Our pinned objects are still on TTM's LRU
lists */
-    if (!i915_gem_object_evictable(obj))
-        return false;
-
-    /* This isn't valid with a buddy allocator */
-    return ttm_bo_eviction_valuable(bo, place);
+    return i915_gem_object_evictable(obj);
  }
  static void i915_ttm_evict_flags(struct ttm_buffer_object *bo,

drivers/gpu/drm/i915/gem/i915_gem_ttm.c +0 -0
@@ -328,11 +324,15 @@ i915_ttm_resource_get_st(struct 
 drm_i915_gem_object *obj,
       struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);

      struct ttm_resource_manager *man = ttm_manager_type(bo->bdev, res->mem_type); +    struct intel_memory_region *mr = obj->mm.region; if (man->use_tt)
          return i915_ttm_tt_get_st(bo->ttm);
-    return intel_region_ttm_node_to_st(obj->mm.region, res-

Quoted 5 lines
Quoted 2 lines
Quoted 1 line

mm_node);

+    if (mr->is_range_manager)

Did you look at moving this test into
intel_region_ttm_node_to_st())

Quoted 7 lines

I guess I didn't like the _node since that seems to suggest drm_mm_node
to me.

What about something like:
i915_ttm_resource_to_st(res, mr)
intel_region_ttm_resource_to_st(mr, res)

intel_region_ttm_resource_to_st() would be nice I think. I think it would be nice if the region ttm code could hide the manager selection.

/Thomas

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#10 lore raw

PATCH v2 6/6 drm/i915/ttm: restore min_page_size behaviour

In reply to Matthew Auld

We now have bo->page_alignment which perfectly describes what we need if we have min page size restrictions for lmem. We can also drop the flag here, since this is the default behaviour for all objects.

v2(Thomas):
- bo->page_alignment is in page units

Cc Thomas Hellström <[email protected]>
---
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c      | 4 ++--
 drivers/gpu/drm/i915/intel_memory_region.h   | 3 +--
 drivers/gpu/drm/i915/intel_region_ttm.c      | 2 +-
 drivers/gpu/drm/i915/selftests/mock_region.c | 2 +-
 4 files changed, 5 insertions(+), 6 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -2
index 5bf1d1945dd6..3df73c79aa19 100644
@@ -680,9 +680,9 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,
 	 */
 	obj->base.vma_node.driver_private = i915_gem_to_ttm(obj);
 	ret = ttm_bo_init(&i915->bdev, i915_gem_to_ttm(obj), size,
-			  bo_type, &i915_sys_placement, 1,
+			  bo_type, &i915_sys_placement,
+			  mem->min_page_size >> PAGE_SHIFT,
 			  true, NULL, NULL, i915_ttm_bo_destroy);
-
 	if (!ret)
 		obj->ttm.created = true;
 
drivers/gpu/drm/i915/intel_memory_region.h +1 -2
index b04fb22726d9..2be8433d373a 100644
@@ -40,8 +40,7 @@ enum intel_region_id {
 #define REGION_STOLEN_SMEM   BIT(INTEL_REGION_STOLEN_SMEM)
 #define REGION_STOLEN_LMEM   BIT(INTEL_REGION_STOLEN_LMEM)
 
-#define I915_ALLOC_MIN_PAGE_SIZE  BIT(0)
-#define I915_ALLOC_CONTIGUOUS     BIT(1)
+#define I915_ALLOC_CONTIGUOUS     BIT(0)
 
 #define for_each_memory_region(mr, i915, id) \
 	for (id = 0; id < ARRAY_SIZE((i915)->mm.regions); id++) \
drivers/gpu/drm/i915/intel_region_ttm.c +1 -1
index 23a1336d2335..ad43ca90a46b 100644
@@ -153,7 +153,7 @@ intel_region_ttm_node_alloc(struct intel_memory_region *mem,
 	int ret;
 
 	mock_bo.base.size = size;
-	mock_bo.page_alignment = 1;
+	mock_bo.page_alignment = mem->min_page_size >> PAGE_SHIFT;
 	place.flags = flags;
 
 	ret = man->func->alloc(man, &mock_bo, &place, &res);
drivers/gpu/drm/i915/selftests/mock_region.c +1 -1
index d3e4e6573cb9..6ce0f9dacad7 100644
@@ -28,7 +28,7 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)
 	struct sg_table *pages;
 	int err;
 
-	flags = I915_ALLOC_MIN_PAGE_SIZE;
+	flags = 0;
 	if (obj->flags & I915_BO_ALLOC_CONTIGUOUS)
 		flags |= TTM_PL_FLAG_CONTIGUOUS;
 
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v2 6/6
#11 lore raw

Re: [PATCH v2 6/6] drm/i915/ttm: restore min_page_size behaviour

Quoted 9 lines · Matthew Auld

We now have bo->page_alignment which perfectly describes what we need if we have min page size restrictions for lmem. We can also drop the flag here, since this is the default behaviour for all objects.

v2(Thomas):
- bo->page_alignment is in page units

Cc Thomas Hellström <[email protected]>
#12 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for Add back the buddy allocator (rev2)

In reply to Matthew Auld
== Series Details ==

== Series Details ==

Series: Add back the buddy allocator (rev2)
URL : https://patchwork.freedesktop.org/series/91110/
State : failure

== Summary ==

Applying: drm/i915/ttm: add ttm_buddy_man
Applying: drm/i915/ttm: add i915_sg_from_buddy_resource
Applying: drm/i915/ttm: Calculate the object placement at get_pages time
error: sha1 information is lacking or useless (drivers/gpu/drm/i915/gem/i915_gem_ttm.c).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0003 drm/i915/ttm: Calculate the object placement at get_pages time When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx