drm/amd/amdgpu: Add update_mqd callback to amdgpu_mqd struct
Subsystems (3)
PATCH 1/9 drm/amd/amdgpu: Add update_mqd callback to amdgpu_mqd struct
Extend the amdgpu_mqd structure with a new 'update_mqd' callback to support runtime updates of MQD properties for user queues
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -815,6 +815,8 @@ struct amdgpu_mqd {unsigned mqd_size;int (*init_mqd)(struct amdgpu_device *adev,void *mqd,struct amdgpu_mqd_prop *p); +int (*update_mqd)(struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *p); };struct amdgpu_pcie_reset_ctx {
Signature · 1 line
2.49.0
PATCH 2/9 drm/amd/amdgpu: Add mqd_update callback to amdgpu_userq_funcs
Extend the amdgpu_usermode_queue function table (amdgpu_userq_funcs) with a new 'mqd_update' callback to support runtime updates of user queue MQD configurations.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 19 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 +++ 2 files changed, 22 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +19 -0
@@ -811,6 +811,25 @@ struct amdgpu_mqd_prop {bool kernel_queue; }; + +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 */ +}; + +/* MQD update information container (aligned with KFD) */ +struct amdgpu_mqd_update_info { +union { +struct { +/* Must be multiple of 32 */ +uint32_t count; +uint32_t *ptr; + } cu_mask; + }; +enum amdgpu_mqd_update_flag update_flag; +}; +struct amdgpu_mqd {unsigned mqd_size; int (*init_mqd)(struct amdgpu_device *adev, void *mqd,
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
@@ -41,6 +41,7 @@ enum amdgpu_userq_state { };struct amdgpu_mqd_prop ; +struct amdgpu_mqd_update_info ;struct amdgpu_userq_obj {void *cpu_ptr;
@@ -79,6 +80,8 @@ 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, +struct amdgpu_mqd_update_info *minfo);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
PATCH 3/9 drm/amd/amdgpu/gfx11: Implement GFX11 MQD update callbacks for COMPUTE IPs
In reply to Jesse.ZhangAdd architecture-specific 'update_mqd' callbacks for GFX11 to support runtime MQD priority updates.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 79 ++++++++++++++++---------- 1 file changed, 49 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +49 -30
@@ -4238,11 +4238,55 @@ static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)return gfx_v11_0_cp_gfx_start (adev); } +/** +* gfx_v11_0_compute_update_queue - Update runtime-configurable queue parameters +* @adev: amdgpu device pointer +* @mqd: MQD structure to update +* @prop: MQD properties containing updated configuration parameters +*/ +static int gfx_v11_0_compute_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop) +{ +struct v11_compute_mqd *mqd = m; +uint64_t hqd_gpu_addr; +uint32_t tmp; + +/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */ + hqd_gpu_addr = prop->hqd_base_gpu_addr >>8 ; + mqd->cp_hqd_pq_base_lo = hqd_gpu_addr; + mqd->cp_hqd_pq_base_hi =upper_32_bits (hqd_gpu_addr); + +/* set up the HQD, this is similar to CP_RB0_CNTL */ + tmp = regCP_HQD_PQ_CONTROL_DEFAULT; + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,QUEUE_SIZE , + (order_base_2 (prop->queue_size /4 ) -1 )); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,RPTR_BLOCK_SIZE , + (order_base_2 (AMDGPU_GPU_PAGE_SIZE /4 ) -1 )); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,UNORD_DISPATCH ,1 ); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TUNNEL_DISPATCH , + prop->allow_tunneling); +if (prop->kernel_queue) { + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,PRIV_STATE ,1 ); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,KMD_QUEUE ,1 ); + } +if (prop->tmz_queue) + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TMZ ,1 ); + mqd->cp_hqd_pq_control = tmp; + +/* set static priority for a compute queue/ring */ + mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority; + mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; + + mqd->cp_hqd_active = prop->hqd_active; + +return 0 ; +} +static int gfx_v11_0_compute_mqd_init (struct amdgpu_device *adev,void *m,struct amdgpu_mqd_prop *prop) {struct v11_compute_mqd *mqd = m; -uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr; +uint64_t wb_gpu_addr, eop_base_addr;uint32_t tmp; mqd->header =0xC0310800 ;
@@ -4298,28 +4342,6 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m, tmp =REG_SET_FIELD (tmp,CP_MQD_CONTROL ,VMID ,0 ); mqd->cp_mqd_control = tmp; -/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */ - hqd_gpu_addr = prop->hqd_base_gpu_addr >>8 ; - mqd->cp_hqd_pq_base_lo = hqd_gpu_addr; - mqd->cp_hqd_pq_base_hi =upper_32_bits (hqd_gpu_addr); - -/* set up the HQD, this is similar to CP_RB0_CNTL */ - tmp = regCP_HQD_PQ_CONTROL_DEFAULT; - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,QUEUE_SIZE , - (order_base_2 (prop->queue_size /4 ) -1 )); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,RPTR_BLOCK_SIZE , - (order_base_2 (AMDGPU_GPU_PAGE_SIZE /4 ) -1 )); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,UNORD_DISPATCH ,1 ); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TUNNEL_DISPATCH , - prop->allow_tunneling); -if (prop->kernel_queue) { - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,PRIV_STATE ,1 ); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,KMD_QUEUE ,1 ); - } -if (prop->tmz_queue) - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TMZ ,1 ); - mqd->cp_hqd_pq_control = tmp; -/* set the wb address whether it's enabled or not */ wb_gpu_addr = prop->rptr_gpu_addr; mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr &0xfffffffc ;
@@ -4363,17 +4385,12 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m, tmp =REG_SET_FIELD (tmp,CP_HQD_IB_CONTROL ,MIN_IB_AVAIL_SIZE ,3 ); mqd->cp_hqd_ib_control = tmp; -/* set static priority for a compute queue/ring */ - mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority; - mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; - - mqd->cp_hqd_active = prop->hqd_active; -/* set UQ fenceaddress */ mqd->fence_address_lo =lower_32_bits (prop->fence_address); mqd->fence_address_hi =upper_32_bits (prop->fence_address); -return 0 ; +/* Initialize runtime-configurable parameters */ +return gfx_v11_0_compute_mqd_update (adev, mqd, prop); }static int gfx_v11_0_kiq_init_register (struct amdgpu_ring *ring)
@@ -7423,6 +7440,8 @@ static void gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v11_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v11_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v11_0_compute_mqd_update; } static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
PATCH 4/9 drm/amd/amdgpu/gfx11: Add CU mask and priority support to GFX11 compute MQD update
In reply to Jesse.Zhang- Extend amdgpu_mqd_prop with CU mask fields and debug WA flags
- Implement GFX11 CU mask mapping (WGP mode) and MQD setters for CU mask/priority
- Integrate setters into gfx_v11_0_compute_mqd_update() to apply runtime changes
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 82 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -809,6 +809,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; };
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +82 -0
94 lines not on this page · raw message
Signature · 1 line
2.49.0
Re: [PATCH 4/9] drm/amd/amdgpu/gfx11: Add CU mask and priority support to GFX11 compute MQD update
Quoted 31 lines · Jesse.Zhang
- Extend
amdgpu_mqd_propwith CU mask fields and debug WA flags
- Implement GFX11 CU mask mapping (WGP mode) and MQD setters for CU mask/priority
- Integrate setters intogfx_v11_0_compute_mqd_update()to apply runtime changesSigned-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 82 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -809,6 +809,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; };drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev) · line 4244
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0@@ -4238,6 +4238,87 @@ 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_mqd_symmetrically_map_cu_mask (struct amdgpu_device *adev, +const uint32_t *cu_mask, +uint32_t cu_mask_count, +uint32_t *se_mask)
This looks generic. We could probably make this amdgpu_gfx_mqd_symmetrically_map_cu_mask() and use it for both gfx11 and 12.
Alex
Quoted 91 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +78
-1+{ +struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info; +struct amdgpu_gfx_config *gfx_info = &adev->gfx.config; +uint32_t cu_per_sh[8 ][4 ] = {0 }; +int i, se, sh, cu, cu_bitmap_sh_mul; +int xcc_inst =ffs (adev->gfx.xcc_mask) -1 ; +int cu_inc =2 ;/* WGP mode */ +int num_xcc, inc, inst =0 ; +uint32_t en_mask =3 ; + +if (xcc_inst <0 ) + xcc_inst =0 ; + + num_xcc =hweight16 (adev->gfx.xcc_mask); +if (!num_xcc) + num_xcc =1 ; + + inc = cu_inc * num_xcc; + + cu_bitmap_sh_mul =2 ; + +for (se =0 ; se < gfx_info->max_shader_engines; se++) +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) + cu_per_sh[se][sh] =hweight32 ( + cu_info->bitmap[xcc_inst][se %4 ][sh + (se /4 ) * + cu_bitmap_sh_mul]); + +for (i =0 ; i < gfx_info->max_shader_engines; i++) + se_mask[i] =0 ; + + i = inst; +for (cu =0 ; cu <16 ; cu += cu_inc) { +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) { +for (se =0 ; se < gfx_info->max_shader_engines; se++) { +if (cu_per_sh[se][sh] > cu) { +if ((i /32 ) < cu_mask_count && (cu_mask[i /32 ] & (1 << (i %32 )))) + se_mask[se] |= en_mask << (cu + sh *16 ); + i += inc; +if (i >= cu_mask_count *32 ) +return ; + } + } + } + } +} + +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 ; + } + +gfx_v11_0_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 ]; +} +/** * gfx_v11_0_compute_update_queue - Update runtime-configurable queue parameters * @adev: amdgpu device pointer @@ -4278,6 +4359,7 @@ static int gfx_v11_0_compute_mqd_update(struct amdgpu_device *adev, void *m, mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; mqd->cp_hqd_active = prop->hqd_active; +gfx_v11_0_compute_mqd_set_cu_mask (adev, mqd, prop);return 0 ; } --2.49.0
RE: [PATCH 4/9] drm/amd/amdgpu/gfx11: Add CU mask and priority support to GFX11 compute MQD update
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 49 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, January 23, 2026 4:08 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 4/9] drm/amd/amdgpu/gfx11: Add CU mask and priority support to GFX11 compute MQD updatedrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int
Quoted 36 lines · Jesse.Zhang
- Extend
amdgpu_mqd_propwith CU mask fields and debug WA flags
- Implement GFX11 CU mask mapping (WGP mode) and MQD setters for CU mask/priority
- Integrate setters intogfx_v11_0_compute_mqd_update()to apply runtime changesSigned-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 82 ++++++++++++++++++++++++++ 2 files changed, 86 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -809,6 +809,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; };drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -4238,6 +4238,87 @@ static int
gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0return gfx_v11_0_cp_gfx_start (adev); }
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int · line 4240
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-0+static void gfx_v11_0_mqd_symmetrically_map_cu_mask(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev) · line 4244
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+const uint32_t *cu_mask, + uint32_t cu_mask_count, + uint32_t *se_mask)This looks generic. We could probably make this
amdgpu_gfx_mqd_symmetrically_map_cu_mask()and use it for both gfx11 and 12.
Make sense, and will update the function.
Thanks
Jesse
Quoted 101 lines
Alex
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +26
-0+{ +struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info; +struct amdgpu_gfx_config *gfx_info = &adev->gfx.config; +uint32_t cu_per_sh[8 ][4 ] = {0 }; +int i, se, sh, cu, cu_bitmap_sh_mul; +int xcc_inst =ffs (adev->gfx.xcc_mask) -1 ; +int cu_inc =2 ;/* WGP mode */ +int num_xcc, inc, inst =0 ; +uint32_t en_mask =3 ; + +if (xcc_inst <0 ) + xcc_inst =0 ; + + num_xcc =hweight16 (adev->gfx.xcc_mask); +if (!num_xcc) + num_xcc =1 ; + + inc = cu_inc * num_xcc; + + cu_bitmap_sh_mul =2 ; + +for (se =0 ; se < gfx_info->max_shader_engines; se++) +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) + cu_per_sh[se][sh] =hweight32 ( + cu_info->bitmap[xcc_inst][se %4 ][sh + (se /4 ) * + cu_bitmap_sh_mul]);drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+ +for (i =0 ; i < gfx_info->max_shader_engines; i++) + se_mask[i] =0 ; + + i = inst; +for (cu =0 ; cu <16 ; cu += cu_inc) { +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) { +for (se =0 ; se < gfx_info->max_shader_engines; se++) { +if (cu_per_sh[se][sh] > cu) { + if ((i / 32) < cu_mask_count && (cu_mask[i / 32] & (1 <<(i % 32))))
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +11
-0+ se_mask[se] |= en_mask << (cu + sh *16 ); + i += inc; +if (i >= cu_mask_count *32 ) +return ; + } + } + } + } +} + +static void gfx_v11_0_compute_mqd_set_cu_mask(struct amdgpu_device*adev,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+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|drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8
-0+ +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) ?Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +9
-0+ 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 ; + } + + gfx_v11_0_mqd_symmetrically_map_cu_mask(adev, prop->cu_mask,drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8
-0+ 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 ]; } +/** * gfx_v11_0_compute_update_queue - Update runtime-configurable queue parameters
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_compute_mqd_update(struct
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0* @adev: amdgpu device pointer @@ -4278,6 +4359,7 @@ static int gfx_v11_0_compute_mqd_update(struct
amdgpu_device*adev, void *m,Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1
-1mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; mqd->cp_hqd_active = prop->hqd_active; +gfx_v11_0_compute_mqd_set_cu_mask (adev, mqd, prop);return 0 ; } --2.49.0
PATCH 5/9 drm/amd/amdgpu/gfx12: Implement GFX12 MQD update callbacks for GFX/COMPUTE IPs
In reply to Jesse.ZhangAdd architecture-specific 'update_mqd' callbacks for GFX12 to support runtime MQD priority updates.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 74 ++++++++++++++++---------- 1 file changed, 46 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +46 -28
@@ -3110,11 +3110,54 @@ static int gfx_v12_0_cp_async_gfx_ring_resume(struct amdgpu_device *adev)return gfx_v12_0_cp_gfx_start (adev); } +/** +* gfx_v12_0_compute_update_queue - Update runtime-configurable queue parameters +* @adev: amdgpu device pointer +* @mqd: MQD structure to update +* @prop: MQD properties containing updated configuration parameters +*/ +static int gfx_v12_0_compute_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop) +{ +struct v12_compute_mqd *mqd = m; +uint64_t hqd_gpu_addr; +uint32_t tmp; + +/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */ + hqd_gpu_addr = prop->hqd_base_gpu_addr >>8 ; + mqd->cp_hqd_pq_base_lo = hqd_gpu_addr; + mqd->cp_hqd_pq_base_hi =upper_32_bits (hqd_gpu_addr); + +/* set up the HQD, this is similar to CP_RB0_CNTL */ + tmp = regCP_HQD_PQ_CONTROL_DEFAULT; + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,QUEUE_SIZE , + (order_base_2 (prop->queue_size /4 ) -1 )); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,RPTR_BLOCK_SIZE , + (order_base_2 (AMDGPU_GPU_PAGE_SIZE /4 ) -1 )); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,UNORD_DISPATCH ,1 ); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TUNNEL_DISPATCH ,0 ); +if (prop->kernel_queue) { + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,PRIV_STATE ,1 ); + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,KMD_QUEUE ,1 ); + } +if (prop->tmz_queue) + tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TMZ ,1 ); + mqd->cp_hqd_pq_control = tmp; + +/* set static priority for a compute queue/ring */ + mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority; + mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; + + mqd->cp_hqd_active = prop->hqd_active; + +return 0 ; +} +static int gfx_v12_0_compute_mqd_init (struct amdgpu_device *adev,void *m,struct amdgpu_mqd_prop *prop) {struct v12_compute_mqd *mqd = m; -uint64_t hqd_gpu_addr, wb_gpu_addr, eop_base_addr; +uint64_t wb_gpu_addr, eop_base_addr;uint32_t tmp; mqd->header =0xC0310800 ;
@@ -3170,27 +3213,6 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m, tmp =REG_SET_FIELD (tmp,CP_MQD_CONTROL ,VMID ,0 ); mqd->cp_mqd_control = tmp; -/* set the pointer to the HQD, this is similar CP_RB0_BASE/_HI */ - hqd_gpu_addr = prop->hqd_base_gpu_addr >>8 ; - mqd->cp_hqd_pq_base_lo = hqd_gpu_addr; - mqd->cp_hqd_pq_base_hi =upper_32_bits (hqd_gpu_addr); - -/* set up the HQD, this is similar to CP_RB0_CNTL */ - tmp = regCP_HQD_PQ_CONTROL_DEFAULT; - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,QUEUE_SIZE , - (order_base_2 (prop->queue_size /4 ) -1 )); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,RPTR_BLOCK_SIZE , - (order_base_2 (AMDGPU_GPU_PAGE_SIZE /4 ) -1 )); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,UNORD_DISPATCH ,1 ); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TUNNEL_DISPATCH ,0 ); -if (prop->kernel_queue) { - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,PRIV_STATE ,1 ); - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,KMD_QUEUE ,1 ); - } -if (prop->tmz_queue) - tmp =REG_SET_FIELD (tmp,CP_HQD_PQ_CONTROL ,TMZ ,1 ); - mqd->cp_hqd_pq_control = tmp; -/* set the wb address whether it's enabled or not */ wb_gpu_addr = prop->rptr_gpu_addr; mqd->cp_hqd_pq_rptr_report_addr_lo = wb_gpu_addr &0xfffffffc ;
@@ -3234,12 +3256,6 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m, tmp =REG_SET_FIELD (tmp,CP_HQD_IB_CONTROL ,MIN_IB_AVAIL_SIZE ,3 ); mqd->cp_hqd_ib_control = tmp; -/* set static priority for a compute queue/ring */ - mqd->cp_hqd_pipe_priority = prop->hqd_pipe_priority; - mqd->cp_hqd_queue_priority = prop->hqd_queue_priority; - - mqd->cp_hqd_active = prop->hqd_active; -/* set UQ fenceaddress */ mqd->fence_address_lo =lower_32_bits (prop->fence_address); mqd->fence_address_hi =upper_32_bits (prop->fence_address);
@@ -5669,6 +5685,8 @@ static void gfx_v12_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v12_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v12_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v12_0_compute_mqd_update; } static void gfx_v12_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
PATCH 6/9 drm/amd/amdgpu/gfx12: Add CU mask and priority support to GFX12 compute MQD update
In reply to Jesse.Zhang- Extend amdgpu_mqd_prop with CU mask fields and debug WA flags
- Implement GFX12 CU mask mapping (WGP mode) and MQD setters for CU mask/priority
- Integrate setters into gfx_v12_0_compute_mqd_update() to apply runtime changes
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 74 ++++++++++++++++++++++++++ 1 file changed, 74 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +74 -0
@@ -3110,6 +3110,79 @@ 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_mqd_symmetrically_map_cu_mask (struct amdgpu_device *adev, +const uint32_t *cu_mask, +uint32_t cu_mask_count, +uint32_t *se_mask) +{ +struct amdgpu_cu_info *cu_info = &adev->gfx.cu_info; +struct amdgpu_gfx_config *gfx_info = &adev->gfx.config; +uint32_t cu_per_sh[8 ][4 ] = {0 }; +int i, se, sh, cu; +const int xcc_inst =0 ; +int cu_inc =2 ;/* WGP mode */ +int num_xcc =1 ; +int inc = cu_inc * num_xcc; +int inst =0 ; +uint32_t en_mask =3 ; +int cu_bitmap_sh_mul =2 ; + +for (se =0 ; se < gfx_info->max_shader_engines; se++) +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) + cu_per_sh[se][sh] =hweight32 ( + cu_info->bitmap[xcc_inst][se %4 ][sh + (se /4 ) * + cu_bitmap_sh_mul]); + +for (i =0 ; i < gfx_info->max_shader_engines; i++) + se_mask[i] =0 ; + + i = inst; +for (cu =0 ; cu <16 ; cu += cu_inc) { +for (sh =0 ; sh < gfx_info->max_sh_per_se; sh++) { +for (se =0 ; se < gfx_info->max_shader_engines; se++) { +if (cu_per_sh[se][sh] > cu) { +if ((i /32 ) < cu_mask_count && (cu_mask[i /32 ] & (1 << (i %32 )))) + se_mask[se] |= en_mask << (cu + sh *16 ); + i += inc; +if (i >= cu_mask_count *32 ) +return ; + } + } + } + } +} + +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 ; + } + +gfx_v12_0_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 ]; +} +/** * gfx_v12_0_compute_update_queue - Update runtime-configurable queue parameters * @adev: amdgpu device pointer
@@ -3150,6 +3223,7 @@ static int gfx_v12_0_compute_mqd_update(struct amdgpu_device *adev, void *m, mqd->cp_hqd_active = prop->hqd_active; +gfx_v12_0_compute_mqd_set_cu_mask (adev, mqd, prop);return 0 ; }
Signature · 1 line
2.49.0
PATCH 7/9 amdgpu: Add MQD update functionality for user queues
In reply to Jesse.ZhangThis patch adds support for updating MQD
properties for user queues, specifically focusing on CU mask updates.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +34 -0
@@ -432,6 +432,39 @@ 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 +* @minfo: MQD update information (CU mask/priority etc.) +* +* Return: 0 on success, negative error code on failure +*/ +static int mes_userq_mqd_update (struct amdgpu_usermode_queue *queue, +struct amdgpu_mqd_update_info *minfo) +{ +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 (minfo) { + props->cu_flags = minfo->update_flag; + props->cu_mask_count = minfo->cu_mask.count; + props->cu_mask = minfo->cu_mask.ptr; + } + +if (mqd_hw_default->update_mqd) + retval = mqd_hw_default->update_mqd (adev, (void *)queue->mqd.cpu_ptr, props); + +if (!retval && minfo) + 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 +546,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
Re: [PATCH 7/9] amdgpu: Add MQD update functionality for user queues
Quoted 25 lines · Jesse.Zhang
This patch adds support for updating MQD
properties for user queues, specifically focusing on CU mask updates.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+)drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +8
-0@@ -432,6 +432,39 @@ 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 +* @minfo: MQD update information (CU mask/priority etc.) +* +* Return: 0 on success, negative error code on failure +*/ +static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue,
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue, · line 452
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +10
-0+ struct amdgpu_mqd_update_info *minfo) +{ +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 ; +
Should return an error for non-compute queues.
Alex
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +16
-1+if (minfo) { + props->cu_flags = minfo->update_flag; + props->cu_mask_count = minfo->cu_mask.count; + props->cu_mask = minfo->cu_mask.ptr; + } + +if (mqd_hw_default->update_mqd) + retval = mqd_hw_default->update_mqd (adev, (void *)queue->mqd.cpu_ptr, props); + +if (!retval && minfo) + 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 +546,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, --2.49.0
PATCH 8/9 drm/amdgpu: Add ioctl for setting user queue CU mask
In reply to Jesse.ZhangThis patch introduces a new DRM ioctl to allow userspace to set the CU (Compute Unit) mask for user queues, enabling fine-grained control over compute workload distribution.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 107 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 3 + include/uapi/drm/amdgpu_drm.h | 12 +++ 4 files changed, 123 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3075,6 +3075,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ , amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SET_CU_MASK , amdgpu_userq_set_cu_mask_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_WAIT , amdgpu_userq_wait_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(AMDGPU_GEM_LIST_HANDLES, amdgpu_gem_list_handles_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +107 -0
113 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3 -0
@@ -115,6 +115,9 @@ struct amdgpu_db_info {int amdgpu_userq_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_userq_set_cu_mask_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct drm_file *file_priv,struct amdgpu_device *adev);
include/uapi/drm/amdgpu_drm.h +12 -0
@@ -58,6 +58,7 @@ extern "C" {#define DRM_AMDGPU_USERQ_SIGNAL 0x17#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19 +#define DRM_AMDGPU_USERQ_SET_CU_MASK 0x1a#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -79,6 +80,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_SIGNAL DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SIGNAL, struct drm_amdgpu_userq_signal)#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles) +#define DRM_IOCTL_AMDGPU_USERQ_SET_CU_MASK DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SET_CU_MASK, struct amdgpu_userq_set_cu_mask_args)/** * DOC: memory domains
@@ -428,6 +430,16 @@ union drm_amdgpu_userq {struct drm_amdgpu_userq_out out; }; +/* IOCTL arguments for setting user queue CU mask */ +struct amdgpu_userq_set_cu_mask_args { +/* Target user queue ID */ +__u32 queue_id; +/* CU mask bit count (multiple of 32) */ +__u32 num_cu_mask; +/* User-space pointer to CU mask data */ +__u64 cu_mask_ptr; +}; +/* GFX V11 IP specific MQD parameters */ struct drm_amdgpu_userq_mqd_gfx11 {/**
Signature · 1 line
2.49.0
PATCH 9/9 drm/amdgpu: Add queue update IOCTL support
In reply to Jesse.ZhangAdd AMDGPU_USERQ_UPDATE_QUEUE IOCTL to support updating user mode queue properties after creation. This allows userspace to modify queue attributes like ring buffer address, ring size, queue priority, and queue percentage dynamically.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 106 +++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 6 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + include/uapi/drm/amdgpu_drm.h | 13 +++ 6 files changed, 122 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
@@ -813,6 +813,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; };
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3075,6 +3075,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ , amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_UPDATE_QUEUE , amdgpu_update_queue_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SET_CU_MASK , amdgpu_userq_set_cu_mask_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +98 -8
134 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +6 -0
@@ -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 ,
@@ -118,6 +121,9 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filpint amdgpu_userq_set_cu_mask_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_update_queue_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct drm_file *file_priv,struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1 -0
@@ -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 =100 ;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;
include/uapi/drm/amdgpu_drm.h +13 -0
@@ -59,6 +59,7 @@ extern "C" {#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19#define DRM_AMDGPU_USERQ_SET_CU_MASK 0x1a +#define DRM_AMDGPU_USERQ_UPDATE_QUEUE 0x1b#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -81,6 +82,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)#define DRM_IOCTL_AMDGPU_USERQ_SET_CU_MASK DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SET_CU_MASK, struct amdgpu_userq_set_cu_mask_args) +#define DRM_IOCTL_AMDGPU_USERQ_UPDATE_QUEUE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_UPDATE_QUEUE, struct amdgpu_userq_update_queue_args)/** * DOC: memory domains
@@ -343,6 +345,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
@@ -440,6 +443,16 @@ struct amdgpu_userq_set_cu_mask_args {__u64 cu_mask_ptr; }; + +/* IOCTL parameters used to set user queue updates */ +struct amdgpu_userq_update_queue_args { +__u64 ring_base_address; +__u32 queue_id; +__u32 ring_size; +__u32 queue_percentage; +__u32 queue_priority; +}; +/* GFX V11 IP specific MQD parameters */ struct drm_amdgpu_userq_mqd_gfx11 {/**
Signature · 1 line
2.49.0
Re: [PATCH 9/9] drm/amdgpu: Add queue update IOCTL support
Quoted 35 lines · Jesse.Zhang
Add
AMDGPU_USERQ_UPDATE_QUEUEIOCTL to support updating user mode queue properties after creation. This allows userspace to modify queue attributes like ring buffer address, ring size, queue priority, and queue percentage dynamically.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 106 +++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 6 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + include/uapi/drm/amdgpu_drm.h | 13 +++ 6 files changed, 122 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -813,6 +813,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; };drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3078
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -3075,6 +3075,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ , amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_UPDATE_QUEUE, amdgpu_update_queue_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
I don't think we need a new IOCTL. Just a new op for AMDGPU_USERQ. E.g., AMDGPU_USERQ_OP_MODIFY
Quoted 79 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SET_CU_MASK , amdgpu_userq_set_cu_mask_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_SIGNAL , amdgpu_userq_signal_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +36
-8@@ -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;@@ -907,7 +927,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];@@ -923,23 +942,94 @@ 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, minfo); +if (r) +return r; -if (unmap_queue) { -int map_r =amdgpu_userq_map_helper (queue); -if (map_r) -dev_err (adev->dev,"Failed to remap queue %llu after update\n" , +/* +* 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" , queue->doorbell_index); -if (!r) - r = map_r; }return r; } +int amdgpu_update_queue_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue, · line 980
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+struct amdgpu_userq_update_queue_args *args = data; +struct amdgpu_usermode_queue *queue; +struct amdgpu_mqd_prop *props; +int r; + +/* +* Repurpose queue percentage to accommodate new features: +* bit 0-7: queue percentage +* bit 8-15: pm4_target_xcc +*/
Just make the target xcc an explicit parameter.
Quoted 31 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +31
-0+if ((args->queue_percentage &0xFF ) >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->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->ring_size) && (args->ring_size !=0 )) { +drm_file_err (uq_mgr->file,"Ring size must be a power of 2 or 0\n" ); +return -EINVAL ; + } + +if (args->ring_size >0 && args->ring_size <AMDGPU_GPU_PAGE_SIZE ) { + args->ring_size =AMDGPU_GPU_PAGE_SIZE ; +drm_file_err (uq_mgr->file,"Size clamped to AMDGPU_GPU_PAGE_SIZE\n" ); + } + +if ((args->ring_base_address) && + (!access_ok ((const void __user *) args->ring_base_address, +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->queue_id);
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue, · line 1021
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+if (!queue) { +mutex_unlock (&uq_mgr->userq_mutex); +return -EINVAL ; + } + + props = queue->userq_prop; + props->queue_size = args->ring_size; + props->hqd_base_gpu_addr = args->ring_base_address; + props->queue_percentage = args->queue_percentage &0xFF ; +/* bit 8-15 are repurposed to be PM4 target XCC */
We should handle this explicitly rather than stashing it in percentage.
Quoted 79 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11
-0+ props->pm4_target_xcc = (args->queue_percentage >>8 ) &0xFF ; + props->hqd_pipe_priority = amdgpu_userq_pipe_priority_map[args->queue_priority]; + props->hqd_queue_priority = args->queue_priority; + + r =amdgpu_userq_update_queue (queue,NULL ); + +mutex_unlock (&uq_mgr->userq_mutex); + +return r; +} +int amdgpu_userq_set_cu_mask_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +6
-0@@ -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 ,@@ -118,6 +121,9 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filpint amdgpu_userq_set_cu_mask_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +int amdgpu_update_queue_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); +int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct drm_file *file_priv,struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0@@ -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 =100 ;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;include/uapi/drm/amdgpu_drm.h +3
-0@@ -59,6 +59,7 @@ extern "C" {#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19#define DRM_AMDGPU_USERQ_SET_CU_MASK 0x1a +#define DRM_AMDGPU_USERQ_UPDATE_QUEUE 0x1b#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)@@ -81,6 +82,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_WAIT DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)#define DRM_IOCTL_AMDGPU_USERQ_SET_CU_MASK DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_SET_CU_MASK, struct amdgpu_userq_set_cu_mask_args) +#define DRM_IOCTL_AMDGPU_USERQ_UPDATE_QUEUE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_UPDATE_QUEUE, struct amdgpu_userq_update_queue_args)/** * DOC: memory domains @@ -343,6 +345,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
include/uapi/drm/amdgpu_drm.h struct amdgpu_userq_set_cu_mask_args { · line 451
Quoted 9 lines
include/uapi/drm/amdgpu_drm.h +6
-0@@ -440,6 +443,16 @@ struct amdgpu_userq_set_cu_mask_args {__u64 cu_mask_ptr; }; + +/* IOCTL parameters used to set user queue updates */ +struct amdgpu_userq_update_queue_args { +__u64 ring_base_address; +__u32 queue_id; +__u32 ring_size;
Do we actually need to be able to change the ring base address and size? I know KFD can do it, but we should verify if we really need to be able to change the ring size at runtime.
include/uapi/drm/amdgpu_drm.h struct amdgpu_userq_set_cu_mask_args { · line 453
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +2
-0+__u32 queue_percentage; +__u32 queue_priority;
We should probably also make these available for USERQ create as well. I would fold CU mask in as well.
Alex
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2
-1+}; +/* GFX V11 IP specific MQD parameters */ struct drm_amdgpu_userq_mqd_gfx11 {/** -- 2.49.0
RE: [PATCH 9/9] drm/amdgpu: Add queue update IOCTL support
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 51 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, January 23, 2026 4:33 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 9/9] drm/amdgpu: Add queue update IOCTL supportQuoted 2 lines · Jesse.Zhang
Add
AMDGPU_USERQ_UPDATE_QUEUEIOCTL to support updating usermode
Quoted 9 lines
queue properties after creation. This allows userspace to modify queue attributes like ring buffer address, ring size, queue priority, and queue percentage dynamically.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 106 +++++++++++++++++++--
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 6 ++ drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 1 + include/uapi/drm/amdgpu_drm.h | 13 +++ 6 files changed, 122 insertions(+), 8 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -813,6 +813,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; };drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3075
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -3075,6 +3075,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl,DRM_AUTH|DRM_RENDER_ALLOW),
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3076
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR,
Quoted 8 lines
amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3080
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-0DRM_IOCTL_DEF_DRV (AMDGPU_USERQ , amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (AMDGPU_USERQ_UPDATE_QUEUE , + amdgpu_update_queue_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),I don't think we need a new IOCTL. Just a new op for
AMDGPU_USERQ. E.g.,AMDGPU_USERQ_OP_MODIFY
Yes, will fix it.
Maybe we can add a new op for CU mask too.
Like AMDGPU_USERQ_OP_CU_MASK.
Thanks
Jesse
Quoted 281 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { · line 3081
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SET_CU_MASK,
amdgpu_userq_set_cu_mask_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),Quoted 1 line
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL,
amdgpu_userq_signal_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),Quoted 1 line
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT,
amdgpu_userq_wait_ioctl,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct
Quoted 33 lines
DRM_AUTH|DRM_RENDER_ALLOW), diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index4cbf75723c08..922f73b92db3100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +20
-0@@ -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;@@ -907,7 +927,6 @@ static int amdgpu_userq_update_queue(struct
amdgpu_usermode_queue*queue,drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1struct 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];@@ -923,23 +942,94 @@ static int amdgpu_userq_update_queue(struct
amdgpu_usermode_queue*queue,Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +0
-1r =amdgpu_userq_unmap_helper (queue);if (r)return r; - unmap_queue = true; }drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +4
-4r = uq_funcs->mqd_update (queue, minfo); +if (r) +return r; -if (unmap_queue) { -int map_r =amdgpu_userq_map_helper (queue); -if (map_r) - dev_err(adev->dev, "Failed to remap queue %llu after update\n", +/* +* If the queue is considered active (has valid size, address, and percentage),
Quoted 20 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +12
-2+* 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", queue->doorbell_index); -if (!r) - r = map_r; }return r; } +int amdgpu_update_queue_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) { +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue, · line 980
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+struct amdgpu_userq_update_queue_args *args = data; +struct amdgpu_usermode_queue *queue; +struct amdgpu_mqd_prop *props; +int r; + +/* +* Repurpose queue percentage to accommodate new features: +* bit 0-7: queue percentage +* bit 8-15: pm4_target_xcc +*/ Just make the target xcc an explicit parameter.
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct · line 981
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ if ((args->queue_percentage & 0xFF) >
AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct · line 982
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ drm_file_err(uq_mgr->file, "Queue percentage must be between 0 toAMDGPU_USERQ_MAX_QUEUE_PERCENTAGE\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue,
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +5
-0+return -EINVAL ; + } + +/* Validate priority */ + if (args->queue_priority >
AMDGPU_GFX_QUEUE_PRIORITY_MAXIMUM) {drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct · line 988
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +1
-0+ drm_file_err(uq_mgr->file, "Queue priority must be between 0 toKFD_MAX_QUEUE_PRIORITY\n");
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+return -EINVAL ; + } + +/* Validate ring size */ +if (!is_power_of_2 (args->ring_size) && (args->ring_size !=0 )) { +drm_file_err (uq_mgr->file,"Ring size must be a power of 2 or 0\n" ); +return -EINVAL ; + } + +if (args->ring_size >0 && args->ring_size <AMDGPU_GPU_PAGE_SIZE ){
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct · line 1000
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +2
-0+ args->ring_size =AMDGPU_GPU_PAGE_SIZE ; + drm_file_err(uq_mgr->file, "Size clamped toAMDGPU_GPU_PAGE_SIZE\n");
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11
-0+ } + +if ((args->ring_base_address) && + (!access_ok ((const void __user *) args->ring_base_address, +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->queue_id);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c static int amdgpu_userq_update_queue(struct amdgpu_usermode_queue *queue, · line 1021
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +10
-0+if (!queue) { +mutex_unlock (&uq_mgr->userq_mutex); +return -EINVAL ; + } + + props = queue->userq_prop; + props->queue_size = args->ring_size; + props->hqd_base_gpu_addr = args->ring_base_address; + props->queue_percentage = args->queue_percentage &0xFF ; +/* bit 8-15 are repurposed to be PM4 target XCC */ We should handle this explicitly rather than stashing it in percentage.
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +11
-1+ props->pm4_target_xcc = (args->queue_percentage >>8 ) &0xFF ; + props->hqd_pipe_priority = amdgpu_userq_pipe_priority_map[args- queue_priority]; + props->hqd_queue_priority = args->queue_priority; + + r =amdgpu_userq_update_queue (queue,NULL ); + +mutex_unlock (&uq_mgr->userq_mutex); + +return r; +} +int amdgpu_userq_set_cu_mask_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index43bf104d2fb8..c8ea81c17c6e100644drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +0
-0@@ -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,Quoted 3 lines
userq_mgr) #definework_to_uq_mgr(w, name)container_of(w, struct amdgpu_userq_mgr, name)
+#defineAMDGPU_USERQ_IS_ACTIVE(q)((q)->userq_prop->queue_size > 0&& \
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +2
-0+ (q)->userq_prop->hqd_base_gpu_addr != 0 && \ + (q)->userq_prop->queue_percentage > 0) enum amdgpu_userq_state { AMDGPU_USERQ_STATE_UNMAPPED = 0, @@ -118,6 +121,9 @@ intamdgpu_userq_ioctl(struct
drm_device*dev, void *data, structdrm_file*filp int amdgpu_userq_set_cu_mask_ioctl(structdrm_device*dev, void *data,struct drm_file *filp);drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +3
-0+int amdgpu_update_queue_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp); + int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct
drm_file*file_priv,drivers/gpu/drm/amd/amdgpu/mes_userqueue.c static int mes_userq_mqd_create(struct
Quoted 8 lines
struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0
-0@@ -304,6 +304,7 @@ static int mes_userq_mqd_create(struct
amdgpu_usermode_queue*queue,Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +1
-0userq_props->use_doorbell = true; userq_props->doorbell_index = queue->doorbell_index; userq_props->fence_address = queue->fence_drv->gpu_addr; + userq_props->queue_percentage =100 ;if (queue->queue_type ==AMDGPU_HW_IP_COMPUTE ) {struct drm_amdgpu_userq_mqd_compute_gfx11
*compute_mqd; diff --gita/include/uapi/drm/amdgpu_drm.hb/include/uapi/drm/amdgpu_drm.hindex41b6b3cea834..c42328453652100644include/uapi/drm/amdgpu_drm.h extern "C" { · line 64
Quoted 6 lines
include/uapi/drm/amdgpu_drm.h +1
-0@@ -59,6 +59,7 @@ extern "C" {#define DRM_AMDGPU_USERQ_WAIT 0x18#define DRM_AMDGPU_GEM_LIST_HANDLES 0x19#define DRM_AMDGPU_USERQ_SET_CU_MASK 0x1a +#define DRM_AMDGPU_USERQ_UPDATE_QUEUE 0x1b#define DRM_IOCTL_AMDGPU_GEM_CREATE
DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)include/uapi/drm/amdgpu_drm.h extern "C" { · line 65
Quoted 1 line
include/uapi/drm/amdgpu_drm.h +0
-0#define DRM_IOCTL_AMDGPU_GEM_MMAP
DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)include/uapi/drm/amdgpu_drm.h extern "C" { · line 82
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +0
-0@@ -81,6 +82,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_USERQ_WAIT
DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ_WAIT, struct drm_amdgpu_userq_wait)include/uapi/drm/amdgpu_drm.h extern "C" { · line 83
Quoted 1 line
include/uapi/drm/amdgpu_drm.h +0
-0#define DRM_IOCTL_AMDGPU_GEM_LIST_HANDLES DRM_IOWR(DRM_COMMAND_BASE +
include/uapi/drm/amdgpu_drm.h extern "C" { · line 85
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +0
-0DRM_AMDGPU_GEM_LIST_HANDLES, struct drm_amdgpu_gem_list_handles)#define DRM_IOCTL_AMDGPU_USERQ_SET_CU_MASK DRM_IOWR(DRM_COMMAND_BASE +
Quoted 1 line
DRM_AMDGPU_USERQ_SET_CU_MASK, struct
amdgpu_userq_set_cu_mask_args)Quoted 1 line
+#define
DRM_IOCTL_AMDGPU_USERQ_UPDATE_QUEUEDRM_IOWR(DRM_COMMAND_BASE
Quoted 7 lines
++
DRM_AMDGPU_USERQ_UPDATE_QUEUE, structinclude/uapi/drm/amdgpu_drm.h +1
-0+amdgpu_userq_update_queue_args)/** * DOC: memory domains @@ -343,6 +345,7 @@ union drm_amdgpu_ctx { #define
AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH3 /* adminonly */
Quoted 6 lines
/* for queues that need access to protected content */ #define
AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE(1 << 2)include/uapi/drm/amdgpu_drm.h +1
-0+#define AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE 100/* * This structure is a container to pass input configuration @@ include/uapi/drm/amdgpu_drm.h struct amdgpu_userq_set_cu_mask_args { · line 451
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +6
-1-440,6 +443,16 @@ struct amdgpu_userq_set_cu_mask_args {__u64 cu_mask_ptr; }; + +/* IOCTL parameters used to set user queue updates */ struct +amdgpu_userq_update_queue_args { +__u64 ring_base_address; +__u32 queue_id; +__u32 ring_size;Do we actually need to be able to change the ring base address and size? I know KFD can do it, but we should verify if we really need to be able to change the ring size at runtime.
include/uapi/drm/amdgpu_drm.h struct amdgpu_userq_set_cu_mask_args { · line 453
Quoted 2 lines
include/uapi/drm/amdgpu_drm.h +2
-0+__u32 queue_percentage; +__u32 queue_priority;We should probably also make these available for USERQ create as well. I would fold CU mask in as well.
Alex
Quoted 8 lines
include/uapi/drm/amdgpu_drm.h +2
-0+}; + /* GFX V11 IP specific MQD parameters */ structdrm_amdgpu_userq_mqd_gfx11 { /**--
2.49.0
Quoted 14 lines · Jesse.Zhang
Extend the
amdgpu_mqdstructure with a new 'update_mqd' callback to support runtime updates of MQD properties for user queuesSigned-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_mqd { · line 819
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -815,6 +815,8 @@ struct amdgpu_mqd {unsigned mqd_size;int (*init_mqd)(struct amdgpu_device *adev,void *mqd,struct amdgpu_mqd_prop *p); +int (*update_mqd)(struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *p);
Do we actually need a new callback, or can we just call init_mqd() again with updated parameters?
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-1};struct amdgpu_pcie_reset_ctx { --2.49.0
[AMD Official Use Only - AMD Internal Distribution Only]
Quoted 19 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, January 23, 2026 4:05 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH 1/9] drm/amd/amdgpu: Addupdate_mqdcallback toamdgpu_mqdstructQuoted 9 lines · Jesse.Zhang
Extend the
amdgpu_mqdstructure with a new 'update_mqd' callback to support runtime updates of MQD properties for user queuesSigned-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ 1 file changed, 2 insertions(+)
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_mqd { · line 819
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0@@ -815,6 +815,8 @@ struct amdgpu_mqd {unsigned mqd_size;int (*init_mqd)(struct amdgpu_device *adev,void *mqd,struct amdgpu_mqd_prop *p); +int (*update_mqd)(struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *p);Do we actually need a new callback, or can we just call
init_mqd()again with updated parameters?
[Zhang, Jesse(Jie)]
The update_mqd function only contains the MQD parameter, which changes dynamically at runtime. However, we can also directly call the init_mqd function to update all parameters. I will update the patch and remove the update_mqd function.
Thanks
Jesse
Quoted 8 lines
Alex
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-1};struct amdgpu_pcie_reset_ctx { --2.49.0