Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Upadhyay <tejas.upadhyay@intel.com>
Subject: [igt-dev] [PATCH i-g-t v9 1/4] lib/igt_sysfs: Add support to query number of tiles
Date: Mon, 10 Jul 2023 10:13:27 +0530	[thread overview]
Message-ID: <20230710044330.770948-2-himal.prasad.ghimiray@intel.com> (raw)
In-Reply-To: <20230710044330.770948-1-himal.prasad.ghimiray@intel.com>

With tile and GT seperation in KMD, we need to know
number of tiles supported by platform.
We will need to access tile associated properties from IGT.
Hence adding iterator for all supported tiles.

v2:
- Calculate number of tiles once within iterator. (Rahul)
- Use snprintf instead of sprintf.

v3:
- Remove unrequired for_each_sysfs_tile_dirfd (Ashutosh)

v4:
- Implement tiles related functions in lib. (Ashutosh)

v5:
- Fix comments and remove not required conditional check. (Ashutosh)

v6:
- Remove xe_for_each_tile. (Ashutosh)

Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
Cc: Aravind Iddamsetty <aravind.iddamsetty@intel.com>
Cc: Upadhyay <tejas.upadhyay@intel.com>
Cc: Janga Rahul Kumar <janga.rahul.kumar@intel.com>
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
---
 lib/igt_sysfs.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  8 ++++++
 2 files changed, 79 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 0876f4c6b..eb35a8088 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -903,3 +903,74 @@ void igt_sysfs_engines(int xe, int engines, const char **property,
 		close(engine_fd);
 	}
 }
+
+/**
+ * xe_sysfs_tile_path:
+ * @xe_device: fd of the device
+ * @tile: tile number
+ * @path: buffer to fill with the sysfs tile path to the device
+ * @pathlen: length of @path buffer
+ *
+ * Returns:
+ * The directory path, or NULL on failure.
+ */
+char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen)
+{
+	struct stat st;
+
+	if (xe_device < 0)
+		return NULL;
+
+	if (igt_debug_on(fstat(xe_device, &st)) || igt_debug_on(!S_ISCHR(st.st_mode)))
+		return NULL;
+
+	snprintf(path, pathlen, "/sys/dev/char/%d:%d/device/tile%d",
+		 major(st.st_rdev), minor(st.st_rdev), tile);
+
+	if (!access(path, F_OK))
+		return path;
+	return NULL;
+}
+
+/**
+ * xe_sysfs_tile_open:
+ * @xe_device: fd of the device
+ * @tile: tile number
+ *
+ * This opens the sysfs tile directory corresponding to device and tile for use
+ *
+ * Returns:
+ * The directory fd, or -1 on failure.
+ */
+int xe_sysfs_tile_open(int xe_device, int tile)
+{
+	char path[96];
+
+	if (!xe_sysfs_tile_path(xe_device, tile, path, sizeof(path)))
+		return -1;
+
+	return open(path, O_RDONLY);
+}
+
+/**
+ * xe_sysfs_get_num_tiles:
+ * @xe_device: fd of the device
+ *
+ * Reads number of tile sysfs entries.
+ * Asserts for at least one tile entry.
+ * (see xe_sysfs_tile_path).
+ *
+ * Returns: Number of tiles.
+ */
+int xe_sysfs_get_num_tiles(int xe_device)
+{
+	int num_tiles = 0;
+	char path[96];
+
+	while (xe_sysfs_tile_path(xe_device, num_tiles, path, sizeof(path)))
+		++num_tiles;
+
+	igt_assert_f(num_tiles > 0, "No GT sysfs entry is found.");
+
+	return num_tiles;
+}
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 5635fc690..6d7154329 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -38,6 +38,11 @@
 	     (dirfd__ = igt_sysfs_gt_open(i915__, gt__)) != -1; \
 	     close(dirfd__), gt__++)
 
+#define for_each_sysfs_tile_dirfd(xe__, dirfd__, tile__) \
+	for (tile__ = 0; \
+	     (dirfd__ = xe_sysfs_tile_open(xe__, tile__)) != -1; \
+	     close(dirfd__), tile__++)
+
 #define i915_for_each_gt for_each_sysfs_gt_dirfd
 
 #define igt_sysfs_rps_write(dir, id, data, len) \
@@ -150,4 +155,7 @@ void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw);
 void igt_sysfs_engines(int xe, int engines, const char **property,
 		       void (*test)(int, int, const char **));
 
+char *xe_sysfs_tile_path(int xe_device, int tile, char *path, int pathlen);
+int xe_sysfs_tile_open(int xe_device, int tile);
+int xe_sysfs_get_num_tiles(int xe_device);
 #endif /* __IGT_SYSFS_H__ */
-- 
2.25.1

  reply	other threads:[~2023-07-10  4:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10  4:43 [igt-dev] [PATCH i-g-t v9 0/4] Handle GT and tile seperation in IGT Himal Prasad Ghimiray
2023-07-10  4:43 ` Himal Prasad Ghimiray [this message]
2023-07-10  6:34   ` [igt-dev] [PATCH i-g-t v9 1/4] lib/igt_sysfs: Add support to query number of tiles Dixit, Ashutosh
2023-07-10  4:43 ` [igt-dev] [PATCH i-g-t v9 2/4] lib/igt_sysfs: Handling gt related sysfs uapi changes Himal Prasad Ghimiray
2023-07-10  6:35   ` Dixit, Ashutosh
2023-07-10  4:43 ` [igt-dev] [PATCH i-g-t v9 3/4] tests/xe/xe_guc_pc: Change the sysfs paths Himal Prasad Ghimiray
2023-07-10  6:36   ` Dixit, Ashutosh
2023-07-10  4:43 ` [igt-dev] [PATCH i-g-t v9 4/4] tests/xe/xe_sysfs_tile: adds new test to verify per tile vram addr_range Himal Prasad Ghimiray
2023-07-10  6:38   ` Dixit, Ashutosh
2023-07-10  5:38 ` [igt-dev] ✓ Fi.CI.BAT: success for Handle GT and tile seperation in IGT (rev8) Patchwork
2023-07-10  5:45 ` [igt-dev] ○ CI.xeBAT: info " Patchwork
2023-07-10  6:52 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2023-07-10 13:36   ` Kamil Konieczny
2023-07-11  7:40     ` Yedireswarapu, SaiX Nandan
2023-07-11  6:55 ` Patchwork
2023-07-11  7:29 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork

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=20230710044330.770948-2-himal.prasad.ghimiray@intel.com \
    --to=himal.prasad.ghimiray@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=tejas.upadhyay@intel.com \
    /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