amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2

Use variables to remove ternary expression in print statement
 and improve readability. This will help to optimize the code
 duplication in the switch statement
 Also Changed:
  replaced single_dpm_table->count as iterator in for loops
    with safer clocks_num_levels value
  replaced dpm_table.value usage with local var clocks_mhz

Signed-off-by: Darren Powell <darren.powell@amd.com>
Reviewed-by: Lijo Lazar <lijo.lazar@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
This commit is contained in:
Darren Powell 2023-04-03 23:37:50 -04:00 committed by Alex Deucher
parent 2ecf214b45
commit d62846f778

View File

@ -792,12 +792,11 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
for (i = 0; i < display_levels; i++) {
clock_mhz = freq_values[i];
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (display_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
clock_mhz,
(display_levels == 1) ?
"*" :
(freq_match) ? "*" : "");
(freq_match) ? "*" : "");
}
break;
@ -818,10 +817,10 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
for (i = 0; i < clocks.num_levels; i++) {
clock_mhz = clocks.data[i].clocks_in_khz / 1000;
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (clocks.num_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
i, clock_mhz,
(clocks.num_levels == 1) ? "*" :
(freq_match) ? "*" : "");
}
break;
@ -839,10 +838,10 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
for (i = 0; i < clocks.num_levels; i++) {
clock_mhz = clocks.data[i].clocks_in_khz / 1000;
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (clocks.num_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
i, clock_mhz,
(clocks.num_levels == 1) ? "*" :
(freq_match) ? "*" : "");
}
break;
@ -857,13 +856,13 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
for (i = 0; i < single_dpm_table->count; i++) {
for (i = 0; i < clocks.num_levels; i++) {
clock_mhz = clocks.data[i].clocks_in_khz / 1000;
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (clocks.num_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
i, single_dpm_table->dpm_levels[i].value,
(clocks.num_levels == 1) ? "*" :
i, clock_mhz,
(freq_match) ? "*" : "");
}
break;
@ -878,13 +877,13 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
for (i = 0; i < single_dpm_table->count; i++) {
for (i = 0; i < clocks.num_levels; i++) {
clock_mhz = clocks.data[i].clocks_in_khz / 1000;
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (clocks.num_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
i, single_dpm_table->dpm_levels[i].value,
(clocks.num_levels == 1) ? "*" :
i, clock_mhz,
(freq_match) ? "*" : "");
}
break;
@ -899,13 +898,13 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
for (i = 0; i < single_dpm_table->count; i++) {
for (i = 0; i < clocks.num_levels; i++) {
clock_mhz = clocks.data[i].clocks_in_khz / 1000;
freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
freq_match |= (clocks.num_levels == 1);
*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
i, single_dpm_table->dpm_levels[i].value,
(clocks.num_levels == 1) ? "*" :
i, clock_mhz,
(freq_match) ? "*" : "");
}
break;