From: Jonathan Cavitt <jonathan.cavitt@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: jonathan.cavitt@intel.com, saurabhg.gupta@intel.com,
alex.zuo@intel.com, kamil.konieczny@linux.intel.com,
vinay.belgaumkar@intel.com
Subject: [PATCH v9 1/4] lib/igt_sysfs: Add engine list helpers
Date: Tue, 3 Dec 2024 22:32:10 +0000 [thread overview]
Message-ID: <20241203223213.81798-2-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20241203223213.81798-1-jonathan.cavitt@intel.com>
Create two new helper functions, igt_sysfs_get_engine_list and
igt_sysfs_free_engine_list, that create and destroy lists of open
engines, respectively. The list created by igt_sysfs_get_engine_list
can be used to iterate over the set of engines in sysfs/engines and must
be freed by igt_sysfs_free_engine_list after use.
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
lib/igt_sysfs.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
lib/igt_sysfs.h | 3 +++
2 files changed, 64 insertions(+)
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 00d5822fd3..eaf8fd8829 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -1307,6 +1307,67 @@ static uint16_t xe_get_engine_class(char *name)
return class;
}
+/**
+ * igt_sysfs_get_engine_list:
+ * @engines: fd of the directory engine
+ *
+ * Iterates over sysfs/engines and returns an array of
+ * opened engines. The user will be in charge of closing
+ * the opened engines.
+ *
+ * The returned array will always be terminated by a -1.
+ */
+int *igt_sysfs_get_engine_list(int engines)
+{
+ struct dirent *de;
+ DIR *dir;
+ const int array_max = 16;
+ int *ret = calloc(array_max, sizeof(int));
+ int size = 0;
+
+ igt_assert(ret);
+
+ lseek(engines, 0, SEEK_SET);
+
+ dir = fdopendir(engines);
+ if (!dir)
+ close(engines);
+
+ while ((de = readdir(dir))) {
+ if (*de->d_name == '.')
+ continue;
+ igt_assert_lt(size, array_max);
+ ret[size] = openat(engines, de->d_name, O_RDONLY);
+ if (ret[size] < 0) {
+ ret[size] = 0;
+ continue;
+ }
+ size += 1;
+ }
+
+ igt_assert_lt(size, array_max);
+ ret[size] = -1;
+
+ return ret;
+}
+
+/**
+ * igt_sysfs_free_engine_list:
+ * @list: list of opened engines
+ * @size: number of engines in list
+ *
+ * Helper for cleaning up after igt_sysfs_get_engine_list.
+ * Closes all engines in list before freeing the list.
+ */
+void igt_sysfs_free_engine_list(int *list)
+{
+ int i = 0;
+
+ while (list[i] != -1)
+ close(list[i++]);
+ free(list);
+}
+
/**
* igt_sysfs_engines:
* @xe: fd of the device
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 54a4087918..86345f3d1b 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -168,6 +168,9 @@ typedef struct igt_sysfs_rw_attr {
void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw);
+int *igt_sysfs_get_engine_list(int engines);
+void igt_sysfs_free_engine_list(int *list);
+
void igt_sysfs_engines(int xe, int engines, int gt, bool all, const char **property,
void (*test)(int, int, const char **, uint16_t, int));
--
2.43.0
next prev parent reply other threads:[~2024-12-03 22:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 22:32 [PATCH v9 0/4] test/intel/xe_sysfs: Restore sysfs params correctly Jonathan Cavitt
2024-12-03 22:32 ` Jonathan Cavitt [this message]
2024-12-03 22:32 ` [PATCH v9 2/4] tests/intel/xe_sysfs*: Restore values on test failure Jonathan Cavitt
2024-12-03 22:32 ` [PATCH v9 3/4] tests/intel/xe_sysfs_timeslice_duration: Restore preempt timeout Jonathan Cavitt
2024-12-03 22:32 ` [PATCH v9 4/4] tests/intel/xe_sysfs_scheduler: Assert sysfs params are restored Jonathan Cavitt
[not found] ` <Z1Cd7leuoeUuTVpx@kamilkon-DESK1>
2024-12-04 22:20 ` [v9, " Cavitt, Jonathan
2024-12-03 23:16 ` ✓ i915.CI.BAT: success for test/intel/xe_sysfs: Restore sysfs params correctly Patchwork
2024-12-03 23:29 ` ✗ Xe.CI.BAT: failure " Patchwork
2024-12-04 0:53 ` ✗ Xe.CI.Full: " Patchwork
2024-12-04 1:03 ` ✗ i915.CI.Full: " Patchwork
2024-12-04 19:25 ` ✓ Xe.CI.BAT: success for test/intel/xe_sysfs: Restore sysfs params correctly (rev2) Patchwork
2024-12-04 19:32 ` ✓ i915.CI.BAT: " Patchwork
2024-12-04 20:42 ` ✗ i915.CI.Full: failure " Patchwork
2024-12-05 0:11 ` ✗ Xe.CI.Full: " 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=20241203223213.81798-2-jonathan.cavitt@intel.com \
--to=jonathan.cavitt@intel.com \
--cc=alex.zuo@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.intel.com \
--cc=saurabhg.gupta@intel.com \
--cc=vinay.belgaumkar@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