public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [igt-dev] [PATCH i-g-t] i915/i915_hwmon: Measure dGfx power with hwmon
@ 2023-01-14 17:05 Ashutosh Dixit
  2023-01-14 17:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for i915/i915_hwmon: Measure dGfx power with hwmon (rev3) Patchwork
  2023-01-17 19:09 ` [igt-dev] [PATCH i-g-t] i915/i915_hwmon: Measure dGfx power with hwmon Dixit, Ashutosh
  0 siblings, 2 replies; 4+ messages in thread
From: Ashutosh Dixit @ 2023-01-14 17:05 UTC (permalink / raw)
  To: igt-dev; +Cc: Badal Nilawar

In several instances (e.g. when investigating GPU power limits) it is very
useful to be able to measure GPU power easily. Since we already have all
ingridients for doing so, add a couple of hwmon tests to measure dGfx power
when idle and power under load.

v2: Changed tests names from hwmon-power-idle/busy to power-idle/busy

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 tests/i915/i915_hwmon.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tests/i915/i915_hwmon.c b/tests/i915/i915_hwmon.c
index 6d9937e99dc..aec503919d5 100644
--- a/tests/i915/i915_hwmon.c
+++ b/tests/i915/i915_hwmon.c
@@ -6,11 +6,40 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include "igt.h"
+#include "i915/gem.h"
+#include "igt_power.h"
 #include "igt_hwmon.h"
 #include "igt_sysfs.h"
 
 IGT_TEST_DESCRIPTION("Tests for i915 hwmon");
 
+static void hwmon_power(int i915, bool load)
+{
+	const intel_ctx_t *ctx = intel_ctx_create_all_physical(i915);
+	struct power_sample sample[2];
+	int sleep_duration_sec = 3;
+	struct igt_power gpu;
+	igt_spin_t *spin;
+
+	gem_quiescent_gpu(i915);
+	if (load) {
+		spin = igt_spin_new(i915, .ctx = ctx, .engine = ALL_ENGINES,
+				    .flags = IGT_SPIN_POLL_RUN);
+		/* Wait till at least one spinner starts */
+		igt_spin_busywait_until_started(spin);
+	}
+
+	igt_assert(!igt_power_open(i915, &gpu, "gpu"));
+	igt_power_get_energy(&gpu, &sample[0]);
+	usleep(sleep_duration_sec * USEC_PER_SEC);
+	igt_power_get_energy(&gpu, &sample[1]);
+	igt_info("Measured power: %g mW\n", igt_power_get_mW(&gpu, &sample[0], &sample[1]));
+
+	igt_power_close(&gpu);
+	igt_free_spins(i915);
+	intel_ctx_destroy(i915, ctx);
+}
+
 static void hwmon_read(int hwm)
 {
 	struct dirent *de;
@@ -81,6 +110,16 @@ igt_main
 		hwmon_write(hwm);
 	}
 
+	igt_describe("Measure idle power using hwmon");
+	igt_subtest("power-idle") {
+		hwmon_power(fd, false);
+	}
+
+	igt_describe("Measure power with load using hwmon");
+	igt_subtest("power-busy") {
+		hwmon_power(fd, true);
+	}
+
 	igt_fixture {
 		close(hwm);
 		close(fd);
-- 
2.38.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread
* [igt-dev] [PATCH i-g-t] i915/i915_hwmon: Measure dGfx power with hwmon
@ 2023-01-14  5:04 Ashutosh Dixit
  0 siblings, 0 replies; 4+ messages in thread
From: Ashutosh Dixit @ 2023-01-14  5:04 UTC (permalink / raw)
  To: igt-dev; +Cc: Badal Nilawar

In several instances (e.g. when investigating GPU power limits) it is very
useful to be able to measure GPU power easily. Since we already have all
ingridients for doing so, add a couple of hwmon tests to measure dGfx power
when idle and power under load.

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 tests/i915/i915_hwmon.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tests/i915/i915_hwmon.c b/tests/i915/i915_hwmon.c
index 6d9937e99dc..111a589bd91 100644
--- a/tests/i915/i915_hwmon.c
+++ b/tests/i915/i915_hwmon.c
@@ -6,11 +6,40 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include "igt.h"
+#include "i915/gem.h"
+#include "igt_power.h"
 #include "igt_hwmon.h"
 #include "igt_sysfs.h"
 
 IGT_TEST_DESCRIPTION("Tests for i915 hwmon");
 
+static void hwmon_power(int i915, bool load)
+{
+	const intel_ctx_t *ctx = intel_ctx_create_all_physical(i915);
+	struct power_sample sample[2];
+	int sleep_duration_sec = 3;
+	struct igt_power gpu;
+	igt_spin_t *spin;
+
+	gem_quiescent_gpu(i915);
+	if (load) {
+		spin = igt_spin_new(i915, .ctx = ctx, .engine = ALL_ENGINES,
+				    .flags = IGT_SPIN_POLL_RUN);
+		/* Wait till at least one spinner starts */
+		igt_spin_busywait_until_started(spin);
+	}
+
+	igt_assert(!igt_power_open(i915, &gpu, "gpu"));
+	igt_power_get_energy(&gpu, &sample[0]);
+	usleep(sleep_duration_sec * USEC_PER_SEC);
+	igt_power_get_energy(&gpu, &sample[1]);
+	igt_info("Measured power: %g mW\n", igt_power_get_mW(&gpu, &sample[0], &sample[1]));
+
+	igt_power_close(&gpu);
+	igt_free_spins(i915);
+	intel_ctx_destroy(i915, ctx);
+}
+
 static void hwmon_read(int hwm)
 {
 	struct dirent *de;
@@ -81,6 +110,16 @@ igt_main
 		hwmon_write(hwm);
 	}
 
+	igt_describe("Measure idle power using hwmon");
+	igt_subtest("hwmon-power-idle") {
+		hwmon_power(fd, false);
+	}
+
+	igt_describe("Measure power with load using hwmon");
+	igt_subtest("hwmon-power-busy") {
+		hwmon_power(fd, true);
+	}
+
 	igt_fixture {
 		close(hwm);
 		close(fd);
-- 
2.38.0

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

end of thread, other threads:[~2023-01-17 19:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-14 17:05 [igt-dev] [PATCH i-g-t] i915/i915_hwmon: Measure dGfx power with hwmon Ashutosh Dixit
2023-01-14 17:44 ` [igt-dev] ✗ Fi.CI.BAT: failure for i915/i915_hwmon: Measure dGfx power with hwmon (rev3) Patchwork
2023-01-17 19:09 ` [igt-dev] [PATCH i-g-t] i915/i915_hwmon: Measure dGfx power with hwmon Dixit, Ashutosh
  -- strict thread matches above, loose matches on Subject: below --
2023-01-14  5:04 Ashutosh Dixit

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