drm/amdgpu: use kernel BO API for benchmark buffer management
Subsystems (2)
Alex Deucher
maintainerPATCH 1/2 drm/amdgpu: use kernel BO API for benchmark buffer management
Simplifies the code quite a bit.
Signed-off-by Alex Deucher <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 78 ++++--------------- 1 file changed, 17 insertions(+), 61 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +17 -61
@@ -75,57 +75,25 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, {struct amdgpu_bo *dobj =NULL ;struct amdgpu_bo *sobj =NULL ; -struct amdgpu_bo_param bp;uint64_t saddr, daddr;int r, n; -memset (&bp,0 ,sizeof (bp)); - bp.size = size; - bp.byte_align =PAGE_SIZE ; - bp.domain = sdomain; - bp.flags =0 ; - bp.type = ttm_bo_type_kernel; - bp.resv =NULL ; - bp.bo_ptr_size =sizeof (struct amdgpu_bo ); - n =AMDGPU_BENCHMARK_ITERATIONS ; - r =amdgpu_bo_create (adev, &bp, &sobj); -if (r) { - goto out_cleanup; - } - r =amdgpu_bo_reserve (sobj, false); -if (unlikely (r !=0 )) - goto out_cleanup; - r =amdgpu_bo_pin (sobj, sdomain); -if (r) { -amdgpu_bo_unreserve (sobj); - goto out_cleanup; - } - r =amdgpu_ttm_alloc_gart (&sobj->tbo); -amdgpu_bo_unreserve (sobj); -if (r) { - goto out_cleanup; - } - saddr =amdgpu_bo_gpu_offset (sobj); - bp.domain = ddomain; - r =amdgpu_bo_create (adev, &bp, &dobj); -if (r) { - goto out_cleanup; - } - r =amdgpu_bo_reserve (dobj, false); -if (unlikely (r !=0 )) + + r =amdgpu_bo_create_kernel (adev, size, +PAGE_SIZE , sdomain, + &sobj, + &saddr, +NULL ); +if (r) goto out_cleanup; - r =amdgpu_bo_pin (dobj, ddomain); -if (r) { -amdgpu_bo_unreserve (sobj); + r =amdgpu_bo_create_kernel (adev, size, +PAGE_SIZE , ddomain, + &dobj, + &daddr, +NULL ); +if (r) goto out_cleanup; - } - r =amdgpu_ttm_alloc_gart (&dobj->tbo); -amdgpu_bo_unreserve (dobj); -if (r) { - goto out_cleanup; - } - daddr =amdgpu_bo_gpu_offset (dobj);if (adev->mman.buffer_funcs) { r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n);
@@ -141,22 +109,10 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,if (r <0 )dev_info (adev->dev,"Error while benchmarking BO move.\n" ); -if (sobj) { - r =amdgpu_bo_reserve (sobj, true); -if (likely (r ==0 )) { -amdgpu_bo_unpin (sobj); -amdgpu_bo_unreserve (sobj); - } -amdgpu_bo_unref (&sobj); - } -if (dobj) { - r =amdgpu_bo_reserve (dobj, true); -if (likely (r ==0 )) { -amdgpu_bo_unpin (dobj); -amdgpu_bo_unreserve (dobj); - } -amdgpu_bo_unref (&dobj); - } +if (sobj) +amdgpu_bo_free_kernel (&sobj, &saddr,NULL ); +if (dobj) +amdgpu_bo_free_kernel (&dobj, &daddr,NULL );return r; }
Signature · 1 line
2.35.1
Alex Deucher
maintainerPATCH 2/2 drm/amdgpu: use ktime rather than jiffies for benchmark results
To protect against wraparounds.
Signed-off-by Alex Deucher <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +17 -14
@@ -29,14 +29,13 @@#define AMDGPU_BENCHMARK_COMMON_MODES_N 17static int amdgpu_benchmark_do_move (struct amdgpu_device *adev,unsigned size, -uint64_t saddr,uint64_t daddr,int n) +uint64_t saddr,uint64_t daddr,int n,s64 *time_ms) { -unsigned long start_jiffies; -unsigned long end_jiffies; +ktime_t stime, etime;struct dma_fence *fence;int i, r; - start_jiffies = jiffies; + stime =ktime_get ();for (i =0 ; i < n; i++) {struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; r = amdgpu_copy_buffer(ring, saddr, daddr, size, NULL, &fence,
@@ -48,25 +47,28 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,if (r) goto exit_do_move; } - end_jiffies = jiffies; - r =jiffies_to_msecs (end_jiffies - start_jiffies); exit_do_move: + etime =ktime_get (); + *time_ms =ktime_ms_delta (etime, stime); +return r; }static void amdgpu_benchmark_log_results (struct amdgpu_device *adev,int n,unsigned size, -unsigned int time, +s64 time_ms,unsigned sdomain,unsigned ddomain,char *kind) { -unsigned int throughput = (n * (size >>10 )) / time; +s64 throughput = (n * (size >>10 )); + + throughput =div64_s64 (throughput, time_ms);dev_info (adev->dev,"amdgpu: %s %u bo moves of %u kB from" -" %d to %d in %u ms, throughput: %u Mb/s or %u MB/s\n" , - kind, n, size >>10 , sdomain, ddomain, time, +" %d to %d in %lld ms, throughput: %lld Mb/s or %lld MB/s\n" , + kind, n, size >>10 , sdomain, ddomain, time_ms, throughput *8 , throughput); }
@@ -76,6 +78,7 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,struct amdgpu_bo *dobj =NULL ;struct amdgpu_bo *sobj =NULL ;uint64_t saddr, daddr; +s64 time_ms;int r, n; n =AMDGPU_BENCHMARK_ITERATIONS ;
@@ -96,11 +99,11 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, goto out_cleanup;if (adev->mman.buffer_funcs) { - r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n); -if (r <0 ) + r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n, &time_ms); +if (r) goto out_cleanup; -if (r >0 ) -amdgpu_benchmark_log_results (adev, n, size, r, +else +amdgpu_benchmark_log_results (adev, n, size, time_ms, sdomain, ddomain,"dma" ); }
Signature · 1 line
2.35.1
Re: [PATCH 2/2] drm/amdgpu: use ktime rather than jiffies for benchmark results
Am 2022-02-21 um 17:30 schrieb Alex Deucher:
Quoted 30 lines
To protect against wraparounds.
Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +3
-4@@ -29,14 +29,13 @@#define AMDGPU_BENCHMARK_COMMON_MODES_N 17static int amdgpu_benchmark_do_move (struct amdgpu_device *adev,unsigned size, -uint64_t saddr,uint64_t daddr,int n) +uint64_t saddr,uint64_t daddr,int n,s64 *time_ms) { -unsigned long start_jiffies; -unsigned long end_jiffies; +ktime_t stime, etime;struct dma_fence *fence;int i, r; - start_jiffies = jiffies; + stime =ktime_get ();for (i =0 ; i < n; i++) {struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; r = amdgpu_copy_buffer(ring, saddr, daddr, size, NULL, &fence,
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size, · line 53
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2
-2@@ -48,25 +47,28 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,if (r) goto exit_do_move; } - end_jiffies = jiffies; - r =jiffies_to_msecs (end_jiffies - start_jiffies); exit_do_move: + etime =ktime_get (); + *time_ms =ktime_ms_delta (etime, stime);
Milliseconds are pretty coarse. Would it make sense to use microseconds (ktime_us_delta) to get more accurate measurements instead?
Regards,
Felix
Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +12
-8+return r; }static void amdgpu_benchmark_log_results (struct amdgpu_device *adev,int n,unsigned size, -unsigned int time, +s64 time_ms,unsigned sdomain,unsigned ddomain,char *kind) { -unsigned int throughput = (n * (size >>10 )) / time; +s64 throughput = (n * (size >>10 )); + + throughput =div64_s64 (throughput, time_ms);dev_info (adev->dev,"amdgpu: %s %u bo moves of %u kB from" -" %d to %d in %u ms, throughput: %u Mb/s or %u MB/s\n" , - kind, n, size >>10 , sdomain, ddomain, time, +" %d to %d in %lld ms, throughput: %lld Mb/s or %lld MB/s\n" , + kind, n, size >>10 , sdomain, ddomain, time_ms, throughput *8 , throughput); }@@ -76,6 +78,7 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,struct amdgpu_bo *dobj =NULL ;struct amdgpu_bo *sobj =NULL ;uint64_t saddr, daddr; +s64 time_ms;int r, n; n =AMDGPU_BENCHMARK_ITERATIONS ;@@ -96,11 +99,11 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, goto out_cleanup;if (adev->mman.buffer_funcs) { - r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n); -if (r <0 ) + r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n, &time_ms); +if (r) goto out_cleanup; -if (r >0 ) -amdgpu_benchmark_log_results (adev, n, size, r, +else +amdgpu_benchmark_log_results (adev, n, size, time_ms, sdomain, ddomain,"dma" ); }
Am 21.02.22 um 23:30 schrieb Alex Deucher:
Quoted 3 lines
Simplifies the code quite a bit.
Signed-off-by Alex Deucher <[email protected]>
Quoted 106 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 78 ++++--------------- 1 file changed, 17 insertions(+), 61 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +17
-61@@ -75,57 +75,25 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size, {struct amdgpu_bo *dobj =NULL ;struct amdgpu_bo *sobj =NULL ; -struct amdgpu_bo_param bp;uint64_t saddr, daddr;int r, n; -memset (&bp,0 ,sizeof (bp)); - bp.size = size; - bp.byte_align =PAGE_SIZE ; - bp.domain = sdomain; - bp.flags =0 ; - bp.type = ttm_bo_type_kernel; - bp.resv =NULL ; - bp.bo_ptr_size =sizeof (struct amdgpu_bo ); - n =AMDGPU_BENCHMARK_ITERATIONS ; - r =amdgpu_bo_create (adev, &bp, &sobj); -if (r) { - goto out_cleanup; - } - r =amdgpu_bo_reserve (sobj, false); -if (unlikely (r !=0 )) - goto out_cleanup; - r =amdgpu_bo_pin (sobj, sdomain); -if (r) { -amdgpu_bo_unreserve (sobj); - goto out_cleanup; - } - r =amdgpu_ttm_alloc_gart (&sobj->tbo); -amdgpu_bo_unreserve (sobj); -if (r) { - goto out_cleanup; - } - saddr =amdgpu_bo_gpu_offset (sobj); - bp.domain = ddomain; - r =amdgpu_bo_create (adev, &bp, &dobj); -if (r) { - goto out_cleanup; - } - r =amdgpu_bo_reserve (dobj, false); -if (unlikely (r !=0 )) + + r =amdgpu_bo_create_kernel (adev, size, +PAGE_SIZE , sdomain, + &sobj, + &saddr, +NULL ); +if (r) goto out_cleanup; - r =amdgpu_bo_pin (dobj, ddomain); -if (r) { -amdgpu_bo_unreserve (sobj); + r =amdgpu_bo_create_kernel (adev, size, +PAGE_SIZE , ddomain, + &dobj, + &daddr, +NULL ); +if (r) goto out_cleanup; - } - r =amdgpu_ttm_alloc_gart (&dobj->tbo); -amdgpu_bo_unreserve (dobj); -if (r) { - goto out_cleanup; - } - daddr =amdgpu_bo_gpu_offset (dobj);if (adev->mman.buffer_funcs) { r =amdgpu_benchmark_do_move (adev, size, saddr, daddr, n);@@ -141,22 +109,10 @@ static int amdgpu_benchmark_move(struct amdgpu_device *adev, unsigned size,if (r <0 )dev_info (adev->dev,"Error while benchmarking BO move.\n" ); -if (sobj) { - r =amdgpu_bo_reserve (sobj, true); -if (likely (r ==0 )) { -amdgpu_bo_unpin (sobj); -amdgpu_bo_unreserve (sobj); - } -amdgpu_bo_unref (&sobj); - } -if (dobj) { - r =amdgpu_bo_reserve (dobj, true); -if (likely (r ==0 )) { -amdgpu_bo_unpin (dobj); -amdgpu_bo_unreserve (dobj); - } -amdgpu_bo_unref (&dobj); - } +if (sobj) +amdgpu_bo_free_kernel (&sobj, &saddr,NULL ); +if (dobj) +amdgpu_bo_free_kernel (&dobj, &daddr,NULL );return r; }