Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Riana Tauro <riana.tauro@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: badal.nilawar@intel.com
Subject: [igt-dev] [PATCH i-g-t 2/3] tests/xe: Add a test to toggle GT C states and validate power
Date: Thu, 17 Aug 2023 11:23:00 +0530	[thread overview]
Message-ID: <20230817055301.855960-3-riana.tauro@intel.com> (raw)
In-Reply-To: <20230817055301.855960-1-riana.tauro@intel.com>

Add a test that toggles GT C states by checking if GT is in C0 when
forcewake is acquired and in C6 once released.
This test also validates power consumed by GPU in GT C6 is lesser
than GT C0.

v2: change test name (Suja, Anshuman)
v3: add exit handler for closing forcewake handle
    define a macro for number of repetitions (Vinay)
    change forcewake open to readonly (Anshuman)
    modify test to validate power

Signed-off-by: Riana Tauro <riana.tauro@intel.com>
---
 tests/xe/xe_pm_residency.c | 67 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/tests/xe/xe_pm_residency.c b/tests/xe/xe_pm_residency.c
index fd4876eaf..3a6611fac 100644
--- a/tests/xe/xe_pm_residency.c
+++ b/tests/xe/xe_pm_residency.c
@@ -14,14 +14,17 @@
 
 #include "igt.h"
 #include "igt_device.h"
+#include "igt_power.h"
 #include "igt_sysfs.h"
 
 #include "xe/xe_query.h"
 #include "xe/xe_util.h"
 
+#define NUM_REPS 16 /* No of Repetitions */
 #define SLEEP_DURATION 3000 /* in milliseconds */
 
 const double tolerance = 0.1;
+int forcewake_handle = -1;
 
 #define assert_within_epsilon(x, ref, tol) \
 	igt_assert_f((double)(x) <= (1.0 + (tol)) * (double)(ref) && \
@@ -50,9 +53,19 @@ enum test_type {
  * Description: Validate idle residency measured over suspend(s2idle)
  *              is greater than suspend time or within tolerance
  * Run type: FULL
+ *
+ * SUBTEST: toggle-gt-c6
+ * Description: toggles GT C states by acquiring/releasing forcewake,
+ *		also validates power consumed by GPU in GT C6 is lesser than that of GT C0.
+ * Run type: FULL
  */
 IGT_TEST_DESCRIPTION("Tests for gtidle properties");
 
+static void restore(int sig)
+{
+	close(forcewake_handle);
+}
+
 static unsigned int measured_usleep(unsigned int usec)
 {
 	struct timespec ts = { };
@@ -117,6 +130,54 @@ static void test_idle_residency(int fd, int gt, enum test_type flag)
 	assert_within_epsilon(residency_end - residency_start, elapsed_ms, tolerance);
 }
 
+static void measure_power(struct igt_power *gpu, double *power)
+{
+	struct power_sample power_sample[2];
+
+	igt_power_get_energy(gpu, &power_sample[0]);
+	measured_usleep(SLEEP_DURATION * 1000);
+	igt_power_get_energy(gpu, &power_sample[1]);
+	*power = igt_power_get_mW(gpu, &power_sample[0], &power_sample[1]);
+}
+
+static void toggle_gt_c6(int fd, int n)
+{
+	double gt_c0_power, gt_c6_power;
+	int gt;
+	struct igt_power gpu;
+
+	igt_power_open(fd, &gpu, "gpu");
+
+	do {
+		forcewake_handle = igt_debugfs_open(fd, "forcewake_all", O_RDONLY);
+		igt_assert(forcewake_handle >= 0);
+		/* check if all gts are in C0 after forcewake is acquired */
+		xe_for_each_gt(fd, gt)
+			igt_assert_f(!xe_is_gt_in_c6(fd, gt),
+				     "Forcewake acquired, GT should be in C0\n");
+
+		if (n == NUM_REPS)
+			measure_power(&gpu, &gt_c0_power);
+
+		close(forcewake_handle);
+		/* check if all gts are in C6 after forcewake is released */
+		xe_for_each_gt(fd, gt)
+			igt_assert_f(igt_wait(xe_is_gt_in_c6(fd, gt), 1000, 1),
+				     "Forcewake released, GT should be in C6\n");
+
+		if (n == NUM_REPS)
+			measure_power(&gpu, &gt_c6_power);
+	} while (n--);
+
+	igt_power_close(&gpu);
+	igt_info("GPU consumed %fmW in GT C6 and %fmW in GT C0\n", gt_c6_power, gt_c0_power);
+
+	/* FIXME: Remove dgfx check after hwmon is added */
+	if (!xe_has_vram(fd))
+		igt_assert_f(gt_c6_power < gt_c0_power,
+			     "Power consumed in GT C6 should be lower than GT C0\n");
+}
+
 igt_main
 {
 	uint32_t d3cold_allowed;
@@ -152,6 +213,12 @@ igt_main
 		xe_for_each_gt(fd, gt)
 			test_idle_residency(fd, gt, TEST_IDLE);
 
+	igt_describe("Toggle GT C states by acquiring/releasing forcewake and validate power measured");
+	igt_subtest("toggle-gt-c6") {
+		igt_install_exit_handler(restore);
+		toggle_gt_c6(fd, NUM_REPS);
+	}
+
 	igt_fixture {
 		close(fd);
 	}
-- 
2.40.0

  parent reply	other threads:[~2023-08-17  5:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17  5:52 [igt-dev] [PATCH i-g-t 0/3] Toggle GT C States and validate power Riana Tauro
2023-08-17  5:52 ` [igt-dev] [PATCH i-g-t 1/3] lib/igt_power: Modify igt_power library for xe Riana Tauro
2023-08-18  8:00   ` Kamil Konieczny
2023-08-18  8:36     ` Riana Tauro
2023-08-17  5:53 ` Riana Tauro [this message]
2023-08-23  8:40   ` [igt-dev] [PATCH i-g-t 2/3] tests/xe: Add a test to toggle GT C states and validate power Sundaresan, Sujaritha
2023-08-17  5:53 ` [igt-dev] [PATCH i-g-t 3/3] HAX: Add toggle-gt-c6 to xe-fast-feedback.testlist Riana Tauro
2023-08-17  6:35 ` [igt-dev] ✗ GitLab.Pipeline: warning for Toggle GT C States and validate power Patchwork
2023-08-17  7:01 ` [igt-dev] ○ CI.xeBAT: info " Patchwork
2023-08-17  7:08 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2023-08-17 18:07 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230817055301.855960-3-riana.tauro@intel.com \
    --to=riana.tauro@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox