From 105fbaab4967efe22897faf0fe56af829a14273a Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Tue, 15 Oct 2024 16:35:09 +0200 Subject: [PATCH] v3dv: Switch to use libbroadcom_perfcntr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Maíra Canal Part-of: --- src/broadcom/vulkan/meson.build | 2 +- src/broadcom/vulkan/v3dv_device.c | 13 +++++ src/broadcom/vulkan/v3dv_private.h | 2 + src/broadcom/vulkan/v3dv_query.c | 36 ++++++++++-- src/broadcom/vulkan/v3dvx_private.h | 7 --- src/broadcom/vulkan/v3dvx_query.c | 89 ----------------------------- 6 files changed, 48 insertions(+), 101 deletions(-) delete mode 100644 src/broadcom/vulkan/v3dvx_query.c diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build index 176061a1845..c0ac093cd25 100644 --- a/src/broadcom/vulkan/meson.build +++ b/src/broadcom/vulkan/meson.build @@ -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, diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index f5d10d687f8..f6a8411bbd1 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -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; diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index cda7dea8383..f95792aedc9 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -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; diff --git a/src/broadcom/vulkan/v3dv_query.c b/src/broadcom/vulkan/v3dv_query.c index 38af0a55556..e50c5c90492 100644 --- a/src/broadcom/vulkan/v3dv_query.c +++ b/src/broadcom/vulkan/v3dv_query.c @@ -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 diff --git a/src/broadcom/vulkan/v3dvx_private.h b/src/broadcom/vulkan/v3dvx_private.h index 7063d771f9c..dcecb87d411 100644 --- a/src/broadcom/vulkan/v3dvx_private.h +++ b/src/broadcom/vulkan/v3dvx_private.h @@ -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); diff --git a/src/broadcom/vulkan/v3dvx_query.c b/src/broadcom/vulkan/v3dvx_query.c deleted file mode 100644 index 36f3695d7f8..00000000000 --- a/src/broadcom/vulkan/v3dvx_query.c +++ /dev/null @@ -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); -}