Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib/igt_sysfs: Implement dynamic adjustment of debug log level
@ 2024-07-04  9:42 Pranay Samala
  2024-07-04 17:44 ` ✓ CI.xeBAT: success for " Patchwork
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pranay Samala @ 2024-07-04  9:42 UTC (permalink / raw)
  To: igt-dev; +Cc: kunal1.joshi, sameer.lattannavar, pranay.samala

Adjust debug log levels dynamically to prevent machine
disk overflow during excessive test debug logs.

Introduce function to modify log levels as needed,
with an exit handler restoring default settings post-test.

Signed-off-by: Pranay Samala <pranay.samala@intel.com>
---
 lib/igt_sysfs.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_sysfs.h |  3 +++
 2 files changed, 48 insertions(+)

diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index ffeec1ca2..c256f0ae7 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -412,6 +412,51 @@ int igt_sysfs_get_num_gt(int device)
 	return num_gts;
 }
 
+void igt_debug_reset(int drm_fd)
+{
+	int fd = igt_sysfs_open(drm_fd);
+
+	if (fd < 0)
+		return;
+	const char *buf = "14";
+
+	const char *path = "/sys/module/drm/parameters/debug";
+	int debug_dir = openat(fd, path, O_WRONLY);
+
+	igt_debug("Resetting Debug value\n");
+	igt_assert_eq(write(debug_dir, buf, strlen(buf)), strlen(buf));
+	close(fd);
+}
+
+static void igt_debug_exit_handler(int sig)
+{
+	int fd = drm_open_driver(DRIVER_INTEL | DRIVER_XE);
+
+	/* Here we assume that only one i915 device will be ever present */
+	igt_debug_reset(fd);
+	close(fd);
+}
+
+void igt_set_debug_value(int drm_fd, unsigned int value)
+{
+	char buf[16];
+	int fd = igt_sysfs_open(drm_fd);
+
+	if (fd < 0)
+		return;
+
+	const char *path = "/sys/module/drm/parameters/debug";
+	int debug_dir = openat(fd, path, O_WRONLY);
+
+	igt_debug("Setting Debug value to %d\n", value);
+	snprintf(buf, sizeof(buf), "%d", value);
+	igt_assert_eq(write(debug_dir, buf, strlen(buf)), strlen(buf));
+
+	close(fd);
+	close(debug_dir);
+	igt_install_exit_handler(igt_debug_exit_handler);
+}
+
 /**
  * igt_sysfs_write:
  * @dir: sysfs directory
diff --git a/lib/igt_sysfs.h b/lib/igt_sysfs.h
index 6c604d939..abc9c1739 100644
--- a/lib/igt_sysfs.h
+++ b/lib/igt_sysfs.h
@@ -138,6 +138,9 @@ void igt_sysfs_set_boolean(int dir, const char *attr, bool value);
 void bind_fbcon(bool enable);
 void fbcon_blink_enable(bool enable);
 
+void igt_set_debug_value(int dir, unsigned int value);
+void igt_debug_reset(int dir);
+
 /**
  * igt_sysfs_rw_attr:
  * @dir: file descriptor for parent directory
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-07-05  7:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-04  9:42 [PATCH i-g-t] lib/igt_sysfs: Implement dynamic adjustment of debug log level Pranay Samala
2024-07-04 17:44 ` ✓ CI.xeBAT: success for " Patchwork
2024-07-04 17:55 ` ✓ Fi.CI.BAT: " Patchwork
2024-07-04 23:02 ` ✓ CI.xeFULL: " Patchwork
2024-07-05  7:44 ` ✓ Fi.CI.IGT: " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox