drm/amdgpu: Final fix for https://bugs.freedesktop.org/106872
Subsystems (2)
cover drm/amdgpu: Final fix for https://bugs.freedesktop.org/106872
From: Michel Dänzer <[email protected]>
Finally got confirmation from the debugging patch in the bug report that these values need to be atomic, or they can get corrupted.
Patch 1 is so that it's not necessary to use two atomic values for computing the amount of non-pinned CPU visible VRAM, as that could still give an inconsistent result if there are BOs being (un)pinned concurrently.
Michel Dänzer (3):
drm/amdgpu: Keep track of amount of pinned CPU visible VRAM drm/amdgpu: Make pin_size values atomic
drm/amdgpu: Warn and update pin_size values when destroying a pinned
BO
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 23 ++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 43 +++++++++++++++++----- 4 files changed, 49 insertions(+), 25 deletions(-)
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180711162342.14835-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org
PATCH 1/3 drm/amdgpu: Keep track of amount of pinned CPU visible VRAM
From: Michel Dänzer <[email protected]>
Instead of CPU invisible VRAM. Preparation for the following, no functional change intended.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -1593,7 +1593,7 @@ struct amdgpu_device {/* tracking pinned memory */ u64 vram_pin_size; -u64 invisible_pin_size; +u64 visible_pin_size;u64 gart_pin_size;/* amdkfd interface */
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -3
@@ -504,7 +504,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file vram_gtt.vram_size = adev->gmc.real_vram_size; vram_gtt.vram_size -= adev->vram_pin_size; vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size); + vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; vram_gtt.gtt_size -= adev->gart_pin_size;
@@ -525,8 +525,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - - (adev->vram_pin_size - adev->invisible_pin_size); + adev->gmc.visible_vram_size - adev->visible_pin_size; mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +4 -2
@@ -917,7 +917,8 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->invisible_pin_size +=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size += +amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { adev->gart_pin_size +=amdgpu_bo_size (bo); }
@@ -969,7 +970,8 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->invisible_pin_size -=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size -= +amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { adev->gart_pin_size -=amdgpu_bo_size (bo); }
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180711162342.14835-2-michel-otUistvHUpPR7s880joybQ@public.gmane.org
Re: [PATCH 1/3] drm/amdgpu: Keep track of amount of pinned CPU visible VRAM
Am 11.07.2018 um 18:23 schrieb Michel Dänzer:
Quoted 54 lines
From: Michel Dänzer <[email protected]>
Instead of CPU invisible VRAM. Preparation for the following, no functional change intended.
Signed-off-by Michel Dänzer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++-- 3 files changed, 7 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-1@@ -1593,7 +1593,7 @@ struct amdgpu_device {/* tracking pinned memory */ u64 vram_pin_size; -u64 invisible_pin_size; +u64 visible_pin_size;u64 gart_pin_size;/* amdkfd interface */ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-3@@ -504,7 +504,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file vram_gtt.vram_size = adev->gmc.real_vram_size; vram_gtt.vram_size -= adev->vram_pin_size; vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size); + vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; vram_gtt.gtt_size -= adev->gart_pin_size;@@ -525,8 +525,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - - (adev->vram_pin_size - adev->invisible_pin_size); + adev->gmc.visible_vram_size - adev->visible_pin_size; mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, · line 921
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1@@ -917,7 +917,8 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->invisible_pin_size +=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size += +amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo);
Any particular reason why we should not invert amdgpu_vram_mgr_bo_invisible_size() as well?
Apart from that looks good to me,
Christian.
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_unpin(struct amdgpu_bo *bo) · line 977
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1}else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { adev->gart_pin_size +=amdgpu_bo_size (bo); }@@ -969,7 +970,8 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->invisible_pin_size -=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size -= +amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { adev->gart_pin_size -=amdgpu_bo_size (bo); }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 262947bc-5532-2a0a-d48b-e54f6dc840eb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 1/3] drm/amdgpu: Keep track of amount of pinned CPU visible VRAM
Quoted 20 lines · Christian König
Am 11.07.2018 um 18:23 schrieb Michel Dänzer:
Quoted 19 lines
From: Michel Dänzer <[email protected]>
Instead of CPU invisible VRAM. Preparation for the following, no functional change intended.
Signed-off-by Michel Dänzer <[email protected]>[...]
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-0@@ -917,7 +917,8 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo,u32 domain, domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type); if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, · line 921
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-1adev->vram_pin_size += amdgpu_bo_size(bo); - adev->invisible_pin_size +=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size += + amdgpu_bo_size(bo) - amdgpu_vram_mgr_bo_invisible_size(bo);Any particular reason why we should not invert
amdgpu_vram_mgr_bo_invisible_size()as well?
Right, that occurred to me as well in the meantime. I was planning to send a follow-up patch for this, but since patch 3 needs a v2 anyway, I'll do a v2 of this one as well.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 2/3 drm/amdgpu: Make pin_size values atomic
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
Concurrent execution of the non-atomic arithmetic could result in completely bogus values.
Cc: [email protected]
Bugzilla: https://bugs.freedesktop.org/106872
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 22 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -3
@@ -1592,9 +1592,9 @@ struct amdgpu_device {DECLARE_HASHTABLE (mn_hash,7 );/* tracking pinned memory */ -u64 vram_pin_size; -u64 visible_pin_size; -u64 gart_pin_size; +atomic64_t vram_pin_size; +atomic64_t visible_pin_size; +atomic64_t gart_pin_size;/* amdkfd interface */ struct kfd_dev *kfd;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -262,7 +262,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,return ; } - total_vram = adev->gmc.real_vram_size - adev->vram_pin_size; + total_vram = adev->gmc.real_vram_size -atomic64_read (&adev->vram_pin_size); used_vram =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); free_vram = used_vram >= total_vram ?0 : total_vram - used_vram;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +11 -11
@@ -501,13 +501,13 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filecase AMDGPU_INFO_VRAM_GTT : {struct drm_amdgpu_info_vram_gtt vram_gtt; - vram_gtt.vram_size = adev->gmc.real_vram_size; - vram_gtt.vram_size -= adev->vram_pin_size; - vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; + vram_gtt.vram_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); + vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; - vram_gtt.gtt_size -= adev->gart_pin_size; + vram_gtt.gtt_size -=atomic64_read (&adev->gart_pin_size);return copy_to_user (out, &vram_gtt,min ((size_t )size,sizeof (vram_gtt))) ? -EFAULT :0 ; }
@@ -516,16 +516,16 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filememset (&mem,0 ,sizeof (mem)); mem.vram.total_heap_size = adev->gmc.real_vram_size; - mem.vram.usable_heap_size = - adev->gmc.real_vram_size - adev->vram_pin_size; + mem.vram.usable_heap_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); mem.vram.heap_usage =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.vram.max_allocation = mem.vram.usable_heap_size *3 /4 ; mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; - mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - adev->visible_pin_size; + mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =
@@ -533,8 +533,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT ].size; mem.gtt.total_heap_size *=PAGE_SIZE ; - mem.gtt.usable_heap_size = mem.gtt.total_heap_size - - adev->gart_pin_size; + mem.gtt.usable_heap_size = mem.gtt.total_heap_size - +atomic64_read (&adev->gart_pin_size); mem.gtt.heap_usage =amdgpu_gtt_mgr_usage (&adev->mman.bdev.man[TTM_PL_TT ]); mem.gtt.max_allocation = mem.gtt.usable_heap_size *3 /4 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +10 -8
@@ -916,11 +916,12 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { - adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->visible_pin_size += -amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_add (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { - adev->gart_pin_size +=amdgpu_bo_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->gart_pin_size); } error:
@@ -969,11 +970,12 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)return 0 ;if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { - adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->visible_pin_size -= -amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); +atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { - adev->gart_pin_size -=amdgpu_bo_size (bo); +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); }for (i =0 ; i < bo->placement.num_placement; i++) {
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180711162342.14835-3-michel-otUistvHUpPR7s880joybQ@public.gmane.org
Christian König
Reviewed-byRe: [PATCH 2/3] drm/amdgpu: Make pin_size values atomic
Am 11.07.2018 um 18:23 schrieb Michel Dänzer:
Quoted 8 lines
From: Michel Dänzer <[email protected]>
Concurrent execution of the non-atomic arithmetic could result in completely bogus values.
Cc: [email protected]
Bugzilla: https://bugs.freedesktop.org/106872Signed-off-by Michel Dänzer <[email protected]>
Quoted 120 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 22 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 18 ++++++++++-------- 4 files changed, 25 insertions(+), 23 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-3@@ -1592,9 +1592,9 @@ struct amdgpu_device {DECLARE_HASHTABLE (mn_hash,7 );/* tracking pinned memory */ -u64 vram_pin_size; -u64 visible_pin_size; -u64 gart_pin_size; +atomic64_t vram_pin_size; +atomic64_t visible_pin_size; +atomic64_t gart_pin_size;/* amdkfd interface */ struct kfd_dev *kfd;drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1
-1@@ -262,7 +262,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,return ; } - total_vram = adev->gmc.real_vram_size - adev->vram_pin_size; + total_vram = adev->gmc.real_vram_size -atomic64_read (&adev->vram_pin_size); used_vram =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); free_vram = used_vram >= total_vram ?0 : total_vram - used_vram;drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +11
-11@@ -501,13 +501,13 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filecase AMDGPU_INFO_VRAM_GTT : {struct drm_amdgpu_info_vram_gtt vram_gtt; - vram_gtt.vram_size = adev->gmc.real_vram_size; - vram_gtt.vram_size -= adev->vram_pin_size; - vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; + vram_gtt.vram_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); + vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; - vram_gtt.gtt_size -= adev->gart_pin_size; + vram_gtt.gtt_size -=atomic64_read (&adev->gart_pin_size);return copy_to_user (out, &vram_gtt,min ((size_t )size,sizeof (vram_gtt))) ? -EFAULT :0 ; }@@ -516,16 +516,16 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filememset (&mem,0 ,sizeof (mem)); mem.vram.total_heap_size = adev->gmc.real_vram_size; - mem.vram.usable_heap_size = - adev->gmc.real_vram_size - adev->vram_pin_size; + mem.vram.usable_heap_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); mem.vram.heap_usage =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.vram.max_allocation = mem.vram.usable_heap_size *3 /4 ; mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; - mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - adev->visible_pin_size; + mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =@@ -533,8 +533,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT ].size; mem.gtt.total_heap_size *=PAGE_SIZE ; - mem.gtt.usable_heap_size = mem.gtt.total_heap_size - - adev->gart_pin_size; + mem.gtt.usable_heap_size = mem.gtt.total_heap_size - +atomic64_read (&adev->gart_pin_size); mem.gtt.heap_usage =amdgpu_gtt_mgr_usage (&adev->mman.bdev.man[TTM_PL_TT ]); mem.gtt.max_allocation = mem.gtt.usable_heap_size *3 /4 ;drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-7@@ -916,11 +916,12 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { - adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->visible_pin_size += -amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_add (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { - adev->gart_pin_size +=amdgpu_bo_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->gart_pin_size); } error:@@ -969,11 +970,12 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)return 0 ;if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { - adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->visible_pin_size -= -amdgpu_bo_size (bo) -amdgpu_vram_mgr_bo_invisible_size (bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_unpin(struct amdgpu_bo *bo) · line 981
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5
-1+atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { - adev->gart_pin_size -=amdgpu_bo_size (bo); +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); }for (i =0 ; i < bo->placement.num_placement; i++) {
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/3 drm/amdgpu: Warn and update pin_size values when destroying a pinned BO
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
This shouldn't happen, but if it does, we'll get a backtrace of the caller, and update the pin_size values as needed.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +29 -8
@@ -63,10 +63,38 @@ static bool amdgpu_need_backup(struct amdgpu_device *adev)return true; } +/** +* amdgpu_bo_subtract_pin_size - Remove BO from pin size accounting +* +* @bo: &amdgpu_bo buffer object +* +* This function is called when a BO stops being pinned, and updates the +* &amdgpu_device pin_size values accordingly. +*/ +static void amdgpu_bo_subtract_pin_size (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); + }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); + } +} +static void amdgpu_ttm_bo_destroy (struct ttm_buffer_object *tbo) {struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); +int i; + +for (i =0 ; i < bo->placement.num_placement; i++) { +if (WARN_ON_ONCE (bo->placements[i].flags &TTM_PL_FLAG_NO_EVICT )) +amdgpu_bo_subtract_pin_size (bo); + }if (bo->kfd_bo)amdgpu_amdkfd_unreserve_system_memory_limit (bo);
@@ -969,14 +997,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->pin_count)return 0 ; -if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); -atomic64_sub (amdgpu_bo_size (bo) - -amdgpu_vram_mgr_bo_invisible_size (bo), - &adev->visible_pin_size); - }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); - } +amdgpu_bo_subtract_pin_size (bo);for (i =0 ; i < bo->placement.num_placement; i++) { bo->placements[i].lpfn =0 ;
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180711162342.14835-4-michel-otUistvHUpPR7s880joybQ@public.gmane.org
Re: [PATCH 3/3] drm/amdgpu: Warn and update pin_size values when destroying a pinned BO
Am 11.07.2018 um 18:23 schrieb Michel Dänzer:
Quoted 40 lines
From: Michel Dänzer <[email protected]>
This shouldn't happen, but if it does, we'll get a backtrace of the caller, and update the
pin_sizevalues as needed.Signed-off-by Michel Dänzer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 37 +++++++++++++++++----- 1 file changed, 29 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +22
-0@@ -63,10 +63,38 @@ static bool amdgpu_need_backup(struct amdgpu_device *adev)return true; } +/** +* amdgpu_bo_subtract_pin_size - Remove BO from pin size accounting +* +* @bo: &amdgpu_bo buffer object +* +* This function is called when a BO stops being pinned, and updates the +* &amdgpu_device pin_size values accordingly. +*/ +static void amdgpu_bo_subtract_pin_size (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_bo_size (bo) - +amdgpu_vram_mgr_bo_invisible_size (bo), + &adev->visible_pin_size); + }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); + } +} +
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c static bool amdgpu_need_backup(struct amdgpu_device *adev) · line 97
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6
-0static void amdgpu_ttm_bo_destroy (struct ttm_buffer_object *tbo) {struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); +int i; + +for (i =0 ; i < bo->placement.num_placement; i++) { +if (WARN_ON_ONCE (bo->placements[i].flags &TTM_PL_FLAG_NO_EVICT )) +amdgpu_bo_subtract_pin_size (bo); + }
That would subtract the values once for each placement which is not something we want. I would rather take a look at bo->pin_count.
Regards,
Christian.
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0
-2if (bo->kfd_bo)amdgpu_amdkfd_unreserve_system_memory_limit (bo);@@ -969,14 +997,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->pin_count)return 0 ; -if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_unpin(struct amdgpu_bo *bo) · line 1003
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1
-6-atomic64_sub (amdgpu_bo_size (bo) - -amdgpu_vram_mgr_bo_invisible_size (bo), - &adev->visible_pin_size); - }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); - } +amdgpu_bo_subtract_pin_size (bo);for (i =0 ; i < bo->placement.num_placement; i++) { bo->placements[i].lpfn =0 ;
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 1/3 drm/amdgpu: Keep track of amount of pinned CPU visible VRAM
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
Instead of CPU invisible VRAM. Preparation for the following, no functional change intended.
v2:
* Also change amdgpu_vram_mgr_bo_invisible_size to amdgpu_vram_mgr_bo_visible_size, allowing further simplification (Christian König)
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 20 ++++++++------------ 5 files changed, 14 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
@@ -1593,7 +1593,7 @@ struct amdgpu_device {/* tracking pinned memory */ u64 vram_pin_size; -u64 invisible_pin_size; +u64 visible_pin_size;u64 gart_pin_size;/* amdkfd interface */
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -3
@@ -504,7 +504,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file vram_gtt.vram_size = adev->gmc.real_vram_size; vram_gtt.vram_size -= adev->vram_pin_size; vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size); + vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; vram_gtt.gtt_size -= adev->gart_pin_size;
@@ -525,8 +525,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - - (adev->vram_pin_size - adev->invisible_pin_size); + adev->gmc.visible_vram_size - adev->visible_pin_size; mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
@@ -917,7 +917,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->invisible_pin_size +=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size +=amdgpu_vram_mgr_bo_visible_size (bo); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { adev->gart_pin_size +=amdgpu_bo_size (bo); }
@@ -969,7 +969,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->invisible_pin_size -=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size -=amdgpu_vram_mgr_bo_visible_size (bo); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { adev->gart_pin_size -=amdgpu_bo_size (bo); }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -1
@@ -73,7 +73,7 @@ bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);uint64_t amdgpu_gtt_mgr_usage (struct ttm_mem_type_manager *man);int amdgpu_gtt_mgr_recover (struct ttm_mem_type_manager *man); -u64 amdgpu_vram_mgr_bo_invisible_size (struct amdgpu_bo *bo); +u64 amdgpu_vram_mgr_bo_visible_size (struct amdgpu_bo *bo);uint64_t amdgpu_vram_mgr_usage (struct ttm_mem_type_manager *man);uint64_t amdgpu_vram_mgr_vis_usage (struct ttm_mem_type_manager *man);
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +8 -12
@@ -97,33 +97,29 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, }/** -* amdgpu_vram_mgr_bo_invisible_size - CPU invisible BO size +* amdgpu_vram_mgr_bo_visible_size - CPU visible BO size * * @bo: &amdgpu_bo buffer object (must be in VRAM) * * Returns: -* How much of the given &amdgpu_bo buffer object lies in CPU invisible VRAM. +* How much of the given &amdgpu_bo buffer object lies in CPU visible VRAM. */ -u64 amdgpu_vram_mgr_bo_invisible_size (struct amdgpu_bo *bo) +u64 amdgpu_vram_mgr_bo_visible_size (struct amdgpu_bo *bo) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct ttm_mem_reg *mem = &bo->tbo.mem;struct drm_mm_node *nodes = mem->mm_node;unsigned pages = mem->num_pages; -u64 usage =0 ; +u64 usage;if (amdgpu_gmc_vram_full_visible (&adev->gmc)) -return 0 ; +return amdgpu_bo_size (bo);if (mem->start >= adev->gmc.visible_vram_size >>PAGE_SHIFT ) -return amdgpu_bo_size (bo); +return 0 ; -while (nodes && pages) { - usage += nodes->size <<PAGE_SHIFT ; - usage -=amdgpu_vram_mgr_vis_size (adev, nodes); - pages -= nodes->size; - ++nodes; - } +for (usage =0 ; nodes && pages; pages -= nodes->size, nodes++) + usage +=amdgpu_vram_mgr_vis_size (adev, nodes);return usage; }
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180712143751.14353-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org
PATCH v2 2/3 drm/amdgpu: Make pin_size values atomic
From: Michel Dänzer <[email protected]>
Concurrent execution of the non-atomic arithmetic could result in completely bogus values.
v2:
* Rebased on v2 of the previous patch
Cc: [email protected]
Bugzilla: https://bugs.freedesktop.org/106872
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 6 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 22 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 14 ++++++++------ 4 files changed, 23 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -3
@@ -1592,9 +1592,9 @@ struct amdgpu_device {DECLARE_HASHTABLE (mn_hash,7 );/* tracking pinned memory */ -u64 vram_pin_size; -u64 visible_pin_size; -u64 gart_pin_size; +atomic64_t vram_pin_size; +atomic64_t visible_pin_size; +atomic64_t gart_pin_size;/* amdkfd interface */ struct kfd_dev *kfd;
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
@@ -262,7 +262,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,return ; } - total_vram = adev->gmc.real_vram_size - adev->vram_pin_size; + total_vram = adev->gmc.real_vram_size -atomic64_read (&adev->vram_pin_size); used_vram =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); free_vram = used_vram >= total_vram ?0 : total_vram - used_vram;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +11 -11
@@ -501,13 +501,13 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filecase AMDGPU_INFO_VRAM_GTT : {struct drm_amdgpu_info_vram_gtt vram_gtt; - vram_gtt.vram_size = adev->gmc.real_vram_size; - vram_gtt.vram_size -= adev->vram_pin_size; - vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; + vram_gtt.vram_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); + vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; - vram_gtt.gtt_size -= adev->gart_pin_size; + vram_gtt.gtt_size -=atomic64_read (&adev->gart_pin_size);return copy_to_user (out, &vram_gtt,min ((size_t )size,sizeof (vram_gtt))) ? -EFAULT :0 ; }
@@ -516,16 +516,16 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_filememset (&mem,0 ,sizeof (mem)); mem.vram.total_heap_size = adev->gmc.real_vram_size; - mem.vram.usable_heap_size = - adev->gmc.real_vram_size - adev->vram_pin_size; + mem.vram.usable_heap_size = adev->gmc.real_vram_size - +atomic64_read (&adev->vram_pin_size); mem.vram.heap_usage =amdgpu_vram_mgr_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.vram.max_allocation = mem.vram.usable_heap_size *3 /4 ; mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; - mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - adev->visible_pin_size; + mem.cpu_accessible_vram.usable_heap_size = adev->gmc.visible_vram_size - +atomic64_read (&adev->visible_pin_size); mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =
@@ -533,8 +533,8 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT ].size; mem.gtt.total_heap_size *=PAGE_SIZE ; - mem.gtt.usable_heap_size = mem.gtt.total_heap_size - - adev->gart_pin_size; + mem.gtt.usable_heap_size = mem.gtt.total_heap_size - +atomic64_read (&adev->gart_pin_size); mem.gtt.heap_usage =amdgpu_gtt_mgr_usage (&adev->mman.bdev.man[TTM_PL_TT ]); mem.gtt.max_allocation = mem.gtt.usable_heap_size *3 /4 ;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -6
@@ -916,10 +916,11 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { - adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->visible_pin_size +=amdgpu_vram_mgr_bo_visible_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_add (amdgpu_vram_mgr_bo_visible_size (bo), + &adev->visible_pin_size); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { - adev->gart_pin_size +=amdgpu_bo_size (bo); +atomic64_add (amdgpu_bo_size (bo), &adev->gart_pin_size); } error:
@@ -968,10 +969,11 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)return 0 ;if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { - adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->visible_pin_size -=amdgpu_vram_mgr_bo_visible_size (bo); +atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_vram_mgr_bo_visible_size (bo), + &adev->visible_pin_size); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { - adev->gart_pin_size -=amdgpu_bo_size (bo); +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); }for (i =0 ; i < bo->placement.num_placement; i++) {
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 3/3 drm/amdgpu: Warn and update pin_size values when destroying a pinned BO
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
This shouldn't happen, but if it does, we'll get a backtrace of the caller, and update the pin_size values as needed.
v2:
* Check bo->pin_count instead of placement flags (Christian König)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +25 -7
@@ -63,11 +63,35 @@ static bool amdgpu_need_backup(struct amdgpu_device *adev)return true; } +/** +* amdgpu_bo_subtract_pin_size - Remove BO from pin_size accounting +* +* @bo: &amdgpu_bo buffer object +* +* This function is called when a BO stops being pinned, and updates the +* &amdgpu_device pin_size values accordingly. +*/ +static void amdgpu_bo_subtract_pin_size (struct amdgpu_bo *bo) +{ +struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); + +if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); +atomic64_sub (amdgpu_vram_mgr_bo_visible_size (bo), + &adev->visible_pin_size); + }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { +atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); + } +} +static void amdgpu_ttm_bo_destroy (struct ttm_buffer_object *tbo) {struct amdgpu_device *adev =amdgpu_ttm_adev (tbo->bdev);struct amdgpu_bo *bo =ttm_to_amdgpu_bo (tbo); +if (WARN_ON_ONCE (bo->pin_count >0 )) +amdgpu_bo_subtract_pin_size (bo); +if (bo->kfd_bo)amdgpu_amdkfd_unreserve_system_memory_limit (bo);
@@ -968,13 +992,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->pin_count)return 0 ; -if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->vram_pin_size); -atomic64_sub (amdgpu_vram_mgr_bo_visible_size (bo), - &adev->visible_pin_size); - }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { -atomic64_sub (amdgpu_bo_size (bo), &adev->gart_pin_size); - } +amdgpu_bo_subtract_pin_size (bo);for (i =0 ; i < bo->placement.num_placement; i++) { bo->placements[i].lpfn =0 ;
Signature · 6 lines
2.18.0 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v2 1/3] drm/amdgpu: Keep track of amount of pinned CPU visible VRAM
In reply to a message not in the archiveAm 12.07.2018 um 16:37 schrieb Michel Dänzer:
Quoted 5 lines
From: Michel Dänzer <[email protected]>
Instead of CPU invisible VRAM. Preparation for the following, no functional change intended.
Quoted 7 lines
v2:
* Also changeamdgpu_vram_mgr_bo_invisible_sizetoamdgpu_vram_mgr_bo_visible_size, allowing further simplification (Christian König)Signed-off-by Michel Dänzer <[email protected]>
Nice, that makes the code even more cleaner than I thought it would :)
All three are Reviewed-by: Christian König <[email protected]>.
Thanks,
Christian.
Quoted 115 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 5 ++--- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 20 ++++++++------------ 5 files changed, 14 insertions(+), 19 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-1@@ -1593,7 +1593,7 @@ struct amdgpu_device {/* tracking pinned memory */ u64 vram_pin_size; -u64 invisible_pin_size; +u64 visible_pin_size;u64 gart_pin_size;/* amdkfd interface */ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2
-3@@ -504,7 +504,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file vram_gtt.vram_size = adev->gmc.real_vram_size; vram_gtt.vram_size -= adev->vram_pin_size; vram_gtt.vram_cpu_accessible_size = adev->gmc.visible_vram_size; - vram_gtt.vram_cpu_accessible_size -= (adev->vram_pin_size - adev->invisible_pin_size); + vram_gtt.vram_cpu_accessible_size -= adev->visible_pin_size; vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT ].size; vram_gtt.gtt_size *=PAGE_SIZE ; vram_gtt.gtt_size -= adev->gart_pin_size;@@ -525,8 +525,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file mem.cpu_accessible_vram.total_heap_size = adev->gmc.visible_vram_size; mem.cpu_accessible_vram.usable_heap_size = - adev->gmc.visible_vram_size - - (adev->vram_pin_size - adev->invisible_pin_size); + adev->gmc.visible_vram_size - adev->visible_pin_size; mem.cpu_accessible_vram.heap_usage =amdgpu_vram_mgr_vis_usage (&adev->mman.bdev.man[TTM_PL_VRAM ]); mem.cpu_accessible_vram.max_allocation =drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2
-2@@ -917,7 +917,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, domain =amdgpu_mem_type_to_domain (bo->tbo.mem.mem_type);if (domain ==AMDGPU_GEM_DOMAIN_VRAM ) { adev->vram_pin_size +=amdgpu_bo_size (bo); - adev->invisible_pin_size +=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size +=amdgpu_vram_mgr_bo_visible_size (bo); }else if (domain ==AMDGPU_GEM_DOMAIN_GTT ) { adev->gart_pin_size +=amdgpu_bo_size (bo); }@@ -969,7 +969,7 @@ int amdgpu_bo_unpin(struct amdgpu_bo *bo)if (bo->tbo.mem.mem_type ==TTM_PL_VRAM ) { adev->vram_pin_size -=amdgpu_bo_size (bo); - adev->invisible_pin_size -=amdgpu_vram_mgr_bo_invisible_size (bo); + adev->visible_pin_size -=amdgpu_vram_mgr_bo_visible_size (bo); }else if (bo->tbo.mem.mem_type ==TTM_PL_TT ) { adev->gart_pin_size -=amdgpu_bo_size (bo); }drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1
-1@@ -73,7 +73,7 @@ bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);uint64_t amdgpu_gtt_mgr_usage (struct ttm_mem_type_manager *man);int amdgpu_gtt_mgr_recover (struct ttm_mem_type_manager *man); -u64 amdgpu_vram_mgr_bo_invisible_size (struct amdgpu_bo *bo); +u64 amdgpu_vram_mgr_bo_visible_size (struct amdgpu_bo *bo);uint64_t amdgpu_vram_mgr_usage (struct ttm_mem_type_manager *man);uint64_t amdgpu_vram_mgr_vis_usage (struct ttm_mem_type_manager *man);drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +6
-7@@ -97,33 +97,29 @@ static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, }/** -* amdgpu_vram_mgr_bo_invisible_size - CPU invisible BO size +* amdgpu_vram_mgr_bo_visible_size - CPU visible BO size * * @bo: &amdgpu_bo buffer object (must be in VRAM) * * Returns: -* How much of the given &amdgpu_bo buffer object lies in CPU invisible VRAM. +* How much of the given &amdgpu_bo buffer object lies in CPU visible VRAM. */ -u64 amdgpu_vram_mgr_bo_invisible_size (struct amdgpu_bo *bo) +u64 amdgpu_vram_mgr_bo_visible_size (struct amdgpu_bo *bo) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev);struct ttm_mem_reg *mem = &bo->tbo.mem;struct drm_mm_node *nodes = mem->mm_node;unsigned pages = mem->num_pages; -u64 usage =0 ; +u64 usage;if (amdgpu_gmc_vram_full_visible (&adev->gmc)) -return 0 ; +return amdgpu_bo_size (bo);if (mem->start >= adev->gmc.visible_vram_size >>PAGE_SHIFT ) -return amdgpu_bo_size (bo); +return 0 ; -while (nodes && pages) {
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c static u64 amdgpu_vram_mgr_vis_size(struct amdgpu_device *adev, · line 125
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c +2
-5- usage += nodes->size <<PAGE_SHIFT ; - usage -=amdgpu_vram_mgr_vis_size (adev, nodes); - pages -= nodes->size; - ++nodes; - } +for (usage =0 ; nodes && pages; pages -= nodes->size, nodes++) + usage +=amdgpu_vram_mgr_vis_size (adev, nodes);return usage; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx