From: Francois Dugast <francois.dugast@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Francois Dugast <francois.dugast@intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: [PATCH i-g-t,v4 1/2] lib/igt_sysfs: Promote driver rebind function
Date: Mon, 30 Sep 2024 16:08:23 +0200 [thread overview]
Message-ID: <20240930141248.810483-2-francois.dugast@intel.com> (raw)
In-Reply-To: <20240930141248.810483-1-francois.dugast@intel.com>
Move the rebind function to the library so that it can be used in other
tests without code duplication. Also extend it to support simple bind
and unbind.
Signed-off-by: Francois Dugast <francois.dugast@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
---
lib/igt_sysfs.c | 54 +++++++++++++++++++++++++++++++++++++++++
lib/igt_sysfs.h | 9 +++++++
tests/intel/xe_wedged.c | 36 ++++-----------------------
3 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index aec0bb53d..f8e634f8f 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -1360,3 +1360,57 @@ int xe_sysfs_get_num_tiles(int xe_device)
return num_tiles;
}
+
+/**
+ * xe_sysfs_driver_do:
+ * @xe_device: fd of the device
+ * @pci_slot: PCI slot of the device
+ * @action: the action to perform through sysfs on the driver
+ *
+ * Use sysfs to perform an action on the driver.
+ *
+ * Returns: fd of the device, which renewed if needed
+ */
+int xe_sysfs_driver_do(int xe_device, char pci_slot[], enum xe_sysfs_driver_action action)
+{
+ int sysfs;
+
+ sysfs = open("/sys/bus/pci/drivers/xe", O_DIRECTORY);
+ igt_assert(sysfs);
+
+ switch(action) {
+ case XE_SYSFS_DRIVER_BIND:
+ igt_assert(igt_sysfs_set(sysfs, "bind", pci_slot));
+ close(sysfs);
+ break;
+ case XE_SYSFS_DRIVER_TRY_BIND:
+ igt_sysfs_set(sysfs, "bind", pci_slot);
+ close(sysfs);
+ break;
+ case XE_SYSFS_DRIVER_UNBIND:
+ igt_assert(igt_sysfs_set(sysfs, "unbind", pci_slot));
+ close(sysfs);
+ break;
+ case XE_SYSFS_DRIVER_REBIND:
+ igt_assert(igt_sysfs_set(sysfs, "unbind", pci_slot));
+
+ /*
+ * We need to close the client for a proper release, before
+ * binding back again.
+ */
+ close(xe_device);
+
+ igt_assert(igt_sysfs_set(sysfs, "bind", pci_slot));
+ close(sysfs);
+
+ /* Renew the client connection */
+ xe_device = drm_open_driver(DRIVER_XE);
+ igt_assert(xe_device);
+
+ break;
+ default:
+ igt_assert(!"missing");
+ }
+
+ return xe_device;
+}
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 2a1e3b1bf..0ee253826 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -175,4 +175,13 @@ int xe_sysfs_get_num_tiles(int xe_device);
char *xe_sysfs_engine_path(int xe_device, int gt, int class, char *path, int pathlen);
int xe_sysfs_engine_open(int xe_device, int gt, int class);
+enum xe_sysfs_driver_action {
+ XE_SYSFS_DRIVER_BIND,
+ XE_SYSFS_DRIVER_TRY_BIND,
+ XE_SYSFS_DRIVER_UNBIND,
+ XE_SYSFS_DRIVER_REBIND,
+};
+
+int xe_sysfs_driver_do(int xe_device, char pci_slot[], enum xe_sysfs_driver_action action);
+
#endif /* __IGT_SYSFS_H__ */
diff --git a/tests/intel/xe_wedged.c b/tests/intel/xe_wedged.c
index a3f7a697f..ba790aa8d 100644
--- a/tests/intel/xe_wedged.c
+++ b/tests/intel/xe_wedged.c
@@ -41,34 +41,6 @@ static void force_wedged(int fd)
sleep(1);
}
-static int rebind_xe(int fd)
-{
- char pci_slot[NAME_MAX];
- int sysfs;
-
- igt_device_get_pci_slot_name(fd, pci_slot);
-
- sysfs = open("/sys/bus/pci/drivers/xe", O_DIRECTORY);
- igt_assert(sysfs);
-
- igt_assert(igt_sysfs_set(sysfs, "unbind", pci_slot));
-
- /*
- * We need to close the client for a proper release, before
- * binding back again.
- */
- close(fd);
-
- igt_assert(igt_sysfs_set(sysfs, "bind", pci_slot));
- close(sysfs);
-
- /* Renew the client connection */
- fd = drm_open_driver(DRIVER_XE);
- igt_assert(fd);
-
- return fd;
-}
-
static int simple_ioctl(int fd)
{
int ret;
@@ -231,9 +203,11 @@ igt_main
{
struct drm_xe_engine_class_instance *hwe;
int fd;
+ char pci_slot[NAME_MAX];
igt_fixture {
fd = drm_open_driver(DRIVER_XE);
+ igt_device_get_pci_slot_name(fd, pci_slot);
}
igt_subtest("basic-wedged") {
@@ -245,7 +219,7 @@ igt_main
force_wedged(fd);
igt_assert_neq(simple_ioctl(fd), 0);
- fd = rebind_xe(fd);
+ fd = xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_REBIND);
igt_assert_eq(simple_ioctl(fd), 0);
xe_for_each_engine(fd, hwe)
simple_exec(fd, hwe);
@@ -265,7 +239,7 @@ igt_main
*/
sleep(1);
igt_assert_neq(simple_ioctl(fd), 0);
- fd = rebind_xe(fd);
+ fd = xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_REBIND);
igt_assert_eq(simple_ioctl(fd), 0);
xe_for_each_engine(fd, hwe)
simple_exec(fd, hwe);
@@ -289,7 +263,7 @@ igt_main
}
/* Tests might have failed, force a rebind before exiting */
- fd = rebind_xe(fd);
+ fd = xe_sysfs_driver_do(fd, pci_slot, XE_SYSFS_DRIVER_REBIND);
drm_close_driver(fd);
}
--
2.43.0
next prev parent reply other threads:[~2024-09-30 14:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-30 14:08 [PATCH i-g-t,v4 0/2] Add test for fault injection Francois Dugast
2024-09-30 14:08 ` Francois Dugast [this message]
2024-09-30 14:08 ` [PATCH i-g-t, v4 2/2] tests/intel/xe_fault_injection: Add new " Francois Dugast
2024-09-30 15:12 ` Rodrigo Vivi
2024-09-30 20:23 ` ✓ CI.xeBAT: success for Add test for fault injection (rev2) Patchwork
2024-09-30 20:28 ` ✓ Fi.CI.BAT: " Patchwork
2024-10-01 4:01 ` ✗ CI.xeFULL: failure " Patchwork
2024-10-01 7:12 ` ✗ Fi.CI.IGT: " 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=20240930141248.810483-2-francois.dugast@intel.com \
--to=francois.dugast@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=rodrigo.vivi@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