Replace usage of sprintf with sysfs_emit in swsmu powerplay
Subsystems (3)
v2 cover Replace usage of sprintf with sysfs_emit in swsmu powerplay
=== Description ===
Replace usage of sprintf with sysfs_emit in swsmu powerplay
v2: rebased on 2f56b0d631eb
=== Test System ===
* DESKTOP(AMD FX-8350 + NAVI10(731F/ca), BIOS: F2)
+ ISO(Ubuntu 20.04.2 LTS)
+ Kernel(5.13.0-gb1d634be9673-fdoagd5f)
=== Patch Summary ===
linux: ([email protected]:agd5f) origin/amd-staging-drm-next @ 2f56b0d631eb
+ c4a20b3363cd amdgpu/pm: Replace navi10 usage of sprintf with sysfs_emit
+ cd2e3983959b amdgpu/pm: Replace smu11 usage of sprintf with sysfs_emit
+ bd82d29a9635 amdgpu/pm: Replace smu12/13 usage of sprintf with sysfs_emit
=== General Test for each platform ===
AMDGPU_PCI_ADDR=lspci -nn | grep "VGA\|Display" | cut -d " " -f 1 AMDGPU_HWMON=ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}' HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON} LOGFILE=pp_printf.test.log
lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_dpm_sclkpp_sclk_odpp_mclk_odpp_dpm_pciepp_od_clk_voltagepp_power_profile_mode "
for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE
Darren Powell (3):
amdgpu/pm: Replace navi10 usage of sprintf with sysfs_emit amdgpu/pm: Replace smu11 usage of sprintf with sysfs_emit amdgpu/pm: Replace smu12/13 usage of sprintf with sysfs_emit
.../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 26 ++++---- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 61 ++++++++++--------- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 34 +++++------ .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 46 +++++++------- .../gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 20 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 21 +++---- .../drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 14 ++--- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 6 +- 8 files changed, 115 insertions(+), 113 deletions(-)
base-commit: 2f56b0d631eba0e76cfc789d85cc5632256ad42d
Signature · 1 line
2.32.0
PATCH v2 1/3 amdgpu/pm: Replace navi10 usage of sprintf with sysfs_emit
initial modification of files
smu_cmn.c
navi10_ppt.c
=== Test ===
AMDGPU_PCI_ADDR=lspci -nn | grep "VGA\|Display" | cut -d " " -f 1 AMDGPU_HWMON=ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}' HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON} LOGFILE=pp_printf.test.log
lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_dpm_sclkpp_sclk_odpp_mclk_odpp_dpm_pciepp_od_clk_voltagepp_power_profile_mode "
for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE
--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 61 ++++++++++--------- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 6 +- 2 files changed, 35 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +32 -29
@@ -1303,7 +1303,7 @@ static int navi10_print_clk_levels(struct smu_context *smu,if (ret)return size; - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, value, + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, cur_value == value ?"*" :"" ); } }else {
@@ -1321,7 +1321,7 @@ static int navi10_print_clk_levels(struct smu_context *smu, freq_values[1 ] = (freq_values[0 ] + freq_values[2 ]) /2 ;for (i =0 ; i <3 ; i++) { - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, freq_values[i], + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], i == mark_index ?"*" :"" ); }
@@ -1331,7 +1331,7 @@ static int navi10_print_clk_levels(struct smu_context *smu, gen_speed =smu_v11_0_get_current_pcie_link_speed_level (smu); lane_width =smu_v11_0_get_current_pcie_link_width_level (smu);for (i =0 ; i <NUM_LINK_LEVELS ; i++) - size +=sprintf (buf + size,"%d: %s %s %dMhz %s\n" , i, + size +=sysfs_emit_at (buf, size,"%d: %s %s %dMhz %s\n" , i, (dpm_context->dpm_tables.pcie_table.pcie_gen[i] ==0 ) ?"2.5GT/s," : (dpm_context->dpm_tables.pcie_table.pcie_gen[i] ==1 ) ?"5.0GT/s," : (dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 2) ? "8.0GT/s," :
@@ -1352,23 +1352,24 @@ static int navi10_print_clk_levels(struct smu_context *smu,break ;if (!navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_GFXCLK_LIMITS ))break ; - size +=sprintf (buf + size,"OD_SCLK:\n" ); - size +=sprintf (buf + size,"0: %uMhz\n1: %uMhz\n" , od_table->GfxclkFmin, od_table->GfxclkFmax); + size +=sysfs_emit_at (buf, size,"OD_SCLK:\n" ); + size +=sysfs_emit_at (buf, size,"0: %uMhz\n1: %uMhz\n" , + od_table->GfxclkFmin, od_table->GfxclkFmax);break ;case SMU_OD_MCLK :if (!smu->od_enabled || !od_table || !od_settings)break ;if (!navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_UCLK_MAX ))break ; - size +=sprintf (buf + size,"OD_MCLK:\n" ); - size +=sprintf (buf + size,"1: %uMHz\n" , od_table->UclkFmax); + size +=sysfs_emit_at (buf, size,"OD_MCLK:\n" ); + size +=sysfs_emit_at (buf, size,"1: %uMHz\n" , od_table->UclkFmax);break ;case SMU_OD_VDDC_CURVE :if (!smu->od_enabled || !od_table || !od_settings)break ;if (!navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_GFXCLK_CURVE ))break ; - size +=sprintf (buf + size,"OD_VDDC_CURVE:\n" ); + size +=sysfs_emit_at (buf, size,"OD_VDDC_CURVE:\n" );for (i =0 ; i <3 ; i++) {switch (i) {case 0 :
@@ -1383,55 +1384,57 @@ static int navi10_print_clk_levels(struct smu_context *smu,default :break ; } - size +=sprintf (buf + size,"%d: %uMHz %umV\n" , i, curve_settings[0 ], curve_settings[1 ] /NAVI10_VOLTAGE_SCALE ); + size +=sysfs_emit_at (buf, size,"%d: %uMHz %umV\n" , + i, curve_settings[0 ], + curve_settings[1 ] /NAVI10_VOLTAGE_SCALE ); }break ;case SMU_OD_RANGE :if (!smu->od_enabled || !od_table || !od_settings)break ; - size =sprintf (buf,"%s:\n" ,"OD_RANGE" ); + size =sysfs_emit (buf,"%s:\n" ,"OD_RANGE" );if (navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_GFXCLK_LIMITS )) {navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_GFXCLKFMIN , &min_value,NULL );navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_GFXCLKFMAX ,NULL , &max_value); - size +=sprintf (buf + size,"SCLK: %7uMhz %10uMhz\n" , + size +=sysfs_emit_at (buf, size,"SCLK: %7uMhz %10uMhz\n" , min_value, max_value); }if (navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_UCLK_MAX )) {navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_UCLKFMAX , &min_value, &max_value); - size +=sprintf (buf + size,"MCLK: %7uMhz %10uMhz\n" , + size +=sysfs_emit_at (buf, size,"MCLK: %7uMhz %10uMhz\n" , min_value, max_value); }if (navi10_od_feature_is_supported (od_settings,SMU_11_0_ODCAP_GFXCLK_CURVE )) {navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P1 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_SCLK[0]: %7uMhz %10uMhz\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_SCLK[0]: %7uMhz %10uMhz\n" , + min_value, max_value);navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P1 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_VOLT[0]: %7dmV %11dmV\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_VOLT[0]: %7dmV %11dmV\n" , + min_value, max_value);navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P2 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_SCLK[1]: %7uMhz %10uMhz\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_SCLK[1]: %7uMhz %10uMhz\n" , + min_value, max_value);navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P2 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_VOLT[1]: %7dmV %11dmV\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_VOLT[1]: %7dmV %11dmV\n" , + min_value, max_value);navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEFREQ_P3 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_SCLK[2]: %7uMhz %10uMhz\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_SCLK[2]: %7uMhz %10uMhz\n" , + min_value, max_value);navi10_od_setting_get_range (od_settings,SMU_11_0_ODSETTING_VDDGFXCURVEVOLTAGE_P3 , &min_value, &max_value); - size +=sprintf (buf + size,"VDDC_CURVE_VOLT[2]: %7dmV %11dmV\n" , - min_value, max_value); + size +=sysfs_emit_at (buf, size,"VDDC_CURVE_VOLT[2]: %7dmV %11dmV\n" , + min_value, max_value); }break ;
@@ -1730,7 +1733,7 @@ static int navi10_get_power_profile_mode(struct smu_context *smu, char *buf)if (!buf)return -EINVAL ; - size +=sprintf (buf + size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , + size +=sysfs_emit_at (buf, size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , title[0 ], title[1 ], title[2 ], title[3 ], title[4 ], title[5 ], title[6 ], title[7 ], title[8 ], title[9 ], title[10 ]);
@@ -1750,10 +1753,10 @@ static int navi10_get_power_profile_mode(struct smu_context *smu, char *buf)return result; } - size +=sprintf (buf + size,"%2d %14s%s:\n" , + size +=sysfs_emit_at (buf, size,"%2d %14s%s:\n" , i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 0, "GFXCLK",
@@ -1767,7 +1770,7 @@ static int navi10_get_power_profile_mode(struct smu_context *smu, char *buf) activity_monitor.Gfx_PD_Data_error_coeff, activity_monitor.Gfx_PD_Data_error_rate_coeff); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 1, "SOCCLK",
@@ -1781,7 +1784,7 @@ static int navi10_get_power_profile_mode(struct smu_context *smu, char *buf) activity_monitor.Soc_PD_Data_error_coeff, activity_monitor.Soc_PD_Data_error_rate_coeff); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 2, "MEMLK",
drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c +3 -3
@@ -710,7 +710,7 @@ size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu,return 0 ; } - size =sprintf (buf + size,"features high: 0x%08x low: 0x%08x\n" , + size =sysfs_emit_at (buf, size,"features high: 0x%08x low: 0x%08x\n" , feature_mask[1 ], feature_mask[0 ]);memset (sort_feature,-1 ,sizeof (sort_feature));
@@ -725,14 +725,14 @@ size_t smu_cmn_get_pp_feature_mask(struct smu_context *smu, sort_feature[feature_index] = i; } - size +=sprintf (buf + size,"%-2s. %-20s %-3s : %-s\n" , + size +=sysfs_emit_at (buf, size,"%-2s. %-20s %-3s : %-s\n" ,"No" ,"Feature" ,"Bit" ,"State" );for (i =0 ; i <SMU_FEATURE_COUNT ; i++) {if (sort_feature[i] <0 )continue ; - size += sprintf(buf + size, "%02d. %-20s (%2d) : %s\n", + size += sysfs_emit_at(buf, size, "%02d. %-20s (%2d) : %s\n", count++, smu_get_feature_name(smu, sort_feature[i]), i,
Signature · 1 line
2.32.0
PATCH v2 2/3 amdgpu/pm: Replace smu11 usage of sprintf with sysfs_emit
In reply to Darren Powell modification of smu11 files
arcturus_ppt.c
sienna_cichlid_ppt.c
vangogh_ppt.c
=== Test ===
AMDGPU_PCI_ADDR=lspci -nn | grep "VGA\|Display" | cut -d " " -f 1 AMDGPU_HWMON=ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}' HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON} LOGFILE=pp_printf.test.log
lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_dpm_sclkpp_power_profile_mode "
for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE
--- .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 26 +++++------ .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 34 +++++++------- .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 46 +++++++++---------- 3 files changed, 53 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +13 -13
@@ -756,7 +756,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu,uint32_t gen_speed, lane_width;if (amdgpu_ras_intr_triggered ()) -return snprintf (buf,PAGE_SIZE ,"unavailable\n" ); +return sysfs_emit (buf,"unavailable\n" ); dpm_context = smu_dpm->dpm_context;
@@ -780,7 +780,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu,* And it's safe to assume that is always the current clock. */ for (i =0 ; i < clocks.num_levels; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", i, + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, clocks.data[i].clocks_in_khz / 1000, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -803,7 +803,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < clocks.num_levels; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, clocks.data[i].clocks_in_khz / 1000, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -826,7 +826,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < clocks.num_levels; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, clocks.data[i].clocks_in_khz / 1000, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -849,7 +849,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -872,7 +872,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -895,7 +895,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (arcturus_freqs_in_same_level(
@@ -906,7 +906,7 @@ static int arcturus_print_clk_levels(struct smu_context *smu,case SMU_PCIE : gen_speed =smu_v11_0_get_current_pcie_link_speed_level (smu); lane_width =smu_v11_0_get_current_pcie_link_width_level (smu); - size +=sprintf (buf + size,"0: %s %s %dMhz *\n" , + size +=sysfs_emit_at (buf, size,"0: %s %s %dMhz *\n" , (gen_speed ==0 ) ?"2.5GT/s," : (gen_speed ==1 ) ?"5.0GT/s," : (gen_speed == 2) ? "8.0GT/s," :
@@ -1272,11 +1272,11 @@ static int arcturus_get_power_profile_mode(struct smu_context *smu,return result;if (smu_version >=0x360d00 ) - size +=sprintf (buf + size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , + size +=sysfs_emit_at (buf, size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , title[0 ], title[1 ], title[2 ], title[3 ], title[4 ], title[5 ], title[6 ], title[7 ], title[8 ], title[9 ], title[10 ]);else - size +=sprintf (buf + size,"%16s\n" , + size +=sysfs_emit_at (buf, size,"%16s\n" , title[0 ]);for (i =0 ; i <=PP_SMC_POWER_PROFILE_CUSTOM ; i++) {
@@ -1302,11 +1302,11 @@ static int arcturus_get_power_profile_mode(struct smu_context *smu, } } - size +=sprintf (buf + size,"%2d %14s%s\n" , + size +=sysfs_emit_at (buf, size,"%2d %14s%s\n" , i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " );if (smu_version >=0x360d00 ) { - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 0, "GFXCLK",
@@ -1320,7 +1320,7 @@ static int arcturus_get_power_profile_mode(struct smu_context *smu, activity_monitor.Gfx_PD_Data_error_coeff, activity_monitor.Gfx_PD_Data_error_rate_coeff); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 1, "UCLK",
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +17 -17
@@ -1089,7 +1089,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, value, + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, cur_value == value ?"*" :"" ); } }else {
@@ -1111,7 +1111,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < count; i++) { - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, freq_values[i], + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], cur_value == freq_values[i] ?"*" :"" ); }
@@ -1122,7 +1122,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, lane_width =smu_v11_0_get_current_pcie_link_width_level (smu);GET_PPTABLE_MEMBER (LclkFreq, &table_member);for (i =0 ; i <NUM_LINK_LEVELS ; i++) - size +=sprintf (buf + size,"%d: %s %s %dMhz %s\n" , i, + size +=sysfs_emit_at (buf, size,"%d: %s %s %dMhz %s\n" , i, (dpm_context->dpm_tables.pcie_table.pcie_gen[i] ==0 ) ?"2.5GT/s," : (dpm_context->dpm_tables.pcie_table.pcie_gen[i] ==1 ) ?"5.0GT/s," : (dpm_context->dpm_tables.pcie_table.pcie_gen[i] == 2) ? "8.0GT/s," :
@@ -1145,8 +1145,8 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (!sienna_cichlid_is_od_feature_supported (od_settings,SMU_11_0_7_ODCAP_GFXCLK_LIMITS ))break ; - size +=sprintf (buf + size,"OD_SCLK:\n" ); - size +=sprintf (buf + size,"0: %uMhz\n1: %uMhz\n" , od_table->GfxclkFmin, od_table->GfxclkFmax); + size +=sysfs_emit_at (buf, size,"OD_SCLK:\n" ); + size +=sysfs_emit_at (buf, size,"0: %uMhz\n1: %uMhz\n" , od_table->GfxclkFmin, od_table->GfxclkFmax);break ;case SMU_OD_MCLK :
@@ -1156,8 +1156,8 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (!sienna_cichlid_is_od_feature_supported (od_settings,SMU_11_0_7_ODCAP_UCLK_LIMITS ))break ; - size +=sprintf (buf + size,"OD_MCLK:\n" ); - size +=sprintf (buf + size,"0: %uMhz\n1: %uMHz\n" , od_table->UclkFmin, od_table->UclkFmax); + size +=sysfs_emit_at (buf, size,"OD_MCLK:\n" ); + size +=sysfs_emit_at (buf, size,"0: %uMhz\n1: %uMHz\n" , od_table->UclkFmin, od_table->UclkFmax);break ;case SMU_OD_VDDGFX_OFFSET :
@@ -1173,22 +1173,22 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, (smu_version < 0x003a2900))break ; - size +=sprintf (buf + size,"OD_VDDGFX_OFFSET:\n" ); - size +=sprintf (buf + size,"%dmV\n" , od_table->VddGfxOffset); + size +=sysfs_emit_at (buf, size,"OD_VDDGFX_OFFSET:\n" ); + size +=sysfs_emit_at (buf, size,"%dmV\n" , od_table->VddGfxOffset);break ;case SMU_OD_RANGE :if (!smu->od_enabled || !od_table || !od_settings)break ; - size =sprintf (buf,"%s:\n" ,"OD_RANGE" ); + size =sysfs_emit (buf,"%s:\n" ,"OD_RANGE" );if (sienna_cichlid_is_od_feature_supported (od_settings,SMU_11_0_7_ODCAP_GFXCLK_LIMITS )) {sienna_cichlid_get_od_setting_range (od_settings,SMU_11_0_7_ODSETTING_GFXCLKFMIN , &min_value,NULL );sienna_cichlid_get_od_setting_range (od_settings,SMU_11_0_7_ODSETTING_GFXCLKFMAX ,NULL , &max_value); - size +=sprintf (buf + size,"SCLK: %7uMhz %10uMhz\n" , + size +=sysfs_emit_at (buf, size,"SCLK: %7uMhz %10uMhz\n" , min_value, max_value); }
@@ -1197,7 +1197,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, &min_value, NULL);sienna_cichlid_get_od_setting_range (od_settings,SMU_11_0_7_ODSETTING_UCLKFMAX ,NULL , &max_value); - size +=sprintf (buf + size,"MCLK: %7uMhz %10uMhz\n" , + size +=sysfs_emit_at (buf, size,"MCLK: %7uMhz %10uMhz\n" , min_value, max_value); }break ;
@@ -1420,7 +1420,7 @@ static int sienna_cichlid_get_power_profile_mode(struct smu_context *smu, char *if (!buf)return -EINVAL ; - size +=sprintf (buf + size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , + size +=sysfs_emit_at (buf, size,"%16s %s %s %s %s %s %s %s %s %s %s\n" , title[0 ], title[1 ], title[2 ], title[3 ], title[4 ], title[5 ], title[6 ], title[7 ], title[8 ], title[9 ], title[10 ]);
@@ -1440,10 +1440,10 @@ static int sienna_cichlid_get_power_profile_mode(struct smu_context *smu, char *return result; } - size +=sprintf (buf + size,"%2d %14s%s:\n" , + size +=sysfs_emit_at (buf, size,"%2d %14s%s:\n" , i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 0, "GFXCLK",
@@ -1457,7 +1457,7 @@ static int sienna_cichlid_get_power_profile_mode(struct smu_context *smu, char * activity_monitor->Gfx_PD_Data_error_coeff, activity_monitor->Gfx_PD_Data_error_rate_coeff); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 1, "SOCCLK",
@@ -1471,7 +1471,7 @@ static int sienna_cichlid_get_power_profile_mode(struct smu_context *smu, char * activity_monitor->Fclk_PD_Data_error_coeff, activity_monitor->Fclk_PD_Data_error_rate_coeff); - size += sprintf(buf + size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", + size += sysfs_emit_at(buf, size, "%19s %d(%13s) %7d %7d %7d %7d %7d %7d %7d %7d %7d\n", " ", 2, "MEMLK",
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c +23 -23
114 lines not on this page · raw message
Signature · 1 line
2.32.0
PATCH v2 3/3 amdgpu/pm: Replace smu12/13 usage of sprintf with sysfs_emit
In reply to Darren Powell initial modification of files
renoir_ppt.c
aldebaran_ppt.c
yellow_carp_ppt.c
=== Test ===
AMDGPU_PCI_ADDR=lspci -nn | grep "VGA\|Display" | cut -d " " -f 1 AMDGPU_HWMON=ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}' HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON} LOGFILE=pp_printf.test.log
lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_dpm_sclkpp_power_profile_mode "
for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE
--- .../gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 20 +++++++++--------- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 21 +++++++++---------- .../drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 14 ++++++------- 3 files changed, 27 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c +10 -10
@@ -510,16 +510,16 @@ static int renoir_print_clk_levels(struct smu_context *smu, 0, &max);if (ret)return ret; - size +=sprintf (buf + size,"OD_RANGE\nSCLK: %10uMhz %10uMhz\n" , min, max); + size +=sysfs_emit_at (buf, size,"OD_RANGE\nSCLK: %10uMhz %10uMhz\n" , min, max); }break ;case SMU_OD_SCLK :if (smu_dpm_ctx->dpm_level ==AMD_DPM_FORCED_LEVEL_MANUAL ) { min = (smu->gfx_actual_hard_min_freq >0 ) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq; max = (smu->gfx_actual_soft_max_freq >0 ) ? smu->gfx_actual_soft_max_freq : smu->gfx_default_soft_max_freq; - size +=sprintf (buf + size,"OD_SCLK\n" ); - size +=sprintf (buf + size,"0:%10uMhz\n" , min); - size +=sprintf (buf + size,"1:%10uMhz\n" , max); + size +=sysfs_emit_at (buf, size,"OD_SCLK\n" ); + size +=sysfs_emit_at (buf, size,"0:%10uMhz\n" , min); + size +=sysfs_emit_at (buf, size,"1:%10uMhz\n" , max); }break ;case SMU_GFXCLK :
@@ -536,12 +536,12 @@ static int renoir_print_clk_levels(struct smu_context *smu,else i =1 ; - size +=sprintf (buf + size,"0: %uMhz %s\n" , min, + size +=sysfs_emit_at (buf, size,"0: %uMhz %s\n" , min, i ==0 ?"*" :"" ); - size +=sprintf (buf + size,"1: %uMhz %s\n" , + size +=sysfs_emit_at (buf, size,"1: %uMhz %s\n" , i ==1 ? cur_value :RENOIR_UMD_PSTATE_GFXCLK , i ==1 ?"*" :"" ); - size +=sprintf (buf + size,"2: %uMhz %s\n" , max, + size +=sysfs_emit_at (buf, size,"2: %uMhz %s\n" , max, i ==2 ?"*" :"" ); }return size;
@@ -588,14 +588,14 @@ static int renoir_print_clk_levels(struct smu_context *smu,return ret;if (!value)continue ; - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, value, + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, cur_value == value ?"*" :"" );if (cur_value == value) cur_value_match_level = true; }if (!cur_value_match_level) - size +=sprintf (buf + size," %uMhz *\n" , cur_value); + size +=sysfs_emit_at (buf, size," %uMhz *\n" , cur_value);break ;default :
@@ -1118,7 +1118,7 @@ static int renoir_get_power_profile_mode(struct smu_context *smu,if (workload_type <0 )continue ; - size +=sprintf (buf + size,"%2d %14s%s\n" , + size +=sysfs_emit_at (buf, size,"%2d %14s%s\n" , i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); }
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +10 -11
@@ -735,14 +735,14 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,uint32_t min_clk, max_clk;if (amdgpu_ras_intr_triggered ()) -return snprintf (buf,PAGE_SIZE ,"unavailable\n" ); +return sysfs_emit (buf,"unavailable\n" ); dpm_context = smu_dpm->dpm_context;switch (type) {case SMU_OD_SCLK : - size =sprintf (buf,"%s:\n" ,"GFXCLK" ); + size =sysfs_emit (buf,"%s:\n" ,"GFXCLK" ); fallthrough;case SMU_SCLK : ret =aldebaran_get_current_clk_freq_by_table (smu,SMU_GFXCLK , &now);
@@ -779,8 +779,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,*/ if (display_levels == clocks.num_levels) {for (i =0 ; i < clocks.num_levels; i++) - size += sprintf( - buf + size, "%d: %uMhz %s\n", i, + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, freq_values[i], (clocks.num_levels == 1) ? "*" :
@@ -790,14 +789,14 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, "")); }else {for (i =0 ; i < display_levels; i++) - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], i ==1 ?"*" :"" ); }break ;case SMU_OD_MCLK : - size =sprintf (buf,"%s:\n" ,"MCLK" ); + size =sysfs_emit (buf,"%s:\n" ,"MCLK" ); fallthrough;case SMU_MCLK : ret =aldebaran_get_current_clk_freq_by_table (smu,SMU_UCLK , &now);
@@ -814,7 +813,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < clocks.num_levels; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, clocks.data[i].clocks_in_khz / 1000, (clocks.num_levels == 1) ? "*" : (aldebaran_freqs_in_same_level(
@@ -837,7 +836,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < clocks.num_levels; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, clocks.data[i].clocks_in_khz / 1000, (clocks.num_levels == 1) ? "*" : (aldebaran_freqs_in_same_level(
@@ -860,7 +859,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (aldebaran_freqs_in_same_level(
@@ -883,7 +882,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (aldebaran_freqs_in_same_level(
@@ -906,7 +905,7 @@ static int aldebaran_print_clk_levels(struct smu_context *smu, }for (i =0 ; i < single_dpm_table->count; i++) - size += sprintf(buf + size, "%d: %uMhz %s\n", + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, single_dpm_table->dpm_levels[i].value, (clocks.num_levels == 1) ? "*" : (aldebaran_freqs_in_same_level(
drivers/gpu/drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c +7 -7
@@ -572,7 +572,7 @@ static int yellow_carp_get_power_profile_mode(struct smu_context *smu,if (workload_type <0 )continue ; - size +=sprintf (buf + size,"%2d %14s%s\n" , + size +=sysfs_emit_at (buf, size,"%2d %14s%s\n" , i, profile_name[i], (i == smu->power_profile_mode) ?"*" :" " ); }
@@ -1054,15 +1054,15 @@ static int yellow_carp_print_clk_levels(struct smu_context *smu,switch (clk_type) {case SMU_OD_SCLK : - size =sprintf (buf,"%s:\n" ,"OD_SCLK" ); - size +=sprintf (buf + size,"0: %10uMhz\n" , + size =sysfs_emit (buf,"%s:\n" ,"OD_SCLK" ); + size +=sysfs_emit_at (buf, size,"0: %10uMhz\n" , (smu->gfx_actual_hard_min_freq >0 ) ? smu->gfx_actual_hard_min_freq : smu->gfx_default_hard_min_freq); - size +=sprintf (buf + size,"1: %10uMhz\n" , + size +=sysfs_emit_at (buf, size,"1: %10uMhz\n" , (smu->gfx_actual_soft_max_freq >0 ) ? smu->gfx_actual_soft_max_freq : smu->gfx_default_soft_max_freq);break ;case SMU_OD_RANGE : - size =sprintf (buf,"%s:\n" ,"OD_RANGE" ); - size +=sprintf (buf + size,"SCLK: %7uMhz %10uMhz\n" , + size =sysfs_emit (buf,"%s:\n" ,"OD_RANGE" ); + size +=sysfs_emit_at (buf, size,"SCLK: %7uMhz %10uMhz\n" , smu->gfx_default_hard_min_freq, smu->gfx_default_soft_max_freq);break ;case SMU_SOCCLK :
@@ -1083,7 +1083,7 @@ static int yellow_carp_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; - size +=sprintf (buf + size,"%d: %uMhz %s\n" , i, value, + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, cur_value == value ?"*" :"" ); }break ;
Signature · 1 line
2.32.0
Quoted 41 lines · Darren Powell
=== Description ===
Replace usage of sprintf withsysfs_emitin swsmu powerplayv2: rebased on
2f56b0d631eb=== Test System ===
*DESKTOP(AMD FX-8350 + NAVI10(731F/ca), BIOS: F2)
+ ISO(Ubuntu 20.04.2 LTS)
+ Kernel(5.13.0-gb1d634be9673-fdoagd5f)=== Patch Summary ===
linux: ([email protected]:agd5f) origin/amd-staging-drm-next @2f56b0d631eb
+c4a20b3363cdamdgpu/pm: Replace navi10 usage of sprintf withsysfs_emit
+cd2e3983959bamdgpu/pm: Replace smu11 usage of sprintf withsysfs_emit
+bd82d29a9635amdgpu/pm: Replace smu12/13 usage of sprintf withsysfs_emit=== General Test for each platform ===
AMDGPU_PCI_ADDR=lspci -nn | grep "VGA\|Display" | cut -d " " -f 1AMDGPU_HWMON=ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}'HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON} LOGFILE=pp_printf.test.loglspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_dpm_sclkpp_sclk_odpp_mclk_odpp_dpm_pciepp_od_clk_voltagepp_power_profile_mode"for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE
Quoted 4 lines
Darren Powell (3):
amdgpu/pm: Replace navi10 usage of sprintf withsysfs_emitamdgpu/pm: Replace smu11 usage of sprintf withsysfs_emitamdgpu/pm: Replace smu12/13 usage of sprintf withsysfs_emit
Series is:
Quoted 16 lines
.../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 26 ++++---- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 61 ++++++++++--------- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 34 +++++------ .../gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 46 +++++++------- .../gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c | 20 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 21 +++---- .../drm/amd/pm/swsmu/smu13/yellow_carp_ppt.c | 14 ++--- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 6 +- 8 files changed, 115 insertions(+), 113 deletions(-)base-commit:
2f56b0d631eba0e76cfc789d85cc5632256ad42d--
2.32.0