All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 17:27 ` Matthew Auld
  0 siblings, 0 replies; 15+ messages in thread
From: Matthew Auld @ 2021-06-23 17:27 UTC (permalink / raw)
  To: intel-gfx; +Cc: Thomas Hellström, dri-devel

Looks like it got lost along the way, so add it back. This is needed for
the region query uAPI where we want to report a snapshot of how much
lmem is available.

This time around let's push it directly into the allocator, which
simplifies things, like not having to care about internal fragmentation,
or having to remember to track things for all possible interfaces that
might want to allocate or reserve pages.

v2(Thomas): add some more kernel doc

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
 drivers/gpu/drm/i915/i915_buddy.h             |  1 +
 drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
 drivers/gpu/drm/i915/i915_query.c             |  2 +-
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
 drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
 drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
 8 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
index 29dd7d0310c1..27cd2487a18f 100644
--- a/drivers/gpu/drm/i915/i915_buddy.c
+++ b/drivers/gpu/drm/i915/i915_buddy.c
@@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
 	size = round_down(size, chunk_size);
 
 	mm->size = size;
+	mm->avail = size;
 	mm->chunk_size = chunk_size;
 	mm->max_order = ilog2(size) - ilog2(chunk_size);
 
@@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
 		i915_block_free(mm, mm->roots[i]);
 	}
 
+	GEM_WARN_ON(mm->avail != mm->size);
+
 	kfree(mm->roots);
 	kfree(mm->free_list);
 	kmem_cache_destroy(mm->slab_blocks);
@@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
 		     struct i915_buddy_block *block)
 {
 	GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
+	mm->avail += i915_buddy_block_size(mm, block);
 	__i915_buddy_free(mm, block);
 }
 
@@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
 	}
 
 	mark_allocated(block);
+	mm->avail -= i915_buddy_block_size(mm, block);
 	kmemleak_update_trace(block);
 	return block;
 
@@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
 			}
 
 			mark_allocated(block);
+			mm->avail -= i915_buddy_block_size(mm, block);
 			list_add_tail(&block->link, &allocated);
 			continue;
 		}
diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
index 37f8c42071d1..feb7c1bb6244 100644
--- a/drivers/gpu/drm/i915/i915_buddy.h
+++ b/drivers/gpu/drm/i915/i915_buddy.h
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
 	/* Must be at least PAGE_SIZE */
 	u64 chunk_size;
 	u64 size;
+	u64 avail;
 };
 
 static inline u64
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index cc745751ac53..4765f220469e 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 		   atomic_read(&i915->mm.free_count),
 		   i915->mm.shrink_memory);
 	for_each_memory_region(mr, i915, id)
-		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
-			   mr->name, &mr->total, &mr->avail);
+		seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
+			   mr->name, &mr->total,
+			   intel_memory_region_get_avail(mr));
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
index e49da36c62fb..f10dcea94ac9 100644
--- a/drivers/gpu/drm/i915/i915_query.c
+++ b/drivers/gpu/drm/i915/i915_query.c
@@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
 		info.region.memory_class = mr->type;
 		info.region.memory_instance = mr->instance;
 		info.probed_size = mr->total;
-		info.unallocated_size = mr->avail;
+		info.unallocated_size = intel_memory_region_get_avail(mr);
 
 		if (__copy_to_user(info_ptr, &info, sizeof(info)))
 			return -EFAULT;
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
index fc7ad5c035b8..562d11edc5e4 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
@@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
 	return ret;
 }
 
+/**
+ * i915_ttm_buddy_man_avail - Get the currently available size
+ * @man: The buddy allocator ttm manager
+ *
+ * Return: The available size in bytes
+ */
+u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
+{
+	struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
+	struct i915_buddy_mm *mm = &bman->mm;
+
+	return mm->avail;
+}
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
index 26026213e20a..39f5b1a4c3e7 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
@@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
 int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
 			       u64 start, u64 size);
 
+u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
+
 #endif
diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
index df59f884d37c..d5edf088be48 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.c
+++ b/drivers/gpu/drm/i915/intel_memory_region.c
@@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
 	va_end(ap);
 }
 
+/**
+ * intel_memory_region_get_avail - Get the currently available size for the
+ * region
+ * @mr: The memory region
+ *
+ * Return: The available size in bytes
+ */
+u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
+{
+	if (mr->type == INTEL_MEMORY_LOCAL)
+		return i915_ttm_buddy_man_get_avail(mr->region_private);
+
+	return mr->avail;
+}
+
 static void __intel_memory_region_destroy(struct kref *kref)
 {
 	struct intel_memory_region *mem =
diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
index 2be8433d373a..6f7a073d5a70 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.h
+++ b/drivers/gpu/drm/i915/intel_memory_region.h
@@ -74,6 +74,7 @@ struct intel_memory_region {
 	resource_size_t io_start;
 	resource_size_t min_page_size;
 	resource_size_t total;
+	/* Do not access directly. Use the accessor instead. */
 	resource_size_t avail;
 
 	u16 type;
@@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
 int intel_memory_region_reserve(struct intel_memory_region *mem,
 				resource_size_t offset,
 				resource_size_t size);
+
+u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
+
 #endif
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 17:27 ` Matthew Auld
  0 siblings, 0 replies; 15+ messages in thread
From: Matthew Auld @ 2021-06-23 17:27 UTC (permalink / raw)
  To: intel-gfx; +Cc: Thomas Hellström, dri-devel

Looks like it got lost along the way, so add it back. This is needed for
the region query uAPI where we want to report a snapshot of how much
lmem is available.

This time around let's push it directly into the allocator, which
simplifies things, like not having to care about internal fragmentation,
or having to remember to track things for all possible interfaces that
might want to allocate or reserve pages.

v2(Thomas): add some more kernel doc

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
 drivers/gpu/drm/i915/i915_buddy.h             |  1 +
 drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
 drivers/gpu/drm/i915/i915_query.c             |  2 +-
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
 drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
 drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
 drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
 8 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
index 29dd7d0310c1..27cd2487a18f 100644
--- a/drivers/gpu/drm/i915/i915_buddy.c
+++ b/drivers/gpu/drm/i915/i915_buddy.c
@@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
 	size = round_down(size, chunk_size);
 
 	mm->size = size;
+	mm->avail = size;
 	mm->chunk_size = chunk_size;
 	mm->max_order = ilog2(size) - ilog2(chunk_size);
 
@@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
 		i915_block_free(mm, mm->roots[i]);
 	}
 
+	GEM_WARN_ON(mm->avail != mm->size);
+
 	kfree(mm->roots);
 	kfree(mm->free_list);
 	kmem_cache_destroy(mm->slab_blocks);
@@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
 		     struct i915_buddy_block *block)
 {
 	GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
+	mm->avail += i915_buddy_block_size(mm, block);
 	__i915_buddy_free(mm, block);
 }
 
@@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
 	}
 
 	mark_allocated(block);
+	mm->avail -= i915_buddy_block_size(mm, block);
 	kmemleak_update_trace(block);
 	return block;
 
@@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
 			}
 
 			mark_allocated(block);
+			mm->avail -= i915_buddy_block_size(mm, block);
 			list_add_tail(&block->link, &allocated);
 			continue;
 		}
diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
index 37f8c42071d1..feb7c1bb6244 100644
--- a/drivers/gpu/drm/i915/i915_buddy.h
+++ b/drivers/gpu/drm/i915/i915_buddy.h
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
 	/* Must be at least PAGE_SIZE */
 	u64 chunk_size;
 	u64 size;
+	u64 avail;
 };
 
 static inline u64
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index cc745751ac53..4765f220469e 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
 		   atomic_read(&i915->mm.free_count),
 		   i915->mm.shrink_memory);
 	for_each_memory_region(mr, i915, id)
-		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
-			   mr->name, &mr->total, &mr->avail);
+		seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
+			   mr->name, &mr->total,
+			   intel_memory_region_get_avail(mr));
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
index e49da36c62fb..f10dcea94ac9 100644
--- a/drivers/gpu/drm/i915/i915_query.c
+++ b/drivers/gpu/drm/i915/i915_query.c
@@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
 		info.region.memory_class = mr->type;
 		info.region.memory_instance = mr->instance;
 		info.probed_size = mr->total;
-		info.unallocated_size = mr->avail;
+		info.unallocated_size = intel_memory_region_get_avail(mr);
 
 		if (__copy_to_user(info_ptr, &info, sizeof(info)))
 			return -EFAULT;
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
index fc7ad5c035b8..562d11edc5e4 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
@@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
 	return ret;
 }
 
+/**
+ * i915_ttm_buddy_man_avail - Get the currently available size
+ * @man: The buddy allocator ttm manager
+ *
+ * Return: The available size in bytes
+ */
+u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
+{
+	struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
+	struct i915_buddy_mm *mm = &bman->mm;
+
+	return mm->avail;
+}
diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
index 26026213e20a..39f5b1a4c3e7 100644
--- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
+++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
@@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
 int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
 			       u64 start, u64 size);
 
+u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
+
 #endif
diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
index df59f884d37c..d5edf088be48 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.c
+++ b/drivers/gpu/drm/i915/intel_memory_region.c
@@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
 	va_end(ap);
 }
 
+/**
+ * intel_memory_region_get_avail - Get the currently available size for the
+ * region
+ * @mr: The memory region
+ *
+ * Return: The available size in bytes
+ */
+u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
+{
+	if (mr->type == INTEL_MEMORY_LOCAL)
+		return i915_ttm_buddy_man_get_avail(mr->region_private);
+
+	return mr->avail;
+}
+
 static void __intel_memory_region_destroy(struct kref *kref)
 {
 	struct intel_memory_region *mem =
diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
index 2be8433d373a..6f7a073d5a70 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.h
+++ b/drivers/gpu/drm/i915/intel_memory_region.h
@@ -74,6 +74,7 @@ struct intel_memory_region {
 	resource_size_t io_start;
 	resource_size_t min_page_size;
 	resource_size_t total;
+	/* Do not access directly. Use the accessor instead. */
 	resource_size_t avail;
 
 	u16 type;
@@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
 int intel_memory_region_reserve(struct intel_memory_region *mem,
 				resource_size_t offset,
 				resource_size_t size);
+
+u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
+
 #endif
-- 
2.26.3

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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: add back the avail tracking
  2021-06-23 17:27 ` [Intel-gfx] " Matthew Auld
  (?)
@ 2021-06-23 18:09 ` Patchwork
  -1 siblings, 0 replies; 15+ messages in thread
From: Patchwork @ 2021-06-23 18:09 UTC (permalink / raw)
  To: Matthew Auld; +Cc: intel-gfx


[-- Attachment #1.1: Type: text/plain, Size: 3956 bytes --]

== Series Details ==

Series: drm/i915: add back the avail tracking
URL   : https://patchwork.freedesktop.org/series/91826/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_10268 -> Patchwork_20445
====================================================

Summary
-------

  **FAILURE**

  Serious unknown changes coming with Patchwork_20445 absolutely need to be
  verified manually.
  
  If you think the reported changes have nothing to do with the changes
  introduced in Patchwork_20445, please notify your bug team to allow them
  to document this new failure mode, which will reduce false positives in CI.

  External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/index.html

Possible new issues
-------------------

  Here are the unknown changes that may have been introduced in Patchwork_20445:

### IGT changes ###

#### Possible regressions ####

  * igt@core_hotunplug@unbind-rebind:
    - fi-bwr-2160:        [PASS][1] -> [FAIL][2]
   [1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10268/fi-bwr-2160/igt@core_hotunplug@unbind-rebind.html
   [2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-bwr-2160/igt@core_hotunplug@unbind-rebind.html

  
Known issues
------------

  Here are the changes found in Patchwork_20445 that come from known issues:

### IGT changes ###

#### Issues hit ####

  * igt@amdgpu/amd_basic@cs-sdma:
    - fi-kbl-guc:         NOTRUN -> [SKIP][3] ([fdo#109271]) +59 similar issues
   [3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-guc/igt@amdgpu/amd_basic@cs-sdma.html

  * igt@amdgpu/amd_prime@i915-to-amd:
    - fi-kbl-soraka:      NOTRUN -> [SKIP][4] ([fdo#109271]) +1 similar issue
   [4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-soraka/igt@amdgpu/amd_prime@i915-to-amd.html

  * igt@gem_huc_copy@huc-copy:
    - fi-kbl-guc:         NOTRUN -> [SKIP][5] ([fdo#109271] / [i915#2190])
   [5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-guc/igt@gem_huc_copy@huc-copy.html

  * igt@i915_module_load@reload:
    - fi-kbl-soraka:      [PASS][6] -> [DMESG-WARN][7] ([i915#1982])
   [6]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_10268/fi-kbl-soraka/igt@i915_module_load@reload.html
   [7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-soraka/igt@i915_module_load@reload.html

  * igt@kms_chamelium@vga-hpd-fast:
    - fi-kbl-guc:         NOTRUN -> [SKIP][8] ([fdo#109271] / [fdo#111827]) +8 similar issues
   [8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-guc/igt@kms_chamelium@vga-hpd-fast.html

  * igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d:
    - fi-kbl-guc:         NOTRUN -> [SKIP][9] ([fdo#109271] / [i915#533])
   [9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-guc/igt@kms_pipe_crc_basic@compare-crc-sanitycheck-pipe-d.html

  
  [fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
  [fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
  [i915#1982]: https://gitlab.freedesktop.org/drm/intel/issues/1982
  [i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
  [i915#533]: https://gitlab.freedesktop.org/drm/intel/issues/533


Participating hosts (41 -> 38)
------------------------------

  Additional (1): fi-kbl-guc 
  Missing    (4): fi-ilk-m540 fi-bdw-samus fi-bsw-cyan bat-adlp-4 


Build changes
-------------

  * Linux: CI_DRM_10268 -> Patchwork_20445

  CI-20190529: 20190529
  CI_DRM_10268: 0e0529132a50160a0e8bd0aa9608226445a3299b @ git://anongit.freedesktop.org/gfx-ci/linux
  IGT_6117: 3ba0a02404f243d6d8f232c6215163cc4b0fd699 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
  Patchwork_20445: 3a58986e9d90be65deec35d265030178ef26fb40 @ git://anongit.freedesktop.org/gfx-ci/linux


== Linux commits ==

3a58986e9d90 drm/i915: add back the avail tracking

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/index.html

[-- Attachment #1.2: Type: text/html, Size: 5002 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
  2021-06-23 17:27 ` [Intel-gfx] " Matthew Auld
@ 2021-06-23 19:15   ` Daniel Vetter
  -1 siblings, 0 replies; 15+ messages in thread
From: Daniel Vetter @ 2021-06-23 19:15 UTC (permalink / raw)
  To: Matthew Auld; +Cc: Thomas Hellström, intel-gfx, dri-devel

On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> Looks like it got lost along the way, so add it back. This is needed for
> the region query uAPI where we want to report a snapshot of how much
> lmem is available.
> 
> This time around let's push it directly into the allocator, which
> simplifies things, like not having to care about internal fragmentation,
> or having to remember to track things for all possible interfaces that
> might want to allocate or reserve pages.
> 
> v2(Thomas): add some more kernel doc
> 
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

Since this is uapi, do umds use this? Or just igt?

Please record both the umd user for this and the igts that verifies this
is not nonsense to the commit message. We need to be much better with
keeping records for our uapi additions, there's been some really badly
justified uapi in the past that turned out to be for testcases only.
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
>  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
>  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
>  drivers/gpu/drm/i915/i915_query.c             |  2 +-
>  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
>  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
>  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
>  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
>  8 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> index 29dd7d0310c1..27cd2487a18f 100644
> --- a/drivers/gpu/drm/i915/i915_buddy.c
> +++ b/drivers/gpu/drm/i915/i915_buddy.c
> @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
>  	size = round_down(size, chunk_size);
>  
>  	mm->size = size;
> +	mm->avail = size;
>  	mm->chunk_size = chunk_size;
>  	mm->max_order = ilog2(size) - ilog2(chunk_size);
>  
> @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
>  		i915_block_free(mm, mm->roots[i]);
>  	}
>  
> +	GEM_WARN_ON(mm->avail != mm->size);
> +
>  	kfree(mm->roots);
>  	kfree(mm->free_list);
>  	kmem_cache_destroy(mm->slab_blocks);
> @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
>  		     struct i915_buddy_block *block)
>  {
>  	GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> +	mm->avail += i915_buddy_block_size(mm, block);
>  	__i915_buddy_free(mm, block);
>  }
>  
> @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
>  	}
>  
>  	mark_allocated(block);
> +	mm->avail -= i915_buddy_block_size(mm, block);
>  	kmemleak_update_trace(block);
>  	return block;
>  
> @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
>  			}
>  
>  			mark_allocated(block);
> +			mm->avail -= i915_buddy_block_size(mm, block);
>  			list_add_tail(&block->link, &allocated);
>  			continue;
>  		}
> diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> index 37f8c42071d1..feb7c1bb6244 100644
> --- a/drivers/gpu/drm/i915/i915_buddy.h
> +++ b/drivers/gpu/drm/i915/i915_buddy.h
> @@ -70,6 +70,7 @@ struct i915_buddy_mm {
>  	/* Must be at least PAGE_SIZE */
>  	u64 chunk_size;
>  	u64 size;
> +	u64 avail;
>  };
>  
>  static inline u64
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index cc745751ac53..4765f220469e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
>  		   atomic_read(&i915->mm.free_count),
>  		   i915->mm.shrink_memory);
>  	for_each_memory_region(mr, i915, id)
> -		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> -			   mr->name, &mr->total, &mr->avail);
> +		seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> +			   mr->name, &mr->total,
> +			   intel_memory_region_get_avail(mr));
>  
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> index e49da36c62fb..f10dcea94ac9 100644
> --- a/drivers/gpu/drm/i915/i915_query.c
> +++ b/drivers/gpu/drm/i915/i915_query.c
> @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
>  		info.region.memory_class = mr->type;
>  		info.region.memory_instance = mr->instance;
>  		info.probed_size = mr->total;
> -		info.unallocated_size = mr->avail;
> +		info.unallocated_size = intel_memory_region_get_avail(mr);
>  
>  		if (__copy_to_user(info_ptr, &info, sizeof(info)))
>  			return -EFAULT;
> diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> index fc7ad5c035b8..562d11edc5e4 100644
> --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
>  	return ret;
>  }
>  
> +/**
> + * i915_ttm_buddy_man_avail - Get the currently available size
> + * @man: The buddy allocator ttm manager
> + *
> + * Return: The available size in bytes
> + */
> +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> +{
> +	struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> +	struct i915_buddy_mm *mm = &bman->mm;
> +
> +	return mm->avail;
> +}
> diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> index 26026213e20a..39f5b1a4c3e7 100644
> --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
>  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
>  			       u64 start, u64 size);
>  
> +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> +
>  #endif
> diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> index df59f884d37c..d5edf088be48 100644
> --- a/drivers/gpu/drm/i915/intel_memory_region.c
> +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
>  	va_end(ap);
>  }
>  
> +/**
> + * intel_memory_region_get_avail - Get the currently available size for the
> + * region
> + * @mr: The memory region
> + *
> + * Return: The available size in bytes
> + */
> +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> +{
> +	if (mr->type == INTEL_MEMORY_LOCAL)
> +		return i915_ttm_buddy_man_get_avail(mr->region_private);
> +
> +	return mr->avail;
> +}
> +
>  static void __intel_memory_region_destroy(struct kref *kref)
>  {
>  	struct intel_memory_region *mem =
> diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> index 2be8433d373a..6f7a073d5a70 100644
> --- a/drivers/gpu/drm/i915/intel_memory_region.h
> +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> @@ -74,6 +74,7 @@ struct intel_memory_region {
>  	resource_size_t io_start;
>  	resource_size_t min_page_size;
>  	resource_size_t total;
> +	/* Do not access directly. Use the accessor instead. */
>  	resource_size_t avail;
>  
>  	u16 type;
> @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
>  int intel_memory_region_reserve(struct intel_memory_region *mem,
>  				resource_size_t offset,
>  				resource_size_t size);
> +
> +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> +
>  #endif
> -- 
> 2.26.3
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 19:15   ` Daniel Vetter
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel Vetter @ 2021-06-23 19:15 UTC (permalink / raw)
  To: Matthew Auld; +Cc: Thomas Hellström, intel-gfx, dri-devel

On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> Looks like it got lost along the way, so add it back. This is needed for
> the region query uAPI where we want to report a snapshot of how much
> lmem is available.
> 
> This time around let's push it directly into the allocator, which
> simplifies things, like not having to care about internal fragmentation,
> or having to remember to track things for all possible interfaces that
> might want to allocate or reserve pages.
> 
> v2(Thomas): add some more kernel doc
> 
> Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

Since this is uapi, do umds use this? Or just igt?

Please record both the umd user for this and the igts that verifies this
is not nonsense to the commit message. We need to be much better with
keeping records for our uapi additions, there's been some really badly
justified uapi in the past that turned out to be for testcases only.
-Daniel

> ---
>  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
>  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
>  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
>  drivers/gpu/drm/i915/i915_query.c             |  2 +-
>  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
>  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
>  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
>  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
>  8 files changed, 45 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> index 29dd7d0310c1..27cd2487a18f 100644
> --- a/drivers/gpu/drm/i915/i915_buddy.c
> +++ b/drivers/gpu/drm/i915/i915_buddy.c
> @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
>  	size = round_down(size, chunk_size);
>  
>  	mm->size = size;
> +	mm->avail = size;
>  	mm->chunk_size = chunk_size;
>  	mm->max_order = ilog2(size) - ilog2(chunk_size);
>  
> @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
>  		i915_block_free(mm, mm->roots[i]);
>  	}
>  
> +	GEM_WARN_ON(mm->avail != mm->size);
> +
>  	kfree(mm->roots);
>  	kfree(mm->free_list);
>  	kmem_cache_destroy(mm->slab_blocks);
> @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
>  		     struct i915_buddy_block *block)
>  {
>  	GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> +	mm->avail += i915_buddy_block_size(mm, block);
>  	__i915_buddy_free(mm, block);
>  }
>  
> @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
>  	}
>  
>  	mark_allocated(block);
> +	mm->avail -= i915_buddy_block_size(mm, block);
>  	kmemleak_update_trace(block);
>  	return block;
>  
> @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
>  			}
>  
>  			mark_allocated(block);
> +			mm->avail -= i915_buddy_block_size(mm, block);
>  			list_add_tail(&block->link, &allocated);
>  			continue;
>  		}
> diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> index 37f8c42071d1..feb7c1bb6244 100644
> --- a/drivers/gpu/drm/i915/i915_buddy.h
> +++ b/drivers/gpu/drm/i915/i915_buddy.h
> @@ -70,6 +70,7 @@ struct i915_buddy_mm {
>  	/* Must be at least PAGE_SIZE */
>  	u64 chunk_size;
>  	u64 size;
> +	u64 avail;
>  };
>  
>  static inline u64
> diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> index cc745751ac53..4765f220469e 100644
> --- a/drivers/gpu/drm/i915/i915_debugfs.c
> +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
>  		   atomic_read(&i915->mm.free_count),
>  		   i915->mm.shrink_memory);
>  	for_each_memory_region(mr, i915, id)
> -		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> -			   mr->name, &mr->total, &mr->avail);
> +		seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> +			   mr->name, &mr->total,
> +			   intel_memory_region_get_avail(mr));
>  
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> index e49da36c62fb..f10dcea94ac9 100644
> --- a/drivers/gpu/drm/i915/i915_query.c
> +++ b/drivers/gpu/drm/i915/i915_query.c
> @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
>  		info.region.memory_class = mr->type;
>  		info.region.memory_instance = mr->instance;
>  		info.probed_size = mr->total;
> -		info.unallocated_size = mr->avail;
> +		info.unallocated_size = intel_memory_region_get_avail(mr);
>  
>  		if (__copy_to_user(info_ptr, &info, sizeof(info)))
>  			return -EFAULT;
> diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> index fc7ad5c035b8..562d11edc5e4 100644
> --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
>  	return ret;
>  }
>  
> +/**
> + * i915_ttm_buddy_man_avail - Get the currently available size
> + * @man: The buddy allocator ttm manager
> + *
> + * Return: The available size in bytes
> + */
> +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> +{
> +	struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> +	struct i915_buddy_mm *mm = &bman->mm;
> +
> +	return mm->avail;
> +}
> diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> index 26026213e20a..39f5b1a4c3e7 100644
> --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
>  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
>  			       u64 start, u64 size);
>  
> +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> +
>  #endif
> diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> index df59f884d37c..d5edf088be48 100644
> --- a/drivers/gpu/drm/i915/intel_memory_region.c
> +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
>  	va_end(ap);
>  }
>  
> +/**
> + * intel_memory_region_get_avail - Get the currently available size for the
> + * region
> + * @mr: The memory region
> + *
> + * Return: The available size in bytes
> + */
> +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> +{
> +	if (mr->type == INTEL_MEMORY_LOCAL)
> +		return i915_ttm_buddy_man_get_avail(mr->region_private);
> +
> +	return mr->avail;
> +}
> +
>  static void __intel_memory_region_destroy(struct kref *kref)
>  {
>  	struct intel_memory_region *mem =
> diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> index 2be8433d373a..6f7a073d5a70 100644
> --- a/drivers/gpu/drm/i915/intel_memory_region.h
> +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> @@ -74,6 +74,7 @@ struct intel_memory_region {
>  	resource_size_t io_start;
>  	resource_size_t min_page_size;
>  	resource_size_t total;
> +	/* Do not access directly. Use the accessor instead. */
>  	resource_size_t avail;
>  
>  	u16 type;
> @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
>  int intel_memory_region_reserve(struct intel_memory_region *mem,
>  				resource_size_t offset,
>  				resource_size_t size);
> +
> +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> +
>  #endif
> -- 
> 2.26.3
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
  2021-06-23 19:15   ` Daniel Vetter
@ 2021-06-23 19:35     ` Matthew Auld
  -1 siblings, 0 replies; 15+ messages in thread
From: Matthew Auld @ 2021-06-23 19:35 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Jason Ekstrand, Thomas Hellström,
	Intel Graphics Development, Matthew Auld, ML dri-devel

On Wed, 23 Jun 2021 at 20:15, Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> > Looks like it got lost along the way, so add it back. This is needed for
> > the region query uAPI where we want to report a snapshot of how much
> > lmem is available.
> >
> > This time around let's push it directly into the allocator, which
> > simplifies things, like not having to care about internal fragmentation,
> > or having to remember to track things for all possible interfaces that
> > might want to allocate or reserve pages.
> >
> > v2(Thomas): add some more kernel doc
> >
> > Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>
> Since this is uapi, do umds use this? Or just igt?
>
> Please record both the umd user for this and the igts that verifies this
> is not nonsense to the commit message. We need to be much better with
> keeping records for our uapi additions, there's been some really badly
> justified uapi in the past that turned out to be for testcases only.

For the userspace justification, I pinged you and Jason about that in
the previous thread, since it's not completely clear if real userspace
even cares about this. I can maybe just limit it to debugfs?

> -Daniel
>
> > ---
> >  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
> >  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
> >  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
> >  drivers/gpu/drm/i915/i915_query.c             |  2 +-
> >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
> >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
> >  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
> >  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
> >  8 files changed, 45 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> > index 29dd7d0310c1..27cd2487a18f 100644
> > --- a/drivers/gpu/drm/i915/i915_buddy.c
> > +++ b/drivers/gpu/drm/i915/i915_buddy.c
> > @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
> >       size = round_down(size, chunk_size);
> >
> >       mm->size = size;
> > +     mm->avail = size;
> >       mm->chunk_size = chunk_size;
> >       mm->max_order = ilog2(size) - ilog2(chunk_size);
> >
> > @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
> >               i915_block_free(mm, mm->roots[i]);
> >       }
> >
> > +     GEM_WARN_ON(mm->avail != mm->size);
> > +
> >       kfree(mm->roots);
> >       kfree(mm->free_list);
> >       kmem_cache_destroy(mm->slab_blocks);
> > @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
> >                    struct i915_buddy_block *block)
> >  {
> >       GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> > +     mm->avail += i915_buddy_block_size(mm, block);
> >       __i915_buddy_free(mm, block);
> >  }
> >
> > @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
> >       }
> >
> >       mark_allocated(block);
> > +     mm->avail -= i915_buddy_block_size(mm, block);
> >       kmemleak_update_trace(block);
> >       return block;
> >
> > @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
> >                       }
> >
> >                       mark_allocated(block);
> > +                     mm->avail -= i915_buddy_block_size(mm, block);
> >                       list_add_tail(&block->link, &allocated);
> >                       continue;
> >               }
> > diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> > index 37f8c42071d1..feb7c1bb6244 100644
> > --- a/drivers/gpu/drm/i915/i915_buddy.h
> > +++ b/drivers/gpu/drm/i915/i915_buddy.h
> > @@ -70,6 +70,7 @@ struct i915_buddy_mm {
> >       /* Must be at least PAGE_SIZE */
> >       u64 chunk_size;
> >       u64 size;
> > +     u64 avail;
> >  };
> >
> >  static inline u64
> > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> > index cc745751ac53..4765f220469e 100644
> > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
> >                  atomic_read(&i915->mm.free_count),
> >                  i915->mm.shrink_memory);
> >       for_each_memory_region(mr, i915, id)
> > -             seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> > -                        mr->name, &mr->total, &mr->avail);
> > +             seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> > +                        mr->name, &mr->total,
> > +                        intel_memory_region_get_avail(mr));
> >
> >       return 0;
> >  }
> > diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> > index e49da36c62fb..f10dcea94ac9 100644
> > --- a/drivers/gpu/drm/i915/i915_query.c
> > +++ b/drivers/gpu/drm/i915/i915_query.c
> > @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
> >               info.region.memory_class = mr->type;
> >               info.region.memory_instance = mr->instance;
> >               info.probed_size = mr->total;
> > -             info.unallocated_size = mr->avail;
> > +             info.unallocated_size = intel_memory_region_get_avail(mr);
> >
> >               if (__copy_to_user(info_ptr, &info, sizeof(info)))
> >                       return -EFAULT;
> > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > index fc7ad5c035b8..562d11edc5e4 100644
> > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> >       return ret;
> >  }
> >
> > +/**
> > + * i915_ttm_buddy_man_avail - Get the currently available size
> > + * @man: The buddy allocator ttm manager
> > + *
> > + * Return: The available size in bytes
> > + */
> > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> > +{
> > +     struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> > +     struct i915_buddy_mm *mm = &bman->mm;
> > +
> > +     return mm->avail;
> > +}
> > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > index 26026213e20a..39f5b1a4c3e7 100644
> > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
> >  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> >                              u64 start, u64 size);
> >
> > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> > +
> >  #endif
> > diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> > index df59f884d37c..d5edf088be48 100644
> > --- a/drivers/gpu/drm/i915/intel_memory_region.c
> > +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> > @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
> >       va_end(ap);
> >  }
> >
> > +/**
> > + * intel_memory_region_get_avail - Get the currently available size for the
> > + * region
> > + * @mr: The memory region
> > + *
> > + * Return: The available size in bytes
> > + */
> > +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> > +{
> > +     if (mr->type == INTEL_MEMORY_LOCAL)
> > +             return i915_ttm_buddy_man_get_avail(mr->region_private);
> > +
> > +     return mr->avail;
> > +}
> > +
> >  static void __intel_memory_region_destroy(struct kref *kref)
> >  {
> >       struct intel_memory_region *mem =
> > diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> > index 2be8433d373a..6f7a073d5a70 100644
> > --- a/drivers/gpu/drm/i915/intel_memory_region.h
> > +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> > @@ -74,6 +74,7 @@ struct intel_memory_region {
> >       resource_size_t io_start;
> >       resource_size_t min_page_size;
> >       resource_size_t total;
> > +     /* Do not access directly. Use the accessor instead. */
> >       resource_size_t avail;
> >
> >       u16 type;
> > @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
> >  int intel_memory_region_reserve(struct intel_memory_region *mem,
> >                               resource_size_t offset,
> >                               resource_size_t size);
> > +
> > +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> > +
> >  #endif
> > --
> > 2.26.3
> >
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 19:35     ` Matthew Auld
  0 siblings, 0 replies; 15+ messages in thread
From: Matthew Auld @ 2021-06-23 19:35 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Thomas Hellström, Intel Graphics Development, Matthew Auld,
	ML dri-devel

On Wed, 23 Jun 2021 at 20:15, Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> > Looks like it got lost along the way, so add it back. This is needed for
> > the region query uAPI where we want to report a snapshot of how much
> > lmem is available.
> >
> > This time around let's push it directly into the allocator, which
> > simplifies things, like not having to care about internal fragmentation,
> > or having to remember to track things for all possible interfaces that
> > might want to allocate or reserve pages.
> >
> > v2(Thomas): add some more kernel doc
> >
> > Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>
> Since this is uapi, do umds use this? Or just igt?
>
> Please record both the umd user for this and the igts that verifies this
> is not nonsense to the commit message. We need to be much better with
> keeping records for our uapi additions, there's been some really badly
> justified uapi in the past that turned out to be for testcases only.

For the userspace justification, I pinged you and Jason about that in
the previous thread, since it's not completely clear if real userspace
even cares about this. I can maybe just limit it to debugfs?

> -Daniel
>
> > ---
> >  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
> >  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
> >  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
> >  drivers/gpu/drm/i915/i915_query.c             |  2 +-
> >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
> >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
> >  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
> >  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
> >  8 files changed, 45 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> > index 29dd7d0310c1..27cd2487a18f 100644
> > --- a/drivers/gpu/drm/i915/i915_buddy.c
> > +++ b/drivers/gpu/drm/i915/i915_buddy.c
> > @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
> >       size = round_down(size, chunk_size);
> >
> >       mm->size = size;
> > +     mm->avail = size;
> >       mm->chunk_size = chunk_size;
> >       mm->max_order = ilog2(size) - ilog2(chunk_size);
> >
> > @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
> >               i915_block_free(mm, mm->roots[i]);
> >       }
> >
> > +     GEM_WARN_ON(mm->avail != mm->size);
> > +
> >       kfree(mm->roots);
> >       kfree(mm->free_list);
> >       kmem_cache_destroy(mm->slab_blocks);
> > @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
> >                    struct i915_buddy_block *block)
> >  {
> >       GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> > +     mm->avail += i915_buddy_block_size(mm, block);
> >       __i915_buddy_free(mm, block);
> >  }
> >
> > @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
> >       }
> >
> >       mark_allocated(block);
> > +     mm->avail -= i915_buddy_block_size(mm, block);
> >       kmemleak_update_trace(block);
> >       return block;
> >
> > @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
> >                       }
> >
> >                       mark_allocated(block);
> > +                     mm->avail -= i915_buddy_block_size(mm, block);
> >                       list_add_tail(&block->link, &allocated);
> >                       continue;
> >               }
> > diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> > index 37f8c42071d1..feb7c1bb6244 100644
> > --- a/drivers/gpu/drm/i915/i915_buddy.h
> > +++ b/drivers/gpu/drm/i915/i915_buddy.h
> > @@ -70,6 +70,7 @@ struct i915_buddy_mm {
> >       /* Must be at least PAGE_SIZE */
> >       u64 chunk_size;
> >       u64 size;
> > +     u64 avail;
> >  };
> >
> >  static inline u64
> > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> > index cc745751ac53..4765f220469e 100644
> > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
> >                  atomic_read(&i915->mm.free_count),
> >                  i915->mm.shrink_memory);
> >       for_each_memory_region(mr, i915, id)
> > -             seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> > -                        mr->name, &mr->total, &mr->avail);
> > +             seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> > +                        mr->name, &mr->total,
> > +                        intel_memory_region_get_avail(mr));
> >
> >       return 0;
> >  }
> > diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> > index e49da36c62fb..f10dcea94ac9 100644
> > --- a/drivers/gpu/drm/i915/i915_query.c
> > +++ b/drivers/gpu/drm/i915/i915_query.c
> > @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
> >               info.region.memory_class = mr->type;
> >               info.region.memory_instance = mr->instance;
> >               info.probed_size = mr->total;
> > -             info.unallocated_size = mr->avail;
> > +             info.unallocated_size = intel_memory_region_get_avail(mr);
> >
> >               if (__copy_to_user(info_ptr, &info, sizeof(info)))
> >                       return -EFAULT;
> > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > index fc7ad5c035b8..562d11edc5e4 100644
> > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> >       return ret;
> >  }
> >
> > +/**
> > + * i915_ttm_buddy_man_avail - Get the currently available size
> > + * @man: The buddy allocator ttm manager
> > + *
> > + * Return: The available size in bytes
> > + */
> > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> > +{
> > +     struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> > +     struct i915_buddy_mm *mm = &bman->mm;
> > +
> > +     return mm->avail;
> > +}
> > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > index 26026213e20a..39f5b1a4c3e7 100644
> > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
> >  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> >                              u64 start, u64 size);
> >
> > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> > +
> >  #endif
> > diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> > index df59f884d37c..d5edf088be48 100644
> > --- a/drivers/gpu/drm/i915/intel_memory_region.c
> > +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> > @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
> >       va_end(ap);
> >  }
> >
> > +/**
> > + * intel_memory_region_get_avail - Get the currently available size for the
> > + * region
> > + * @mr: The memory region
> > + *
> > + * Return: The available size in bytes
> > + */
> > +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> > +{
> > +     if (mr->type == INTEL_MEMORY_LOCAL)
> > +             return i915_ttm_buddy_man_get_avail(mr->region_private);
> > +
> > +     return mr->avail;
> > +}
> > +
> >  static void __intel_memory_region_destroy(struct kref *kref)
> >  {
> >       struct intel_memory_region *mem =
> > diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> > index 2be8433d373a..6f7a073d5a70 100644
> > --- a/drivers/gpu/drm/i915/intel_memory_region.h
> > +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> > @@ -74,6 +74,7 @@ struct intel_memory_region {
> >       resource_size_t io_start;
> >       resource_size_t min_page_size;
> >       resource_size_t total;
> > +     /* Do not access directly. Use the accessor instead. */
> >       resource_size_t avail;
> >
> >       u16 type;
> > @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
> >  int intel_memory_region_reserve(struct intel_memory_region *mem,
> >                               resource_size_t offset,
> >                               resource_size_t size);
> > +
> > +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> > +
> >  #endif
> > --
> > 2.26.3
> >
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
>
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] drm/i915: add back the avail tracking
  2021-06-23 17:27 ` [Intel-gfx] " Matthew Auld
  (?)
@ 2021-06-23 20:05   ` kernel test robot
  -1 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 20:05 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx; +Cc: Thomas Hellström, kbuild-all, dri-devel

[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 66091 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 20:05   ` kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 20:05 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx; +Cc: Thomas Hellström, kbuild-all, dri-devel

[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 66091 bytes --]

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 20:05   ` kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 20:05 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 1978 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-allyesconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        make W=1 ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 66091 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] drm/i915: add back the avail tracking
  2021-06-23 17:27 ` [Intel-gfx] " Matthew Auld
  (?)
@ 2021-06-23 21:16   ` kernel test robot
  -1 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 21:16 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx
  Cc: clang-built-linux, kbuild-all, dri-devel, Thomas Hellström

[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-randconfig-a002-20210622 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project b259740801d3515810ecc15bf0c24b0d476a1608)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43128 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 21:16   ` kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 21:16 UTC (permalink / raw)
  To: Matthew Auld, intel-gfx
  Cc: clang-built-linux, kbuild-all, dri-devel, Thomas Hellström

[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-randconfig-a002-20210622 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project b259740801d3515810ecc15bf0c24b0d476a1608)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 43128 bytes --]

[-- Attachment #3: Type: text/plain, Size: 160 bytes --]

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] drm/i915: add back the avail tracking
@ 2021-06-23 21:16   ` kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2021-06-23 21:16 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]

Hi Matthew,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-tip/drm-tip]
[cannot apply to drm-intel/for-linux-next drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next drm/drm-next v5.13-rc7 next-20210623]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
base:   git://anongit.freedesktop.org/drm/drm-tip drm-tip
config: x86_64-randconfig-a002-20210622 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project b259740801d3515810ecc15bf0c24b0d476a1608)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install x86_64 cross compiling tool for clang build
        # apt-get install binutils-x86-64-linux-gnu
        # https://github.com/0day-ci/linux/commit/e0f10761566f8471fa72a8791ff116d07420bd81
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Matthew-Auld/drm-i915-add-back-the-avail-tracking/20210624-012853
        git checkout e0f10761566f8471fa72a8791ff116d07420bd81
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/i915/i915_ttm_buddy_manager.c:256: warning: expecting prototype for i915_ttm_buddy_man_avail(). Prototype was for i915_ttm_buddy_man_get_avail() instead


vim +256 drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

   248	
   249	/**
   250	 * i915_ttm_buddy_man_avail - Get the currently available size
   251	 * @man: The buddy allocator ttm manager
   252	 *
   253	 * Return: The available size in bytes
   254	 */
   255	u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
 > 256	{

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 43128 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
  2021-06-23 19:35     ` Matthew Auld
@ 2021-06-24  8:50       ` Daniel Vetter
  -1 siblings, 0 replies; 15+ messages in thread
From: Daniel Vetter @ 2021-06-24  8:50 UTC (permalink / raw)
  To: Matthew Auld
  Cc: Thomas Hellström, Jason Ekstrand,
	Intel Graphics Development, ML dri-devel, Matthew Auld

On Wed, Jun 23, 2021 at 08:35:30PM +0100, Matthew Auld wrote:
> On Wed, 23 Jun 2021 at 20:15, Daniel Vetter <daniel@ffwll.ch> wrote:
> >
> > On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> > > Looks like it got lost along the way, so add it back. This is needed for
> > > the region query uAPI where we want to report a snapshot of how much
> > > lmem is available.
> > >
> > > This time around let's push it directly into the allocator, which
> > > simplifies things, like not having to care about internal fragmentation,
> > > or having to remember to track things for all possible interfaces that
> > > might want to allocate or reserve pages.
> > >
> > > v2(Thomas): add some more kernel doc
> > >
> > > Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> > > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > > Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> >
> > Since this is uapi, do umds use this? Or just igt?
> >
> > Please record both the umd user for this and the igts that verifies this
> > is not nonsense to the commit message. We need to be much better with
> > keeping records for our uapi additions, there's been some really badly
> > justified uapi in the past that turned out to be for testcases only.
> 
> For the userspace justification, I pinged you and Jason about that in
> the previous thread, since it's not completely clear if real userspace
> even cares about this. I can maybe just limit it to debugfs?

Sorry I missed that ping. If it's just for igt then debugfs should be good
enough. Otherwise I'd do a quick check on the internal code repos and
maybe ping Jason on irc if he misses this, just in case we've overlooked
something.
-Daniel

> 
> > -Daniel
> >
> > > ---
> > >  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
> > >  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
> > >  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
> > >  drivers/gpu/drm/i915/i915_query.c             |  2 +-
> > >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
> > >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
> > >  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
> > >  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
> > >  8 files changed, 45 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> > > index 29dd7d0310c1..27cd2487a18f 100644
> > > --- a/drivers/gpu/drm/i915/i915_buddy.c
> > > +++ b/drivers/gpu/drm/i915/i915_buddy.c
> > > @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
> > >       size = round_down(size, chunk_size);
> > >
> > >       mm->size = size;
> > > +     mm->avail = size;
> > >       mm->chunk_size = chunk_size;
> > >       mm->max_order = ilog2(size) - ilog2(chunk_size);
> > >
> > > @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
> > >               i915_block_free(mm, mm->roots[i]);
> > >       }
> > >
> > > +     GEM_WARN_ON(mm->avail != mm->size);
> > > +
> > >       kfree(mm->roots);
> > >       kfree(mm->free_list);
> > >       kmem_cache_destroy(mm->slab_blocks);
> > > @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
> > >                    struct i915_buddy_block *block)
> > >  {
> > >       GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> > > +     mm->avail += i915_buddy_block_size(mm, block);
> > >       __i915_buddy_free(mm, block);
> > >  }
> > >
> > > @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
> > >       }
> > >
> > >       mark_allocated(block);
> > > +     mm->avail -= i915_buddy_block_size(mm, block);
> > >       kmemleak_update_trace(block);
> > >       return block;
> > >
> > > @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
> > >                       }
> > >
> > >                       mark_allocated(block);
> > > +                     mm->avail -= i915_buddy_block_size(mm, block);
> > >                       list_add_tail(&block->link, &allocated);
> > >                       continue;
> > >               }
> > > diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> > > index 37f8c42071d1..feb7c1bb6244 100644
> > > --- a/drivers/gpu/drm/i915/i915_buddy.h
> > > +++ b/drivers/gpu/drm/i915/i915_buddy.h
> > > @@ -70,6 +70,7 @@ struct i915_buddy_mm {
> > >       /* Must be at least PAGE_SIZE */
> > >       u64 chunk_size;
> > >       u64 size;
> > > +     u64 avail;
> > >  };
> > >
> > >  static inline u64
> > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> > > index cc745751ac53..4765f220469e 100644
> > > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > > @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
> > >                  atomic_read(&i915->mm.free_count),
> > >                  i915->mm.shrink_memory);
> > >       for_each_memory_region(mr, i915, id)
> > > -             seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> > > -                        mr->name, &mr->total, &mr->avail);
> > > +             seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> > > +                        mr->name, &mr->total,
> > > +                        intel_memory_region_get_avail(mr));
> > >
> > >       return 0;
> > >  }
> > > diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> > > index e49da36c62fb..f10dcea94ac9 100644
> > > --- a/drivers/gpu/drm/i915/i915_query.c
> > > +++ b/drivers/gpu/drm/i915/i915_query.c
> > > @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
> > >               info.region.memory_class = mr->type;
> > >               info.region.memory_instance = mr->instance;
> > >               info.probed_size = mr->total;
> > > -             info.unallocated_size = mr->avail;
> > > +             info.unallocated_size = intel_memory_region_get_avail(mr);
> > >
> > >               if (__copy_to_user(info_ptr, &info, sizeof(info)))
> > >                       return -EFAULT;
> > > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > index fc7ad5c035b8..562d11edc5e4 100644
> > > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> > >       return ret;
> > >  }
> > >
> > > +/**
> > > + * i915_ttm_buddy_man_avail - Get the currently available size
> > > + * @man: The buddy allocator ttm manager
> > > + *
> > > + * Return: The available size in bytes
> > > + */
> > > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> > > +{
> > > +     struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> > > +     struct i915_buddy_mm *mm = &bman->mm;
> > > +
> > > +     return mm->avail;
> > > +}
> > > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > index 26026213e20a..39f5b1a4c3e7 100644
> > > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
> > >  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> > >                              u64 start, u64 size);
> > >
> > > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> > > +
> > >  #endif
> > > diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> > > index df59f884d37c..d5edf088be48 100644
> > > --- a/drivers/gpu/drm/i915/intel_memory_region.c
> > > +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> > > @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
> > >       va_end(ap);
> > >  }
> > >
> > > +/**
> > > + * intel_memory_region_get_avail - Get the currently available size for the
> > > + * region
> > > + * @mr: The memory region
> > > + *
> > > + * Return: The available size in bytes
> > > + */
> > > +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> > > +{
> > > +     if (mr->type == INTEL_MEMORY_LOCAL)
> > > +             return i915_ttm_buddy_man_get_avail(mr->region_private);
> > > +
> > > +     return mr->avail;
> > > +}
> > > +
> > >  static void __intel_memory_region_destroy(struct kref *kref)
> > >  {
> > >       struct intel_memory_region *mem =
> > > diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> > > index 2be8433d373a..6f7a073d5a70 100644
> > > --- a/drivers/gpu/drm/i915/intel_memory_region.h
> > > +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> > > @@ -74,6 +74,7 @@ struct intel_memory_region {
> > >       resource_size_t io_start;
> > >       resource_size_t min_page_size;
> > >       resource_size_t total;
> > > +     /* Do not access directly. Use the accessor instead. */
> > >       resource_size_t avail;
> > >
> > >       u16 type;
> > > @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
> > >  int intel_memory_region_reserve(struct intel_memory_region *mem,
> > >                               resource_size_t offset,
> > >                               resource_size_t size);
> > > +
> > > +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> > > +
> > >  #endif
> > > --
> > > 2.26.3
> > >
> > > _______________________________________________
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> >
> > --
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Intel-gfx] [PATCH] drm/i915: add back the avail tracking
@ 2021-06-24  8:50       ` Daniel Vetter
  0 siblings, 0 replies; 15+ messages in thread
From: Daniel Vetter @ 2021-06-24  8:50 UTC (permalink / raw)
  To: Matthew Auld
  Cc: Thomas Hellström, Intel Graphics Development, ML dri-devel,
	Matthew Auld

On Wed, Jun 23, 2021 at 08:35:30PM +0100, Matthew Auld wrote:
> On Wed, 23 Jun 2021 at 20:15, Daniel Vetter <daniel@ffwll.ch> wrote:
> >
> > On Wed, Jun 23, 2021 at 06:27:06PM +0100, Matthew Auld wrote:
> > > Looks like it got lost along the way, so add it back. This is needed for
> > > the region query uAPI where we want to report a snapshot of how much
> > > lmem is available.
> > >
> > > This time around let's push it directly into the allocator, which
> > > simplifies things, like not having to care about internal fragmentation,
> > > or having to remember to track things for all possible interfaces that
> > > might want to allocate or reserve pages.
> > >
> > > v2(Thomas): add some more kernel doc
> > >
> > > Signed-off-by: Matthew Auld <matthew.auld@intel.com>
> > > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > > Reviewed-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> >
> > Since this is uapi, do umds use this? Or just igt?
> >
> > Please record both the umd user for this and the igts that verifies this
> > is not nonsense to the commit message. We need to be much better with
> > keeping records for our uapi additions, there's been some really badly
> > justified uapi in the past that turned out to be for testcases only.
> 
> For the userspace justification, I pinged you and Jason about that in
> the previous thread, since it's not completely clear if real userspace
> even cares about this. I can maybe just limit it to debugfs?

Sorry I missed that ping. If it's just for igt then debugfs should be good
enough. Otherwise I'd do a quick check on the internal code repos and
maybe ping Jason on irc if he misses this, just in case we've overlooked
something.
-Daniel

> 
> > -Daniel
> >
> > > ---
> > >  drivers/gpu/drm/i915/i915_buddy.c             |  6 ++++++
> > >  drivers/gpu/drm/i915/i915_buddy.h             |  1 +
> > >  drivers/gpu/drm/i915/i915_debugfs.c           |  5 +++--
> > >  drivers/gpu/drm/i915/i915_query.c             |  2 +-
> > >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.c | 13 +++++++++++++
> > >  drivers/gpu/drm/i915/i915_ttm_buddy_manager.h |  2 ++
> > >  drivers/gpu/drm/i915/intel_memory_region.c    | 15 +++++++++++++++
> > >  drivers/gpu/drm/i915/intel_memory_region.h    |  4 ++++
> > >  8 files changed, 45 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/i915_buddy.c b/drivers/gpu/drm/i915/i915_buddy.c
> > > index 29dd7d0310c1..27cd2487a18f 100644
> > > --- a/drivers/gpu/drm/i915/i915_buddy.c
> > > +++ b/drivers/gpu/drm/i915/i915_buddy.c
> > > @@ -80,6 +80,7 @@ int i915_buddy_init(struct i915_buddy_mm *mm, u64 size, u64 chunk_size)
> > >       size = round_down(size, chunk_size);
> > >
> > >       mm->size = size;
> > > +     mm->avail = size;
> > >       mm->chunk_size = chunk_size;
> > >       mm->max_order = ilog2(size) - ilog2(chunk_size);
> > >
> > > @@ -159,6 +160,8 @@ void i915_buddy_fini(struct i915_buddy_mm *mm)
> > >               i915_block_free(mm, mm->roots[i]);
> > >       }
> > >
> > > +     GEM_WARN_ON(mm->avail != mm->size);
> > > +
> > >       kfree(mm->roots);
> > >       kfree(mm->free_list);
> > >       kmem_cache_destroy(mm->slab_blocks);
> > > @@ -235,6 +238,7 @@ void i915_buddy_free(struct i915_buddy_mm *mm,
> > >                    struct i915_buddy_block *block)
> > >  {
> > >       GEM_BUG_ON(!i915_buddy_block_is_allocated(block));
> > > +     mm->avail += i915_buddy_block_size(mm, block);
> > >       __i915_buddy_free(mm, block);
> > >  }
> > >
> > > @@ -288,6 +292,7 @@ i915_buddy_alloc(struct i915_buddy_mm *mm, unsigned int order)
> > >       }
> > >
> > >       mark_allocated(block);
> > > +     mm->avail -= i915_buddy_block_size(mm, block);
> > >       kmemleak_update_trace(block);
> > >       return block;
> > >
> > > @@ -373,6 +378,7 @@ int i915_buddy_alloc_range(struct i915_buddy_mm *mm,
> > >                       }
> > >
> > >                       mark_allocated(block);
> > > +                     mm->avail -= i915_buddy_block_size(mm, block);
> > >                       list_add_tail(&block->link, &allocated);
> > >                       continue;
> > >               }
> > > diff --git a/drivers/gpu/drm/i915/i915_buddy.h b/drivers/gpu/drm/i915/i915_buddy.h
> > > index 37f8c42071d1..feb7c1bb6244 100644
> > > --- a/drivers/gpu/drm/i915/i915_buddy.h
> > > +++ b/drivers/gpu/drm/i915/i915_buddy.h
> > > @@ -70,6 +70,7 @@ struct i915_buddy_mm {
> > >       /* Must be at least PAGE_SIZE */
> > >       u64 chunk_size;
> > >       u64 size;
> > > +     u64 avail;
> > >  };
> > >
> > >  static inline u64
> > > diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
> > > index cc745751ac53..4765f220469e 100644
> > > --- a/drivers/gpu/drm/i915/i915_debugfs.c
> > > +++ b/drivers/gpu/drm/i915/i915_debugfs.c
> > > @@ -246,8 +246,9 @@ static int i915_gem_object_info(struct seq_file *m, void *data)
> > >                  atomic_read(&i915->mm.free_count),
> > >                  i915->mm.shrink_memory);
> > >       for_each_memory_region(mr, i915, id)
> > > -             seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
> > > -                        mr->name, &mr->total, &mr->avail);
> > > +             seq_printf(m, "%s: total:%pa, available:%llu bytes\n",
> > > +                        mr->name, &mr->total,
> > > +                        intel_memory_region_get_avail(mr));
> > >
> > >       return 0;
> > >  }
> > > diff --git a/drivers/gpu/drm/i915/i915_query.c b/drivers/gpu/drm/i915/i915_query.c
> > > index e49da36c62fb..f10dcea94ac9 100644
> > > --- a/drivers/gpu/drm/i915/i915_query.c
> > > +++ b/drivers/gpu/drm/i915/i915_query.c
> > > @@ -465,7 +465,7 @@ static int query_memregion_info(struct drm_i915_private *i915,
> > >               info.region.memory_class = mr->type;
> > >               info.region.memory_instance = mr->instance;
> > >               info.probed_size = mr->total;
> > > -             info.unallocated_size = mr->avail;
> > > +             info.unallocated_size = intel_memory_region_get_avail(mr);
> > >
> > >               if (__copy_to_user(info_ptr, &info, sizeof(info)))
> > >                       return -EFAULT;
> > > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > index fc7ad5c035b8..562d11edc5e4 100644
> > > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.c
> > > @@ -246,3 +246,16 @@ int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> > >       return ret;
> > >  }
> > >
> > > +/**
> > > + * i915_ttm_buddy_man_avail - Get the currently available size
> > > + * @man: The buddy allocator ttm manager
> > > + *
> > > + * Return: The available size in bytes
> > > + */
> > > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man)
> > > +{
> > > +     struct i915_ttm_buddy_manager *bman = to_buddy_manager(man);
> > > +     struct i915_buddy_mm *mm = &bman->mm;
> > > +
> > > +     return mm->avail;
> > > +}
> > > diff --git a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > index 26026213e20a..39f5b1a4c3e7 100644
> > > --- a/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > +++ b/drivers/gpu/drm/i915/i915_ttm_buddy_manager.h
> > > @@ -53,4 +53,6 @@ int i915_ttm_buddy_man_fini(struct ttm_device *bdev,
> > >  int i915_ttm_buddy_man_reserve(struct ttm_resource_manager *man,
> > >                              u64 start, u64 size);
> > >
> > > +u64 i915_ttm_buddy_man_get_avail(struct ttm_resource_manager *man);
> > > +
> > >  #endif
> > > diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
> > > index df59f884d37c..d5edf088be48 100644
> > > --- a/drivers/gpu/drm/i915/intel_memory_region.c
> > > +++ b/drivers/gpu/drm/i915/intel_memory_region.c
> > > @@ -132,6 +132,21 @@ void intel_memory_region_set_name(struct intel_memory_region *mem,
> > >       va_end(ap);
> > >  }
> > >
> > > +/**
> > > + * intel_memory_region_get_avail - Get the currently available size for the
> > > + * region
> > > + * @mr: The memory region
> > > + *
> > > + * Return: The available size in bytes
> > > + */
> > > +u64 intel_memory_region_get_avail(struct intel_memory_region *mr)
> > > +{
> > > +     if (mr->type == INTEL_MEMORY_LOCAL)
> > > +             return i915_ttm_buddy_man_get_avail(mr->region_private);
> > > +
> > > +     return mr->avail;
> > > +}
> > > +
> > >  static void __intel_memory_region_destroy(struct kref *kref)
> > >  {
> > >       struct intel_memory_region *mem =
> > > diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
> > > index 2be8433d373a..6f7a073d5a70 100644
> > > --- a/drivers/gpu/drm/i915/intel_memory_region.h
> > > +++ b/drivers/gpu/drm/i915/intel_memory_region.h
> > > @@ -74,6 +74,7 @@ struct intel_memory_region {
> > >       resource_size_t io_start;
> > >       resource_size_t min_page_size;
> > >       resource_size_t total;
> > > +     /* Do not access directly. Use the accessor instead. */
> > >       resource_size_t avail;
> > >
> > >       u16 type;
> > > @@ -125,4 +126,7 @@ intel_memory_region_set_name(struct intel_memory_region *mem,
> > >  int intel_memory_region_reserve(struct intel_memory_region *mem,
> > >                               resource_size_t offset,
> > >                               resource_size_t size);
> > > +
> > > +u64 intel_memory_region_get_avail(struct intel_memory_region *mem);
> > > +
> > >  #endif
> > > --
> > > 2.26.3
> > >
> > > _______________________________________________
> > > Intel-gfx mailing list
> > > Intel-gfx@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/intel-gfx
> >
> > --
> > Daniel Vetter
> > Software Engineer, Intel Corporation
> > http://blog.ffwll.ch
> > _______________________________________________
> > Intel-gfx mailing list
> > Intel-gfx@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/intel-gfx

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-06-24  8:50 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 17:27 [PATCH] drm/i915: add back the avail tracking Matthew Auld
2021-06-23 17:27 ` [Intel-gfx] " Matthew Auld
2021-06-23 18:09 ` [Intel-gfx] ✗ Fi.CI.BAT: failure for " Patchwork
2021-06-23 19:15 ` [Intel-gfx] [PATCH] " Daniel Vetter
2021-06-23 19:15   ` Daniel Vetter
2021-06-23 19:35   ` Matthew Auld
2021-06-23 19:35     ` Matthew Auld
2021-06-24  8:50     ` Daniel Vetter
2021-06-24  8:50       ` Daniel Vetter
2021-06-23 20:05 ` kernel test robot
2021-06-23 20:05   ` kernel test robot
2021-06-23 20:05   ` [Intel-gfx] " kernel test robot
2021-06-23 21:16 ` kernel test robot
2021-06-23 21:16   ` kernel test robot
2021-06-23 21:16   ` [Intel-gfx] " kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.