[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8ab3663c-c18c-4177-87e7-b7558210e1bc@arm.com>
Date: Mon, 21 Jul 2025 10:06:39 +0100
From: Lukas Zapolskas <lukas.zapolskas@....com>
To: Adrián Larumbe <adrian.larumbe@...labora.com>
Cc: Boris Brezillon <boris.brezillon@...labora.com>,
Steven Price <steven.price@....com>, Liviu Dudau <liviu.dudau@....com>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>, Thomas Zimmermann <tzimmermann@...e.de>,
David Airlie <airlied@...il.com>, Simona Vetter <simona@...ll.ch>,
dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/7] drm/panthor: Add DEV_QUERY.PERF_INFO handling for
Gx10
On 18/07/2025 16:11, Adrián Larumbe wrote:
> Hi Lucas, forgot to add one comment in the previous patch review,
>
> On 16.05.2025 16:49, Lukas Zapolskas wrote:
>> This change adds the IOCTL to query data about the performance counter
>> setup. Some of this data was available via previous DEV_QUERY calls,
>> for instance for GPU info, but exposing it via PERF_INFO
>> minimizes the overhead of creating a single session to just the one
>> aggregate IOCTL.
>>
>> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@....com>
>> Reviewed-by: Adrián Larumbe <adrian.larumbe@...labora.com>
>> ---
>> drivers/gpu/drm/panthor/Makefile | 1 +
>> drivers/gpu/drm/panthor/panthor_device.c | 5 ++
>> drivers/gpu/drm/panthor/panthor_device.h | 3 +
>> drivers/gpu/drm/panthor/panthor_drv.c | 10 +++-
>> drivers/gpu/drm/panthor/panthor_fw.h | 3 +
>> drivers/gpu/drm/panthor/panthor_perf.c | 76 ++++++++++++++++++++++++
>> drivers/gpu/drm/panthor/panthor_perf.h | 15 +++++
>> drivers/gpu/drm/panthor/panthor_regs.h | 1 +
>> 8 files changed, 113 insertions(+), 1 deletion(-)
>> create mode 100644 drivers/gpu/drm/panthor/panthor_perf.c
>> create mode 100644 drivers/gpu/drm/panthor/panthor_perf.h
>>
>> diff --git a/drivers/gpu/drm/panthor/Makefile b/drivers/gpu/drm/panthor/Makefile
>> index 15294719b09c..0df9947f3575 100644
>> --- a/drivers/gpu/drm/panthor/Makefile
>> +++ b/drivers/gpu/drm/panthor/Makefile
>> @@ -9,6 +9,7 @@ panthor-y := \
>> panthor_gpu.o \
>> panthor_heap.o \
>> panthor_mmu.o \
>> + panthor_perf.o \
>> panthor_sched.o
>>
>> obj-$(CONFIG_DRM_PANTHOR) += panthor.o
>> diff --git a/drivers/gpu/drm/panthor/panthor_device.c b/drivers/gpu/drm/panthor/panthor_device.c
>> index a9da1d1eeb70..76b4cf3dc391 100644
>> --- a/drivers/gpu/drm/panthor/panthor_device.c
>> +++ b/drivers/gpu/drm/panthor/panthor_device.c
>> @@ -19,6 +19,7 @@
>> #include "panthor_fw.h"
>> #include "panthor_gpu.h"
>> #include "panthor_mmu.h"
>> +#include "panthor_perf.h"
>> #include "panthor_regs.h"
>> #include "panthor_sched.h"
>>
>> @@ -259,6 +260,10 @@ int panthor_device_init(struct panthor_device *ptdev)
>> if (ret)
>> goto err_unplug_fw;
>>
>> + ret = panthor_perf_init(ptdev);
>> + if (ret)
>> + goto err_unplug_fw;
>> +
>> /* ~3 frames */
>> pm_runtime_set_autosuspend_delay(ptdev->base.dev, 50);
>> pm_runtime_use_autosuspend(ptdev->base.dev);
>> diff --git a/drivers/gpu/drm/panthor/panthor_device.h b/drivers/gpu/drm/panthor/panthor_device.h
>> index da6574021664..657ccc39568c 100644
>> --- a/drivers/gpu/drm/panthor/panthor_device.h
>> +++ b/drivers/gpu/drm/panthor/panthor_device.h
>> @@ -120,6 +120,9 @@ struct panthor_device {
>> /** @csif_info: Command stream interface information. */
>> struct drm_panthor_csif_info csif_info;
>>
>> + /** @perf_info: Performance counter interface information. */
>> + struct drm_panthor_perf_info perf_info;
>> +
>> /** @gpu: GPU management data. */
>> struct panthor_gpu *gpu;
>>
>> diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
>> index 06fe46e32073..9d2b716cca45 100644
>> --- a/drivers/gpu/drm/panthor/panthor_drv.c
>> +++ b/drivers/gpu/drm/panthor/panthor_drv.c
>> @@ -175,7 +175,8 @@ panthor_get_uobj_array(const struct drm_panthor_obj_array *in, u32 min_stride,
>> PANTHOR_UOBJ_DECL(struct drm_panthor_sync_op, timeline_value), \
>> PANTHOR_UOBJ_DECL(struct drm_panthor_queue_submit, syncs), \
>> PANTHOR_UOBJ_DECL(struct drm_panthor_queue_create, ringbuf_size), \
>> - PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs))
>> + PANTHOR_UOBJ_DECL(struct drm_panthor_vm_bind_op, syncs), \
>> + PANTHOR_UOBJ_DECL(struct drm_panthor_perf_info, shader_blocks))
>>
>> /**
>> * PANTHOR_UOBJ_SET() - Copy a kernel object to a user object.
>> @@ -835,6 +836,10 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
>> args->size = sizeof(priorities_info);
>> return 0;
>>
>> + case DRM_PANTHOR_DEV_QUERY_PERF_INFO:
>> + args->size = sizeof(ptdev->perf_info);
>> + return 0;
>> +
>> default:
>> return -EINVAL;
>> }
>> @@ -859,6 +864,9 @@ static int panthor_ioctl_dev_query(struct drm_device *ddev, void *data, struct d
>> panthor_query_group_priorities_info(file, &priorities_info);
>> return PANTHOR_UOBJ_SET(args->pointer, args->size, priorities_info);
>>
>> + case DRM_PANTHOR_DEV_QUERY_PERF_INFO:
>> + return PANTHOR_UOBJ_SET(args->pointer, args->size, ptdev->perf_info);
>> +
>> default:
>> return -EINVAL;
>> }
>> diff --git a/drivers/gpu/drm/panthor/panthor_fw.h b/drivers/gpu/drm/panthor/panthor_fw.h
>> index 6598d96c6d2a..8bcb933fa790 100644
>> --- a/drivers/gpu/drm/panthor/panthor_fw.h
>> +++ b/drivers/gpu/drm/panthor/panthor_fw.h
>> @@ -197,8 +197,11 @@ struct panthor_fw_global_control_iface {
>> u32 output_va;
>> u32 group_num;
>> u32 group_stride;
>> +#define GLB_PERFCNT_FW_SIZE(x) ((((x) >> 16) << 8))
>> u32 perfcnt_size;
>> u32 instr_features;
>> +#define PERFCNT_FEATURES_MD_SIZE(x) (((x) & GENMASK(3, 0)) << 8)
>> + u32 perfcnt_features;
>> };
>>
>> struct panthor_fw_global_input_iface {
>> diff --git a/drivers/gpu/drm/panthor/panthor_perf.c b/drivers/gpu/drm/panthor/panthor_perf.c
>> new file mode 100644
>> index 000000000000..66e9a197ac1f
>> --- /dev/null
>> +++ b/drivers/gpu/drm/panthor/panthor_perf.c
>> @@ -0,0 +1,76 @@
>> +// SPDX-License-Identifier: GPL-2.0 or MIT
>> +/* Copyright 2023 Collabora Ltd */
>> +/* Copyright 2025 Arm ltd. */
>> +
>> +#include <linux/bitops.h>
>> +#include <drm/panthor_drm.h>
>> +
>> +#include "panthor_device.h"
>> +#include "panthor_fw.h"
>> +#include "panthor_perf.h"
>> +
>> +struct panthor_perf_counter_block {
>> + struct drm_panthor_perf_block_header header;
>> + u64 counters[];
>> +};
>> +
>> +static size_t get_annotated_block_size(size_t counters_per_block)
>> +{
>> + return struct_size_t(struct panthor_perf_counter_block, counters, counters_per_block);
>> +}
>> +
>> +static size_t session_get_user_sample_size(const struct drm_panthor_perf_info *const info)
>> +{
>> + const size_t block_size = get_annotated_block_size(info->counters_per_block);
>> + const size_t block_nr = info->cshw_blocks + info->fw_blocks +
>> + info->tiler_blocks + info->memsys_blocks + info->shader_blocks;
>> +
>> + return sizeof(struct drm_panthor_perf_sample_header) + (block_size * block_nr);
>
> I think you could use 'perf_info->sample_header_size' because you assign it in the calling function.
>
I think so. Will go over and see where I'm duplicating the sizeof() calls, since I may be doing so
in several places.
>> +}
>> +
>> +/**
>> + * PANTHOR_PERF_COUNTERS_PER_BLOCK - On CSF architectures pre-11.x, the number of counters
>> + * per block was hardcoded to be 64. Arch 11.0 onwards supports the PRFCNT_FEATURES GPU register,
>> + * which indicates the same information.
>> + */
>> +#define PANTHOR_PERF_COUNTERS_PER_BLOCK (64)
>> +
>> +static void panthor_perf_info_init(struct panthor_device *ptdev)
>> +{
>> + struct panthor_fw_global_iface *glb_iface = panthor_fw_get_glb_iface(ptdev);
>> + struct drm_panthor_perf_info *const perf_info = &ptdev->perf_info;
>> +
>> + if (PERFCNT_FEATURES_MD_SIZE(glb_iface->control->perfcnt_features))
>> + perf_info->flags |= DRM_PANTHOR_PERF_BLOCK_STATES_SUPPORT;
>> +
>> + perf_info->counters_per_block = PANTHOR_PERF_COUNTERS_PER_BLOCK;
>> +
>> + perf_info->sample_header_size = sizeof(struct drm_panthor_perf_sample_header);
>> + perf_info->block_header_size = sizeof(struct drm_panthor_perf_block_header);
>> +
>> + if (GLB_PERFCNT_FW_SIZE(glb_iface->control->perfcnt_size))
>> + perf_info->fw_blocks = 1;
>> +
>> + perf_info->cshw_blocks = 1;
>> + perf_info->tiler_blocks = 1;
>> + perf_info->memsys_blocks = GPU_MEM_FEATURES_L2_SLICES(ptdev->gpu_info.mem_features);
>> + perf_info->shader_blocks = hweight64(ptdev->gpu_info.shader_present);
>> +
>> + perf_info->sample_size = session_get_user_sample_size(perf_info);
>> +}
>> +
>> +/**
>> + * panthor_perf_init - Initialize the performance counter subsystem.
>> + * @ptdev: Panthor device
>> + *
>> + * Return: 0 on success, negative error code on failure.
>> + */
>> +int panthor_perf_init(struct panthor_device *ptdev)
>> +{
>> + if (!ptdev)
>> + return -EINVAL;
>> +
>> + panthor_perf_info_init(ptdev);
>> +
>> + return 0;
>> +}
>> diff --git a/drivers/gpu/drm/panthor/panthor_perf.h b/drivers/gpu/drm/panthor/panthor_perf.h
>> new file mode 100644
>> index 000000000000..3c32c24c164c
>> --- /dev/null
>> +++ b/drivers/gpu/drm/panthor/panthor_perf.h
>> @@ -0,0 +1,15 @@
>> +/* SPDX-License-Identifier: GPL-2.0 or MIT */
>> +/* Copyright 2025 Collabora Ltd */
>> +/* Copyright 2025 Arm ltd. */
>> +
>> +#ifndef __PANTHOR_PERF_H__
>> +#define __PANTHOR_PERF_H__
>> +
>> +#include <linux/types.h>
>> +
>> +struct panthor_device;
>> +
>> +int panthor_perf_init(struct panthor_device *ptdev);
>> +
>> +#endif /* __PANTHOR_PERF_H__ */
>> +
>> diff --git a/drivers/gpu/drm/panthor/panthor_regs.h b/drivers/gpu/drm/panthor/panthor_regs.h
>> index b7b3b3add166..d9e9379d1a20 100644
>> --- a/drivers/gpu/drm/panthor/panthor_regs.h
>> +++ b/drivers/gpu/drm/panthor/panthor_regs.h
>> @@ -27,6 +27,7 @@
>> #define GPU_TILER_FEATURES 0xC
>> #define GPU_MEM_FEATURES 0x10
>> #define GROUPS_L2_COHERENT BIT(0)
>> +#define GPU_MEM_FEATURES_L2_SLICES(x) ((((x) & GENMASK(11, 8)) >> 8) + 1)
>>
>> #define GPU_MMU_FEATURES 0x14
>> #define GPU_MMU_FEATURES_VA_BITS(x) ((x) & GENMASK(7, 0))
>> --
>> 2.33.0.dirty
>
>
> Adrian Larumbe
Powered by blists - more mailing lists