v3dv: Switch to use libbroadcom_perfcntr

Switch to a common library that does all the performance counter
readout. This converts one version-dependend file to a generic one.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32277>
This commit is contained in:
Christian Gmeiner
2024-10-15 16:35:09 +02:00
committed by Marge Bot
parent bb3fc7a44f
commit 105fbaab49
6 changed files with 48 additions and 101 deletions
+1 -1
View File
@@ -46,7 +46,6 @@ files_per_version = files(
'v3dvx_pipeline.c',
'v3dvx_meta_common.c',
'v3dvx_pipeline.c',
'v3dvx_query.c',
'v3dvx_queue.c',
)
@@ -59,6 +58,7 @@ v3dv_deps = [
dep_libdrm,
dep_valgrind,
dep_v3d_hw,
idep_broadcom_perfcntrs,
idep_nir,
idep_nir_headers,
idep_vulkan_util,
+13
View File
@@ -647,6 +647,9 @@ physical_device_finish(struct v3dv_physical_device *device)
util_sparse_array_finish(&device->bo_map);
if (device->perfcntr)
v3d_perfcntrs_fini(device->perfcntr);
close(device->render_fd);
if (device->display_fd >= 0)
close(device->display_fd);
@@ -1345,6 +1348,16 @@ create_physical_device(struct v3dv_instance *instance,
goto fail;
}
if (device->caps.perfmon) {
device->perfcntr = v3d_perfcntrs_init(&device->devinfo, device->render_fd);
if (!device->perfcntr) {
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
"Failed to get init perfmon.");
goto fail;
}
}
result = init_uuids(device);
if (result != VK_SUCCESS)
goto fail;
+2
View File
@@ -92,6 +92,7 @@
#include "drm-uapi/v3d_drm.h"
#include "vk_alloc.h"
#include "perfcntrs/v3d_perfcntrs.h"
#include "simulator/v3d_simulator.h"
#include "v3dv_cl.h"
@@ -157,6 +158,7 @@ struct v3dv_physical_device {
VkPhysicalDeviceMemoryProperties memory;
struct v3d_device_info devinfo;
struct v3d_perfcntrs *perfcntr;
#if USE_V3D_SIMULATOR
struct v3d_simulator_file *sim_file;
+32 -4
View File
@@ -1357,10 +1357,38 @@ v3dv_EnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR(
{
V3DV_FROM_HANDLE(v3dv_physical_device, pDevice, physicalDevice);
return v3d_X((&pDevice->devinfo), enumerate_performance_query_counters)(pDevice,
pCounterCount,
pCounters,
pCounterDescriptions);
uint32_t desc_count = *pCounterCount;
uint8_t ncounters = pDevice->perfcntr->max_perfcnt;
VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterKHR,
out, pCounters, pCounterCount);
VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterDescriptionKHR,
out_desc, pCounterDescriptions, &desc_count);
for (int i = 0; i < ncounters; i++) {
const struct v3d_perfcntr_desc *perfcntr_desc = v3d_perfcntrs_get_by_index(pDevice->perfcntr, i);
vk_outarray_append_typed(VkPerformanceCounterKHR, &out, counter) {
counter->unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
counter->scope = VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR;
counter->storage = VK_PERFORMANCE_COUNTER_STORAGE_UINT64_KHR;
unsigned char sha1_result[20];
_mesa_sha1_compute(perfcntr_desc->name, strlen(perfcntr_desc->name), sha1_result);
memcpy(counter->uuid, sha1_result, sizeof(counter->uuid));
}
vk_outarray_append_typed(VkPerformanceCounterDescriptionKHR,
&out_desc, desc) {
desc->flags = 0;
snprintf(desc->name, sizeof(desc->name), "%s", perfcntr_desc->name);
snprintf(desc->category, sizeof(desc->category), "%s", perfcntr_desc->category);
snprintf(desc->description, sizeof(desc->description), "%s", perfcntr_desc->description);
}
}
return vk_outarray_status(&out);
}
VKAPI_ATTR void VKAPI_CALL
-7
View File
@@ -339,13 +339,6 @@ v3dX(create_default_attribute_values)(struct v3dv_device *device,
void
v3dX(job_emit_noop)(struct v3dv_job *job);
/* Used at v3dv_query */
VkResult
v3dX(enumerate_performance_query_counters)(struct v3dv_physical_device *pDevice,
uint32_t *pCounterCount,
VkPerformanceCounterKHR *pCounters,
VkPerformanceCounterDescriptionKHR *pCounterDescriptions);
/* Used at v3dv_descriptor_set, and other descriptor set utils */
uint32_t v3dX(descriptor_bo_size)(VkDescriptorType type);
-89
View File
@@ -1,89 +0,0 @@
/*
* Copyright © 2023 Raspberry Pi Ltd
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "v3dv_private.h"
#include "common/v3d_performance_counters.h"
VkResult
v3dX(enumerate_performance_query_counters)(struct v3dv_physical_device *pDevice,
uint32_t *pCounterCount,
VkPerformanceCounterKHR *pCounters,
VkPerformanceCounterDescriptionKHR *pCounterDescriptions)
{
struct v3d_device_info *devinfo = &pDevice->devinfo;
uint32_t desc_count = *pCounterCount;
uint8_t ncounters = devinfo->max_perfcnt ? devinfo->max_perfcnt
: ARRAY_SIZE(v3d_performance_counters);
VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterKHR,
out, pCounters, pCounterCount);
VK_OUTARRAY_MAKE_TYPED(VkPerformanceCounterDescriptionKHR,
out_desc, pCounterDescriptions, &desc_count);
for (int i = 0; i < ncounters; i++) {
struct drm_v3d_perfmon_get_counter counter = {
.counter = i,
};
const char *name, *category, *description;
if (devinfo->max_perfcnt) {
int ret = v3d_ioctl(pDevice->render_fd, DRM_IOCTL_V3D_PERFMON_GET_COUNTER,
&counter);
if (ret) {
mesa_loge("Failed to get counter description for counter %d: %s\n",
i, strerror(errno));
}
name = (char *) counter.name;
category = (char *) counter.category;
description = (char *) counter.description;
} else {
/* Legacy path for kernels without support for DRM_IOCTL_V3D_PERFMON_GET_COUNTER */
name = v3d_performance_counters[i][V3D_PERFCNT_NAME];
category = v3d_performance_counters[i][V3D_PERFCNT_CATEGORY];
description = v3d_performance_counters[i][V3D_PERFCNT_DESCRIPTION];
}
vk_outarray_append_typed(VkPerformanceCounterKHR, &out, counter) {
counter->unit = VK_PERFORMANCE_COUNTER_UNIT_GENERIC_KHR;
counter->scope = VK_PERFORMANCE_COUNTER_SCOPE_COMMAND_KHR;
counter->storage = VK_PERFORMANCE_COUNTER_STORAGE_UINT64_KHR;
unsigned char sha1_result[20];
_mesa_sha1_compute(name, strlen(name), sha1_result);
memcpy(counter->uuid, sha1_result, sizeof(counter->uuid));
}
vk_outarray_append_typed(VkPerformanceCounterDescriptionKHR,
&out_desc, desc) {
desc->flags = 0;
snprintf(desc->name, sizeof(desc->name), "%s", name);
snprintf(desc->category, sizeof(desc->category), "%s", category);
snprintf(desc->description, sizeof(desc->description), "%s", description);
}
}
return vk_outarray_status(&out);
}