Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org,
	"Dominik Karol Piątkowski" <dominik.karol.piatkowski@intel.com>,
	igt-dev@lists.freedesktop.org,
	"Isabella Basso" <isabbasso@riseup.net>,
	intel-xe@lists.freedesktop.org
Subject: Re: [Intel-xe] [Intel-gfx] [PATCH i-g-t v3 10/17] lib/ktap: Read /dev/kmsg in blocking mode
Date: Tue, 19 Sep 2023 08:23:47 +0200	[thread overview]
Message-ID: <20230919082347.5bbee759@maurocar-mobl2> (raw)
In-Reply-To: <20230918134249.31645-29-janusz.krzysztofik@linux.intel.com>

On Mon, 18 Sep 2023 15:43:00 +0200
Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com> wrote:

> 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>
> Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> # v1

LGTM.

Reviewed-by: Mauro Carvalho Chehab <mchehab@kernel.org>


> ---
>  lib/igt_kmod.c |  7 +++++-
>  lib/igt_ktap.c | 66 +++++++++++++++++---------------------------------
>  2 files changed, 28 insertions(+), 45 deletions(-)
> 
> diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
> index 7392276401..96240543a7 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));
> diff --git a/lib/igt_ktap.c b/lib/igt_ktap.c
> index 5bc5e003d7..282e44176e 100644
> --- a/lib/igt_ktap.c
> +++ b/lib/igt_ktap.c
> @@ -59,17 +59,12 @@ static int log_to_end(enum igt_log_level level, int fd,
>  	while (*lend == '\0') {
>  		igt_log(IGT_LOG_DOMAIN, level, "%s", record);
>  
> -		while (read(fd, record, BUF_LEN) < 0) {
> -			if (errno == EPIPE) {
> +		if (read(fd, record, BUF_LEN) < 0) {
> +			if (errno == EPIPE)
>  				igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n");
> -				return -2;
> -			}
> -
> -			if (errno == EAGAIN)
> -				/* No records available */
> -				continue;
> +			else
> +				igt_warn("an error occurred while reading kmsg: %m\n");
>  
> -			igt_warn("kmsg truncated: unknown error (%m)\n");
>  			return -2;
>  		}
>  
> @@ -173,17 +168,12 @@ static int find_next_tap_subtest(int fd, char *record, char *test_name, bool is_
>  		return -1;
>  
>  	if (is_builtin) {
> -		while (read(fd, record, BUF_LEN) < 0) {
> -			if (errno == EPIPE) {
> +		if (read(fd, record, BUF_LEN) < 0) {
> +			if (errno == EPIPE)
>  				igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n");
> -				return -2;
> -			}
> +			else
> +				igt_warn("an error occurred while reading kmsg: %m\n");
>  
> -			if (errno == EAGAIN)
> -				/* No records available */
> -				continue;
> -
> -			igt_warn("kmsg truncated: unknown error (%m)\n");
>  			return -2;
>  		}
>  	}
> @@ -209,17 +199,12 @@ static int find_next_tap_subtest(int fd, char *record, char *test_name, bool is_
>  		if (cutoff)
>  			cutoff[0] = '\0';
>  
> -		while (read(fd, record, BUF_LEN) < 0) {
> -			if (errno == EPIPE) {
> +		if (read(fd, record, BUF_LEN) < 0) {
> +			if (errno == EPIPE)
>  				igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n");
> -				return -2;
> -			}
> -
> -			if (errno == EAGAIN)
> -				/* No records available */
> -				continue;
> +			else
> +				igt_warn("unknown error reading kmsg (%m)\n");
>  
> -			igt_warn("kmsg truncated: unknown error (%m)\n");
>  			return -2;
>  		}
>  
> @@ -356,17 +341,12 @@ static int parse_tap_level(int fd, char *base_test_name, int test_count, bool *f
>  	char base_test_name_for_next_level[BUF_LEN + 1];
>  
>  	for (int i = 0; i < test_count; i++) {
> -		while (read(fd, record, BUF_LEN) < 0) {
> -			if (errno == EAGAIN)
> -				/* No records available */
> -				continue;
> -
> -			if (errno == EPIPE) {
> +		if (read(fd, record, BUF_LEN) < 0) {
> +			if (errno == EPIPE)
>  				igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n");
> -				return -1;
> -			}
> +			else
> +				igt_warn("error reading kmsg (%m)\n");
>  
> -			igt_warn("kmsg truncated: unknown error (%m)\n");
>  			return -1;
>  		}
>  
> @@ -494,15 +474,13 @@ igt_ktap_parser_start:
>  	test_name[0] = '\0';
>  	test_name[BUF_LEN] = '\0';
>  
> -	while (read(fd, record, BUF_LEN) < 0) {
> -		if (errno == EAGAIN)
> -			/* No records available */
> -			continue;
> -
> -		if (errno == EPIPE) {
> +	if (read(fd, record, BUF_LEN) < 0) {
> +		if (errno == EPIPE)
>  			igt_warn("kmsg truncated: too many messages. You may want to increase log_buf_len in kmcdline\n");
> -			goto igt_ktap_parser_end;
> -		}
> +		else
> +			igt_warn("error reading kmsg (%m)\n");
> +
> +		goto igt_ktap_parser_end;
>  	}
>  
>  	test_count = find_next_tap_subtest(fd, record, test_name, is_builtin);

  reply	other threads:[~2023-09-19  6:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 13:42 [Intel-xe] [PATCH i-g-t v3 00/17] Fix IGT Kunit implementation issues Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 01/17] lib/kunit: Drop unused file stream Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 02/17] lib/kunit: Stop loading kunit module explicitly Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 03/17] lib/kunit: Fix struct kmod_module kunit_kmod not freed Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 04/17] lib/kunit: Optimize calls to igt_success/skip/fail() Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 05/17] lib/kunit: Fix illegal igt_fail() calls inside subtest body Janusz Krzysztofik
2023-09-19  6:25   ` [Intel-xe] [Intel-gfx] " Mauro Carvalho Chehab
2023-09-19  6:26     ` Mauro Carvalho Chehab
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 06/17] lib/ktap: Make sure we fail on premature cancel Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 07/17] lib/ktap: Drop checks for EINTR on read() failures Janusz Krzysztofik
2023-09-19  6:30   ` [Intel-xe] [Intel-gfx] " Mauro Carvalho Chehab
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 08/17] lib/kunit: Cancel KTP parser on module load failure Janusz Krzysztofik
2023-09-18 13:42 ` [Intel-xe] [PATCH i-g-t v3 09/17] lib/ktap: Drop is_running flag Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 10/17] lib/ktap: Read /dev/kmsg in blocking mode Janusz Krzysztofik
2023-09-19  6:23   ` Mauro Carvalho Chehab [this message]
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 11/17] lib/kunit: Fail / skip on kernel taint Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 12/17] lib/ktap: Use IGT linked lists for storing KTAP results Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 13/17] lib/ktap: Reimplement KTAP parser Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 14/17] lib/kunit: Load test modules in background Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 15/17] lib/kunit: Parse KTAP report from the main process thread Janusz Krzysztofik
2023-09-20 18:05   ` [Intel-xe] [Intel-gfx] " Mauro Carvalho Chehab
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 16/17] lib/kunit: Strip "_test" or "_kunit" suffix from subtest names Janusz Krzysztofik
2023-09-18 13:43 ` [Intel-xe] [PATCH i-g-t v3 17/17] lib/kunit: Omit suite name prefix if the same as subtest name Janusz Krzysztofik
2023-09-19  6:36   ` [Intel-xe] [Intel-gfx] " Mauro Carvalho Chehab
2023-09-18 14:20 ` [Intel-xe] ✗ CI.Patch_applied: failure for Fix IGT Kunit implementation issues (rev3) Patchwork

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=20230919082347.5bbee759@maurocar-mobl2 \
    --to=mauro.chehab@linux.intel.com \
    --cc=dominik.karol.piatkowski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=isabbasso@riseup.net \
    --cc=janusz.krzysztofik@linux.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