diff mbox series

[i-g-t,v4,2/5] lib: Add more debug messages to error paths

Message ID 20240718085912.15434-9-janusz.krzysztofik@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series tests/gem_ctx_exec: Fix failing preempt timeout updates | expand

Commit Message

Janusz Krzysztofik July 18, 2024, 8:55 a.m. UTC
On an attempt to resolve the issue of mysteriously failing updates of
sysfs entries representing engine preempt timeout values, add debug
messages to error paths of involved library functions.

v2: No changes.
v3: Add still more debug messages.
v4: Fix missing line termination.

Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/6268
Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>
---
 lib/i915/gem_engine_topology.c | 19 +++++++++++--------
 lib/igt_sysfs.c                |  4 ++--
 2 files changed, 13 insertions(+), 10 deletions(-)

Comments

Kamil Konieczny July 18, 2024, 12:08 p.m. UTC | #1
Hi Janusz,
On 2024-07-18 at 10:55:13 +0200, Janusz Krzysztofik wrote:
> On an attempt to resolve the issue of mysteriously failing updates of
> sysfs entries representing engine preempt timeout values, add debug
> messages to error paths of involved library functions.
> 
> v2: No changes.
> v3: Add still more debug messages.
> v4: Fix missing line termination.
> 
> Link: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/6268
> Signed-off-by: Janusz Krzysztofik <janusz.krzysztofik@linux.intel.com>

Reviewed-by: Kamil Konieczny <kamil.konieczny@linux.intel.com>

> ---
>  lib/i915/gem_engine_topology.c | 19 +++++++++++--------
>  lib/igt_sysfs.c                |  4 ++--
>  2 files changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
> index afb576afb2..c878e95f08 100644
> --- a/lib/i915/gem_engine_topology.c
> +++ b/lib/i915/gem_engine_topology.c
> @@ -454,12 +454,12 @@ static int __open_primary(int dir)
>  	int len;
>  
>  	fd = openat(dir, "dev", O_RDONLY);
> -	if (fd < 0)
> +	if (igt_debug_on(fd < 0))
>  		return dir;
>  
>  	len = read(fd, buf, sizeof(buf) - 1);
>  	close(fd);
> -	if (len <= 0)
> +	if (igt_debug_on(len <= 0))
>  		return dir;
>  	buf[len] = '\0';
>  
> @@ -467,7 +467,7 @@ static int __open_primary(int dir)
>  	if (minor < 64)
>  		return dir;
>  
> -	if (readlinkat(dir, "device", target, sizeof(target)) < 0)
> +	if (igt_debug_on(readlinkat(dir, "device", target, sizeof(target)) < 0))
>  		return dir;
>  
>  	fd = openat(dir, "..", O_RDONLY);
> @@ -500,24 +500,27 @@ static FILE *__open_attr(int dir, const char *mode, ...)
>  	va_list ap;
>  
>  	/* The attributes are not to be found on render nodes */
> -	dir = __open_primary(dir);
> +	igt_debug_on((dir = __open_primary(dir)) < 0);
>  
>  	va_start(ap, mode);
>  	while (dir >= 0 && (path = va_arg(ap, const char *))) {
>  		int fd;
>  
> -		fd = openat(dir, path, O_RDONLY);
> +		igt_debug_on_f((fd = openat(dir, path, O_RDONLY)) < 0,
> +			       "failed component: %s\n", path);
>  		close(dir);
>  
>  		dir = fd;
>  	}
>  	va_end(ap);
> +	if (dir < 0)
> +		return NULL;
>  
>  	if (*mode != 'r') /* clumsy, but fun */
> -		dir = reopen(dir, O_RDWR);
> +		igt_debug_on((dir = reopen(dir, O_RDWR)) < 0);
>  
>  	file = fdopen(dir, mode);
> -	if (!file) {
> +	if (igt_debug_on(!file)) {
>  		close(dir);
>  		return NULL;
>  	}
> @@ -554,7 +557,7 @@ int gem_engine_property_printf(int i915, const char *engine, const char *attr,
>  
>  	file = __open_attr(igt_sysfs_open(i915), "w",
>  			   "engine", engine, attr, NULL);
> -	if (!file)
> +	if (igt_debug_on(!file))
>  		return -1;
>  
>  	va_start(ap, fmt);
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index 42b2af41ab..550472d819 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -186,7 +186,7 @@ char *igt_sysfs_path(int device, char *path, int pathlen)
>  	snprintf(path, pathlen, "/sys/dev/char/%d:%d",
>  		 major(st.st_rdev), minor(st.st_rdev));
>  
> -	if (access(path, F_OK))
> +	if (igt_debug_on(access(path, F_OK)))
>  		return NULL;
>  
>  	return path;
> @@ -206,7 +206,7 @@ int igt_sysfs_open(int device)
>  {
>  	char path[80];
>  
> -	if (!igt_sysfs_path(device, path, sizeof(path)))
> +	if (igt_debug_on(!igt_sysfs_path(device, path, sizeof(path))))
>  		return -1;
>  
>  	return open(path, O_RDONLY);
> -- 
> 2.45.2
>
diff mbox series

Patch

diff --git a/lib/i915/gem_engine_topology.c b/lib/i915/gem_engine_topology.c
index afb576afb2..c878e95f08 100644
--- a/lib/i915/gem_engine_topology.c
+++ b/lib/i915/gem_engine_topology.c
@@ -454,12 +454,12 @@  static int __open_primary(int dir)
 	int len;
 
 	fd = openat(dir, "dev", O_RDONLY);
-	if (fd < 0)
+	if (igt_debug_on(fd < 0))
 		return dir;
 
 	len = read(fd, buf, sizeof(buf) - 1);
 	close(fd);
-	if (len <= 0)
+	if (igt_debug_on(len <= 0))
 		return dir;
 	buf[len] = '\0';
 
@@ -467,7 +467,7 @@  static int __open_primary(int dir)
 	if (minor < 64)
 		return dir;
 
-	if (readlinkat(dir, "device", target, sizeof(target)) < 0)
+	if (igt_debug_on(readlinkat(dir, "device", target, sizeof(target)) < 0))
 		return dir;
 
 	fd = openat(dir, "..", O_RDONLY);
@@ -500,24 +500,27 @@  static FILE *__open_attr(int dir, const char *mode, ...)
 	va_list ap;
 
 	/* The attributes are not to be found on render nodes */
-	dir = __open_primary(dir);
+	igt_debug_on((dir = __open_primary(dir)) < 0);
 
 	va_start(ap, mode);
 	while (dir >= 0 && (path = va_arg(ap, const char *))) {
 		int fd;
 
-		fd = openat(dir, path, O_RDONLY);
+		igt_debug_on_f((fd = openat(dir, path, O_RDONLY)) < 0,
+			       "failed component: %s\n", path);
 		close(dir);
 
 		dir = fd;
 	}
 	va_end(ap);
+	if (dir < 0)
+		return NULL;
 
 	if (*mode != 'r') /* clumsy, but fun */
-		dir = reopen(dir, O_RDWR);
+		igt_debug_on((dir = reopen(dir, O_RDWR)) < 0);
 
 	file = fdopen(dir, mode);
-	if (!file) {
+	if (igt_debug_on(!file)) {
 		close(dir);
 		return NULL;
 	}
@@ -554,7 +557,7 @@  int gem_engine_property_printf(int i915, const char *engine, const char *attr,
 
 	file = __open_attr(igt_sysfs_open(i915), "w",
 			   "engine", engine, attr, NULL);
-	if (!file)
+	if (igt_debug_on(!file))
 		return -1;
 
 	va_start(ap, fmt);
diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
index 42b2af41ab..550472d819 100644
--- a/lib/igt_sysfs.c
+++ b/lib/igt_sysfs.c
@@ -186,7 +186,7 @@  char *igt_sysfs_path(int device, char *path, int pathlen)
 	snprintf(path, pathlen, "/sys/dev/char/%d:%d",
 		 major(st.st_rdev), minor(st.st_rdev));
 
-	if (access(path, F_OK))
+	if (igt_debug_on(access(path, F_OK)))
 		return NULL;
 
 	return path;
@@ -206,7 +206,7 @@  int igt_sysfs_open(int device)
 {
 	char path[80];
 
-	if (!igt_sysfs_path(device, path, sizeof(path)))
+	if (igt_debug_on(!igt_sysfs_path(device, path, sizeof(path))))
 		return -1;
 
 	return open(path, O_RDONLY);