rework bo mem stats tracking
Subsystems (6)
v8 cover rework bo mem stats tracking
Right now every time the fdinfo is read, we go through the vm lists and lock all the BOs to calcuate the statistics. This causes a lot of lock contention when the VM is actively used. It gets worse if there is a lot of shared BOs or if there's a lot of submissions. We have seen submissions lock-up for seconds due to fdinfo for some workload. Therefore, rework the implementation to track the BOs as they get moved around.
The amd-only visible memory stat is removed to simplify implementation, it's unclear how useful this stat is since kernel map/unmap BOs whenever it wants to and on a modern system all of VRAM can be mapped if needed.
v5: rebase on top of the drm_print_memory_stats refactor
v6: split the drm changes into a seperate patch for drm-devel review, fix handling of drm-total- vs drm-resident- and handle drm-purgable-.
v7: make drm-active- optional
v8: clearify documentation, minor tweaks, and some bug fixes found during testing
Yunxiang Li (5):
drm: add drm_memory_stats_is_zero
drm: make drm-active- stats optional Documentation/gpu: Clarify drm memory stats definition drm/amdgpu: remove unused function parameter drm/amdgpu: track bo memory stats at runtime
Documentation/gpu/drm-usage-stats.rst | 36 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 17 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 17 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 111 +++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 179 ++++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 20 ++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 1 + drivers/gpu/drm/drm_file.c | 23 ++- drivers/gpu/drm/i915/i915_drm_client.c | 1 + drivers/gpu/drm/xe/xe_drm_client.c | 1 + include/drm/drm_file.h | 1 + include/drm/drm_gem.h | 14 +- 16 files changed, 254 insertions(+), 182 deletions(-)
Signature · 1 line
2.34.1
PATCH v8 1/5 drm: add drm_memory_stats_is_zero
Add a helper to check if the memory stats is zero, this will be used to check for memory accounting errors.
--- drivers/gpu/drm/drm_file.c | 10 ++++++++++ include/drm/drm_file.h | 1 + 2 files changed, 11 insertions(+)
drivers/gpu/drm/drm_file.c +10 -0
@@ -859,6 +859,16 @@ static void print_size(struct drm_printer *p, const char *stat,drm_printf (p,"drm-%s-%s:\t%llu%s\n" , stat, region, sz, units[u]); } +int drm_memory_stats_is_zero (const struct drm_memory_stats *stats) +{ +return (stats->shared ==0 && + stats->private ==0 && + stats->resident ==0 && + stats->purgeable ==0 && + stats->active ==0 ); +} +EXPORT_SYMBOL (drm_memory_stats_is_zero); +/** * drm_print_memory_stats - A helper to print memory stats * @p: The printer to print output to
include/drm/drm_file.h +1 -0
@@ -477,6 +477,7 @@ struct drm_memory_stats {enum drm_gem_object_status ; +int drm_memory_stats_is_zero (const struct drm_memory_stats *stats); void drm_print_memory_stats(struct drm_printer *p, const struct drm_memory_stats *stats, enum drm_gem_object_status supported_status,
Signature · 1 line
2.34.1
PATCH v8 2/5 drm: make drm-active- stats optional
In reply to Yunxiang LiWhen memory stats is generated fresh everytime by going though all the BOs, their active information is quite easy to get. But if the stats are tracked with BO's state this becomes harder since the job scheduling part doesn't really deal with individual buffers.
Make drm-active- optional to enable amdgpu to switch to the second method.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 1 + drivers/gpu/drm/drm_file.c | 13 +++++++------ drivers/gpu/drm/i915/i915_drm_client.c | 1 + drivers/gpu/drm/xe/xe_drm_client.c | 1 + include/drm/drm_gem.h | 14 ++++++++------ 5 files changed, 18 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +1 -0
@@ -97,6 +97,7 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)drm_print_memory_stats (p, &stats[i].drm, +DRM_GEM_OBJECT_ACTIVE |DRM_GEM_OBJECT_RESIDENT |DRM_GEM_OBJECT_PURGEABLE , pl_name[i]);
drivers/gpu/drm/drm_file.c +7 -6
@@ -884,7 +884,9 @@ void drm_print_memory_stats(struct drm_printer *p, {print_size (p,"total" , region, stats->private + stats->shared);print_size (p,"shared" , region, stats->shared); -print_size (p,"active" , region, stats->active); + +if (supported_status &DRM_GEM_OBJECT_ACTIVE ) +print_size (p,"active" , region, stats->active);if (supported_status &DRM_GEM_OBJECT_RESIDENT )print_size (p,"resident" , region, stats->resident);
@@ -917,15 +919,13 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)if (obj->funcs && obj->funcs->status) { s = obj->funcs->status (obj); - supported_status =DRM_GEM_OBJECT_RESIDENT | -DRM_GEM_OBJECT_PURGEABLE ; + supported_status |= s; } -if (drm_gem_object_is_shared_for_memory_stats (obj)) { +if (drm_gem_object_is_shared_for_memory_stats (obj)) status.shared += obj->size; - }else { +else status.private += obj->size; - }if (s &DRM_GEM_OBJECT_RESIDENT ) { status.resident += add_size;
@@ -938,6 +938,7 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)if (!dma_resv_test_signaled (obj->resv,dma_resv_usage_rw (true))) { status.active += add_size; + supported_status |=DRM_GEM_OBJECT_ACTIVE ;/* If still active, don't count as purgeable: */ s &= ~DRM_GEM_OBJECT_PURGEABLE ;
drivers/gpu/drm/i915/i915_drm_client.c +1 -0
@@ -102,6 +102,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file)for_each_memory_region (mr, i915, id)drm_print_memory_stats (p, &stats[id], +DRM_GEM_OBJECT_ACTIVE |DRM_GEM_OBJECT_RESIDENT |DRM_GEM_OBJECT_PURGEABLE , mr->uabi_name);
drivers/gpu/drm/xe/xe_drm_client.c +1 -0
@@ -229,6 +229,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file)if (man) { drm_print_memory_stats(p, &stats[mem_type], + DRM_GEM_OBJECT_ACTIVE | DRM_GEM_OBJECT_RESIDENT | (mem_type != XE_PL_SYSTEM ? 0 : DRM_GEM_OBJECT_PURGEABLE),
include/drm/drm_gem.h +8 -6
@@ -48,19 +48,21 @@ struct drm_gem_object;* enum drm_gem_object_status - bitmask of object state for fdinfo reporting * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace +* @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission * * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status -* and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if -* it still active or not resident, in which case drm_show_fdinfo() will not +* and drm_show_fdinfo(). Note that an object can report DRM_GEM_OBJECT_PURGEABLE +* and be active or not resident, in which case drm_show_fdinfo() will not * account for it as purgeable. So drivers do not need to check if the buffer -* is idle and resident to return this bit. (Ie. userspace can mark a buffer -* as purgeable even while it is still busy on the GPU.. it does not _actually_ -* become puregeable until it becomes idle. The status gem object func does -* not need to consider this.) +* is idle and resident to return this bit, i.e. userspace can mark a buffer as +* purgeable even while it is still busy on the GPU. It whill not get reported +* in the puregeable stats until it becomes idle. The status gem object func +* does not need to consider this. */ enum drm_gem_object_status {DRM_GEM_OBJECT_RESIDENT =BIT (0 ),DRM_GEM_OBJECT_PURGEABLE =BIT (1 ), +DRM_GEM_OBJECT_ACTIVE =BIT (2 ), };/**
Signature · 1 line
2.34.1
Re: [PATCH v8 2/5] drm: make drm-active- stats optional
Quoted 7 lines · Yunxiang Li
When memory stats is generated fresh everytime by going though all the BOs, their active information is quite easy to get. But if the stats are tracked with BO's state this becomes harder since the job scheduling part doesn't really deal with individual buffers.
Make drm-active- optional to enable amdgpu to switch to the second method.
Perhaps you missed https://lore.kernel.org/dri-devel/[email protected]/ ?
Regards,
Tvrtko
Quoted 122 lines
Signed-off-by Yunxiang Li <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 1 + drivers/gpu/drm/drm_file.c | 13 +++++++------ drivers/gpu/drm/i915/i915_drm_client.c | 1 + drivers/gpu/drm/xe/xe_drm_client.c | 1 + include/drm/drm_gem.h | 14 ++++++++------ 5 files changed, 18 insertions(+), 12 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +1
-0@@ -97,6 +97,7 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)drm_print_memory_stats (p, &stats[i].drm, +DRM_GEM_OBJECT_ACTIVE |DRM_GEM_OBJECT_RESIDENT |DRM_GEM_OBJECT_PURGEABLE , pl_name[i]);drivers/gpu/drm/drm_file.c +7
-6@@ -884,7 +884,9 @@ void drm_print_memory_stats(struct drm_printer *p, {print_size (p,"total" , region, stats->private + stats->shared);print_size (p,"shared" , region, stats->shared); -print_size (p,"active" , region, stats->active); + +if (supported_status &DRM_GEM_OBJECT_ACTIVE ) +print_size (p,"active" , region, stats->active);if (supported_status &DRM_GEM_OBJECT_RESIDENT )print_size (p,"resident" , region, stats->resident);@@ -917,15 +919,13 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)if (obj->funcs && obj->funcs->status) { s = obj->funcs->status (obj); - supported_status =DRM_GEM_OBJECT_RESIDENT | -DRM_GEM_OBJECT_PURGEABLE ; + supported_status |= s; } -if (drm_gem_object_is_shared_for_memory_stats (obj)) { +if (drm_gem_object_is_shared_for_memory_stats (obj)) status.shared += obj->size; - }else { +else status.private += obj->size; - }if (s &DRM_GEM_OBJECT_RESIDENT ) { status.resident += add_size;@@ -938,6 +938,7 @@ void drm_show_memory_stats(struct drm_printer *p, struct drm_file *file)if (!dma_resv_test_signaled (obj->resv,dma_resv_usage_rw (true))) { status.active += add_size; + supported_status |=DRM_GEM_OBJECT_ACTIVE ;/* If still active, don't count as purgeable: */ s &= ~DRM_GEM_OBJECT_PURGEABLE ;drivers/gpu/drm/i915/i915_drm_client.c +1
-0@@ -102,6 +102,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file)for_each_memory_region (mr, i915, id)drm_print_memory_stats (p, &stats[id], +DRM_GEM_OBJECT_ACTIVE |DRM_GEM_OBJECT_RESIDENT |DRM_GEM_OBJECT_PURGEABLE , mr->uabi_name);drivers/gpu/drm/xe/xe_drm_client.c +1
-0@@ -229,6 +229,7 @@ static void show_meminfo(struct drm_printer *p, struct drm_file *file)if (man) { drm_print_memory_stats(p, &stats[mem_type], + DRM_GEM_OBJECT_ACTIVE | DRM_GEM_OBJECT_RESIDENT | (mem_type != XE_PL_SYSTEM ? 0 : DRM_GEM_OBJECT_PURGEABLE),include/drm/drm_gem.h +8
-6@@ -48,19 +48,21 @@ struct drm_gem_object;* enum drm_gem_object_status - bitmask of object state for fdinfo reporting * @DRM_GEM_OBJECT_RESIDENT: object is resident in memory (ie. not unpinned) * @DRM_GEM_OBJECT_PURGEABLE: object marked as purgeable by userspace +* @DRM_GEM_OBJECT_ACTIVE: object is currently used by an active submission * * Bitmask of status used for fdinfo memory stats, see &drm_gem_object_funcs.status -* and drm_show_fdinfo(). Note that an object can DRM_GEM_OBJECT_PURGEABLE if -* it still active or not resident, in which case drm_show_fdinfo() will not +* and drm_show_fdinfo(). Note that an object can report DRM_GEM_OBJECT_PURGEABLE +* and be active or not resident, in which case drm_show_fdinfo() will not * account for it as purgeable. So drivers do not need to check if the buffer -* is idle and resident to return this bit. (Ie. userspace can mark a buffer -* as purgeable even while it is still busy on the GPU.. it does not _actually_ -* become puregeable until it becomes idle. The status gem object func does -* not need to consider this.) +* is idle and resident to return this bit, i.e. userspace can mark a buffer as +* purgeable even while it is still busy on the GPU. It whill not get reported +* in the puregeable stats until it becomes idle. The status gem object func +* does not need to consider this. */ enum drm_gem_object_status {DRM_GEM_OBJECT_RESIDENT =BIT (0 ),DRM_GEM_OBJECT_PURGEABLE =BIT (1 ), +DRM_GEM_OBJECT_ACTIVE =BIT (2 ), };/**
RE: [PATCH v8 2/5] drm: make drm-active- stats optional
[Public]
Indeed I have, thanks for the reminder
Teddy
PATCH v8 3/5 Documentation/gpu: Clarify drm memory stats definition
In reply to Yunxiang LiDefine how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
--- Documentation/gpu/drm-usage-stats.rst | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-)
Documentation/gpu/drm-usage-stats.rst +16 -20
@@ -140,13 +140,9 @@ both. Memory ^^^^^^ -- drm-memory-<region>: <uint> [KiB|MiB] - -Each possible memory type which can be used to store buffer objects by the -GPU in question shall be given a stable and unique name to be returned as the -string here. - -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objects by the GPU +in question shall be given a stable and unique name to be used as the "<region>" +string. The region name "memory" is reserved to refer to normal system memory. Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.
@@ -154,31 +150,27 @@ objects belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. -This key is deprecated and is an alias for drm-resident-<region>. Only one of -the two should be present in the output. +- drm-total-<region>: <uint> [KiB|MiB] + +The total size of all created buffers including shared and private memory. The +backing store for the buffers does not have to be currently instantiated to +count under this category. To avoid double counting, if a buffer falls under +multiple regions, the implementation should pick only one of the regions, and do +so in a consistent manner. - drm-shared-<region>: <uint> [KiB|MiB] The total size of buffers that are shared with another file (e.g., have more -than a single handle). - -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and private memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +than a single handle). Same caveat as drm-total- applies. - drm-resident-<region>: <uint> [KiB|MiB] The total size of buffers that are resident (have their backing store present or instantiated) in the specified region. -This is an alias for drm-memory-<region> and only one of the two should be -present in the output. - - drm-purgeable-<region>: <uint> [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable. For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have been marked
@@ -192,6 +184,10 @@ One practical example of this can be presence of unsignaled fences in an GEM buffer reservation object. Therefore the active category is a subset of resident. +- drm-memory-<region>: <uint> [KiB|MiB] + +This key is deprecated and is an alias for drm-resident-<region> if present. + Implementation Details ======================
Signature · 1 line
2.34.1
Re: [PATCH v8 3/5] Documentation/gpu: Clarify drm memory stats definition
Am 16.11.24 um 05:44 schrieb Yunxiang Li:
Quoted 21 lines
Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
Signed-off-by Yunxiang Li <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-)Documentation/gpu/drm-usage-stats.rst +0
-0@@ -140,13 +140,9 @@ both. Memory ^^^^^^
Documentation/gpu/drm-usage-stats.rst both. · line 145
Quoted 10 lines
Documentation/gpu/drm-usage-stats.rst +3
-7-- drm-memory-<region>: <uint> [KiB|MiB] - -Each possible memory type which can be used to store buffer objects by the -GPU in question shall be given a stable and unique name to be returned as the -string here. - -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objects by the GPU +in question shall be given a stable and unique name to be used as the "<region>" +string. The region name "memory" is reserved to refer to normal system memory.
That looks like you squashed the "The region name..." sentence at the end. Is that really helpful and intended?
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 155
Quoted 12 lines
Documentation/gpu/drm-usage-stats.rst +3
-2Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.@@ -154,31 +150,27 @@ objects belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. -This key is deprecated and is an alias for drm-resident-<region>. Only one of -the two should be present in the output. +- drm-total-<region>: <uint> [KiB|MiB] + +The total size of all created buffers including shared and private memory. The
Maybe write "requested" instead of "created" since without a backing store it is questionable if the BO is really "created".
Apart from those two nit picks it looks good to me, Christian.
Quoted 43 lines
Documentation/gpu/drm-usage-stats.rst +10
-11+backing store for the buffers does not have to be currently instantiated to +count under this category. To avoid double counting, if a buffer falls under +multiple regions, the implementation should pick only one of the regions, and do +so in a consistent manner. - drm-shared-<region>: <uint> [KiB|MiB] The total size of buffers that are shared with another file (e.g., have more -than a single handle). - -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and private memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +than a single handle). Same caveat as drm-total- applies. - drm-resident-<region>: <uint> [KiB|MiB] The total size of buffers that are resident (have their backing store present or instantiated) in the specified region. -This is an alias for drm-memory-<region> and only one of the two should be -present in the output. - - drm-purgeable-<region>: <uint> [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable. For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have been marked@@ -192,6 +184,10 @@ One practical example of this can be presence of unsignaled fences in an GEM buffer reservation object. Therefore the active category is a subset of resident. +- drm-memory-<region>: <uint> [KiB|MiB] + +This key is deprecated and is an alias for drm-resident-<region> if present. + Implementation Details ======================
Re: [PATCH v8 3/5] Documentation/gpu: Clarify drm memory stats definition
Quoted 39 lines · Christian König
Am 16.11.24 um 05:44 schrieb Yunxiang Li:
Quoted 30 lines
Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
Signed-off-by Yunxiang Li <[email protected]>---
Documentation/gpu/drm-usage-stats.rst| 36 ++++++++++++---------------1 file changed, 16 insertions(+), 20 deletions(-)Documentation/gpu/drm-usage-stats.rst +0
-0@@ -140,13 +140,9 @@ both.Memory
^^^^^^
-- drm-memory-<region>: <uint> [KiB|MiB]Documentation/gpu/drm-usage-stats.rst +0
-2- -Each possible memory type which can be used to store buffer objectsby the
-GPU in question shall be given a stable and unique name to be returned as theDocumentation/gpu/drm-usage-stats.rst +1
-3-string here. - -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objectsQuoted 5 lines
by the GPU
+in question shall be given a stable and unique name to be used as the "<region>"
+string. The region name "memory" is reserved to refer to normal system memory.That looks like you squashed the "The region name..." sentence at the end. Is that really helpful and intended?
Quoted 15 lines
Quoted 12 lines
Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.
Documentation/gpu/drm-usage-stats.rst +0
-0@@ -154,31 +150,27 @@ objects belong to this client, in the respectivememory region.
Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes.
-This key is deprecated and is an alias for drm-resident-<region>. Only one ofDocumentation/gpu/drm-usage-stats.rst +3
-1-the two should be present in the output. +- drm-total-<region>: <uint> [KiB|MiB] + +The total size of all created buffers including shared and privateQuoted 1 line
memory. The
Maybe write "requested" instead of "created" since without a backing store it is questionable if the BO is really "created".
Hmm is the term "requested" in colloquial use either by end users or user space developers in the context of buffer objects?
If we think the sentence needs to be improved upon, maybe something like: "The total size of all buffers, either created by user space APIs, or internally by the driver, including both shared and private buffers."
?
Regards,
Tvrtko
Quoted 47 lines
Apart from those two nit picks it looks good to me, Christian.
Quoted 42 lines
+backing store for the buffers does not have to be currently instantiated to
+count under this category. To avoid double counting, if a buffer falls under
+multiple regions, the implementation should pick only one of the regions, and do
+so in a consistent manner.
- drm-shared-<region>: <uint> [KiB|MiB]
The total size of buffers that are shared with another file (e.g., have moreDocumentation/gpu/drm-usage-stats.rst +0
-5-than a single handle). - -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and privatememory. The
-backing store for the buffers does not have to be currently instantiated to beDocumentation/gpu/drm-usage-stats.rst +1
-1-counted under this category. +than a single handle). Same caveat as drm-total- applies.- drm-resident-<region>: <uint> [KiB|MiB]
The total size of buffers that are resident (have their backing store present or instantiated) in the specified region.
-This is an alias for drm-memory-<region> and only one of the two should beDocumentation/gpu/drm-usage-stats.rst +0
-2-present in the output. -- drm-purgeable-<region>: <uint> [KiB|MiB]
Documentation/gpu/drm-usage-stats.rst +1
-1-The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable.For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have been marked
Documentation/gpu/drm-usage-stats.rst +0
-0@@ -192,6 +184,10 @@ One practical example of this can be presence ofunsignaled fences in an GEM
buffer reservation object. Therefore the active category is a subset of resident.
+- drm-memory-<region>: <uint> [KiB|MiB]Documentation/gpu/drm-usage-stats.rst +2
-0+ +This key is deprecated and is an alias for drm-resident-<region> ifpresent.
+
Implementation Details
======================
Re: [PATCH v8 3/5] Documentation/gpu: Clarify drm memory stats definition
In reply to Yunxiang LiQuoted 35 lines · Yunxiang Li
Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
Signed-off-by Yunxiang Li <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-)Documentation/gpu/drm-usage-stats.rst +3
-7@@ -140,13 +140,9 @@ both. Memory ^^^^^^ -- drm-memory-<region>: <uint> [KiB|MiB] - -Each possible memory type which can be used to store buffer objects by the -GPU in question shall be given a stable and unique name to be returned as the -string here. - -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objects by the GPU +in question shall be given a stable and unique name to be used as the "<region>" +string. The region name "memory" is reserved to refer to normal system memory. Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 158
Quoted 5 lines
Documentation/gpu/drm-usage-stats.rst +0
-2@@ -154,31 +150,27 @@ objects belong to this client, in the respective memory region. Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes. -This key is deprecated and is an alias for drm-resident-<region>. Only one of -the two should be present in the output.
IMO the second sentence should stay in principle (I mean at the new location, where you moved it). Intent is to avoid new implementations adding both keys. The fact amdgpu has both is not relevant for that purpose. We don't want someone just reading it is an alias and having to have any doubt whether they need to output both or not.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 159
Quoted 7 lines
Documentation/gpu/drm-usage-stats.rst +7
-0+- drm-total-<region>: <uint> [KiB|MiB] + +The total size of all created buffers including shared and private memory. The +backing store for the buffers does not have to be currently instantiated to +count under this category. To avoid double counting, if a buffer falls under +multiple regions, the implementation should pick only one of the regions, and do +so in a consistent manner.
Addition feels fine to me in principle. I would only suggest rewording it a bit to avoid ambiguity about what it means to "fall under". Perhaps like this:
To avoid double counting when buffers can be instantiated in one of the multiple allowed memory regions, the implementation should account the total against only one of the regions, and should pick this region in a consistent manner.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 164
Quoted 12 lines
Documentation/gpu/drm-usage-stats.rst +1
-7- drm-shared-<region>: <uint> [KiB|MiB] The total size of buffers that are shared with another file (e.g., have more -than a single handle). - -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and private memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +than a single handle). Same caveat as drm-total- applies.
I suggest to explicitly point out the caveat is the multiple region one.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 177
Quoted 8 lines
Documentation/gpu/drm-usage-stats.rst +0
-2- drm-resident-<region>: <uint> [KiB|MiB] The total size of buffers that are resident (have their backing store present or instantiated) in the specified region. -This is an alias for drm-memory-<region> and only one of the two should be -present in the output.
I think it does not harm to keep this note at both keys. Or at least make one reference the other for this point specifically.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 173
Quoted 5 lines
Documentation/gpu/drm-usage-stats.rst +1
-2- - drm-purgeable-<region>: <uint> [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable.
Is it not redundant? How could something not resident be purgeable in the first place?
Documentation/gpu/drm-usage-stats.rst One practical example of this can be presence of unsignaled fences in an GEM · line 193
Quoted 13 lines
Documentation/gpu/drm-usage-stats.rst +4
-0For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have been marked@@ -192,6 +184,10 @@ One practical example of this can be presence of unsignaled fences in an GEM buffer reservation object. Therefore the active category is a subset of resident. +- drm-memory-<region>: <uint> [KiB|MiB] + +This key is deprecated and is an alias for drm-resident-<region> if present. + Implementation Details ======================
Regards,
Tvrtko
RE: [PATCH v8 3/5] Documentation/gpu: Clarify drm memory stats definition
[Public]
Quoted 45 lines
From: Tvrtko Ursulin <[email protected]>
Sent: Monday, November 18, 2024 9:38Quoted 27 lines · Yunxiang Li
Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
Signed-off-by Yunxiang Li <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-)Documentation/gpu/drm-usage-stats.rst +0
-3@@ -140,13 +140,9 @@ both. Memory ^^^^^^ -- drm-memory-<region>: <uint> [KiB|MiB] - -Each possible memory type which can be used to store buffer objectsby the -GPU in question shall be given a stable and unique name to be returned as the -string here.
Documentation/gpu/drm-usage-stats.rst both.
Quoted 4 lines
Documentation/gpu/drm-usage-stats.rst +2
-2- -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objects +by the GPU in question shall be given a stable and unique name to be used asthe "<region>"
Quoted 1 line
+string. The region name "memory" is reserved to refer to normal system
memory.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory
Quoted 4 lines
Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.
Documentation/gpu/drm-usage-stats.rst +0
-0@@ -154,31 +150,27 @@ objects belong to this client, in the respective memoryregion.
Quoted 3 lines
Documentation/gpu/drm-usage-stats.rst +0
-0Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes.
Quoted 8 lines
Quoted 2 lines
Documentation/gpu/drm-usage-stats.rst +0
-1-This key is deprecated and is an alias for drm-resident-<region>.Only one of -the two should be present in the output.
IMO the second sentence should stay in principle (I mean at the new location, where you moved it). Intent is to avoid new implementations adding both keys. The fact amdgpu has both is not relevant for that purpose. We don't want someone just reading it is an alias and having to have any doubt whether they need to output both or not.
I see, yeah I will mention in the drm-memory- part that that tag is legacy amdgpu only behavior.
Quoted 9 lines
Documentation/gpu/drm-usage-stats.rst
Quoted 7 lines
+- drm-total-<region>: <uint> [KiB|MiB]
Documentation/gpu/drm-usage-stats.rst +6
-0+ +The total size of all created buffers including shared and private +memory. The backing store for the buffers does not have to be +currently instantiated to count under this category. To avoid double +counting, if a buffer falls under multiple regions, the +implementation should pick only one of the regions, and do so in a consistentmanner.
Quoted 6 lines
Addition feels fine to me in principle. I would only suggest rewording it a bit to avoid ambiguity about what it means to "fall under". Perhaps like this:
To avoid double counting when buffers can be instantiated in one of the multiple allowed memory regions, the implementation should account the total against only one of the regions, and should pick this region in a consistent manner.
Ack
Quoted 14 lines
Quoted 9 lines
- drm-shared-<region>: <uint> [KiB|MiB]
The total size of buffers that are shared with another file (e.g.,
have more -than a single handle).Documentation/gpu/drm-usage-stats.rst +0
-4- -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and privateQuoted 3 lines
memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +than a single handle). Same caveat as drm-total- applies.
I suggest to explicitly point out the caveat is the multiple region one.
and Ack
Quoted 11 lines
Quoted 8 lines
- drm-resident-<region>: <uint> [KiB|MiB]
The total size of buffers that are resident (have their backing store present or instantiated) in the specified region.
-This is an alias for drm-memory-<region> and only one of the two should be -present in the output.
I think it does not harm to keep this note at both keys. Or at least make one reference the other for this point specifically.
Might be easier to just have drm-memory- as a foot note here, instead of its own section
Quoted 8 lines
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 173
Quoted 5 lines
Documentation/gpu/drm-usage-stats.rst +1
-2- - drm-purgeable-<region>: <uint> [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable.Is it not redundant? How could something not resident be purgeable in the first place?
There is the possible confusion between buffers having a purgeable bit and buffers in a state that is purgeable, I feel like it's worth an explicit callout since there's also code comments about this difference.
Quoted 18 lines
Quoted 3 lines
For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have
been marked @@ -192,6 +184,10 @@ One practical example of this can bepresence of unsignaled fences in an GEM
Documentation/gpu/drm-usage-stats.rst One practical example of this can be presence of unsignaled fences in an GEM · line 192
Quoted 10 lines
buffer reservation object. Therefore the active category is a subset of resident.
+- drm-memory-<region>: <uint> [KiB|MiB]
Documentation/gpu/drm-usage-stats.rst +3
-0+ +This key is deprecated and is an alias for drm-resident-<region> if present. + Implementation Details ======================Regards,
Tvrtko
Re: [PATCH v8 3/5] Documentation/gpu: Clarify drm memory stats definition
Quoted 99 lines · Yunxiang (Teddy)
[Public]
Quoted 45 lines
From: Tvrtko Ursulin <[email protected]>
Sent: Monday, November 18, 2024 9:38Quoted 27 lines · Yunxiang Li
Define how to handle buffers with multiple possible placement so we don't get incompatible implementations. Callout the resident requirement for drm-purgeable- explicitly. Remove the requirement for there to be only drm-memory- or only drm-resident-, it's not what's implemented and having both is better for back-compat. Also re-order the paragraphs to flow better.
Signed-off-by Yunxiang Li <[email protected]>--- Documentation/gpu/drm-usage-stats.rst | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-)Documentation/gpu/drm-usage-stats.rst +0
-3@@ -140,13 +140,9 @@ both. Memory ^^^^^^ -- drm-memory-<region>: <uint> [KiB|MiB] - -Each possible memory type which can be used to store buffer objectsby the -GPU in question shall be given a stable and unique name to be returned as the -string here.
Documentation/gpu/drm-usage-stats.rst both.
Quoted 4 lines
Documentation/gpu/drm-usage-stats.rst +2
-2- -The region name "memory" is reserved to refer to normal system memory. +Each possible memory type which can be used to store buffer objects +by the GPU in question shall be given a stable and unique name to be used asthe "<region>"
Quoted 1 line
+string. The region name "memory" is reserved to refer to normal system
memory.
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory
Quoted 4 lines
Value shall reflect the amount of storage currently consumed by the buffer objects belong to this client, in the respective memory region.
Documentation/gpu/drm-usage-stats.rst +0
-0@@ -154,31 +150,27 @@ objects belong to this client, in the respective memoryregion.
Quoted 3 lines
Documentation/gpu/drm-usage-stats.rst +0
-0Default unit shall be bytes with optional unit specifiers of 'KiB' or 'MiB' indicating kibi- or mebi-bytes.Quoted 8 lines
Quoted 2 lines
Documentation/gpu/drm-usage-stats.rst +0
-1-This key is deprecated and is an alias for drm-resident-<region>.Only one of -the two should be present in the output.
IMO the second sentence should stay in principle (I mean at the new location, where you moved it). Intent is to avoid new implementations adding both keys. The fact amdgpu has both is not relevant for that purpose. We don't want someone just reading it is an alias and having to have any doubt whether they need to output both or not.
I see, yeah I will mention in the drm-memory- part that that tag is legacy amdgpu only behavior.
Quoted 9 lines
Documentation/gpu/drm-usage-stats.rst
Quoted 7 lines
+- drm-total-<region>: <uint> [KiB|MiB]
Documentation/gpu/drm-usage-stats.rst +6
-0+ +The total size of all created buffers including shared and private +memory. The backing store for the buffers does not have to be +currently instantiated to count under this category. To avoid double +counting, if a buffer falls under multiple regions, the +implementation should pick only one of the regions, and do so in a consistentmanner.
Quoted 6 lines
Addition feels fine to me in principle. I would only suggest rewording it a bit to avoid ambiguity about what it means to "fall under". Perhaps like this:
To avoid double counting when buffers can be instantiated in one of the multiple allowed memory regions, the implementation should account the total against only one of the regions, and should pick this region in a consistent manner.
Ack
Quoted 14 lines
Quoted 9 lines
- drm-shared-<region>: <uint> [KiB|MiB]
The total size of buffers that are shared with another file (e.g.,
have more -than a single handle).Documentation/gpu/drm-usage-stats.rst +0
-4- -- drm-total-<region>: <uint> [KiB|MiB] - -The total size of all created buffers including shared and privateQuoted 3 lines
memory. The -backing store for the buffers does not have to be currently instantiated to be -counted under this category. +than a single handle). Same caveat as drm-total- applies.
I suggest to explicitly point out the caveat is the multiple region one.
and Ack
Quoted 6 lines
Quoted 6 lines
- drm-resident-<region>: <uint> [KiB|MiB]
The total size of buffers that are resident (have their backing store present or instantiated) in the specified region.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
-This is an alias for drm-memory-<region> and only one of the two should be -present in the output.
I think it does not harm to keep this note at both keys. Or at least make one reference the other for this point specifically.
Might be easier to just have drm-memory- as a foot note here, instead of its own section
Not entirely sure but as long as the legacy and one key note is easily spotted when reading either of the two it works for me.
Quoted 11 lines
Quoted 9 lines
Documentation/gpu/drm-usage-stats.rst objects belong to this client, in the respective memory region. · line 173
Quoted 6 lines
Documentation/gpu/drm-usage-stats.rst +1
-2- - drm-purgeable-<region>: <uint> [KiB|MiB] -The total size of buffers that are purgeable. +The total size of buffers that are resident and purgeable.Is it not redundant? How could something not resident be purgeable in the first place?
There is the possible confusion between buffers having a purgeable bit and buffers in a state that is purgeable, I feel like it's worth an explicit callout since there's also code comments about this difference.
Hm I don't follow this. If you are talking about some implementation details does someone viewing this from the outside cares? Anyway, the addition does not harm, just that I don't see the need. Feel free to leave it.
Regards,
Tvrtko
Quoted 19 lines
Quoted 19 lines
Quoted 4 lines
For example drivers which implement a form of 'madvise' like functionality can here count buffers which have instantiated backing store, but have
been marked @@ -192,6 +184,10 @@ One practical example of this can bepresence of unsignaled fences in an GEM
Documentation/gpu/drm-usage-stats.rst One practical example of this can be presence of unsignaled fences in an GEM · line 192
Quoted 10 lines
buffer reservation object. Therefore the active category is a subset of resident.
+- drm-memory-<region>: <uint> [KiB|MiB]
Documentation/gpu/drm-usage-stats.rst +3
-0+ +This key is deprecated and is an alias for drm-resident-<region> if present. + Implementation Details ======================Regards,
Tvrtko
PATCH v8 4/5 drm/amdgpu: remove unused function parameter
In reply to Yunxiang Liamdgpu_vm_bo_invalidate doesn't use the adev parameter and not all callers have a reference to adev handy, so remove it for cleanliness.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 4 +--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 3 +-- 6 files changed, 7 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -2
@@ -1105,7 +1105,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)* We can't use gang submit on with reserved VMIDs when the VM changes * can't be invalidated by more than one engine at the same time. */ -if (p->gang_size >1 && !p->adev->vm_manager.concurrent_flush) { +if (p->gang_size >1 && !adev->vm_manager.concurrent_flush) {for (i =0 ; i < p->gang_size; ++i) {struct drm_sched_entity *entity = p->entities[i];struct drm_gpu_scheduler *sched = entity->rq->sched;
@@ -1189,7 +1189,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)if (!bo)continue ; -amdgpu_vm_bo_invalidate (adev, bo, false); +amdgpu_vm_bo_invalidate (bo, false); } }
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +1 -1
@@ -345,7 +345,7 @@ amdgpu_dma_buf_move_notify(struct dma_buf_attachment *attach)/* FIXME: This should be after the "if", but needs a fix to make sure * DMABuf imports are initialized in the right VM list. */ -amdgpu_vm_bo_invalidate (adev, bo, false); +amdgpu_vm_bo_invalidate (bo, false);if (!bo->tbo.resource || bo->tbo.resource->mem_type ==TTM_PL_SYSTEM )return ;
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -2
@@ -976,7 +976,6 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,int amdgpu_gem_op_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) { -struct amdgpu_device *adev =drm_to_adev (dev);struct drm_amdgpu_gem_op *args = data;struct drm_gem_object *gobj;struct amdgpu_vm_bo_base *base;
@@ -1036,7 +1035,7 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data, robj->allowed_domains |=AMDGPU_GEM_DOMAIN_GTT ;if (robj->flags &AMDGPU_GEM_CREATE_VM_ALWAYS_VALID ) -amdgpu_vm_bo_invalidate (adev, robj, true); +amdgpu_vm_bo_invalidate (robj, true);amdgpu_bo_unreserve (robj);break ;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
@@ -1150,7 +1150,6 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,bool evict, struct ttm_resource *new_mem) { - struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev); struct ttm_resource *old_mem = bo->resource;struct amdgpu_bo *abo;
@@ -1158,7 +1157,7 @@ void amdgpu_bo_move_notify(struct ttm_buffer_object *bo,return ; abo =ttm_to_amdgpu_bo (bo); -amdgpu_vm_bo_invalidate (adev, abo, evict); +amdgpu_vm_bo_invalidate (abo, evict);amdgpu_bo_kunmap (abo);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -3
@@ -2143,14 +2143,12 @@ bool amdgpu_vm_evictable(struct amdgpu_bo *bo)/** * amdgpu_vm_bo_invalidate - mark the bo as invalid * -* @adev: amdgpu_device pointer * @bo: amdgpu buffer object * @evicted: is the BO evicted * * Mark @bo as invalid. */ -void amdgpu_vm_bo_invalidate (struct amdgpu_device *adev, -struct amdgpu_bo *bo,bool evicted) +void amdgpu_vm_bo_invalidate (struct amdgpu_bo *bo,bool evicted) {struct amdgpu_vm_bo_base *bo_base;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -2
@@ -524,8 +524,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev,struct amdgpu_bo_va *bo_va, bool clear);bool amdgpu_vm_evictable (struct amdgpu_bo *bo); -void amdgpu_vm_bo_invalidate (struct amdgpu_device *adev, -struct amdgpu_bo *bo,bool evicted); +void amdgpu_vm_bo_invalidate (struct amdgpu_bo *bo,bool evicted);uint64_t amdgpu_vm_map_gart (const dma_addr_t *pages_addr,uint64_t addr);struct amdgpu_bo_va *amdgpu_vm_bo_find (struct amdgpu_vm *vm,struct amdgpu_bo *bo);
Signature · 1 line
2.34.1
PATCH v8 5/5 drm/amdgpu: track bo memory stats at runtime
In reply to Yunxiang LiBefore, every time fdinfo is queried we try to lock all the BOs in the VM and calculate memory usage from scratch. This works okay if the fdinfo is rarely read and the VMs don't have a ton of BOs. If either of these conditions is not true, we get a massive performance hit.
In this new revision, we track the BOs as they change states. This way when the fdinfo is queried we only need to take the status lock and copy out the usage stats with minimal impact to the runtime performance. With this new approach however, we would no longer be able to track active buffers.
---
v8: implement drm-total- and drm-resident- as discussed, tweaked amdgpu_vm_update_stats parameters, and bug fixes
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c | 15 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c | 18 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 110 +++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 175 +++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 17 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c | 1 + 8 files changed, 204 insertions(+), 140 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c +13 -2
@@ -36,6 +36,7 @@#include "amdgpu_gem.h" #include "amdgpu_dma_buf.h" #include "amdgpu_xgmi.h" +#include "amdgpu_vm.h" #include <drm/amdgpu_drm.h> #include <drm/ttm/ttm_tt.h> #include <linux/dma-buf.h>
@@ -190,6 +191,14 @@ static void amdgpu_dma_buf_unmap(struct dma_buf_attachment *attach, } } +static void amdgpu_dma_buf_release (struct dma_buf *buf) +{ +struct amdgpu_bo *bo =gem_to_amdgpu_bo (buf->priv); + +amdgpu_vm_bo_update_shared (bo,-1 ); +drm_gem_dmabuf_release (buf); +} +/** * amdgpu_dma_buf_begin_cpu_access - &dma_buf_ops.begin_cpu_access implementation * @dma_buf: Shared DMA buffer
@@ -237,7 +246,7 @@ const struct dma_buf_ops amdgpu_dmabuf_ops = { .unpin = amdgpu_dma_buf_unpin, .map_dma_buf = amdgpu_dma_buf_map, .unmap_dma_buf = amdgpu_dma_buf_unmap, - .release = drm_gem_dmabuf_release, + .release = amdgpu_dma_buf_release, .begin_cpu_access = amdgpu_dma_buf_begin_cpu_access, .mmap = drm_gem_dmabuf_mmap, .vmap = drm_gem_dmabuf_vmap,
@@ -265,8 +274,10 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_gem_object *gobj,return ERR_PTR (-EPERM ); buf =drm_gem_prime_export (gobj, flags); -if (!IS_ERR (buf)) +if (!IS_ERR (buf)) { buf->ops = &amdgpu_dmabuf_ops; +amdgpu_vm_bo_update_shared (bo,+1 ); + }return buf; }
drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c +6 -12
@@ -60,7 +60,7 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)struct amdgpu_fpriv *fpriv = file->driver_priv;struct amdgpu_vm *vm = &fpriv->vm; -struct amdgpu_mem_stats stats[__AMDGPU_PL_LAST +1 ] = { }; +struct amdgpu_mem_stats stats[__AMDGPU_PL_LAST];ktime_t usage[AMDGPU_HW_IP_NUM ];const char *pl_name[] = { [TTM_PL_VRAM ] ="vram" ,
@@ -72,15 +72,8 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file) [AMDGPU_PL_DOORBELL] = "doorbell", };unsigned int hw_ip, i; -int ret; - - ret =amdgpu_bo_reserve (vm->root.bo, false); -if (ret) -return ; - -amdgpu_vm_get_memory (vm, stats,ARRAY_SIZE (stats)); -amdgpu_bo_unreserve (vm->root.bo); +amdgpu_vm_get_memory (vm, stats);amdgpu_ctx_mgr_usage (&fpriv->ctx_mgr, usage);/*
@@ -97,7 +90,6 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)drm_print_memory_stats (p, &stats[i].drm, -DRM_GEM_OBJECT_ACTIVE |DRM_GEM_OBJECT_RESIDENT |DRM_GEM_OBJECT_PURGEABLE , pl_name[i]);
@@ -115,9 +107,11 @@ void amdgpu_show_fdinfo(struct drm_printer *p, struct drm_file *file)drm_printf (p,"amd-evicted-vram:\t%llu KiB\n" , stats[TTM_PL_VRAM ].evicted/1024UL );drm_printf (p,"amd-requested-vram:\t%llu KiB\n" , - stats[TTM_PL_VRAM ].requested/1024UL ); + (stats[TTM_PL_VRAM ].drm.shared + + stats[TTM_PL_VRAM ].drm.private) /1024UL );drm_printf (p,"amd-requested-gtt:\t%llu KiB\n" , - stats[TTM_PL_TT ].requested/1024UL ); + (stats[TTM_PL_TT ].drm.shared + + stats[TTM_PL_TT ].drm.private) /1024UL );for (hw_ip =0 ; hw_ip <AMDGPU_HW_IP_NUM ; ++hw_ip) {if (!usage[hw_ip])
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +40 -70
128 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -3
@@ -300,9 +300,7 @@ int amdgpu_bo_sync_wait_resv(struct amdgpu_device *adev, struct dma_resv *resv,int amdgpu_bo_sync_wait (struct amdgpu_bo *bo,void *owner,bool intr);u64 amdgpu_bo_gpu_offset (struct amdgpu_bo *bo);u64 amdgpu_bo_gpu_offset_no_check (struct amdgpu_bo *bo); -void amdgpu_bo_get_memory (struct amdgpu_bo *bo, -struct amdgpu_mem_stats *stats, -unsigned int size); +uint32_t amdgpu_bo_mem_stats_placement (struct amdgpu_bo *bo);uint32_t amdgpu_bo_get_preferred_domain (struct amdgpu_device *adev,uint32_t domain);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +2 -2
@@ -26,15 +26,15 @@#include <linux/dma-direction.h> #include <drm/gpu_scheduler.h> +#include <drm/ttm/ttm_placement.h> #include "amdgpu_vram_mgr.h" -#include "amdgpu.h" #define AMDGPU_PL_GDS (TTM_PL_PRIV + 0)#define AMDGPU_PL_GWS (TTM_PL_PRIV + 1)#define AMDGPU_PL_OA (TTM_PL_PRIV + 2)#define AMDGPU_PL_PREEMPT (TTM_PL_PRIV + 3)#define AMDGPU_PL_DOORBELL (TTM_PL_PRIV + 4) -#define __AMDGPU_PL_LAST (TTM_PL_PRIV + 4) +#define __AMDGPU_PL_LAST (TTM_PL_PRIV + 5)#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +130 -45
238 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +11 -6
@@ -35,6 +35,7 @@#include "amdgpu_sync.h" #include "amdgpu_ring.h" #include "amdgpu_ids.h" +#include "amdgpu_ttm.h" struct drm_exec ;
@@ -324,10 +325,7 @@ struct amdgpu_vm_fault_info {struct amdgpu_mem_stats {struct drm_memory_stats drm; -/* buffers that requested this placement */ -uint64_t requested; -/* buffers that requested this placement -* but are currently evicted */ +/* buffers that requested this placement but are currently evicted */ uint64_t evicted; };
@@ -345,6 +343,9 @@ struct amdgpu_vm {/* Lock to protect vm_bo add/del/move on all lists of vm */ spinlock_t status_lock; +/* Memory statistics for this vm, protected by the status_lock */ +struct amdgpu_mem_stats stats[__AMDGPU_PL_LAST]; +/* Per-VM and PT BOs who needs a validation */ struct list_head evicted;
@@ -525,6 +526,11 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, bool clear);bool amdgpu_vm_evictable (struct amdgpu_bo *bo);void amdgpu_vm_bo_invalidate (struct amdgpu_bo *bo,bool evicted); +void amdgpu_vm_update_stats (struct amdgpu_vm_bo_base *base, +struct ttm_resource *new_res,int sign); +void amdgpu_vm_bo_update_shared (struct amdgpu_bo *bo,int sign); +void amdgpu_vm_bo_move (struct amdgpu_bo *bo,struct ttm_resource *new_mem, +bool evicted);uint64_t amdgpu_vm_map_gart (const dma_addr_t *pages_addr,uint64_t addr);struct amdgpu_bo_va *amdgpu_vm_bo_find (struct amdgpu_vm *vm,struct amdgpu_bo *bo);
@@ -575,8 +581,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm);void amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm);void amdgpu_vm_get_memory (struct amdgpu_vm *vm, -struct amdgpu_mem_stats *stats, -unsigned int size); +struct amdgpu_mem_stats stats[__AMDGPU_PL_LAST]);int amdgpu_vm_pt_clear (struct amdgpu_device *adev,struct amdgpu_vm *vm,struct amdgpu_bo_vm *vmbo,bool immediate);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_pt.c +1 -0
@@ -537,6 +537,7 @@ static void amdgpu_vm_pt_free(struct amdgpu_vm_bo_base *entry)if (!entry->bo)return ; +amdgpu_vm_update_stats (entry, entry->bo->tbo.resource,-1 ); entry->bo->vm_bo =NULL ;ttm_bo_set_bulk_move (&entry->bo->tbo,NULL );
Signature · 1 line
2.34.1