drm/amdgpu: add new performance monitor PSP interfaces
Subsystems (5)
PATCH 1/22 drm/amdgpu: add new performance monitor PSP interfaces
Introduce new psp interfaces and structures for performance monitoring hardware control.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 22 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +22 -0
@@ -359,6 +359,28 @@ struct spirom_bo { };#endif +enum psp_ptl_cmd { +PSP_PTL_PERF_MON_QUERY =0xA0000000 , +PSP_PTL_PERF_MON_SET =0xA0000001 , +}; + +enum psp_ptl_format_type +{ +GFX_FTYPE_I8 =0x00000000 , +GFX_FTYPE_F16 =0x00000001 , +GFX_FTYPE_BF16 =0x00000002 , +GFX_FTYPE_F32 =0x00000003 , +GFX_FTYPE_F64 =0x00000004 , +GFX_FTYPE_INVALID =0xFFFFFFFF , +}; + +struct psp_ptl_perf_req { +enum psp_ptl_cmd req; +uint32_t ptl_state; +uint32_t pref_format1; +uint32_t pref_format2; +}; +struct psp_context {struct amdgpu_device *adev;struct psp_ring km_ring;
drivers/gpu/drm/amd/amdgpu/psp_gfx_if.h +18 -0
@@ -107,6 +107,7 @@ enum psp_gfx_cmd_idGFX_CMD_ID_CONFIG_SQ_PERFMON =0x00000046 ,/* Config CGTT_SQ_CLK_CTRL */ /* Dynamic memory partitioninig (NPS mode change)*/ GFX_CMD_ID_FB_NPS_MODE =0x00000048 ,/* Configure memory partitioning mode */ +GFX_CMD_ID_PERF_HW =0x0000004C ,/* performance monitor */ GFX_CMD_ID_FB_FW_RESERV_ADDR =0x00000050 ,/* Query FW reservation addr */ GFX_CMD_ID_FB_FW_RESERV_EXT_ADDR = 0x00000051, /* Query FW reservation extended addr */ };
@@ -373,6 +374,13 @@ struct psp_gfx_cmd_fb_memory_part {uint32_t resvd; }; +struct psp_gfx_cmd_req_perf_hw { +uint32_t req; +uint32_t ptl_state; +uint32_t pref_format1; +uint32_t pref_format2; +}; +/* All GFX ring buffer commands. */ union psp_gfx_commands {
@@ -389,6 +397,7 @@ union psp_gfx_commandsstruct psp_gfx_cmd_sriov_spatial_part cmd_spatial_part;struct psp_gfx_cmd_config_sq_perfmon config_sq_perfmon;struct psp_gfx_cmd_fb_memory_part cmd_memory_part; +struct psp_gfx_cmd_req_perf_hw cmd_req_perf_hw; };struct psp_gfx_uresp_reserved
@@ -415,12 +424,21 @@ struct psp_gfx_uresp_fw_reserve_info {uint32_t reserve_size; }; +struct psp_gfx_uresp_perf_hw +{ +uint32_t resp; +uint32_t ptl_state; +uint32_t pref_format1; +uint32_t pref_format2; +}; +/* Union of command-specific responses for GPCOM ring. */ union psp_gfx_uresp {struct psp_gfx_uresp_reserved reserved;struct psp_gfx_uresp_bootcfg boot_cfg;struct psp_gfx_uresp_fwar_db_info fwar_db_info;struct psp_gfx_uresp_fw_reserve_info fw_reserve_info; +struct psp_gfx_uresp_perf_hw perf_hw_info; };/* Structure of GFX Response buffer.
Signature · 1 line
2.34.1
PATCH 2/22 drm/amdgpu: add psp interfaces for peak tops limiter driver
Introduce a Peak Tops Limiter (PTL) driver that dynamically caps engine frequency to ensure delivered TOPS never exceeds a defined TOPS_limit. This initial implementation provides core data structures and kernel-space interfaces (set/get, enable/disable) to manage PTL state.
PTL performs a firmware handshake to initialize its state and update predefined format types. It supports updating these format types at runtime while user-space tools automatically switch PTL state, and also allows explicitly switching PTL state via newly added commands.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 80 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 6 ++ include/uapi/linux/kfd_ioctl.h | 9 +++ 3 files changed, 95 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +80 -0
@@ -679,6 +679,8 @@ static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id cmd_id)return "SPATIAL_PARTITION" ;case GFX_CMD_ID_FB_NPS_MODE :return "NPS_MODE_CHANGE" ; +case GFX_CMD_ID_PERF_HW : +return "PERF MONITORING HW" ;default :return "UNKNOWN CMD" ; }
@@ -1197,6 +1199,84 @@ int psp_memory_partition(struct psp_context *psp, int mode)return ret; } +static int psp_ptl_fmt_verify (struct psp_context *psp,enum amdgpu_ptl_fmt fmt, +uint32_t *ptl_fmt) +{ +struct amdgpu_device *adev = psp->adev; + +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) +return -EINVAL ; + +switch (fmt) { +case AMDGPU_PTL_FMT_I8 : + *ptl_fmt =GFX_FTYPE_I8 ; +break ; +case AMDGPU_PTL_FMT_F16 : + *ptl_fmt =GFX_FTYPE_F16 ; +break ; +case AMDGPU_PTL_FMT_BF16 : + *ptl_fmt =GFX_FTYPE_BF16 ; +break ; +case AMDGPU_PTL_FMT_F32 : + *ptl_fmt =GFX_FTYPE_F32 ; +break ; +case AMDGPU_PTL_FMT_F64 : + *ptl_fmt =GFX_FTYPE_F64 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +uint32_t *ptl_state,uint32_t *fmt1,uint32_t *fmt2) +{ +struct psp_gfx_cmd_resp *cmd; +uint32_t ptl_fmt1, ptl_fmt2; +int ret; + +if (!psp || !ptl_state || !fmt1 || !fmt2) +return -EINVAL ; + +if (amdgpu_sriov_vf (psp->adev)) +return 0 ; + +if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) || +psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2)) +return -EINVAL ; + + cmd =acquire_psp_cmd_buf (psp); + + cmd->cmd_id =GFX_CMD_ID_PERF_HW ; + cmd->cmd.cmd_req_perf_hw.req = req_code; + cmd->cmd.cmd_req_perf_hw.ptl_state = *ptl_state; + cmd->cmd.cmd_req_perf_hw.pref_format1 = ptl_fmt1; + cmd->cmd.cmd_req_perf_hw.pref_format2 = ptl_fmt2; + + ret =psp_cmd_submit_buf (psp,NULL , cmd, psp->fence_buf_mc_addr); +if (ret) + goto out; + +switch (req_code) { +case PSP_PTL_PERF_MON_QUERY : + *ptl_state = cmd->resp.uresp.perf_hw_info.ptl_state; + *fmt1 = cmd->resp.uresp.perf_hw_info.pref_format1; + *fmt2 = cmd->resp.uresp.perf_hw_info.pref_format2; +break ; +case PSP_PTL_PERF_MON_SET : + psp->ptl_enabled = *ptl_state; + psp->ptl_fmt1 = ptl_fmt1; + psp->ptl_fmt2 = ptl_fmt2; +break ; + } + +out: +release_psp_cmd_buf (psp); +return ret; +} +int psp_spatial_partition (struct psp_context *psp,int mode) {struct psp_gfx_cmd_resp *cmd;
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +6 -0
@@ -471,6 +471,10 @@ struct psp_context {#if defined(CONFIG_DEBUG_FS )struct spirom_bo *spirom_dump_trip;#endif +enum amdgpu_ptl_fmt ptl_fmt1; +enum amdgpu_ptl_fmt ptl_fmt2; +bool ptl_enabled; +bool ptl_hw_supported; };struct amdgpu_psp_funcs {
@@ -654,5 +658,7 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev);int amdgpu_psp_get_fw_type (struct amdgpu_firmware_info *ucode,enum psp_gfx_fw_type *type); +int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +u32 *ptl_state,u32 *fmt1,u32 *fmt2);#endif
include/uapi/linux/kfd_ioctl.h +9 -0
@@ -1558,6 +1558,15 @@ struct kfd_ioctl_dbg_trap_args { }; }; +enum amdgpu_ptl_fmt { +AMDGPU_PTL_FMT_I8 =0 , +AMDGPU_PTL_FMT_F16 =1 , +AMDGPU_PTL_FMT_BF16 =2 , +AMDGPU_PTL_FMT_F32 =3 , +AMDGPU_PTL_FMT_F64 =4 , +AMDGPU_PTL_FMT_INVALID =5 , +}; +#define KFD_IOC_PROFILER_VERSION_NUM 1enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 ,
Signature · 1 line
2.34.1
Re: [PATCH 02/22] drm/amdgpu: add psp interfaces for peak tops limiter driver
Quoted 74 lines · Perry Yuan
Introduce a Peak Tops Limiter (PTL) driver that dynamically caps engine frequency to ensure delivered TOPS never exceeds a defined
TOPS_limit. This initial implementation provides core data structures and kernel-space interfaces (set/get, enable/disable) to manage PTL state.PTL performs a firmware handshake to initialize its state and update predefined format types. It supports updating these format types at runtime while user-space tools automatically switch PTL state, and also allows explicitly switching PTL state via newly added commands.
Signed-off-by Perry Yuan <[email protected]>Reviewed-by Lijo Lazar <[email protected]>Acked-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 80 +++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 6 ++ include/uapi/linux/kfd_ioctl.h | 9 +++ 3 files changed, 95 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +39
-0@@ -679,6 +679,8 @@ static const char *psp_gfx_cmd_name(enum psp_gfx_cmd_id cmd_id)return "SPATIAL_PARTITION" ;case GFX_CMD_ID_FB_NPS_MODE :return "NPS_MODE_CHANGE" ; +case GFX_CMD_ID_PERF_HW : +return "PERF MONITORING HW" ;default :return "UNKNOWN CMD" ; }@@ -1197,6 +1199,84 @@ int psp_memory_partition(struct psp_context *psp, int mode)return ret; } +static int psp_ptl_fmt_verify (struct psp_context *psp,enum amdgpu_ptl_fmt fmt, +uint32_t *ptl_fmt) +{ +struct amdgpu_device *adev = psp->adev; + +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) +return -EINVAL ; + +switch (fmt) { +case AMDGPU_PTL_FMT_I8 : + *ptl_fmt =GFX_FTYPE_I8 ; +break ; +case AMDGPU_PTL_FMT_F16 : + *ptl_fmt =GFX_FTYPE_F16 ; +break ; +case AMDGPU_PTL_FMT_BF16 : + *ptl_fmt =GFX_FTYPE_BF16 ; +break ; +case AMDGPU_PTL_FMT_F32 : + *ptl_fmt =GFX_FTYPE_F32 ; +break ; +case AMDGPU_PTL_FMT_F64 : + *ptl_fmt =GFX_FTYPE_F64 ; +break ; +default : +return -EINVAL ; + } + +return 0 ; +} + +int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +uint32_t *ptl_state,uint32_t *fmt1,uint32_t *fmt2) +{ +struct psp_gfx_cmd_resp *cmd; +uint32_t ptl_fmt1, ptl_fmt2; +int ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c int psp_memory_partition(struct psp_context *psp, int mode) · line 1248
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +10
-0+ +if (!psp || !ptl_state || !fmt1 || !fmt2) +return -EINVAL ; + +if (amdgpu_sriov_vf (psp->adev)) +return 0 ; + +if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) || +psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2)) +return -EINVAL ;
Do we need a FW version check for this?
Alex
Quoted 80 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +31
-0+ + cmd =acquire_psp_cmd_buf (psp); + + cmd->cmd_id =GFX_CMD_ID_PERF_HW ; + cmd->cmd.cmd_req_perf_hw.req = req_code; + cmd->cmd.cmd_req_perf_hw.ptl_state = *ptl_state; + cmd->cmd.cmd_req_perf_hw.pref_format1 = ptl_fmt1; + cmd->cmd.cmd_req_perf_hw.pref_format2 = ptl_fmt2; + + ret =psp_cmd_submit_buf (psp,NULL , cmd, psp->fence_buf_mc_addr); +if (ret) + goto out; + +switch (req_code) { +case PSP_PTL_PERF_MON_QUERY : + *ptl_state = cmd->resp.uresp.perf_hw_info.ptl_state; + *fmt1 = cmd->resp.uresp.perf_hw_info.pref_format1; + *fmt2 = cmd->resp.uresp.perf_hw_info.pref_format2; +break ; +case PSP_PTL_PERF_MON_SET : + psp->ptl_enabled = *ptl_state; + psp->ptl_fmt1 = ptl_fmt1; + psp->ptl_fmt2 = ptl_fmt2; +break ; + } + +out: +release_psp_cmd_buf (psp); +return ret; +} +int psp_spatial_partition (struct psp_context *psp,int mode) {struct psp_gfx_cmd_resp *cmd;drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +6
-0@@ -471,6 +471,10 @@ struct psp_context {#if defined(CONFIG_DEBUG_FS )struct spirom_bo *spirom_dump_trip;#endif +enum amdgpu_ptl_fmt ptl_fmt1; +enum amdgpu_ptl_fmt ptl_fmt2; +bool ptl_enabled; +bool ptl_hw_supported; };struct amdgpu_psp_funcs {@@ -654,5 +658,7 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev);int amdgpu_psp_get_fw_type (struct amdgpu_firmware_info *ucode,enum psp_gfx_fw_type *type); +int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +u32 *ptl_state,u32 *fmt1,u32 *fmt2);#endif include/uapi/linux/kfd_ioctl.h +9
-1@@ -1558,6 +1558,15 @@ struct kfd_ioctl_dbg_trap_args { }; }; +enum amdgpu_ptl_fmt { +AMDGPU_PTL_FMT_I8 =0 , +AMDGPU_PTL_FMT_F16 =1 , +AMDGPU_PTL_FMT_BF16 =2 , +AMDGPU_PTL_FMT_F32 =3 , +AMDGPU_PTL_FMT_F64 =4 , +AMDGPU_PTL_FMT_INVALID =5 , +}; +#define KFD_IOC_PROFILER_VERSION_NUM 1enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 , --2.34.1
PATCH 3/22 drm/amdgpu: add PTL enable/query gfx control support for GC 9.4.4
In reply to Perry YuanIntroduce hardware detection, runtime state tracking and a kgd->ptl_ctrl() callback to enable/disable/query PTL via the PSP performance-monitor interface (commands 0xA0000000/1). The driver now exposes PTL capability to KFD and keeps the software state in sync with the hardware.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +36 -0
@@ -2370,11 +2370,45 @@ static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block)return r; } +static int gfx_v9_4_3_perf_monitor_ptl_init (struct amdgpu_device *adev,bool state) +{ +uint32_t fmt1, fmt2; +uint32_t ptl_state = state ?1 :0 ; +int r; + +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) +return -ENOTSUPP ; + +if (!adev->psp.funcs) +return -EOPNOTSUPP ; + +if (!adev->psp.ptl_hw_supported) { + fmt1 =GFX_FTYPE_I8 ; + fmt2 =GFX_FTYPE_BF16 ; + }else { + fmt1 = adev->psp.ptl_fmt1; + fmt2 = adev->psp.ptl_fmt2; + } + +/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */ + r =psp_performance_monitor_hw (&adev->psp,PSP_PTL_PERF_MON_SET , &ptl_state, + &fmt1, &fmt2); +if (r) +return r; + + adev->psp.ptl_hw_supported = true; + +return 0 ; +} +static int gfx_v9_4_3_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; +if (adev->psp.ptl_hw_supported) +gfx_v9_4_3_perf_monitor_ptl_init (adev,0 ); +amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );
@@ -2549,6 +2583,8 @@ static int gfx_v9_4_3_late_init(struct amdgpu_ip_block *ip_block) adev->gfx.ras->enable_watchdog_timer) adev->gfx.ras->enable_watchdog_timer (adev); +gfx_v9_4_3_perf_monitor_ptl_init (adev,1 ); +return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH 03/22] drm/amdgpu: add PTL enable/query gfx control support for GC 9.4.4
Quoted 19 lines · Perry Yuan
Introduce hardware detection, runtime state tracking and a
kgd->ptl_ctrl()callback to enable/disable/query PTL via the PSP performance-monitor interface (commands 0xA0000000/1). The driver now exposes PTL capability to KFD and keeps the software state in sync with the hardware.Signed-off-by Perry Yuan <[email protected]>Reviewed-by Lijo Lazar <[email protected]>Acked-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0
-0
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block) · line 2373
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +1
-0@@ -2370,11 +2370,45 @@ static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block)return r; } +static int gfx_v9_4_3_perf_monitor_ptl_init (struct amdgpu_device *adev,bool state)
Rather than state, call the parameter enable or something more obvious as to what it's doing.
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +27
-0+{ +uint32_t fmt1, fmt2; +uint32_t ptl_state = state ?1 :0 ; +int r; + +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) +return -ENOTSUPP ; + +if (!adev->psp.funcs) +return -EOPNOTSUPP ; + +if (!adev->psp.ptl_hw_supported) { + fmt1 =GFX_FTYPE_I8 ; + fmt2 =GFX_FTYPE_BF16 ; + }else { + fmt1 = adev->psp.ptl_fmt1; + fmt2 = adev->psp.ptl_fmt2; + } + +/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */ + r =psp_performance_monitor_hw (&adev->psp,PSP_PTL_PERF_MON_SET , &ptl_state, + &fmt1, &fmt2); +if (r) +return r; + + adev->psp.ptl_hw_supported = true; +
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_hw_init(struct amdgpu_ip_block *ip_block) · line 2410
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +5
-0+return 0 ; +} +static int gfx_v9_4_3_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; +if (adev->psp.ptl_hw_supported) +gfx_v9_4_3_perf_monitor_ptl_init (adev,0 );
Use false rather than 0 here.
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c static int gfx_v9_4_3_late_init(struct amdgpu_ip_block *ip_block) · line 2586
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2
-0+amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );amdgpu_irq_put (adev, &adev->gfx.priv_inst_irq,0 );amdgpu_irq_put (adev, &adev->gfx.bad_op_irq,0 );@@ -2549,6 +2583,8 @@ static int gfx_v9_4_3_late_init(struct amdgpu_ip_block *ip_block) adev->gfx.ras->enable_watchdog_timer) adev->gfx.ras->enable_watchdog_timer (adev); +gfx_v9_4_3_perf_monitor_ptl_init (adev,1 );
Use true here rather than 1.
Alex
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +1
-1+return 0 ; } --2.34.1
PATCH 4/22 drm/amdkfd: add kgd control interface for ptl
In reply to Perry YuanAdd kgd->ptl_ctrl() callback so KFD can query/enable/disable PTL state through the PSP performance monitor interface.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c | 13 ++++++++++++- drivers/gpu/drm/amd/include/kgd_kfd_interface.h | 5 +++++ 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c +12 -1
@@ -520,6 +520,16 @@ static uint32_t kgd_gfx_v9_4_3_hqd_sdma_get_doorbell(struct amdgpu_device *adev,return is_active ? doorbell_off >>2 :0 ; } +static uint32_t kgd_v9_4_3_ptl_ctrl (struct amdgpu_device *adev, +uint32_t cmd, +uint32_t *ptl_state, +enum amdgpu_ptl_fmt *fmt1, +enum amdgpu_ptl_fmt *fmt2) +{ +return psp_performance_monitor_hw (&adev->psp, cmd, + ptl_state, fmt1, fmt2); +} +const struct kfd2kgd_calls gc_9_4_3_kfd2kgd = { .program_sh_mem_settings = kgd_gfx_v9_program_sh_mem_settings, .set_pasid_vmid_mapping = kgd_gfx_v9_4_3_set_pasid_vmid_mapping,
@@ -555,5 +565,6 @@ const struct kfd2kgd_calls gc_9_4_3_kfd2kgd = { .clear_address_watch = kgd_gfx_v9_4_3_clear_address_watch, .hqd_get_pq_addr = kgd_gfx_v9_hqd_get_pq_addr, .hqd_reset = kgd_gfx_v9_hqd_reset, - .hqd_sdma_get_doorbell = kgd_gfx_v9_4_3_hqd_sdma_get_doorbell + .hqd_sdma_get_doorbell = kgd_gfx_v9_4_3_hqd_sdma_get_doorbell, + .ptl_ctrl = kgd_v9_4_3_ptl_ctrl };
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +5 -0
@@ -333,6 +333,11 @@ struct kfd2kgd_calls { uint32_t inst, unsigned int utimeout);uint32_t (*hqd_sdma_get_doorbell)(struct amdgpu_device *adev,int engine,int queue); +uint32_t (*ptl_ctrl)(struct amdgpu_device *adev, +uint32_t cmd, +uint32_t *ptl_state, +enum amdgpu_ptl_fmt *fmt1, + enum amdgpu_ptl_fmt *fmt2); };#endif /* KGD_KFD_INTERFACE_H_INCLUDED */
Signature · 1 line
2.34.1
PATCH 5/22 drm/amdgpu: integrate PTL control with PMC device locking
In reply to Perry YuanCombine PTL hardware control with the existing PMC device locking mechanism to ensure proper synchronization and hardware state management during profiling operations.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +23 -0
@@ -1764,6 +1764,27 @@ static int kfd_ioctl_svm(struct file *filep, struct kfd_process *p, void *data) }#endif +static int kfd_ptl_control (struct kfd_process_device *pdd,bool enable) +{ +struct amdgpu_device *adev = pdd->dev->adev; +enum amdgpu_ptl_fmt pref_format1 = adev->psp.ptl_fmt1; +enum amdgpu_ptl_fmt pref_format2 = adev->psp.ptl_fmt2; +uint32_t ptl_state = enable ?1 :0 ; +int ret; + +if (!adev->psp.ptl_hw_supported) +return -EOPNOTSUPP ; + +if (!pdd->dev->kfd2kgd || !pdd->dev->kfd2kgd->ptl_ctrl) +return -EOPNOTSUPP ; + + ret = pdd->dev->kfd2kgd->ptl_ctrl (adev,PSP_PTL_PERF_MON_SET , + &ptl_state, + &pref_format1, + &pref_format2); +return ret; +} +static int criu_checkpoint_process (struct kfd_process *p,uint8_t __user *user_priv_data,uint64_t *priv_offset)
@@ -3229,6 +3250,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,if (!kfd->profiler_process) { kfd->profiler_process = p; status =0 ; +kfd_ptl_control (pdd, false); }else if (kfd->profiler_process == p) { status = -EALREADY ; }else {
@@ -3237,6 +3259,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, }else if (op ==0 && kfd->profiler_process == p) { kfd->profiler_process =NULL ; status =0 ; +kfd_ptl_control (pdd, true); }mutex_unlock (&kfd->profiler_lock);
Signature · 1 line
2.34.1
PATCH 6/22 drm/amdkfd: enable PTL while kfd_process profiler release
In reply to Perry YuanWhen the profiler is released it needs to enable PTL again to make sure PTL state is restored to preivous state.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -1
@@ -1764,7 +1764,7 @@ static int kfd_ioctl_svm(struct file *filep, struct kfd_process *p, void *data) }#endif -static int kfd_ptl_control (struct kfd_process_device *pdd,bool enable) +int kfd_ptl_control (struct kfd_process_device *pdd,bool enable) {struct amdgpu_device *adev = pdd->dev->adev;enum amdgpu_ptl_fmt pref_format1 = adev->psp.ptl_fmt1;
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +3 -0
@@ -1607,6 +1607,9 @@ static inline bool kfd_is_first_node(struct kfd_node *node)return (node == node->kfd->nodes[0 ]); } +/* PTL support */ +int kfd_ptl_control (struct kfd_process_device *pdd,bool enable); +/* Debugfs */ #if defined(CONFIG_DEBUG_FS )
drivers/gpu/drm/amd/amdkfd/kfd_process.c +1 -0
@@ -1115,6 +1115,7 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_procemutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); +kfd_ptl_control (pdd, true); pdd->dev->kfd->profiler_process =NULL ; }mutex_unlock (&pdd->dev->kfd->profiler_lock);
Signature · 1 line
2.34.1
PATCH 7/22 Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interface
In reply to Perry YuanThe PTL (Peak Tops Limiter) feature exposes per-GPU sysfs files under /sys/class/drm/cardX/device/ptl/ to allow users to enable or disable PTL, configure preferred data formats, and query supported formats. The usage of these sysfs files is not always obvious, so add documentation to describe their purpose and provide concrete usage examples.
V3 changes:
* format show will display preferred formats instead of N/A (Alex)
--- Documentation/gpu/amdgpu/index.rst | 1 + Documentation/gpu/amdgpu/ptl.rst | 94 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/gpu/amdgpu/ptl.rst
Documentation/gpu/amdgpu/index.rst +1 -0
@@ -23,3 +23,4 @@ Next (GCN), Radeon DNA (RDNA), and Compute DNA (CDNA) architectures. debugfs process-isolation amdgpu-glossary + ptl
Documentation/gpu/amdgpu/ptl.rst new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH 07/22] Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interface
Quoted 56 lines · Perry Yuan
The PTL (Peak Tops Limiter) feature exposes per-GPU sysfs files under
/sys/class/drm/cardX/device/ptl/to allow users to enable or disable PTL, configure preferred data formats, and query supported formats. The usage of these sysfs files is not always obvious, so add documentation to describe their purpose and provide concrete usage examples.V3 changes:
* format show will display preferred formats instead of N/A (Alex)Signed-off-by Perry Yuan <[email protected]>Suggested-by Alex Deucher <[email protected]>Reviewed-by Yifan Zhang <[email protected]>--- Documentation/gpu/amdgpu/index.rst | 1 + Documentation/gpu/amdgpu/ptl.rst | 94 ++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 Documentation/gpu/amdgpu/ptl.rstDocumentation/gpu/amdgpu/index.rst +1
-0@@ -23,3 +23,4 @@ Next (GCN), Radeon DNA (RDNA), and Compute DNA (CDNA) architectures. debugfs process-isolation amdgpu-glossary + ptlDocumentation/gpu/amdgpu/ptl.rst new file +22
-0@@ -0,0 +1,94 @@ +======================================= +Peak Tops Limiter (PTL) sysfs Interface +======================================= + +Overview +-------- +The Peak Tops Limiter (PTL) sysfs interface enables users to control and +configure the PTL feature for each GPU individually. All PTL-related +sysfs files are located under `/sys/class/drm/cardX/device/ptl/`, where +`X` is the GPU index. Through these files, users can enable or disable +PTL, set preferred data formats, and query supported formats for each GPU. + +PTL sysfs files +---------------- +The following files are available under `/sys/class/drm/cardX/device/ptl/`: + +- `ptl_enable` +- `ptl_format` +- `ptl_supported_formats` + +PTL Enable/Disable +------------------
Documentation/gpu/amdgpu/ptl.rst line 32
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+File: `ptl_enable` +Type: Read/Write (rw) + +Read: Returns the current PTL status as a string: `enabled` if PTL +is active, or `disabled` if inactive. + +Write: + +- Write `1` or `enabled` to enable PTL +- Write `0` or `disabled` to disable PTL
Ideally enable or disable, I.e., drop the "d".
Alex
Quoted 65 lines
Documentation/gpu/amdgpu/ptl.rst new file +62
-1+ +Examples:: + + # Query PTL status + cat /sys/class/drm/card1/device/ptl/ptl_enable + # Output: enabled + + # Enable PTL + sudo bash -c "echo 1 > /sys/class/drm/card1/device/ptl/ptl_enable" + + # Disable PTL + sudo bash -c "echo 0 > /sys/class/drm/card1/device/ptl/ptl_enable" + +PTL Format (Preferred Data Formats) +----------------------------------- +File: `ptl_format` +Type: Read/Write (rw) + +Read: Returns the two preferred formats, e.g. `I8,F32`. + +Write: Accepts two formats separated by a comma, e.g. `I8,F32`. + +- Both formats must be supported and different. +- If an invalid format is provided (not supported, or both formats are the + same), the driver will return "write error: Invalid argument". + +Examples:: + + # Query PTL formats + cat /sys/class/drm/card1/device/ptl/ptl_format + # Output: I8,F32 + + # Set PTL formats + sudo bash -c "echo I8,F32 > /sys/class/drm/card1/device/ptl/ptl_format" + +Supported Formats +----------------- +File: `ptl_supported_formats` +Type: Read-only (r) + +Read: Returns a comma-separated list of supported formats, e.g. +`I8,F16,BF16,F32,F64`. + +Example:: + + # Check supported formats + cat /sys/class/drm/card1/device/ptl/ptl_supported_formats + # Output: I8,F16,BF16,F32,F64 + +Behavioral Notes +---------------- +- PTL formats can only be set when PTL is enabled. +- If PTL is disabled, `ptl_format` returns `N/A`. +- Only two formats can be set at a time, and they must be from the supported set and different.. +- All commands support per-GPU targeting. +- Root permission is required to enable/disable PTL or change formats. +- If the hardware does not support PTL, the PTL sysfs directory will not + be created. + +Implementation +-------------- +The PTL sysfs nodes are implemented in `drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c`. --2.34.1
RE: [PATCH 07/22] Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interface
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Alex,
Quoted 84 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, February 6, 2026 5:37 AM
To: Yuan, Perry <[email protected]>
Cc: Deucher, Alexander <[email protected]>; amd- [email protected]; Zhang, Yifan <[email protected]>
Subject: Re: [PATCH 07/22]Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interfaceQuoted 10 lines · Perry Yuan
The PTL (Peak Tops Limiter) feature exposes per-GPU sysfs files under
/sys/class/drm/cardX/device/ptl/to allow users to enable or disable PTL, configure preferred data formats, and query supported formats. The usage of these sysfs files is not always obvious, so add documentation to describe their purpose and provide concrete usage examples.V3 changes:
* format show will display preferred formats instead of N/A (Alex)Quoted 6 lines
Signed-off-by Perry Yuan <[email protected]>Suggested-by Alex Deucher <[email protected]>Reviewed-by Yifan Zhang <[email protected]>--- Documentation/gpu/amdgpu/index.rst | 1 + Documentation/gpu/amdgpu/ptl.rst | 94++++++++++++++++++++++++++++++
Documentation/gpu/amdgpu/index.rst Next (GCN), Radeon DNA (RDNA), and Compute DNA
Quoted 9 lines
2 files changed, 95 insertions(+) create mode 100644 Documentation/gpu/amdgpu/ptl.rstDocumentation/gpu/amdgpu/index.rst +0
-0@@ -23,3 +23,4 @@ Next (GCN), Radeon DNA (RDNA), and Compute DNA(CDNA) architectures.
Quoted 12 lines
Documentation/gpu/amdgpu/index.rst +1
-0debugfs process-isolation amdgpu-glossary + ptlDocumentation/gpu/amdgpu/ptl.rst new file +1
-0@@ -0,0 +1,94 @@ +=======================================Documentation/gpu/amdgpu/ptl.rst line 11
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+Peak Tops Limiter (PTL) sysfs Interface +======================================= + +Overview +-------- +The Peak Tops Limiter (PTL) sysfs interface enables users to control +and configure the PTL feature for each GPU individually. All +PTL-related sysfs files are located under +`/sys/class/drm/cardX/device/ptl/`, where `X` is the GPU index. +Through these files, users can enable or disable PTL, set preferred dataformats, and query supported formats for each GPU.
Quoted 11 lines
Documentation/gpu/amdgpu/ptl.rst new file +11
-0+ +PTL sysfs files +---------------- +The following files are available under `/sys/class/drm/cardX/device/ptl/`: + +- `ptl_enable` +- `ptl_format` +- `ptl_supported_formats` + +PTL Enable/Disable +------------------Documentation/gpu/amdgpu/ptl.rst line 32
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+File: `ptl_enable` +Type: Read/Write (rw) + +Read: Returns the current PTL status as a string: `enabled` if PTL is +active, or `disabled` if inactive. + +Write: + +- Write `1` or `enabled` to enable PTL +- Write `0` or `disabled` to disable PTLIdeally
enableordisable, I.e., drop the "d".
Quoted 1 line
Alex
Could we retain the current 'enabled' and 'disabled' states? While they may not be ideal, changing them would break compatibility with the amd-smi tool that already has been released to user.
Thanks.
Perry.
Quoted 70 lines
Quoted 46 lines
Documentation/gpu/amdgpu/ptl.rst new file +45
-0+ +Examples:: + + # Query PTL status + cat /sys/class/drm/card1/device/ptl/ptl_enable + # Output: enabled + + # Enable PTL + sudo bash -c "echo 1 > /sys/class/drm/card1/device/ptl/ptl_enable" + + # Disable PTL + sudo bash -c "echo 0 > /sys/class/drm/card1/device/ptl/ptl_enable" + +PTL Format (Preferred Data Formats) +----------------------------------- +File: `ptl_format` +Type: Read/Write (rw) + +Read: Returns the two preferred formats, e.g. `I8,F32`. + +Write: Accepts two formats separated by a comma, e.g. `I8,F32`. + +- Both formats must be supported and different. +- If an invalid format is provided (not supported, or both formats +are the + same), the driver will return "write error: Invalid argument". + +Examples:: + + # Query PTL formats + cat /sys/class/drm/card1/device/ptl/ptl_format + # Output: I8,F32 + + # Set PTL formats + sudo bash -c "echo I8,F32 > /sys/class/drm/card1/device/ptl/ptl_format" + +Supported Formats +----------------- +File: `ptl_supported_formats` +Type: Read-only (r) + +Read: Returns a comma-separated list of supported formats, e.g. +`I8,F16,BF16,F32,F64`. + +Example::Documentation/gpu/amdgpu/ptl.rst
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+ + # Check supported formats + cat /sys/class/drm/card1/device/ptl/ptl_supported_formats + # Output: I8,F16,BF16,F32,F64 + +Behavioral Notes +---------------- +- PTL formats can only be set when PTL is enabled. +- If PTL is disabled, `ptl_format` returns `N/A`. +- Only two formats can be set at a time, and they must be from the supported setand different..
Documentation/gpu/amdgpu/ptl.rst
Quoted 9 lines
Documentation/gpu/amdgpu/ptl.rst new file +9
-0+- All commands support per-GPU targeting. +- Root permission is required to enable/disable PTL or change formats. +- If the hardware does not support PTL, the PTL sysfs directory will +not + be created. + +Implementation +-------------- +The PTL sysfs nodes are implemented in
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c.Quoted 3 lines
--
2.34.1
Re: [PATCH 07/22] Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interface
Quoted 89 lines · Perry
[AMD Official Use Only - AMD Internal Distribution Only]
Hi Alex,
Quoted 84 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Friday, February 6, 2026 5:37 AM
To: Yuan, Perry <[email protected]>
Cc: Deucher, Alexander <[email protected]>; amd- [email protected]; Zhang, Yifan <[email protected]>
Subject: Re: [PATCH 07/22]Documentation/amdgpu: Add documentation for Peak Tops Limiter (PTL) sysfs interfaceQuoted 10 lines · Perry Yuan
The PTL (Peak Tops Limiter) feature exposes per-GPU sysfs files under
/sys/class/drm/cardX/device/ptl/to allow users to enable or disable PTL, configure preferred data formats, and query supported formats. The usage of these sysfs files is not always obvious, so add documentation to describe their purpose and provide concrete usage examples.V3 changes:
* format show will display preferred formats instead of N/A (Alex)Quoted 6 lines
Signed-off-by Perry Yuan <[email protected]>Suggested-by Alex Deucher <[email protected]>Reviewed-by Yifan Zhang <[email protected]>--- Documentation/gpu/amdgpu/index.rst | 1 + Documentation/gpu/amdgpu/ptl.rst | 94++++++++++++++++++++++++++++++
Documentation/gpu/amdgpu/index.rst Next (GCN), Radeon DNA (RDNA), and Compute DNA
Quoted 9 lines
2 files changed, 95 insertions(+) create mode 100644 Documentation/gpu/amdgpu/ptl.rstDocumentation/gpu/amdgpu/index.rst +0
-0@@ -23,3 +23,4 @@ Next (GCN), Radeon DNA (RDNA), and Compute DNA(CDNA) architectures.
Quoted 12 lines
Documentation/gpu/amdgpu/index.rst +1
-0debugfs process-isolation amdgpu-glossary + ptlDocumentation/gpu/amdgpu/ptl.rst new file +1
-0@@ -0,0 +1,94 @@ +=======================================Documentation/gpu/amdgpu/ptl.rst line 11
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+Peak Tops Limiter (PTL) sysfs Interface +======================================= + +Overview +-------- +The Peak Tops Limiter (PTL) sysfs interface enables users to control +and configure the PTL feature for each GPU individually. All +PTL-related sysfs files are located under +`/sys/class/drm/cardX/device/ptl/`, where `X` is the GPU index. +Through these files, users can enable or disable PTL, set preferred dataformats, and query supported formats for each GPU.
Quoted 11 lines
Documentation/gpu/amdgpu/ptl.rst new file +11
-0+ +PTL sysfs files +---------------- +The following files are available under `/sys/class/drm/cardX/device/ptl/`: + +- `ptl_enable` +- `ptl_format` +- `ptl_supported_formats` + +PTL Enable/Disable +------------------Documentation/gpu/amdgpu/ptl.rst line 32
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+File: `ptl_enable` +Type: Read/Write (rw) + +Read: Returns the current PTL status as a string: `enabled` if PTL is +active, or `disabled` if inactive. + +Write: + +- Write `1` or `enabled` to enable PTL +- Write `0` or `disabled` to disable PTLIdeally
enableordisable, I.e., drop the "d".
Quoted 3 lines
Quoted 1 line
Alex
Could we retain the current 'enabled' and 'disabled' states? While they may not be ideal, changing them would break compatibility with the amd-smi tool that already has been released to user.
Ok.
Alex
Quoted 75 lines
Thanks.
Perry.Quoted 70 lines
Quoted 46 lines
Documentation/gpu/amdgpu/ptl.rst new file +45
-0+ +Examples:: + + # Query PTL status + cat /sys/class/drm/card1/device/ptl/ptl_enable + # Output: enabled + + # Enable PTL + sudo bash -c "echo 1 > /sys/class/drm/card1/device/ptl/ptl_enable" + + # Disable PTL + sudo bash -c "echo 0 > /sys/class/drm/card1/device/ptl/ptl_enable" + +PTL Format (Preferred Data Formats) +----------------------------------- +File: `ptl_format` +Type: Read/Write (rw) + +Read: Returns the two preferred formats, e.g. `I8,F32`. + +Write: Accepts two formats separated by a comma, e.g. `I8,F32`. + +- Both formats must be supported and different. +- If an invalid format is provided (not supported, or both formats +are the + same), the driver will return "write error: Invalid argument". + +Examples:: + + # Query PTL formats + cat /sys/class/drm/card1/device/ptl/ptl_format + # Output: I8,F32 + + # Set PTL formats + sudo bash -c "echo I8,F32 > /sys/class/drm/card1/device/ptl/ptl_format" + +Supported Formats +----------------- +File: `ptl_supported_formats` +Type: Read-only (r) + +Read: Returns a comma-separated list of supported formats, e.g. +`I8,F16,BF16,F32,F64`. + +Example::Documentation/gpu/amdgpu/ptl.rst
Quoted 10 lines
Documentation/gpu/amdgpu/ptl.rst new file +10
-0+ + # Check supported formats + cat /sys/class/drm/card1/device/ptl/ptl_supported_formats + # Output: I8,F16,BF16,F32,F64 + +Behavioral Notes +---------------- +- PTL formats can only be set when PTL is enabled. +- If PTL is disabled, `ptl_format` returns `N/A`. +- Only two formats can be set at a time, and they must be from the supported setand different..
Documentation/gpu/amdgpu/ptl.rst
Quoted 9 lines
Documentation/gpu/amdgpu/ptl.rst new file +9
-0+- All commands support per-GPU targeting. +- Root permission is required to enable/disable PTL or change formats. +- If the hardware does not support PTL, the PTL sysfs directory will +not + be created. + +Implementation +-------------- +The PTL sysfs nodes are implemented in
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c.Quoted 3 lines
--
2.34.1
PATCH 8/22 drm/amdgpu: add sysfs for Peak Tops Limiter (PTL)
In reply to Perry YuanAdd per-GPU sysfs files under /sys/class/drm/cardX/device/ptl to control the Peak Tops Limiter (PTL) feature. Exposes ptl_enable (enable/disable PTL), ptl_format (set/query preferred formats), and ptl_supported_formats (list supported formats)
Example usage
-------------
Query PTL status:
cat /sys/class/drm/card1/device/ptl/ptl_enable
Enable PTL:
sudo bash -c "echo 1 > /sys/class/drm/card1/device/ptl/ptl_enable"
Disable PTL:
sudo bash -c "echo 0 > /sys/class/drm/card1/device/ptl/ptl_enable"
Set PTL preferred formats:
`sudo bash -c "echo I8,F32 > /sys/class/drm/card1/device/ptl/ptl_format"`
Query supported formats:
cat /sys/class/drm/card1/device/ptl/ptl_supported_formats
v3 changes:
* move N/A to previous format in format show(Alex)
* fix format check for format store(Alex)
* drop the ptl declarations into amdgpu_ptl.h(Alex)
v2 changes:
* add usage commands in commit info (Alex)
* move amdgpu_ptl_fmt into kgd_kfd_interface.h (Alex)
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 168 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 3 + 3 files changed, 172 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -3146,6 +3146,7 @@ static const struct attribute_group *amdgpu_sysfs_groups[] = { &amdgpu_vram_mgr_attr_group, &amdgpu_gtt_mgr_attr_group, &amdgpu_flash_attr_group, + &amdgpu_ptl_attr_group, NULL, };
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +168 -0
186 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +3 -0
@@ -63,6 +63,7 @@#define MBOX_TOS_RESP_MASK (GFX_CMD_RESPONSE_MASK | GFX_CMD_STATUS_MASK)extern const struct attribute_group amdgpu_flash_attr_group; +extern const struct attribute_group amdgpu_ptl_attr_group;enum psp_shared_mem_size {PSP_ASD_SHARED_MEM_SIZE =0x0 ,
@@ -660,5 +661,7 @@ int amdgpu_psp_get_fw_type(struct amdgpu_firmware_info *ucode,int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2); +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev); +void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev);#endif
Signature · 1 line
2.34.1
Re: [PATCH 08/22] drm/amdgpu: add sysfs for Peak Tops Limiter (PTL)
Quoted 104 lines · Perry Yuan
Add per-GPU sysfs files under
/sys/class/drm/cardX/device/ptlto control the Peak Tops Limiter (PTL) feature. Exposesptl_enable(enable/disable PTL),ptl_format(set/query preferred formats), andptl_supported_formats(list supported formats)Example usage
-------------
Query PTL status:
cat /sys/class/drm/card1/device/ptl/ptl_enableEnable PTL:
sudo bash -c "echo 1 > /sys/class/drm/card1/device/ptl/ptl_enable"Disable PTL:
sudo bash -c "echo 0 > /sys/class/drm/card1/device/ptl/ptl_enable"Set PTL preferred formats:
`sudo bash -c "echo I8,F32 > /sys/class/drm/card1/device/ptl/ptl_format"`Query supported formats:
cat /sys/class/drm/card1/device/ptl/ptl_supported_formatsv3 changes:
* move N/A to previous format in format show(Alex)
* fix format check for format store(Alex)
* drop the ptl declarations intoamdgpu_ptl.h(Alex)v2 changes:
* add usage commands in commit info (Alex)
* moveamdgpu_ptl_fmtintokgd_kfd_interface.h(Alex)Signed-off-by Perry Yuan <[email protected]>Reviewed-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 168 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 3 + 3 files changed, 172 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -3146,6 +3146,7 @@ static const struct attribute_group *amdgpu_sysfs_groups[] = { &amdgpu_vram_mgr_attr_group, &amdgpu_gtt_mgr_attr_group, &amdgpu_flash_attr_group, + &amdgpu_ptl_attr_group, NULL, };drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +37
-0@@ -52,6 +52,15 @@ static int psp_load_smu_fw(struct psp_context *psp);static int psp_rap_terminate (struct psp_context *psp);static int psp_securedisplay_terminate (struct psp_context *psp); +static const char *const amdgpu_ptl_fmt_str[] = { + [AMDGPU_PTL_FMT_I8 ] ="I8" , + [AMDGPU_PTL_FMT_F16 ] ="F16" , + [AMDGPU_PTL_FMT_BF16 ] ="BF16" , + [AMDGPU_PTL_FMT_F32 ] ="F32" , + [AMDGPU_PTL_FMT_F64 ] ="F64" , + [AMDGPU_PTL_FMT_INVALID ] ="INVALID" , +}; +static int psp_ring_init (struct psp_context *psp,enum psp_ring_type ring_type) {@@ -1277,6 +1286,140 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code,return ret; } +static enum amdgpu_ptl_fmt str_to_ptl_fmt (const char *str) +{ +int i; + +for (i =0 ; i <AMDGPU_PTL_FMT_INVALID ; ++i) { +if (!strcmp (str, amdgpu_ptl_fmt_str[i])) +return (enum amdgpu_ptl_fmt )i; + } + +return AMDGPU_PTL_FMT_INVALID ; +} + +static ssize_t ptl_supported_formats_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t len =0 ; + +for (int i =0 ; i <AMDGPU_PTL_FMT_INVALID ; ++i) { + len +=sysfs_emit_at (buf, len,"%s%s" , + amdgpu_ptl_fmt_str[i], + (i <AMDGPU_PTL_FMT_INVALID -1 ) ?"," :"\n" ); + } + +return len; +} + +static ssize_t ptl_enable_store(struct device *dev, + struct device_attribute *attr,
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code, · line 1326
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +10
-0+ const char *buf, size_t count) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); +struct psp_context *psp = &adev->psp; +bool enable, cur_enabled; +uint32_t ptl_state, fmt1, fmt2; +int ret; + +if (sysfs_streq (buf,"enabled" ) ||sysfs_streq (buf,"1" ))
"enable"
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code, · line 1328
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +2
-0+ enable = true; + else if (sysfs_streq(buf, "disabled") || sysfs_streq(buf, "0"))
"disable"
Alex
Quoted 152 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +119
-0+ enable = false; + else + return -EINVAL; + + fmt1 = psp->ptl_fmt1; + fmt2 = psp->ptl_fmt2; + ptl_state = enable ?1 :0 ; + + cur_enabled =READ_ONCE (psp->ptl_enabled); +if (cur_enabled == enable) +return count; + + ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2); +if (ret) { +dev_err (adev->dev,"Failed to set PTL err = %d\n" , ret); +return ret; + } + +return count; +} + +static ssize_t ptl_enable_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); +struct psp_context *psp = &adev->psp; + +return sysfs_emit (buf,"%s\n" , psp->ptl_enabled ?"enabled" :"disabled" ); +} + +static ssize_t ptl_format_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); +struct psp_context *psp = &adev->psp; +char fmt1_str[8 ], fmt2_str[8 ]; +enum amdgpu_ptl_fmt fmt1_enum, fmt2_enum; +uint32_t ptl_state, fmt1, fmt2; +int ret; + +/* Only allow format update when PTL is enabled */ +if (!psp->ptl_enabled) +return -EPERM ; + +/* Parse input, expecting "FMT1,FMT2" */ +if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) +return -EINVAL ; + + fmt1_enum =str_to_ptl_fmt (fmt1_str); + fmt2_enum =str_to_ptl_fmt (fmt2_str); + +if (fmt1_enum >=AMDGPU_PTL_FMT_INVALID || + fmt2_enum >=AMDGPU_PTL_FMT_INVALID || + fmt1_enum == fmt2_enum) +return -EINVAL ; + + ptl_state = psp->ptl_enabled; + fmt1 = fmt1_enum; + fmt2 = fmt2_enum; + ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2); +if (ret) { +dev_err (adev->dev,"Failed to update PTL err = %d\n" , ret); +return ret; + } + +return count; +} + +static ssize_t ptl_format_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); +struct psp_context *psp = &adev->psp; + +return sysfs_emit (buf,"%s,%s\n" , + amdgpu_ptl_fmt_str[psp->ptl_fmt1], + amdgpu_ptl_fmt_str[psp->ptl_fmt2]); +} + +static umode_t amdgpu_ptl_is_visible (struct kobject *kobj,struct attribute *attr,int idx) +{ +struct device *dev =kobj_to_dev (kobj); +struct drm_device *ddev =dev_get_drvdata (dev); +struct amdgpu_device *adev =drm_to_adev (ddev); + +/* Only show PTL sysfs files if PTL hardware is supported */ +if (!adev->psp.ptl_hw_supported) +return 0 ; + +return attr->mode; +} +int psp_spatial_partition (struct psp_context *psp,int mode) {struct psp_gfx_cmd_resp *cmd;@@ -4271,6 +4414,31 @@ void psp_copy_fw(struct psp_context *psp, uint8_t *start_addr, uint32_t bin_size static DEVICE_ATTR(usbc_pd_fw, 0644, psp_usbc_pd_fw_sysfs_read, psp_usbc_pd_fw_sysfs_write); +/** +* DOC: PTL sysfs attributes +* These sysfs files under /sys/class/drm/cardX/device/ptl allow users to enable or disable +* the Peak Tops Limiter (PTL), configure preferred PTL data formats, and query supported +* formats for each GPU. +*/ +static DEVICE_ATTR(ptl_enable, 0644, + ptl_enable_show, ptl_enable_store); +static DEVICE_ATTR(ptl_format, 0644, + ptl_format_show, ptl_format_store); +static DEVICE_ATTR(ptl_supported_formats, 0444, + ptl_supported_formats_show, NULL); + +static struct attribute *ptl_attrs[] = { + &dev_attr_ptl_enable.attr, + &dev_attr_ptl_format.attr, + &dev_attr_ptl_supported_formats.attr, +NULL , +}; + +const struct attribute_group amdgpu_ptl_attr_group = { + .name ="ptl" , + .attrs = ptl_attrs, + .is_visible = amdgpu_ptl_is_visible, +};int is_psp_fw_valid (struct psp_bin_desc bin) {drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +3
-1@@ -63,6 +63,7 @@#define MBOX_TOS_RESP_MASK (GFX_CMD_RESPONSE_MASK | GFX_CMD_STATUS_MASK)extern const struct attribute_group amdgpu_flash_attr_group; +extern const struct attribute_group amdgpu_ptl_attr_group;enum psp_shared_mem_size {PSP_ASD_SHARED_MEM_SIZE =0x0 ,@@ -660,5 +661,7 @@ int amdgpu_psp_get_fw_type(struct amdgpu_firmware_info *ucode,int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2); +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev); +void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev);#endif --2.34.1
PATCH 9/22 drm/amdgpu: add firmware version check for PTL support
In reply to Perry YuanPTL (Peak TOPS Limiter) functionality is only available starting from firmware 0x0036081a. Add the same firmware version gate in both places that already verify PTL hardware capability:
v2 change:
* move psp and gc version check into psp_performance_monitor_hw()
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4 -0
@@ -1252,6 +1252,10 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code,if (amdgpu_sriov_vf (psp->adev))return 0 ; +if (amdgpu_ip_version (psp->adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || + psp->sos.fw_version <0x0036081a ) +return -EOPNOTSUPP ; +if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) ||psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2))return -EINVAL ;
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0 -3
@@ -2376,9 +2376,6 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool stauint32_t ptl_state = state ?1 :0 ;int r; -if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) -return -ENOTSUPP ; -if (!adev->psp.funcs)return -EOPNOTSUPP ;
Signature · 1 line
2.34.1
Re: [PATCH 09/22] drm/amdgpu: add firmware version check for PTL support
Quoted 10 lines · Perry Yuan
PTL (Peak TOPS Limiter) functionality is only available starting from firmware
0x0036081a. Add the same firmware version gate in both places that already verify PTL hardware capability:v2 change:
* move psp and gc version check intopsp_performance_monitor_hw()Signed-off-by Perry Yuan <[email protected]>Reviewed-by Lijo Lazar <[email protected]>
I'd squash this into patch 2.
Alex
Quoted 37 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 4 ++++ drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +4
-0@@ -1252,6 +1252,10 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code,if (amdgpu_sriov_vf (psp->adev))return 0 ; +if (amdgpu_ip_version (psp->adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || + psp->sos.fw_version <0x0036081a ) +return -EOPNOTSUPP ; +if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) ||psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2))return -EINVAL ;drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +0
-4@@ -2376,9 +2376,6 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool stauint32_t ptl_state = state ?1 :0 ;int r; -if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 )) -return -ENOTSUPP ; -if (!adev->psp.funcs)return -EOPNOTSUPP ; --2.34.1
PATCH 10/22 drm/amdgpu: add PTL sysfs interface for old kernels
In reply to Perry Yuansome old kernels do not export pci_driver.dev_groups, so the "ptl" sub-directory is not create whle HAVE_PCI_DRIVER_DEV_GROUPS is set as false by kcl.
Move the sysfs creation path into amdgpu_device_sys_interface_init() / amdgpu_device_sys_interface_fini() so that both new and old kernels use the same amdgpu_ptl_attr_group definition while keeping the implementation in one place.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -4337,6 +4337,7 @@ static int amdgpu_device_sys_interface_init(struct amdgpu_device *adev)amdgpu_reg_state_sysfs_init (adev);amdgpu_xcp_sysfs_init (adev);amdgpu_uma_sysfs_init (adev); +amdgpu_ptl_sysfs_init (adev);return r; }
@@ -4353,6 +4354,7 @@ static void amdgpu_device_sys_interface_fini(struct amdgpu_device *adev)amdgpu_reg_state_sysfs_fini (adev);amdgpu_xcp_sysfs_fini (adev);amdgpu_uma_sysfs_fini (adev); +amdgpu_ptl_sysfs_fini (adev); }/**
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0 -1
@@ -3146,7 +3146,6 @@ static const struct attribute_group *amdgpu_sysfs_groups[] = { &amdgpu_vram_mgr_attr_group, &amdgpu_gtt_mgr_attr_group, &amdgpu_flash_attr_group, - &amdgpu_ptl_attr_group, NULL, };
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +16 -0
@@ -1424,6 +1424,22 @@ static umode_t amdgpu_ptl_is_visible(struct kobject *kobj, struct attribute *attreturn attr->mode; } +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev) +{ +if (!adev->psp.ptl_hw_supported) +return 0 ; + +return sysfs_create_group (&adev->dev->kobj, &amdgpu_ptl_attr_group); +} + +void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev) +{ +if (!adev->psp.ptl_hw_supported) +return ; + +sysfs_remove_group (&adev->dev->kobj, &amdgpu_ptl_attr_group); +} +int psp_spatial_partition (struct psp_context *psp,int mode) {struct psp_gfx_cmd_resp *cmd;
Signature · 1 line
2.34.1
PATCH 11/22 drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic
In reply to Perry YuanIntroduce a new IOCTL option to allow userspace explicit control over the Peak Tops Limiter (PTL) state for profiling
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 89 +++++++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 +- include/uapi/linux/kfd_ioctl.h | 7 ++ 6 files changed, 108 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +2 -0
@@ -476,6 +476,8 @@ struct psp_context {enum amdgpu_ptl_fmt ptl_fmt2;bool ptl_enabled;bool ptl_hw_supported; +/* PTL disable reference counting */ +atomic_t ptl_disable_ref; };struct amdgpu_psp_funcs {
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2 -0
@@ -2395,6 +2395,8 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool sta adev->psp.ptl_hw_supported = true; +atomic_set (&adev->psp.ptl_disable_ref,0 ); +return 0 ; }
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +87 -2
113 lines not on this page · raw message
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6 -0
@@ -872,6 +872,8 @@ struct kfd_process_device {bool has_reset_queue;u32 pasid; +/* Indicates this process has requested PTL stay disabled */ +bool ptl_disable_req; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)
@@ -1609,6 +1611,10 @@ static inline bool kfd_is_first_node(struct kfd_node *node)/* PTL support */ int kfd_ptl_control (struct kfd_process_device *pdd,bool enable); +int kfd_ptl_disable_request (struct kfd_process_device *pdd, +struct kfd_process *p); +int kfd_ptl_disable_release (struct kfd_process_device *pdd, +struct kfd_process *p);/* Debugfs */ #if defined(CONFIG_DEBUG_FS )
drivers/gpu/drm/amd/amdkfd/kfd_process.c +4 -1
@@ -1115,7 +1115,6 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_procemutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); -kfd_ptl_control (pdd, true); pdd->dev->kfd->profiler_process =NULL ; }mutex_unlock (&pdd->dev->kfd->profiler_lock);
@@ -1133,6 +1132,10 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)pr_debug ("Releasing pdd (topology id %d, for pid %d)\n" , pdd->dev->id, p->lead_thread->pid);kfd_process_profiler_release (p, pdd); + +if (pdd->ptl_disable_req) +kfd_ptl_disable_release (pdd, p); +kfd_process_device_destroy_cwsr_dgpu (pdd);kfd_process_device_destroy_ib_mem (pdd);
include/uapi/linux/kfd_ioctl.h +7 -0
@@ -1572,6 +1572,7 @@ enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 ,KFD_IOC_PROFILER_PC_SAMPLE =1 ,KFD_IOC_PROFILER_VERSION =2 , + KFD_IOC_PROFILER_PTL_CONTROL = 3, };/**
@@ -1583,10 +1584,16 @@ struct kfd_ioctl_pmc_settings {__u32 perfcount_enable;/* Force Perfcount Enable for queues on GPU */ }; +struct kfd_ioctl_ptl_control { +__u32 gpu_id;/* user_gpu_id */ +__u32 enable;/* set 1 to enable PTL, set 0 to disable PTL */ +}; +struct kfd_ioctl_profiler_args {__u32 op;/* kfd_profiler_op */ union {struct kfd_ioctl_pmc_settings pmc; +struct kfd_ioctl_ptl_control ptl;__u32 version;/* KFD_IOC_PROFILER_VERSION_NUM */ }; };
Signature · 1 line
2.34.1
Re: [PATCH 11/22] drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic
Quoted 6 lines · Perry Yuan
Introduce a new IOCTL option to allow userspace explicit control over the Peak Tops Limiter (PTL) state for profiling
Signed-off-by Perry Yuan <[email protected]>Reviewed-by Yifan Zhang <[email protected]>
Please provide a link to the userspace that uses this new IOCTL interface.
Alex
Quoted 235 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 89 +++++++++++++++++++++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 ++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 5 +- include/uapi/linux/kfd_ioctl.h | 7 ++ 6 files changed, 108 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +2
-0@@ -476,6 +476,8 @@ struct psp_context {enum amdgpu_ptl_fmt ptl_fmt2;bool ptl_enabled;bool ptl_hw_supported; +/* PTL disable reference counting */ +atomic_t ptl_disable_ref; };struct amdgpu_psp_funcs {drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2
-0@@ -2395,6 +2395,8 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool sta adev->psp.ptl_hw_supported = true; +atomic_set (&adev->psp.ptl_disable_ref,0 ); +return 0 ; }drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +87
-2@@ -1785,6 +1785,88 @@ int kfd_ptl_control(struct kfd_process_device *pdd, bool enable)return ret; } +int kfd_ptl_disable_request (struct kfd_process_device *pdd, +struct kfd_process *p) +{ +struct amdgpu_device *adev; +int ret =0 ; + +if (!pdd) +return -ENODEV ; + + adev = pdd->dev->adev; +mutex_lock (&p->mutex); + +if (pdd->ptl_disable_req) + goto out; + +if (atomic_inc_return (&adev->psp.ptl_disable_ref) ==1 ) { + ret =kfd_ptl_control (pdd, false); +if (ret) { +atomic_dec (&adev->psp.ptl_disable_ref); +dev_warn (pdd->dev->adev->dev, +"failed to disable PTL\n" ); + goto out; + } + } + pdd->ptl_disable_req = true; + +out: +mutex_unlock (&p->mutex); +return ret; +} + +int kfd_ptl_disable_release (struct kfd_process_device *pdd, +struct kfd_process *p) +{ +struct amdgpu_device *adev; +int ret =0 ; + +if (!pdd) +return -ENODEV ; + + adev = pdd->dev->adev; +mutex_lock (&p->mutex); +if (!pdd->ptl_disable_req) + goto out; + +if (atomic_dec_return (&adev->psp.ptl_disable_ref) ==0 ) { + ret =kfd_ptl_control (pdd, true); +if (ret) { +atomic_inc (&adev->psp.ptl_disable_ref); +dev_warn (pdd->dev->adev->dev, +"failed to enable PTL\n" ); + goto out; + } + } + pdd->ptl_disable_req = false; + +out: +mutex_unlock (&p->mutex); +return ret; +} + +static int kfd_profiler_ptl_control (struct kfd_process *p, +struct kfd_ioctl_ptl_control *args) +{ +struct kfd_process_device *pdd; +int ret; + +mutex_lock (&p->mutex); + pdd =kfd_process_device_data_by_id (p, args->gpu_id); +mutex_unlock (&p->mutex); + +if (!pdd) +return -ENODEV ; + +if (args->enable ==0 ) + ret =kfd_ptl_disable_request (pdd, p); +else + ret =kfd_ptl_disable_release (pdd, p); + +return ret; +} +static int criu_checkpoint_process (struct kfd_process *p,uint8_t __user *user_priv_data,uint64_t *priv_offset)@@ -3250,7 +3332,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,if (!kfd->profiler_process) { kfd->profiler_process = p; status =0 ; -kfd_ptl_control (pdd, false); +kfd_ptl_disable_request (pdd, p); }else if (kfd->profiler_process == p) { status = -EALREADY ; }else {@@ -3259,7 +3341,8 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, }else if (op ==0 && kfd->profiler_process == p) { kfd->profiler_process =NULL ; status =0 ; -kfd_ptl_control (pdd, true); +kfd_ptl_disable_release (pdd, p); + }mutex_unlock (&kfd->profiler_lock);@@ -3302,6 +3385,8 @@ static int kfd_ioctl_profiler(struct file *filep, struct kfd_process *p, void *dreturn 0 ;case KFD_IOC_PROFILER_PMC :return kfd_profiler_pmc (p, &args->pmc); +case KFD_IOC_PROFILER_PTL_CONTROL : +return kfd_profiler_ptl_control (p, &args->ptl); }return -EINVAL ; }drivers/gpu/drm/amd/amdkfd/kfd_priv.h +6
-0@@ -872,6 +872,8 @@ struct kfd_process_device {bool has_reset_queue;u32 pasid; +/* Indicates this process has requested PTL stay disabled */ +bool ptl_disable_req; };#define qpd_to_pdd (x) container_of(x, struct kfd_process_device, qpd)@@ -1609,6 +1611,10 @@ static inline bool kfd_is_first_node(struct kfd_node *node)/* PTL support */ int kfd_ptl_control (struct kfd_process_device *pdd,bool enable); +int kfd_ptl_disable_request (struct kfd_process_device *pdd, +struct kfd_process *p); +int kfd_ptl_disable_release (struct kfd_process_device *pdd, +struct kfd_process *p);/* Debugfs */ #if defined(CONFIG_DEBUG_FS )drivers/gpu/drm/amd/amdkfd/kfd_process.c +4
-1@@ -1115,7 +1115,6 @@ static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_procemutex_lock (&pdd->dev->kfd->profiler_lock);if (pdd->dev->kfd->profiler_process == p) { pdd->qpd.dqm->ops.set_perfcount (pdd->qpd.dqm,0 ); -kfd_ptl_control (pdd, true); pdd->dev->kfd->profiler_process =NULL ; }mutex_unlock (&pdd->dev->kfd->profiler_lock);@@ -1133,6 +1132,10 @@ static void kfd_process_destroy_pdds(struct kfd_process *p)pr_debug ("Releasing pdd (topology id %d, for pid %d)\n" , pdd->dev->id, p->lead_thread->pid);kfd_process_profiler_release (p, pdd); + +if (pdd->ptl_disable_req) +kfd_ptl_disable_release (pdd, p); +kfd_process_device_destroy_cwsr_dgpu (pdd);kfd_process_device_destroy_ib_mem (pdd);include/uapi/linux/kfd_ioctl.h +7
-1@@ -1572,6 +1572,7 @@ enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 ,KFD_IOC_PROFILER_PC_SAMPLE =1 ,KFD_IOC_PROFILER_VERSION =2 , + KFD_IOC_PROFILER_PTL_CONTROL = 3, };/** @@ -1583,10 +1584,16 @@ struct kfd_ioctl_pmc_settings {__u32 perfcount_enable;/* Force Perfcount Enable for queues on GPU */ }; +struct kfd_ioctl_ptl_control { +__u32 gpu_id;/* user_gpu_id */ +__u32 enable;/* set 1 to enable PTL, set 0 to disable PTL */ +}; +struct kfd_ioctl_profiler_args {__u32 op;/* kfd_profiler_op */ union {struct kfd_ioctl_pmc_settings pmc; +struct kfd_ioctl_ptl_control ptl;__u32 version;/* KFD_IOC_PROFILER_VERSION_NUM */ }; }; --2.34.1
PATCH 12/22 drm/amdkfd: suspend scheduler during PTL re-enabling
In reply to Perry YuanStop the scheduler before releasing the PTL disable request to ensure the GPU is quiescent during the PTL state transition. This prevents potential queue preemption failures and GPU resets caused by modifying PTL state while waves are executing
v1->v2:
only stop/start the scheduler when the PTL state actually needs to transition(Yifan)
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +5 -0
@@ -1831,7 +1831,11 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, goto out;if (atomic_dec_return (&adev->psp.ptl_disable_ref) ==0 ) { +if (adev->kfd.init_complete) +amdgpu_amdkfd_stop_sched (adev, pdd->dev->node_id); ret =kfd_ptl_control (pdd, true); +if (adev->kfd.init_complete) +amdgpu_amdkfd_start_sched (adev, pdd->dev->node_id);if (ret) {atomic_inc (&adev->psp.ptl_disable_ref); dev_warn(pdd->dev->adev->dev,
@@ -1839,6 +1843,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, goto out; } } + pdd->ptl_disable_req = false; out:
Signature · 1 line
2.34.1
PATCH 13/22 drm/amdkfd: Refactor PTL control and add HW support check
In reply to Perry YuanThis is a design change to move the scheduler suspension and resumption logic directly into kfd_ptl_control. This ensures the KFD scheduler is always stopped during PTL switching command execution, which is required for the updated PTL control flow.
Additionally, update profile_lock_device() to check for ptl_hw_supported before attempting to enable or disable PTL restrictions.
--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 27 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +21 -6
@@ -1778,10 +1778,17 @@ int kfd_ptl_control(struct kfd_process_device *pdd, bool enable)if (!pdd->dev->kfd2kgd || !pdd->dev->kfd2kgd->ptl_ctrl)return -EOPNOTSUPP ; +if (adev->kfd.init_complete) +amdgpu_amdkfd_stop_sched (adev, pdd->dev->node_id); + ret = pdd->dev->kfd2kgd->ptl_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &pref_format1, &pref_format2); + +if (adev->kfd.init_complete) +amdgpu_amdkfd_start_sched (adev, pdd->dev->node_id); +return ret; }
@@ -1831,11 +1838,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, goto out;if (atomic_dec_return (&adev->psp.ptl_disable_ref) ==0 ) { -if (adev->kfd.init_complete) -amdgpu_amdkfd_stop_sched (adev, pdd->dev->node_id); ret =kfd_ptl_control (pdd, true); -if (adev->kfd.init_complete) -amdgpu_amdkfd_start_sched (adev, pdd->dev->node_id);if (ret) {atomic_inc (&adev->psp.ptl_disable_ref); dev_warn(pdd->dev->adev->dev,
@@ -3337,7 +3340,13 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,if (!kfd->profiler_process) { kfd->profiler_process = p; status =0 ; -kfd_ptl_disable_request (pdd, p); +if (pdd->dev->adev->psp.ptl_hw_supported) { + status =kfd_ptl_disable_request (pdd, p); +if (status !=0 ) +dev_err (kfd_device, +"Failed to lock device %d for profiling, error %d\n" , + gpu_id, status); + } }else if (kfd->profiler_process == p) { status = -EALREADY ; }else {
@@ -3346,8 +3355,14 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, }else if (op ==0 && kfd->profiler_process == p) { kfd->profiler_process =NULL ; status =0 ; -kfd_ptl_disable_release (pdd, p); +if (pdd->dev->adev->psp.ptl_hw_supported) { + status =kfd_ptl_disable_release (pdd, p); +if (status) +dev_err (kfd_device, +"Failed to unlock device %d for profiling, error %d\n" , + gpu_id, status); + } }mutex_unlock (&kfd->profiler_lock);
Signature · 1 line
2.34.1
PATCH 14/22 drm/amdkfd: Optimize PTL locking to fix potential deadlock
In reply to Perry YuanRelease profiler_lock before calling kfd_ptl_disable_request and kfd_ptl_disable_release to resolve potential deadlock Introduce a dedicated adev->psp.ptl_mutex to protect PTL state instead of relying on the KFD process mutex. This optimization ensures thread safety independent of the process lock hierarchy.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 + drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++++++++---- 4 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -4442,6 +4442,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->virt.vf_errors.lock);hash_init (adev->mn_hash);mutex_init (&adev->psp.mutex); +mutex_init (&adev->psp.ptl_mutex);mutex_init (&adev->notifier_lock);mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +15 -1
@@ -1260,6 +1260,15 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code, psp_ptl_fmt_verify(psp, *fmt2, &ptl_fmt2))return -EINVAL ; +/* +* Add check to skip if state and formats are identical to current ones +*/ +if (req_code ==PSP_PTL_PERF_MON_SET && + psp->ptl_enabled == *ptl_state && + psp->ptl_fmt1 == ptl_fmt1 && + psp->ptl_fmt2 == ptl_fmt2) +return 0 ; + cmd =acquire_psp_cmd_buf (psp); cmd->cmd_id =GFX_CMD_ID_PERF_HW ;
@@ -1334,19 +1343,24 @@ static ssize_t ptl_enable_store(struct device *dev,else return -EINVAL ; +mutex_lock (&psp->ptl_mutex); fmt1 = psp->ptl_fmt1; fmt2 = psp->ptl_fmt2; ptl_state = enable ?1 :0 ; cur_enabled =READ_ONCE (psp->ptl_enabled); -if (cur_enabled == enable) +if (cur_enabled == enable) { +mutex_unlock (&psp->ptl_mutex);return count; + } ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to set PTL err = %d\n" , ret); +mutex_unlock (&psp->ptl_mutex);return ret; } +mutex_unlock (&psp->ptl_mutex);return count; }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
@@ -478,6 +478,7 @@ struct psp_context {bool ptl_hw_supported;/* PTL disable reference counting */ atomic_t ptl_disable_ref; +struct mutex ptl_mutex; };struct amdgpu_psp_funcs {
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +8 -4
@@ -1802,7 +1802,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd,return -ENODEV ; adev = pdd->dev->adev; -mutex_lock (&p->mutex); +mutex_lock (&adev->psp.ptl_mutex);if (pdd->ptl_disable_req) goto out;
@@ -1819,7 +1819,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, pdd->ptl_disable_req = true; out: -mutex_unlock (&p->mutex); +mutex_unlock (&adev->psp.ptl_mutex);return ret; }
@@ -1833,7 +1833,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd,return -ENODEV ; adev = pdd->dev->adev; -mutex_lock (&p->mutex); +mutex_lock (&adev->psp.ptl_mutex);if (!pdd->ptl_disable_req) goto out;
@@ -1850,7 +1850,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, pdd->ptl_disable_req = false; out: -mutex_unlock (&p->mutex); +mutex_unlock (&adev->psp.ptl_mutex);return ret; }
@@ -3340,6 +3340,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,if (!kfd->profiler_process) { kfd->profiler_process = p; status =0 ; +mutex_unlock (&kfd->profiler_lock);if (pdd->dev->adev->psp.ptl_hw_supported) { status =kfd_ptl_disable_request (pdd, p);if (status !=0 )
@@ -3347,6 +3348,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,"Failed to lock device %d for profiling, error %d\n" , gpu_id, status); } +return status; }else if (kfd->profiler_process == p) { status = -EALREADY ; }else {
@@ -3355,6 +3357,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, }else if (op ==0 && kfd->profiler_process == p) { kfd->profiler_process =NULL ; status =0 ; +mutex_unlock (&kfd->profiler_lock);if (pdd->dev->adev->psp.ptl_hw_supported) { status =kfd_ptl_disable_release (pdd, p);
@@ -3363,6 +3366,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p,"Failed to unlock device %d for profiling, error %d\n" , gpu_id, status); } +return status; }mutex_unlock (&kfd->profiler_lock);
Signature · 1 line
2.34.1
PATCH 15/22 drm/amdgpu: update PTL sysfs mutex protection section
In reply to Perry Yuanextends the critical section of 'ptl_mutex' to
cover the PTL sysfs update operation.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +15 -6
@@ -1336,14 +1336,16 @@ static ssize_t ptl_enable_store(struct device *dev,uint32_t ptl_state, fmt1, fmt2;int ret; -if (sysfs_streq (buf,"enabled" ) ||sysfs_streq (buf,"1" )) +mutex_lock (&psp->ptl_mutex); +if (sysfs_streq (buf,"enabled" ) ||sysfs_streq (buf,"1" )) { enable = true; -else if (sysfs_streq (buf,"disabled" ) ||sysfs_streq (buf,"0" )) + }else if (sysfs_streq (buf,"disabled" ) ||sysfs_streq (buf,"0" )) { enable = false; -else + }else { +mutex_unlock (&psp->ptl_mutex);return -EINVAL ; + } -mutex_lock (&psp->ptl_mutex); fmt1 = psp->ptl_fmt1; fmt2 = psp->ptl_fmt2; ptl_state = enable ?1 :0 ;
@@ -1390,17 +1392,22 @@ static ssize_t ptl_format_store(struct device *dev,if (!psp->ptl_enabled)return -EPERM ; +mutex_lock (&psp->ptl_mutex);/* Parse input, expecting "FMT1,FMT2" */ -if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) +if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) { +mutex_unlock (&psp->ptl_mutex);return -EINVAL ; + } fmt1_enum =str_to_ptl_fmt (fmt1_str); fmt2_enum =str_to_ptl_fmt (fmt2_str);if (fmt1_enum >=AMDGPU_PTL_FMT_INVALID || fmt2_enum >=AMDGPU_PTL_FMT_INVALID || - fmt1_enum == fmt2_enum) + fmt1_enum == fmt2_enum) { +mutex_unlock (&psp->ptl_mutex);return -EINVAL ; + } ptl_state = psp->ptl_enabled; fmt1 = fmt1_enum;
@@ -1408,8 +1415,10 @@ static ssize_t ptl_format_store(struct device *dev, ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to update PTL err = %d\n" , ret); +mutex_unlock (&psp->ptl_mutex);return ret; } +mutex_unlock (&psp->ptl_mutex);return count; }
Signature · 1 line
2.34.1
PATCH 16/22 drm/amdgpu: Refactor PTL control into public API and internal implementation
In reply to Perry YuanSeparate the PTL (Peak Tops Limiter) control logic into a stable public API layer and an internal implementation layer.
v2: revise commit info
--- .../drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 77 +++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 +- 4 files changed, 48 insertions(+), 35 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c +1 -1
@@ -526,7 +526,7 @@ static uint32_t kgd_v9_4_3_ptl_ctrl(struct amdgpu_device *adev,enum amdgpu_ptl_fmt *fmt1, enum amdgpu_ptl_fmt *fmt2) { - return psp_performance_monitor_hw(&adev->psp, cmd, + return amdgpu_ptl_perf_monitor_ctrl(adev, cmd,ptl_state ,fmt1 ,fmt2 ); }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +45 -32
122 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -1
@@ -662,7 +662,7 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev);int amdgpu_psp_get_fw_type (struct amdgpu_firmware_info *ucode,enum psp_gfx_fw_type *type); -int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +int amdgpu_ptl_perf_monitor_ctrl (struct amdgpu_device *adev,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2);int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev);void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +1 -1
@@ -2388,7 +2388,7 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool sta }/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */ - r =psp_performance_monitor_hw (&adev->psp,PSP_PTL_PERF_MON_SET , &ptl_state, + r =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (r)return r;
Signature · 1 line
2.34.1
Re: [PATCH 16/22] drm/amdgpu: Refactor PTL control into public API and internal implementation
Quoted 9 lines · Perry Yuan
Separate the PTL (Peak Tops Limiter) control logic into a stable public API layer and an internal implementation layer.
v2: revise commit info
Signed-off-by Perry Yuan <[email protected]>Suggested-by Alex Deucher <[email protected]>Reviewed-by Yifan Zhang <[email protected]>
Would be nice to re-generate the patches with this squashed in earlier in the series.
Alex
Quoted 180 lines
--- .../drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 77 +++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 +- 4 files changed, 48 insertions(+), 35 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c +1
-1@@ -526,7 +526,7 @@ static uint32_t kgd_v9_4_3_ptl_ctrl(struct amdgpu_device *adev,enum amdgpu_ptl_fmt *fmt1, enum amdgpu_ptl_fmt *fmt2) { - return psp_performance_monitor_hw(&adev->psp, cmd, + return amdgpu_ptl_perf_monitor_ctrl(adev, cmd,ptl_state ,fmt1 ,fmt2 ); }drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +45
-32@@ -1239,48 +1239,25 @@ static int psp_ptl_fmt_verify(struct psp_context *psp, enum amdgpu_ptl_fmt fmt,return 0 ; } -int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, -uint32_t *ptl_state,uint32_t *fmt1,uint32_t *fmt2) +static int psp_ptl_invoke (struct psp_context *psp,u32 req_code, +uint32_t *ptl_state,uint32_t *fmt1,uint32_t *fmt2) {struct psp_gfx_cmd_resp *cmd; -uint32_t ptl_fmt1, ptl_fmt2;int ret; -if (!psp || !ptl_state || !fmt1 || !fmt2) -return -EINVAL ; - -if (amdgpu_sriov_vf (psp->adev)) -return 0 ; - -if (amdgpu_ip_version (psp->adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || - psp->sos.fw_version <0x0036081a ) -return -EOPNOTSUPP ; - -if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) || -psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2)) -return -EINVAL ; - -/* -* Add check to skip if state and formats are identical to current ones -*/ -if (req_code ==PSP_PTL_PERF_MON_SET && - psp->ptl_enabled == *ptl_state && - psp->ptl_fmt1 == ptl_fmt1 && - psp->ptl_fmt2 == ptl_fmt2) -return 0 ; - cmd =acquire_psp_cmd_buf (psp); cmd->cmd_id =GFX_CMD_ID_PERF_HW ; cmd->cmd.cmd_req_perf_hw.req = req_code; cmd->cmd.cmd_req_perf_hw.ptl_state = *ptl_state; - cmd->cmd.cmd_req_perf_hw.pref_format1 = ptl_fmt1; - cmd->cmd.cmd_req_perf_hw.pref_format2 = ptl_fmt2; + cmd->cmd.cmd_req_perf_hw.pref_format1 = *fmt1; + cmd->cmd.cmd_req_perf_hw.pref_format2 = *fmt2; ret =psp_cmd_submit_buf (psp,NULL , cmd, psp->fence_buf_mc_addr);if (ret) goto out; +/* Parse response */ switch (req_code) {case PSP_PTL_PERF_MON_QUERY : *ptl_state = cmd->resp.uresp.perf_hw_info.ptl_state;@@ -1288,9 +1265,10 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code, *fmt2 = cmd->resp.uresp.perf_hw_info.pref_format2;break ;case PSP_PTL_PERF_MON_SET : +/* Update cached state only on success */ psp->ptl_enabled = *ptl_state; - psp->ptl_fmt1 = ptl_fmt1; - psp->ptl_fmt2 = ptl_fmt2; + psp->ptl_fmt1 = *fmt1; + psp->ptl_fmt2 = *fmt2;break ; }@@ -1299,6 +1277,41 @@ int psp_performance_monitor_hw(struct psp_context *psp, u32 req_code,return ret; } +int amdgpu_ptl_perf_monitor_ctrl (struct amdgpu_device *adev,u32 req_code, +uint32_t *ptl_state,uint32_t *fmt1,uint32_t *fmt2) +{ +uint32_t ptl_fmt1, ptl_fmt2; +struct psp_context *psp; + +if (!adev || !ptl_state || !fmt1 || !fmt2) +return -EINVAL ; + +if (amdgpu_sriov_vf (adev)) +return 0 ; + + psp = &adev->psp; + +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || + psp->sos.fw_version <0x0036081a ) +return -EOPNOTSUPP ; + +/* Verify formats */ +if (psp_ptl_fmt_verify (psp, *fmt1, &ptl_fmt1) || +psp_ptl_fmt_verify (psp, *fmt2, &ptl_fmt2)) +return -EINVAL ; + +/* +* Add check to skip if state and formats are identical to current ones +*/ +if (req_code ==PSP_PTL_PERF_MON_SET && + psp->ptl_enabled == *ptl_state && + psp->ptl_fmt1 == ptl_fmt1 && + psp->ptl_fmt2 == ptl_fmt2) +return 0 ; + +return psp_ptl_invoke (psp, req_code, ptl_state, &ptl_fmt1, &ptl_fmt2); +} +static enum amdgpu_ptl_fmt str_to_ptl_fmt (const char *str) {int i;@@ -1356,7 +1369,7 @@ static ssize_t ptl_enable_store(struct device *dev,return count; } - ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2); + ret =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to set PTL err = %d\n" , ret);mutex_unlock (&psp->ptl_mutex);@@ -1412,7 +1425,7 @@ static ssize_t ptl_format_store(struct device *dev, ptl_state = psp->ptl_enabled; fmt1 = fmt1_enum; fmt2 = fmt2_enum; - ret =psp_performance_monitor_hw (psp,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2); + ret =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to update PTL err = %d\n" , ret);mutex_unlock (&psp->ptl_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1
-1@@ -662,7 +662,7 @@ void amdgpu_psp_debugfs_init(struct amdgpu_device *adev);int amdgpu_psp_get_fw_type (struct amdgpu_firmware_info *ucode,enum psp_gfx_fw_type *type); -int psp_performance_monitor_hw (struct psp_context *psp,u32 req_code, +int amdgpu_ptl_perf_monitor_ctrl (struct amdgpu_device *adev,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2);int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev);void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev);drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +1
-2@@ -2388,7 +2388,7 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool sta }/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */ - r =psp_performance_monitor_hw (&adev->psp,PSP_PTL_PERF_MON_SET , &ptl_state, + r =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (r)return r; --2.34.1
PATCH 17/22 drm/amdgpu: group PTL fields into struct amdgpu_ptl
In reply to Perry YuanMove PTL enums and structures to a unified location in amdgpu_psp.h. Introduce struct amdgpu_ptl to group PTL related fields, replacing loose fields in struct psp_context for better code organization.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 58 ++++++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 18 ++++--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 13 ++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 49 +++++++++--------- 5 files changed, 74 insertions(+), 66 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4442,7 +4442,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->virt.vf_errors.lock);hash_init (adev->mn_hash);mutex_init (&adev->psp.mutex); -mutex_init (&adev->psp.ptl_mutex); +mutex_init (&adev->psp.ptl.ptl_mutex);mutex_init (&adev->notifier_lock);mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +32 -26
171 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +11 -7
@@ -382,6 +382,16 @@ struct psp_ptl_perf_req {uint32_t pref_format2; }; +struct amdgpu_ptl { +enum amdgpu_ptl_fmt ptl_fmt1; +enum amdgpu_ptl_fmt ptl_fmt2; +bool ptl_enabled; +bool ptl_hw_supported; +/* PTL disable reference counting */ +atomic_t ptl_disable_ref; +struct mutex ptl_mutex; +}; +struct psp_context {struct amdgpu_device *adev;struct psp_ring km_ring;
@@ -472,13 +482,7 @@ struct psp_context {#if defined(CONFIG_DEBUG_FS )struct spirom_bo *spirom_dump_trip;#endif -enum amdgpu_ptl_fmt ptl_fmt1; -enum amdgpu_ptl_fmt ptl_fmt2; -bool ptl_enabled; -bool ptl_hw_supported; -/* PTL disable reference counting */ -atomic_t ptl_disable_ref; -struct mutex ptl_mutex; +struct amdgpu_ptl ptl; };struct amdgpu_psp_funcs {
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +7 -6
@@ -2374,17 +2374,18 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool sta {uint32_t fmt1, fmt2;uint32_t ptl_state = state ?1 :0 ; +struct amdgpu_ptl *ptl = &adev->psp.ptl;int r;if (!adev->psp.funcs)return -EOPNOTSUPP ; -if (!adev->psp.ptl_hw_supported) { +if (!ptl->ptl_hw_supported) { fmt1 =GFX_FTYPE_I8 ; fmt2 =GFX_FTYPE_BF16 ; }else { - fmt1 = adev->psp.ptl_fmt1; - fmt2 = adev->psp.ptl_fmt2; + fmt1 = ptl->ptl_fmt1; + fmt2 = ptl->ptl_fmt2; }/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */
@@ -2393,9 +2394,9 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool staif (r)return r; - adev->psp.ptl_hw_supported = true; + ptl->ptl_hw_supported = true; -atomic_set (&adev->psp.ptl_disable_ref,0 ); +atomic_set (&ptl->ptl_disable_ref,0 );return 0 ; }
@@ -2405,7 +2406,7 @@ static int gfx_v9_4_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; -if (adev->psp.ptl_hw_supported) +if (adev->psp.ptl.ptl_hw_supported)gfx_v9_4_3_perf_monitor_ptl_init (adev,0 );amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +23 -26
128 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 18/22 drm/amdgpu: clean up PTL structure member naming convention
In reply to Perry YuanRemove redundant 'ptl_' prefix from amdgpu_ptl structure members since they are already accessed through a ptl pointer, making the prefix redundant and verbose.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 57 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 12 ++--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 ++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 26 +++++----- 5 files changed, 55 insertions(+), 54 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -1
@@ -4442,7 +4442,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->virt.vf_errors.lock);hash_init (adev->mn_hash);mutex_init (&adev->psp.mutex); -mutex_init (&adev->psp.ptl.ptl_mutex); +mutex_init (&adev->psp.ptl.mutex);mutex_init (&adev->notifier_lock);mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +29 -28
162 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +6 -6
@@ -383,13 +383,13 @@ struct psp_ptl_perf_req { };struct amdgpu_ptl { -enum amdgpu_ptl_fmt ptl_fmt1; -enum amdgpu_ptl_fmt ptl_fmt2; -bool ptl_enabled; -bool ptl_hw_supported; +enum amdgpu_ptl_fmt fmt1; +enum amdgpu_ptl_fmt fmt2; +bool enabled; +bool hw_supported;/* PTL disable reference counting */ -atomic_t ptl_disable_ref; -struct mutex ptl_mutex; +atomic_t disable_ref; +struct mutex mutex; };struct psp_context {
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +6 -6
@@ -2380,12 +2380,12 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool staif (!adev->psp.funcs)return -EOPNOTSUPP ; -if (!ptl->ptl_hw_supported) { +if (!ptl->hw_supported) { fmt1 =GFX_FTYPE_I8 ; fmt2 =GFX_FTYPE_BF16 ; }else { - fmt1 = ptl->ptl_fmt1; - fmt2 = ptl->ptl_fmt2; + fmt1 = ptl->fmt1; + fmt2 = ptl->fmt2; }/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */
@@ -2394,9 +2394,9 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool staif (r)return r; - ptl->ptl_hw_supported = true; + ptl->hw_supported = true; -atomic_set (&ptl->ptl_disable_ref,0 ); +atomic_set (&ptl->disable_ref,0 );return 0 ; }
@@ -2406,7 +2406,7 @@ static int gfx_v9_4_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; -if (adev->psp.ptl.ptl_hw_supported) +if (adev->psp.ptl.hw_supported)gfx_v9_4_3_perf_monitor_ptl_init (adev,0 );amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +13 -13
@@ -1768,12 +1768,12 @@ int kfd_ptl_control(struct kfd_process_device *pdd, bool enable) {struct amdgpu_device *adev = pdd->dev->adev;struct amdgpu_ptl *ptl = &adev->psp.ptl; -enum amdgpu_ptl_fmt pref_format1 = ptl->ptl_fmt1; -enum amdgpu_ptl_fmt pref_format2 = ptl->ptl_fmt2; +enum amdgpu_ptl_fmt pref_format1 = ptl->fmt1; +enum amdgpu_ptl_fmt pref_format2 = ptl->fmt2;uint32_t ptl_state = enable ?1 :0 ;int ret; -if (!ptl->ptl_hw_supported) +if (!ptl->hw_supported)return -EOPNOTSUPP ;if (!pdd->dev->kfd2kgd || !pdd->dev->kfd2kgd->ptl_ctrl)
@@ -1800,15 +1800,15 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd,struct amdgpu_ptl *ptl = &adev->psp.ptl;int ret =0 ; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);if (pdd->ptl_disable_req) goto out; -if (atomic_inc_return (&ptl->ptl_disable_ref) ==1 ) { +if (atomic_inc_return (&ptl->disable_ref) ==1 ) { ret =kfd_ptl_control (pdd, false);if (ret) { -atomic_dec (&ptl->ptl_disable_ref); +atomic_dec (&ptl->disable_ref);dev_warn (pdd->dev->adev->dev,"failed to disable PTL\n" ); goto out;
@@ -1817,7 +1817,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, pdd->ptl_disable_req = true; out: -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; }
@@ -1828,15 +1828,15 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd,struct amdgpu_ptl *ptl = &adev->psp.ptl;int ret =0 ; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);if (!pdd->ptl_disable_req) goto out; -if (atomic_dec_return (&ptl->ptl_disable_ref) ==0 ) { +if (atomic_dec_return (&ptl->disable_ref) ==0 ) { ret =kfd_ptl_control (pdd, true);if (ret) { -atomic_inc (&ptl->ptl_disable_ref); +atomic_inc (&ptl->disable_ref);dev_warn (adev->dev,"Failed to enable PTL on release: %d\n" , ret); goto out; }
@@ -1845,7 +1845,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, pdd->ptl_disable_req = false; out: -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; }
@@ -3338,7 +3338,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, kfd->profiler_process = p; status =0 ;mutex_unlock (&kfd->profiler_lock); -if (ptl->ptl_hw_supported) { +if (ptl->hw_supported) { status =kfd_ptl_disable_request (pdd, p);if (status !=0 ) dev_err(kfd_device,
@@ -3356,7 +3356,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, status =0 ;mutex_unlock (&kfd->profiler_lock); -if (ptl->ptl_hw_supported) { +if (ptl->hw_supported) { status =kfd_ptl_disable_release (pdd, p);if (status) dev_err(kfd_device,
Signature · 1 line
2.34.1
Re: [PATCH 18/22] drm/amdgpu: clean up PTL structure member naming convention
Quoted 7 lines · Perry Yuan
Remove redundant '
ptl_' prefix fromamdgpu_ptlstructure members since they are already accessed through a ptl pointer, making the prefix redundant and verbose.Signed-off-by Perry Yuan <[email protected]>Reviewed-by Yifan Zhang <[email protected]>
In general with this patch set, I'd suggest cleaning up the history and splitting up the patches with the various fixes and reworks squashed into the original patches. That way we don't have in consistent states in the middle of the series that may affect bisecing.
Alex
Quoted 361 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 57 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 12 ++--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 12 ++--- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 26 +++++----- 5 files changed, 55 insertions(+), 54 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1@@ -4442,7 +4442,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->virt.vf_errors.lock);hash_init (adev->mn_hash);mutex_init (&adev->psp.mutex); -mutex_init (&adev->psp.ptl.ptl_mutex); +mutex_init (&adev->psp.ptl.mutex);mutex_init (&adev->notifier_lock);mutex_init (&adev->pm.stable_pstate_ctx_lock);mutex_init (&adev->benchmark_mutex);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +29
-28@@ -1267,9 +1267,9 @@ static int psp_ptl_invoke(struct psp_context *psp, u32 req_code,break ;case PSP_PTL_PERF_MON_SET :/* Update cached state only on success */ - ptl->ptl_enabled = *ptl_state; - ptl->ptl_fmt1 = *fmt1; - ptl->ptl_fmt2 = *fmt2; + ptl->enabled = *ptl_state; + ptl->fmt1 = *fmt1; + ptl->fmt2 = *fmt2;break ; }@@ -1285,7 +1285,7 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code, {uint32_t ptl_fmt1, ptl_fmt2;struct psp_context *psp; -struct amdgpu_ptl *ptl = &adev->psp.ptl; +struct amdgpu_ptl *ptl;if (!adev || !ptl_state || !fmt1 || !fmt2)return -EINVAL ;@@ -1294,6 +1294,7 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,return 0 ; psp = &adev->psp; + ptl = &psp->ptl;if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || psp->sos.fw_version <0x0036081a )@@ -1308,9 +1309,9 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code,* Add check to skip if state and formats are identical to current ones */ if (req_code ==PSP_PTL_PERF_MON_SET && - ptl->ptl_enabled == *ptl_state && - ptl->ptl_fmt1 == ptl_fmt1 && - ptl->ptl_fmt2 == ptl_fmt2) + ptl->enabled == *ptl_state && + ptl->fmt1 == ptl_fmt1 && + ptl->fmt2 == ptl_fmt2)return 0 ;return psp_ptl_invoke (psp, req_code, ptl_state, &ptl_fmt1, &ptl_fmt2);@@ -1354,33 +1355,33 @@ static ssize_t ptl_enable_store(struct device *dev,uint32_t ptl_state, fmt1, fmt2;int ret; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);if (sysfs_streq (buf,"enabled" ) ||sysfs_streq (buf,"1" )) { enable = true; }else if (sysfs_streq (buf,"disabled" ) ||sysfs_streq (buf,"0" )) { enable = false; }else { -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return -EINVAL ; } - fmt1 = ptl->ptl_fmt1; - fmt2 = ptl->ptl_fmt2; + fmt1 = ptl->fmt1; + fmt2 = ptl->fmt2; ptl_state = enable ?1 :0 ; - cur_enabled =READ_ONCE (psp->ptl_enabled); + cur_enabled =READ_ONCE (psp->enabled);if (cur_enabled == enable) { -mutex_unlock (&psp->ptl_mutex); +mutex_unlock (&psp->mutex);return count; } ret =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to set PTL err = %d\n" , ret); -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; } -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return count; }@@ -1391,7 +1392,7 @@ static ssize_t ptl_enable_show(struct device *dev, struct device_attribute *attrstruct amdgpu_device *adev =drm_to_adev (ddev);struct psp_context *psp = &adev->psp; -return sysfs_emit (buf,"%s\n" , psp->ptl.ptl_enabled ?"enabled" :"disabled" ); +return sysfs_emit (buf,"%s\n" , psp->ptl.enabled ?"enabled" :"disabled" ); } static ssize_t ptl_format_store(struct device *dev,@@ -1408,13 +1409,13 @@ static ssize_t ptl_format_store(struct device *dev,int ret;/* Only allow format update when PTL is enabled */ -if (!ptl->ptl_enabled) +if (!ptl->enabled)return -EPERM ; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);/* Parse input, expecting "FMT1,FMT2" */ if (sscanf (buf,"%7[^,],%7s" , fmt1_str, fmt2_str) !=2 ) { -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return -EINVAL ; }@@ -1424,20 +1425,20 @@ static ssize_t ptl_format_store(struct device *dev,if (fmt1_enum >=AMDGPU_PTL_FMT_INVALID || fmt2_enum >=AMDGPU_PTL_FMT_INVALID || fmt1_enum == fmt2_enum) { -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return -EINVAL ; } - ptl_state = ptl->ptl_enabled; + ptl_state = ptl->enabled; fmt1 = fmt1_enum; fmt2 = fmt2_enum; ret =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to update PTL err = %d\n" , ret); -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; } -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return count; }@@ -1449,8 +1450,8 @@ static ssize_t ptl_format_show(struct device *dev, struct device_attribute *attrstruct psp_context *psp = &adev->psp;return sysfs_emit (buf,"%s,%s\n" , - amdgpu_ptl_fmt_str[psp->ptl.ptl_fmt1], - amdgpu_ptl_fmt_str[psp->ptl.ptl_fmt2]); + amdgpu_ptl_fmt_str[psp->ptl.fmt1], + amdgpu_ptl_fmt_str[psp->ptl.fmt2]); }static umode_t amdgpu_ptl_is_visible (struct kobject *kobj,struct attribute *attr,int idx)@@ -1460,7 +1461,7 @@ static umode_t amdgpu_ptl_is_visible(struct kobject *kobj, struct attribute *attstruct amdgpu_device *adev =drm_to_adev (ddev);/* Only show PTL sysfs files if PTL hardware is supported */ -if (!adev->psp.ptl.ptl_hw_supported) +if (!adev->psp.ptl.hw_supported)return 0 ;return attr->mode;@@ -1468,7 +1469,7 @@ static umode_t amdgpu_ptl_is_visible(struct kobject *kobj, struct attribute *attint amdgpu_ptl_sysfs_init (struct amdgpu_device *adev) { -if (!adev->psp.ptl.ptl_hw_supported) +if (!adev->psp.ptl.hw_supported)return 0 ;return sysfs_create_group (&adev->dev->kobj, &amdgpu_ptl_attr_group);@@ -1476,7 +1477,7 @@ int amdgpu_ptl_sysfs_init(struct amdgpu_device *adev)void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev) { -if (!adev->psp.ptl.ptl_hw_supported) +if (!adev->psp.ptl.hw_supported)return ;sysfs_remove_group (&adev->dev->kobj, &amdgpu_ptl_attr_group);drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +6
-6@@ -383,13 +383,13 @@ struct psp_ptl_perf_req { };struct amdgpu_ptl { -enum amdgpu_ptl_fmt ptl_fmt1; -enum amdgpu_ptl_fmt ptl_fmt2; -bool ptl_enabled; -bool ptl_hw_supported; +enum amdgpu_ptl_fmt fmt1; +enum amdgpu_ptl_fmt fmt2; +bool enabled; +bool hw_supported;/* PTL disable reference counting */ -atomic_t ptl_disable_ref; -struct mutex ptl_mutex; +atomic_t disable_ref; +struct mutex mutex; };struct psp_context {drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +6
-6@@ -2380,12 +2380,12 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool staif (!adev->psp.funcs)return -EOPNOTSUPP ; -if (!ptl->ptl_hw_supported) { +if (!ptl->hw_supported) { fmt1 =GFX_FTYPE_I8 ; fmt2 =GFX_FTYPE_BF16 ; }else { - fmt1 = ptl->ptl_fmt1; - fmt2 = ptl->ptl_fmt2; + fmt1 = ptl->fmt1; + fmt2 = ptl->fmt2; }/* initialize PTL with default formats: GFX_FTYPE_I8 & GFX_FTYPE_BF16 */ @@ -2394,9 +2394,9 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool staif (r)return r; - ptl->ptl_hw_supported = true; + ptl->hw_supported = true; -atomic_set (&ptl->ptl_disable_ref,0 ); +atomic_set (&ptl->disable_ref,0 );return 0 ; }@@ -2406,7 +2406,7 @@ static int gfx_v9_4_3_hw_fini(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;int i, num_xcc; -if (adev->psp.ptl.ptl_hw_supported) +if (adev->psp.ptl.hw_supported)gfx_v9_4_3_perf_monitor_ptl_init (adev,0 );amdgpu_irq_put (adev, &adev->gfx.priv_reg_irq,0 );drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +13
-14@@ -1768,12 +1768,12 @@ int kfd_ptl_control(struct kfd_process_device *pdd, bool enable) {struct amdgpu_device *adev = pdd->dev->adev;struct amdgpu_ptl *ptl = &adev->psp.ptl; -enum amdgpu_ptl_fmt pref_format1 = ptl->ptl_fmt1; -enum amdgpu_ptl_fmt pref_format2 = ptl->ptl_fmt2; +enum amdgpu_ptl_fmt pref_format1 = ptl->fmt1; +enum amdgpu_ptl_fmt pref_format2 = ptl->fmt2;uint32_t ptl_state = enable ?1 :0 ;int ret; -if (!ptl->ptl_hw_supported) +if (!ptl->hw_supported)return -EOPNOTSUPP ;if (!pdd->dev->kfd2kgd || !pdd->dev->kfd2kgd->ptl_ctrl)@@ -1800,15 +1800,15 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd,struct amdgpu_ptl *ptl = &adev->psp.ptl;int ret =0 ; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);if (pdd->ptl_disable_req) goto out; -if (atomic_inc_return (&ptl->ptl_disable_ref) ==1 ) { +if (atomic_inc_return (&ptl->disable_ref) ==1 ) { ret =kfd_ptl_control (pdd, false);if (ret) { -atomic_dec (&ptl->ptl_disable_ref); +atomic_dec (&ptl->disable_ref);dev_warn (pdd->dev->adev->dev,"failed to disable PTL\n" ); goto out;@@ -1817,7 +1817,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, pdd->ptl_disable_req = true; out: -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; }@@ -1828,15 +1828,15 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd,struct amdgpu_ptl *ptl = &adev->psp.ptl;int ret =0 ; -mutex_lock (&ptl->ptl_mutex); +mutex_lock (&ptl->mutex);if (!pdd->ptl_disable_req) goto out; -if (atomic_dec_return (&ptl->ptl_disable_ref) ==0 ) { +if (atomic_dec_return (&ptl->disable_ref) ==0 ) { ret =kfd_ptl_control (pdd, true);if (ret) { -atomic_inc (&ptl->ptl_disable_ref); +atomic_inc (&ptl->disable_ref);dev_warn (adev->dev,"Failed to enable PTL on release: %d\n" , ret); goto out; }@@ -1845,7 +1845,7 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, pdd->ptl_disable_req = false; out: -mutex_unlock (&ptl->ptl_mutex); +mutex_unlock (&ptl->mutex);return ret; }@@ -3338,7 +3338,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, kfd->profiler_process = p; status =0 ;mutex_unlock (&kfd->profiler_lock); -if (ptl->ptl_hw_supported) { +if (ptl->hw_supported) { status =kfd_ptl_disable_request (pdd, p);if (status !=0 ) dev_err(kfd_device,@@ -3356,7 +3356,7 @@ static inline uint32_t profile_lock_device(struct kfd_process *p, status =0 ;mutex_unlock (&kfd->profiler_lock); -if (ptl->ptl_hw_supported) { +if (ptl->hw_supported) { status =kfd_ptl_disable_release (pdd, p);if (status) dev_err(kfd_device, --2.34.1
PATCH 19/22 drm/amdgpu: Track PTL disable requests by source
In reply to Perry YuanUse a bitmap to track PTL disable requests from sysfs and profiler. PTL is only re-enabled once all sources have released their disable requests, avoiding premature enablement.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 32 +++++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 8 ++++++ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 +++ 3 files changed, 38 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +26 -6
@@ -1314,6 +1314,21 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code, ptl->fmt2 == ptl_fmt2)return 0 ; +/* If enabling PTL, check disable bitmap */ +if (req_code ==PSP_PTL_PERF_MON_SET && *ptl_state ==1 ) { +if (!bitmap_empty (ptl->disable_bitmap, +AMDGPU_PTL_DISABLE_MAX )) { +dev_dbg (adev->dev, +"PTL enable blocked: SYSFS=%d, PROFILER=%d (ref=%d)\n" , +test_bit (AMDGPU_PTL_DISABLE_SYSFS , + ptl->disable_bitmap), +test_bit (AMDGPU_PTL_DISABLE_PROFILER , + ptl->disable_bitmap), +atomic_read (&ptl->disable_ref)); +return 0 ; + } + } +return psp_ptl_invoke (psp, req_code, ptl_state, &ptl_fmt1, &ptl_fmt2); }
@@ -1351,9 +1366,10 @@ static ssize_t ptl_enable_store(struct device *dev,struct amdgpu_device *adev =drm_to_adev (ddev);struct psp_context *psp = &adev->psp;struct amdgpu_ptl *ptl = &adev->psp.ptl; -bool enable, cur_enabled;uint32_t ptl_state, fmt1, fmt2;int ret; +bool enable; +bool bit_changed = false;mutex_lock (&ptl->mutex);if (sysfs_streq (buf,"enabled" ) ||sysfs_streq (buf,"1" )) {
@@ -1369,18 +1385,22 @@ static ssize_t ptl_enable_store(struct device *dev, fmt2 = ptl->fmt2; ptl_state = enable ?1 :0 ; - cur_enabled =READ_ONCE (psp->enabled); -if (cur_enabled == enable) { -mutex_unlock (&psp->mutex); -return count; - } +if (enable) + bit_changed =test_and_clear_bit (AMDGPU_PTL_DISABLE_SYSFS , + ptl->disable_bitmap); ret =amdgpu_ptl_perf_monitor_ctrl (adev,PSP_PTL_PERF_MON_SET , &ptl_state, &fmt1, &fmt2);if (ret) {dev_err (adev->dev,"Failed to set PTL err = %d\n" , ret); +if (enable && bit_changed) +set_bit (AMDGPU_PTL_DISABLE_SYSFS , ptl->disable_bitmap);mutex_unlock (&ptl->mutex);return ret; } + +if (!enable) +set_bit (AMDGPU_PTL_DISABLE_SYSFS , ptl->disable_bitmap); +mutex_unlock (&ptl->mutex);return count;
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +8 -0
@@ -31,6 +31,7 @@#include "ta_ras_if.h" #include "ta_rap_if.h" #include "ta_secureDisplay_if.h" +#include <linux/bitops.h> #define PSP_FENCE_BUFFER_SIZE 0x1000#define PSP_CMD_BUFFER_SIZE 0x1000
@@ -382,6 +383,12 @@ struct psp_ptl_perf_req {uint32_t pref_format2; }; +enum amdgpu_ptl_disable_source { +AMDGPU_PTL_DISABLE_SYSFS =0 , +AMDGPU_PTL_DISABLE_PROFILER , +AMDGPU_PTL_DISABLE_MAX , +}; +struct amdgpu_ptl {enum amdgpu_ptl_fmt fmt1;enum amdgpu_ptl_fmt fmt2;
@@ -390,6 +397,7 @@ struct amdgpu_ptl {/* PTL disable reference counting */ atomic_t disable_ref;struct mutex mutex; +DECLARE_BITMAP (disable_bitmap,AMDGPU_PTL_DISABLE_MAX ); };struct psp_context {
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +4 -0
@@ -1814,6 +1814,8 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, goto out; } } + +set_bit (AMDGPU_PTL_DISABLE_PROFILER , ptl->disable_bitmap); pdd->ptl_disable_req = true; out:
@@ -1834,9 +1836,11 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, goto out;if (atomic_dec_return (&ptl->disable_ref) ==0 ) { +clear_bit (AMDGPU_PTL_DISABLE_PROFILER , ptl->disable_bitmap); ret =kfd_ptl_control (pdd, true);if (ret) {atomic_inc (&ptl->disable_ref); +set_bit (AMDGPU_PTL_DISABLE_PROFILER , ptl->disable_bitmap);dev_warn (adev->dev,"Failed to enable PTL on release: %d\n" , ret); goto out; }
Signature · 1 line
2.34.1
PATCH 20/22 drm/amdgpu: add amdgpu.ptl module parameter for PTL control
In reply to Perry YuanAdd a new kernel module parameter 'amdgpu.ptl' to allow users to enable or disable PTL feature at driver loading time.
Parameter values:
*) 0 or -1: disable PTL (default)
*) 1: enable PTL
*) 2: permanently disable PTL
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 13 ++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 18 ++++++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 + drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 28 ++++++++++++++++++++++++- 5 files changed, 56 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
@@ -268,6 +268,7 @@ extern int amdgpu_rebar;extern int amdgpu_wbrf;extern int amdgpu_user_queue; +extern int amdgpu_ptl;extern uint amdgpu_hdmi_hpd_debounce_delay_ms;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +13 -0
@@ -248,6 +248,7 @@ int amdgpu_umsch_mm_fwlog;int amdgpu_rebar =-1 ;/* auto */ int amdgpu_user_queue =-1 ;uint amdgpu_hdmi_hpd_debounce_delay_ms; +int amdgpu_ptl =-1 ;/* auto */ DECLARE_DYNDBG_CLASSMAP(drm_debug_classes, DD_CLASS_TYPE_DISJOINT_BITS, 0, "DRM_UT_CORE",
@@ -1134,6 +1135,18 @@ module_param_named(user_queue, amdgpu_user_queue, int, 0444);MODULE_PARM_DESC (hdmi_hpd_debounce_delay_ms,"HDMI HPD disconnect debounce delay in milliseconds (0 to disable (by default), 1500 is common)" );module_param_named (hdmi_hpd_debounce_delay_ms, amdgpu_hdmi_hpd_debounce_delay_ms, uint,0644 ); +/** +* DOC: ptl (int) +* Enable PTL feature at boot time. Possible values: +* +* - -1 = auto (ASIC specific default) +* - 0 = disable PTL (default) +* - 1 = enable PTL +* - 2 = permanently disable PTL (cannot be re-enabled at runtime) +*/ +MODULE_PARM_DESC (ptl,"Enable PTL (-1 = auto, 0 = disable (default), 1 = enable, 2 = permanently disable)" ); +module_param_named (ptl, amdgpu_ptl, int,0444 ); +/* These devices are not supported by amdgpu. * They are supported by the mach64, r128, radeon drivers */
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +14 -4
@@ -1296,6 +1296,9 @@ int amdgpu_ptl_perf_monitor_ctrl(struct amdgpu_device *adev, u32 req_code, psp = &adev->psp; ptl = &psp->ptl; +if (ptl->permanently_disabled && *ptl_state ==1 ) +return 0 ; +if (amdgpu_ip_version (adev,GC_HWIP ,0 ) !=IP_VERSION (9 ,4 ,4 ) || psp->sos.fw_version <0x0036081a )return -EOPNOTSUPP ;
@@ -1364,7 +1367,6 @@ static ssize_t ptl_enable_store(struct device *dev, {struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev); -struct psp_context *psp = &adev->psp;struct amdgpu_ptl *ptl = &adev->psp.ptl;uint32_t ptl_state, fmt1, fmt2;int ret;
@@ -1381,6 +1383,12 @@ static ssize_t ptl_enable_store(struct device *dev,return -EINVAL ; } +/* Block enable when permanently disabled */ +if (ptl->permanently_disabled) { +mutex_unlock (&ptl->mutex); +return -EPERM ; + } + fmt1 = ptl->fmt1; fmt2 = ptl->fmt2; ptl_state = enable ?1 :0 ;
@@ -1410,9 +1418,12 @@ static ssize_t ptl_enable_show(struct device *dev, struct device_attribute *attr {struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev); -struct psp_context *psp = &adev->psp; +struct amdgpu_ptl *ptl = &adev->psp.ptl; -return sysfs_emit (buf,"%s\n" , psp->ptl.enabled ?"enabled" :"disabled" ); +if (ptl->permanently_disabled) +return sysfs_emit (buf,"permanently disabled\n" ); + +return sysfs_emit (buf,"%s\n" , ptl->enabled ?"enabled" :"disabled" ); } static ssize_t ptl_format_store(struct device *dev,
@@ -1421,7 +1432,6 @@ static ssize_t ptl_format_store(struct device *dev, {struct drm_device *ddev =dev_get_drvdata (dev);struct amdgpu_device *adev =drm_to_adev (ddev); -struct psp_context *psp = &adev->psp;char fmt1_str[8 ], fmt2_str[8 ];enum amdgpu_ptl_fmt fmt1_enum, fmt2_enum;struct amdgpu_ptl *ptl = &adev->psp.ptl;
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
@@ -394,6 +394,7 @@ struct amdgpu_ptl {enum amdgpu_ptl_fmt fmt2;bool enabled;bool hw_supported; +bool permanently_disabled;/* PTL disable reference counting */ atomic_t disable_ref;struct mutex mutex;
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +27 -1
@@ -2401,6 +2401,32 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool stareturn 0 ; } +static int gfx_v9_4_3_ptl_hw_init (struct amdgpu_device *adev) +{ +struct amdgpu_ptl *ptl = &adev->psp.ptl; +bool enable; + +switch (amdgpu_ptl) { +case 1 : + enable = true; +break ; +case 2 : +/* Permanently disabled - cannot be re-enabled */ + enable = false; + ptl->permanently_disabled = true; +break ; +case -1 : +case 0 : +default : + enable = false; +break ; + } + +gfx_v9_4_3_perf_monitor_ptl_init (adev, enable ?1 :0 ); + +return 0 ; +} +static int gfx_v9_4_3_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -2583,7 +2609,7 @@ static int gfx_v9_4_3_late_init(struct amdgpu_ip_block *ip_block) adev->gfx.ras->enable_watchdog_timer) adev->gfx.ras->enable_watchdog_timer (adev); -gfx_v9_4_3_perf_monitor_ptl_init (adev,1 ); +gfx_v9_4_3_ptl_hw_init (adev);return 0 ; }
Signature · 1 line
2.34.1
PATCH 21/22 drm/amdgpu: add new data types F8 and Vector for PTL
In reply to Perry YuanAdd F8 and VECTOR to amdgpu_ptl_fmt and PSP format mapping. Update PTL format strings and GFX format enum to keep PSP/KFD in sync.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 8 ++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 4 ++-- include/uapi/linux/kfd_ioctl.h | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +8 -0
@@ -58,6 +58,8 @@ static const char * const amdgpu_ptl_fmt_str[] = { [AMDGPU_PTL_FMT_BF16] = "BF16", [AMDGPU_PTL_FMT_F32] = "F32", [AMDGPU_PTL_FMT_F64] = "F64", + [AMDGPU_PTL_FMT_F8] = "F8", + [AMDGPU_PTL_FMT_VECTOR] = "VECTOR", [AMDGPU_PTL_FMT_INVALID] = "INVALID", };
@@ -1232,6 +1234,12 @@ static int psp_ptl_fmt_verify(struct psp_context *psp, enum amdgpu_ptl_fmt fmt,case AMDGPU_PTL_FMT_F64 : *ptl_fmt =GFX_FTYPE_F64 ;break ; +case AMDGPU_PTL_FMT_F8 : + *ptl_fmt =GFX_FTYPE_F8 ; +break ; +case AMDGPU_PTL_FMT_VECTOR : + *ptl_fmt =GFX_FTYPE_VECTOR ; +break ;default :return -EINVAL ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +2 -0
@@ -373,6 +373,8 @@ enum psp_ptl_format_typeGFX_FTYPE_BF16 =0x00000002 ,GFX_FTYPE_F32 =0x00000003 ,GFX_FTYPE_F64 =0x00000004 , +GFX_FTYPE_F8 =0x00000005 , +GFX_FTYPE_VECTOR =0x00000006 , GFX_FTYPE_INVALID = 0xFFFFFFFF, };
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2 -2
@@ -2381,8 +2381,8 @@ static int gfx_v9_4_3_perf_monitor_ptl_init(struct amdgpu_device *adev, bool stareturn -EOPNOTSUPP ;if (!ptl->hw_supported) { - fmt1 =GFX_FTYPE_I8 ; - fmt2 =GFX_FTYPE_BF16 ; + fmt1 =GFX_FTYPE_VECTOR ; + fmt2 =GFX_FTYPE_F8 ; }else { fmt1 = ptl->fmt1; fmt2 = ptl->fmt2;
include/uapi/linux/kfd_ioctl.h +3 -1
@@ -1564,7 +1564,9 @@ enum amdgpu_ptl_fmt {AMDGPU_PTL_FMT_BF16 =2 ,AMDGPU_PTL_FMT_F32 =3 ,AMDGPU_PTL_FMT_F64 =4 , - AMDGPU_PTL_FMT_INVALID = 5, +AMDGPU_PTL_FMT_F8 =5 , +AMDGPU_PTL_FMT_VECTOR =6 , + AMDGPU_PTL_FMT_INVALID = 7, };#define KFD_IOC_PROFILER_VERSION_NUM 1
Signature · 1 line
2.34.1
PATCH 22/22 drm/amdgpu: add amdgpu_ptl.h for PTL format and command definitions
In reply to Perry YuanCollect amdgpu_ptl_fmt in one header so both GFX, KFD and PSP drivers can share them without duplication.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 23 +------ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 + drivers/gpu/drm/amd/include/amdgpu_ptl.h | 60 +++++++++++++++++++ .../gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 11 ---- 6 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 drivers/gpu/drm/amd/include/amdgpu_ptl.h
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
@@ -38,6 +38,8 @@#include "amdgpu_vm.h" #include "amdgpu_xcp.h" #include "kfd_topology.h" +#include "amdgpu_ptl.h" +extern uint64_t amdgpu_amdkfd_total_mem_size;enum TLB_FLUSH_TYPE {
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -22
@@ -32,6 +32,7 @@#include "ta_rap_if.h" #include "ta_secureDisplay_if.h" #include <linux/bitops.h> +#include "amdgpu_ptl.h" #define PSP_FENCE_BUFFER_SIZE 0x1000#define PSP_CMD_BUFFER_SIZE 0x1000
@@ -64,7 +65,6 @@#define MBOX_TOS_RESP_MASK (GFX_CMD_RESPONSE_MASK | GFX_CMD_STATUS_MASK)extern const struct attribute_group amdgpu_flash_attr_group; -extern const struct attribute_group amdgpu_ptl_attr_group;enum psp_shared_mem_size {PSP_ASD_SHARED_MEM_SIZE =0x0 ,
@@ -385,24 +385,6 @@ struct psp_ptl_perf_req {uint32_t pref_format2; }; -enum amdgpu_ptl_disable_source { -AMDGPU_PTL_DISABLE_SYSFS =0 , -AMDGPU_PTL_DISABLE_PROFILER , -AMDGPU_PTL_DISABLE_MAX , -}; - -struct amdgpu_ptl { -enum amdgpu_ptl_fmt fmt1; -enum amdgpu_ptl_fmt fmt2; -bool enabled; -bool hw_supported; -bool permanently_disabled; -/* PTL disable reference counting */ -atomic_t disable_ref; -struct mutex mutex; - DECLARE_BITMAP(disable_bitmap, AMDGPU_PTL_DISABLE_MAX); -}; -struct psp_context {struct amdgpu_device *adev;struct psp_ring km_ring;
@@ -679,7 +661,4 @@ int amdgpu_psp_get_fw_type(struct amdgpu_firmware_info *ucode,int amdgpu_ptl_perf_monitor_ctrl (struct amdgpu_device *adev,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2); -int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev); -void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev); -#endif
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1 -0
@@ -44,6 +44,7 @@#include "kfd_smi_events.h" #include "amdgpu_dma_buf.h" #include "kfd_debug.h" +#include "amdgpu_ptl.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);
drivers/gpu/drm/amd/include/amdgpu_ptl.h new file +60 -0
60 lines not on this page · raw message
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -0
@@ -33,6 +33,7 @@#include <linux/dma-fence.h> #include "amdgpu_irq.h" #include "amdgpu_gfx.h" +#include "amdgpu_ptl.h" struct pci_dev ;struct amdgpu_device ;
include/uapi/linux/kfd_ioctl.h +0 -11
@@ -1558,17 +1558,6 @@ struct kfd_ioctl_dbg_trap_args { }; }; -enum amdgpu_ptl_fmt { -AMDGPU_PTL_FMT_I8 =0 , -AMDGPU_PTL_FMT_F16 =1 , -AMDGPU_PTL_FMT_BF16 =2 , -AMDGPU_PTL_FMT_F32 =3 , -AMDGPU_PTL_FMT_F64 =4 , -AMDGPU_PTL_FMT_F8 =5 , -AMDGPU_PTL_FMT_VECTOR =6 , -AMDGPU_PTL_FMT_INVALID =7 , -}; -#define KFD_IOC_PROFILER_VERSION_NUM 1enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 ,
Signature · 1 line
2.34.1
Re: [PATCH 22/22] drm/amdgpu: add amdgpu_ptl.h for PTL format and command definitions
Quoted 147 lines · Perry Yuan
Collect
amdgpu_ptl_fmtin one header so both GFX, KFD and PSP drivers can share them without duplication.Signed-off-by Perry Yuan <[email protected]>Suggested-by Alex Deucher <[email protected]>Reviewed-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 23 +------ drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 1 + drivers/gpu/drm/amd/include/amdgpu_ptl.h | 60 +++++++++++++++++++ .../gpu/drm/amd/include/kgd_kfd_interface.h | 1 + include/uapi/linux/kfd_ioctl.h | 11 ---- 6 files changed, 65 insertions(+), 33 deletions(-)create mode 100644
drivers/gpu/drm/amd/include/amdgpu_ptl.hdrivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-0@@ -38,6 +38,8 @@#include "amdgpu_vm.h" #include "amdgpu_xcp.h" #include "kfd_topology.h" +#include "amdgpu_ptl.h" +extern uint64_t amdgpu_amdkfd_total_mem_size;enum TLB_FLUSH_TYPE {drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1
-22@@ -32,6 +32,7 @@#include "ta_rap_if.h" #include "ta_secureDisplay_if.h" #include <linux/bitops.h> +#include "amdgpu_ptl.h" #define PSP_FENCE_BUFFER_SIZE 0x1000#define PSP_CMD_BUFFER_SIZE 0x1000@@ -64,7 +65,6 @@#define MBOX_TOS_RESP_MASK (GFX_CMD_RESPONSE_MASK | GFX_CMD_STATUS_MASK)extern const struct attribute_group amdgpu_flash_attr_group; -extern const struct attribute_group amdgpu_ptl_attr_group;enum psp_shared_mem_size {PSP_ASD_SHARED_MEM_SIZE =0x0 ,@@ -385,24 +385,6 @@ struct psp_ptl_perf_req {uint32_t pref_format2; }; -enum amdgpu_ptl_disable_source { -AMDGPU_PTL_DISABLE_SYSFS =0 , -AMDGPU_PTL_DISABLE_PROFILER , -AMDGPU_PTL_DISABLE_MAX , -}; - -struct amdgpu_ptl { -enum amdgpu_ptl_fmt fmt1; -enum amdgpu_ptl_fmt fmt2; -bool enabled; -bool hw_supported; -bool permanently_disabled; -/* PTL disable reference counting */ -atomic_t disable_ref; -struct mutex mutex; - DECLARE_BITMAP(disable_bitmap, AMDGPU_PTL_DISABLE_MAX); -}; -struct psp_context {struct amdgpu_device *adev;struct psp_ring km_ring;@@ -679,7 +661,4 @@ int amdgpu_psp_get_fw_type(struct amdgpu_firmware_info *ucode,int amdgpu_ptl_perf_monitor_ctrl (struct amdgpu_device *adev,u32 req_code,u32 *ptl_state,u32 *fmt1,u32 *fmt2); -int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev); -void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev); -#endif drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +1
-0@@ -44,6 +44,7 @@#include "kfd_smi_events.h" #include "amdgpu_dma_buf.h" #include "kfd_debug.h" +#include "amdgpu_ptl.h" static long kfd_ioctl (struct file *,unsigned int ,unsigned long );static int kfd_open (struct inode *,struct file *);drivers/gpu/drm/amd/include/amdgpu_ptl.h new file +47
-0@@ -0,0 +1,60 @@ +/* +* Copyright 2026 Advanced Micro Devices, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR +* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __AMDGPU_PTL_H__ +#define __AMDGPU_PTL_H__ + +enum amdgpu_ptl_fmt { + AMDGPU_PTL_FMT_I8 = 0, + AMDGPU_PTL_FMT_F16 = 1, + AMDGPU_PTL_FMT_BF16 = 2, + AMDGPU_PTL_FMT_F32 = 3, + AMDGPU_PTL_FMT_F64 = 4, + AMDGPU_PTL_FMT_F8 = 5, + AMDGPU_PTL_FMT_VECTOR = 6, + AMDGPU_PTL_FMT_INVALID = 7, +}; + +enum amdgpu_ptl_disable_source { + AMDGPU_PTL_DISABLE_SYSFS = 0, + AMDGPU_PTL_DISABLE_PROFILER, + AMDGPU_PTL_DISABLE_MAX, +}; + +struct amdgpu_ptl { + enum amdgpu_ptl_fmt fmt1; + enum amdgpu_ptl_fmt fmt2; + bool enabled; + bool hw_supported;
drivers/gpu/drm/amd/include/amdgpu_ptl.h line 57
Quoted 10 lines
drivers/gpu/drm/amd/include/amdgpu_ptl.h new file +10
-0+bool permanently_disabled; +/* PTL disable reference counting */ +atomic_t disable_ref; +struct mutex mutex; +DECLARE_BITMAP (disable_bitmap,AMDGPU_PTL_DISABLE_MAX ); +}; + +int amdgpu_ptl_sysfs_init (struct amdgpu_device *adev); +void amdgpu_ptl_sysfs_fini (struct amdgpu_device *adev); +
Please move amdgpu_ptl_perf_monitor_ctrl decalartion also to this file.
Thanks,
Lijo
Quoted 37 lines
drivers/gpu/drm/amd/include/amdgpu_ptl.h new file +3
-0+extern const struct attribute_group amdgpu_ptl_attr_group; + +#endif /* __AMDGPU_PTL_H__ */ drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1
-0@@ -33,6 +33,7 @@#include <linux/dma-fence.h> #include "amdgpu_irq.h" #include "amdgpu_gfx.h" +#include "amdgpu_ptl.h" struct pci_dev ;struct amdgpu_device ;include/uapi/linux/kfd_ioctl.h +0
-11@@ -1558,17 +1558,6 @@ struct kfd_ioctl_dbg_trap_args { }; }; -enum amdgpu_ptl_fmt { -AMDGPU_PTL_FMT_I8 =0 , -AMDGPU_PTL_FMT_F16 =1 , -AMDGPU_PTL_FMT_BF16 =2 , -AMDGPU_PTL_FMT_F32 =3 , -AMDGPU_PTL_FMT_F64 =4 , -AMDGPU_PTL_FMT_F8 =5 , -AMDGPU_PTL_FMT_VECTOR =6 , -AMDGPU_PTL_FMT_INVALID =7 , -}; -#define KFD_IOC_PROFILER_VERSION_NUM 1enum kfd_profiler_ops {KFD_IOC_PROFILER_PMC =0 ,