Skip to contentSkip to conversation

tests/amdgpu: add stable pstate test

PATCH In review Jesse Zhang 3 participants 3 messages Sep 22, 2023 – Sep 23, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/amdgpu: add stable pstate test

---
 tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/amdgpu/amd_basic.c +43 -0
index 24c70a9f7..f23a13343 100644
@@ -612,6 +612,39 @@ amdgpu_sync_dependency_test(amdgpu_device_handle device_handle)
 	free_cmd_base(base);
 }
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+static void
+amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
+{
+	int r;
+	amdgpu_context_handle context_handle;
+	uint32_t current_pstate = 0, new_pstate = 0;
+
+	r = amdgpu_cs_ctx_create(device_handle, &context_handle);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &current_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_NONE);
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_SET_STABLE_PSTATE,
+					AMDGPU_CTX_STABLE_PSTATE_PEAK, NULL);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &new_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_PEAK);
+
+	r = amdgpu_cs_ctx_free(context_handle);
+	igt_assert_eq(r, 0);
+
+}
+#endif
+
 static void
 amdgpu_gfx_dispatch_test_gfx(amdgpu_device_handle device_handle)
 {
@@ -739,6 +772,16 @@ igt_main
 		}
 	}
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+	igt_describe("Check-pstate-for-gfx-power-and-clock");
+	igt_subtest_with_dynamic("stable-pstate-test-with-IP-SMU") {
+		if (arr_cap[AMD_IP_GFX]) {
+			igt_dynamic_f("stable-pstate-test")
+			amdgpu_stable_pstate_test(device);
+		}
+	}
+#endif
+
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
Signature · 1 line
2.25.1
#1 lore raw

On 2023-09-22 01:52, Jesse Zhang wrote:

Add a one-liner description in the body of the commit.

Add a stable p-state test.

Quoted 11 lines
---
 tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/amdgpu/amd_basic.c +0 -0
index 24c70a9f7..f23a13343 100644

tests/amdgpu/amd_basic.c amdgpu_sync_dependency_test(amdgpu_device_handle device_handle) · line 621

Quoted 10 lines
tests/amdgpu/amd_basic.c +7 -0
@@ -612,6 +612,39 @@ amdgpu_sync_dependency_test(amdgpu_device_handle device_handle)
 	free_cmd_base(base);
 }
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+static void
+amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
+{
+	int r;
+	amdgpu_context_handle context_handle;
+	uint32_t current_pstate = 0, new_pstate = 0;

Don't initialize them to 0 here. Just do,

	uint32_t current_pstate, new_pstate;

If you used them without them being initialized, that would be an error, the compiler would catch this and you want that, so you can revisit the code. But if you initialize them, this would hide this error. So don't initialize them when you define them.

Quoted 46 lines
tests/amdgpu/amd_basic.c +36 -0
+
+	r = amdgpu_cs_ctx_create(device_handle, &context_handle);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &current_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_NONE);
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_SET_STABLE_PSTATE,
+					AMDGPU_CTX_STABLE_PSTATE_PEAK, NULL);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &new_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_PEAK);
+
+	r = amdgpu_cs_ctx_free(context_handle);
+	igt_assert_eq(r, 0);
+
+}
+#endif
+
 static void
 amdgpu_gfx_dispatch_test_gfx(amdgpu_device_handle device_handle)
 {
@@ -739,6 +772,16 @@ igt_main
 		}
 	}
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+	igt_describe("Check-pstate-for-gfx-power-and-clock");
+	igt_subtest_with_dynamic("stable-pstate-test-with-IP-SMU") {
+		if (arr_cap[AMD_IP_GFX]) {
+			igt_dynamic_f("stable-pstate-test")
+			amdgpu_stable_pstate_test(device);
+		}
+	}
+#endif
+
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);
Signature · 2 lines
Regards,
Luben
#2 lore raw
In reply to Jesse Zhang

Hi Jesse,

Please, do not add pstate test to the basic tests.

Please, create a separate file amd_pstate.c, and use conditional compilation which  depends on when such' ioctl' was added to drmlib ,

for example, into meson.build  we have this approach already.

    if libdrm_amdgpu.version().version_compare('> 2.4.99')
        amdgpu_progs +=[ 'amd_dispatch',]
    else
        warning('libdrm <= 2.4.99 found, amdgpu_cs_query_reset_state2 not applicable') endif

Thanks, Vitaly

Quoted 67 lines · Jesse Zhang
---
 tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tests/amdgpu/amd_basic.c +43 -0
index 24c70a9f7..f23a13343 100644
@@ -612,6 +612,39 @@ amdgpu_sync_dependency_test(amdgpu_device_handle device_handle)
 	free_cmd_base(base);
 }
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+static void
+amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
+{
+	int r;
+	amdgpu_context_handle context_handle;
+	uint32_t current_pstate = 0, new_pstate = 0;
+
+	r = amdgpu_cs_ctx_create(device_handle, &context_handle);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &current_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_NONE);
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_SET_STABLE_PSTATE,
+					AMDGPU_CTX_STABLE_PSTATE_PEAK, NULL);
+	igt_assert_eq(r, 0);
+
+	r = amdgpu_cs_ctx_stable_pstate(context_handle,
+					AMDGPU_CTX_OP_GET_STABLE_PSTATE,
+					0, &new_pstate);
+	igt_assert_eq(r, 0);
+	igt_assert_eq(new_pstate, AMDGPU_CTX_STABLE_PSTATE_PEAK);
+
+	r = amdgpu_cs_ctx_free(context_handle);
+	igt_assert_eq(r, 0);
+
+}
+#endif
+
 static void
 amdgpu_gfx_dispatch_test_gfx(amdgpu_device_handle device_handle)
 {
@@ -739,6 +772,16 @@ igt_main
 		}
 	}
 
+#ifdef AMDGPU_CTX_OP_GET_STABLE_PSTATE
+	igt_describe("Check-pstate-for-gfx-power-and-clock");
+	igt_subtest_with_dynamic("stable-pstate-test-with-IP-SMU") {
+		if (arr_cap[AMD_IP_GFX]) {
+			igt_dynamic_f("stable-pstate-test")
+			amdgpu_stable_pstate_test(device);
+		}
+	}
+#endif
+
 	igt_fixture {
 		amdgpu_device_deinitialize(device);
 		drm_close_driver(fd);