[PATCH 4/7] drm/amdgpu: add a benchmark mutex

Alex Deucher alexander.deucher at amd.com
Fri Feb 18 22:26:00 UTC 2022


To avoid multiple runs in parallel to avoid mixing results.

Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 23 +++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c    |  1 +
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 66d556fc17ef..c736c30e0a0a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1100,6 +1100,8 @@ struct amdgpu_device {
 	struct list_head                ras_list;
 
 	struct ip_discovery_top         *ip_top;
+
+	struct mutex			benchmark_mutex;
 };
 
 static inline struct amdgpu_device *drm_to_adev(struct drm_device *ddev)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
index 62422c395789..8e4997983124 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c
@@ -183,6 +183,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 		1920 * 1200 * 4
 	};
 
+	mutex_lock(&adev->benchmark_mutex);
 	switch (test_number) {
 	case 1:
 		dev_info(adev->dev, "benchmark test: %d\n", test_number);
@@ -190,11 +191,11 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 		r = amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_GTT,
 					  AMDGPU_GEM_DOMAIN_VRAM);
 		if (r)
-			return r;
+			goto done;
 		r = amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_VRAM,
 					  AMDGPU_GEM_DOMAIN_GTT);
 		if (r)
-			return r;
+			goto done;
 		break;
 	case 2:
 		dev_info(adev->dev, "benchmark test: %d\n", test_number);
@@ -202,7 +203,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 		amdgpu_benchmark_move(adev, 1024*1024, AMDGPU_GEM_DOMAIN_VRAM,
 				      AMDGPU_GEM_DOMAIN_VRAM);
 		if (r)
-			return r;
+			goto done;
 		break;
 	case 3:
 		dev_info(adev->dev, "benchmark test: %d\n", test_number);
@@ -212,7 +213,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 						  AMDGPU_GEM_DOMAIN_GTT,
 						  AMDGPU_GEM_DOMAIN_VRAM);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 	case 4:
@@ -223,7 +224,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 						  AMDGPU_GEM_DOMAIN_VRAM,
 						  AMDGPU_GEM_DOMAIN_GTT);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 	case 5:
@@ -234,7 +235,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 						  AMDGPU_GEM_DOMAIN_VRAM,
 						  AMDGPU_GEM_DOMAIN_VRAM);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 	case 6:
@@ -245,7 +246,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 						  AMDGPU_GEM_DOMAIN_GTT,
 						  AMDGPU_GEM_DOMAIN_VRAM);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 	case 7:
@@ -256,7 +257,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 						  AMDGPU_GEM_DOMAIN_VRAM,
 						  AMDGPU_GEM_DOMAIN_GTT);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 	case 8:
@@ -267,7 +268,7 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 					      AMDGPU_GEM_DOMAIN_VRAM,
 					      AMDGPU_GEM_DOMAIN_VRAM);
 			if (r)
-				return r;
+				goto done;
 		}
 		break;
 
@@ -276,5 +277,9 @@ int amdgpu_benchmark(struct amdgpu_device *adev, int test_number)
 		r = -EINVAL;
 		break;
 	}
+
+done:
+	mutex_unlock(&adev->benchmark_mutex);
+
 	return r;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 31834d2d4d55..63b4876e13c1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3550,6 +3550,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	mutex_init(&adev->psp.mutex);
 	mutex_init(&adev->notifier_lock);
 	mutex_init(&adev->pm.stable_pstate_ctx_lock);
+	mutex_init(&adev->benchmark_mutex);
 
 	amdgpu_device_init_apu_flags(adev);
 
-- 
2.35.1



More information about the amd-gfx mailing list