[PATCH 10/66] lib/xe_eudebug: Add support for dynamic debugger sysfs toggle
Christoph Manszewski
christoph.manszewski at intel.com
Mon Jul 29 16:01:03 UTC 2024
The debugger now uses a dedicated sysfs entry:
/sys/class/drm/card<N>/device/enable_eudebug
to toggle the debugger on/off. This change adds helper functons for
toggling the debugger.
Signed-off-by: Mika Kuoppala <mika.kuoppala at intel.com>
Signed-off-by: Christoph Manszewski <christoph.manszewski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
---
lib/xe/xe_eudebug.c | 88 +++++++++++++++++++++++++++++++++++++++++++++
lib/xe/xe_eudebug.h | 3 ++
2 files changed, 91 insertions(+)
diff --git a/lib/xe/xe_eudebug.c b/lib/xe/xe_eudebug.c
index 7f99fabc5..18e0ac422 100644
--- a/lib/xe/xe_eudebug.c
+++ b/lib/xe/xe_eudebug.c
@@ -7,10 +7,12 @@
#include <poll.h>
#include <signal.h>
#include <sys/select.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "igt.h"
+#include "igt_sysfs.h"
#include "intel_pat.h"
#include "xe_eudebug.h"
#include "xe_ioctl.h"
@@ -1034,6 +1036,24 @@ static void *debugger_worker_loop(void *data)
return NULL;
}
+/**
+ * xe_eudebug_debugger_available:
+ * @fd: Xe file descriptor
+ *
+ * Returns: true it debugger connection is available, false otherwise.
+ */
+bool xe_eudebug_debugger_available(int fd)
+{
+ struct drm_xe_eudebug_connect param = { .pid = getpid() };
+ int debugfd;
+
+ debugfd = igt_ioctl(fd, DRM_IOCTL_XE_EUDEBUG_CONNECT, ¶m);
+ if (debugfd >= 0)
+ close(debugfd);
+
+ return debugfd >= 0;
+}
+
/**
* xe_eudebug_debugger_create:
* @master_fd: xe client used to open the debugger connection
@@ -1557,6 +1577,74 @@ static void metadata_event(struct xe_eudebug_client *c, uint32_t flags,
xe_eudebug_event_log_write(c->log, (void *)&em);
}
+static int enable_getset(int fd, bool *old, bool *new)
+{
+ static const char * const fname = "enable_eudebug";
+ int ret = 0;
+
+ int sysfs, device_fd;
+ bool val_before;
+ struct stat st;
+
+ igt_assert(new || old);
+
+ igt_assert_eq(fstat(fd, &st), 0);
+ sysfs = igt_sysfs_open(fd);
+ if (sysfs < 0)
+ return -1;
+
+ device_fd = openat(sysfs, "device", O_DIRECTORY | O_RDONLY);
+ close(sysfs);
+ if (device_fd < 0)
+ return -1;
+
+ if (!__igt_sysfs_get_boolean(device_fd, fname, &val_before)) {
+ ret = -1;
+ goto out;
+ }
+
+ igt_debug("enable_eudebug before: %d\n", val_before);
+
+ if (old)
+ *old = val_before;
+
+ ret = 0;
+ if (new) {
+ if (__igt_sysfs_set_boolean(device_fd, fname, *new))
+ igt_assert_eq(igt_sysfs_get_boolean(device_fd, fname), *new);
+ else
+ ret = -1;
+ }
+
+out:
+ close(device_fd);
+ return ret;
+}
+
+/**
+ * xe_eudebug_enable
+ * @fd: xe client
+ * @enable: state toggle - true to enable, false to disable
+ *
+ * Enables/disables eudebug capability by writing to
+ * '/sys/class/drm/card<N>/device/enable_eudebug' sysfs entry.
+ *
+ * Returns: previous toggle value, i.e. true when eudebugging was enabled,
+ * false when eudebugging was disabled.
+ */
+bool xe_eudebug_enable(int fd, bool enable)
+{
+ bool old = false;
+ int ret = enable_getset(fd, &old, &enable);
+
+ if (ret) {
+ igt_skip_on(enable);
+ old = false;
+ }
+
+ return old;
+}
+
/* Eu debugger wrappers around resource creating xe ioctls. */
/**
diff --git a/lib/xe/xe_eudebug.h b/lib/xe/xe_eudebug.h
index ec75634f5..1343cb25c 100644
--- a/lib/xe/xe_eudebug.h
+++ b/lib/xe/xe_eudebug.h
@@ -123,6 +123,7 @@ void xe_eudebug_event_log_compare(struct xe_eudebug_event_log *c, struct xe_eude
void xe_eudebug_event_log_write(struct xe_eudebug_event_log *l, struct drm_xe_eudebug_event *e);
void xe_eudebug_event_log_match_opposite(struct xe_eudebug_event_log *l, uint32_t filter);
+bool xe_eudebug_debugger_available(int fd);
struct xe_eudebug_debugger *
xe_eudebug_debugger_create(int xe, uint64_t flags, void *data);
void xe_eudebug_debugger_destroy(struct xe_eudebug_debugger *d);
@@ -146,6 +147,8 @@ void xe_eudebug_client_wait_stage(struct xe_eudebug_client *c, uint64_t stage);
uint64_t xe_eudebug_client_get_seqno(struct xe_eudebug_client *c);
void xe_eudebug_client_set_data(struct xe_eudebug_client *c, void *ptr);
+bool xe_eudebug_enable(int fd, bool enable);
+
int xe_eudebug_client_open_driver(struct xe_eudebug_client *c);
void xe_eudebug_client_close_driver(struct xe_eudebug_client *c, int fd);
uint32_t xe_eudebug_client_vm_create(struct xe_eudebug_client *c, int fd,
--
2.34.1
More information about the igt-dev
mailing list