Re: [PATCH i-g-t 03/10] lib/xe: Gather workarounds debugfs dumps

Matt Roper <[email protected]> Wed, 29 Jul 2026 14:39:26 -0700
Newsgroups org.freedesktop.lists.igt-dev
Message-ID <[email protected]>
On Tue, Jul 21, 2026 at 03:59:56PM -0300, Gustavo Sousa wrote:
> In an upcoming change, we will cache workaround information in struct
> xe_device.  As a preparation for that, add the logic to gather the
> dumps of workaround debugfs files into a single array, which will be
> used as the cached information in the future.
> 
> Signed-off-by: Gustavo Sousa <[email protected]>

Reviewed-by: Matt Roper <[email protected]>

> ---
>  lib/xe/xe_wa.c | 92 ++++++++++++++++++++++++++++++++++++----------------------
>  1 file changed, 58 insertions(+), 34 deletions(-)
> 
> diff --git a/lib/xe/xe_wa.c b/lib/xe/xe_wa.c
> index d44431e7e61f..e4e1b0bb7972 100644
> --- a/lib/xe/xe_wa.c
> +++ b/lib/xe/xe_wa.c
> @@ -7,12 +7,65 @@
>  #include <stdint.h>
>  #include <stdio.h>
>  
> +#include "igt_core.h"
>  #include "igt_debugfs.h"
>  #include "igt_sysfs.h"
>  
>  #include "xe/xe_wa.h"
>  #include "xe/xe_query.h"
>  
> +static void free_wa_debugfs_dumps(char **dumps)
> +{
> +	for (char **dump = dumps; *dump; dump++)
> +		free(*dump);
> +
> +	free(dumps);
> +}
> +
> +static char **get_wa_debugfs_dumps(int fd)
> +{
> +	char **dumps;
> +	int gt;
> +	int debugfs_fd;
> +	int count = 1; /* Device workarounds */
> +
> +	xe_for_each_gt(fd, gt)
> +		count++;
> +
> +	dumps = calloc(count + 1, sizeof(*dumps));
> +	if (!dumps)
> +		return NULL;
> +
> +	debugfs_fd = igt_debugfs_dir(fd);
> +	if (debugfs_fd == -1)
> +		goto err;
> +
> +	count = 0;
> +
> +	if (!(dumps[count++] = igt_sysfs_get(debugfs_fd, "workarounds")))
> +		goto err;
> +
> +	xe_for_each_gt(fd, gt) {
> +		char name[32];
> +
> +		snprintf(name, sizeof(name), "gt%d/workarounds", gt);
> +
> +		if (!(dumps[count++] = igt_sysfs_get(debugfs_fd, name)))
> +			goto err;
> +	}
> +
> +	goto out;
> +
> +err:
> +	free_wa_debugfs_dumps(dumps);
> +	dumps = NULL;
> +
> +out:
> +	close(debugfs_fd);
> +
> +	return dumps;
> +}
> +
>  static bool debugfs_dump_has_wa(char *dump, const char *wa)
>  {
>  	char *a = dump;
> @@ -50,27 +103,6 @@ static bool debugfs_dump_has_wa(char *dump, const char *wa)
>  	return false;
>  }
>  
> -static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
> -			       const char *debugfs_name, const char *wa)
> -{
> -	char *debugfs_dump;
> -
> -	if (!igt_debugfs_exists(drm_fd, debugfs_name, O_RDONLY))
> -		return -1;
> -
> -	debugfs_dump = igt_sysfs_get(debugfs_fd, debugfs_name);
> -	if (debugfs_dump) {
> -		bool has_wa = debugfs_dump_has_wa(debugfs_dump, wa);
> -
> -		free(debugfs_dump);
> -
> -		if (has_wa)
> -			return 1;
> -	}
> -
> -	return 0;
> -}
> -
>  /**
>   * xe_wa: Check if a workaround is enabled for the device.
>   * @fd: A drm file descriptor.
> @@ -80,25 +112,17 @@ static int debugfs_file_has_wa(int drm_fd, int debugfs_fd,
>   */
>  int xe_wa(int fd, const char *wa)
>  {
> +	char **dumps = get_wa_debugfs_dumps(fd);
>  	int ret = 0;
> -	int debugfs_fd;
> -	unsigned int xe;
> -	char name[256];
>  
> -	debugfs_fd = igt_debugfs_dir(fd);
> -	if (debugfs_fd == -1)
> +	if (igt_warn_on(!dumps))
>  		return -1;
>  
> -	xe_for_each_gt(fd, xe) {
> -		sprintf(name, "gt%d/workarounds", xe);
> -		ret = debugfs_file_has_wa(fd, debugfs_fd, name, wa);
> -		if (ret)
> +	for (char **dump = dumps; *dump; dump++)
> +		if ((ret = debugfs_dump_has_wa(*dump, wa)))
>  			break;
> -	}
>  
> -	if (!ret)
> -		ret = debugfs_file_has_wa(fd, debugfs_fd, "workarounds", wa);
> +	free_wa_debugfs_dumps(dumps);
>  
> -	close(debugfs_fd);
>  	return ret;
>  }
> 
> -- 
> 2.55.0
> 

-- 
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation