From bb3fc7a44f9ef18725c8cda274fc1fde97d5ad70 Mon Sep 17 00:00:00 2001 From: Christian Gmeiner Date: Tue, 15 Oct 2024 16:15:36 +0200 Subject: [PATCH] v3d: Switch to use libbroadcom_perfcntrs 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/gallium/drivers/v3d/meson.build | 4 +- src/gallium/drivers/v3d/v3d_query.c | 47 ++++++++--- src/gallium/drivers/v3d/v3d_query.h | 2 + ...dx_query_perfcnt.c => v3d_query_perfcnt.c} | 83 ++----------------- src/gallium/drivers/v3d/v3d_screen.c | 15 ++-- src/gallium/drivers/v3d/v3d_screen.h | 4 +- src/gallium/drivers/v3d/v3dx_context.h | 6 -- 7 files changed, 50 insertions(+), 111 deletions(-) rename src/gallium/drivers/v3d/{v3dx_query_perfcnt.c => v3d_query_perfcnt.c} (71%) diff --git a/src/gallium/drivers/v3d/meson.build b/src/gallium/drivers/v3d/meson.build index a85a1cec34f..d228bdd2ae4 100644 --- a/src/gallium/drivers/v3d/meson.build +++ b/src/gallium/drivers/v3d/meson.build @@ -16,6 +16,7 @@ files_libv3d = files( 'v3d_program.c', 'v3d_query.c', 'v3d_query.h', + 'v3d_query_perfcnt.c', 'v3d_query_pipe.c', 'v3d_resource.c', 'v3d_resource.h', @@ -29,7 +30,6 @@ files_per_version = files( 'v3dx_emit.c', 'v3dx_format_table.c', 'v3dx_job.c', - 'v3dx_query_perfcnt.c', 'v3dx_rcl.c', 'v3dx_state.c', 'v3dx_tfu.c', @@ -78,5 +78,5 @@ libv3d = static_library( driver_v3d = declare_dependency( compile_args : '-DGALLIUM_V3D', link_with : [libv3d, libv3dwinsys, libbroadcom_cle, libbroadcom_v3d], - dependencies : idep_nir, + dependencies : [idep_nir, idep_broadcom_perfcntrs], ) diff --git a/src/gallium/drivers/v3d/v3d_query.c b/src/gallium/drivers/v3d/v3d_query.c index 83f82e44a3d..1a44091f093 100644 --- a/src/gallium/drivers/v3d/v3d_query.c +++ b/src/gallium/drivers/v3d/v3d_query.c @@ -28,11 +28,21 @@ v3d_get_driver_query_group_info(struct pipe_screen *pscreen, unsigned index, struct pipe_driver_query_group_info *info) { struct v3d_screen *screen = v3d_screen(pscreen); - struct v3d_device_info *devinfo = &screen->devinfo; - return v3d_X(devinfo, get_driver_query_group_info_perfcnt)(screen, - index, - info); + if (!screen->has_perfmon) + return 0; + + if (!info) + return 1; + + if (index > 0) + return 0; + + info->name = "V3D counters"; + info->max_active_queries = DRM_V3D_MAX_PERF_COUNTERS; + info->num_queries = screen->perfcnt->max_perfcnt; + + return 1; } int @@ -40,11 +50,26 @@ v3d_get_driver_query_info(struct pipe_screen *pscreen, unsigned index, struct pipe_driver_query_info *info) { struct v3d_screen *screen = v3d_screen(pscreen); - struct v3d_device_info *devinfo = &screen->devinfo; + struct v3d_perfcntr_desc *desc; - return v3d_X(devinfo, get_driver_query_info_perfcnt)(screen, - index, - info); + if (!screen->has_perfmon) + return 0; + + if (!info) + return screen->perfcnt->max_perfcnt; + + desc = v3d_perfcntrs_get_by_index(screen->perfcnt, index); + if (!desc) + return 0; + + info->name = desc->name; + info->group_id = 0; + info->query_type = PIPE_QUERY_DRIVER_SPECIFIC + index; + info->result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_CUMULATIVE; + info->type = PIPE_DRIVER_QUERY_TYPE_UINT64; + info->flags = PIPE_DRIVER_QUERY_FLAG_BATCH; + + return 1; } static struct pipe_query * @@ -60,12 +85,8 @@ v3d_create_batch_query(struct pipe_context *pctx, unsigned num_queries, unsigned *query_types) { struct v3d_context *v3d = v3d_context(pctx); - struct v3d_screen *screen = v3d->screen; - struct v3d_device_info *devinfo = &screen->devinfo; - return v3d_X(devinfo, create_batch_query_perfcnt)(v3d_context(pctx), - num_queries, - query_types); + return v3d_create_batch_query_pipe(v3d, num_queries, query_types); } static void diff --git a/src/gallium/drivers/v3d/v3d_query.h b/src/gallium/drivers/v3d/v3d_query.h index 605ed1a12f9..b2d8124a908 100644 --- a/src/gallium/drivers/v3d/v3d_query.h +++ b/src/gallium/drivers/v3d/v3d_query.h @@ -42,5 +42,7 @@ struct v3d_query }; struct pipe_query *v3d_create_query_pipe(struct v3d_context *v3d, unsigned query_type, unsigned index); +struct pipe_query *v3d_create_batch_query_pipe(struct v3d_context *v3d, unsigned num_queries, + unsigned *query_types); #endif /* V3D_QUERY_H */ diff --git a/src/gallium/drivers/v3d/v3dx_query_perfcnt.c b/src/gallium/drivers/v3d/v3d_query_perfcnt.c similarity index 71% rename from src/gallium/drivers/v3d/v3dx_query_perfcnt.c rename to src/gallium/drivers/v3d/v3d_query_perfcnt.c index d627b54d8ce..4689825b657 100644 --- a/src/gallium/drivers/v3d/v3dx_query_perfcnt.c +++ b/src/gallium/drivers/v3d/v3d_query_perfcnt.c @@ -28,8 +28,7 @@ */ #include "v3d_query.h" - -#include "common/v3d_performance_counters.h" +#include "v3d_screen.h" struct v3d_query_perfcnt { @@ -51,77 +50,6 @@ kperfmon_destroy(struct v3d_context *v3d, struct v3d_perfmon_state *perfmon) perfmon->kperfmon_id, strerror(errno)); } -int -v3dX(get_driver_query_group_info_perfcnt)(struct v3d_screen *screen, unsigned index, - struct pipe_driver_query_group_info *info) -{ - struct v3d_device_info *devinfo = &screen->devinfo; - - if (!screen->has_perfmon) - return 0; - - if (!info) - return 1; - - if (index > 0) - return 0; - - info->name = "V3D counters"; - info->max_active_queries = DRM_V3D_MAX_PERF_COUNTERS; - info->num_queries = devinfo->max_perfcnt ? devinfo->max_perfcnt - : ARRAY_SIZE(v3d_performance_counters); - - return 1; -} - -int -v3dX(get_driver_query_info_perfcnt)(struct v3d_screen *screen, unsigned index, - struct pipe_driver_query_info *info) -{ - struct v3d_device_info *devinfo = &screen->devinfo; - unsigned max_perfcnt = devinfo->max_perfcnt ? devinfo->max_perfcnt - : ARRAY_SIZE(v3d_performance_counters); - - if (!screen->has_perfmon) - return 0; - - if (!info) - return max_perfcnt; - - if (index >= max_perfcnt) - return 0; - - if (screen->perfcnt_names) { - if (screen->perfcnt_names[index]) { - info->name = screen->perfcnt_names[index]; - } else { - struct drm_v3d_perfmon_get_counter counter = { - .counter = index, - }; - int ret = v3d_ioctl(screen->fd, DRM_IOCTL_V3D_PERFMON_GET_COUNTER, &counter); - if (ret != 0) { - fprintf(stderr, "Failed to get performance counter %d: %s\n", - index, strerror(errno)); - return 0; - } - - screen->perfcnt_names[index] = ralloc_strdup(screen->perfcnt_names, - (const char *) counter.name); - info->name = screen->perfcnt_names[index]; - } - } else { - info->name = v3d_performance_counters[index][V3D_PERFCNT_NAME]; - } - - info->group_id = 0; - info->query_type = PIPE_QUERY_DRIVER_SPECIFIC + index; - info->result_type = PIPE_DRIVER_QUERY_RESULT_TYPE_CUMULATIVE; - info->type = PIPE_DRIVER_QUERY_TYPE_UINT64; - info->flags = PIPE_DRIVER_QUERY_FLAG_BATCH; - - return 1; -} - static void v3d_destroy_query_perfcnt(struct v3d_context *v3d, struct v3d_query *query) { @@ -259,15 +187,14 @@ static const struct v3d_query_funcs perfcnt_query_funcs = { }; struct pipe_query * -v3dX(create_batch_query_perfcnt)(struct v3d_context *v3d, unsigned num_queries, - unsigned *query_types) +v3d_create_batch_query_pipe(struct v3d_context *v3d, unsigned num_queries, + unsigned *query_types) { + struct v3d_screen *screen = v3d->screen; struct v3d_query_perfcnt *pquery = NULL; struct v3d_query *query; struct v3d_perfmon_state *perfmon = NULL; - struct v3d_device_info *devinfo = &v3d->screen->devinfo; - unsigned max_perfcnt = devinfo->max_perfcnt ? devinfo->max_perfcnt - : ARRAY_SIZE(v3d_performance_counters); + unsigned max_perfcnt = screen->perfcnt->max_perfcnt; int i; /* Validate queries */ diff --git a/src/gallium/drivers/v3d/v3d_screen.c b/src/gallium/drivers/v3d/v3d_screen.c index 9adefc55660..35d8520e750 100644 --- a/src/gallium/drivers/v3d/v3d_screen.c +++ b/src/gallium/drivers/v3d/v3d_screen.c @@ -76,8 +76,8 @@ v3d_screen_destroy(struct pipe_screen *pscreen) { struct v3d_screen *screen = v3d_screen(pscreen); - ralloc_free(screen->perfcnt_names); - screen->perfcnt_names = NULL; + v3d_perfcntrs_fini(screen->perfcnt); + screen->perfcnt = NULL; _mesa_hash_table_destroy(screen->bo_handles, NULL); v3d_bufmgr_destroy(pscreen); @@ -944,14 +944,9 @@ v3d_screen_create(int fd, const struct pipe_screen_config *config, if (!v3d_get_device_info(screen->fd, &screen->devinfo, &v3d_ioctl)) goto fail; - const uint8_t max_perfcnt = screen->devinfo.max_perfcnt; - if (max_perfcnt) { - screen->perfcnt_names = rzalloc_array(screen, char*, max_perfcnt); - if (!screen->perfcnt_names) { - fprintf(stderr, "Error allocating performance counters names"); - goto fail; - } - } + screen->perfcnt = v3d_perfcntrs_init(&screen->devinfo, screen->fd); + if (!screen->perfcnt) + goto fail; driParseConfigFiles(config->options, config->options_info, 0, "v3d", NULL, NULL, NULL, 0, NULL, 0); diff --git a/src/gallium/drivers/v3d/v3d_screen.h b/src/gallium/drivers/v3d/v3d_screen.h index 2d48e36e744..c4dfd509ddc 100644 --- a/src/gallium/drivers/v3d/v3d_screen.h +++ b/src/gallium/drivers/v3d/v3d_screen.h @@ -33,6 +33,7 @@ #include "util/slab.h" #include "broadcom/common/v3d_debug.h" #include "broadcom/common/v3d_device_info.h" +#include "broadcom/perfcntrs/v3d_perfcntrs.h" struct v3d_bo; @@ -58,8 +59,7 @@ struct v3d_screen { const char *name; - /** Stores performance counters names **/ - char **perfcnt_names; + struct v3d_perfcntrs *perfcnt; struct slab_parent_pool transfer_pool; diff --git a/src/gallium/drivers/v3d/v3dx_context.h b/src/gallium/drivers/v3d/v3dx_context.h index 898def5bf0b..07c7409e11f 100644 --- a/src/gallium/drivers/v3d/v3dx_context.h +++ b/src/gallium/drivers/v3d/v3dx_context.h @@ -63,12 +63,6 @@ bool v3dX(tfu)(struct pipe_context *pctx, unsigned int dst_layer, bool for_mipmap); -int v3dX(get_driver_query_group_info_perfcnt)(struct v3d_screen *screen, - unsigned index, - struct pipe_driver_query_group_info *info); -int v3dX(get_driver_query_info_perfcnt)(struct v3d_screen *screen, - unsigned index, - struct pipe_driver_query_info *info); struct pipe_query *v3dX(create_batch_query_perfcnt)(struct v3d_context *v3d, unsigned num_queries, unsigned *query_types);