Module: Mesa
Branch: main
Commit: f868c1727ddba842ef1b72acbaf1c656473b5fd4
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=f868c1727ddba842ef1b72acbaf1c656473b5fd4

Author: José Roberto de Souza <[email protected]>
Date:   Thu Mar 23 13:19:01 2023 -0700

anv: Fetch max_context_priority from drm_xe_query_config

A new property was added to drm_xe_query_config with the max engine
priority for running process, so we can use it directly on
anv_xe_physical_device_get_parameters() and nuke
anv_xe_physical_device_max_priority_update().

Signed-off-by: José Roberto de Souza <[email protected]>
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22112>

---

 src/intel/vulkan/anv_device.c    |  15 ------
 src/intel/vulkan/xe/anv_device.c | 101 +++++++++++++++++++--------------------
 src/intel/vulkan/xe/anv_device.h |   2 -
 src/intel/vulkan/xe/anv_queue.c  |   1 +
 4 files changed, 50 insertions(+), 69 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 1be7599cf56..022cd53700a 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -805,20 +805,6 @@ anv_physical_device_get_parameters(struct 
anv_physical_device *device)
    }
 }
 
-static void
-anv_physical_device_max_priority_update(struct anv_physical_device *device)
-{
-   switch (device->info.kmd_type) {
-   case INTEL_KMD_TYPE_I915:
-      break;
-   case INTEL_KMD_TYPE_XE:
-      anv_xe_physical_device_max_priority_update(device);
-      break;
-   default:
-      unreachable("Missing");
-   }
-}
-
 static VkResult
 anv_physical_device_try_create(struct vk_instance *vk_instance,
                                struct _drmDevice *drm_device,
@@ -1004,7 +990,6 @@ anv_physical_device_try_create(struct vk_instance 
*vk_instance,
    device->info.has_compute_engine = intel_engines_count(device->engine_info,
                                                          
INTEL_ENGINE_CLASS_COMPUTE);
    anv_physical_device_init_queue_families(device);
-   anv_physical_device_max_priority_update(device);
 
    anv_physical_device_init_perf(device, fd);
 
diff --git a/src/intel/vulkan/xe/anv_device.c b/src/intel/vulkan/xe/anv_device.c
index 6bf4a42e068..a5827d968ee 100644
--- a/src/intel/vulkan/xe/anv_device.c
+++ b/src/intel/vulkan/xe/anv_device.c
@@ -46,18 +46,6 @@ VkResult anv_xe_device_setup_vm(struct anv_device *device)
    return VK_SUCCESS;
 }
 
-VkResult
-anv_xe_physical_device_get_parameters(struct anv_physical_device *device)
-{
-   device->has_exec_timeline = true;
-   /* max_context_priority will be updated in
-    * anv_xe_physical_device_max_priority_update()
-    */
-   device->max_context_priority = VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR;
-
-   return VK_SUCCESS;
-}
-
 enum drm_sched_priority
 anv_vk_priority_to_drm_sched_priority(VkQueueGlobalPriorityKHR vk_priority)
 {
@@ -74,51 +62,60 @@ 
anv_vk_priority_to_drm_sched_priority(VkQueueGlobalPriorityKHR vk_priority)
    }
 }
 
-void
-anv_xe_physical_device_max_priority_update(struct anv_physical_device *device)
+static VkQueueGlobalPriorityKHR
+drm_sched_priority_to_vk_priority(enum drm_sched_priority drm_sched_priority)
 {
-   if (!device->engine_info->num_engines)
-      return;
-
-   struct drm_xe_vm_create create_vm = {};
-   if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_VM_CREATE, &create_vm))
-      return;
+   switch (drm_sched_priority) {
+   case DRM_SCHED_PRIORITY_MIN:
+      return VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR;
+   case DRM_SCHED_PRIORITY_NORMAL:
+      return VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR;
+   case DRM_SCHED_PRIORITY_HIGH:
+      return VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR;
+   default:
+      unreachable("Invalid drm_sched_priority");
+      return VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR;
+   }
+}
 
-   const VkQueueGlobalPriorityKHR priorities[] = {
-      VK_QUEUE_GLOBAL_PRIORITY_LOW_KHR,
-      VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_KHR,
-      VK_QUEUE_GLOBAL_PRIORITY_HIGH_KHR,
-   };
-   struct drm_xe_engine_destroy destroy_engine;
-   struct drm_xe_vm_destroy destroy_vm = {
-      .vm_id = create_vm.vm_id,
-   };
-   struct drm_xe_engine_create create_engine = {
-      .instances = (uintptr_t)device->engine_info->engines,
-      .width = 1,
-      .num_placements = 1,
-      .vm_id = create_vm.vm_id,
+static void *
+xe_query_alloc_fetch(struct anv_physical_device *device, uint32_t query_id)
+{
+   struct drm_xe_device_query query = {
+      .query = query_id,
    };
-   if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_ENGINE_CREATE,
-                   &create_engine))
-      goto destroy_vm;
-
-   for (unsigned i = 0; i < ARRAY_SIZE(priorities); i++) {
-      struct drm_xe_engine_set_property engine_property = {
-         .engine_id = create_engine.engine_id,
-         .property = XE_ENGINE_SET_PROPERTY_PRIORITY,
-         engine_property.value = 
anv_vk_priority_to_drm_sched_priority(priorities[i]),
-      };
-      if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_ENGINE_SET_PROPERTY,
-                      &engine_property))
-         break;
-      device->max_context_priority = priorities[i];
+   if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query))
+      return NULL;
+
+   void *data = calloc(1, query.size);
+   if (!data)
+      return NULL;
+
+   query.data = (uintptr_t)data;
+   if (intel_ioctl(device->local_fd, DRM_IOCTL_XE_DEVICE_QUERY, &query)) {
+      free(data);
+      return NULL;
    }
 
-   destroy_engine.engine_id = create_engine.engine_id;
-   intel_ioctl(device->local_fd, DRM_IOCTL_XE_ENGINE_DESTROY, &destroy_engine);
-destroy_vm:
-   intel_ioctl(device->local_fd, DRM_IOCTL_XE_VM_DESTROY, &destroy_vm);
+   return data;
+}
+
+VkResult
+anv_xe_physical_device_get_parameters(struct anv_physical_device *device)
+{
+   struct drm_xe_query_config *config;
+
+   config = xe_query_alloc_fetch(device, DRM_XE_DEVICE_QUERY_CONFIG);
+   if (!config)
+      return vk_errorf(device, VK_ERROR_INITIALIZATION_FAILED,
+                       "unable to query device config");
+
+   device->has_exec_timeline = true;
+   device->max_context_priority =
+         
drm_sched_priority_to_vk_priority(config->info[XE_QUERY_CONFIG_MAX_ENGINE_PRIORITY]);
+
+   free(config);
+   return VK_SUCCESS;
 }
 
 VkResult
diff --git a/src/intel/vulkan/xe/anv_device.h b/src/intel/vulkan/xe/anv_device.h
index bb7ebc1a439..669d5639c99 100644
--- a/src/intel/vulkan/xe/anv_device.h
+++ b/src/intel/vulkan/xe/anv_device.h
@@ -38,7 +38,5 @@ VkResult anv_xe_device_check_status(struct vk_device 
*vk_device);
 
 VkResult
 anv_xe_physical_device_get_parameters(struct anv_physical_device *device);
-void
-anv_xe_physical_device_max_priority_update(struct anv_physical_device *device);
 enum drm_sched_priority
 anv_vk_priority_to_drm_sched_priority(VkQueueGlobalPriorityKHR vk_priority);
diff --git a/src/intel/vulkan/xe/anv_queue.c b/src/intel/vulkan/xe/anv_queue.c
index 336cdcda01b..5c42435c73a 100644
--- a/src/intel/vulkan/xe/anv_queue.c
+++ b/src/intel/vulkan/xe/anv_queue.c
@@ -30,6 +30,7 @@
 #include "xe/anv_device.h"
 
 #include "drm-uapi/xe_drm.h"
+#include "drm-uapi/gpu_scheduler.h"
 
 VkResult
 anv_xe_create_engine(struct anv_device *device,

Reply via email to