anv: Fix context id or exec queue used to open perf stream

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 <mesa-stable>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Signed-off-by: José Roberto de Souza <jose.souza@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30652>
(cherry picked from commit c5d79d533a)
This commit is contained in:
José Roberto de Souza 2024-08-13 09:05:33 -07:00 committed by Eric Engestrom
parent 2df813acb9
commit 706c8a9b45
4 changed files with 47 additions and 7 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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;
}

View file

@ -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