Re: [Intel-gfx] [PATCH v2 1/2] drm/i915: support forcing the page size with lmem

2021-06-24 Thread Thomas Hellström


On 6/23/21 4:16 PM, Matthew Auld wrote:

For some specialised objects we might need something larger than the
regions min_page_size due to some hw restriction, and slightly more
hairy is needing something smaller with the guarantee that such objects
will never be inserted into any GTT, which is the case for the paging
structures.

This also fixes how we setup the BO page_alignment, if we later migrate
the object somewhere else. For example if the placements are {SMEM,
LMEM}, then we might get this wrong. Pushing the min_page_size behaviour
into the manager should fix this.

v2(Thomas): push the default page size behaviour into buddy_man, and let
the user override it with the page-alignment, which looks cleaner

Signed-off-by: Matthew Auld 
Cc: Thomas Hellström 


Reviewed-by: Thomas Hellström 

___
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx


[Intel-gfx] [PATCH v2 1/2] drm/i915: support forcing the page size with lmem

2021-06-23 Thread Matthew Auld
For some specialised objects we might need something larger than the
regions min_page_size due to some hw restriction, and slightly more
hairy is needing something smaller with the guarantee that such objects
will never be inserted into any GTT, which is the case for the paging
structures.

This also fixes how we setup the BO page_alignment, if we later migrate
the object somewhere else. For example if the placements are {SMEM,
LMEM}, then we might get this wrong. Pushing the min_page_size behaviour
into the manager should fix this.

v2(Thomas): push the default page size behaviour into buddy_man, and let
the user override it with the page-alignment, which looks cleaner

Signed-off-by: Matthew Auld 
Cc: Thomas Hellström 
---
 drivers/gpu/drm/i915/gem/i915_gem_create.c|  2 +-
 drivers/gpu/drm/i915/gem/i915_gem_lmem.c  | 33 +-
 drivers/gpu/drm/i915/gem/i915_gem_lmem.h  |  5 ++
 drivers/gpu/drm/i915/gem/i915_gem_region.c| 13 +++-
 drivers/gpu/drm/i915/gem/i915_gem_region.h|  1 +
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c |  3 +-
 drivers/gpu/drm/i915/gem/i915_gem_stolen.c|  3 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c   |  6 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.h   |  1 +
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |  3 +-
 .../drm/i915/gem/selftests/i915_gem_mman.c|  8 +--
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 14 -
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 +-
 drivers/gpu/drm/i915/intel_memory_region.h|  1 +
 drivers/gpu/drm/i915/intel_region_ttm.c   |  4 +-
 .../drm/i915/selftests/intel_memory_region.c  | 63 ++-
 drivers/gpu/drm/i915/selftests/mock_region.c  |  1 +
 17 files changed, 143 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_create.c 
b/drivers/gpu/drm/i915/gem/i915_gem_create.c
index 93bf63bbaff1..51f92e4b1a69 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_create.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_create.c
@@ -90,7 +90,7 @@ i915_gem_setup(struct drm_i915_gem_object *obj, u64 size)
 */
flags = I915_BO_ALLOC_USER;
 
-   ret = mr->ops->init_object(mr, obj, size, flags);
+   ret = mr->ops->init_object(mr, obj, size, 0, flags);
if (ret)
return ret;
 
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_lmem.c 
b/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
index d539dffa1554..174a9e34ad93 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
@@ -71,11 +71,42 @@ bool i915_gem_object_is_lmem(struct drm_i915_gem_object 
*obj)
  mr->type == INTEL_MEMORY_STOLEN_LOCAL);
 }
 
+/**
+ * __i915_gem_object_create_lmem_with_ps - Create lmem object and force the
+ * minimum page size for the backing pages.
+ * @i915: The i915 instance.
+ * @size: The size in bytes for the object. Note that we need to round the size
+ * up depending on the @page_size. The final object size can be fished out from
+ * the drm GEM object.
+ * @page_size: The requested minimum page size in bytes for this object. The is
+ * useful if we need something bigger than the regions min_page_size due to 
some
+ * hw restriction, or in some very specialised cases where it needs to be
+ * smaller, where the internal fragmentation cost is too great when rounding up
+ * the object size.
+ * @flags: the optional BO allocation flags
+ *
+ * Note that this interface assumes you know what you are doing when forcing 
the
+ * page_size. If this is smaller than the regions min_page_size then it can
+ * never be inserted into any GTT, otherwise it might lead to undefined
+ * behaviour.
+ *
+ * Return: The object pointer, which might be an ERR_PTR in the case of 
failure.
+ */
+struct drm_i915_gem_object *
+__i915_gem_object_create_lmem_with_ps(struct drm_i915_private *i915,
+ resource_size_t size,
+ resource_size_t page_size,
+ unsigned int flags)
+{
+   return 
i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
+size, page_size, flags);
+}
+
 struct drm_i915_gem_object *
 i915_gem_object_create_lmem(struct drm_i915_private *i915,
resource_size_t size,
unsigned int flags)
 {
return 
i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
-size, flags);
+size, 0, flags);
 }
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_lmem.h 
b/drivers/gpu/drm/i915/gem/i915_gem_lmem.h
index ea76fd11ccb0..e98608cebbbc 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_lmem.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_lmem.h
@@ -21,6 +21,11 @@ i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
 
 bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj);
 
+struct drm_i915_gem_object *