Skip to contentSkip to conversation

drm/i915: add back the avail tracking

PATCH In review Matthew Auld 5 participants 7 messages Jun 23, 2021 – Jun 24, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/i915: add back the avail tracking

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

---
 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(-)
drivers/gpu/drm/i915/i915_buddy.c +6 -0
index 29dd7d0310c1..27cd2487a18f 100644
@@ -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;
 		}
drivers/gpu/drm/i915/i915_buddy.h +1 -0
index 37f8c42071d1..feb7c1bb6244 100644
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
 	/* Must be at least PAGE_SIZE */
 	u64 chunk_size;
 	u64 size;
+	u64 avail;
 };
 
 static inline u64
drivers/gpu/drm/i915/i915_debugfs.c +3 -2
index cc745751ac53..4765f220469e 100644
@@ -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;
 }
drivers/gpu/drm/i915/i915_query.c +1 -1
index e49da36c62fb..f10dcea94ac9 100644
@@ -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;
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +13 -0
index fc7ad5c035b8..562d11edc5e4 100644
@@ -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;
+}
drivers/gpu/drm/i915/i915_ttm_buddy_manager.h +2 -0
index 26026213e20a..39f5b1a4c3e7 100644
@@ -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
drivers/gpu/drm/i915/intel_memory_region.c +15 -0
index df59f884d37c..d5edf088be48 100644
@@ -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 =
drivers/gpu/drm/i915/intel_memory_region.h +4 -0
index 2be8433d373a..6f7a073d5a70 100644
@@ -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
Signature · 6 lines
2.26.3

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

[Intel-gfx] ✗ Fi.CI.BAT: failure for drm/i915: add back the avail tracking

== Series Details ==

== 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@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-bwr-2160/igt@[email protected]

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/[email protected]

* 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/[email protected]

* 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@[email protected]

* 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@[email protected]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_20445/fi-kbl-soraka/igt@[email protected]

* 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@[email protected]

* 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@[email protected]

[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

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

#2 lore raw
In reply to Matthew Auld
Quoted 9 lines · Matthew Auld

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.

Quoted 5 lines

v2(Thomas): add some more kernel doc

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

Quoted 182 lines
---
 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(-)
drivers/gpu/drm/i915/i915_buddy.c +6 -0
index 29dd7d0310c1..27cd2487a18f 100644
@@ -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;
 		}
drivers/gpu/drm/i915/i915_buddy.h +1 -0
index 37f8c42071d1..feb7c1bb6244 100644
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
 	/* Must be at least PAGE_SIZE */
 	u64 chunk_size;
 	u64 size;
+	u64 avail;
 };
 
 static inline u64
drivers/gpu/drm/i915/i915_debugfs.c +3 -2
index cc745751ac53..4765f220469e 100644
@@ -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;
 }
drivers/gpu/drm/i915/i915_query.c +1 -1
index e49da36c62fb..f10dcea94ac9 100644
@@ -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;
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +13 -0
index fc7ad5c035b8..562d11edc5e4 100644
@@ -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;
+}
drivers/gpu/drm/i915/i915_ttm_buddy_manager.h +2 -0
index 26026213e20a..39f5b1a4c3e7 100644
@@ -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
drivers/gpu/drm/i915/intel_memory_region.c +15 -0
index df59f884d37c..d5edf088be48 100644
@@ -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 =
drivers/gpu/drm/i915/intel_memory_region.h +4 -0
index 2be8433d373a..6f7a073d5a70 100644
@@ -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
Signature · 6 lines
2.26.3

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#3 lore raw
Quoted 17 lines · Daniel Vetter
Quoted 9 lines · Matthew Auld

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.

Quoted 5 lines

v2(Thomas): add some more kernel doc

Quoted 6 lines

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?

Quoted 180 lines

-Daniel

Quoted 178 lines
---
 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(-)
drivers/gpu/drm/i915/i915_buddy.c +6 -0
index 29dd7d0310c1..27cd2487a18f 100644
@@ -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;
              }
drivers/gpu/drm/i915/i915_buddy.h +1 -0
index 37f8c42071d1..feb7c1bb6244 100644
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
      /* Must be at least PAGE_SIZE */
      u64 chunk_size;
      u64 size;
+     u64 avail;
 };
 
 static inline u64
drivers/gpu/drm/i915/i915_debugfs.c +3 -2
index cc745751ac53..4765f220469e 100644
@@ -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;
 }
drivers/gpu/drm/i915/i915_query.c +1 -1
index e49da36c62fb..f10dcea94ac9 100644
@@ -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;
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +13 -0
index fc7ad5c035b8..562d11edc5e4 100644
@@ -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;
+}
drivers/gpu/drm/i915/i915_ttm_buddy_manager.h +2 -0
index 26026213e20a..39f5b1a4c3e7 100644
@@ -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
drivers/gpu/drm/i915/intel_memory_region.c +15 -0
index df59f884d37c..d5edf088be48 100644
@@ -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 =
drivers/gpu/drm/i915/intel_memory_region.h +4 -1
index 2be8433d373a..6f7a073d5a70 100644
@@ -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

Quoted 13 lines
Quoted 4 lines

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

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

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

#4 lore raw
Quoted 20 lines · Matthew Auld
Quoted 19 lines · Daniel Vetter
Quoted 9 lines · Matthew Auld

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.

Quoted 5 lines

v2(Thomas): add some more kernel doc

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

Quoted 8 lines
Quoted 4 lines

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

Quoted 194 lines
Quoted 194 lines

-Daniel

Quoted 178 lines
---
 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(-)
drivers/gpu/drm/i915/i915_buddy.c +6 -0
index 29dd7d0310c1..27cd2487a18f 100644
@@ -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;
              }
drivers/gpu/drm/i915/i915_buddy.h +1 -0
index 37f8c42071d1..feb7c1bb6244 100644
@@ -70,6 +70,7 @@ struct i915_buddy_mm {
      /* Must be at least PAGE_SIZE */
      u64 chunk_size;
      u64 size;
+     u64 avail;
 };
 
 static inline u64
drivers/gpu/drm/i915/i915_debugfs.c +3 -2
index cc745751ac53..4765f220469e 100644
@@ -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;
 }
drivers/gpu/drm/i915/i915_query.c +1 -1
index e49da36c62fb..f10dcea94ac9 100644
@@ -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;
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c +13 -0
index fc7ad5c035b8..562d11edc5e4 100644
@@ -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;
+}
drivers/gpu/drm/i915/i915_ttm_buddy_manager.h +2 -0
index 26026213e20a..39f5b1a4c3e7 100644
@@ -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
drivers/gpu/drm/i915/intel_memory_region.c +15 -0
index df59f884d37c..d5edf088be48 100644
@@ -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 =
drivers/gpu/drm/i915/intel_memory_region.h +4 -1
index 2be8433d373a..6f7a073d5a70 100644
@@ -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

Quoted 4 lines

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

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#5 lore raw
In reply to Matthew Auld
Thank you for the patch! Perhaps something to improve:

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

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

#6 lore raw
In reply to Matthew Auld
Thank you for the patch! Perhaps something to improve:

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

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