From: Kamil Konieczny <kamil.konieczny@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>,
Petri Latvala <adrinael@adrinael.net>,
Karol Krol <karol.krol@intel.com>,
Ewelina Musial <ewelina.musial@intel.com>
Subject: [PATCH i-g-t v2 2/4] runner/executor: Limit reading dmesg to chunks
Date: Wed, 20 Nov 2024 19:32:06 +0100 [thread overview]
Message-ID: <20241120183208.146299-3-kamil.konieczny@linux.intel.com> (raw)
In-Reply-To: <20241120183208.146299-1-kamil.konieczny@linux.intel.com>
There was no disk limit checks in reading kernel dmesg and that
could lead to writing really huge dumps longer than 400MB,
greatly exceeding disk limits used by CI and hardly useful for
developers. Make a dmesg dumping in chunks, size depending on
number of CPUs present, with a minimum of 64KB.
This could also allow to kick in disk limits checks if a driver
starts spilling messages into dmesg.
v2: correct size at last dump, also inform user about exceeding
limits (Kamil)
Closes: https://gitlab.freedesktop.org/drm/igt-gpu-tools/-/issues/129
Cc: Petri Latvala <adrinael@adrinael.net>
Cc: Karol Krol <karol.krol@intel.com>
Cc: Ewelina Musial <ewelina.musial@intel.com>
Signed-off-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
runner/executor.c | 64 ++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 55 insertions(+), 9 deletions(-)
diff --git a/runner/executor.c b/runner/executor.c
index e4d1fc323..a5b5c0eab 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -585,13 +585,14 @@ void close_outputs(int *fds)
}
/* Returns the number of bytes written to disk, or a negative number on error */
-static long dump_dmesg(int kmsgfd, int outfd)
+static long dump_dmesg(int kmsgfd, int outfd, ssize_t size)
{
/*
* Write kernel messages to the log file until we reach
- * 'now'. Unfortunately, /dev/kmsg doesn't support seeking to
- * -1 from SEEK_END so we need to use a second fd to read a
- * message to match against, or stop when we reach EAGAIN.
+ * 'now' or we read at least size bytes. Unfortunately,
+ * /dev/kmsg doesn't support seeking to -1 from SEEK_END
+ * so we need to use a second fd to read a message to
+ * match against, or stop when we reach EAGAIN.
*/
int comparefd;
@@ -606,6 +607,9 @@ static long dump_dmesg(int kmsgfd, int outfd)
if (kmsgfd < 0)
return 0;
+ if (size < 0)
+ return 0;
+
comparefd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
if (comparefd < 0) {
errf("Error opening another fd for /dev/kmsg\n");
@@ -690,6 +694,13 @@ static long dump_dmesg(int kmsgfd, int outfd)
if (seq >= cmpseq)
return written;
}
+
+ if (size && written >= size) {
+ if (comparefd >= 0)
+ close(comparefd);
+
+ return written;
+ }
}
}
@@ -883,6 +894,25 @@ static void write_packet_with_canary(int fd, struct runnerpacket *packet, bool s
/* TODO: Refactor this macro from here and from various tests to lib */
#define KB(x) ((x) * 1024)
+#if !defined(SIZE_MAX)
+#define SIZE_MAX (((size_t)-1) ^ (1 << (8 * sizeof(size_t) - 1)))
+#endif
+
+/* Calculates disk limit to use when dumping dmesg, returns:
+ * number > 0 : size of limit to use
+ * number < 0 : negative number when limit exceeded, no more dumping
+ **/
+static size_t calc_last_dmesg_chunk(size_t limit, size_t disk_usage)
+{
+ size_t dt = limit - disk_usage;
+
+ assert(SIZE_MAX > 0);
+ if (!limit)
+ return SIZE_MAX; /* no limit */
+
+ return dt != 0 ? dt : -1;
+}
+
/*
* Returns:
* =0 - Success
@@ -915,6 +945,8 @@ static int monitor_output(pid_t child,
unsigned long taints = 0;
bool aborting = false;
size_t disk_usage = 0;
+ size_t dmsg_chunk_size = 4096 * max_t(size_t, sysconf(_SC_NPROCESSORS_ONLN), 16);
+ 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 */
@@ -1240,11 +1272,9 @@ static int monitor_output(pid_t child,
socket_end:
if (kmsgfd >= 0 && FD_ISSET(kmsgfd, &set)) {
- long dmesgwritten;
-
time_last_activity = time_now;
- dmesgwritten = dump_dmesg(kmsgfd, outputs[_F_DMESG]);
+ dmesgwritten = dump_dmesg(kmsgfd, outputs[_F_DMESG], dmsg_chunk_size);
if (settings->sync)
fdatasync(outputs[_F_DMESG]);
@@ -1482,7 +1512,8 @@ static int monitor_output(pid_t child,
asprintf(abortreason, "Child refuses to die, tainted 0x%lx.", taints);
}
- dump_dmesg(kmsgfd, outputs[_F_DMESG]);
+ dmsg_chunk_size = calc_last_dmesg_chunk(settings->disk_usage_limit, disk_usage);
+ dump_dmesg(kmsgfd, outputs[_F_DMESG], dmsg_chunk_size);
if (settings->sync)
fdatasync(outputs[_F_DMESG]);
@@ -1508,9 +1539,24 @@ static int monitor_output(pid_t child,
}
}
- dump_dmesg(kmsgfd, outputs[_F_DMESG]);
+ dmsg_chunk_size = calc_last_dmesg_chunk(settings->disk_usage_limit, disk_usage);
+ dmesgwritten = dump_dmesg(kmsgfd, outputs[_F_DMESG], dmsg_chunk_size);
if (settings->sync)
fdatasync(outputs[_F_DMESG]);
+ if (dmesgwritten > 0) {
+ disk_usage += dmesgwritten;
+ if (settings->disk_usage_limit && disk_usage > settings->disk_usage_limit) {
+ char disk[1024];
+
+ snprintf(disk, sizeof(disk), "igt_runner: disk limit exceeded at dmesg dump, %ld > %ld\n", disk_usage, settings->disk_usage_limit);
+ if (settings->log_level >= LOG_LEVEL_NORMAL) {
+ outf("%s", disk);
+ fflush(stdout);
+ } else if (killed) {
+ errf("%s", disk);
+ }
+ }
+ }
free(buf);
free(outbuf);
--
2.47.0
next prev parent reply other threads:[~2024-11-20 18:32 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-20 18:32 [PATCH i-g-t v2 0/4] runner: Allow limits at dumping dmesg Kamil Konieczny
2024-11-20 18:32 ` [PATCH i-g-t v2 1/4] runner/executor: Check for error at writing dmesg dump Kamil Konieczny
2024-11-27 6:09 ` Peter Senna Tschudin
2024-11-27 15:05 ` [i-g-t,v2,1/4] " Ryszard Knop
2024-11-29 19:31 ` [i-g-t, v2, 1/4] " Kamil Konieczny
2024-11-20 18:32 ` Kamil Konieczny [this message]
2024-11-27 15:12 ` [i-g-t,v2,2/4] runner/executor: Limit reading dmesg to chunks Ryszard Knop
2024-11-29 19:24 ` Kamil Konieczny
2024-11-20 18:32 ` [PATCH i-g-t v2 3/4] runner/executor: Fix error handling at terminating test Kamil Konieczny
2024-11-27 14:32 ` [i-g-t,v2,3/4] " Ryszard Knop
2024-11-20 18:32 ` [PATCH i-g-t v2 4/4] runner/executor: Inform about terminating Kamil Konieczny
2024-11-27 14:32 ` [i-g-t,v2,4/4] " Ryszard Knop
2024-11-20 19:52 ` ✓ Fi.CI.BAT: success for runner: Allow limits at dumping dmesg (rev2) Patchwork
2024-11-21 4:39 ` ✗ Xe.CI.Full: failure " Patchwork
2024-11-23 23:06 ` ✗ i915.CI.Full: " Patchwork
2024-11-26 11:54 ` [PATCH i-g-t v2 0/4] runner: Allow limits at dumping dmesg Sokolowski, Jan
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=20241120183208.146299-3-kamil.konieczny@linux.intel.com \
--to=kamil.konieczny@linux.intel.com \
--cc=adrinael@adrinael.net \
--cc=ewelina.musial@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=karol.krol@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