drm/amdgpu: use kernel BO API for benchmark buffer management
authorAlex Deucher <alexander.deucher@amd.com>
Mon, 21 Feb 2022 21:01:03 +0000 (16:01 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 23 Feb 2022 19:02:51 +0000 (14:02 -0500)
Simplifies the code quite a bit.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c

index 9973b6266a3d8ab01f0ecd60f9f48cb29aa88c3b..0701b7dbf5f9032fa255f4c97c78a459779239b9 100644 (file)
@@ -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 @@ out_cleanup:
        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;
 }