[Mesa-dev] [PATCH v2] intel/tools: new intel_sanitize_gpu tool

Chris Wilson chris at chris-wilson.co.uk
Thu Feb 8 08:27:15 UTC 2018


Quoting Scott D Phillips (2018-02-08 00:19:04)
> From: Kevin Rogovin <kevin.rogovin at intel.com>
> 
> Adds a new debug tool to pad each GEM BO allocated with (weak)
> pseudo-random noise values which are then checked after each
> batchbuffer dispatch to the kernel. This can be quite valuable to
> find diffucult to track down heisenberg style bugs.
> 
> [scott.d.phillips at intel.com: split to separate tool]
> 
> v2: (by Scott D Phillips)
>     - track gem handles per fd (Kevin)
>     - remove handles on GEM_CLOSE (Kevin)
>     - ignore prime handles
>     - meson & shell script
> ---
> +__attribute__ ((visibility ("default"))) int
> +open(const char *path, int flags, ...)
> +{
> +   va_list args;
> +   mode_t mode;
> +
> +   va_start(args, flags);
> +   mode = va_arg(args, int);
> +   va_end(args);
> +
> +   int fd = libc_open(path, flags, mode);
> +
> +   if (fd >= 0 && strcmp(path, "/dev/dri/renderD128") == 0)
> +      add_drm_fd(fd);
> +
> +   return fd;
> +}

> +__attribute__ ((visibility ("default"))) int
> +ioctl(int fd, unsigned long request, ...)
> +{
> +   va_list args;
> +   void *argp;
> +   struct stat buf;
> +
> +   va_start(args, request);
> +   argp = va_arg(args, void *);
> +   va_end(args);
> +
> +   if (_IOC_TYPE(request) == DRM_IOCTL_BASE &&
> +       !is_drm_fd(fd) && fstat(fd, &buf) == 0 &&
> +       (buf.st_mode & S_IFMT) == S_IFCHR && major(buf.st_rdev) == DRM_MAJOR) {

So you know how to recognise drm from fstat, why not use that for open
(so you don't hardcode the assumption that i915 is card0)?

What you are missing is recognising i915 devices, for which you want to
query drm_version:

static int __get_drm_device_name(int fd, char *name, int len)
{
	drm_version_t version = {
		.name = name,
		.name_len = len
	};
	int err = 0;

        if (ioctl(fd, DRM_IOCTL_VERSION, &version))
		err = -errno;

        return err;
}

static bool __is_device(int fd, const char *expect)
{
        char name[5] = "";

        if (__get_drm_device_name(fd, name, sizeof(name) - 1))
                return false;

        return strcmp(expect, name) == 0;
}

static bool is_i915_device(int fd)
{
        return __is_device(fd, "i915");
}
-Chris


More information about the mesa-dev mailing list