Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ashutosh Dixit <ashutosh.dixit@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 04/20] lib/i915/perf: Derive topology info for xe devices
Date: Mon,  7 Aug 2023 18:00:01 -0700	[thread overview]
Message-ID: <20230808010017.37819-5-ashutosh.dixit@intel.com> (raw)
In-Reply-To: <20230808010017.37819-1-ashutosh.dixit@intel.com>

Derive topology info for xe devices and feed it into
intel_perf_for_devinfo.

Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com>
---
 lib/i915/perf.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++-
 lib/i915/perf.h |   1 +
 2 files changed, 115 insertions(+), 1 deletion(-)

diff --git a/lib/i915/perf.c b/lib/i915/perf.c
index 5b82eeaf04b9..8a3f696f4b39 100644
--- a/lib/i915/perf.c
+++ b/lib/i915/perf.c
@@ -38,8 +38,11 @@
 #include <i915_drm.h>
 
 #include "drmtest.h"
+#include "igt_aux.h"
 #include "i915_pciids.h"
 #include "intel_chipset.h"
+#include "ioctl_wrappers.h"
+#include "linux_scaffold.h"
 #include "perf.h"
 #include "xe/xe_query.h"
 
@@ -608,6 +611,107 @@ intel_sysfs_attr_id_to_name(int sysfs_dirfd, intel_sysfs_attr_id id, int gt)
 		intel_sysfs_attr_name[0][id];
 }
 
+struct drm_i915_query_topology_info *
+xe_fill_i915_topology_info(int drm_fd)
+{
+	struct drm_i915_query_topology_info i915_topinfo = {};
+	struct drm_i915_query_topology_info *i915_topo;
+	struct drm_xe_query_topology_mask *xe_topo;
+	int total_size, pos = 0;
+	u8 *ptr;
+	struct drm_xe_device_query query = {
+		.extensions = 0,
+		.query = DRM_XE_DEVICE_QUERY_GT_TOPOLOGY,
+		.size = 0,
+		.data = 0,
+	};
+
+	/* Fixed fields, see fill_topology_info() and intel_sseu_set_info() in i915 */
+	i915_topinfo.max_slices = 1;			/* always 1 */
+	if (IS_PONTEVECCHIO(xe_dev_id(drm_fd))) {
+		i915_topinfo.max_subslices = 64;
+		i915_topinfo.max_eus_per_subslice = 8;
+	} else if (intel_graphics_ver(xe_dev_id(drm_fd)) >= IP_VER(12, 50)) {
+		i915_topinfo.max_subslices = 32;
+		i915_topinfo.max_eus_per_subslice = 16;
+	} else if (intel_graphics_ver(xe_dev_id(drm_fd)) >= IP_VER(12, 0)) {
+		i915_topinfo.max_subslices = 6;
+		i915_topinfo.max_eus_per_subslice = 16;
+	} else {
+		igt_assert(0);
+	}
+	i915_topinfo.subslice_offset = 1;		/* always 1 */
+	i915_topinfo.subslice_stride = DIV_ROUND_UP(i915_topinfo.max_subslices, 8);
+	i915_topinfo.eu_offset = i915_topinfo.subslice_offset + i915_topinfo.subslice_stride;
+	i915_topinfo.eu_stride = DIV_ROUND_UP(i915_topinfo.max_eus_per_subslice, 8);
+
+	/* Allocate and start filling the struct to return */
+	total_size = sizeof(i915_topinfo) + i915_topinfo.eu_offset +
+			i915_topinfo.max_subslices * i915_topinfo.eu_stride;
+	i915_topo = malloc(total_size);
+	igt_assert(i915_topo);
+
+	memcpy(i915_topo, &i915_topinfo, sizeof(i915_topinfo));
+	ptr = (u8 *)i915_topo + sizeof(i915_topinfo);
+	*ptr++ = 0x1;					/* slice mask */
+
+	/* Get xe topology masks */
+	igt_assert_eq(igt_ioctl(drm_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+	igt_assert_neq(query.size, 0);
+
+	xe_topo = malloc(query.size);
+	igt_assert(xe_topo);
+
+	query.data = to_user_pointer(xe_topo);
+	igt_assert_eq(igt_ioctl(drm_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query), 0);
+	igt_debug("Topology size: %d\n", query.size);
+
+	while (query.size >= sizeof(struct drm_xe_query_topology_mask)) {
+		struct drm_xe_query_topology_mask *topo =
+			(struct drm_xe_query_topology_mask*)((unsigned char*)xe_topo + pos);
+		int i, sz = sizeof(struct drm_xe_query_topology_mask) + topo->num_bytes;
+		u64 geom_mask, compute_mask;
+
+		igt_debug(" gt_id: %d type: %d n:%d [%d] ", topo->gt_id, topo->type, topo->num_bytes, sz);
+		for (int j=0; j< topo->num_bytes; j++)
+			igt_debug(" %02x", topo->mask[j]);
+		igt_debug("\n");
+
+		/* i915 only returns topology for gt 0, do the same here */
+		if (topo->gt_id)
+			continue;
+
+		/* Follow the same order as in xe query_gt_topology() */
+		switch (topo->type) {
+		case XE_TOPO_DSS_GEOMETRY:
+			igt_assert_lte(i915_topo->subslice_stride, 8);	/* Fit in u64 mask */
+			memcpy(&geom_mask, topo->mask, i915_topo->subslice_stride);
+			break;
+		case XE_TOPO_DSS_COMPUTE:
+			memcpy(&compute_mask, topo->mask, i915_topo->subslice_stride);
+			geom_mask |= compute_mask;
+			memcpy(ptr, &geom_mask, i915_topo->subslice_stride);
+			ptr += i915_topo->subslice_stride;
+			break;
+		case XE_TOPO_EU_PER_DSS:
+			for (i = 0; i < i915_topo->max_subslices; i++) {
+				memcpy(ptr, topo->mask, i915_topo->eu_stride);
+				ptr += i915_topo->eu_stride;
+			}
+			break;
+		default:
+			igt_assert(0);
+		}
+
+		query.size -= sz;
+		pos += sz;
+	}
+
+	free(xe_topo);
+
+	return i915_topo;
+}
+
 static struct intel_perf *
 xe_perf_for_fd(int drm_fd, int gt)
 {
@@ -616,6 +720,7 @@ xe_perf_for_fd(int drm_fd, int gt)
 	uint32_t timestamp_frequency;
 	uint64_t gt_min_freq;
 	uint64_t gt_max_freq;
+	struct drm_i915_query_topology_info *topology;
 	struct intel_perf *ret;
 	int sysfs_dir_fd = open_master_sysfs_dir(drm_fd);
 	char path_min[64], path_max[64];
@@ -644,15 +749,23 @@ xe_perf_for_fd(int drm_fd, int gt)
 	device_id = intel_get_drm_devid(drm_fd);
 	timestamp_frequency = xe_gts(drm_fd)->gts[0].oa_timestamp_freq;
 
+	topology = xe_fill_i915_topology_info(drm_fd);
+	if (!topology) {
+		igt_warn("xe_fill_i915_topology_info failed\n");
+		return NULL;
+	}
+
 	ret = intel_perf_for_devinfo(device_id,
 				     device_revision,
 				     timestamp_frequency,
 				     gt_min_freq * 1000000,
 				     gt_max_freq * 1000000,
-				     NULL);
+				     topology);
 	if (!ret)
 		igt_warn("intel_perf_for_devinfo failed\n");
 
+	free(topology);
+
 	return ret;
 }
 
diff --git a/lib/i915/perf.h b/lib/i915/perf.h
index 8a71ac635e78..f3df578ddc5f 100644
--- a/lib/i915/perf.h
+++ b/lib/i915/perf.h
@@ -318,6 +318,7 @@ intel_perf_devinfo_eu_available(const struct intel_perf_devinfo *devinfo,
 	return (devinfo->eu_masks[subslice_offset + eu / 8] & (1U << eu % 8)) != 0;
 }
 
+struct drm_i915_query_topology_info *xe_fill_i915_topology_info(int drm_fd);
 struct intel_perf *intel_perf_for_fd(int drm_fd, int gt);
 struct intel_perf *intel_perf_for_devinfo(uint32_t device_id,
 					  uint32_t revision,
-- 
2.41.0

  parent reply	other threads:[~2023-08-08  1:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-08  0:59 [igt-dev] [PATCH i-g-t 00/20] Extend i915/perf for testing Xe OA Ashutosh Dixit
2023-08-08  0:59 ` [igt-dev] [PATCH i-g-t 01/20] drm-uapi/xe_drm: OA changes Ashutosh Dixit
2023-08-08  0:59 ` [igt-dev] [PATCH i-g-t 02/20] lib/xe/xe_query: Add xe_gts interface Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 03/20] lib/i915/perf: Add xe_perf_for_fd Ashutosh Dixit
2023-08-08  6:20   ` Zbigniew Kempczyński
2023-08-08  1:00 ` Ashutosh Dixit [this message]
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 05/20] tests/i915/perf: Track variables across i915 and xe Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 06/20] tests/i915/perf: Skip not ready tests for xe Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 07/20] tests/i915/perf: Fix i915_perf_revision for use with xe Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 08/20] tests/i915/perf: Fix sysfs functions for xe Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 09/20] tests/i915/perf: Fix test_i915_ref_count " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 10/20] tests/i915/perf: Support only default_engine_group " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 11/20] tests/i915/perf: Only iterate over render engines " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 12/20] tests/i915/perf: Don't load module Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 13/20] tests/i915/perf: Move test_sysctl_defaults after the fixture Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 14/20] tests/i915/perf: Fix has_class_instance for xe Ashutosh Dixit
2023-08-08  6:35   ` Zbigniew Kempczyński
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 15/20] tests/i915/perf: Temporarily skip render_copy " Ashutosh Dixit
2023-08-08  6:30   ` Zbigniew Kempczyński
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 16/20] tests/i915/perf: Skip intel_ctx_create_all_physical " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 17/20] tests/i915/perf: Skip __for_each_render_engine " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 18/20] tests/i915/perf: Fix buf_map " Ashutosh Dixit
2023-08-08  6:26   ` Zbigniew Kempczyński
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 19/20] tests/i915/perf: Use engine_id in gen12_test_mi_rpc " Ashutosh Dixit
2023-08-08  1:00 ` [igt-dev] [PATCH i-g-t 20/20] HAX: Add OA tests to xe-fast-feedback.testlist Ashutosh Dixit
2023-08-08  2:00 ` [igt-dev] ✓ Fi.CI.BAT: success for Extend i915/perf for testing Xe OA (rev2) Patchwork
2023-08-08  2:02 ` [igt-dev] ○ CI.xeBAT: info " Patchwork
2023-08-08  9:12 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2023-07-20 23:17 [igt-dev] [PATCH i-g-t 00/20] Extend i915/perf for testing Xe OA Ashutosh Dixit
2023-07-20 23:17 ` [igt-dev] [PATCH i-g-t 04/20] lib/i915/perf: Derive topology info for xe devices Ashutosh Dixit

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=20230808010017.37819-5-ashutosh.dixit@intel.com \
    --to=ashutosh.dixit@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