[Mesa-dev] [PATCH v2 6/6] anv: do not open random render node(s)

Ilia Mirkin imirkin at alum.mit.edu
Wed Feb 15 16:38:13 UTC 2017


On Wed, Feb 15, 2017 at 10:51 AM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
>
> drmGetDevices2() provides us with enough flexibility to build heuristics
> upon. Opening a random node on the other hand will wake up the device,
> regardless if it's the one we're interested or not.
>
> v2:
>  - Explicitly require/check for libdrm.
>  - Zero physicalDeviceCount when drmGetDevices2() returns < 1 devices.
>
> Cc: Jason Ekstrand <jason.ekstrand at intel.com>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com> (v1)
> ---
>  configure.ac                  |  1 +
>  src/intel/vulkan/Makefile.am  |  3 ++-
>  src/intel/vulkan/anv_device.c | 53 +++++++++++++++++++++++++++++++------------
>  3 files changed, 41 insertions(+), 16 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 4b7f2298f7..23ce256da6 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1780,6 +1780,7 @@ if test -n "$with_vulkan_drivers"; then
>              if test "x$HAVE_I965_DRI" != xyes; then
>                  AC_MSG_ERROR([Intel Vulkan driver requires the i965 dri driver])
>              fi
> +            require_libdrm "ANV"
>              HAVE_INTEL_VULKAN=yes;
>
>              ;;
> diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
> index 95f276ed7e..bf2590e643 100644
> --- a/src/intel/vulkan/Makefile.am
> +++ b/src/intel/vulkan/Makefile.am
> @@ -68,7 +68,7 @@ AM_CPPFLAGS += \
>  endif
>
>  AM_CPPFLAGS += \
> -       $(INTEL_CFLAGS) \
> +       $(LIBDRM_CFLAGS) \
>         $(VALGRIND_CFLAGS) \
>         $(DEFINES)
>
> @@ -133,6 +133,7 @@ VULKAN_LIB_DEPS += \
>         $(top_builddir)/src/intel/isl/libisl.la \
>         $(top_builddir)/src/intel/blorp/libblorp.la \
>         $(PER_GEN_LIBS) \
> +       $(LIBDRM_LIBS) \
>         $(PTHREAD_LIBS) \
>         $(DLOPEN_LIBS) \
>         -lm
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index d1a6cc8e9c..808f6f18cc 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -29,6 +29,7 @@
>  #include <sys/stat.h>
>  #include <unistd.h>
>  #include <fcntl.h>
> +#include <xf86drm.h>
>
>  #include "anv_private.h"
>  #include "util/strtod.h"
> @@ -388,6 +389,40 @@ void anv_DestroyInstance(
>     vk_free(&instance->alloc, instance);
>  }
>
> +static VkResult
> +anv_enumerate_devices(struct anv_instance *instance)
> +{
> +   /* TODO: Check for more devices ? */
> +   drmDevicePtr devices[8];
> +   VkResult result = VK_SUCCESS;
> +   int max_devices;
> +
> +   instance->physicalDeviceCount = 0;
> +
> +   max_devices = drmGetDevices2(0, devices, sizeof(devices));
> +   if (max_devices < 1)
> +      return VK_ERROR_INCOMPATIBLE_DRIVER;

so result = VK_SUCCESS

> +
> +   for (unsigned i = 0; i < (unsigned)max_devices; i++) {
> +      if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER &&
> +          devices[i]->bustype == DRM_BUS_PCI &&
> +          devices[i]->deviceinfo.pci->vendor_id == 0x8086) {

let's say this never triggers

> +
> +         result = anv_physical_device_init(&instance->physicalDevice,
> +                        instance,
> +                        devices[i]->nodes[DRM_NODE_RENDER]);
> +         if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
> +            break;
> +      }
> +   }

result is still VK_SUCCESS. Seems like it should default to
VK_ERROR_INCOMPATIBLE_DRIVER instead?

> +
> +   if (result == VK_SUCCESS)
> +      instance->physicalDeviceCount = 1;
> +
> +   return result;
> +}
> +
> +
>  VkResult anv_EnumeratePhysicalDevices(
>      VkInstance                                  _instance,
>      uint32_t*                                   pPhysicalDeviceCount,
> @@ -397,22 +432,10 @@ VkResult anv_EnumeratePhysicalDevices(
>     VkResult result;
>
>     if (instance->physicalDeviceCount < 0) {
> -      char path[20];
> -      for (unsigned i = 0; i < 8; i++) {
> -         snprintf(path, sizeof(path), "/dev/dri/renderD%d", 128 + i);
> -         result = anv_physical_device_init(&instance->physicalDevice,
> -                                           instance, path);
> -         if (result != VK_ERROR_INCOMPATIBLE_DRIVER)
> -            break;
> -      }
> -
> -      if (result == VK_ERROR_INCOMPATIBLE_DRIVER) {
> -         instance->physicalDeviceCount = 0;
> -      } else if (result == VK_SUCCESS) {
> -         instance->physicalDeviceCount = 1;
> -      } else {
> +      result = anv_enumerate_devices(instance);
> +      if (result != VK_SUCCESS &&
> +          result != VK_ERROR_INCOMPATIBLE_DRIVER)
>           return result;
> -      }
>     }
>
>     /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
> --
> 2.11.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list