Add initial test to xe query test suite that exercises the reset stats
query.  The new test outputs the results of the query.

Signed-off-by: Jonathan Cavitt <[email protected]>
---
 tests/intel/xe_query.c | 85 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/tests/intel/xe_query.c b/tests/intel/xe_query.c
index 1566680e7a..9862ea87d9 100644
--- a/tests/intel/xe_query.c
+++ b/tests/intel/xe_query.c
@@ -1077,6 +1077,90 @@ static void test_query_oa_units(int fd)
        }
 }
 
+/**
+ * The reset stats query will report -EOPNOTSUPP if the kernel is
+ * configured without CONFIG_PROC_FS.  Check this before running
+ * any tests on this query.
+ */
+static bool
+query_reset_stats_supported(int fd)
+{
+       struct drm_xe_device_query query = {
+               .extensions = 0,
+               .query = DRM_XE_DEVICE_QUERY_RESET_STATS,
+               .size = 0,
+               .data = 0,
+       };
+       int ret = igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);
+
+       if (ret)
+               igt_assert(ret == -EOPNOTSUPP);
+       return !ret;
+}
+
+/**
+ * SUBTEST: query-reset-stats
+ * Description: Display fields for reset stats query
+ *
+ * SUBTEST: multigpu-query-reset-stats
+ * Description: Display fields for reset stats query for all GPU devices
+ * Sub-category: MultiGPU
+ */
+static void test_query_reset_stats(int fd)
+{
+       struct drm_xe_query_reset_stats *qrs;
+       struct drm_xe_device_query query = {
+               .extensions = 0,
+               .query = DRM_XE_DEVICE_QUERY_RESET_STATS,
+               .size = 0,
+               .data = 0,
+       };
+       struct drm_xe_exec_queue_ban *ban;
+
+       igt_skip_on(!query_reset_stats_supported(fd));
+       igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+
+       qrs = malloc(query.size);
+       igt_assert(qrs);
+
+       query.data = to_user_pointer(qrs);
+       igt_assert_eq(igt_ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+
+       igt_info("reset count: %lld\n", qrs->reset_count);
+       igt_info("ban count: %lld\n", qrs->ban_count);
+
+       for (int i = 0; i < qrs->ban_count; i++) {
+               ban = &qrs->ban_list[i];
+
+               igt_info("-------------------------------\n");
+               igt_info("exec queue ban %d\n", i);
+               igt_info("-------------------------------\n");
+               igt_info("exec_queue_id: %d\n", ban->exec_queue_id);
+               if (!ban->pf_found) {
+                       igt_info("no associated pagefault\n");
+                       continue;
+               }
+               igt_info("pagefault associated:\n");
+               igt_info("\tASID: %d\n"
+                        "\tVFID: %d\n"
+                        "\tPDATA: 0x%04x\n"
+                        "\tFaulted Address: 0x%08x%08x\n"
+                        "\tFaultType: %d\n"
+                        "\tAccessType: %d\n"
+                        "\tEngineClass: %d %s\n"
+                        "\tEngineInstance: %d\n",
+                        ban->asid, ban->vfid, ban->pdata,
+                        upper_32_bits(ban->fault_addr),
+                        lower_32_bits(ban->fault_addr),
+                        ban->fault_type, ban->access_type,
+                        ban->engine_class,
+                        xe_engine_class_string(ban->engine_class),
+                        ban->engine_instance);
+       }
+
+       free(qrs);
+}
+
 igt_main
 {
        const struct {
@@ -1094,6 +1178,7 @@ igt_main
                { "query-uc-fw-version-guc", test_query_uc_fw_version_guc },
                { "query-uc-fw-version-huc", test_query_uc_fw_version_huc },
                { "query-oa-units", test_query_oa_units },
+               { "query-reset-stats", test_query_reset_stats },
                { "query-invalid-cs-cycles", test_engine_cycles_invalid },
                { "query-invalid-query", test_query_invalid_query },
                { "query-invalid-size", test_query_invalid_size },
-- 
2.43.0

Reply via email to