public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Christoph Manszewski <christoph.manszewski@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Rudnicki@freedesktop.org, Piotr <piotr.rudnicki@intel.com>,
	Piatkowski@freedesktop.org,
	Dominik Karol <dominik.karol.piatkowski@intel.com>,
	Jan Sokolowski <jan.sokolowski@intel.com>,
	Christoph Manszewski <christoph.manszewski@intel.com>
Subject: [PATCH i-g-t v4 4/5] lib/xe/xe_eudebug: Track active debugger sessions and close when disabling
Date: Fri, 20 Feb 2026 16:37:53 +0100	[thread overview]
Message-ID: <20260220153748.210381-11-christoph.manszewski@intel.com> (raw)
In-Reply-To: <20260220153748.210381-7-christoph.manszewski@intel.com>

Active debugger sessions prevent disabling EU Debug via the sysfs
toggle. As a result when a test fails the igt_fixture will fail to
disable EU Debug if the worker threads have open debugger fds.

Introduce active debugger session (debugger fd) tracking and use it to
close leftover sessions before attempting to disable eudebug. The kernel
'struct drm_driver.postclose' handler which removes the debugger
sessions tracked by Xe EU Debug runs asynchronously to 'close' so retry
disabling in a loop on '-EBUSY'.

Signed-off-by: Dominik Karol Piątkowski <dominik.karol.piatkowski@intel.com>
Signed-off-by: Christoph Manszewski <christoph.manszewski@intel.com>
---
 lib/xe/xe_eudebug.c | 74 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

diff --git a/lib/xe/xe_eudebug.c b/lib/xe/xe_eudebug.c
index 7a641d2bd..a0caad2c3 100644
--- a/lib/xe/xe_eudebug.c
+++ b/lib/xe/xe_eudebug.c
@@ -18,6 +18,58 @@
 #include "xe_ioctl.h"
 #include "xe/xe_query.h"
 
+struct debugger_fd_entry {
+	int fd;
+	struct igt_list_head link;
+};
+
+static IGT_LIST_HEAD(active_debugger_fds);
+static pthread_mutex_t active_debugger_fds_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static void register_debugger_fd(int fd)
+{
+	struct debugger_fd_entry *entry;
+
+	pthread_mutex_lock(&active_debugger_fds_lock);
+
+	entry = calloc(1, sizeof(*entry));
+	igt_assert(entry);
+	entry->fd = fd;
+	IGT_INIT_LIST_HEAD(&entry->link);
+	igt_list_add(&entry->link, &active_debugger_fds);
+
+	pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
+static void unregister_debugger_fd(int fd)
+{
+	struct debugger_fd_entry *entry, *tmp;
+
+	pthread_mutex_lock(&active_debugger_fds_lock);
+	igt_list_for_each_entry_safe(entry, tmp, &active_debugger_fds, link) {
+		if (entry->fd == fd) {
+			igt_list_del(&entry->link);
+			free(entry);
+			break;
+		}
+	}
+	pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
+static void close_all_debugger_fds(void)
+{
+	struct debugger_fd_entry *entry, *tmp;
+
+	pthread_mutex_lock(&active_debugger_fds_lock);
+	igt_list_for_each_entry_safe(entry, tmp, &active_debugger_fds, link) {
+		igt_debug("closing leftover debugger fd %d\n", entry->fd);
+		close(entry->fd);
+		igt_list_del(&entry->link);
+		free(entry);
+	}
+	pthread_mutex_unlock(&active_debugger_fds_lock);
+}
+
 struct event_trigger {
 	xe_eudebug_trigger_fn fn;
 	int type;
@@ -1270,6 +1322,8 @@ static int __xe_eudebug_debugger_attach(struct xe_eudebug_debugger *d, pid_t pid
 	d->fd = ret;
 	d->target_pid = pid;
 
+	register_debugger_fd(d->fd);
+
 	return 0;
 }
 
@@ -1323,6 +1377,7 @@ int xe_eudebug_debugger_attach(struct xe_eudebug_debugger *d,
 void xe_eudebug_debugger_detach(struct xe_eudebug_debugger *d)
 {
 	igt_assert(d->target_pid);
+	unregister_debugger_fd(d->fd);
 	close(d->fd);
 	d->target_pid = 0;
 	d->fd = -1;
@@ -1909,7 +1964,24 @@ bool xe_eudebug_enable(int fd, bool enable)
 {
 	char sysfs_path[PATH_MAX];
 	bool old = false;
-	int ret = __xe_eudebug_enable_getset(fd, &old, &enable);
+	int ret = 0;
+
+	/* When disabling eudebug, close all active debugger sessions first. */
+	if (!enable)
+		close_all_debugger_fds();
+
+	/* 'struct drm_driver.postclose' runs asynchronously to 'close', wait for it to complete */
+	for (int i = 0; i < 10; ++i) {
+		ret = __xe_eudebug_enable_getset(fd, &old, &enable);
+
+		if (ret != -EBUSY)
+			break;
+
+		if (i < 9) {
+			igt_debug("xe_eudebug_enable: Failed (%d), retrying...\n", ret);
+			sleep(1);
+		}
+	}
 
 	if (ret == -ENOENT) {
 		igt_assert(igt_sysfs_path(fd, sysfs_path, sizeof(sysfs_path)));
-- 
2.47.1


  parent reply	other threads:[~2026-02-20 15:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20 15:37 [PATCH i-g-t v4 0/5] Improve eudebug test cleanup Christoph Manszewski
2026-02-20 15:37 ` [PATCH i-g-t v4 1/5] tests/xe/xe_eudebug: Change pthread_join to pthread_timedjoin_np Christoph Manszewski
2026-03-10 12:57   ` Rudnicki, Piotr
2026-02-20 15:37 ` [PATCH i-g-t v4 2/5] lib/xe/xe_eudebug: Modify toggle error handling Christoph Manszewski
2026-03-10 12:57   ` Rudnicki, Piotr
2026-02-20 15:37 ` [PATCH i-g-t v4 3/5] xe/xe_eudebug: Add reattach function and make plain connect private Christoph Manszewski
2026-03-10 12:58   ` Rudnicki, Piotr
2026-02-20 15:37 ` Christoph Manszewski [this message]
2026-03-10 11:17   ` [PATCH i-g-t v4 4/5] lib/xe/xe_eudebug: Track active debugger sessions and close when disabling Rudnicki, Piotr
2026-02-20 15:37 ` [PATCH i-g-t v4 5/5] lib/xe/xe_eudebug: Get drm card sysfs path Christoph Manszewski
2026-03-10 12:59   ` Rudnicki, Piotr
2026-02-20 20:43 ` ✓ Xe.CI.BAT: success for Improve eudebug test cleanup (rev4) Patchwork
2026-02-20 21:30 ` ✓ i915.CI.BAT: " Patchwork
2026-02-21  8:55 ` ✗ i915.CI.Full: failure " Patchwork
2026-02-23  9:58 ` ✗ 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=20260220153748.210381-11-christoph.manszewski@intel.com \
    --to=christoph.manszewski@intel.com \
    --cc=Piatkowski@freedesktop.org \
    --cc=Rudnicki@freedesktop.org \
    --cc=dominik.karol.piatkowski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jan.sokolowski@intel.com \
    --cc=piotr.rudnicki@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