summaryrefslogtreecommitdiff
path: root/lib/igt_kmod.c
diff options
context:
space:
mode:
authorJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>2023-09-01 12:14:19 +0200
committerJanusz Krzysztofik <janusz.krzysztofik@linux.intel.com>2023-09-19 10:35:47 +0200
commit94dbcc8bd1815d7840b82b1b85eadd45ed6927fa (patch)
treea0929a9d011f6b56106ddf61d8c49f941430dfb3 /lib/igt_kmod.c
parent700fd82e7b15fb39802677cc403fa5ec7e4bd0a3 (diff)
lib/ktap: Read /dev/kmsg in blocking mode
We obtain KTAP report from /dev/kmsg. That file is now opened from igt_ktest_begin(), a function originally designed for i915 selftests and now reused with kunit tests. The original intention of opening that file was to dump kernel messages to stderr on selftest error. For that purpose, the file is now opened in non-blocking mode so we don't end up waiting for more kernel messages than already available. Since our ktap parser code reuses the file descriptor, we now have to loop over EAGAIN responses, waiting for more KTAP data. Since we have no sleeps inside those loops, extremely high CPU usage can be observed. Simplify reading KTAP reports by first switching the file descriptor back to blocking mode. While being at it, fix read errors other than EPIPE likely unintentionally ignored when reading first line of KTAP data. v2: Drop EINTR handling as not applicable since SIGINT default signal handler kills the whole process anyway, - update commit description to also mention read error handling fix. Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>
Diffstat (limited to 'lib/igt_kmod.c')
-rw-r--r--lib/igt_kmod.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index 739227640..96240543a 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -24,6 +24,7 @@
#include <ctype.h>
#include <signal.h>
#include <errno.h>
+#include <fcntl.h>
#include <sys/utsname.h>
#include "igt_aux.h"
@@ -758,12 +759,16 @@ static void __igt_kunit(struct igt_ktest *tst, const char *opts)
{
struct kmod_module *kunit_kmod;
bool is_builtin;
- int ret;
struct ktap_test_results *results;
struct ktap_test_results_element *temp;
+ int flags, ret;
igt_skip_on_f(tst->kmsg < 0, "Could not open /dev/kmsg\n");
+ flags = fcntl(tst->kmsg, F_GETFL, 0) & ~O_NONBLOCK;
+ igt_skip_on_f(fcntl(tst->kmsg, F_SETFL, flags) == -1,
+ "Could not set /dev/kmsg to blocking mode\n");
+
igt_skip_on(lseek(tst->kmsg, 0, SEEK_END) < 0);
igt_skip_on(kmod_module_new_from_name(kmod_ctx(), "kunit", &kunit_kmod));