Remove 0 MHz as a valid current frequency (v4)
Subsystems (3)
cover Remove 0 MHz as a valid current frequency (v4)
Some ASICs support low-power functionality for the whole ASIC or just an IP block. When in such low-power mode, some sysfs interfaces would report a frequency of 0, e.g.,
$cat /sys/class/drm/card0/device/pp_dpm_sclk
0: 500Mhz
1: 0Mhz *
2: 2200Mhz
$_
An operating frequency of 0 MHz doesn't make sense, and this interface is designed to report only operating clock frequencies, i.e. non-zero, and possibly the current one.
When in this low-power state, round to the smallest operating frequency, for this interface, as follows,
$cat /sys/class/drm/card0/device/pp_dpm_sclk
0: 500Mhz *
1: 2200Mhz
$_
v2: Fix description to reflect change in patch 1--add an 's'.
v3: Don't tag a current if current is 0.
v4: Verbalize some subject titles.
Luben Tuikov (5):
drm/amd/pm: Rename a couple of functions (v3) drm/amd/pm: Rename cur_value to curr_value
drm/amd/pm: Rename freq_values --> freq_value dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3) dpm/amd/pm: Navi10: Remove 0 MHz as a current clock frequency (v3)
.../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 57 ++++++++------ .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 74 ++++++++++++------- 2 files changed, 83 insertions(+), 48 deletions(-)
base-commit: d1065882691179f507a7c6aba0477eb7d1935ebd
Signature · 1 line
2.33.1.558.g2bd2f258f4
PATCH 1/5 drm/amd/pm: Rename a couple of functions (v3)
Rename sienna_cichlid_is_support_fine_grained_dpm() to sienna_cichlid_supports_fine_grained_dpm().
Rename navi10_is_support_fine_grained_dpm() to navi10_supports_fine_grained_dpm().
v2: Fix function name in commit message to reflect the change being done: add a missing 's'.
v3: Start the subject with a verb. (Suggested by Paul M.)
--- drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 7 ++++--- drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -3
@@ -1231,7 +1231,8 @@ static int navi10_get_current_clk_freq_by_table(struct smu_context *smu, value); } -static bool navi10_is_support_fine_grained_dpm (struct smu_context *smu,enum smu_clk_type clk_type) +static bool navi10_supports_fine_grained_dpm (struct smu_context *smu, +enum smu_clk_type clk_type) {PPTable_t *pptable = smu->smu_table.driver_pptable;DpmDescriptor_t *dpm_desc =NULL ;
@@ -1299,7 +1300,7 @@ static int navi10_print_clk_levels(struct smu_context *smu,if (ret)return size; -if (!navi10_is_support_fine_grained_dpm (smu, clk_type)) { +if (!navi10_supports_fine_grained_dpm (smu, clk_type)) {for (i =0 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret)
@@ -1465,7 +1466,7 @@ static int navi10_force_clk_levels(struct smu_context *smu,case SMU_UCLK :case SMU_FCLK :/* There is only 2 levels for fine grained DPM */ -if (navi10_is_support_fine_grained_dpm (smu, clk_type)) { +if (navi10_supports_fine_grained_dpm (smu, clk_type)) { soft_max_level = (soft_max_level >=1 ?1 :0 ); soft_min_level = (soft_min_level >=1 ?1 :0 ); }
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +4 -3
@@ -1006,7 +1006,8 @@ static int sienna_cichlid_get_current_clk_freq_by_table(struct smu_context *smu, } -static bool sienna_cichlid_is_support_fine_grained_dpm (struct smu_context *smu,enum smu_clk_type clk_type) +static bool sienna_cichlid_supports_fine_grained_dpm (struct smu_context *smu, +enum smu_clk_type clk_type) {DpmDescriptor_t *dpm_desc =NULL ;DpmDescriptor_t *table_member;
@@ -1084,7 +1085,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; -if (!sienna_cichlid_is_support_fine_grained_dpm (smu, clk_type)) { +if (!sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) {for (i =0 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret)
@@ -1235,7 +1236,7 @@ static int sienna_cichlid_force_clk_levels(struct smu_context *smu,case SMU_UCLK :case SMU_FCLK :/* There is only 2 levels for fine grained DPM */ -if (sienna_cichlid_is_support_fine_grained_dpm (smu, clk_type)) { +if (sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) { soft_max_level = (soft_max_level >=1 ?1 :0 ); soft_min_level = (soft_min_level >=1 ?1 :0 ); }
Signature · 1 line
2.33.1.558.g2bd2f258f4
PATCH 2/5 drm/amd/pm: Rename cur_value to curr_value
In reply to Luben TuikovRename "cur_value", which stands for "cursor
value" to "curr_value", which stands for "current
value".
--- drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 12 ++++++------ .../drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +6 -6
@@ -1267,7 +1267,7 @@ static int navi10_print_clk_levels(struct smu_context *smu, {uint16_t *curve_settings;int i, size =0 , ret =0 ; -uint32_t cur_value =0 , value =0 , count =0 ; +uint32_t curr_value =0 , value =0 , count =0 ;uint32_t freq_values[3 ] = {0 };uint32_t mark_index =0 ;struct smu_table_context *table_context = &smu->smu_table;
@@ -1292,7 +1292,7 @@ static int navi10_print_clk_levels(struct smu_context *smu,case SMU_VCLK :case SMU_DCLK :case SMU_DCEFCLK : - ret =navi10_get_current_clk_freq_by_table (smu, clk_type, &cur_value); + ret =navi10_get_current_clk_freq_by_table (smu, clk_type, &curr_value);if (ret)return size;
@@ -1307,7 +1307,7 @@ static int navi10_print_clk_levels(struct smu_context *smu,return size; size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, - cur_value == value ?"*" :"" ); + curr_value == value ?"*" :"" ); } }else { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_values[0 ]);
@@ -1317,9 +1317,9 @@ static int navi10_print_clk_levels(struct smu_context *smu,if (ret)return size; - freq_values[1 ] = cur_value; - mark_index = cur_value == freq_values[0 ] ?0 : - cur_value == freq_values[2 ] ?2 :1 ; + freq_values[1 ] = curr_value; + mark_index = curr_value == freq_values[0 ] ?0 : + curr_value == freq_values[2 ] ?2 :1 ;if (mark_index !=1 ) freq_values[1 ] = (freq_values[0 ] + freq_values[2 ]) /2 ;
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +8 -7
@@ -1052,7 +1052,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ; -uint32_t cur_value =0 , value =0 , count =0 ; +uint32_t curr_value =0 , value =0 , count =0 ;uint32_t freq_values[3 ] = {0 };uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;
@@ -1073,10 +1073,11 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,case SMU_DCLK :case SMU_DCLK1 :case SMU_DCEFCLK : - ret =sienna_cichlid_get_current_clk_freq_by_table (smu, clk_type, &cur_value); + ret =sienna_cichlid_get_current_clk_freq_by_table (smu, clk_type, &curr_value);if (ret) goto print_clk_out; +/* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type ==SMU_GFXCLK ) || (clk_type ==SMU_SCLK ))amdgpu_gfx_off_ctrl (adev, false);
@@ -1092,7 +1093,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, goto print_clk_out; size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, - cur_value == value ?"*" :"" ); + curr_value == value ?"*" :"" ); } }else { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_values[0 ]);
@@ -1102,9 +1103,9 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; - freq_values[1 ] = cur_value; - mark_index = cur_value == freq_values[0 ] ?0 : - cur_value == freq_values[2 ] ?2 :1 ; + freq_values[1 ] = curr_value; + mark_index = curr_value == freq_values[0 ] ?0 : + curr_value == freq_values[2 ] ?2 :1 ; count =3 ;if (mark_index !=1 ) {
@@ -1114,7 +1115,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,for (i =0 ; i < count; i++) { size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], - cur_value == freq_values[i] ?"*" :"" ); + curr_value == freq_values[i] ?"*" :"" ); } }
Signature · 1 line
2.33.1.558.g2bd2f258f4
PATCH 3/5 drm/amd/pm: Rename freq_values --> freq_value
In reply to Luben TuikovBy usage: read freq_values[x] to freq_value[x].
--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 16 ++++++++-------- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +8 -8
@@ -1268,7 +1268,7 @@ static int navi10_print_clk_levels(struct smu_context *smu,uint16_t *curve_settings;int i, size =0 , ret =0 ;uint32_t curr_value =0 , value =0 , count =0 ; -uint32_t freq_values[3 ] = {0 }; +uint32_t freq_value[3 ] = {0 ,0 ,0 };uint32_t mark_index =0 ;struct smu_table_context *table_context = &smu->smu_table;uint32_t gen_speed, lane_width;
@@ -1310,21 +1310,21 @@ static int navi10_print_clk_levels(struct smu_context *smu, curr_value == value ? "*" : ""); } }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_values[0 ]); + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]);if (ret)return size; - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_values[2 ]); + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret)return size; - freq_values[1 ] = curr_value; - mark_index = curr_value == freq_values[0 ] ?0 : - curr_value == freq_values[2 ] ?2 :1 ; + freq_value[1 ] = curr_value; + mark_index = curr_value == freq_value[0 ] ?0 : + curr_value == freq_value[2 ] ?2 :1 ;if (mark_index !=1 ) - freq_values[1 ] = (freq_values[0 ] + freq_values[2 ]) /2 ; + freq_value[1 ] = (freq_value[0 ] + freq_value[2 ]) /2 ;for (i =0 ; i <3 ; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], i == mark_index ?"*" :"" ); }
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +9 -9
@@ -1053,7 +1053,7 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ;uint32_t curr_value =0 , value =0 , count =0 ; -uint32_t freq_values[3 ] = {0 }; +uint32_t freq_value[3 ] = {0 ,0 ,0 };uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;uint32_t min_value, max_value;
@@ -1096,26 +1096,26 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, curr_value == value ? "*" : ""); } }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_values[0 ]); + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]);if (ret) goto print_clk_out; - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_values[2 ]); + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret) goto print_clk_out; - freq_values[1 ] = curr_value; - mark_index = curr_value == freq_values[0 ] ?0 : - curr_value == freq_values[2 ] ?2 :1 ; + freq_value[1 ] = curr_value; + mark_index = curr_value == freq_value[0 ] ?0 : + curr_value == freq_value[2 ] ?2 :1 ; count =3 ;if (mark_index !=1 ) { count =2 ; - freq_values[1 ] = freq_values[2 ]; + freq_value[1 ] = freq_value[2 ]; }for (i =0 ; i < count; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_values[i], - curr_value == freq_values[i] ?"*" :"" ); + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); } }
Signature · 1 line
2.33.1.558.g2bd2f258f4
PATCH 4/5 dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3)
In reply to Luben TuikovA current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value.
v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current.
v3: Start the subject title with a verb. (PaulM)
--- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +40 -20
@@ -1040,7 +1040,8 @@ static void sienna_cichlid_get_od_setting_range(struct smu_11_0_7_overdrive_tabl }static int sienna_cichlid_print_clk_levels (struct smu_context *smu, -enum smu_clk_type clk_type,char *buf) +enum smu_clk_type clk_type, +char *buf) {struct amdgpu_device *adev = smu->adev;struct smu_table_context *table_context = &smu->smu_table;
@@ -1052,12 +1053,12 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ; -uint32_t curr_value =0 , value =0 , count =0 ; +uint32_t curr_value, value, count;uint32_t freq_value[3 ] = {0 ,0 ,0 }; -uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;uint32_t min_value, max_value;uint32_t smu_version; +bool fine_grained;smu_cmn_get_sysfs_buf (&buf, &size);
@@ -1077,6 +1078,20 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , + &freq_value[0 ]); +if (ret) + goto print_clk_out; + +/* A current value of a clock frequency of 0, means +* that the IP block is in some kind of low power +* state. Ignore it and don't report it here. Here we +* only report the possible operating (non-zero) +* frequencies of the block requested. So, if the +* current clock value is 0, then we don't report a +* "current" value from the DPM states, i.e. we don't +* add an asterisk. +*/ /* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type ==SMU_GFXCLK ) || (clk_type ==SMU_SCLK ))
@@ -1086,38 +1101,43 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; -if (!sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) { -for (i =0 ; i < count; i++) { + fine_grained =sienna_cichlid_supports_fine_grained_dpm (smu, clk_type); +if (!fine_grained) { +/* We already got the 0-th index--print it +* here and continue thereafter. +*/ + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" ,0 , freq_value[0 ], + curr_value == freq_value[0 ] ?"*" :"" ); +for (i =1 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret) goto print_clk_out; - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, curr_value == value ?"*" :"" ); } }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]); -if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ]; ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret) goto print_clk_out; - freq_value[1 ] = curr_value; - mark_index = curr_value == freq_value[0 ] ?0 : - curr_value == freq_value[2 ] ?2 :1 ; - - count =3 ; -if (mark_index !=1 ) { +if (freq_value[1 ] == freq_value[0 ]) { + i =1 ; + count =3 ; + }else if (freq_value[1 ] == freq_value[2 ]) { + i =0 ; count =2 ; - freq_value[1 ] = freq_value[2 ]; + }else { + i =0 ; + count =3 ; } -for (i =0 ; i < count; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], - curr_value == freq_value[i] ?"*" :"" ); +for ( ; i < count; i++) { + size +=sysfs_emit_at (buf, size, +"%d: %uMhz %s\n" , + i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); } - }break ;case SMU_PCIE :
Signature · 1 line
2.33.1.558.g2bd2f258f4
Re: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3)
Quoted 92 lines · Luben Tuikov
A current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value.
v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current.
v3: Start the subject title with a verb. (PaulM)Cc Alex Deucher <[email protected]>Cc Lijo Lazar <[email protected]>Cc Paul Menzel <[email protected]>Signed-off-by Luben Tuikov <[email protected]>--- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +26
-5@@ -1040,7 +1040,8 @@ static void sienna_cichlid_get_od_setting_range(struct smu_11_0_7_overdrive_tabl }static int sienna_cichlid_print_clk_levels (struct smu_context *smu, -enum smu_clk_type clk_type,char *buf) +enum smu_clk_type clk_type, +char *buf) {struct amdgpu_device *adev = smu->adev;struct smu_table_context *table_context = &smu->smu_table;@@ -1052,12 +1053,12 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ; -uint32_t curr_value =0 , value =0 , count =0 ; +uint32_t curr_value, value, count;uint32_t freq_value[3 ] = {0 ,0 ,0 }; -uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;uint32_t min_value, max_value;uint32_t smu_version; +bool fine_grained;smu_cmn_get_sysfs_buf (&buf, &size);@@ -1077,6 +1078,20 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , + &freq_value[0 ]); +if (ret) + goto print_clk_out; + +/* A current value of a clock frequency of 0, means +* that the IP block is in some kind of low power +* state. Ignore it and don't report it here. Here we +* only report the possible operating (non-zero) +* frequencies of the block requested. So, if the +* current clock value is 0, then we don't report a +* "current" value from the DPM states, i.e. we don't +* add an asterisk. +*/ /* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type ==SMU_GFXCLK ) || (clk_type ==SMU_SCLK ))@@ -1086,38 +1101,43 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; -if (!sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) { -for (i =0 ; i < count; i++) { + fine_grained =sienna_cichlid_supports_fine_grained_dpm (smu, clk_type); +if (!fine_grained) { +/* We already got the 0-th index--print it +* here and continue thereafter. +*/ + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" ,0 , freq_value[0 ], + curr_value == freq_value[0 ] ?"*" :"" ); +for (i =1 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret)
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c static int sienna_cichlid_print_clk_levels(struct smu_context *smu, · line 1119
Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1
-4goto print_clk_out; - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, curr_value == value ?"*" :"" ); } }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]); -if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ];
Omitting second expression is not standard C - https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html
Thanks,
Lijo
Quoted 36 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +13
-11ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret) goto print_clk_out; - freq_value[1 ] = curr_value; - mark_index = curr_value == freq_value[0 ] ?0 : - curr_value == freq_value[2 ] ?2 :1 ; - - count =3 ; -if (mark_index !=1 ) { +if (freq_value[1 ] == freq_value[0 ]) { + i =1 ; + count =3 ; + }else if (freq_value[1 ] == freq_value[2 ]) { + i =0 ; count =2 ; - freq_value[1 ] = freq_value[2 ]; + }else { + i =0 ; + count =3 ; } -for (i =0 ; i < count; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], - curr_value == freq_value[i] ?"*" :"" ); +for ( ; i < count; i++) { + size +=sysfs_emit_at (buf, size, +"%d: %uMhz %s\n" , + i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); } - }break ;case SMU_PCIE :
Re: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3)
On 2021-10-18 23:38, Lazar, Lijo wrote:
On 10/19/2021 5:19 AM, Luben Tuikov wrote: A current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value. v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current. v3: Start the subject title with a verb. (PaulM) Cc: Alex Deucher <[email protected]> Cc: Lijo Lazar <[email protected]> Cc: Paul Menzel <[email protected]> Signed-off-by: Luben Tuikov <[email protected]> --- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c index f630d5e928ccfe..6fe792be77dbbb 100644 --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c @@ -1040,7 +1040,8 @@ static void sienna_cichlid_get_od_setting_range(struct smu_11_0_7_overdrive_tabl } static int sienna_cichlid_print_clk_levels(struct smu_context *smu, - enum smu_clk_type clk_type, char *buf) + enum smu_clk_type clk_type, + char *buf) { struct amdgpu_device *adev = smu->adev; struct smu_table_context *table_context = &smu->smu_table; @@ -1052,12 +1053,12 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table; int i, size = 0, ret = 0; - uint32_t curr_value = 0, value = 0, count = 0; + uint32_t curr_value, value, count; uint32_t freq_value[3] = {0, 0, 0}; - uint32_t mark_index = 0; uint32_t gen_speed, lane_width; uint32_t min_value, max_value; uint32_t smu_version; + bool fine_grained; smu_cmn_get_sysfs_buf(&buf, &size); @@ -1077,6 +1078,20 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, if (ret) goto print_clk_out; + ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, 0, + &freq_value[0]); + if (ret) + goto print_clk_out; + + /* A current value of a clock frequency of 0, means + * that the IP block is in some kind of low power + * state. Ignore it and don't report it here. Here we + * only report the possible operating (non-zero) + * frequencies of the block requested. So, if the + * current clock value is 0, then we don't report a + * "current" value from the DPM states, i.e. we don't + * add an asterisk. + */ /* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type == SMU_GFXCLK) || (clk_type == SMU_SCLK)) @@ -1086,38 +1101,43 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu, if (ret) goto print_clk_out; - if (!sienna_cichlid_supports_fine_grained_dpm(smu, clk_type)) { - for (i = 0; i < count; i++) { + fine_grained = sienna_cichlid_supports_fine_grained_dpm(smu, clk_type); + if (!fine_grained) { + /* We already got the 0-th index--print it + * here and continue thereafter. + */ + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", 0, freq_value[0], + curr_value == freq_value[0] ? "*" : ""); + for (i = 1; i < count; i++) { ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, i, &value); if (ret) goto print_clk_out; - size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, value, curr_value == value ? "*" : ""); } } else { - ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, 0, &freq_value[0]); - if (ret) - goto print_clk_out; + freq_value[1] = curr_value ?: freq_value[0]; Omitting second expression is not standard C - https://gcc.gnu.org/onlinedocs/gcc/Conditionals.html
Lijo just clarified to me that:
well, i had to look up as I haven't seen it before I hope the following should make it clear about its usage:
$cd linux/
$find . -name "*.[ch]" -exec grep -E "\?:" \{\} \+ | wc -l
1042
$_
Regards,
Luben
Thanks, Lijo ret = smu_v11_0_get_dpm_freq_by_index(smu, clk_type, count - 1, &freq_value[2]); if (ret) goto print_clk_out; - freq_value[1] = curr_value; - mark_index = curr_value == freq_value[0] ? 0 : - curr_value == freq_value[2] ? 2 : 1; - - count = 3; - if (mark_index != 1) { + if (freq_value[1] == freq_value[0]) { + i = 1; + count = 3; + } else if (freq_value[1] == freq_value[2]) { + i = 0; count = 2; - freq_value[1] = freq_value[2]; + } else { + i = 0; + count = 3; } - for (i = 0; i < count; i++) { - size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, freq_value[i], - curr_value == freq_value[i] ? "*" : ""); + for ( ; i < count; i++) { + size += sysfs_emit_at(buf, size, + "%d: %uMhz %s\n", + i, freq_value[i], + curr_value == freq_value[i] ? "*" : ""); } - } break; case SMU_PCIE:
Re: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3)
Quoted 109 lines · Luben Tuikov
Quoted 97 lines · Lijo
Quoted 96 lines · Luben Tuikov
A current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value.
v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current.
v3: Start the subject title with a verb. (PaulM)Cc Alex Deucher<[email protected]>Cc Lijo Lazar<[email protected]>Cc Paul Menzel<[email protected]>Signed-off-by Luben Tuikov<[email protected]>--- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +26
-6@@ -1040,7 +1040,8 @@ static void sienna_cichlid_get_od_setting_range(struct smu_11_0_7_overdrive_tabl }static int sienna_cichlid_print_clk_levels (struct smu_context *smu, -enum smu_clk_type clk_type,char *buf) +enum smu_clk_type clk_type, +char *buf) {struct amdgpu_device *adev = smu->adev;struct smu_table_context *table_context = &smu->smu_table;@@ -1052,12 +1053,12 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ; -uint32_t curr_value =0 , value =0 , count =0 ; +uint32_t curr_value, value, count;uint32_t freq_value[3 ] = {0 ,0 ,0 }; -uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;uint32_t min_value, max_value;uint32_t smu_version; +bool fine_grained;smu_cmn_get_sysfs_buf (&buf, &size);@@ -1077,6 +1078,20 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , + &freq_value[0 ]); +if (ret) + goto print_clk_out; + +/* A current value of a clock frequency of 0, means +* that the IP block is in some kind of low power +* state. Ignore it and don't report it here. Here we +* only report the possible operating (non-zero) +* frequencies of the block requested. So, if the +* current clock value is 0, then we don't report a +* "current" value from the DPM states, i.e. we don't +* add an asterisk. +*/ /* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type ==SMU_GFXCLK ) || (clk_type ==SMU_SCLK ))@@ -1086,38 +1101,43 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; -if (!sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) { -for (i =0 ; i < count; i++) { + fine_grained =sienna_cichlid_supports_fine_grained_dpm (smu, clk_type); +if (!fine_grained) { +/* We already got the 0-th index--print it +* here and continue thereafter. +*/ + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" ,0 , freq_value[0 ], + curr_value == freq_value[0 ] ?"*" :"" ); +for (i =1 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret) goto print_clk_out; - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, curr_value == value ?"*" :"" );Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c static int sienna_cichlid_print_clk_levels(struct smu_context *smu, · line 1119
Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1
-3} }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]); -if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ];Omitting second expression is not standard C -
https://gcc.gnu.org/onlinedocs/gcc/Conditionals.htmlLijo just clarified to me that:
Quoted 9 lines
Quoted 1 line
well, i had to look up as I haven't seen it before
I hope the following should make it clear about its usage:
$cd linux/
$find . -name "*.[ch]" -exec grep -E "\?:" \{\} \+ | wc -l 1042
$_
Thanks Luben!
Thanks,
Lijo
Quoted 42 lines
Regards,
LubenQuoted 38 lines
Thanks,
LijoQuoted 36 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +13
-11ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret) goto print_clk_out; - freq_value[1 ] = curr_value; - mark_index = curr_value == freq_value[0 ] ?0 : - curr_value == freq_value[2 ] ?2 :1 ; - - count =3 ; -if (mark_index !=1 ) { +if (freq_value[1 ] == freq_value[0 ]) { + i =1 ; + count =3 ; + }else if (freq_value[1 ] == freq_value[2 ]) { + i =0 ; count =2 ; - freq_value[1 ] = freq_value[2 ]; + }else { + i =0 ; + count =3 ; } -for (i =0 ; i < count; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], - curr_value == freq_value[i] ?"*" :"" ); +for ( ; i < count; i++) { + size +=sysfs_emit_at (buf, size, +"%d: %uMhz %s\n" , + i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); } - }break ;case SMU_PCIE :
Re: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3)
Quoted 111 lines · Lijo
Quoted 109 lines · Luben Tuikov
Quoted 97 lines · Lijo
Quoted 96 lines · Luben Tuikov
A current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value.
v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current.
v3: Start the subject title with a verb. (PaulM)Cc Alex Deucher<[email protected]>Cc Lijo Lazar<[email protected]>Cc Paul Menzel<[email protected]>Signed-off-by Luben Tuikov<[email protected]>--- .../amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 60 ++++++++++++------- 1 file changed, 40 insertions(+), 20 deletions(-)drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +26
-6@@ -1040,7 +1040,8 @@ static void sienna_cichlid_get_od_setting_range(struct smu_11_0_7_overdrive_tabl }static int sienna_cichlid_print_clk_levels (struct smu_context *smu, -enum smu_clk_type clk_type,char *buf) +enum smu_clk_type clk_type, +char *buf) {struct amdgpu_device *adev = smu->adev;struct smu_table_context *table_context = &smu->smu_table;@@ -1052,12 +1053,12 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,OverDriveTable_t *od_table = (OverDriveTable_t *)table_context->overdrive_table;int i, size =0 , ret =0 ; -uint32_t curr_value =0 , value =0 , count =0 ; +uint32_t curr_value, value, count;uint32_t freq_value[3 ] = {0 ,0 ,0 }; -uint32_t mark_index =0 ;uint32_t gen_speed, lane_width;uint32_t min_value, max_value;uint32_t smu_version; +bool fine_grained;smu_cmn_get_sysfs_buf (&buf, &size);@@ -1077,6 +1078,20 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , + &freq_value[0 ]); +if (ret) + goto print_clk_out; + +/* A current value of a clock frequency of 0, means +* that the IP block is in some kind of low power +* state. Ignore it and don't report it here. Here we +* only report the possible operating (non-zero) +* frequencies of the block requested. So, if the +* current clock value is 0, then we don't report a +* "current" value from the DPM states, i.e. we don't +* add an asterisk. +*/ /* no need to disable gfxoff when retrieving the current gfxclk */ if ((clk_type ==SMU_GFXCLK ) || (clk_type ==SMU_SCLK ))@@ -1086,38 +1101,43 @@ static int sienna_cichlid_print_clk_levels(struct smu_context *smu,if (ret) goto print_clk_out; -if (!sienna_cichlid_supports_fine_grained_dpm (smu, clk_type)) { -for (i =0 ; i < count; i++) { + fine_grained =sienna_cichlid_supports_fine_grained_dpm (smu, clk_type); +if (!fine_grained) { +/* We already got the 0-th index--print it +* here and continue thereafter. +*/ + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" ,0 , freq_value[0 ], + curr_value == freq_value[0 ] ?"*" :"" ); +for (i =1 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret) goto print_clk_out; - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, value, curr_value == value ?"*" :"" );Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c static int sienna_cichlid_print_clk_levels(struct smu_context *smu, · line 1119
Quoted 6 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1
-3} }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]); -if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ];Omitting second expression is not standard C -
https://gcc.gnu.org/onlinedocs/gcc/Conditionals.htmlLijo just clarified to me that:
Quoted 1 line
well, i had to look up as I haven't seen it before
Quoted 8 lines
Quoted 7 lines
I hope the following should make it clear about its usage:
$cd linux/
$find . -name "*.[ch]" -exec grep -E "\?:" \{\} \+ | wc -l 1042
$_Thanks Luben!
You're welcome. I'm glad you're learning new things from my patches. Would've been easier if you'd just said in your email that you've never seen this ternary conditional shortcut before and that you've just learned of it from my patch. (Or not post anything at all in this very case and get in touch with me privately via email or Teams--I would've gladly clarified it there.)
I hope the find+egrep above is also edifying, so you can use it in the future in your learning process.
Regards,
Luben
Quoted 45 lines
Thanks,
LijoQuoted 41 lines
Regards,
LubenQuoted 38 lines
Thanks,
LijoQuoted 36 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +13
-11ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret) goto print_clk_out; - freq_value[1 ] = curr_value; - mark_index = curr_value == freq_value[0 ] ?0 : - curr_value == freq_value[2 ] ?2 :1 ; - - count =3 ; -if (mark_index !=1 ) { +if (freq_value[1 ] == freq_value[0 ]) { + i =1 ; + count =3 ; + }else if (freq_value[1 ] == freq_value[2 ]) { + i =0 ; count =2 ; - freq_value[1 ] = freq_value[2 ]; + }else { + i =0 ; + count =3 ; } -for (i =0 ; i < count; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], - curr_value == freq_value[i] ?"*" :"" ); +for ( ; i < count; i++) { + size +=sysfs_emit_at (buf, size, +"%d: %uMhz %s\n" , + i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); } - }break ;case SMU_PCIE :
Use of conditionals with omitted operands in amdgpu (x? : y) (was: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3))
Dear Luben,
Am 19.10.21 um 06:50 schrieb Luben Tuikov:
Quoted 5 lines · Lijo
Quoted 4 lines · Luben Tuikov
Quoted 2 lines · Lijo
Quoted 1 line · Luben Tuikov
[…]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c static int sienna_cichlid_print_clk_levels(struct smu_context *smu, · line 1119
Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1
-2-if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ];Omitting second expression is not standard C -
https://gcc.gnu.org/onlinedocs/gcc/Conditionals.htmlLijo just clarified to me that:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
well, i had to look up as I haven't seen it before
I hope the following should make it clear about its usage:
$cd linux/
$find . -name "*.[ch]" -exec grep -E "\?:" \{\} \+ | wc -l 1042
$_
$ git grep -E "\?:" -- '*amdgpu*.[ch]'
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c: * Solution?:So for the AMDGPU subsystem, as the only result is a comment, currently, conditionals with omitted operands are not used. So, it’s a valid question, if the use should be introduced into the subsystem.
The GCC documentation also states:
Quoted 6 lines
In this simple case, the ability to omit the middle operand is not especially useful. When it becomes useful is when the first operand does, or may (if it is a macro argument), contain a side effect. Then repeating the operand in the middle would perform the side effect twice. Omitting the middle operand uses the value already computed without the undesirable effects of recomputing it.
So, in your case, there are no side effect, if I am not mistaken.
I do not care, if the extension is going to be used or not. The maintainers might want to officially confirm the use in the subsystem, as using these extensions is surprising for some C developers not knowing the GNU extensions.
Quoted 8 lines
Quoted 1 line
Thanks Luben!
You're welcome. I'm glad you're learning new things from my patches. Would've been easier if you'd just said in your email that you've never seen this ternary conditional shortcut before and that you've just learned of it from my patch. (Or not post anything at all in this very case and get in touch with me privately via email or Teams--I would've gladly clarified it there.)
In my opinion, asking this on the list is perfectly valid, as other readers, might have the same question. But being more elaborate to avoid misunderstandings is always a good thing.
Quoted 2 lines
I hope the find+egrep above is also edifying, so you can use it in the future in your learning process.
I hope, you like my solution without using find. ;-)
Kind regards,
Paul
Re: Use of conditionals with omitted operands in amdgpu (x? : y) (was: [PATCH 4/5] dpm/amd/pm: Sienna: Remove 0 MHz as a current clock frequency (v3))
+AlexD
+ChrisianK
+LKML
Quoted 33 lines · Paul Menzel
Dear Luben,
Am 19.10.21 um 06:50 schrieb Luben Tuikov:
Quoted 4 lines · Lijo
Quoted 3 lines · Luben Tuikov
Quoted 2 lines · Lijo
Quoted 1 line · Luben Tuikov
[…]
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c static int sienna_cichlid_print_clk_levels(struct smu_context *smu, · line 1119
Quoted 3 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c +1
-2-if (ret) - goto print_clk_out; + freq_value[1 ] = curr_value ?: freq_value[0 ];Lijo just clarified to me that:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
well, i had to look up as I haven't seen it before
I hope the following should make it clear about its usage:
$cd linux/
$find . -name "*.[ch]" -exec grep -E "\?:" \{\} \+ | wc -l 1042
$_$ git grep -E "\?:" -- '*amdgpu*.[ch]' drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_hdcp.c: * Solution?:So for the AMDGPU subsystem, as the only result is a comment, currently, conditionals with omitted operands are not used. So, it’s a valid question, if the use should be introduced into the subsystem.
The GCC documentation also states:
Quoted 7 lines
Quoted 6 lines
In this simple case, the ability to omit the middle operand is not especially useful. When it becomes useful is when the first operand does, or may (if it is a macro argument), contain a side effect. Then repeating the operand in the middle would perform the side effect twice. Omitting the middle operand uses the value already computed without the undesirable effects of recomputing it.
So, in your case, there are no side effect, if I am not mistaken.
The explanation you quoted above makes a case *for* using the extension. It's telling you that it is a good thing to use the extension so should the first operand be a macro with an argument, it'll avoid being evaluated twice.
Quoted 2 lines
I do not care, if the extension is going to be used or not.
So then why post this message, if you don't care? Since your email continues after this, like this:
Quoted 2 lines
The
maintainers might want to officially confirm the use in the subsystem,
I've added the maintainers, Alex and Christian, as well as LKML to the To: list of this email.
I believe that it is perfectly fine to use the ternary conditional abbreviation "c = a ?: b;", as the kernel uses it extensively, over 1000 occurrences in the kernel. It also eliminates side effects should 'a' be a macro with an argument which evaluates.
Quoted 10 lines
as using these extensions is surprising for some C developers not knowing the GNU extensions.
Quoted 7 lines
Quoted 1 line
Thanks Luben!
You're welcome. I'm glad you're learning new things from my patches. Would've been easier if you'd just said in your email that you've never seen this ternary conditional shortcut before and that you've just learned of it from my patch. (Or not post anything at all in this very case and get in touch with me privately via email or Teams--I would've gladly clarified it there.)
Quoted 3 lines
In my opinion, asking this on the list is perfectly valid, as other readers, might have the same question. But being more elaborate to avoid misunderstandings is always a good thing.
Lijo wasn't asking anything. There was no question in any of his emails on this thread which is all about the use of "?:", which is a well-established practice.
Why are we having a thread about the use of "?:" ?
Regards,
Luben
Quoted 9 lines
Quoted 3 lines
I hope the find+egrep above is also edifying, so you can use it in the future in your learning process.
I hope, you like my solution without using find. ;-)
Kind regards,
Paul
PATCH 5/5 dpm/amd/pm: Navi10: Remove 0 MHz as a current clock frequency (v3)
In reply to Luben TuikovA current value of a clock frequency of 0, means that the IP block is in some kind of low power state. Ignore it and don't report it here. Here we only report the possible operating (non-zero) frequencies of the block requested. So, if the current clock value is 0, then print the DPM frequencies, but don't report a current value.
v2: Don't report the minimum one as the current one when reported one is 0, i.e. don't add an asterisk (Lijo). LT: It is conceivable that this may confuse user-mode tools if they scan and look for a current one, i.e. look for an asterisk, but they'll have to adapt and use other methods for finding power states of the chip--we can't report 0 as current.
v3: Start the subject title with a verb. (PaulM)
--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +28 -16
@@ -1267,9 +1267,8 @@ static int navi10_print_clk_levels(struct smu_context *smu, {uint16_t *curve_settings;int i, size =0 , ret =0 ; -uint32_t curr_value =0 , value =0 , count =0 ; +uint32_t curr_value, value, count;uint32_t freq_value[3 ] = {0 ,0 ,0 }; -uint32_t mark_index =0 ;struct smu_table_context *table_context = &smu->smu_table;uint32_t gen_speed, lane_width;struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
@@ -1279,6 +1278,7 @@ static int navi10_print_clk_levels(struct smu_context *smu, (OverDriveTable_t *)table_context->overdrive_table;struct smu_11_0_overdrive_table *od_settings = smu->od_settings;uint32_t min_value, max_value; +bool fine_grained;smu_cmn_get_sysfs_buf (&buf, &size);
@@ -1296,12 +1296,20 @@ static int navi10_print_clk_levels(struct smu_context *smu,if (ret)return size; + ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , + &freq_value[0 ]); +if (ret) +return size; + ret =smu_v11_0_get_dpm_level_count (smu, clk_type, &count);if (ret)return size; -if (!navi10_supports_fine_grained_dpm (smu, clk_type)) { -for (i =0 ; i < count; i++) { + fine_grained =navi10_supports_fine_grained_dpm (smu, clk_type); +if (!fine_grained) { + size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" ,0 , freq_value[0 ], + curr_value == freq_value[0 ] ?"*" :"" ); +for (i =1 ; i < count; i++) { ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, i, &value);if (ret)return size;
@@ -1310,24 +1318,28 @@ static int navi10_print_clk_levels(struct smu_context *smu, curr_value == value ? "*" : ""); } }else { - ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type,0 , &freq_value[0 ]); -if (ret) -return size; + freq_value[1 ] = curr_value ?: freq_value[0 ]; ret =smu_v11_0_get_dpm_freq_by_index (smu, clk_type, count -1 , &freq_value[2 ]);if (ret)return size; - freq_value[1 ] = curr_value; - mark_index = curr_value == freq_value[0 ] ?0 : - curr_value == freq_value[2 ] ?2 :1 ; -if (mark_index !=1 ) - freq_value[1 ] = (freq_value[0 ] + freq_value[2 ]) /2 ; - -for (i =0 ; i <3 ; i++) { - size +=sysfs_emit_at (buf, size,"%d: %uMhz %s\n" , i, freq_value[i], - i == mark_index ?"*" :"" ); +if (freq_value[1 ] == freq_value[0 ]) { + i =1 ; + count =3 ; + }else if (freq_value[1 ] == freq_value[2 ]) { + i =0 ; + count =2 ; + }else { + i =0 ; + count =3 ; } +for ( ; i < count; i++) { + size +=sysfs_emit_at (buf, size, +"%d: %uMhz %s\n" , + i, freq_value[i], + curr_value == freq_value[i] ?"*" :"" ); + } }break ;case SMU_PCIE :
Signature · 1 line
2.33.1.558.g2bd2f258f4
Dear Luben,
Sorry, two more style nits.
1. Could you please use 75 characters per line for the text width of the commit messages. Currently, especially 4/5, are hard to read being so short.
2. No idea, what is done in amd-gfx, but for me it is more common to put the iteration number (reroll count) in the PATCH tag in the beginning. No idea, how Patchwork deals with it.
Kind regards,
Paul
Quoted 8 lines · Paul Menzel
Dear Luben,
Sorry, two more style nits.
1. Could you please use 75 characters per line for the text width of the commit messages. Currently, especially 4/5, are hard to read being so short.
This is the default we use--I've not made any changes to the wrap. git-log(1) indents the text by 4/8 chars and it looks better if the text doesn't roll past 75 chars per line in git-log.
Quoted 4 lines
2. No idea, what is done in amd-gfx, but for me it is more common to put the iteration number (reroll count) in the PATCH tag in the beginning. No idea, how Patchwork deals with it.
This is what we do in amd-gfx and particularly in amdgpu, so that the version of the patch is recorded in the title of the patch and in history.
Regards,
Luben
Quoted 5 lines
Kind regards,
Paul
Dear Luben,
Thank you for your quick reply.
Am 19.10.21 um 09:43 schrieb Luben Tuikov:
Quoted 9 lines · Paul Menzel
Quoted 6 lines
Sorry, two more style nits.
1. Could you please use 75 characters per line for the text width of the commit messages. Currently, especially 4/5, are hard to read being so short.
This is the default we use--I've not made any changes to the wrap.
What do you mean? Your editor wraps the lines at the point, where you configured it, doesn’t it?
Quoted 2 lines
git-log(1) indents the text by 4/8 chars and it looks better if the text doesn't roll past 75 chars per line in git-log.
Patch 4/5 uses a text width of 50 characters, which is too short. From commit 2a076f40d8c9 (checkpatch, SubmittingPatches: suggest line wrapping commit messages at 75 columns) [1], which added a check for too long lines:
Quoted 11 lines
Suggest line wrapping at 75 columns so the default git commit log indentation of 4 plus the commit message text still fits on an 80 column screen.
Quoted 3 lines
2. No idea, what is done in amd-gfx, but for me it is more common to put the iteration number (reroll count) in the PATCH tag in the beginning. No idea, how Patchwork deals with it.
This is what we do in amd-gfx and particularly in amdgpu, so that the version of the patch is recorded in the title of the patch and in history.
I forgot. Thank you.
Kind regards,
Paul