[PATCH v2] drm/amdgpu: Add supported NPS modes node
Lazar, Lijo
lijo.lazar at amd.com
Tue Nov 5 11:02:27 UTC 2024
On 11/5/2024 4:22 PM, Asad Kamal wrote:
> Add sysfs node to show supported NPS mode for the
> partition configuration selected using xcp_config
>
> v2: Hide node if dynamic nps switch not supported
>
> Signed-off-by: Asad Kamal <asad.kamal at amd.com>
> Reviewed-by: Lijo Lazar <lijo.lazar at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 41 +++++++++++++++++++++++++
> 1 file changed, 41 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> index 83a16918ea76..964667125be0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c
> @@ -471,6 +471,16 @@ static const char *xcp_desc[] = {
> [AMDGPU_CPX_PARTITION_MODE] = "CPX",
> };
>
> +static const char *nps_desc[] = {
> + [UNKNOWN_MEMORY_PARTITION_MODE] = "UNKNOWN",
> + [AMDGPU_NPS1_PARTITION_MODE] = "NPS1",
> + [AMDGPU_NPS2_PARTITION_MODE] = "NPS2",
> + [AMDGPU_NPS3_PARTITION_MODE] = "NPS3",
> + [AMDGPU_NPS4_PARTITION_MODE] = "NPS4",
> + [AMDGPU_NPS6_PARTITION_MODE] = "NPS6",
> + [AMDGPU_NPS8_PARTITION_MODE] = "NPS8",
> +};
> +
> ATTRIBUTE_GROUPS(xcp_cfg_res_sysfs);
>
> #define to_xcp_attr(x) \
> @@ -540,6 +550,26 @@ static ssize_t supported_xcp_configs_show(struct kobject *kobj,
> return size;
> }
>
> +static ssize_t supported_nps_configs_show(struct kobject *kobj,
> + struct kobj_attribute *attr, char *buf)
> +{
> + struct amdgpu_xcp_cfg *xcp_cfg = to_xcp_cfg(kobj);
> + int size = 0, mode;
> + char *sep = "";
> +
> + if (!xcp_cfg || !xcp_cfg->compatible_nps_modes)
> + return sysfs_emit(buf, "Not supported\n");
> +
> + for_each_inst(mode, xcp_cfg->compatible_nps_modes) {
> + size += sysfs_emit_at(buf, size, "%s%s", sep, nps_desc[mode]);
> + sep = ", ";
> + }
> +
> + size += sysfs_emit_at(buf, size, "\n");
> +
> + return size;
> +}
> +
> static ssize_t xcp_config_show(struct kobject *kobj,
> struct kobj_attribute *attr, char *buf)
> {
> @@ -596,6 +626,9 @@ static const struct kobj_type xcp_cfg_sysfs_ktype = {
> static struct kobj_attribute supp_part_sysfs_mode =
> __ATTR_RO(supported_xcp_configs);
>
> +static struct kobj_attribute supp_nps_sysfs_mode =
> + __ATTR_RO(supported_nps_configs);
> +
> static const struct attribute *xcp_attrs[] = {
> &supp_part_sysfs_mode.attr,
> &xcp_cfg_sysfs_mode.attr,
> @@ -625,6 +658,12 @@ void amdgpu_xcp_cfg_sysfs_init(struct amdgpu_device *adev)
> if (r)
> goto err1;
>
> + if (adev->gmc.supported_nps_modes != 0) {
> + r = sysfs_create_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);
> + if (r)
> + goto err1;
This doesn't look correct. At this point other files are created which
need to be removed on error.
Thanks,
Lijo
> + }
> +
> mode = (xcp_cfg->xcp_mgr->mode ==
> AMDGPU_UNKNOWN_COMPUTE_PARTITION_MODE) ?
> AMDGPU_SPX_PARTITION_MODE :
> @@ -673,6 +712,8 @@ void amdgpu_xcp_cfg_sysfs_fini(struct amdgpu_device *adev)
> kobject_put(&xcp_res->kobj);
> }
>
> + if (adev->gmc.supported_nps_modes != 0)
> + sysfs_remove_file(&xcp_cfg->kobj, &supp_nps_sysfs_mode.attr);
> sysfs_remove_files(&xcp_cfg->kobj, xcp_attrs);
> kobject_put(&xcp_cfg->kobj);
> }
More information about the amd-gfx
mailing list