Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
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 v5 1/3] lib/igt_sysfs: Add igt_sysfs_get_next_engine
Date: Thu,  7 Nov 2024 22:52:52 +0000	[thread overview]
Message-ID: <20241107225254.302010-2-jonathan.cavitt@intel.com> (raw)
In-Reply-To: <20241107225254.302010-1-jonathan.cavitt@intel.com>

Create a new helper function, igt_sysfs_get_next_engine, that iterates
over sysfs/engines and stores the next engine for the user.  The
function returns true if the next engine in the list is available, and
false otherwise.  The function will be used in the test suite in a later
patch.

Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
---
 lib/igt_sysfs.c | 36 ++++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 26a3aa31fb..3d0dada969 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -1236,6 +1236,42 @@ static uint16_t xe_get_engine_class(char *name)
 	return class;
 }
 
+/**
+ * igt_sysfs_get_next_engine:
+ * @engines: fd of the directory engine
+ * @prior: previous engine from the sysfs/engines list
+ *
+ * Iterates over sysfs/engines and stores the next engine in prior.
+ * Returns true if there are more engines to iterate over, and false otherwise.
+ */
+bool igt_sysfs_get_next_engine(int engines, int *prior)
+{
+	struct dirent *de;
+	DIR *dir;
+
+	if (!prior)
+		lseek(engines, 0, SEEK_SET);
+	else
+		close(*prior);
+
+	dir = fdopendir(engines);
+	if (!dir) {
+		close(engines);
+		return false;
+	}
+
+	while ((de = readdir(dir))) {
+		if (*de->d_name == '.')
+			continue;
+
+		*prior = openat(engines, de->d_name, O_RDONLY);
+		if (*prior >= 0)
+			return true;
+	}
+	return false;
+}
+
+
 /**
  * igt_sysfs_engines:
  * @xe: fd of the device
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 852b95053f..bff5ed68e6 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -163,6 +163,7 @@ typedef struct igt_sysfs_rw_attr {
 
 void igt_sysfs_rw_attr_verify(igt_sysfs_rw_attr_t *rw);
 
+bool igt_sysfs_get_next_engine(int engines, int *prior);
 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


  reply	other threads:[~2024-11-07 22:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-07 22:52 [PATCH v5 0/3] test/intel/xe_sysfs: Restore sysfs params correctly Jonathan Cavitt
2024-11-07 22:52 ` Jonathan Cavitt [this message]
2024-11-15 14:36   ` [PATCH v5 1/3] lib/igt_sysfs: Add igt_sysfs_get_next_engine Kamil Konieczny
2024-11-15 16:23     ` Cavitt, Jonathan
2024-11-07 22:52 ` [PATCH v5 2/3] tests/intel/xe_sysfs*: Restore values on test failure Jonathan Cavitt
2024-11-07 22:52 ` [PATCH v5 3/3] tests/intel/xe_sysfs_timeslice_duration: Restore preempt timeout Jonathan Cavitt
2024-11-07 23:14 ` ✗ GitLab.Pipeline: warning for test/intel/xe_sysfs: Restore sysfs params correctly Patchwork
2024-11-07 23:40 ` ✓ CI.xeBAT: success " Patchwork
2024-11-08  0:03 ` ✓ Fi.CI.BAT: " Patchwork
2024-11-08  3:10 ` ✗ Fi.CI.IGT: failure " Patchwork
2024-11-09  6:11 ` ✗ CI.xeFULL: " 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=20241107225254.302010-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