[PATCH i-g-t 3/3] tests/intel/xe_pmu: Add test for per-engine-class activity

Riana Tauro riana.tauro at intel.com
Wed Jan 15 07:30:40 UTC 2025


Add basic test to validate per-engine-class activity for
all engines

Signed-off-by: Riana Tauro <riana.tauro at intel.com>
---
 tests/intel/xe_pmu.c | 55 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/tests/intel/xe_pmu.c b/tests/intel/xe_pmu.c
index 1f88e2560..de31e4dc1 100644
--- a/tests/intel/xe_pmu.c
+++ b/tests/intel/xe_pmu.c
@@ -35,7 +35,7 @@
 
 #define SLEEP_DURATION 2 /* in seconds */
 const double tolerance = 0.1;
-const unsigned long batch_duration_ns = 500e6;
+const unsigned long batch_duration_ns = 2000e6;
 const char *no_debug_data = "\0";
 
 #define __assert_within_epsilon(x, ref, tol_up, tol_down, debug_data) \
@@ -308,6 +308,52 @@ static void end_workload(int fd, struct workload *wl)
 	xe_vm_destroy(fd, wl->vm);
 }
 
+/**
+ * SUBTEST: per-engine-class-activity
+ * Description: Test to validate engine busyness by running a workload and
+ *              reading the busy ticks and total ticks counters
+ */
+static void engine_activity(int fd, struct drm_xe_engine_class_instance *eci)
+{
+	uint64_t config, engine_class, engine_instance, gt_shift, param_config;
+	uint64_t busy_ticks, total_ticks, before[2], after[2];
+	struct workload wl;
+	int pmu_fd[2];
+
+	gt_shift = pmu_format_shift(fd, "gt_id");
+	engine_class = pmu_format_shift(fd, "engine_class");
+	engine_instance = pmu_format_shift(fd, "engine_instance");
+
+	param_config = (uint64_t)eci->gt_id << gt_shift | eci->engine_class << engine_class
+			| eci->engine_instance << engine_instance;
+	config = xe_perf_event_config(fd, "engine-active-ticks") | param_config;
+	pmu_fd[0] = open_group(fd, config, -1);
+
+	config = xe_perf_event_config(fd, "total-ticks") | param_config;
+	pmu_fd[1] = open_group(fd, config, pmu_fd[0]);
+
+	run_workload(fd, eci->gt_id, eci, &wl);
+
+	pmu_read_multi(pmu_fd[0], 2, before);
+	measured_usleep(batch_duration_ns / 1000);
+	pmu_read_multi(pmu_fd[0], 2, after);
+
+	end_workload(fd, &wl);
+
+	busy_ticks = after[0] - before[0];
+	total_ticks = after[1] - before[1];
+
+	igt_debug("Engine active ticks:  after %ld, before %ld delta %ld\n", after[0], before[0],
+		  busy_ticks);
+	igt_debug("Total ticks: after %ld, before %ld delta %ld\n", after[1], before[1],
+		  total_ticks);
+
+	close(pmu_fd[0]);
+	close(pmu_fd[1]);
+
+	assert_within_epsilon(busy_ticks, total_ticks, tolerance);
+}
+
 static void test_frequency(int fd, int gt, struct drm_xe_engine_class_instance *eci)
 {
 	struct workload wl;
@@ -399,6 +445,13 @@ igt_main
 		xe_for_each_engine(fd, hwe)
 			test_frequency(fd, hwe->gt_id, hwe);
 
+	igt_describe("Validate per-engine-activity with workload running by reading pmu counters");
+	igt_subtest_with_dynamic("per-engine-class-activity")
+		xe_for_each_engine(fd, hwe)
+			igt_dynamic_f("engine-%s%d", xe_engine_class_string(hwe->engine_class),
+				      hwe->engine_instance)
+				engine_activity(fd, hwe);
+
 	igt_fixture {
 		close(fd);
 	}
-- 
2.47.1



More information about the igt-dev mailing list