igt-dev.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Sobin Thomas <sobin.thomas@intel.com>
To: igt-dev@lists.freedesktop.org, zbigniew.kempczynski@intel.com
Cc: Sobin Thomas <sobin.thomas@intel.com>
Subject: [PATCH i-g-t 1/1] feat: Enable/Disable DRM debug logging between tests in shard mode
Date: Mon, 15 Dec 2025 10:33:05 +0000	[thread overview]
Message-ID: <20251215103305.445335-2-sobin.thomas@intel.com> (raw)
In-Reply-To: <20251215103305.445335-1-sobin.thomas@intel.com>

In shard mode, when disk usage limit is exceeded during a test, DRM
debug logging is disabled by writing "0" to /sys/module/drm/parameters/debug
to prevent premature exit. However, this disabled state persisted across
subsequent tests in the same shard, causing loss of debug information for
tests that did not exceed the disk limit.

Add a global flag to track when DRM debug was disabled in a previous test.
At the start of each new test in monitor_output(), check this flag and
restore DRM debug logging to the original value (or default "14" if the
original value could not be saved). Verify the write succeeded by reading
back the value, retrying up to 10 times with 100ms delays if needed.

The original DRM debug value is saved once at startup in execute() before
any tests run, ensuring we can restore to the correct state. The per-test
logging_disabled flag remains local to monitor_output() to track state
within the current test execution.

This ensures each test starts with a clean state and proper debug logging,
while still allowing dynamic disabling when disk limits are exceeded.

Signed-off-by: Sobin Thomas <sobin.thomas@intel.com>
---
 runner/executor.c | 148 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 147 insertions(+), 1 deletion(-)

diff --git a/runner/executor.c b/runner/executor.c
index 847abe481..8b1bb4d33 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -45,12 +45,15 @@
 #define KMSG_HEADER "[IGT] "
 #define KMSG_WARN 4
 #define GRACEFUL_EXITCODE -SIGHUP
-
+#define DRM_DEBUG_DEFAULT "14"
+#define DRM_DEBUG_DISABLE "0x0"
 static struct {
 	int *fds;
 	size_t num_dogs;
 } watchdogs;
 
+static bool global_logging_disabled;
+
 static void runner_gettime(struct timespec *tv)
 {
 	if (clock_gettime(CLOCK_BOOTTIME, tv))
@@ -948,6 +951,111 @@ static size_t calc_last_dmesg_chunk(size_t limit, size_t disk_usage)
 	return dt != 0 ? dt : -1;
 }
 
+static char original_drm_debug[16] = {0};
+static bool drm_debug_saved;
+
+static void restore_drm_debug(void)
+{
+	int fd;
+	static const char default_debug[] = "14";
+	const char *value_to_write;
+	char readback[16];
+	ssize_t cnt;
+	int retries = 10;
+	bool success = false;
+
+	// Use saved value if available, otherwise use default "14"
+	value_to_write = drm_debug_saved ? original_drm_debug : DRM_DEBUG_DEFAULT;
+	outf("Restoring DRM Debug to %s", value_to_write);
+	while (retries-- > 0 && !success) {
+		outf("Restoring DRM Debug");
+		/* Write the value */
+		fd = open("/sys/module/drm/parameters/debug", O_WRONLY);
+		if (fd >= 0) {
+			write(fd, default_debug, sizeof(default_debug) - 1);
+			close(fd);
+		} else {
+			errf("Failed to open /sys/module/drm/parameters/debug"
+			     "for writing: %m\n");
+			break;
+		}
+
+	/* Read it back to verify */
+	fd = open("/sys/module/drm/parameters/debug", O_RDONLY);
+	if (fd >= 0) {
+		cnt = read(fd, readback, sizeof(readback) - 1);
+		if (cnt > 0) {
+			readback[cnt] = '\0';
+			/* Remove trailing newline if present */
+			if (cnt > 0 && readback[cnt - 1] == '\n')
+				readback[cnt - 1] = '\0';
+
+			/* Check if it matches what we wrote */
+			if (strcmp(readback, DRM_DEBUG_DEFAULT) == 0) {
+				outf("Write Success");
+				success = true;
+				if (settings->log_level >= LOG_LEVEL_NORMAL) {
+					errf("[RUNNER] Successfully restored "
+					     "DRM debug to %s\n", readback);
+				}
+			} else {
+				errf("[RUNNER] DRM debug readback mismatch:"
+				     "wrote 14, read %s (retry %d)\n",
+					readback, 10 - retries);
+				usleep(100000); /* Wait 100ms before retry */
+			}
+		}
+		close(fd);
+	} else {
+		errf("Failed to open /sys/module/drm/parameters/debug for reading: %m\n");
+		break;
+	}
+	}
+
+	if (!success)
+		errf("[RUNNER] Failed to restore DRM debug to default "
+		     "after 10 retries\n");
+}
+
+static void disable_drm_debug(void)
+{
+	int fd;
+	static const char zero[] = "0x0";
+	const char *msg = "[RUNNER] logging disabled due to disk usage limit\n";
+	int cnt = 0;
+	// Save the current value before disabling
+	if (!drm_debug_saved) {
+		fd = open("/sys/module/drm/parameters/debug", O_RDONLY);
+	if (fd >= 0) {
+		cnt = read(fd, original_drm_debug, sizeof(original_drm_debug) - 1);
+		if (cnt > 0) {
+			original_drm_debug[cnt] = '\0';
+			// Remove trailing newline if present
+			if (cnt > 0 && original_drm_debug[cnt - 1] == '\n')
+				original_drm_debug[cnt - 1] = '\0';
+			drm_debug_saved = true;
+		}
+		close(fd);
+		}
+	}
+
+	fd = open("/sys/module/drm/parameters/debug", O_WRONLY);
+	if (fd >= 0) {
+		write(fd, zero, sizeof(zero) - 1);
+		close(fd);
+		fprintf(stdout, "%s", msg);
+		fprintf(stderr, "%s", msg);
+
+		fflush(stdout);
+		fflush(stderr);
+
+		/* Log to kernel that we disabled debug */
+		kmsg_log(4, "igt_runner: Disabled DRM debug due to disk usage limit\n");
+	}
+	global_logging_disabled = true;
+}
+
+
 /*
  * Returns:
  *  =0 - Success
@@ -984,10 +1092,20 @@ static int monitor_output(pid_t child,
 	long dmesgwritten;
 	bool socket_comms_used = false; /* whether the test actually uses comms */
 	bool results_received = false; /* whether we already have test results that might need overriding if we detect an abort condition */
+	bool logging_disabled = false;
 
 	runner_gettime(&time_beg);
 	time_last_activity = time_last_subtest = time_killed = time_beg;
 
+	/* Restore DRM debug at the start of each test if it was disabled earlier */
+	if (global_logging_disabled) {
+		restore_drm_debug();
+		global_logging_disabled = false;
+
+		if (settings->log_level >= LOG_LEVEL_NORMAL)
+			outf("[RUNNER] Restored DRM debug logging for new test\n");
+	}
+
 	if (errfd > nfds)
 		nfds = errfd;
 	if (socketfd > nfds)
@@ -1321,6 +1439,34 @@ static int monitor_output(pid_t child,
 			}
 		}
 
+		/* Check if we need to disable logging due to disk usage limit */
+
+		if (!logging_disabled && disk_usage_limit_exceeded(settings, disk_usage)) {
+			char msg[256];
+
+			logging_disabled = true;
+
+			/* Disable DRM debug to reduce dmesg spam */
+			disable_drm_debug();
+
+			/* Write warning message to output files */
+			snprintf(msg, sizeof(msg),
+				"\n[RUNNER] Disk usage limit reached (%zu/%zu bytes). "
+				"Disabling further logging and DRM debug. Test continues.\n ",
+				disk_usage, settings->disk_usage_limit);
+
+			write(outputs[_F_OUT], msg, strlen(msg));
+			write(outputs[_F_ERR], msg, strlen(msg));
+
+			if (settings->log_level >= LOG_LEVEL_NORMAL)
+				fprintf(stderr, "%s", msg);
+
+			if (settings->sync) {
+				fdatasync(outputs[_F_OUT]);
+				fdatasync(outputs[_F_ERR]);
+			}
+		}
+
 		if (sigfd >= 0 && FD_ISSET(sigfd, &set)) {
 			double time;
 
-- 
2.51.0


  reply	other threads:[~2025-12-15 10:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 10:33 [PATCH i-g-t 0/1] Enable/Disable DRM debug logging between tests in shard mode Sobin Thomas
2025-12-15 10:33 ` Sobin Thomas [this message]
2025-12-15 13:02   ` [PATCH i-g-t 1/1] feat: " Jani Nikula
2025-12-16  9:15   ` Zbigniew Kempczyński

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=20251215103305.445335-2-sobin.thomas@intel.com \
    --to=sobin.thomas@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=zbigniew.kempczynski@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;
as well as URLs for NNTP newsgroup(s).