Skip to contentSkip to conversation

drm/amdgpu: add mqd_update callback to AMDGPU user queue interface

PATCH Superseded Jesse.Zhang 2 participants 11 messages Jan 23 – Jan 27

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 drm/amdgpu: add mqd_update callback to AMDGPU user queue interface

Extend the AMDGPU user queue function interface to support MQD updates by adding an mqd_update callback.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +1 -0
index 95ace14e458c..c80d69368196 100644
@@ -79,6 +79,7 @@ struct amdgpu_usermode_queue {
 struct amdgpu_userq_funcs {
 	int (*mqd_create)(struct amdgpu_usermode_queue *queue,
 			  struct drm_amdgpu_userq_in *args);
+	int (*mqd_update)(struct amdgpu_usermode_queue *queue);
 	void (*mqd_destroy)(struct amdgpu_usermode_queue *uq);
 	int (*unmap)(struct amdgpu_usermode_queue *queue);
 	int (*map)(struct amdgpu_usermode_queue *queue);
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/7 drm/amdgpu: Add CU mask support for MQD properties

Add new fields to the amdgpu_mqd_prop structure to track CU (Compute Unit) mask information, including the mask itself, count, flags, and a flag to indicate if user-specified CU masking is active.

v2: Create a generic function amdgpu_gfx_mqd_symmetrically_map_cu_mask()

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 10 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 49 +++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  2 +
 3 files changed, 61 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10 -0
index 11a36c132905..a8f4f73fa0ce 100644
@@ -789,6 +789,12 @@ struct amd_powerplay {
 					  (rid == 0x01) || \
 					  (rid == 0x10))))
 
+enum amdgpu_mqd_update_flag {
+       AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE = 1,
+       AMDGPU_UPDATE_FLAG_DBG_WA_DISABLE = 2,
+       AMDGPU_UPDATE_FLAG_IS_GWS = 4, /* quirk for gfx9 IP */
+};
+
 struct amdgpu_mqd_prop {
 	uint64_t mqd_gpu_addr;
 	uint64_t hqd_base_gpu_addr;
@@ -809,6 +815,10 @@ struct amdgpu_mqd_prop {
 	uint64_t fence_address;
 	bool tmz_queue;
 	bool kernel_queue;
+	uint32_t *cu_mask;
+	uint32_t cu_mask_count;
+	uint32_t cu_flags;
+	bool is_user_cu_masked;
 };
 
 struct amdgpu_mqd {
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +49 -0

55 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -0
index 585cc8e81bb2..720ed3a2c78c 100644
@@ -583,6 +583,8 @@ int amdgpu_gfx_kiq_init(struct amdgpu_device *adev,
 int amdgpu_gfx_mqd_sw_init(struct amdgpu_device *adev,
 			   unsigned mqd_size, int xcc_id);
 void amdgpu_gfx_mqd_sw_fini(struct amdgpu_device *adev, int xcc_id);
+void amdgpu_gfx_mqd_symmetrically_map_cu_mask(struct amdgpu_device *adev, const uint32_t *cu_mask,
+					      uint32_t cu_mask_count, uint32_t *se_mask);
 int amdgpu_gfx_disable_kcq(struct amdgpu_device *adev, int xcc_id);
 int amdgpu_gfx_enable_kcq(struct amdgpu_device *adev, int xcc_id);
 int amdgpu_gfx_disable_kgq(struct amdgpu_device *adev, int xcc_id);
Signature · 1 line
2.49.0
#2 lore raw

PATCH 3/7 drm/amdgpu/gfx11: add CU mask support for compute MQD initialization

In reply to Jesse.Zhang

Extend the GFX11 compute MQD initialization to support Compute Unit (CU) masking for fine-grained resource allocation. This allows compute queues to be limited to specific CUs for performance isolation and debugging purposes.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 33 ++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +33 -0
index 3a4ca104b161..55d98b1a9ac5 100644
@@ -4238,6 +4238,37 @@ static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
 	return gfx_v11_0_cp_gfx_start(adev);
 }
 
+static void gfx_v11_0_compute_mqd_set_cu_mask(struct amdgpu_device *adev,
+					      struct v11_compute_mqd *mqd,
+					      struct amdgpu_mqd_prop *prop)
+{
+	uint32_t se_mask[8] = {0};
+	uint32_t wa_mask;
+	bool has_wa_flag = prop->cu_flags & (AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE |
+					  AMDGPU_UPDATE_FLAG_DBG_WA_DISABLE);
+
+	if (!has_wa_flag && (!prop->cu_mask || !prop->cu_mask_count))
+		return;
+
+	if (has_wa_flag) {
+		wa_mask = (prop->cu_flags & AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE) ?
+			  0xffff : 0xffffffff;
+		mqd->compute_static_thread_mgmt_se0 = wa_mask;
+		mqd->compute_static_thread_mgmt_se1 = wa_mask;
+		mqd->compute_static_thread_mgmt_se2 = wa_mask;
+		mqd->compute_static_thread_mgmt_se3 = wa_mask;
+		return;
+	}
+
+	amdgpu_gfx_mqd_symmetrically_map_cu_mask(adev, prop->cu_mask,
+						prop->cu_mask_count, se_mask);
+
+	mqd->compute_static_thread_mgmt_se0 = se_mask[0];
+	mqd->compute_static_thread_mgmt_se1 = se_mask[1];
+	mqd->compute_static_thread_mgmt_se2 = se_mask[2];
+	mqd->compute_static_thread_mgmt_se3 = se_mask[3];
+}
+
 static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 				      struct amdgpu_mqd_prop *prop)
 {
@@ -4372,6 +4403,8 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 	/* set UQ fenceaddress */
 	mqd->fence_address_lo = lower_32_bits(prop->fence_address);
 	mqd->fence_address_hi = upper_32_bits(prop->fence_address);
+	/* set CU mask */
+	gfx_v11_0_compute_mqd_set_cu_mask(adev, mqd, prop);
 
 	return 0;
 }
Signature · 1 line
2.49.0
#3 lore raw

PATCH 4/7 drm/amdgpu/gfx12: add CU mask support for compute MQD initialization

In reply to Jesse.Zhang

Extend the GFX12 compute MQD initialization to support Compute Unit (CU) masking for fine-grained resource allocation. This allows compute queues to be limited to specific CUs for performance isolation and debugging purposes.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 33 ++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +33 -0
index 6cd16f016c37..73478dd0f6ad 100644
@@ -3110,6 +3110,37 @@ static int gfx_v12_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
 	return gfx_v12_0_cp_gfx_start(adev);
 }
 
+static void gfx_v12_0_compute_mqd_set_cu_mask(struct amdgpu_device *adev,
+					      struct v12_compute_mqd *mqd,
+					      struct amdgpu_mqd_prop *prop)
+{
+	uint32_t se_mask[8] = {0};
+	uint32_t wa_mask;
+	bool has_wa_flag = prop->cu_flags & (AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE |
+					  AMDGPU_UPDATE_FLAG_DBG_WA_DISABLE);
+
+	if (!has_wa_flag && (!prop->cu_mask || !prop->cu_mask_count))
+		return;
+
+	if (has_wa_flag) {
+		wa_mask = (prop->cu_flags & AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE) ?
+			  0xffff : 0xffffffff;
+		mqd->compute_static_thread_mgmt_se0 = wa_mask;
+		mqd->compute_static_thread_mgmt_se1 = wa_mask;
+		mqd->compute_static_thread_mgmt_se2 = wa_mask;
+		mqd->compute_static_thread_mgmt_se3 = wa_mask;
+		return;
+	}
+
+	amdgpu_gfx_mqd_symmetrically_map_cu_mask(adev, prop->cu_mask,
+						prop->cu_mask_count, se_mask);
+
+	mqd->compute_static_thread_mgmt_se0 = se_mask[0];
+	mqd->compute_static_thread_mgmt_se1 = se_mask[1];
+	mqd->compute_static_thread_mgmt_se2 = se_mask[2];
+	mqd->compute_static_thread_mgmt_se3 = se_mask[3];
+}
+
 static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 				      struct amdgpu_mqd_prop *prop)
 {
@@ -3243,6 +3274,8 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 	/* set UQ fenceaddress */
 	mqd->fence_address_lo = lower_32_bits(prop->fence_address);
 	mqd->fence_address_hi = upper_32_bits(prop->fence_address);
+	/* set CU mask */
+	gfx_v12_0_compute_mqd_set_cu_mask(adev, mqd, prop);
 
 	return 0;
 }
Signature · 1 line
2.49.0
Reviewed-by on v1 4/7
#4 lore raw

Re: [PATCH 4/7] drm/amdgpu/gfx12: add CU mask support for compute MQD initialization

Quoted 7 lines · Jesse.Zhang

Extend the GFX12 compute MQD initialization to support Compute Unit (CU) masking for fine-grained resource allocation. This allows compute queues to be limited to specific CUs for performance isolation and debugging purposes.

Patches 1-4:

Quoted 58 lines
---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 33 ++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +33 -1
index 6cd16f016c37..73478dd0f6ad 100644
@@ -3110,6 +3110,37 @@ static int gfx_v12_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
        return gfx_v12_0_cp_gfx_start(adev);
 }
 
+static void gfx_v12_0_compute_mqd_set_cu_mask(struct amdgpu_device *adev,
+                                             struct v12_compute_mqd *mqd,
+                                             struct amdgpu_mqd_prop *prop)
+{
+       uint32_t se_mask[8] = {0};
+       uint32_t wa_mask;
+       bool has_wa_flag = prop->cu_flags & (AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE |
+                                         AMDGPU_UPDATE_FLAG_DBG_WA_DISABLE);
+
+       if (!has_wa_flag && (!prop->cu_mask || !prop->cu_mask_count))
+               return;
+
+       if (has_wa_flag) {
+               wa_mask = (prop->cu_flags & AMDGPU_UPDATE_FLAG_DBG_WA_ENABLE) ?
+                         0xffff : 0xffffffff;
+               mqd->compute_static_thread_mgmt_se0 = wa_mask;
+               mqd->compute_static_thread_mgmt_se1 = wa_mask;
+               mqd->compute_static_thread_mgmt_se2 = wa_mask;
+               mqd->compute_static_thread_mgmt_se3 = wa_mask;
+               return;
+       }
+
+       amdgpu_gfx_mqd_symmetrically_map_cu_mask(adev, prop->cu_mask,
+                                               prop->cu_mask_count, se_mask);
+
+       mqd->compute_static_thread_mgmt_se0 = se_mask[0];
+       mqd->compute_static_thread_mgmt_se1 = se_mask[1];
+       mqd->compute_static_thread_mgmt_se2 = se_mask[2];
+       mqd->compute_static_thread_mgmt_se3 = se_mask[3];
+}
+
 static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
                                      struct amdgpu_mqd_prop *prop)
 {
@@ -3243,6 +3274,8 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
        /* set UQ fenceaddress */
        mqd->fence_address_lo = lower_32_bits(prop->fence_address);
        mqd->fence_address_hi = upper_32_bits(prop->fence_address);
+       /* set CU mask */
+       gfx_v12_0_compute_mqd_set_cu_mask(adev, mqd, prop);
 
        return 0;
 }
--

2.49.0

#5 lore raw

PATCH 5/7 amdgpu: Add MQD update functionality for user queues

In reply to Jesse.Zhang

This patch adds support for updating MQD
properties for user queues, specifically focusing on CU mask updates.

v2: Return an error for non-compute queues. (Alex)
remove the parameter minfo

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +28 -0
index f2309d72bbe6..0565986949bd 100644
@@ -432,6 +432,33 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	return r;
 }
 
+/**
+ * mes_userq_mqd_update - Core MQD update logic for user queues
+ * @queue: Target mes_user_queue structure
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue)
+{
+	int retval = 0;
+	struct amdgpu_device *adev = queue->userq_mgr->adev;
+	struct amdgpu_mqd_prop *props = queue->userq_prop;
+	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
+
+	if (!queue || !props)
+		return -EINVAL;
+
+	if (queue->queue_type != AMDGPU_HW_IP_COMPUTE)
+		return -EINVAL;
+
+	retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, props);
+
+	if (!retval && props->cu_mask_count && props->cu_mask)
+		props->is_user_cu_masked = true;
+
+	return retval;
+}
+
 static void mes_userq_mqd_destroy(struct amdgpu_usermode_queue *queue)
 {
 	struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
@@ -513,6 +540,7 @@ static int mes_userq_restore(struct amdgpu_usermode_queue *queue)
 
 const struct amdgpu_userq_funcs userq_mes_funcs = {
 	.mqd_create = mes_userq_mqd_create,
+	.mqd_update = mes_userq_mqd_update,
 	.mqd_destroy = mes_userq_mqd_destroy,
 	.unmap = mes_userq_unmap,
 	.map = mes_userq_map,
Signature · 1 line
2.49.0
#6 lore raw

PATCH 6/7 drm/amdgpu: implement CU mask modification support for AMDGPU user queues

In reply to Jesse.Zhang

Add support for dynamic Compute Unit (CU) mask modification to AMDGPU user queues via a new MODIFY_CU_MASK operation. This enables userspace to update CU allocation for existing queues at runtime.

v2: add a new op for AMDGPU_USERQ. E.g., AMDGPU_USERQ_OP_CU_MASK

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 111 ++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h             |  13 +++
 2 files changed, 124 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +111 -0
index 256ceca6d429..4d7841f47dd3 100644
@@ -901,6 +901,113 @@ bool amdgpu_userq_enabled(struct drm_device *dev)
 	return false;
 }
 
+static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue)
+{
+	struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	const struct amdgpu_userq_funcs *uq_funcs;
+	bool unmap_queue = false;
+	int r;
+
+	uq_funcs = adev->userq_funcs[queue->queue_type];
+	if (!uq_funcs || (queue->queue_type != AMDGPU_HW_IP_COMPUTE))
+		return -EOPNOTSUPP;
+
+	/*
+	 * Unmap the queue if it's mapped or preempted to ensure a clean update.
+	 * If the queue is already unmapped or hung, we skip this step.
+	 */
+	if (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+	    queue->state == AMDGPU_USERQ_STATE_PREEMPTED) {
+		r = amdgpu_userq_unmap_helper(queue);
+		if (r)
+			return r;
+		unmap_queue = true;
+	}
+
+	r = uq_funcs->mqd_update(queue);
+
+	if (unmap_queue) {
+		r = amdgpu_userq_map_helper(queue);
+		if (r)
+			drm_file_err(uq_mgr->file, "Failed to remap queue %llu after update\n",
+				queue->doorbell_index);
+	}
+
+	return r;
+}
+
+static int amdgpu_userq_set_cu_mask(struct drm_file *filp,  union drm_amdgpu_userq *args)
+{
+	struct amdgpu_fpriv *fpriv = filp->driver_priv;
+	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+	struct amdgpu_device *adev = uq_mgr->adev;
+	struct amdgpu_usermode_queue *queue;
+	struct amdgpu_mqd_prop *props;
+	const int max_num_cus = 1024;
+	size_t cu_mask_size;
+	uint32_t count;
+	uint32_t *ptr;
+	int r;
+
+	mutex_lock(&uq_mgr->userq_mutex);
+	queue = amdgpu_userq_find(uq_mgr, args->in.queue_id);
+	if (!queue) {
+		mutex_unlock(&uq_mgr->userq_mutex);
+		return -EINVAL;
+	}
+	props = queue->userq_prop;
+
+	if (args->in.cu_mask_count == 0 || args->in.cu_mask_count % 32) {
+		r = -EINVAL;
+		goto unlock;
+	}
+
+	count = args->in.cu_mask_count;
+	/* To prevent an unreasonably large CU mask size, set an arbitrary
+	* limit of max_num_cus bits.  We can then just drop any CU mask bits
+	* past max_num_cus bits and just use the first max_num_cus bits.
+	*/
+	if (count > max_num_cus) {
+		drm_file_err(uq_mgr->file, "CU mask cannot be greater than 1024 bits");
+		count = max_num_cus;
+		cu_mask_size = sizeof(uint32_t) * (max_num_cus / 32);
+	} else {
+		cu_mask_size = sizeof(uint32_t) * (args->in.cu_mask_count / 32);
+	}
+
+	ptr = memdup_user(u64_to_user_ptr(args->in.cu_mask_ptr),
+				    cu_mask_size);
+	if (IS_ERR(ptr)) {
+		r = PTR_ERR(ptr);
+		goto unlock;
+	}
+
+	/* ASICs that have WGPs must enforce pairwise enabled mask checks. */
+	if (ptr && adev->ip_versions[GC_HWIP][0] >= IP_VERSION(10, 0, 0)) {
+		for (int i = 0; i < count; i +=2) {
+			uint32_t cu_pair = (ptr[i / 32] >> (i % 32)) & 0x3;
+
+			if (cu_pair && cu_pair != 0x3) {
+				drm_file_err(uq_mgr->file, "CUs must be adjacent pairwise enabled.\n");
+				kfree(ptr);
+				r = -EINVAL;
+				goto unlock;
+			}
+		}
+	}
+
+	props->cu_mask = ptr;
+	props->cu_mask_count = count;
+	r = amdgpu_userq_update_queue(queue);
+
+	kfree(ptr);
+unlock:
+	mutex_unlock(&uq_mgr->userq_mutex);
+
+	return r;
+}
+
 int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		       struct drm_file *filp)
 {
@@ -920,6 +1027,10 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 			drm_file_err(filp, "Failed to create usermode queue\n");
 		break;
 
+	case AMDGPU_USERQ_OP_MODIFY_CU_MASK:
+		amdgpu_userq_set_cu_mask(filp, args);
+		break;
+
 	case AMDGPU_USERQ_OP_FREE:
 		r = amdgpu_userq_destroy(filp, args->in.queue_id);
 		if (r)
include/uapi/drm/amdgpu_drm.h +13 -0
index ab2bf47553e1..cfc3a9313229 100644
@@ -330,6 +330,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE	1
 #define AMDGPU_USERQ_OP_FREE	2
+#define AMDGPU_USERQ_OP_MODIFY_CU_MASK	3
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -410,6 +411,18 @@ struct drm_amdgpu_userq_in {
 	 * gfx11 workloads, size = sizeof(drm_amdgpu_userq_mqd_gfx11).
 	 */
 	__u64 mqd_size;
+	/**
+	 * @cu_mask_ptr: User-space pointer to CU (Compute Unit) mask array
+	 * Points to an array of __u32 values that define which CUs are enabled
+	 * for this queue (0 = disabled, 1 = enabled per bit)
+	 */
+	__u64 cu_mask_ptr;
+	/**
+	 * @cu_mask_count: Number of entries in the CU mask array
+	 * Total count of __u32 elements in the cu_mask_ptr array (each element
+	 * represents 32 CUs/WGPs)
+	 */
+	__u32 cu_mask_count;
 };
 
 /* The structure to carry output of userqueue ops */
Signature · 1 line
2.49.0
#7 lore raw

Re: [PATCH 6/7] drm/amdgpu: implement CU mask modification support for AMDGPU user queues

Quoted 161 lines · Jesse.Zhang

Add support for dynamic Compute Unit (CU) mask modification to AMDGPU user queues via a new MODIFY_CU_MASK operation. This enables userspace to update CU allocation for existing queues at runtime.

v2: add a new op for AMDGPU_USERQ. E.g., AMDGPU_USERQ_OP_CU_MASK

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 111 ++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h             |  13 +++
 2 files changed, 124 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +111 -0
index 256ceca6d429..4d7841f47dd3 100644
@@ -901,6 +901,113 @@ bool amdgpu_userq_enabled(struct drm_device *dev)
        return false;
 }
 
+static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue)
+{
+       struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
+       struct amdgpu_device *adev = uq_mgr->adev;
+       const struct amdgpu_userq_funcs *uq_funcs;
+       bool unmap_queue = false;
+       int r;
+
+       uq_funcs = adev->userq_funcs[queue->queue_type];
+       if (!uq_funcs || (queue->queue_type != AMDGPU_HW_IP_COMPUTE))
+               return -EOPNOTSUPP;
+
+       /*
+        * Unmap the queue if it's mapped or preempted to ensure a clean update.
+        * If the queue is already unmapped or hung, we skip this step.
+        */
+       if (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+           queue->state == AMDGPU_USERQ_STATE_PREEMPTED) {
+               r = amdgpu_userq_unmap_helper(queue);
+               if (r)
+                       return r;
+               unmap_queue = true;
+       }
+
+       r = uq_funcs->mqd_update(queue);
+
+       if (unmap_queue) {
+               r = amdgpu_userq_map_helper(queue);
+               if (r)
+                       drm_file_err(uq_mgr->file, "Failed to remap queue %llu after update\n",
+                               queue->doorbell_index);
+       }
+
+       return r;
+}
+
+static int amdgpu_userq_set_cu_mask(struct drm_file *filp,  union drm_amdgpu_userq *args)
+{
+       struct amdgpu_fpriv *fpriv = filp->driver_priv;
+       struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+       struct amdgpu_device *adev = uq_mgr->adev;
+       struct amdgpu_usermode_queue *queue;
+       struct amdgpu_mqd_prop *props;
+       const int max_num_cus = 1024;
+       size_t cu_mask_size;
+       uint32_t count;
+       uint32_t *ptr;
+       int r;
+
+       mutex_lock(&uq_mgr->userq_mutex);
+       queue = amdgpu_userq_find(uq_mgr, args->in.queue_id);
+       if (!queue) {
+               mutex_unlock(&uq_mgr->userq_mutex);
+               return -EINVAL;
+       }
+       props = queue->userq_prop;
+
+       if (args->in.cu_mask_count == 0 || args->in.cu_mask_count % 32) {
+               r = -EINVAL;
+               goto unlock;
+       }
+
+       count = args->in.cu_mask_count;
+       /* To prevent an unreasonably large CU mask size, set an arbitrary
+       * limit of max_num_cus bits.  We can then just drop any CU mask bits
+       * past max_num_cus bits and just use the first max_num_cus bits.
+       */
+       if (count > max_num_cus) {
+               drm_file_err(uq_mgr->file, "CU mask cannot be greater than 1024 bits");
+               count = max_num_cus;
+               cu_mask_size = sizeof(uint32_t) * (max_num_cus / 32);
+       } else {
+               cu_mask_size = sizeof(uint32_t) * (args->in.cu_mask_count / 32);
+       }
+
+       ptr = memdup_user(u64_to_user_ptr(args->in.cu_mask_ptr),
+                                   cu_mask_size);
+       if (IS_ERR(ptr)) {
+               r = PTR_ERR(ptr);
+               goto unlock;
+       }
+
+       /* ASICs that have WGPs must enforce pairwise enabled mask checks. */
+       if (ptr && adev->ip_versions[GC_HWIP][0] >= IP_VERSION(10, 0, 0)) {
+               for (int i = 0; i < count; i +=2) {
+                       uint32_t cu_pair = (ptr[i / 32] >> (i % 32)) & 0x3;
+
+                       if (cu_pair && cu_pair != 0x3) {
+                               drm_file_err(uq_mgr->file, "CUs must be adjacent pairwise enabled.\n");
+                               kfree(ptr);
+                               r = -EINVAL;
+                               goto unlock;
+                       }
+               }
+       }
+
+       props->cu_mask = ptr;
+       props->cu_mask_count = count;
+       r = amdgpu_userq_update_queue(queue);
+
+       kfree(ptr);
+unlock:
+       mutex_unlock(&uq_mgr->userq_mutex);
+
+       return r;
+}
+
 int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
                       struct drm_file *filp)
 {
@@ -920,6 +1027,10 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
                        drm_file_err(filp, "Failed to create usermode queue\n");
                break;
 
+       case AMDGPU_USERQ_OP_MODIFY_CU_MASK:
+               amdgpu_userq_set_cu_mask(filp, args);
+               break;
+
        case AMDGPU_USERQ_OP_FREE:
                r = amdgpu_userq_destroy(filp, args->in.queue_id);
                if (r)
include/uapi/drm/amdgpu_drm.h +3 -0
index ab2bf47553e1..cfc3a9313229 100644
@@ -330,6 +330,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE 1
 #define AMDGPU_USERQ_OP_FREE   2
+#define AMDGPU_USERQ_OP_MODIFY_CU_MASK 3
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -410,6 +411,18 @@ struct drm_amdgpu_userq_in {
         * gfx11 workloads, size = sizeof(drm_amdgpu_userq_mqd_gfx11).
         */
        __u64 mqd_size;
+       /**
+        * @cu_mask_ptr: User-space pointer to CU (Compute Unit) mask array

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_userq_in { · line 425

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+        * Points to an array of __u32 values that define which CUs are enabled
+        * for this queue (0 = disabled, 1 = enabled per bit)
+        */
+       __u64 cu_mask_ptr;
+       /**
+        * @cu_mask_count: Number of entries in the CU mask array
+        * Total count of __u32 elements in the cu_mask_ptr array (each element
+        * represents 32 CUs/WGPs)
+        */
+       __u32 cu_mask_count;

I'd put these in drm_amdgpu_userq_mqd_compute_gfx11. Then you can use the mqd to set the CU mask on queue creation or modification. I don't see why we should limit it to just modify.

Alex

Quoted 6 lines
include/uapi/drm/amdgpu_drm.h +0 -1
 };
 
 /* The structure to carry output of userqueue ops */
--

2.49.0

#8 lore raw

RE: [PATCH 6/7] drm/amdgpu: implement CU mask modification support for AMDGPU user queues

[AMD Official Use Only - AMD Internal Distribution Only]

Quoted 184 lines

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Saturday, January 24, 2026 5:05 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 6/7] drm/amdgpu: implement CU mask modification support for AMDGPU user queues

Quoted 6 lines · Jesse.Zhang

Add support for dynamic Compute Unit (CU) mask modification to AMDGPU user queues via a new MODIFY_CU_MASK operation. This enables userspace to update CU allocation for existing queues at runtime.

v2: add a new op for AMDGPU_USERQ. E.g.,

AMDGPU_USERQ_OP_CU_MASK

Quoted 5 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 111

++++++++++++++++++++++

Quoted 32 lines
 include/uapi/drm/amdgpu_drm.h             |  13 +++
 2 files changed, 124 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +20 -0
index 256ceca6d429..4d7841f47dd3 100644
@@ -901,6 +901,113 @@ bool amdgpu_userq_enabled(struct drm_device *dev)
        return false;
 }
 
+static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue
+*queue) {
+       struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
+       struct amdgpu_device *adev = uq_mgr->adev;
+       const struct amdgpu_userq_funcs *uq_funcs;
+       bool unmap_queue = false;
+       int r;
+
+       uq_funcs = adev->userq_funcs[queue->queue_type];
+       if (!uq_funcs || (queue->queue_type != AMDGPU_HW_IP_COMPUTE))
+               return -EOPNOTSUPP;
+
+       /*
+        * Unmap the queue if it's mapped or preempted to ensure a clean update.
+        * If the queue is already unmapped or hung, we skip this step.
+        */
+       if (queue->state == AMDGPU_USERQ_STATE_MAPPED ||
+           queue->state == AMDGPU_USERQ_STATE_PREEMPTED) {
+               r = amdgpu_userq_unmap_helper(queue);
+               if (r)

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c bool amdgpu_userq_enabled(struct drm_device *dev) · line 933

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -0
+                       return r;
+               unmap_queue = true;
+       }
+
+       r = uq_funcs->mqd_update(queue);
+
+       if (unmap_queue) {
+               r = amdgpu_userq_map_helper(queue);
+               if (r)
+                       drm_file_err(uq_mgr->file, "Failed to remap queue %llu after

update\n",

Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +29 -0
+                               queue->doorbell_index);
+       }
+
+       return r;
+}
+
+static int amdgpu_userq_set_cu_mask(struct drm_file *filp,  union
+drm_amdgpu_userq *args) {
+       struct amdgpu_fpriv *fpriv = filp->driver_priv;
+       struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+       struct amdgpu_device *adev = uq_mgr->adev;
+       struct amdgpu_usermode_queue *queue;
+       struct amdgpu_mqd_prop *props;
+       const int max_num_cus = 1024;
+       size_t cu_mask_size;
+       uint32_t count;
+       uint32_t *ptr;
+       int r;
+
+       mutex_lock(&uq_mgr->userq_mutex);
+       queue = amdgpu_userq_find(uq_mgr, args->in.queue_id);
+       if (!queue) {
+               mutex_unlock(&uq_mgr->userq_mutex);
+               return -EINVAL;
+       }
+       props = queue->userq_prop;
+
+       if (args->in.cu_mask_count == 0 || args->in.cu_mask_count % 32) {
+               r = -EINVAL;

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c bool amdgpu_userq_enabled(struct drm_device *dev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -0
+               goto unlock;
+       }
+
+       count = args->in.cu_mask_count;
+       /* To prevent an unreasonably large CU mask size, set an arbitrary
+       * limit of max_num_cus bits.  We can then just drop any CU mask bits
+       * past max_num_cus bits and just use the first max_num_cus bits.
+       */
+       if (count > max_num_cus) {
+               drm_file_err(uq_mgr->file, "CU mask cannot be greater than 1024

bits");

Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11 -0
+               count = max_num_cus;
+               cu_mask_size = sizeof(uint32_t) * (max_num_cus / 32);
+       } else {
+               cu_mask_size = sizeof(uint32_t) * (args->in.cu_mask_count / 32);
+       }
+
+       ptr = memdup_user(u64_to_user_ptr(args->in.cu_mask_ptr),
+                                   cu_mask_size);
+       if (IS_ERR(ptr)) {
+               r = PTR_ERR(ptr);
+               goto unlock;

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c bool amdgpu_userq_enabled(struct drm_device *dev)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10 -0
+       }
+
+       /* ASICs that have WGPs must enforce pairwise enabled mask checks. */
+       if (ptr && adev->ip_versions[GC_HWIP][0] >= IP_VERSION(10, 0, 0)) {
+               for (int i = 0; i < count; i +=2) {
+                       uint32_t cu_pair = (ptr[i / 32] >> (i % 32)) &
+ 0x3;
+
+                       if (cu_pair && cu_pair != 0x3) {
+                               drm_file_err(uq_mgr->file, "CUs must be adjacent pairwise

enabled.\n");

Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +18 -0
+                               kfree(ptr);
+                               r = -EINVAL;
+                               goto unlock;
+                       }
+               }
+       }
+
+       props->cu_mask = ptr;
+       props->cu_mask_count = count;
+       r = amdgpu_userq_update_queue(queue);
+
+       kfree(ptr);
+unlock:
+       mutex_unlock(&uq_mgr->userq_mutex);
+
+       return r;
+}
+
 int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
                       struct drm_file *filp)  { @@ -920,6 +1027,10 @@

int amdgpu_userq_ioctl(struct drm_device *dev, void *data,

                        drm_file_err(filp, "Failed to create usermode queue\n");
                break;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4 -0
+       case AMDGPU_USERQ_OP_MODIFY_CU_MASK:
+               amdgpu_userq_set_cu_mask(filp, args);
+               break;
+
        case AMDGPU_USERQ_OP_FREE:
                r = amdgpu_userq_destroy(filp, args->in.queue_id);
                if (r)
(quoted diff) +0 -0

b/include/uapi/drm/amdgpu_drm.h index ab2bf47553e1..cfc3a9313229 100644

include/uapi/drm/amdgpu_drm.h +1 -0
@@ -330,6 +330,7 @@ union drm_amdgpu_ctx {
 /* user queue IOCTL operations */
 #define AMDGPU_USERQ_OP_CREATE 1
 #define AMDGPU_USERQ_OP_FREE   2
+#define AMDGPU_USERQ_OP_MODIFY_CU_MASK 3
 
 /* queue priority levels */
 /* low < normal low < normal high < high */ @@ -410,6 +411,18 @@
struct drm_amdgpu_userq_in {
         * gfx11 workloads, size = sizeof(drm_amdgpu_userq_mqd_gfx11).
         */
        __u64 mqd_size;
include/uapi/drm/amdgpu_drm.h +8 -0
+       /**
+        * @cu_mask_ptr: User-space pointer to CU (Compute Unit) mask array
+        * Points to an array of __u32 values that define which CUs are enabled
+        * for this queue (0 = disabled, 1 = enabled per bit)
+        */
+       __u64 cu_mask_ptr;
+       /**
+        * @cu_mask_count: Number of entries in the CU mask array
Quoted 8 lines

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_userq_in { · line 425

Quoted 4 lines
include/uapi/drm/amdgpu_drm.h +4 -0
+        * Total count of __u32 elements in the cu_mask_ptr array (each element
+        * represents 32 CUs/WGPs)
+        */
+       __u32 cu_mask_count;

I'd put these in drm_amdgpu_userq_mqd_compute_gfx11. Then you can use the mqd to set the CU mask on queue creation or modification. I don't see why we should limit it to just modify.

Thanks, Alex. This will make it more flexible. I will update the patch.

Thanks
Jesse

Quoted 9 lines

Alex

Quoted 6 lines

};

/* The structure to carry output of userqueue ops */
--
2.49.0

#9 lore raw

PATCH 7/7 drm/amdgpu: add queue modification support to AMDGPU_USERQ ioctl

In reply to Jesse.Zhang

Extend the AMDGPU_USERQ ioctl to support dynamic modification of existing user mode queues after creation. This provides userspace with the ability to update queue attributes without requiring destruction and recreation of queues.

v2: add a new op for AMDGPU_USERQ. E.g., AMDGPU_USERQ_OP_MODIFY. (Alex)
make the target xcc an explicit parameter. (Alex)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 96 +++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |  3 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c |  1 +
 include/uapi/drm/amdgpu_drm.h              | 17 ++++
 5 files changed, 116 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index a8f4f73fa0ce..ad136145316b 100644
@@ -819,6 +819,9 @@ struct amdgpu_mqd_prop {
 	uint32_t cu_mask_count;
 	uint32_t cu_flags;
 	bool is_user_cu_masked;
+	uint32_t queue_percentage;
+	/* used in gfx9 and gfx12.1 */
+	uint32_t pm4_target_xcc;
 };
 
 struct amdgpu_mqd {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +92 -4

129 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
index c80d69368196..078f424e9415 100644
@@ -31,6 +31,9 @@
 #define to_ev_fence(f) container_of(f, struct amdgpu_eviction_fence, base)
 #define uq_mgr_to_fpriv(u) container_of(u, struct amdgpu_fpriv, userq_mgr)
 #define work_to_uq_mgr(w, name) container_of(w, struct amdgpu_userq_mgr, name)
+#define AMDGPU_USERQ_IS_ACTIVE(q) ((q)->userq_prop->queue_size > 0 &&	\
+			    (q)->userq_prop->hqd_base_gpu_addr != 0 &&	\
+			    (q)->userq_prop->queue_percentage > 0)
 
 enum amdgpu_userq_state {
 	AMDGPU_USERQ_STATE_UNMAPPED = 0,
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
index 0565986949bd..1a0079a2b47c 100644
@@ -304,6 +304,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	userq_props->use_doorbell = true;
 	userq_props->doorbell_index = queue->doorbell_index;
 	userq_props->fence_address = queue->fence_drv->gpu_addr;
+	userq_props->queue_percentage = AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE;
 
 	if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
 		struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;
include/uapi/drm/amdgpu_drm.h +17 -0
index cfc3a9313229..fab2914ac25c 100644
@@ -331,6 +331,7 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_OP_CREATE	1
 #define AMDGPU_USERQ_OP_FREE	2
 #define AMDGPU_USERQ_OP_MODIFY_CU_MASK	3
+#define AMDGPU_USERQ_OP_MODIFY 4
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -342,6 +343,7 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
 /* for queues that need access to protected content */
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE  (1 << 2)
+#define AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE	100
 
 /*
  * This structure is a container to pass input configuration
@@ -423,6 +425,21 @@ struct drm_amdgpu_userq_in {
 	 * represents 32 CUs/WGPs)
 	 */
 	__u32 cu_mask_count;
+	/**
+	 * @queue_percentage: Queue resource allocation percentage (0-100)
+	 * Defines the percentage of GPU resources allocated to this queue
+	 */
+	__u32 queue_percentage;
+	/**
+	 * @hqd_queue_priority: Hqd Queue priority (0-15)
+	 * Higher values indicate higher scheduling priority for the queue
+	 */
+	__u32 hqd_queue_priority;
+	/**
+	 * @pm4_target_xcc: PM4 target XCC identifier (for gfx9/gfx12.1)
+	 * Specifies the target XCC (Cross Compute Complex) for PM4 commands
+	 */
+	__u32 pm4_target_xcc;
 };
 
 /* The structure to carry output of userqueue ops */
Signature · 1 line
2.49.0
#10 lore raw

Re: [PATCH 7/7] drm/amdgpu: add queue modification support to AMDGPU_USERQ ioctl

Quoted 226 lines · Jesse.Zhang

Extend the AMDGPU_USERQ ioctl to support dynamic modification of existing user mode queues after creation. This provides userspace with the ability to update queue attributes without requiring destruction and recreation of queues.

v2: add a new op for AMDGPU_USERQ. E.g., AMDGPU_USERQ_OP_MODIFY. (Alex)
make the target xcc an explicit parameter. (Alex)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c  | 96 +++++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h  |  3 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c |  1 +
 include/uapi/drm/amdgpu_drm.h              | 17 ++++
 5 files changed, 116 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index a8f4f73fa0ce..ad136145316b 100644
@@ -819,6 +819,9 @@ struct amdgpu_mqd_prop {
        uint32_t cu_mask_count;
        uint32_t cu_flags;
        bool is_user_cu_masked;
+       uint32_t queue_percentage;
+       /* used in gfx9 and gfx12.1 */
+       uint32_t pm4_target_xcc;
 };
 
 struct amdgpu_mqd {
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +92 -4
index 4d7841f47dd3..de267135af69 100644
@@ -34,6 +34,26 @@
 #include "amdgpu_hmm.h"
 #include "amdgpu_userq_fence.h"
 
+/* Mapping queue priority to pipe priority, indexed by queue priority */
+int amdgpu_userq_pipe_priority_map[] = {
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_0,
+       AMDGPU_RING_PRIO_1,
+       AMDGPU_RING_PRIO_1,
+       AMDGPU_RING_PRIO_1,
+       AMDGPU_RING_PRIO_1,
+       AMDGPU_RING_PRIO_2,
+       AMDGPU_RING_PRIO_2,
+       AMDGPU_RING_PRIO_2,
+       AMDGPU_RING_PRIO_2,
+       AMDGPU_RING_PRIO_2
+};
+
 u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev)
 {
        int i;
@@ -906,7 +926,6 @@ static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue)
        struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
        struct amdgpu_device *adev = uq_mgr->adev;
        const struct amdgpu_userq_funcs *uq_funcs;
-       bool unmap_queue = false;
        int r;
 
        uq_funcs = adev->userq_funcs[queue->queue_type];
@@ -922,12 +941,17 @@ static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue)
                r = amdgpu_userq_unmap_helper(queue);
                if (r)
                        return r;
-               unmap_queue = true;
        }
 
        r = uq_funcs->mqd_update(queue);
-
-       if (unmap_queue) {
+       if (r)
+               return r;
+       /*
+        * If the queue is considered active (has valid size, address, and percentage),
+        * we attempt to map it. This effectively starts the queue or restarts it
+        * if it was previously running.
+        */
+       if (AMDGPU_USERQ_IS_ACTIVE(queue)) {
                r = amdgpu_userq_map_helper(queue);
                if (r)
                        drm_file_err(uq_mgr->file, "Failed to remap queue %llu after update\n",
@@ -937,6 +961,65 @@ static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue)
        return r;
 }
 
+static int amdgpu_modify_queue(struct drm_file *filp, union drm_amdgpu_userq *args)
+{
+       struct amdgpu_fpriv *fpriv = filp->driver_priv;
+       struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
+       struct amdgpu_usermode_queue *queue;
+       struct amdgpu_mqd_prop *props;
+       int r;
+
+       if (args->in.queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+               drm_file_err(uq_mgr->file, "Queue percentage must be between 0 to AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE\n");
+               return -EINVAL;
+       }
+
+       /* Validate priority */
+       if (args->in.hqd_queue_priority > AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM) {
+               drm_file_err(uq_mgr->file, "Queue priority must be between 0 to KFD_MAX_QUEUE_PRIORITY\n");
+               return -EINVAL;
+       }
+
+       /* Validate ring size */
+       if (!is_power_of_2(args->in.queue_size) && (args->in.queue_size != 0)) {
+               drm_file_err(uq_mgr->file, "Ring size must be a power of 2 or 0\n");
+               return -EINVAL;
+       }
+
+       if (args->in.queue_size > 0 && args->in.queue_size < AMDGPU_GPU_PAGE_SIZE) {
+               args->in.queue_size = AMDGPU_GPU_PAGE_SIZE;
+               drm_file_err(uq_mgr->file, "Size clamped to AMDGPU_GPU_PAGE_SIZE\n");
+       }
+
+       if ((args->in.queue_va) &&
+               (!access_ok((const void __user *) args->in.queue_va,
+                       sizeof(uint64_t)))) {
+               drm_file_err(uq_mgr->file, "Can't access ring base address\n");
+               return -EFAULT;
+       }
+
+       mutex_lock(&uq_mgr->userq_mutex);
+       queue = amdgpu_userq_find(uq_mgr, args->in.queue_id);
+       if (!queue) {
+               mutex_unlock(&uq_mgr->userq_mutex);
+               return -EINVAL;
+       }
+
+       props = queue->userq_prop;
+       props->queue_size = args->in.queue_size;
+       props->hqd_base_gpu_addr = args->in.queue_va;
+       props->queue_percentage = args->in.queue_percentage;
+       props->pm4_target_xcc = args->in.pm4_target_xcc;
+       props->hqd_pipe_priority = amdgpu_userq_pipe_priority_map[args->in.hqd_queue_priority];
+       props->hqd_queue_priority = args->in.hqd_queue_priority;
+
+       r = amdgpu_userq_update_queue(queue);
+
+       mutex_unlock(&uq_mgr->userq_mutex);
+
+       return r;
+}
+
 static int amdgpu_userq_set_cu_mask(struct drm_file *filp,  union drm_amdgpu_userq *args)
 {
        struct amdgpu_fpriv *fpriv = filp->driver_priv;
@@ -1031,6 +1114,11 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
                amdgpu_userq_set_cu_mask(filp, args);
                break;
 
+       case AMDGPU_USERQ_OP_MODIFY:
+               r = amdgpu_modify_queue(filp, args);
+               if (r)
+                       drm_file_err(filp, "Failed to modify usermode queue\n");
+               break;
        case AMDGPU_USERQ_OP_FREE:
                r = amdgpu_userq_destroy(filp, args->in.queue_id);
                if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
index c80d69368196..078f424e9415 100644
@@ -31,6 +31,9 @@
 #define to_ev_fence(f) container_of(f, struct amdgpu_eviction_fence, base)
 #define uq_mgr_to_fpriv(u) container_of(u, struct amdgpu_fpriv, userq_mgr)
 #define work_to_uq_mgr(w, name) container_of(w, struct amdgpu_userq_mgr, name)
+#define AMDGPU_USERQ_IS_ACTIVE(q) ((q)->userq_prop->queue_size > 0 &&  \
+                           (q)->userq_prop->hqd_base_gpu_addr != 0 &&  \
+                           (q)->userq_prop->queue_percentage > 0)
 
 enum amdgpu_userq_state {
        AMDGPU_USERQ_STATE_UNMAPPED = 0,
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
index 0565986949bd..1a0079a2b47c 100644
@@ -304,6 +304,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
        userq_props->use_doorbell = true;
        userq_props->doorbell_index = queue->doorbell_index;
        userq_props->fence_address = queue->fence_drv->gpu_addr;
+       userq_props->queue_percentage = AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE;
 
        if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
                struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;
include/uapi/drm/amdgpu_drm.h +7 -0
index cfc3a9313229..fab2914ac25c 100644
@@ -331,6 +331,7 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_OP_CREATE 1
 #define AMDGPU_USERQ_OP_FREE   2
 #define AMDGPU_USERQ_OP_MODIFY_CU_MASK 3
+#define AMDGPU_USERQ_OP_MODIFY 4
 
 /* queue priority levels */
 /* low < normal low < normal high < high */
@@ -342,6 +343,7 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
 /* for queues that need access to protected content */
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE  (1 << 2)
+#define AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE      100
 
 /*
  * This structure is a container to pass input configuration
@@ -423,6 +425,21 @@ struct drm_amdgpu_userq_in {
         * represents 32 CUs/WGPs)
         */
        __u32 cu_mask_count;
+       /**
+        * @queue_percentage: Queue resource allocation percentage (0-100)
+        * Defines the percentage of GPU resources allocated to this queue
+        */
+       __u32 queue_percentage;

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_userq_in { · line 442

Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10 -0
+       /**
+        * @hqd_queue_priority: Hqd Queue priority (0-15)
+        * Higher values indicate higher scheduling priority for the queue
+        */
+       __u32 hqd_queue_priority;
+       /**
+        * @pm4_target_xcc: PM4 target XCC identifier (for gfx9/gfx12.1)
+        * Specifies the target XCC (Cross Compute Complex) for PM4 commands
+        */
+       __u32 pm4_target_xcc;

Same comment as patch 6.

Alex

Quoted 6 lines
include/uapi/drm/amdgpu_drm.h +0 -1
 };
 
 /* The structure to carry output of userqueue ops */
--

2.49.0