drm/i915/ttm: add ttm_buddy_man
Subsystems (2)
PATCH v5 1/7 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
@@ -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 · 1 line
2.26.3
PATCH v5 5/7 drm/i915/ttm: remove node usage in our naming
Now that ttm_resource_manager just returns a generic ttm_resource we don't need to reference the mm_node stuff anymore which mostly only makes sense for drm_mm_node. In the next few patches we want switch over to the ttm_buddy_man which is just another type of ttm_resource so reflect that in the naming.
--- .../gpu/drm/i915/gem/i915_gem_object_types.h | 5 ++-- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 2 +- drivers/gpu/drm/i915/intel_region_ttm.c | 30 +++++++++---------- drivers/gpu/drm/i915/intel_region_ttm.h | 14 ++++----- drivers/gpu/drm/i915/selftests/mock_region.c | 16 +++++----- 5 files changed, 34 insertions(+), 33 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_object_types.h +3 -2
@@ -265,9 +265,10 @@ struct drm_i915_gem_object {struct intel_memory_region *region;/** -* Memory manager node allocated for this object. +* Memory manager resource allocated for this object. Only +* needed for the mock region. */ -void *st_mm_node; +struct ttm_resource *res;/** * Element within memory_region->objects or region->purgeable
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +1 -1
@@ -327,7 +327,7 @@ i915_ttm_resource_get_st(struct drm_i915_gem_object *obj,if (man->use_tt)return i915_ttm_tt_get_st (bo->ttm); -return intel_region_ttm_node_to_st (obj->mm.region, res); +return intel_region_ttm_resource_to_st (obj->mm.region, res); } static int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,
drivers/gpu/drm/i915/intel_region_ttm.c +15 -15
@@ -68,7 +68,7 @@ int intel_region_to_ttm_type(const struct intel_memory_region *mem) }static struct ttm_resource * -intel_region_ttm_node_reserve (struct intel_memory_region *mem, +intel_region_ttm_resource_reserve (struct intel_memory_region *mem,resource_size_t offset,resource_size_t size) {
@@ -100,12 +100,12 @@ intel_region_ttm_node_reserve(struct intel_memory_region *mem, }/** -* intel_region_ttm_node_free - Free a node allocated from a resource manager -* @mem: The region the node was allocated from. -* @node: The opaque node representing an allocation. +* intel_region_ttm_resource_free - Free a resource allocated from a resource manager +* @mem: The region the resource was allocated from. +* @res: The opaque resource representing an allocation. */ -void intel_region_ttm_node_free (struct intel_memory_region *mem, -struct ttm_resource *res) +void intel_region_ttm_resource_free (struct intel_memory_region *mem, +struct ttm_resource *res) {struct ttm_resource_manager *man = mem->region_private;
@@ -113,8 +113,8 @@ void intel_region_ttm_node_free(struct intel_memory_region *mem, }static const struct intel_memory_region_private_ops priv_ops = { - .reserve = intel_region_ttm_node_reserve, - .free = intel_region_ttm_node_free, + .reserve = intel_region_ttm_resource_reserve, + .free = intel_region_ttm_resource_free, };int intel_region_ttm_init (struct intel_memory_region *mem)
@@ -157,10 +157,10 @@ void intel_region_ttm_fini(struct intel_memory_region *mem) }/** -* intel_region_ttm_node_to_st - Convert an opaque TTM resource manager node +* intel_region_ttm_resource_to_st - Convert an opaque TTM resource manager resource * to an sg_table. * @mem: The memory region. -* @node: The resource manager node obtained from the TTM resource manager. +* @res: The resource manager resource obtained from the TTM resource manager. * * The gem backends typically use sg-tables for operations on the underlying * io_memory. So provide a way for the backends to translate the
@@ -168,8 +168,8 @@ void intel_region_ttm_fini(struct intel_memory_region *mem)* * Return: A malloced sg_table on success, an error pointer on failure. */ -struct sg_table *intel_region_ttm_node_to_st (struct intel_memory_region *mem, -struct ttm_resource *res) +struct sg_table *intel_region_ttm_resource_to_st (struct intel_memory_region *mem, +struct ttm_resource *res) {struct ttm_range_mgr_node *range_node =container_of (res,typeof (*range_node), base);
@@ -196,9 +196,9 @@ struct sg_table *intel_region_ttm_node_to_st(struct intel_memory_region *mem,* Return: A valid pointer on success, an error pointer on failure. */ struct ttm_resource * -intel_region_ttm_node_alloc (struct intel_memory_region *mem, -resource_size_t size, -unsigned int flags) +intel_region_ttm_resource_alloc (struct intel_memory_region *mem, +resource_size_t size, +unsigned int flags) {struct ttm_resource_manager *man = mem->region_private;struct ttm_place place = {};
drivers/gpu/drm/i915/intel_region_ttm.h +7 -7
@@ -22,11 +22,11 @@ int intel_region_ttm_init(struct intel_memory_region *mem);void intel_region_ttm_fini (struct intel_memory_region *mem); -struct sg_table *intel_region_ttm_node_to_st (struct intel_memory_region *mem, -struct ttm_resource *res); +struct sg_table *intel_region_ttm_resource_to_st (struct intel_memory_region *mem, +struct ttm_resource *res); -void intel_region_ttm_node_free (struct intel_memory_region *mem, -struct ttm_resource *node); +void intel_region_ttm_resource_free (struct intel_memory_region *mem, +struct ttm_resource *res);int intel_region_to_ttm_type (const struct intel_memory_region *mem);
@@ -34,8 +34,8 @@ struct ttm_device_funcs *i915_ttm_driver(void);#ifdef CONFIG_DRM_I915_SELFTEST struct ttm_resource * -intel_region_ttm_node_alloc (struct intel_memory_region *mem, -resource_size_t size, -unsigned int flags); +intel_region_ttm_resource_alloc (struct intel_memory_region *mem, +resource_size_t size, +unsigned int flags);#endif #endif /* _INTEL_REGION_TTM_H_ */
drivers/gpu/drm/i915/selftests/mock_region.c +8 -8
@@ -16,7 +16,7 @@static void mock_region_put_pages (struct drm_i915_gem_object *obj,struct sg_table *pages) { -intel_region_ttm_node_free (obj->mm.region, obj->mm.st_mm_node); +intel_region_ttm_resource_free (obj->mm.region, obj->mm.res);sg_free_table (pages);kfree (pages); }
@@ -30,15 +30,15 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj)if (obj->flags &I915_BO_ALLOC_CONTIGUOUS ) flags |=I915_ALLOC_CONTIGUOUS ; - obj->mm.st_mm_node =intel_region_ttm_node_alloc (obj->mm.region, - obj->base.size, - flags); -if (IS_ERR (obj->mm.st_mm_node)) -return PTR_ERR (obj->mm.st_mm_node); + obj->mm.res =intel_region_ttm_resource_alloc (obj->mm.region, + obj->base.size, + flags); +if (IS_ERR (obj->mm.res)) +return PTR_ERR (obj->mm.res); - pages =intel_region_ttm_node_to_st (obj->mm.region, obj->mm.st_mm_node); + pages =intel_region_ttm_resource_to_st (obj->mm.region, obj->mm.res);if (IS_ERR (pages)) { -intel_region_ttm_node_free (obj->mm.region, obj->mm.st_mm_node); +intel_region_ttm_resource_free (obj->mm.region, obj->mm.res);return PTR_ERR (pages); }
Signature · 6 lines
2.26.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 6/7 drm/i915/ttm: switch over to ttm_buddy_man
In reply to Matthew AuldMove 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 | 20 +-- 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 | 122 +++++-------- .../drm/i915/selftests/intel_memory_region.c | 170 ++++++++++++------ drivers/gpu/drm/i915/selftests/mock_region.c | 12 +- 6 files changed, 180 insertions(+), 216 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +2 -18
@@ -175,11 +175,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,
@@ -654,20 +650,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);
@@ -688,7 +672,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
@@ -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 +46 -76
169 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 +9 -3
@@ -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.res = intel_region_ttm_resource_alloc(obj->mm.region, obj->base.size,
@@ -38,13 +40,17 @@ static int mock_region_get_pages(struct drm_i915_gem_object *obj) pages =intel_region_ttm_resource_to_st (obj->mm.region, obj->mm.res);if (IS_ERR (pages)) { -intel_region_ttm_resource_free (obj->mm.region, obj->mm.res); -return PTR_ERR (pages); + err =PTR_ERR (pages); + goto err_free_resource; }__i915_gem_object_set_pages (obj, pages,i915_sg_dma_sizes (pages->sgl));return 0 ; + +err_free_resource: +intel_region_ttm_resource_free (obj->mm.region, obj->mm.res); +return err; }static const struct drm_i915_gem_object_ops mock_region_obj_ops = {
Signature · 1 line
2.26.3
PATCH v5 7/7 drm/i915/ttm: restore min_page_size behaviour
In reply to Matthew AuldWe 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
--- 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
@@ -672,9 +672,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
@@ -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
@@ -167,7 +167,7 @@ intel_region_ttm_resource_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
@@ -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 · 1 line
2.26.3
PATCH v5 2/7 drm/i915/ttm: add i915_sg_from_buddy_resource
In reply to Matthew AuldWe 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
@@ -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 struct 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); +const u64 size = res->num_pages <<PAGE_SHIFT ; +const u64 max_segment =rounddown (UINT_MAX ,PAGE_SIZE ); +struct i915_buddy_mm *mm = bman_res->mm; +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, res->num_pages,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
@@ -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
PATCH v5 3/7 drm/i915/ttm: Calculate the object placement at get_pages time
In reply to Matthew AuldFrom: 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 will if needed be added later.
--- drivers/gpu/drm/i915/gem/i915_gem_ttm.c | 93 ++++++++++++++++++------- drivers/gpu/drm/i915/intel_region_ttm.c | 8 ++- drivers/gpu/drm/i915/intel_region_ttm.h | 2 + 3 files changed, 77 insertions(+), 26 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_ttm.c +69 -24
@@ -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 INTEL_REGION_UNKNOWN +/** * struct i915_ttm_tt - TTM page vector with additional private information * @ttm: The base TTM page vector.
@@ -42,36 +47,71 @@ struct i915_ttm_tt {struct sg_table *cached_st; }; -static const struct ttm_place lmem0_sys_placement_flags[] = { - { - .fpfn =0 , - .lpfn =0 , - .mem_type =I915_PL_LMEM0 , - .flags =0 , - }, { - .fpfn =0 , - .lpfn =0 , - .mem_type =I915_PL_SYSTEM , - .flags =0 , - } -}; - -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 const struct ttm_place sys_placement_flags = { + .fpfn =0 , + .lpfn =0 , + .mem_type =I915_PL_SYSTEM , + .flags =0 , };static struct ttm_placement i915_sys_placement = { .num_placement =1 , - .placement = &lmem0_sys_placement_flags[1 ], + .placement = &sys_placement_flags, .num_busy_placement =1 , - .busy_placement = &lmem0_sys_placement_flags[1 ], + .busy_placement = &sys_placement_flags, };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 num_allowed = obj->mm.n_placements; +unsigned int i; + + 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 +129,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 ;
@@ -416,10 +457,15 @@ 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; +GEM_BUG_ON (obj->mm.n_placements >I915_TTM_MAX_PLACEMENTS ); +/* 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;
@@ -625,7 +671,6 @@ int __i915_gem_ttm_object_init(struct intel_memory_region *mem,i915_gem_object_set_cache_coherency (obj,I915_CACHE_NONE );INIT_RADIX_TREE (&obj->ttm.get_io_page.radix,GFP_KERNEL | __GFP_NOWARN);mutex_init (&obj->ttm.get_io_page.lock); - bo_type = (obj->flags &I915_BO_ALLOC_USER ) ? ttm_bo_type_device : ttm_bo_type_kernel;
drivers/gpu/drm/i915/intel_region_ttm.c +6 -2
@@ -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
@@ -28,6 +28,8 @@ struct sg_table *intel_region_ttm_node_to_st(struct intel_memory_region *mem,void intel_region_ttm_node_free (struct intel_memory_region *mem,struct ttm_resource *node); +int intel_region_to_ttm_type (const struct intel_memory_region *mem); +struct ttm_device_funcs *i915_ttm_driver (void );#ifdef CONFIG_DRM_I915_SELFTEST
Signature · 6 lines
2.26.3 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v5 4/7 drm/i915/ttm: pass along the I915_BO_ALLOC_CONTIGUOUS
In reply to Matthew AuldCurrently 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
--- 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
@@ -79,10 +79,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
@@ -92,16 +96,17 @@ i915_ttm_placement_from_obj(const struct drm_i915_gem_object *obj, struct ttm_placement *placement) {unsigned int num_allowed = obj->mm.n_placements; +unsigned int flags = obj->flags;unsigned int i; 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
Patchwork
CI[Intel-gfx] ✗ Fi.CI.BUILD: failure for series starting with [v5,1/7] drm/i915/ttm: add ttm_buddy_man
In reply to Matthew Auld== Series Details ==
== Series Details ==
Series: series starting with [v5,1/7] drm/i915/ttm: add ttm_buddy_man
URL : https://patchwork.freedesktop.org/series/91589/
State : failure
== Summary ==
Applying: drm/i915/ttm: add ttm_buddy_man
.git/rebase-apply/patch:845: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/Makefile
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: drm/i915/ttm: add i915_sg_from_buddy_resource
Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/i915_scatterlist.c
M drivers/gpu/drm/i915/i915_scatterlist.h
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: drm/i915/ttm: Calculate the object placement at get_pages time Using index info to reconstruct a base tree...
M drivers/gpu/drm/i915/gem/i915_gem_ttm.c
M drivers/gpu/drm/i915/intel_region_ttm.c
M drivers/gpu/drm/i915/intel_region_ttm.h
Falling back to patching base and 3-way merge...
Auto-merging drivers/gpu/drm/i915/intel_region_ttm.h
Auto-merging drivers/gpu/drm/i915/intel_region_ttm.c
Auto-merging drivers/gpu/drm/i915/gem/i915_gem_ttm.c
CONFLICT (content): Merge conflict in drivers/gpu/drm/i915/gem/i915_gem_ttm.c
error: Failed to merge in the changes.
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