drm/amdgpu: handle all fragment sizes v4
Subsystems (2)
PATCH 1/1 drm/amdgpu: handle all fragment sizes v4
From: Roger He <[email protected]>
This can improve performance for some cases.
v2 (chk): handle all sizes, simplify the patch quite a bit v3 (chk): adjust dw estimation as well
v4 (chk): use single loop, make end mask 64bit
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26 -29
@@ -1415,8 +1415,6 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params, uint64_t start, uint64_t end, uint64_t dst, uint64_t flags) { - int r; -/** * The MC L1 TLB supports variable sized pages, based on a fragment * field in the PTE. When this field is set to a non-zero value, page
@@ -1435,39 +1433,38 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params,* Userspace can support this by aligning virtual base address and * allocation size to the fragment size. */ -unsigned pages_per_frag = params->adev->vm_manager.fragment_size; -uint64_t frag_flags =AMDGPU_PTE_FRAG (pages_per_frag); -uint64_t frag_align =1 << pages_per_frag; - -uint64_t frag_start =ALIGN (start, frag_align); -uint64_t frag_end = end & ~(frag_align -1 ); +unsigned max_frag = params->adev->vm_manager.fragment_size; +int r;/* system pages are non continuously */ -if (params->src || !(flags &AMDGPU_PTE_VALID ) || - (frag_start >= frag_end)) +if (params->src || !(flags &AMDGPU_PTE_VALID ))return amdgpu_vm_update_ptes (params, start, end, dst, flags); -/* handle the 4K area at the beginning */ -if (start != frag_start) { - r =amdgpu_vm_update_ptes (params, start, frag_start, - dst, flags); +while (start != end) { +uint64_t frag_flags, frag_end; +unsigned frag; + +/* This intentionally wraps around if no bit is set */ + frag =min ((unsigned )ffs (start) -1 , + (unsigned )fls64 (end - start) -1 ); +if (frag >= max_frag) { + frag_flags =AMDGPU_PTE_FRAG (max_frag); + frag_end = end & ~((1ULL << max_frag) -1 ); + }else { + frag_flags =AMDGPU_PTE_FRAG (frag); + frag_end = start + (1 << frag); + } + + r =amdgpu_vm_update_ptes (params, start, frag_end, dst, + flags | frag_flags);if (r)return r; - dst += (frag_start - start) *AMDGPU_GPU_PAGE_SIZE ; - } - -/* handle the area in the middle */ - r =amdgpu_vm_update_ptes (params, frag_start, frag_end, dst, - flags | frag_flags); -if (r) -return r; -/* handle the 4K area at the end */ -if (frag_end != end) { - dst += (frag_end - frag_start) *AMDGPU_GPU_PAGE_SIZE ; - r =amdgpu_vm_update_ptes (params, frag_end, end, dst, flags); + dst += (frag_end - start) *AMDGPU_GPU_PAGE_SIZE ; + start = frag_end; } -return r; + +return 0 ; }/**
@@ -1557,8 +1554,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* set page commands needed */ ndw += ncmds *10 ; -/* two extra commands for begin/end of fragment */ - ndw +=2 *10 ; +/* extra commands for begin/end fragments */ + ndw +=2 *10 * adev->vm_manager.fragment_size; params.func = amdgpu_vm_do_set_ptes; }
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): 1504172670-2375-1-git-send-email-deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org
Quoted 10 lines · Christian König
From: Roger He <[email protected]>
This can improve performance for some cases.
v2 (chk): handle all sizes, simplify the patch quite a bit v3 (chk): adjust dw estimation as well
v4 (chk): use single loop, make end mask 64bitSigned-off-by Roger He <[email protected]>Signed-off-by Christian König <[email protected]>
Patch looks very good to me, Reviewed-by: Chunming Zhou <[email protected]>
btw, it's best if Roger can give a test with v4.
Regards,
David Zhou
Quoted 82 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24
-27@@ -1415,8 +1415,6 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params, uint64_t start, uint64_t end, uint64_t dst, uint64_t flags) { - int r; -/** * The MC L1 TLB supports variable sized pages, based on a fragment * field in the PTE. When this field is set to a non-zero value, page @@ -1435,39 +1433,38 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params,* Userspace can support this by aligning virtual base address and * allocation size to the fragment size. */ -unsigned pages_per_frag = params->adev->vm_manager.fragment_size; -uint64_t frag_flags =AMDGPU_PTE_FRAG (pages_per_frag); -uint64_t frag_align =1 << pages_per_frag; - -uint64_t frag_start =ALIGN (start, frag_align); -uint64_t frag_end = end & ~(frag_align -1 ); +unsigned max_frag = params->adev->vm_manager.fragment_size; +int r;/* system pages are non continuously */ -if (params->src || !(flags &AMDGPU_PTE_VALID ) || - (frag_start >= frag_end)) +if (params->src || !(flags &AMDGPU_PTE_VALID ))return amdgpu_vm_update_ptes (params, start, end, dst, flags); -/* handle the 4K area at the beginning */ -if (start != frag_start) { - r =amdgpu_vm_update_ptes (params, start, frag_start, - dst, flags); +while (start != end) { +uint64_t frag_flags, frag_end; +unsigned frag; + +/* This intentionally wraps around if no bit is set */ + frag =min ((unsigned )ffs (start) -1 , + (unsigned )fls64 (end - start) -1 ); +if (frag >= max_frag) { + frag_flags =AMDGPU_PTE_FRAG (max_frag); + frag_end = end & ~((1ULL << max_frag) -1 ); + }else { + frag_flags =AMDGPU_PTE_FRAG (frag); + frag_end = start + (1 << frag); + } + + r =amdgpu_vm_update_ptes (params, start, frag_end, dst, + flags | frag_flags);if (r)return r; - dst += (frag_start - start) *AMDGPU_GPU_PAGE_SIZE ; - } - -/* handle the area in the middle */ - r =amdgpu_vm_update_ptes (params, frag_start, frag_end, dst, - flags | frag_flags); -if (r) -return r; -/* handle the 4K area at the end */ -if (frag_end != end) { - dst += (frag_end - frag_start) *AMDGPU_GPU_PAGE_SIZE ; - r =amdgpu_vm_update_ptes (params, frag_end, end, dst, flags); + dst += (frag_end - start) *AMDGPU_GPU_PAGE_SIZE ; + start = frag_end; } -return r; + +return 0 ; }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, · line 1561
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -1557,8 +1554,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* set page commands needed */ ndw += ncmds *10 ; -/* two extra commands for begin/end of fragment */ - ndw +=2 *10 ; +/* extra commands for begin/end fragments */ + ndw +=2 *10 * adev->vm_manager.fragment_size; params.func = amdgpu_vm_do_set_ptes; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Felix Kuehling
Reviewed-byThis looks very elegant now. :)
Quoted 92 lines · Christian König
From: Roger He <[email protected]>
This can improve performance for some cases.
v2 (chk): handle all sizes, simplify the patch quite a bit v3 (chk): adjust dw estimation as well
v4 (chk): use single loop, make end mask 64bitSigned-off-by Roger He <[email protected]>Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +24
-27@@ -1415,8 +1415,6 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params, uint64_t start, uint64_t end, uint64_t dst, uint64_t flags) { - int r; -/** * The MC L1 TLB supports variable sized pages, based on a fragment * field in the PTE. When this field is set to a non-zero value, page @@ -1435,39 +1433,38 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params,* Userspace can support this by aligning virtual base address and * allocation size to the fragment size. */ -unsigned pages_per_frag = params->adev->vm_manager.fragment_size; -uint64_t frag_flags =AMDGPU_PTE_FRAG (pages_per_frag); -uint64_t frag_align =1 << pages_per_frag; - -uint64_t frag_start =ALIGN (start, frag_align); -uint64_t frag_end = end & ~(frag_align -1 ); +unsigned max_frag = params->adev->vm_manager.fragment_size; +int r;/* system pages are non continuously */ -if (params->src || !(flags &AMDGPU_PTE_VALID ) || - (frag_start >= frag_end)) +if (params->src || !(flags &AMDGPU_PTE_VALID ))return amdgpu_vm_update_ptes (params, start, end, dst, flags); -/* handle the 4K area at the beginning */ -if (start != frag_start) { - r =amdgpu_vm_update_ptes (params, start, frag_start, - dst, flags); +while (start != end) { +uint64_t frag_flags, frag_end; +unsigned frag; + +/* This intentionally wraps around if no bit is set */ + frag =min ((unsigned )ffs (start) -1 , + (unsigned )fls64 (end - start) -1 ); +if (frag >= max_frag) { + frag_flags =AMDGPU_PTE_FRAG (max_frag); + frag_end = end & ~((1ULL << max_frag) -1 ); + }else { + frag_flags =AMDGPU_PTE_FRAG (frag); + frag_end = start + (1 << frag); + } + + r =amdgpu_vm_update_ptes (params, start, frag_end, dst, + flags | frag_flags);if (r)return r; - dst += (frag_start - start) *AMDGPU_GPU_PAGE_SIZE ; - } - -/* handle the area in the middle */ - r =amdgpu_vm_update_ptes (params, frag_start, frag_end, dst, - flags | frag_flags); -if (r) -return r; -/* handle the 4K area at the end */ -if (frag_end != end) { - dst += (frag_end - frag_start) *AMDGPU_GPU_PAGE_SIZE ; - r =amdgpu_vm_update_ptes (params, frag_end, end, dst, flags); + dst += (frag_end - start) *AMDGPU_GPU_PAGE_SIZE ; + start = frag_end; } -return r; + +return 0 ; }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, · line 1561
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2
-2@@ -1557,8 +1554,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* set page commands needed */ ndw += ncmds *10 ; -/* two extra commands for begin/end of fragment */ - ndw +=2 *10 ; +/* extra commands for begin/end fragments */ + ndw +=2 *10 * adev->vm_manager.fragment_size; params.func = amdgpu_vm_do_set_ptes; }
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
He, Roger
Tested-by Roger HeIt works very well!
Thanks
Roger(Hongbo.He)
-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Christian K?nig
Sent: Thursday, August 31, 2017 5:45 PM
To: [email protected]
Subject: [PATCH] drm/amdgpu: handle all fragment sizes v4
From: Roger He <[email protected]>
This can improve performance for some cases.
v2 (chk): handle all sizes, simplify the patch quite a bit v3 (chk): adjust dw estimation as well
v4 (chk): use single loop, make end mask 64bit
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +26 -29
@@ -1415,8 +1415,6 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params, uint64_t start, uint64_t end, uint64_t dst, uint64_t flags) { - int r; -/** * The MC L1 TLB supports variable sized pages, based on a fragment * field in the PTE. When this field is set to a non-zero value, page
@@ -1435,39 +1433,38 @@ static int amdgpu_vm_frag_ptes(struct amdgpu_pte_update_params *params,* Userspace can support this by aligning virtual base address and * allocation size to the fragment size. */ -unsigned pages_per_frag = params->adev->vm_manager.fragment_size; -uint64_t frag_flags =AMDGPU_PTE_FRAG (pages_per_frag); -uint64_t frag_align =1 << pages_per_frag; - -uint64_t frag_start =ALIGN (start, frag_align); -uint64_t frag_end = end & ~(frag_align -1 ); +unsigned max_frag = params->adev->vm_manager.fragment_size; +int r;/* system pages are non continuously */ -if (params->src || !(flags &AMDGPU_PTE_VALID ) || - (frag_start >= frag_end)) +if (params->src || !(flags &AMDGPU_PTE_VALID ))return amdgpu_vm_update_ptes (params, start, end, dst, flags); -/* handle the 4K area at the beginning */ -if (start != frag_start) { - r =amdgpu_vm_update_ptes (params, start, frag_start, - dst, flags); +while (start != end) { +uint64_t frag_flags, frag_end; +unsigned frag; + +/* This intentionally wraps around if no bit is set */ + frag =min ((unsigned )ffs (start) -1 , + (unsigned )fls64 (end - start) -1 ); +if (frag >= max_frag) { + frag_flags =AMDGPU_PTE_FRAG (max_frag); + frag_end = end & ~((1ULL << max_frag) -1 ); + }else { + frag_flags =AMDGPU_PTE_FRAG (frag); + frag_end = start + (1 << frag); + } + + r =amdgpu_vm_update_ptes (params, start, frag_end, dst, + flags | frag_flags);if (r)return r; - dst += (frag_start - start) *AMDGPU_GPU_PAGE_SIZE ; - } - -/* handle the area in the middle */ - r =amdgpu_vm_update_ptes (params, frag_start, frag_end, dst, - flags | frag_flags); -if (r) -return r; -/* handle the 4K area at the end */ -if (frag_end != end) { - dst += (frag_end - frag_start) *AMDGPU_GPU_PAGE_SIZE ; - r =amdgpu_vm_update_ptes (params, frag_end, end, dst, flags); + dst += (frag_end - start) *AMDGPU_GPU_PAGE_SIZE ; + start = frag_end; } -return r; + +return 0 ; }/**
@@ -1557,8 +1554,8 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,/* set page commands needed */ ndw += ncmds *10 ; -/* two extra commands for begin/end of fragment */ - ndw +=2 *10 ; +/* extra commands for begin/end fragments */ + ndw +=2 *10 * adev->vm_manager.fragment_size; params.func = amdgpu_vm_do_set_ptes; }
Signature · 10 lines
2.7.4 _______________________________________________ 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