Re: [PATCH v7 1/8] drm/panthor: Add performance counter uAPI

From: Steven Price

Date: Mon Nov 23 2026 - 09:31:08 EST


On 11/10/2026 18:36, Lukas Zapolskas wrote:
> This patch extends the DEV_QUERY ioctl to return information about the
> performance counter setup for userspace, and introduces the new
> DRM_PANTHOR_PERF_SESSION ioctls in order to allow for the sampling of
> performance counters.
>
> The new design is inspired by the perf aux ringbuffer [0], with the
> insert and extract indices being mapped to userspace, allowing
> multiple samples to be exposed at any given time. The buffer is
> annotated to include sample metadata and block metadata inline with
> the elements they describe.
>
> Userspace is responsible for passing in resources for samples to be
> exposed, including the event file descriptor for notification of new
> sample availability, the ringbuffer BO to store samples, and the
> control BO.
>
> [0]: https://docs.kernel.org/userspace-api/perf_ring_buffer.html
>
> Co-developed-by: Mihail Atanassov <mihail.atanassov@xxxxxxx>
> Signed-off-by: Mihail Atanassov <mihail.atanassov@xxxxxxx>
> Signed-off-by: Lukas Zapolskas <lukas.zapolskas@xxxxxxx>

I think we need a little more documentation on how these new ioctls
work. Ideally you shouldn't need to dig through the code to figure this out.

E.g. DRM_PANTHOR_PERF_SESSION_CREATE apparently returns a session handle
- but that's not mentioned anywhere here. There's also no information on
the range that session handles can take. Again digging through the code
it appears that <0 is an error but >=0 is valid. Although digging harder
it seems like in the current implementation only 0 is actually returned?

You also have a shared "control BO" but there's no information about
memory barriers. It would be good to document what user space is
required to do between reading the insert_idx, reading the samples and
writing extract_idx.

One more minor point below...

> ---
> include/uapi/drm/panthor_drm.h | 370 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 370 insertions(+)
>
> diff --git a/include/uapi/drm/panthor_drm.h b/include/uapi/drm/panthor_drm.h
> index a2ff0f4ec691..e45f75b76245 100644
> --- a/include/uapi/drm/panthor_drm.h
> +++ b/include/uapi/drm/panthor_drm.h

[...]

> +/**
> + * struct drm_panthor_perf_session_create - Arguments passed to DRM_PANTHOR_PERF_SESSION_CREATE.
> + */
> +struct drm_panthor_perf_session_create {
> + /**
> + * @block_set: Set of performance counter blocks, member of
> + * enum drm_panthor_perf_counter_set.
> + *
> + * This is a global configuration and only one set can be active at a time. If
> + * another client has already requested a counter set, any further requests
> + * for a different counter set will fail and return an -EBUSY.
> + *
> + * If the requested set does not exist, the request will fail and return an -EINVAL.
> + *
> + * Some sets have additional requirements to be enabled, and the setup request will
> + * fail with an -EACCES if these requirements are not satisfied.
> + */
> + __u8 block_set;
> +
> + /** @pad: MBZ. */
> + __u8 pad[7];
> +
> + /** @fd: eventfd for signalling the availability of a new sample. */
> + __u32 fd;
> +
> + /** @ringbuf_handle: Handle to the BO to write perf counter sample to. */
> + __u32 ringbuf_handle;
> +
> + /**
> + * @control_handle: Handle to the BO containing a contiguous 16 byte range, used for the
> + * insert and extract indices for the ringbuffer.
> + */
> + __u32 control_handle;
> +
> + /**
> + * @sample_slots: The number of slots available in the userspace-provided BO. Must be
> + * a power of 2.
> + *
> + * If sample_slots * sample_size does not match the BO size, the setup request will fail.

Actually the BO size must be PFN_ALIGN(sample_slots * sample_size) -
i.e. rounded up to the nearest page size. I also wonder if this will
come back to bite us if we ever have to deal with multiple page sizes.
Is there a reason to enforce exact sizing rather than just 'big enough'?

Thanks,
Steve