Hi Vinay

VF igt patches were merged so this will need a rebase

On 4/2/2025 7:09 AM, Vinay Belgaumkar wrote:
Add a basic test that uses PMU to read GT actual and requested
frequencies while running a workload.

Cc: Lucas De Marchi <lucas.demar...@intel.com>
Cc: Rodrigo Vivi <rodrigo.v...@intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaum...@intel.com>
---
  tests/intel/xe_pmu.c | 93 ++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 93 insertions(+)

diff --git a/tests/intel/xe_pmu.c b/tests/intel/xe_pmu.c
index 66edf24ad..43085b4d0 100644
--- a/tests/intel/xe_pmu.c
+++ b/tests/intel/xe_pmu.c
@@ -226,6 +226,95 @@ static void test_gt_c6_idle(int xe, unsigned int gt)
        close(pmu_fd);
  }
+/**
+ * SUBTEST: gt-frequency
+ * Description: Validate we can collect accurate frequency PMU stats
+ *             while running a workload.
+ */
+static void test_gt_frequency(int fd, struct drm_xe_engine_class_instance *eci)
+{
+       struct xe_cork *cork = NULL;
+       uint64_t end[2], start[2];
+       unsigned long config_rq_freq, config_act_freq;
+       double min[2], max[2];
+       uint32_t gt = eci->gt_id;
+       uint32_t orig_min = xe_gt_get_freq(fd, eci->gt_id, "min");
+       uint32_t orig_max = xe_gt_get_freq(fd, eci->gt_id, "max");
+       uint32_t vm;
+       int pmu_fd[2];
+
+       config_rq_freq = get_event_config(fd, gt, NULL, 
"gt-requested-frequency");
+       pmu_fd[0] = open_group(fd, config_rq_freq, -1);
+
+       config_act_freq = get_event_config(fd, gt, NULL, "gt-actual-frequency");
+       pmu_fd[1] = open_group(fd, config_act_freq, pmu_fd[0]);
+
+       vm = xe_vm_create(fd, 0, 0);
+
+       cork = xe_cork_create_opts(fd, eci, vm, 1, 1);
+       xe_cork_sync_start(fd, cork);
+
+       /*
+        * Set GPU to min frequency and read PMU counters.
+        */
+       igt_assert(xe_gt_set_freq(fd, gt, "max", orig_min) > 0);
+       igt_assert(xe_gt_get_freq(fd, gt, "max") == orig_min);
+
+       pmu_read_multi(pmu_fd[0], 2, start);
+       usleep(SLEEP_DURATION * USEC_PER_SEC);
+       pmu_read_multi(pmu_fd[0], 2, end);
+
+       min[0] = (end[0] - start[0]);
+       min[1] = (end[1] - start[1]);
+
+       /*
+        * Set GPU to max frequency and read PMU counters.
+        */
+       igt_assert(xe_gt_set_freq(fd, gt, "max", orig_max) > 0);
+       igt_assert(xe_gt_get_freq(fd, gt, "max") == orig_max);
+       igt_assert(xe_gt_set_freq(fd, gt, "min", orig_max) > 0);
+       igt_assert(xe_gt_get_freq(fd, gt, "min") == orig_max);
Should a exit handler be added to restore frequencies in case of assert failure?> +
+       pmu_read_multi(pmu_fd[0], 2, start);
+       usleep(SLEEP_DURATION * USEC_PER_SEC);
+       pmu_read_multi(pmu_fd[0], 2, end);
+
+       max[0] = (end[0] - start[0]);
+       max[1] = (end[1] - start[1]);
+
+       if (!cork->ended)This can be removed. The engine activity had a 
trailing idle case which
ended the cork before. The lib already has this check> + xe_cork_sync_end(fd, cork);
+
+       /*
+        * Restore min/max.
+        */
+       igt_assert(xe_gt_set_freq(fd, gt, "min", orig_min) > 0);
+       igt_assert(xe_gt_get_freq(fd, gt, "min") == orig_min);
+
+       igt_info("Minimum frequency: requested %.1f, actual %.1f\n",
+                min[0], min[1]);
+       igt_info("Maximum frequency: requested %.1f, actual %.1f\n",
+                max[0], max[1]);
+
+       close(pmu_fd[0]);
+       close(pmu_fd[1]);
+
+       if (cork)
+               xe_cork_destroy(fd, cork);
+
+       xe_vm_destroy(fd, vm);
+
+       close(pmu_fd[0]);
+       close(pmu_fd[1]);
+
+       assert_within_epsilon(min[0], orig_min, tolerance);
+       /*
+        * On thermally throttled devices we cannot be sure maximum frequency
+        * can be reached so use larger tolerance downwards.
+        */
+       assert_within_epsilon_up_down(max[0], orig_max, tolerance, 0.15f);
+}
+
  igt_main
  {
        int fd, gt;
@@ -254,6 +343,10 @@ igt_main
        test_each_engine("engine-activity-load", fd, eci)
                engine_activity(fd, eci, TEST_LOAD);
+ igt_describe("Validate PMU GT freq measured is within the tolerance");Can't we have this per-gt instead of engine?

Thanks
Riana> +     test_each_engine("gt-frequency", fd, eci)
+               test_gt_frequency(fd, eci);
+
        igt_fixture {
                close(fd);
        }

Reply via email to