drm/ttm,amdgpu: Introduce LRU bulk move functionality
Subsystems (4)
v3 cover drm/ttm,amdgpu: Introduce LRU bulk move functionality
The idea and proposal is originally from Christian, and I continue to work to deliver it.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.
Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit 0bbf32026cf5ba41e9922b30e26e1bed1ecd38ae
However, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever amdgpu_vm_validate_pt_bos() is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.
While doing so we note the beginning and end of this block in the LRU list.
Now when amdgpu_vm_validate_pt_bos() is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.
Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+
After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
Changes from V1 -> V2:
- Fix to missed the BOs in relocated/moved that should be also moved to the end of LRU.
Changes from V2 -> V3:
- Remove unused parameter and use list_for_each_entry instead of the one with save entry.
Thanks,
Rui
Christian König (2):
drm/ttm: add helper structures for bulk moves on lru list drm/ttm: revise ttm_bo_move_to_lru_tail to support bulk moves
Huang Rui (3):
drm/ttm: add bulk move function on LRU
drm/amdgpu: use bulk moves for efficient VM LRU handling (v3) drm/amdgpu: move PD/PT bos on LRU again
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 ++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ drivers/gpu/drm/ttm/ttm_bo.c | 78 +++++++++++++++++++++++++++++++++- include/drm/ttm/ttm_bo_api.h | 16 ++++++- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++ 5 files changed, 182 insertions(+), 19 deletions(-)
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 1534154331-11810-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
PATCH v3 1/5 drm/ttm: add helper structures for bulk moves on lru list
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
--- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
include/drm/ttm/ttm_bo_driver.h +28 -0
@@ -491,6 +491,34 @@ struct ttm_bo_device { };/** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { +struct ttm_buffer_object *first; +struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/ +struct ttm_lru_bulk_move { +struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY ]; +}; + +/** * ttm_flag_masked * * @old: Pointer to the result and original value.
Signature · 6 lines
2.7.4 _______________________________________________ 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): 1534154331-11810-2-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v3 1/5] drm/ttm: add helper structures for bulk moves on lru list
Am 13.08.2018 um 11:58 schrieb Huang Rui:
Quoted 8 lines
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>
If you ask me that looks like it should work now, but I'm prepossessed because I helped creating this.
Alex, David or Jerry can somebody else take a look as well?
Thanks,
Christian.
Quoted 33 lines
--- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/drm/ttm/ttm_bo_driver.h +21
-0@@ -491,6 +491,34 @@ struct ttm_bo_device { };/** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { +struct ttm_buffer_object *first; +struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/
include/drm/ttm/ttm_bo_driver.h struct ttm_bo_device { · line 524
Quoted 10 lines
include/drm/ttm/ttm_bo_driver.h +7
-0+struct ttm_lru_bulk_move { +struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY ]; +}; + +/** * ttm_flag_masked * * @old: Pointer to the result and original value.
_______________________________________________
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): d0ebdd92-73a7-7959-4df0-391f3dd27526-5C7GfCeVMHo@public.gmane.org
zhoucm1
Acked-by Chunming ZhouRe: [PATCH v3 1/5] drm/ttm: add helper structures for bulk moves on lru list
Quoted 6 lines · Christian König
Am 13.08.2018 um 11:58 schrieb Huang Rui:
Quoted 5 lines
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>If you ask me that looks like it should work now, but I'm prepossessed because I helped creating this.
Alex, David or Jerry can somebody else take a look as well?
remember position, list ops...
Quoted 43 lines
Thanks,
Christian.Quoted 39 lines
---
include/drm/ttm/ttm_bo_driver.h| 28 ++++++++++++++++++++++++++++1 file changed, 28 insertions(+)include/drm/ttm/ttm_bo_driver.h +28
-0@@ -491,6 +491,34 @@ struct ttm_bo_device { }; /** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { + struct ttm_buffer_object *first; + struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/ +struct ttm_lru_bulk_move { + struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY]; + struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY]; + struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY]; +}; + +/**
Quoted 8 lines
include/drm/ttm/ttm_bo_driver.h struct ttm_bo_device { · line 524
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +0
-0* ttm_flag_masked * * @old: Pointer to the result and original value._______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): b993176a-cf49-d3b7-9be1-feb7dc95456f-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v3 1/5] drm/ttm: add helper structures for bulk moves on lru list
Quoted 13 lines · David(ChunMing)
Quoted 10 lines · Christian König
Am 13.08.2018 um 11:58 schrieb Huang Rui:
Quoted 8 lines
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>
Quoted 7 lines
Quoted 4 lines
If you ask me that looks like it should work now, but I'm prepossessed because I helped creating this.
Alex, David or Jerry can somebody else take a look as well?
remember position, list ops...
Acked-by Chunming Zhou <[email protected]>
Thanks David, any comments are warm for me.
Best Regards,
Ray
Quoted 44 lines
Quoted 44 lines
Thanks,
Christian.Quoted 40 lines
---
include/drm/ttm/ttm_bo_driver.h| 28 ++++++++++++++++++++++++++++1 file changed, 28 insertions(+)include/drm/ttm/ttm_bo_driver.h +28
-0@@ -491,6 +491,34 @@ struct ttm_bo_device { }; /** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { + struct ttm_buffer_object *first; + struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/ +struct ttm_lru_bulk_move { + struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY]; + struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY]; + struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY]; +}; + +/**
Quoted 9 lines
Quoted 8 lines
include/drm/ttm/ttm_bo_driver.h struct ttm_bo_device { · line 524
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +0
-0* ttm_flag_masked * * @old: Pointer to the result and original value._______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Zhang, Jerry (Junwei)
Reviewed-by Junwei ZhangRe: [PATCH v3 1/5] drm/ttm: add helper structures for bulk moves on lru list
In reply to a message not in the archiveQuoted 6 lines · Christian König
Am 13.08.2018 um 11:58 schrieb Huang Rui:
Quoted 5 lines
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>If you ask me that looks like it should work now, but I'm prepossessed because I helped creating this.
Alex, David or Jerry can somebody else take a look as well?
Patch 1, 2, 3, 5 are
Patch 4: comments inline.
BTW, a per-vm bo lru may be more efficient, but not a common way.
bulk move could improve that, while possibly there are some worse cases and better cases.
e.g. remark the bo position for target BO, like PD/PT bo and per-vm bo, in which range may include other BOs If the target BO range include more other BOs, may cause evict or anything else low efficiency. We hope target BO grouped together as much as possible, and be moved.
(if not, please correct me)
Regards,
Jerry
Quoted 43 lines
Thanks,
Christian.Quoted 39 lines
--- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/drm/ttm/ttm_bo_driver.h +28
-0@@ -491,6 +491,34 @@ struct ttm_bo_device { };/** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { +struct ttm_buffer_object *first; +struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/ +struct ttm_lru_bulk_move { +struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY ]; +}; + +/**
Quoted 8 lines
include/drm/ttm/ttm_bo_driver.h struct ttm_bo_device { · line 524
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +0
-0* ttm_flag_masked * * @old: Pointer to the result and original value. _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
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): [email protected]
Re: [PATCH v3 1/5] drm/ttm: add helper structures for bulk moves on lru list
Quoted 21 lines · Jerry (Junwei)
Quoted 6 lines · Christian König
Am 13.08.2018 um 11:58 schrieb Huang Rui:
Quoted 5 lines
From: Christian König <[email protected]>
Add bulk move pos to store the pointer of first and last buffer object. The list in between will be bulk moved on lru list.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>If you ask me that looks like it should work now, but I'm prepossessed because I helped creating this.
Alex, David or Jerry can somebody else take a look as well?
Patch 1, 2, 3, 5 are
Reviewed-by Junwei Zhang <[email protected]>Patch 4: comments inline.
Quoted 8 lines
BTW, a per-vm bo lru may be more efficient, but not a common way.
bulk move could improve that, while possibly there are some worse cases and better cases.e.g. remark the bo position for target BO, like PD/PT bo and per-vm bo, in which range may include other BOs If the target BO range include more other BOs, may cause evict or anything else low efficiency. We hope target BO grouped together as much as possible, and be moved.
(if not, please correct me)
Thanks, Jerry. Actually, here we will remember both per-vm and PD/PT BOs positions in the same VM. And move them one time to the end of LRU. And won't move them one by one. The time complexity is from O(n) to O(1). The performance issue is not caused by eviction, but by the many times of moving on LRU list. So for now, we do the bulk move instead.
Thanks,
Ray
Quoted 54 lines
Regards,
JerryQuoted 43 lines
Thanks,
Christian.Quoted 39 lines
--- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/drm/ttm/ttm_bo_driver.h +28
-0@@ -491,6 +491,34 @@ struct ttm_bo_device { };/** +* struct ttm_lru_bulk_move_pos +* +* @first: first BO in the bulk move range +* @last: last BO in the bulk move range +* +* Positions for a lru bulk move. +*/ +struct ttm_lru_bulk_move_pos { +struct ttm_buffer_object *first; +struct ttm_buffer_object *last; +}; + +/** +* struct ttm_lru_bulk_move +* +* @tt: first/last lru entry for BOs in the TT domain +* @vram: first/last lru entry for BOs in the VRAM domain +* @swap: first/last lru entry for BOs on the swap list +* +* Helper structure for bulk moves on the LRU list. +*/ +struct ttm_lru_bulk_move { +struct ttm_lru_bulk_move_pos tt[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos vram[TTM_MAX_BO_PRIORITY ]; +struct ttm_lru_bulk_move_pos swap[TTM_MAX_BO_PRIORITY ]; +}; + +/** Quoted 8 lines
include/drm/ttm/ttm_bo_driver.h struct ttm_bo_device { · line 524
Quoted 3 lines
include/drm/ttm/ttm_bo_driver.h +0
-0* ttm_flag_masked * * @old: Pointer to the result and original value. _______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 2/5 drm/ttm: revise ttm_bo_move_to_lru_tail to support bulk moves
In reply to a message not in the archiveFrom: Christian König <[email protected]>
When move a BO to the end of LRU, it need remember the BO positions. Make sure all moved bo in between "first" and "last". And they will be bulk moving together.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 ++++---- drivers/gpu/drm/ttm/ttm_bo.c | 26 +++++++++++++++++++++++++- include/drm/ttm/ttm_bo_api.h | 6 +++++- 3 files changed, 34 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -4
@@ -297,9 +297,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,break ;spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo); +ttm_bo_move_to_lru_tail (&bo->tbo,NULL );if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo); +ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL );spin_unlock (&glob->lru_lock); }
@@ -319,9 +319,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,if (!bo->parent)continue ; -ttm_bo_move_to_lru_tail (&bo->tbo); +ttm_bo_move_to_lru_tail (&bo->tbo,NULL );if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo); +ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); }spin_unlock (&glob->lru_lock);
drivers/gpu/drm/ttm/ttm_bo.c +25 -1
@@ -214,12 +214,36 @@ void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo) }EXPORT_SYMBOL (ttm_bo_del_sub_from_lru); -void ttm_bo_move_to_lru_tail (struct ttm_buffer_object *bo) +static void ttm_bo_bulk_move_set_pos (struct ttm_lru_bulk_move_pos *pos, +struct ttm_buffer_object *bo) +{ +if (!pos->first) + pos->first = bo; + pos->last = bo; +} + +void ttm_bo_move_to_lru_tail (struct ttm_buffer_object *bo, +struct ttm_lru_bulk_move *bulk) {reservation_object_assert_held (bo->resv);ttm_bo_del_from_lru (bo);ttm_bo_add_to_lru (bo); + +if (bulk && !(bo->mem.placement &TTM_PL_FLAG_NO_EVICT )) { +switch (bo->mem.mem_type) { +case TTM_PL_TT : +ttm_bo_bulk_move_set_pos (&bulk->tt[bo->priority], bo); +break ; + +case TTM_PL_VRAM : +ttm_bo_bulk_move_set_pos (&bulk->vram[bo->priority], bo); +break ; + } +if (bo->ttm && !(bo->ttm->page_flags & + (TTM_PAGE_FLAG_SG |TTM_PAGE_FLAG_SWAPPED ))) +ttm_bo_bulk_move_set_pos (&bulk->swap[bo->priority], bo); + } }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail);
include/drm/ttm/ttm_bo_api.h +5 -1
@@ -51,6 +51,8 @@ struct ttm_placement;struct ttm_place ; +struct ttm_lru_bulk_move ; +/** * struct ttm_bus_placement *
@@ -405,12 +407,14 @@ void ttm_bo_del_from_lru(struct ttm_buffer_object *bo);* ttm_bo_move_to_lru_tail * * @bo: The buffer object. +* @bulk: optional bulk move structure to remember BO positions * * Move this BO to the tail of all lru lists used to lookup and reserve an * object. This function must be called with struct ttm_bo_global::lru_lock * held, and is used to make a BO less likely to be considered for eviction. */ -void ttm_bo_move_to_lru_tail (struct ttm_buffer_object *bo); +void ttm_bo_move_to_lru_tail (struct ttm_buffer_object *bo, +struct ttm_lru_bulk_move *bulk);/** * ttm_bo_lock_delayed_workqueue
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 4/5 drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
In reply to a message not in the archiveI continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.
Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit 0bbf32026cf5ba41e9922b30e26e1bed1ecd38ae
However, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever amdgpu_vm_validate_pt_bos() is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.
While doing so we note the beginning and end of this block in the LRU list.
Now when amdgpu_vm_validate_pt_bos() is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.
Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+
After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and use list_for_each_entry instead of the one with save entry.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +57 -16
@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob; + +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved); +spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer
@@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {
@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);
@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } -spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move); +spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4 -0
@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h"
@@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };struct amdgpu_vm_manager {
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Quoted 99 lines · Huang Rui
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +33
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together.
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10
-0+*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob; + +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);
Moved list is working under vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history about moved_lock)
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } -spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);
To confirm
we only do actual bulk move when no evicted or validate failure?
Regards,
Jerry
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +3
-0@@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };struct amdgpu_vm_manager {
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Quoted 106 lines · Jerry
Quoted 105 lines · Huang Rui
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +39
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob; +
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4
-0+spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);Moved list is working under
vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history aboutmoved_lock)
We actually don't remove them from moved list, just move bo->lru to the end of lru. So here, it doesn't need moved_lock.
Quoted 36 lines
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } }
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3-spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);To confirm
we only do actual bulk move when no evicted or validate failure?
Yes. Because if some BOs are evicted back, they will be moved to moved/relocated list. Then we need update the positions of bulk moving.
Thanks,
Ray
Quoted 41 lines
Regards,
JerryQuoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0struct amdgpu_vm_manager {
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Am 14.08.2018 um 05:05 schrieb Huang Rui:
Quoted 161 lines · Jerry
Quoted 105 lines · Huang Rui
Quoted 104 lines
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +38
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+ +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);Moved list is working under
vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history aboutmoved_lock)We actually don't remove them from moved list, just move
bo->lruto the end of lru. So here, it doesn't needmoved_lock.Quoted 35 lines
Quoted 35 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } }Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3-spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);To confirm
we only do actual bulk move when no evicted or validate failure?
Quoted 2 lines
Yes. Because if some BOs are evicted back, they will be moved to moved/relocated list. Then we need update the positions of bulk moving.
Ah, crap that won't work. Jerry pointed out a quite important bug here.
The moved list contains both per-VM as well as independent BOs, so walking it and moving everything on the LRU won't work as expected.
Probably better to just walk the idle list after we are done with the state machine.
Christian.
Quoted 45 lines
Thanks,
RayQuoted 41 lines
Regards,
JerryQuoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0struct amdgpu_vm_manager {
_______________________________________________
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): 4f7e6d61-0b4a-5c12-38a9-ea905b9f6234-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Quoted 162 lines · Christian
Am 14.08.2018 um 05:05 schrieb Huang Rui:
Quoted 161 lines · Jerry
Quoted 105 lines · Huang Rui
Quoted 104 lines
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +38
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+ +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);Moved list is working under
vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history aboutmoved_lock)We actually don't remove them from moved list, just move
bo->lruto the end of lru. So here, it doesn't needmoved_lock.Quoted 44 lines
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } -spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);To confirm
we only do actual bulk move when no evicted or validate failure?
Quoted 8 lines
Quoted 2 lines
Yes. Because if some BOs are evicted back, they will be moved to moved/relocated list. Then we need update the positions of bulk moving.
Ah, crap that won't work. Jerry pointed out a quite important bug here.
The moved list contains both per-VM as well as independent BOs, so walking it and moving everything on the LRU won't work as expected.
Our purpose is not to move the independent BOs (shared with other VM), right?
Quoted 3 lines
Probably better to just walk the idle list after we are done with the state machine.
If we only walk the idle list here, we probably are not included all the Per-VM BOs, right? Or walk the idle list after command submission.
Thanks,
Ray
Quoted 47 lines
Christian.
Quoted 45 lines
Thanks,
RayQuoted 41 lines
Regards,
JerryQuoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0struct amdgpu_vm_manager {
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Am 14.08.2018 um 09:24 schrieb Huang Rui:
Quoted 170 lines · Christian
Quoted 162 lines
Am 14.08.2018 um 05:05 schrieb Huang Rui:
Quoted 161 lines · Jerry
Quoted 105 lines · Huang Rui
Quoted 104 lines
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +38
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+ +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);Moved list is working under
vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history aboutmoved_lock)We actually don't remove them from moved list, just move
bo->lruto the end of lru. So here, it doesn't needmoved_lock.Quoted 44 lines
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } -spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);To confirm
we only do actual bulk move when no evicted or validate failure?Quoted 7 lines
Quoted 2 lines
Yes. Because if some BOs are evicted back, they will be moved to moved/relocated list. Then we need update the positions of bulk moving.
Ah, crap that won't work. Jerry pointed out a quite important bug here.
The moved list contains both per-VM as well as independent BOs, so walking it and moving everything on the LRU won't work as expected.
Quoted 8 lines
Our purpose is not to move the independent BOs (shared with other VM), right?
Quoted 3 lines
Probably better to just walk the idle list after we are done with the state machine.
If we only walk the idle list here, we probably are not included all the Per-VM BOs, right? Or walk the idle list after command submission.
Walking the idle list after command submission. At this point all BOs should be on there, except for the evicted ones and we can handle those separately.
Regards,
Christian.
Quoted 50 lines
Thanks,
RayQuoted 46 lines
Christian.
Quoted 44 lines
Thanks,
RayQuoted 41 lines
Regards,
JerryQuoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0struct amdgpu_vm_manager {_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
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): e1635b5e-e5a1-c4cf-005c-1920c6fc86e0-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH v3 4/5] drm/amdgpu: use bulk moves for efficient VM LRU handling (v3)
Quoted 177 lines · Christian König
Am 14.08.2018 um 09:24 schrieb Huang Rui:
Quoted 176 lines · Christian
Quoted 162 lines
Am 14.08.2018 um 05:05 schrieb Huang Rui:
Quoted 161 lines · Jerry
Quoted 105 lines · Huang Rui
Quoted 104 lines
I continue to work for bulk moving that based on the proposal by Christian.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
v2: move all BOs include idle, relocated, and moved list to the end of LRU and put them together.
v3: remove unused parameter and uselist_for_each_entryinstead of the one with save entry.Signed-off-by Christian König <[email protected]>Signed-off-by Huang Rui <[email protected]>Tested-by Mike Lothian <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 73 ++++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ 2 files changed, 61 insertions(+), 16 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +38
-0@@ -268,6 +268,53 @@ void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, }/** +* amdgpu_vm_move_to_lru_tail - move one list of BOs to end of LRU +* +* @vm: vm providing the BOs +* @list: the list that stored BOs +* +* Move one list of BOs to the end of LRU and update the positions. +*/ +static void +amdgpu_vm_move_to_lru_tail_by_list (struct amdgpu_vm *vm,struct list_head *list) +{ +struct amdgpu_vm_bo_base *bo_base; + +list_for_each_entry (bo_base, list, vm_status) { +struct amdgpu_bo *bo = bo_base->bo; + +if (!bo->parent) +continue ; + +ttm_bo_move_to_lru_tail (&bo->tbo, &vm->lru_bulk_move); +if (bo->shadow) +ttm_bo_move_to_lru_tail (&bo->shadow->tbo, + &vm->lru_bulk_move); + } +} + +/** +* amdgpu_vm_move_to_lru_tail - move all BOs to the end of LRU +* +* @adev: amdgpu device pointer +* @vm: vm providing the BOs +* +* Move all BOs to the end of LRU and remember their positions to put them +* together. +*/ +static void +amdgpu_vm_move_to_lru_tail (struct amdgpu_device *adev,struct amdgpu_vm *vm) +{ +struct ttm_bo_global *glob = adev->mman.bdev.glob;Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm, · line 313
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-0+ +spin_lock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->idle); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->relocated); +amdgpu_vm_move_to_lru_tail_by_list (vm, &vm->moved);Moved list is working under
vm->moved_lock, so we may hold that as well. otherwise, to use the same one.
(not sure the detail of history aboutmoved_lock)We actually don't remove them from moved list, just move
bo->lruto the end of lru. So here, it doesn't needmoved_lock.Quoted 44 lines
Quoted 32 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +6
-6+spin_unlock (&glob->lru_lock); +} + +/** * amdgpu_vm_validate_pt_bos - validate the page table BOs * * @adev: amdgpu device pointer @@ -286,6 +333,7 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, {struct ttm_bo_global *glob = adev->mman.bdev.glob;struct amdgpu_vm_bo_base *bo_base, *tmp; +bool validated = false;int r =0 ;list_for_each_entry_safe (bo_base, tmp, &vm->evicted, vm_status) {@@ -295,14 +343,9 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, r =validate (param, bo);if (r)break ; - -spin_lock (&glob->lru_lock); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); -spin_unlock (&glob->lru_lock); } + validated = true;if (bo->tbo.type != ttm_bo_type_kernel) {spin_lock (&vm->moved_lock);list_move (&bo_base->vm_status, &vm->moved);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, · line 360
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-3@@ -312,18 +355,16 @@ int amdgpu_vm_validate_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm, } } -spin_lock (&glob->lru_lock); -list_for_each_entry (bo_base, &vm->idle, vm_status) { -struct amdgpu_bo *bo = bo_base->bo; +if (!validated) { +spin_lock (&glob->lru_lock); +ttm_bo_bulk_move_lru_tail (&vm->lru_bulk_move);To confirm
we only do actual bulk move when no evicted or validate failure?Quoted 7 lines
Quoted 2 lines
Yes. Because if some BOs are evicted back, they will be moved to moved/relocated list. Then we need update the positions of bulk moving.
Ah, crap that won't work. Jerry pointed out a quite important bug here.
The moved list contains both per-VM as well as independent BOs, so walking it and moving everything on the LRU won't work as expected.
Our purpose is not to move the independent BOs (shared with other VM), right?
Quoted 3 lines
Probably better to just walk the idle list after we are done with the state machine.
Quoted 7 lines
Quoted 2 lines
If we only walk the idle list here, we probably are not included all the Per-VM BOs, right? Or walk the idle list after command submission.
Walking the idle list after command submission. At this point all BOs should be on there, except for the evicted ones and we can handle those separately.
Thanks. BTW, could you please elaborate more about the state machine? I also see it mentioned on the comments of idle list.
/* All BOs of this VM not currently in the state machine */
struct list_head idle;
Thanks,
Ray
Quoted 60 lines
Regards,
Christian.Quoted 50 lines
Thanks,
RayQuoted 46 lines
Christian.
Quoted 44 lines
Thanks,
RayQuoted 41 lines
Regards,
JerryQuoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-7+spin_unlock (&glob->lru_lock); +return 0 ; + } -if (!bo->parent) -continue ; +memset (&vm->lru_bulk_move,0 ,sizeof (vm->lru_bulk_move)); -ttm_bo_move_to_lru_tail (&bo->tbo,NULL ); -if (bo->shadow) -ttm_bo_move_to_lru_tail (&bo->shadow->tbo,NULL ); - } -spin_unlock (&glob->lru_lock); +amdgpu_vm_move_to_lru_tail (adev, vm);return r; }drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +4
-0@@ -29,6 +29,7 @@#include <linux/rbtree.h> #include <drm/gpu_scheduler.h> #include <drm/drm_file.h> +#include <drm/ttm/ttm_bo_driver.h> #include "amdgpu_sync.h" #include "amdgpu_ring.h" @@ -226,6 +227,9 @@ struct amdgpu_vm {/* Some basic info about the task */ struct amdgpu_task_info task_info; + +/* Store positions of group of BOs */ +struct ttm_lru_bulk_move lru_bulk_move; };Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm { · line 235
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0
-0struct amdgpu_vm_manager {_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 5/5 drm/amdgpu: move PD/PT bos on LRU again
In reply to a message not in the archiveThe new bulk moving functionality is ready, the overhead of moving PD/PT bos to LRU is fixed. So move them on LRU again.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1125,7 +1125,7 @@ int amdgpu_vm_update_directories(struct amdgpu_device *adev, struct amdgpu_vm_bo_base, vm_status); bo_base->moved = false; -list_del_init (&bo_base->vm_status); +list_move (&bo_base->vm_status, &vm->idle); bo = bo_base->bo->parent;if (!bo)
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v3 3/5 drm/ttm: add bulk move function on LRU
In reply to Huang RuiThis function allow us to bulk move a group of BOs to the tail of their LRU. The positions of group of BOs are stored on the (first, last) bulk_move_pos structure.
--- drivers/gpu/drm/ttm/ttm_bo.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_bo_api.h | 10 +++++++++ 2 files changed, 62 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +52 -0
@@ -247,6 +247,58 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); +static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, +struct list_head *lru,bool is_swap) +{ +struct list_head entries, before; +struct list_head *list1, *list2; + + list1 = is_swap ? &pos->last->swap : &pos->last->lru; + list2 = is_swap ? pos->first->swap.prev : pos->first->lru.prev; + +list_cut_position (&entries, lru, list1); +list_cut_position (&before, &entries, list2); +list_splice (&before, lru); +list_splice_tail (&entries, lru); +} + +void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk) +{ +unsigned i; + +for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_mem_type_manager *man; + +if (!bulk->tt[i].first) +continue ; + + man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; +ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); + } + +for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_mem_type_manager *man; + +if (!bulk->vram[i].first) +continue ; + + man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; +ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); + } + +for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->swap[i]; +struct list_head *lru; + +if (!pos->first) +continue ; + + lru = &pos->first->bdev->glob->swap_lru[i]; +ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); + } +} +EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail); +static int ttm_bo_handle_move_mem (struct ttm_buffer_object *bo,struct ttm_mem_reg *mem,bool evict,struct ttm_operation_ctx *ctx)
include/drm/ttm/ttm_bo_api.h +10 -0
@@ -417,6 +417,16 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, struct ttm_lru_bulk_move *bulk);/** +* ttm_bo_bulk_move_lru_tail +* +* @bulk: bulk move structure +* +* Bulk move BOs to the LRU tail, only valid to use when driver makes sure that +* BO order never changes. Should be called with ttm_bo_global::lru_lock held. +*/ +void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk); + +/** * ttm_bo_lock_delayed_workqueue * * Prevent the delayed workqueue from running.
Signature · 6 lines
2.7.4 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
For the series
on RX580,
amd-staging-drm-next
#5024f8dfe478
Dieter
Am 13.08.2018 11:58, schrieb Huang Rui:
Quoted 77 lines
The idea and proposal is originally from Christian, and I continue to work to deliver it.
Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of them on the end of LRU list one by one. Thus, that cause so many BOs moved to the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU instead of one by one.
Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be validated we move all BOs together to the end of the LRU without dropping the lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do, we don't move every BO one by one, but instead cut the LRU list into pieces so that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can see the visible improvement than original, and even better than original with workaround.
Changes from V1 -> V2:
- Fix to missed the BOs in relocated/moved that should be also moved to the end
of LRU.Changes from V2 -> V3:
- Remove unused parameter and uselist_for_each_entryinstead of the one with
save entry.Thanks,
RuiChristian König (2):
drm/ttm: add helper structures for bulk moves on lru list drm/ttm: revisettm_bo_move_to_lru_tailto support bulk movesHuang Rui (3):
drm/ttm: add bulk move function on LRU
drm/amdgpu: use bulk moves for efficient VM LRU handling (v3) drm/amdgpu: move PD/PT bos on LRU again
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 ++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ drivers/gpu/drm/ttm/ttm_bo.c | 78 +++++++++++++++++++++++++++++++++- include/drm/ttm/ttm_bo_api.h | 16 ++++++- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++ 5 files changed, 182 insertions(+), 19 deletions(-)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): 70f3ba4a773f5ee3d1c46bc63991702a-0hun7QTegEsDD4udEopG9Q@public.gmane.org
Quoted 8 lines · Dieter Nützel
For the series
Tested-by Dieter Nützel <[email protected]>on RX580,
amd-staging-drm-next
#5024f8dfe478
Thank you so much, will add tested-by in next version.
Thanks,
Ray
Quoted 100 lines
Dieter
Am 13.08.2018 11:58, schrieb Huang Rui:
Quoted 97 lines
The idea and proposal is originally from Christian, and I continue to work to
deliver it.Background:
amdgpu driver will move all PD/PT and PerVM BOs into idle list. Then move all of
them on the end of LRU list one by one. Thus, that cause so many BOs moved to
the end of the LRU, and impact performance seriously.Then Christian provided a workaround to not move PD/PT BOs on LRU with below
patch:
"drm/amdgpu: band aid validating VM PTs"
Commit0bbf32026cf5ba41e9922b30e26e1bed1ecd38aeHowever, the final solution should bulk move all PD/PT and PerVM BOs on the LRU
instead of one by one.Whenever
amdgpu_vm_validate_pt_bos()is called and we have BOs which need to be
validated we move all BOs together to the end of the LRU without dropping the
lock for the LRU.While doing so we note the beginning and end of this block in the LRU list.
Now when
amdgpu_vm_validate_pt_bos()is called and we don't have anything to do,
we don't move every BO one by one, but instead cut the LRU list into pieces so
that we bulk move everything to the end in just one operation.Test data:
+--------------+-----------------+-----------+---------------------------------------+ | |The Talos |Clpeak(OCL)|BusSpeedReadback(OCL) | | |Principle(Vulkan)| | | +------------------------------------------------------------------------------------+ | | | |0.319 ms(1k) 0.314 ms(2K) 0.308 ms(4K) | | Original | 147.7 FPS | 76.86 us |0.307 ms(8K) 0.310 ms(16K) | +------------------------------------------------------------------------------------+ | Orignial + WA| | |0.254 ms(1K) 0.241 ms(2K) | |(don't move | 162.1 FPS | 42.15 us |0.230 ms(4K) 0.223 ms(8K) 0.204 ms(16K)| |PT BOs on LRU)| | | | +------------------------------------------------------------------------------------+ | Bulk move | 163.1 FPS | 40.52 us |0.244 ms(1K) 0.252 ms(2K) 0.213 ms(4K) | | | | |0.214 ms(8K) 0.225 ms(16K) | +--------------+-----------------+-----------+---------------------------------------+After test them with above three benchmarks include vulkan and opencl. We can
see the visible improvement than original, and even better than original with
workaround.Changes from V1 -> V2:
- Fix to missed the BOs in relocated/moved that should be also moved to the end
of LRU.Changes from V2 -> V3:
- Remove unused parameter and uselist_for_each_entryinstead of the one with
save entry.Thanks,
RuiChristian König (2):
drm/ttm: add helper structures for bulk moves on lru list drm/ttm: revisettm_bo_move_to_lru_tailto support bulk movesHuang Rui (3):
drm/ttm: add bulk move function on LRU
drm/amdgpu: use bulk moves for efficient VM LRU handling (v3) drm/amdgpu: move PD/PT bos on LRU againdrivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 75 ++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 ++ drivers/gpu/drm/ttm/ttm_bo.c | 78 +++++++++++++++++++++++++++++++++- include/drm/ttm/ttm_bo_api.h | 16 ++++++- include/drm/ttm/ttm_bo_driver.h | 28 ++++++++++++ 5 files changed, 182 insertions(+), 19 deletions(-)
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx