Re: [RFC 12/15] drm/xe/uapi: Add access counter parameter extension for exec queue

Matthew Brost
2026-04-01T14:46:42Z

On Tue, Mar 24, 2026 at 03:25:09PM +0100, Francois Dugast wrote:
> Hi Himal,
>
> On Wed, Mar 18, 2026 at 01:14:53PM +0530, Himal Prasad Ghimiray wrote:
> > Introduce DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM extension to allow
> > userspace to configure access counter notifications per exec queue.
> >
> > The extension provides:
> > - trigger: Access counter trigger threshold
> > - notify: Access counter notify threshold
> > - granularity: Access counter granularity level
> >
> > These parameters control hardware access counter behavior for memory
> > access pattern tracking and optimization hints. Userspace can configure
> > different thresholds per exec queue based on workload characteristics.
> >
> > UAPI changes:
> > - Add drm_xe_exec_queue_set_acc_param structure
> > - Add DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM extension ID
> >
> > KMD changes:
> > - Add exec_queue_user_ext_set_acc_param() handler
> > - Store parameters in xe_exec_queue.acc structure
> > - Register handler in extension function table
> >
> > Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> > ---
> > drivers/gpu/drm/xe/xe_exec_queue.c | 27 ++++++++++++++++
> > drivers/gpu/drm/xe/xe_exec_queue_types.h | 9 ++++++
> > include/uapi/drm/xe_drm.h | 39 ++++++++++++++++++++++++
> > 3 files changed, 75 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/xe/xe_exec_queue.c b/drivers/gpu/drm/xe/xe_exec_queue.c
> > index b287d0e0e60a..815e82011c6d 100644
> > --- a/drivers/gpu/drm/xe/xe_exec_queue.c
> > +++ b/drivers/gpu/drm/xe/xe_exec_queue.c
> > @@ -1080,6 +1080,32 @@ static int exec_queue_user_ext_check_final(struct xe_exec_queue *q, u64 properti
> > return 0;
> > }
> >
> > +static int exec_queue_user_ext_set_acc_param(struct xe_device *xe,
> > + struct xe_exec_queue *q,
> > + u64 extension, u64 *properties)
> > +{
> > + u64 __user *address = u64_to_user_ptr(extension);
> > + struct drm_xe_exec_queue_set_acc_param ext;
> > + int err;
> > +
> > + if (!xe->info.has_access_counter)
> > + return -EINVAL;
> > +
> > + err = copy_from_user(&ext, address, sizeof(ext));
> > + if (XE_IOCTL_DBG(xe, err))
> > + return -EFAULT;
> > +
> > + if (XE_IOCTL_DBG(xe, ext.pad1 || ext.pad2))
> > + return -EINVAL;
> > +
> > + /* Store access counter parameters in exec queue */
> > + q->acc.trigger = ext.trigger;
> > + q->acc.notify = ext.notify;
> > + q->acc.granularity = ext.granularity;
> > +
> > + return 0;
> > +}
> > +
> > static int exec_queue_user_ext_set_property(struct xe_device *xe,
> > struct xe_exec_queue *q,
> > u64 extension, u64 *properties)
> > @@ -1123,6 +1149,7 @@ typedef int (*xe_exec_queue_user_extension_fn)(struct xe_device *xe,
> >
> > static const xe_exec_queue_user_extension_fn exec_queue_user_extension_funcs[] = {
> > [DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY] = exec_queue_user_ext_set_property,
> > + [DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM] = exec_queue_user_ext_set_acc_param,
> > };
> >
> > #define MAX_USER_EXTENSIONS 16
> > diff --git a/drivers/gpu/drm/xe/xe_exec_queue_types.h b/drivers/gpu/drm/xe/xe_exec_queue_types.h
> > index 8ce78e0b1d50..3f10e3371e5a 100644
> > --- a/drivers/gpu/drm/xe/xe_exec_queue_types.h
> > +++ b/drivers/gpu/drm/xe/xe_exec_queue_types.h
> > @@ -239,6 +239,15 @@ struct xe_exec_queue {
> >
> > /** @replay_state: GPU hang replay state */
> > void *replay_state;
> > + /** @acc: Access counter parameters */
> > + struct {
> > + /** @acc.trigger: Access counter trigger threshold */
> > + u16 trigger;
> > + /** @acc.notify: Access counter notify threshold */
> > + u16 notify;
> > + /** @acc.granularity: Access counter granularity */
> > + u8 granularity;
> > + } acc;
> >
> > /** @ops: submission backend exec queue operations */
> > const struct xe_exec_queue_ops *ops;
> > diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h
> > index f8b2afb20540..19447ba10b1d 100644
> > --- a/include/uapi/drm/xe_drm.h
> > +++ b/include/uapi/drm/xe_drm.h
> > @@ -1337,6 +1337,7 @@ struct drm_xe_vm_bind {
> > */
> > struct drm_xe_exec_queue_create {
> > #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 0
> > +#define DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM 1
> > #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0
> > #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1
> > #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 2
> > @@ -1377,6 +1378,44 @@ struct drm_xe_exec_queue_create {
> > __u64 reserved[2];
> > };
> >
> > +/** enum drm_xe_access_counter_granularity - Xe access counter granularity */
> > +enum drm_xe_access_counter_granularity {
> > + /** @DRM_XE_ACCESS_COUNTER_GRANULARITY_128K: 128K granularity */
> > + DRM_XE_ACCESS_COUNTER_GRANULARITY_128K,
> > + /** @DRM_XE_ACCESS_COUNTER_GRANULARITY_2M: 2M granularity */
> > + DRM_XE_ACCESS_COUNTER_GRANULARITY_2M,
> > + /** @DRM_XE_ACCESS_COUNTER_GRANULARITY_16M: 16M granularity */
> > + DRM_XE_ACCESS_COUNTER_GRANULARITY_16M,
> > + /** @DRM_XE_ACCESS_COUNTER_GRANULARITY_64M: 64M granularity */
> > + DRM_XE_ACCESS_COUNTER_GRANULARITY_64M,
> > +};
> > +
> > +/**
> > + * struct drm_xe_exec_queue_set_acc_param - Access counter parameters extension
> > + *
> > + * Extension to configure access counter notifications for an exec queue.
> > + * Used with DRM_XE_EXEC_QUEUE_EXTENSION_SET_ACC_PARAM.
> > + */
>
> Sorry if this is already documented elsewhere but I think we would need more
> details about access counters from a user perspective:
>
> - why using them?
> - what is different when using an exec queue after setting access counters?
> - what is the typical flow, maybe with pseudo code?
> - how is @trigger used, what is triggered, on what condition?
> - how is @notify used, what is notified, on what condition?
> - are notifications going to user space or only to internal and trace?
> - what happens if access counters are not supported?
> - can access counters be reset? removed?

+1 to Francois comments. I never really understood the i915 access
counter interfaces on exec queues and without an explaination like
Francois is suggesting, I don't unerstand Xe's uAPI without reverse
engineering the code.

Matt

>
> Thanks,
> Francois
>
> > +struct drm_xe_exec_queue_set_acc_param {
> > + /** @base: base user extension */
> > + struct drm_xe_user_extension base;
> > +
> > + /** @trigger: Access counter trigger threshold */
> > + __u16 trigger;
> > +
> > + /** @notify: Access counter notify threshold */
> > + __u16 notify;
> > +
> > + /** @granularity: granularity, enum @drm_xe_access_counter_granularity */
> > + __u8 granularity;
> > +
> > + /** @pad1: MBZ */
> > + __u8 pad1;
> > +
> > + /** @pad2: MBZ */
> > + __u16 pad2;
> > +};
> > +
> > /**
> > * struct drm_xe_exec_queue_destroy - Input of &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY
> > */
> > --
> > 2.34.1
> >