Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
@ 2023-09-22  5:52 Jesse Zhang
  2023-09-22 21:03 ` Luben Tuikov
  2023-09-23  0:24 ` vitaly prosyak
  0 siblings, 2 replies; 6+ messages in thread
From: Jesse Zhang @ 2023-09-22  5:52 UTC (permalink / raw)
  To: igt-dev; +Cc: Tim Huang, Luben Tuikov, Alex Deucher, Christian Koenig

Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
Signed-off-by: Tim Huang <tim.huang@amd.com>
---
 tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/tests/amdgpu/amd_basic.c b/tests/amdgpu/amd_basic.c
index 24c70a9f7..f23a13343 100644
--- a/tests/amdgpu/amd_basic.c
+++ b/tests/amdgpu/amd_basic.c
@@ -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);
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
  2023-09-22  5:52 [igt-dev] [PATCH] tests/amdgpu: add stable pstate test Jesse Zhang
@ 2023-09-22 21:03 ` Luben Tuikov
  2023-09-23  0:24 ` vitaly prosyak
  1 sibling, 0 replies; 6+ messages in thread
From: Luben Tuikov @ 2023-09-22 21:03 UTC (permalink / raw)
  To: Jesse Zhang, igt-dev; +Cc: Alex Deucher, Tim Huang, Christian Koenig

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.

> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
> Signed-off-by: Tim Huang <tim.huang@amd.com>
> ---
>  tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
> 
> diff --git a/tests/amdgpu/amd_basic.c b/tests/amdgpu/amd_basic.c
> index 24c70a9f7..f23a13343 100644
> --- a/tests/amdgpu/amd_basic.c
> +++ b/tests/amdgpu/amd_basic.c
> @@ -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.

> +
> +	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);

-- 
Regards,
Luben

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
  2023-09-22  5:52 [igt-dev] [PATCH] tests/amdgpu: add stable pstate test Jesse Zhang
  2023-09-22 21:03 ` Luben Tuikov
@ 2023-09-23  0:24 ` vitaly prosyak
  1 sibling, 0 replies; 6+ messages in thread
From: vitaly prosyak @ 2023-09-23  0:24 UTC (permalink / raw)
  To: Jesse Zhang, igt-dev
  Cc: Alex Deucher, Tim Huang, Luben Tuikov, Christian Koenig

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

On 2023-09-22 01:52, Jesse Zhang wrote:
> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
> Signed-off-by: Tim Huang <tim.huang@amd.com>
> ---
>  tests/amdgpu/amd_basic.c | 43 ++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>
> diff --git a/tests/amdgpu/amd_basic.c b/tests/amdgpu/amd_basic.c
> index 24c70a9f7..f23a13343 100644
> --- a/tests/amdgpu/amd_basic.c
> +++ b/tests/amdgpu/amd_basic.c
> @@ -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);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
@ 2023-09-25  6:05 Jesse Zhang
  2023-09-26  1:14 ` vitaly prosyak
  0 siblings, 1 reply; 6+ messages in thread
From: Jesse Zhang @ 2023-09-25  6:05 UTC (permalink / raw)
  To: igt-dev; +Cc: Tim Huang, Luben Tuikov, Alex Deucher, Christian Koenig

In order to verify gfx power and clock, add pstate test.

v2:
   - restricted build for pstate tests due to build failure
       for drmlib <= 2.4.109 (Vitaly)
   - Optimize some code (Luben)

Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
Signed-off-by: Tim Huang <tim.huang@amd.com>
---
 include/drm-uapi/amdgpu_drm.h |  9 +++++
 tests/amdgpu/amd_pstate.c     | 69 +++++++++++++++++++++++++++++++++++
 tests/amdgpu/meson.build      |  6 +++
 3 files changed, 84 insertions(+)
 create mode 100644 tests/amdgpu/amd_pstate.c

diff --git a/include/drm-uapi/amdgpu_drm.h b/include/drm-uapi/amdgpu_drm.h
index 0cbd1540a..6240ae5ea 100644
--- a/include/drm-uapi/amdgpu_drm.h
+++ b/include/drm-uapi/amdgpu_drm.h
@@ -206,6 +206,8 @@ union drm_amdgpu_bo_list {
 #define AMDGPU_CTX_OP_FREE_CTX	2
 #define AMDGPU_CTX_OP_QUERY_STATE	3
 #define AMDGPU_CTX_OP_QUERY_STATE2	4
+#define AMDGPU_CTX_OP_GET_STABLE_PSTATE	5
+#define AMDGPU_CTX_OP_SET_STABLE_PSTATE	6
 
 /* GPU reset status */
 #define AMDGPU_CTX_NO_RESET		0
@@ -237,6 +239,13 @@ union drm_amdgpu_bo_list {
 */
 #define AMDGPU_CTX_PRIORITY_HIGH        512
 #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
+/* select a stable profiling pstate for perfmon tools */
+#define AMDGPU_CTX_STABLE_PSTATE_FLAGS_MASK  0xf
+#define AMDGPU_CTX_STABLE_PSTATE_NONE  0
+#define AMDGPU_CTX_STABLE_PSTATE_STANDARD  1
+#define AMDGPU_CTX_STABLE_PSTATE_MIN_SCLK  2
+#define AMDGPU_CTX_STABLE_PSTATE_MIN_MCLK  3
+#define AMDGPU_CTX_STABLE_PSTATE_PEAK  4
 
 struct drm_amdgpu_ctx_in {
 	/** AMDGPU_CTX_OP_* */
diff --git a/tests/amdgpu/amd_pstate.c b/tests/amdgpu/amd_pstate.c
new file mode 100644
index 000000000..40fdc32cc
--- /dev/null
+++ b/tests/amdgpu/amd_pstate.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2014 Advanced Micro Devices, Inc.
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ * Copyright 2023 Advanced Micro Devices, Inc.
+ */
+#include <amdgpu.h>
+#include <amdgpu_drm.h>
+#include "drmtest.h"
+#include "igt.h"
+
+static void
+amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
+{
+	int r;
+	amdgpu_context_handle context_handle;
+	uint32_t current_pstate, new_pstate;
+
+	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);
+
+}
+
+igt_main
+{
+	amdgpu_device_handle device;
+	int fd = -1;
+
+	igt_fixture {
+		uint32_t major, minor;
+		int err;
+
+		fd = drm_open_driver(DRIVER_AMDGPU);
+
+		err = amdgpu_device_initialize(fd, &major, &minor, &device);
+		igt_require(err == 0);
+
+		igt_info("Initialized amdgpu, driver version %d.%d\n",
+			 major, minor);
+	}

+	igt_subtest("amdgpu_pstate")
+	amdgpu_stable_pstate_test(device);
+
+	igt_fixture {
+		amdgpu_device_deinitialize(device);
+		drm_close_driver(fd);
+	}
+}
+
diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build
index ebf52bf38..4a522386d 100644
--- a/tests/amdgpu/meson.build
+++ b/tests/amdgpu/meson.build
@@ -42,6 +42,12 @@ if libdrm_amdgpu.found()
 	else
 		warning('libdrm <= 2.4.97 found, amd_syncobj test not applicable')
 	endif
+
+	if libdrm_amdgpu.version().version_compare('> 2.4.109')
+		amdgpu_progs +=[ 'amd_pstate', ]
+	else
+		warning('libdrm <= 2.4.109 found, amd_pstate test not applicable')
+	endif
 	amdgpu_deps += libdrm_amdgpu
 endif
 
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
  2023-09-25  6:05 Jesse Zhang
@ 2023-09-26  1:14 ` vitaly prosyak
  0 siblings, 0 replies; 6+ messages in thread
From: vitaly prosyak @ 2023-09-26  1:14 UTC (permalink / raw)
  To: Jesse Zhang, igt-dev
  Cc: Alex Deucher, Tim Huang, Luben Tuikov, Christian Koenig

The patch looks good to me.

However there is kind of issue there:

https://patchwork.freedesktop.org/series/124092/

I am not sure , did you use 'git fetch' and then 'git pull --rebase' just before  the patch was locally created and then sent to igt-dev?

After the fix , please, use:

 Reviewed-by: Vitaly Prosyak <vitaly.prosyak@amd.com>


Thanks, Vitaly


On 2023-09-25 02:05, Jesse Zhang wrote:
> In order to verify gfx power and clock, add pstate test.
>
> v2:
>    - restricted build for pstate tests due to build failure
>        for drmlib <= 2.4.109 (Vitaly)
>    - Optimize some code (Luben)
>
> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
> Signed-off-by: Tim Huang <tim.huang@amd.com>
> ---
>  include/drm-uapi/amdgpu_drm.h |  9 +++++
>  tests/amdgpu/amd_pstate.c     | 69 +++++++++++++++++++++++++++++++++++
>  tests/amdgpu/meson.build      |  6 +++
>  3 files changed, 84 insertions(+)
>  create mode 100644 tests/amdgpu/amd_pstate.c
>
> diff --git a/include/drm-uapi/amdgpu_drm.h b/include/drm-uapi/amdgpu_drm.h
> index 0cbd1540a..6240ae5ea 100644
> --- a/include/drm-uapi/amdgpu_drm.h
> +++ b/include/drm-uapi/amdgpu_drm.h
> @@ -206,6 +206,8 @@ union drm_amdgpu_bo_list {
>  #define AMDGPU_CTX_OP_FREE_CTX	2
>  #define AMDGPU_CTX_OP_QUERY_STATE	3
>  #define AMDGPU_CTX_OP_QUERY_STATE2	4
> +#define AMDGPU_CTX_OP_GET_STABLE_PSTATE	5
> +#define AMDGPU_CTX_OP_SET_STABLE_PSTATE	6
>  
>  /* GPU reset status */
>  #define AMDGPU_CTX_NO_RESET		0
> @@ -237,6 +239,13 @@ union drm_amdgpu_bo_list {
>  */
>  #define AMDGPU_CTX_PRIORITY_HIGH        512
>  #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
> +/* select a stable profiling pstate for perfmon tools */
> +#define AMDGPU_CTX_STABLE_PSTATE_FLAGS_MASK  0xf
> +#define AMDGPU_CTX_STABLE_PSTATE_NONE  0
> +#define AMDGPU_CTX_STABLE_PSTATE_STANDARD  1
> +#define AMDGPU_CTX_STABLE_PSTATE_MIN_SCLK  2
> +#define AMDGPU_CTX_STABLE_PSTATE_MIN_MCLK  3
> +#define AMDGPU_CTX_STABLE_PSTATE_PEAK  4
>  
>  struct drm_amdgpu_ctx_in {
>  	/** AMDGPU_CTX_OP_* */
> diff --git a/tests/amdgpu/amd_pstate.c b/tests/amdgpu/amd_pstate.c
> new file mode 100644
> index 000000000..40fdc32cc
> --- /dev/null
> +++ b/tests/amdgpu/amd_pstate.c
> @@ -0,0 +1,69 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright 2014 Advanced Micro Devices, Inc.
> + * Copyright 2022 Advanced Micro Devices, Inc.
> + * Copyright 2023 Advanced Micro Devices, Inc.
> + */
> +#include <amdgpu.h>
> +#include <amdgpu_drm.h>
> +#include "drmtest.h"
> +#include "igt.h"
> +
> +static void
> +amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
> +{
> +	int r;
> +	amdgpu_context_handle context_handle;
> +	uint32_t current_pstate, new_pstate;
> +
> +	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);
> +
> +}
> +
> +igt_main
> +{
> +	amdgpu_device_handle device;
> +	int fd = -1;
> +
> +	igt_fixture {
> +		uint32_t major, minor;
> +		int err;
> +
> +		fd = drm_open_driver(DRIVER_AMDGPU);
> +
> +		err = amdgpu_device_initialize(fd, &major, &minor, &device);
> +		igt_require(err == 0);
> +
> +		igt_info("Initialized amdgpu, driver version %d.%d\n",
> +			 major, minor);
> +	}
>
> +	igt_subtest("amdgpu_pstate")
> +	amdgpu_stable_pstate_test(device);
> +
> +	igt_fixture {
> +		amdgpu_device_deinitialize(device);
> +		drm_close_driver(fd);
> +	}
> +}
> +
> diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build
> index ebf52bf38..4a522386d 100644
> --- a/tests/amdgpu/meson.build
> +++ b/tests/amdgpu/meson.build
> @@ -42,6 +42,12 @@ if libdrm_amdgpu.found()
>  	else
>  		warning('libdrm <= 2.4.97 found, amd_syncobj test not applicable')
>  	endif
> +
> +	if libdrm_amdgpu.version().version_compare('> 2.4.109')
> +		amdgpu_progs +=[ 'amd_pstate', ]
> +	else
> +		warning('libdrm <= 2.4.109 found, amd_pstate test not applicable')
> +	endif
>  	amdgpu_deps += libdrm_amdgpu
>  endif
>  

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [igt-dev] [PATCH] tests/amdgpu: add stable pstate test
@ 2023-09-26  2:50 Jesse Zhang
  0 siblings, 0 replies; 6+ messages in thread
From: Jesse Zhang @ 2023-09-26  2:50 UTC (permalink / raw)
  To: igt-dev; +Cc: Tim Huang, Luben Tuikov, Alex Deucher, Christian Koenig

In order to verify gfx power and clock, add pstate test.
v2:
   - restricted build for pstate tests due to build failure
       for drmlib <= 2.4.109 (Vitaly)
   - Optimize some code (Luben)

Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
Signed-off-by: Tim Huang <tim.huang@amd.com>
Reviewed-by: Vitaly Prosyak <vitaly.prosyak@amd.com>
---
 include/drm-uapi/amdgpu_drm.h |  9 +++++
 tests/amdgpu/amd_pstate.c     | 69 +++++++++++++++++++++++++++++++++++
 tests/amdgpu/meson.build      |  6 +++
 3 files changed, 84 insertions(+)
 create mode 100644 tests/amdgpu/amd_pstate.c

diff --git a/include/drm-uapi/amdgpu_drm.h b/include/drm-uapi/amdgpu_drm.h
index 323137f42..3f10e45ef 100644
--- a/include/drm-uapi/amdgpu_drm.h
+++ b/include/drm-uapi/amdgpu_drm.h
@@ -206,6 +206,8 @@ union drm_amdgpu_bo_list {
 #define AMDGPU_CTX_OP_FREE_CTX	2
 #define AMDGPU_CTX_OP_QUERY_STATE	3
 #define AMDGPU_CTX_OP_QUERY_STATE2	4
+#define AMDGPU_CTX_OP_GET_STABLE_PSTATE	5
+#define AMDGPU_CTX_OP_SET_STABLE_PSTATE	6
 
 /* GPU reset status */
 #define AMDGPU_CTX_NO_RESET		0
@@ -239,6 +241,13 @@ union drm_amdgpu_bo_list {
 */
 #define AMDGPU_CTX_PRIORITY_HIGH        512
 #define AMDGPU_CTX_PRIORITY_VERY_HIGH   1023
+/* select a stable profiling pstate for perfmon tools */
+#define AMDGPU_CTX_STABLE_PSTATE_FLAGS_MASK  0xf
+#define AMDGPU_CTX_STABLE_PSTATE_NONE  0
+#define AMDGPU_CTX_STABLE_PSTATE_STANDARD  1
+#define AMDGPU_CTX_STABLE_PSTATE_MIN_SCLK  2
+#define AMDGPU_CTX_STABLE_PSTATE_MIN_MCLK  3
+#define AMDGPU_CTX_STABLE_PSTATE_PEAK  4
 
 struct drm_amdgpu_ctx_in {
 	/** AMDGPU_CTX_OP_* */
diff --git a/tests/amdgpu/amd_pstate.c b/tests/amdgpu/amd_pstate.c
new file mode 100644
index 000000000..40fdc32cc
--- /dev/null
+++ b/tests/amdgpu/amd_pstate.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2014 Advanced Micro Devices, Inc.
+ * Copyright 2022 Advanced Micro Devices, Inc.
+ * Copyright 2023 Advanced Micro Devices, Inc.
+ */
+#include <amdgpu.h>
+#include <amdgpu_drm.h>
+#include "drmtest.h"
+#include "igt.h"
+
+static void
+amdgpu_stable_pstate_test(amdgpu_device_handle device_handle)
+{
+	int r;
+	amdgpu_context_handle context_handle;
+	uint32_t current_pstate, new_pstate;
+
+	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);
+
+}
+
+igt_main
+{
+	amdgpu_device_handle device;
+	int fd = -1;
+
+	igt_fixture {
+		uint32_t major, minor;
+		int err;
+
+		fd = drm_open_driver(DRIVER_AMDGPU);
+
+		err = amdgpu_device_initialize(fd, &major, &minor, &device);
+		igt_require(err == 0);
+
+		igt_info("Initialized amdgpu, driver version %d.%d\n",
+			 major, minor);
+	}
+
+	igt_subtest("amdgpu_pstate")
+	amdgpu_stable_pstate_test(device);
+
+	igt_fixture {
+		amdgpu_device_deinitialize(device);
+		drm_close_driver(fd);
+	}
+}
+
diff --git a/tests/amdgpu/meson.build b/tests/amdgpu/meson.build
index 2949249a4..f52fc3645 100644
--- a/tests/amdgpu/meson.build
+++ b/tests/amdgpu/meson.build
@@ -47,6 +47,12 @@ if libdrm_amdgpu.found()
 	else
 		warning('libdrm <= 2.4.99 found, amdgpu_cs_query_reset_state2 not applicable')
 	endif
+	if libdrm_amdgpu.version().version_compare('> 2.4.109')
+		amdgpu_progs +=[ 'amd_pstate', ]
+	else
+		warning('libdrm <= 2.4.109 found, amd_pstate test not applicable')
+	endif
+
 	amdgpu_deps += libdrm_amdgpu
 endif
 
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-09-26  2:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-22  5:52 [igt-dev] [PATCH] tests/amdgpu: add stable pstate test Jesse Zhang
2023-09-22 21:03 ` Luben Tuikov
2023-09-23  0:24 ` vitaly prosyak
  -- strict thread matches above, loose matches on Subject: below --
2023-09-25  6:05 Jesse Zhang
2023-09-26  1:14 ` vitaly prosyak
2023-09-26  2:50 Jesse Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox