Re: [PATCH 3/5] lib: Add a drm_open_any_render() that will try to use render nodes

Ben Widawsky
2013-10-24T20:43:35Z

On Thu, Oct 24, 2013 at 03:40:54PM +0100, Damien Lespiau wrote:
> I was fedup with having to run my tests as root and not being able to
> use my usual setup for tests that only exercise the GT part of the GPU.
>
> Render nodes to the rescue!

I think usually this is a bad idea except for pretty isolated proof of
concept kind of things. Mostly intel-gpu-tools is testing our kernel
driver, and therefore running without a reboot anyway is sort of
unusual.

What do you think about providing some sort of option (maybe via env
var) instead of what you did in patch 5?

>
> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
> ---
> lib/drmtest.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> lib/drmtest.h | 1 +
> 2 files changed, 59 insertions(+)
>
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index 3b80920..8164ef9 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -222,6 +222,35 @@ static int __drm_open_any(void)
> return fd;
> }
>
> +static int __drm_open_any_render(void)
> +{
> + char *name;
> + int i, fd;
> +
> + for (i = 128; i < (128 + 16); i++) {
> + int ret;
> +
> + ret = asprintf(&name, "/dev/dri/renderD%u", i);
> + igt_assert(ret != -1);
> +
> + fd = open(name, O_RDWR);
> + free(name);
> +
> + if (fd == -1)
> + continue;
> +
> + if (!is_intel(fd)) {
> + close(fd);
> + fd = -1;
> + continue;
> + }
> +
> + return fd;
> + }
> +
> + return fd;
> +}
> +
> static void quiescent_gpu_at_exit(int sig)
> {
> int fd;
> @@ -233,6 +262,17 @@ static void quiescent_gpu_at_exit(int sig)
> }
> }
>
> +static void quiescent_gpu_at_exit_render(int sig)
> +{
> + int fd;
> +
> + fd = __drm_open_any_render();
> + if (fd >= 0) {
> + gem_quiescent_gpu(fd);
> + close(fd);
> + }
> +}
> +
> int drm_open_any(void)
> {
> static int open_count;
> @@ -249,6 +289,24 @@ int drm_open_any(void)
> return fd;
> }
>
> +int drm_open_any_render(void)
> +{
> + static int open_count;
> + int fd = __drm_open_any_render();
> +
> + /* no render nodes, fallback to drm_open_any() */
> + if (fd == -1)
> + return drm_open_any();
> +
> + if (__sync_fetch_and_add(&open_count, 1))
> + return fd;
> +
> + gem_quiescent_gpu(fd);
> + igt_install_exit_handler(quiescent_gpu_at_exit_render);
> +
> + return fd;
> +}
> +
> int __gem_set_tiling(int fd, uint32_t handle, int tiling, int stride)
> {
> struct drm_i915_gem_set_tiling st;
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 609e7d8..f5e2708 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -50,6 +50,7 @@ drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
>
> int drm_get_card(void);
> int drm_open_any(void);
> +int drm_open_any_render(void);
>
> void gem_quiescent_gpu(int fd);
>
> --
> 1.8.3.1
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Ben Widawsky, Intel Open Source Technology Center