From 706c8a9b45519336acffd7a7ed6f8edeb6d1e69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Tue, 13 Aug 2024 09:05:33 -0700 Subject: [PATCH] anv: Fix context id or exec queue used to open perf stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was always using device->context_id what is not valid in i915 when has_vm_control is true or when running with Xe KMD. But anv_AcquireProfilingLockKHR() don't have the queue information so at least for now we will only support queries in a single queue. And for consistency doing the same in anv_QueueSetPerformanceConfigurationINTEL() although here we have the queue parameter but queries are only supported in render engine so it would only expose other queues if user set some parameters. Cc: 24.2 Reviewed-by: Lionel Landwerlin Signed-off-by: José Roberto de Souza Part-of: (cherry picked from commit c5d79d533a90ba19031f474a830343b7fa819383) --- .pick_status.json | 2 +- src/intel/vulkan/anv_device.c | 1 + src/intel/vulkan/anv_perf.c | 50 ++++++++++++++++++++++++++++++---- src/intel/vulkan/anv_private.h | 1 + 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 960e968c34d..b3d2256cd20 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -4544,7 +4544,7 @@ "description": "anv: Fix context id or exec queue used to open perf stream", "nominated": true, "nomination_type": 0, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": null, "notes": null diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index a961e624565..4f3b38d6d1c 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -2293,6 +2293,7 @@ anv_physical_device_init_queue_families(struct anv_physical_device *pdevice) protected_flag, .queueCount = gc_count, .engine_class = INTEL_ENGINE_CLASS_RENDER, + .supports_perf = true, }; } if (g_count > 0) { diff --git a/src/intel/vulkan/anv_perf.c b/src/intel/vulkan/anv_perf.c index 5a94906733f..a07dd60e6b9 100644 --- a/src/intel/vulkan/anv_perf.c +++ b/src/intel/vulkan/anv_perf.c @@ -95,13 +95,30 @@ anv_device_perf_init(struct anv_device *device) } static int -anv_device_perf_open(struct anv_device *device, uint64_t metric_id) +anv_device_perf_open(struct anv_device *device, struct anv_queue *queue, uint64_t metric_id) { + uint32_t context_or_exec_queue_id; uint64_t period_exponent = 31; /* slowest sampling period */ + int ret; - return intel_perf_stream_open(device->physical->perf, device->fd, - device->context_id, metric_id, - period_exponent, true, true); + switch (device->physical->info.kmd_type) { + case INTEL_KMD_TYPE_I915: + context_or_exec_queue_id = device->physical->has_vm_control ? + queue->context_id : device->context_id; + break; + case INTEL_KMD_TYPE_XE: + context_or_exec_queue_id = queue->exec_queue_id; + break; + default: + unreachable("missing"); + context_or_exec_queue_id = 0; + } + + ret = intel_perf_stream_open(device->physical->perf, device->fd, + context_or_exec_queue_id, metric_id, + period_exponent, true, true); + + return ret; } /* VK_INTEL_performance_query */ @@ -215,6 +232,20 @@ VkResult anv_ReleasePerformanceConfigurationINTEL( return VK_SUCCESS; } +static struct anv_queue * +anv_device_get_perf_queue(struct anv_device *device) +{ + for (uint32_t i = 0; i < device->queue_count; i++) { + struct anv_queue *queue = &device->queues[i]; + const struct anv_queue_family *family = queue->family; + + if (family->supports_perf) + return queue; + } + + return NULL; +} + VkResult anv_QueueSetPerformanceConfigurationINTEL( VkQueue _queue, VkPerformanceConfigurationINTEL _configuration) @@ -223,9 +254,12 @@ VkResult anv_QueueSetPerformanceConfigurationINTEL( ANV_FROM_HANDLE(anv_performance_configuration_intel, config, _configuration); struct anv_device *device = queue->device; + if (queue != anv_device_get_perf_queue(device)) + return VK_ERROR_UNKNOWN; + if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) { if (device->perf_fd < 0) { - device->perf_fd = anv_device_perf_open(device, config->config_id); + device->perf_fd = anv_device_perf_open(device, queue, config->config_id); if (device->perf_fd < 0) return VK_ERROR_INITIALIZATION_FAILED; } else { @@ -367,7 +401,11 @@ VkResult anv_AcquireProfilingLockKHR( assert(device->perf_fd == -1); if (!INTEL_DEBUG(DEBUG_NO_OACONFIG)) { - fd = anv_device_perf_open(device, first_metric_set->oa_metrics_set_id); + struct anv_queue *queue = anv_device_get_perf_queue(device); + + if (queue == NULL) + return VK_ERROR_UNKNOWN; + fd = anv_device_perf_open(device, queue, first_metric_set->oa_metrics_set_id); if (fd < 0) return VK_TIMEOUT; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 03e31a1efec..7fbc83fa281 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -947,6 +947,7 @@ struct anv_queue_family { uint32_t queueCount; enum intel_engine_class engine_class; + bool supports_perf; }; #define ANV_MAX_QUEUE_FAMILIES 5