Skip to contentSkip to conversation

amdgpu/pm: Implement emit_clock_levels for arcturus, aldebaran

PATCH In review Darren Powell 3 participants 16 messages Apr 27, 2023 – Jul 28, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover amdgpu/pm: Implement emit_clock_levels for arcturus, aldebaran

amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

== Description ==
Scnprintf use within the kernel is not recommended, but simple sysfs_emit replacement has not been successful due to the page alignment requirement of the function. This patch set implements a new api "emit_clock_levels" to facilitate passing both the base and offset to the device rather than just the write pointer.

This patch set replaces print_clock_levels for arcturus and aldebaran platforms with emit_clock_levels, and also optimizes the code to reduce the code duplication for each different clock. This was spread into three parts to show more clearly the changes made to the code, followed by combining the common code into a second switch statement. It is similar to previous work on vega10 to implement emit_clk_levels
commit a63e6b83 ("amdgpu/pm: Implement emit_clk_levels for vega10")
with the addition of the optimization to reduce code duplication.

== Patch Summary ==
linux: ([email protected]:agd5f) origin/amd-staging-drm-next @ 2d8c6b82e241
+ 9a269da4c047 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for arcturus
+ 51ce0fcc9599 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1
+ dcaa5b7551dd amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2
+ 1d16d820e4ee amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3
+ b374fbf6013d amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran
+ 2ecf48d3e83c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1
+ fd8c21e1d1e4 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2
+ a67ce808f18c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

== System Summary ==
* DESKTOP(AMD Ryzen9 7900 + NAVI10(731f/ca), BIOS: 1.11)
+ ISO(Ubuntu 22.04.2 LTS)
+ Kernel(6.1.11-20230412-fdoagd5f-g2d8c6b82e241)

== 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}

lspci -nn | grep "VGA\|Display" > $LOGFILE
printf 'OD enabled = %X\n' "$(( cat /sys/module/amdgpu/parameters/ppfeaturemask & 0x4000 ))" >> $LOGFILE FILES="pp_od_clk_voltage
pp_dpm_sclk
pp_dpm_mclk
pp_dpm_pcie
pp_dpm_socclk
pp_dpm_fclk
pp_dpm_dcefclk
pp_dpm_vclk
pp_dpm_dclk "

for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE

Darren Powell (8):
amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
arcturus
amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
aldebaran
amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 166 ++++++----------
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 181 +++++++-----------
 2 files changed, 132 insertions(+), 215 deletions(-)

base-commit: 2d8c6b82e241f2d1a802ae6bbc24c127e689c724

Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/8 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for arcturus

Replace print_clock_levels with emit_clock_levels for arcturus
* replace .print_clk_levels with .emit_clk_levels in arcturus_ppt_funcs
* added extra parameter int *offset
* removed var size, uses arg *offset instead
* removed call to smu_cmn_get_sysfs_buf
* errors are returned to caller
* returns 0 on success
additional incidental changes
* changed type of var i, now to remove comparing mismatch types
* renamed var s/now/cur_value/
* switch statement default now returns -EINVAL
* RAS Recovery returns -EBUSY

Based on
commit aa93bbdd1492 ("amdgpu/pm: Implement emit_clk_levels for navi10")

---
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 54 +++++++++----------
 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +27 -27
index 9cd005131f56..0136e136e807 100644
@@ -757,29 +757,28 @@ static int arcturus_get_current_clk_freq_by_table(struct smu_context *smu,
 					     value);
 }
 
-static int arcturus_print_clk_levels(struct smu_context *smu,
-			enum smu_clk_type type, char *buf)
+static int arcturus_emit_clk_levels(struct smu_context *smu,
+				    enum smu_clk_type type, char *buf, int *offset)
 {
-	int i, now, size = 0;
 	int ret = 0;
 	struct pp_clock_levels_with_latency clocks;
 	struct smu_11_0_dpm_table *single_dpm_table;
 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
 	struct smu_11_0_dpm_context *dpm_context = NULL;
 	uint32_t gen_speed, lane_width;
+	uint32_t i, cur_value = 0;
 
-	smu_cmn_get_sysfs_buf(&buf, &size);
 
 	if (amdgpu_ras_intr_triggered()) {
-		size += sysfs_emit_at(buf, size, "unavailable\n");
-		return size;
+		*offset += sysfs_emit_at(buf, *offset, "unavailable\n");
+		return -EBUSY;
 	}
 
 	dpm_context = smu_dpm->dpm_context;
 
 	switch (type) {
 	case SMU_SCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current gfx clk Failed!");
 			return ret;
@@ -797,16 +796,16 @@ 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 += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
 					clocks.data[i].clocks_in_khz / 1000,
 					(clocks.num_levels == 1) ? "*" :
 					(arcturus_freqs_in_same_level(
 					clocks.data[i].clocks_in_khz / 1000,
-					now) ? "*" : ""));
+					cur_value) ? "*" : ""));
 		break;
 
 	case SMU_MCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_UCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_UCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current mclk Failed!");
 			return ret;
@@ -820,16 +819,16 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, clocks.data[i].clocks_in_khz / 1000,
 				(clocks.num_levels == 1) ? "*" :
 				(arcturus_freqs_in_same_level(
 				clocks.data[i].clocks_in_khz / 1000,
-				now) ? "*" : ""));
+				cur_value) ? "*" : ""));
 		break;
 
 	case SMU_SOCCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current socclk Failed!");
 			return ret;
@@ -843,16 +842,16 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, clocks.data[i].clocks_in_khz / 1000,
 				(clocks.num_levels == 1) ? "*" :
 				(arcturus_freqs_in_same_level(
 				clocks.data[i].clocks_in_khz / 1000,
-				now) ? "*" : ""));
+				cur_value) ? "*" : ""));
 		break;
 
 	case SMU_FCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_FCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_FCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current fclk Failed!");
 			return ret;
@@ -866,16 +865,16 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
 				(arcturus_freqs_in_same_level(
 				clocks.data[i].clocks_in_khz / 1000,
-				now) ? "*" : ""));
+				cur_value) ? "*" : ""));
 		break;
 
 	case SMU_VCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_VCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_VCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current vclk Failed!");
 			return ret;
@@ -889,16 +888,16 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
 				(arcturus_freqs_in_same_level(
 				clocks.data[i].clocks_in_khz / 1000,
-				now) ? "*" : ""));
+				cur_value) ? "*" : ""));
 		break;
 
 	case SMU_DCLK:
-		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_DCLK, &now);
+		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_DCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current dclk Failed!");
 			return ret;
@@ -912,18 +911,18 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
 				(arcturus_freqs_in_same_level(
 				clocks.data[i].clocks_in_khz / 1000,
-				now) ? "*" : ""));
+				cur_value) ? "*" : ""));
 		break;
 
 	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 += sysfs_emit_at(buf, size, "0: %s %s %dMhz *\n",
+		*offset += sysfs_emit_at(buf, *offset, "0: %s %s %dMhz *\n",
 				(gen_speed == 0) ? "2.5GT/s," :
 				(gen_speed == 1) ? "5.0GT/s," :
 				(gen_speed == 2) ? "8.0GT/s," :
@@ -938,10 +937,11 @@ static int arcturus_print_clk_levels(struct smu_context *smu,
 		break;
 
 	default:
+		return -EINVAL;
 		break;
 	}
 
-	return size;
+	return 0;
 }
 
 static int arcturus_upload_dpm_level(struct smu_context *smu,
@@ -2432,7 +2432,7 @@ static const struct pptable_funcs arcturus_ppt_funcs = {
 	.set_default_dpm_table = arcturus_set_default_dpm_table,
 	.populate_umd_state_clk = arcturus_populate_umd_state_clk,
 	.get_thermal_temperature_range = arcturus_get_thermal_temperature_range,
-	.print_clk_levels = arcturus_print_clk_levels,
+	.emit_clk_levels = arcturus_emit_clk_levels,
 	.force_clk_levels = arcturus_force_clk_levels,
 	.read_sensor = arcturus_read_sensor,
 	.get_fan_speed_pwm = arcturus_get_fan_speed_pwm,
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/8 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1

In reply to Darren Powell

Use variables to remove the multiple nested ternary expressions and improve readability. This will help to optimize the code duplication in the switch statement
Also Changed:
Modify function arcturus_get_clk_table to void function as it
always returns 0
Use const string "attempt_string" to cut down on repetition

---
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 126 ++++++++----------
 1 file changed, 57 insertions(+), 69 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +57 -69
index 0136e136e807..23e768aad6f9 100644
@@ -569,9 +569,9 @@ static int arcturus_populate_umd_state_clk(struct smu_context *smu)
 	return 0;
 }
 
-static int arcturus_get_clk_table(struct smu_context *smu,
-			struct pp_clock_levels_with_latency *clocks,
-			struct smu_11_0_dpm_table *dpm_table)
+static void arcturus_get_clk_table(struct smu_context *smu,
+				   struct pp_clock_levels_with_latency *clocks,
+				   struct smu_11_0_dpm_table *dpm_table)
 {
 	uint32_t i;
 
@@ -584,8 +584,6 @@ static int arcturus_get_clk_table(struct smu_context *smu,
 			dpm_table->dpm_levels[i].value * 1000;
 		clocks->data[i].latency_in_us = 0;
 	}
-
-	return 0;
 }
 
 static int arcturus_freqs_in_same_level(int32_t frequency1,
@@ -767,7 +765,9 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 	struct smu_11_0_dpm_context *dpm_context = NULL;
 	uint32_t gen_speed, lane_width;
 	uint32_t i, cur_value = 0;
-
+	bool freq_match;
+	unsigned int clock_mhz;
+	static const char attempt_string[] = "Attempt to get current";
 
 	if (amdgpu_ras_intr_triggered()) {
 		*offset += sysfs_emit_at(buf, *offset, "unavailable\n");
@@ -780,143 +780,131 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 	case SMU_SCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current gfx clk Failed!");
+			dev_err(smu->adev->dev, "%s gfx clk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.gfx_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get gfx clk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
 		/*
 		 * For DPM disabled case, there will be only one clock level.
 		 * And it's safe to assume that is always the current clock.
 		 */
-		for (i = 0; i < clocks.num_levels; i++)
+		for (i = 0; i < clocks.num_levels; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
+
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
-					clocks.data[i].clocks_in_khz / 1000,
+					clock_mhz,
 					(clocks.num_levels == 1) ? "*" :
-					(arcturus_freqs_in_same_level(
-					clocks.data[i].clocks_in_khz / 1000,
-					cur_value) ? "*" : ""));
+						(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_MCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_UCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current mclk Failed!");
+			dev_err(smu->adev->dev, "%s mclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get memory clk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < clocks.num_levels; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < clocks.num_levels; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
-				i, clocks.data[i].clocks_in_khz / 1000,
+				i, clock_mhz,
 				(clocks.num_levels == 1) ? "*" :
-				(arcturus_freqs_in_same_level(
-				clocks.data[i].clocks_in_khz / 1000,
-				cur_value) ? "*" : ""));
+					(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_SOCCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current socclk Failed!");
+			dev_err(smu->adev->dev, "%s socclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get socclk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < clocks.num_levels; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < clocks.num_levels; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
-				i, clocks.data[i].clocks_in_khz / 1000,
+				i, clock_mhz,
 				(clocks.num_levels == 1) ? "*" :
-				(arcturus_freqs_in_same_level(
-				clocks.data[i].clocks_in_khz / 1000,
-				cur_value) ? "*" : ""));
+					(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_FCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_FCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current fclk Failed!");
+			dev_err(smu->adev->dev, "%s fclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get fclk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
-				(arcturus_freqs_in_same_level(
-				clocks.data[i].clocks_in_khz / 1000,
-				cur_value) ? "*" : ""));
+					(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_VCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_VCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current vclk Failed!");
+			dev_err(smu->adev->dev, "%s vclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get vclk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
-				(arcturus_freqs_in_same_level(
-				clocks.data[i].clocks_in_khz / 1000,
-				cur_value) ? "*" : ""));
+					(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_DCLK:
 		ret = arcturus_get_current_clk_freq_by_table(smu, SMU_DCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current dclk Failed!");
+			dev_err(smu->adev->dev, "%s dclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
-		ret = arcturus_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get dclk levels Failed!");
-			return ret;
-		}
+		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = arcturus_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 				i, single_dpm_table->dpm_levels[i].value,
 				(clocks.num_levels == 1) ? "*" :
-				(arcturus_freqs_in_same_level(
-				clocks.data[i].clocks_in_khz / 1000,
-				cur_value) ? "*" : ""));
+					(freq_match ? "*" : ""));
+		}
 		break;
 
 	case SMU_PCIE:
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/8 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2

In reply to Darren Powell

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

---
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 45 +++++++++----------
 1 file changed, 22 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +22 -23
index 23e768aad6f9..aea78f9dbae2 100644
@@ -794,11 +794,11 @@ static int arcturus_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 = arcturus_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 ? "*" : ""));
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -815,11 +815,11 @@ static int arcturus_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 = arcturus_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 ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -836,11 +836,11 @@ static int arcturus_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 = arcturus_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 ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -854,14 +854,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
 		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -875,14 +875,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
 		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -896,14 +896,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
 		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
 		}
 		break;
 
@@ -926,7 +926,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 
 	default:
 		return -EINVAL;
-		break;
 	}
 
 	return 0;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 3/8] amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2

Quoted 18 lines · Darren Powell

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

---
  .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 45 +++++++++----------
  1 file changed, 22 insertions(+), 23 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +0 -0
index 23e768aad6f9..aea78f9dbae2 100644

drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c static int arcturus_emit_clk_levels(struct smu_context *smu, · line 797

Quoted 4 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +1 -0
@@ -794,11 +794,11 @@ static int arcturus_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 = arcturus_freqs_in_same_level(clock_mhz, cur_value);
+			freq_match |= (clocks.num_levels == 1);

<Nit> You may use it with || in the previous expression to get short circuit benefit.

Thanks,
Lijo

Quoted 106 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +21 -23
-			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
-					clock_mhz,
-					(clocks.num_levels == 1) ? "*" :
-						(freq_match ? "*" : ""));
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -815,11 +815,11 @@ static int arcturus_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 = arcturus_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 ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -836,11 +836,11 @@ static int arcturus_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 = arcturus_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 ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -854,14 +854,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
  		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -875,14 +875,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
  		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -896,14 +896,14 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
  		arcturus_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 = arcturus_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) ? "*" :
-					(freq_match ? "*" : ""));
+						 i, clock_mhz,
+						 freq_match ? "*" : "");
  		}
  		break;
 
@@ -926,7 +926,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 
  	default:
  		return -EINVAL;
-		break;
  	}
 
  	return 0;
#5 lore raw

PATCH 4/8 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3

In reply to Darren Powell

split switch statement into two and consolidate the common
code for printing most of the types of clock speeds

---
 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 77 ++++++-------------
 1 file changed, 24 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +24 -53
index aea78f9dbae2..0e26c8b31daa 100644
@@ -787,19 +787,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.gfx_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		/*
-		 * For DPM disabled case, there will be only one clock level.
-		 * And it's safe to assume that is always the current clock.
-		 */
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
 		break;
 
 	case SMU_MCLK:
@@ -812,15 +799,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
 		break;
 
 	case SMU_SOCCLK:
@@ -833,15 +811,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
 		break;
 
 	case SMU_FCLK:
@@ -854,15 +823,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
 		break;
 
 	case SMU_VCLK:
@@ -875,15 +835,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
 		break;
 
 	case SMU_DCLK:
@@ -896,20 +847,40 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
 		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
 		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
+		break;
+
+	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);
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	switch (type) {
+	case SMU_SCLK:
+	case SMU_MCLK:
+	case SMU_SOCCLK:
+	case SMU_FCLK:
+	case SMU_VCLK:
+	case SMU_DCLK:
+		/*
+		 * For DPM disabled case, there will be only one clock level.
+		 * And it's safe to assume that is always the current clock.
+		 */
 		for (i = 0; i < clocks.num_levels; i++) {
 			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
 			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
+				i, clock_mhz,
+				freq_match ? "*" : "");
 		}
 		break;
 
 	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);
 		*offset += sysfs_emit_at(buf, *offset, "0: %s %s %dMhz *\n",
 				(gen_speed == 0) ? "2.5GT/s," :
 				(gen_speed == 1) ? "5.0GT/s," :
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH 4/8] amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3

Quoted 123 lines · Darren Powell

split switch statement into two and consolidate the common
code for printing most of the types of clock speeds

---
  .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 77 ++++++-------------
  1 file changed, 24 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +22 -49
index aea78f9dbae2..0e26c8b31daa 100644
@@ -787,19 +787,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.gfx_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		/*
-		 * For DPM disabled case, there will be only one clock level.
-		 * And it's safe to assume that is always the current clock.
-		 */
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
  		break;
 
  	case SMU_MCLK:
@@ -812,15 +799,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
  		break;
 
  	case SMU_SOCCLK:
@@ -833,15 +811,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
  		break;
 
  	case SMU_FCLK:
@@ -854,15 +823,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
  		break;
 
  	case SMU_VCLK:
@@ -875,15 +835,6 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
-		for (i = 0; i < clocks.num_levels; i++) {
-			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
-			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
-		}
  		break;
 
  	case SMU_DCLK:
@@ -896,20 +847,40 @@ static int arcturus_emit_clk_levels(struct smu_context *smu,
  		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
  		arcturus_get_clk_table(smu, &clocks, single_dpm_table);
 
+		break;
+
+	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);
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	switch (type) {
+	case SMU_SCLK:
+	case SMU_MCLK:
+	case SMU_SOCCLK:
+	case SMU_FCLK:
+	case SMU_VCLK:
+	case SMU_DCLK:
+		/*
+		 * For DPM disabled case, there will be only one clock level.
+		 * And it's safe to assume that is always the current clock.
+		 */
  		for (i = 0; i < clocks.num_levels; i++) {

drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c static int arcturus_emit_clk_levels(struct smu_context *smu, · line 880

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +2 -2
  			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
  			freq_match = arcturus_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,
-						 freq_match ? "*" : "");
+				i, clock_mhz,
+				freq_match ? "*" : "");
  		}

<Nit> Making this a small inline function or a goto may be considered instead of another switch statement.

Thanks,
Lijo

Quoted 8 lines
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +0 -2
  		break;
 
  	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);
  		*offset += sysfs_emit_at(buf, *offset, "0: %s %s %dMhz *\n",
  				(gen_speed == 0) ? "2.5GT/s," :
  				(gen_speed == 1) ? "5.0GT/s," :
#7 lore raw

PATCH 5/8 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran

In reply to Darren Powell

Replace print_clock_levels with emit_clock_levels for aldebaran
* replace .print_clk_levels with .emit_clk_levels in aldebaran_ppt_funcs
* added extra parameter int *offset
* removed var size, uses arg *offset instead
* removed call to smu_cmn_get_sysfs_buf
* errors are returned to caller
* returns 0 on success
additional incidental changes
* changed type of vars i, now to remove comparing mismatch types
* renamed var s/now/cur_value/
* switch statement default now returns -EINVAL
* RAS Recovery returns -EBUSY

Based on
commit aa93bbdd1492 ("amdgpu/pm: Implement emit_clk_levels for navi10")

---
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 63 +++++++++----------
 1 file changed, 31 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +31 -32
index d30ec3005ea1..f93a50217239 100644
@@ -736,25 +736,23 @@ static int aldebaran_get_current_clk_freq_by_table(struct smu_context *smu,
 					      value);
 }
 
-static int aldebaran_print_clk_levels(struct smu_context *smu,
-				      enum smu_clk_type type, char *buf)
+static int aldebaran_emit_clk_levels(struct smu_context *smu,
+				     enum smu_clk_type type, char *buf, int *offset)
 {
-	int i, now, size = 0;
 	int ret = 0;
 	struct smu_umd_pstate_table *pstate_table = &smu->pstate_table;
 	struct pp_clock_levels_with_latency clocks;
 	struct smu_13_0_dpm_table *single_dpm_table;
 	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
 	struct smu_13_0_dpm_context *dpm_context = NULL;
+	uint32_t i;
 	int display_levels;
 	uint32_t freq_values[3] = {0};
-	uint32_t min_clk, max_clk;
-
-	smu_cmn_get_sysfs_buf(&buf, &size);
+	uint32_t min_clk, max_clk, cur_value = 0;
 
 	if (amdgpu_ras_intr_triggered()) {
-		size += sysfs_emit_at(buf, size, "unavailable\n");
-		return size;
+		*offset += sysfs_emit_at(buf, *offset, "unavailable\n");
+		return -EBUSY;
 	}
 
 	dpm_context = smu_dpm->dpm_context;
@@ -762,10 +760,10 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 	switch (type) {
 
 	case SMU_OD_SCLK:
-		size += sysfs_emit_at(buf, size, "%s:\n", "GFXCLK");
+		*offset += sysfs_emit_at(buf, *offset, "%s:\n", "GFXCLK");
 		fallthrough;
 	case SMU_SCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current gfx clk Failed!");
 			return ret;
@@ -787,29 +785,29 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		freq_values[1] = max_clk;
 
 		/* fine-grained dpm has only 2 levels */
-		if (now > min_clk && now < max_clk) {
+		if (cur_value > min_clk && cur_value < max_clk) {
 			display_levels++;
 			freq_values[2] = max_clk;
-			freq_values[1] = now;
+			freq_values[1] = cur_value;
 		}
 
 		for (i = 0; i < display_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
 				freq_values[i],
 				(display_levels == 1) ?
 					"*" :
 					(aldebaran_freqs_in_same_level(
-						 freq_values[i], now) ?
+						 freq_values[i], cur_value) ?
 						 "*" :
 						 ""));
 
 		break;
 
 	case SMU_OD_MCLK:
-		size += sysfs_emit_at(buf, size, "%s:\n", "MCLK");
+		*offset += sysfs_emit_at(buf, *offset, "%s:\n", "MCLK");
 		fallthrough;
 	case SMU_MCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_UCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_UCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current mclk Failed!");
 			return ret;
@@ -823,16 +821,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, clocks.data[i].clocks_in_khz / 1000,
 					(clocks.num_levels == 1) ? "*" :
 					(aldebaran_freqs_in_same_level(
 								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
 		break;
 
 	case SMU_SOCCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current socclk Failed!");
 			return ret;
@@ -846,16 +844,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, clocks.data[i].clocks_in_khz / 1000,
 					(clocks.num_levels == 1) ? "*" :
 					(aldebaran_freqs_in_same_level(
 								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
 		break;
 
 	case SMU_FCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_FCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_FCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current fclk Failed!");
 			return ret;
@@ -869,16 +867,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
 					(aldebaran_freqs_in_same_level(
 								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
 		break;
 
 	case SMU_VCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_VCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_VCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current vclk Failed!");
 			return ret;
@@ -892,16 +890,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
 					(aldebaran_freqs_in_same_level(
 								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
 		break;
 
 	case SMU_DCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_DCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_DCLK, &cur_value);
 		if (ret) {
 			dev_err(smu->adev->dev, "Attempt to get current dclk Failed!");
 			return ret;
@@ -915,19 +913,20 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
 		}
 
 		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
 					(aldebaran_freqs_in_same_level(
 								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
 		break;
 
 	default:
+		return -EINVAL;
 		break;
 	}
 
-	return size;
+	return 0;
 }
 
 static int aldebaran_upload_dpm_level(struct smu_context *smu,
@@ -2079,7 +2078,7 @@ static const struct pptable_funcs aldebaran_ppt_funcs = {
 	.set_default_dpm_table = aldebaran_set_default_dpm_table,
 	.populate_umd_state_clk = aldebaran_populate_umd_state_clk,
 	.get_thermal_temperature_range = aldebaran_get_thermal_temperature_range,
-	.print_clk_levels = aldebaran_print_clk_levels,
+	.emit_clk_levels = aldebaran_emit_clk_levels,
 	.force_clk_levels = aldebaran_force_clk_levels,
 	.read_sensor = aldebaran_read_sensor,
 	.set_performance_level = aldebaran_set_performance_level,
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH 5/8] amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran

Quoted 26 lines · Darren Powell

Replace print_clock_levels with emit_clock_levels for aldebaran
* replace .print_clk_levels with .emit_clk_levels in aldebaran_ppt_funcs
* added extra parameter int *offset
* removed var size, uses arg *offset instead
* removed call to smu_cmn_get_sysfs_buf
* errors are returned to caller
* returns 0 on success
additional incidental changes
* changed type of vars i, now to remove comparing mismatch types
* renamed var s/now/cur_value/
* switch statement default now returns -EINVAL
* RAS Recovery returns -EBUSY

Based on
commit aa93bbdd1492 ("amdgpu/pm: Implement emit_clk_levels for navi10")

---
  .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 63 +++++++++----------
  1 file changed, 31 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +0 -0
index d30ec3005ea1..f93a50217239 100644

drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c static int aldebaran_get_current_clk_freq_by_table(struct smu_context *smu, · line 740

Quoted 7 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -2
@@ -736,25 +736,23 @@ static int aldebaran_get_current_clk_freq_by_table(struct smu_context *smu,
  					      value);
  }
 
-static int aldebaran_print_clk_levels(struct smu_context *smu,
-				      enum smu_clk_type type, char *buf)
+static int aldebaran_emit_clk_levels(struct smu_context *smu,
+				     enum smu_clk_type type, char *buf, int *offset)

<Nit> It's not necessary to match the name with the API call used. For me, 'print' is more obvious than 'emit'.

Thanks,
Lijo

Quoted 186 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +29 -30
  {
-	int i, now, size = 0;
  	int ret = 0;
  	struct smu_umd_pstate_table *pstate_table = &smu->pstate_table;
  	struct pp_clock_levels_with_latency clocks;
  	struct smu_13_0_dpm_table *single_dpm_table;
  	struct smu_dpm_context *smu_dpm = &smu->smu_dpm;
  	struct smu_13_0_dpm_context *dpm_context = NULL;
+	uint32_t i;
  	int display_levels;
  	uint32_t freq_values[3] = {0};
-	uint32_t min_clk, max_clk;
-
-	smu_cmn_get_sysfs_buf(&buf, &size);
+	uint32_t min_clk, max_clk, cur_value = 0;
 
  	if (amdgpu_ras_intr_triggered()) {
-		size += sysfs_emit_at(buf, size, "unavailable\n");
-		return size;
+		*offset += sysfs_emit_at(buf, *offset, "unavailable\n");
+		return -EBUSY;
  	}
 
  	dpm_context = smu_dpm->dpm_context;
@@ -762,10 +760,10 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  	switch (type) {
 
  	case SMU_OD_SCLK:
-		size += sysfs_emit_at(buf, size, "%s:\n", "GFXCLK");
+		*offset += sysfs_emit_at(buf, *offset, "%s:\n", "GFXCLK");
  		fallthrough;
  	case SMU_SCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current gfx clk Failed!");
  			return ret;
@@ -787,29 +785,29 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		freq_values[1] = max_clk;
 
  		/* fine-grained dpm has only 2 levels */
-		if (now > min_clk && now < max_clk) {
+		if (cur_value > min_clk && cur_value < max_clk) {
  			display_levels++;
  			freq_values[2] = max_clk;
-			freq_values[1] = now;
+			freq_values[1] = cur_value;
  		}
 
  		for (i = 0; i < display_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i,
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
  				freq_values[i],
  				(display_levels == 1) ?
  					"*" :
  					(aldebaran_freqs_in_same_level(
-						 freq_values[i], now) ?
+						 freq_values[i], cur_value) ?
  						 "*" :
  						 ""));
 
  		break;
 
  	case SMU_OD_MCLK:
-		size += sysfs_emit_at(buf, size, "%s:\n", "MCLK");
+		*offset += sysfs_emit_at(buf, *offset, "%s:\n", "MCLK");
  		fallthrough;
  	case SMU_MCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_UCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_UCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current mclk Failed!");
  			return ret;
@@ -823,16 +821,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		}
 
  		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
  					i, clocks.data[i].clocks_in_khz / 1000,
  					(clocks.num_levels == 1) ? "*" :
  					(aldebaran_freqs_in_same_level(
  								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
  		break;
 
  	case SMU_SOCCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current socclk Failed!");
  			return ret;
@@ -846,16 +844,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		}
 
  		for (i = 0; i < clocks.num_levels; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
  					i, clocks.data[i].clocks_in_khz / 1000,
  					(clocks.num_levels == 1) ? "*" :
  					(aldebaran_freqs_in_same_level(
  								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
  		break;
 
  	case SMU_FCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_FCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_FCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current fclk Failed!");
  			return ret;
@@ -869,16 +867,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		}
 
  		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
  					i, single_dpm_table->dpm_levels[i].value,
  					(clocks.num_levels == 1) ? "*" :
  					(aldebaran_freqs_in_same_level(
  								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
  		break;
 
  	case SMU_VCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_VCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_VCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current vclk Failed!");
  			return ret;
@@ -892,16 +890,16 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		}
 
  		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
  					i, single_dpm_table->dpm_levels[i].value,
  					(clocks.num_levels == 1) ? "*" :
  					(aldebaran_freqs_in_same_level(
  								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
  		break;
 
  	case SMU_DCLK:
-		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_DCLK, &now);
+		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_DCLK, &cur_value);
  		if (ret) {
  			dev_err(smu->adev->dev, "Attempt to get current dclk Failed!");
  			return ret;
@@ -915,19 +913,20 @@ static int aldebaran_print_clk_levels(struct smu_context *smu,
  		}
 
  		for (i = 0; i < single_dpm_table->count; i++)
-			size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n",
+			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
  					i, single_dpm_table->dpm_levels[i].value,
  					(clocks.num_levels == 1) ? "*" :
  					(aldebaran_freqs_in_same_level(
  								       clocks.data[i].clocks_in_khz / 1000,
-								       now) ? "*" : ""));
+								       cur_value) ? "*" : ""));
  		break;
 
  	default:
+		return -EINVAL;
  		break;
  	}
 
-	return size;
+	return 0;
  }
 
  static int aldebaran_upload_dpm_level(struct smu_context *smu,
@@ -2079,7 +2078,7 @@ static const struct pptable_funcs aldebaran_ppt_funcs = {
  	.set_default_dpm_table = aldebaran_set_default_dpm_table,
  	.populate_umd_state_clk = aldebaran_populate_umd_state_clk,
  	.get_thermal_temperature_range = aldebaran_get_thermal_temperature_range,
-	.print_clk_levels = aldebaran_print_clk_levels,
+	.emit_clk_levels = aldebaran_emit_clk_levels,
  	.force_clk_levels = aldebaran_force_clk_levels,
  	.read_sensor = aldebaran_read_sensor,
  	.set_performance_level = aldebaran_set_performance_level,
#9 lore raw

PATCH 6/8 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1

In reply to Darren Powell

Use variables to remove the multiple nested ternary expressions and improve readability. This will help to optimize the code duplication in the switch statement
Also Changed:
Modify function aldebaran_get_clk_table to void function as it
always returns 0
Use const string "attempt_string" to cut down on repetition

---
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 125 ++++++++----------
 1 file changed, 57 insertions(+), 68 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +57 -68
index f93a50217239..75833bc3d4c4 100644
@@ -551,9 +551,9 @@ static int aldebaran_populate_umd_state_clk(struct smu_context *smu)
 	return 0;
 }
 
-static int aldebaran_get_clk_table(struct smu_context *smu,
-				   struct pp_clock_levels_with_latency *clocks,
-				   struct smu_13_0_dpm_table *dpm_table)
+static void aldebaran_get_clk_table(struct smu_context *smu,
+				    struct pp_clock_levels_with_latency *clocks,
+				    struct smu_13_0_dpm_table *dpm_table)
 {
 	uint32_t i;
 
@@ -567,7 +567,6 @@ static int aldebaran_get_clk_table(struct smu_context *smu,
 		clocks->data[i].latency_in_us = 0;
 	}
 
-	return 0;
 }
 
 static int aldebaran_freqs_in_same_level(int32_t frequency1,
@@ -749,6 +748,9 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 	int display_levels;
 	uint32_t freq_values[3] = {0};
 	uint32_t min_clk, max_clk, cur_value = 0;
+	bool freq_match;
+	unsigned int clock_mhz;
+	static const char attempt_string[] = "Attempt to get current";
 
 	if (amdgpu_ras_intr_triggered()) {
 		*offset += sysfs_emit_at(buf, *offset, "unavailable\n");
@@ -765,16 +767,12 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 	case SMU_SCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_GFXCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current gfx clk Failed!");
+			dev_err(smu->adev->dev, "%s gfx clk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.gfx_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get gfx clk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
 
 		display_levels = (clocks.num_levels == 1) ? 1 : 2;
 
@@ -791,15 +789,16 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 			freq_values[1] = cur_value;
 		}
 
-		for (i = 0; i < display_levels; i++)
+		for (i = 0; i < display_levels; i++) {
+			clock_mhz = freq_values[i];
+			freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
+
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n", i,
-				freq_values[i],
+				clock_mhz,
 				(display_levels == 1) ?
 					"*" :
-					(aldebaran_freqs_in_same_level(
-						 freq_values[i], cur_value) ?
-						 "*" :
-						 ""));
+					(freq_match) ? "*" : "");
+		}
 
 		break;
 
@@ -809,116 +808,106 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 	case SMU_MCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_UCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current mclk Failed!");
+			dev_err(smu->adev->dev, "%s mclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get memory clk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
+
+		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);
 
-		for (i = 0; i < clocks.num_levels; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
-					i, clocks.data[i].clocks_in_khz / 1000,
+					i, clock_mhz,
 					(clocks.num_levels == 1) ? "*" :
-					(aldebaran_freqs_in_same_level(
-								       clocks.data[i].clocks_in_khz / 1000,
-								       cur_value) ? "*" : ""));
+					(freq_match) ? "*" : "");
+		}
 		break;
 
 	case SMU_SOCCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_SOCCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current socclk Failed!");
+			dev_err(smu->adev->dev, "%s socclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get socclk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
+
+		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);
 
-		for (i = 0; i < clocks.num_levels; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
-					i, clocks.data[i].clocks_in_khz / 1000,
+					i, clock_mhz,
 					(clocks.num_levels == 1) ? "*" :
-					(aldebaran_freqs_in_same_level(
-								       clocks.data[i].clocks_in_khz / 1000,
-								       cur_value) ? "*" : ""));
+					(freq_match) ? "*" : "");
+		}
 		break;
 
 	case SMU_FCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_FCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current fclk Failed!");
+			dev_err(smu->adev->dev, "%s fclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.fclk_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get fclk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
-					(aldebaran_freqs_in_same_level(
-								       clocks.data[i].clocks_in_khz / 1000,
-								       cur_value) ? "*" : ""));
+					(freq_match) ? "*" : "");
+		}
 		break;
 
 	case SMU_VCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_VCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current vclk Failed!");
+			dev_err(smu->adev->dev, "%s vclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.vclk_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get vclk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
-					(aldebaran_freqs_in_same_level(
-								       clocks.data[i].clocks_in_khz / 1000,
-								       cur_value) ? "*" : ""));
+					(freq_match) ? "*" : "");
+		}
 		break;
 
 	case SMU_DCLK:
 		ret = aldebaran_get_current_clk_freq_by_table(smu, SMU_DCLK, &cur_value);
 		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get current dclk Failed!");
+			dev_err(smu->adev->dev, "%s dclk Failed!", attempt_string);
 			return ret;
 		}
 
 		single_dpm_table = &(dpm_context->dpm_tables.dclk_table);
-		ret = aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-		if (ret) {
-			dev_err(smu->adev->dev, "Attempt to get dclk levels Failed!");
-			return ret;
-		}
+		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
+
+		for (i = 0; i < single_dpm_table->count; i++) {
+			clock_mhz = clocks.data[i].clocks_in_khz / 1000;
+			freq_match = aldebaran_freqs_in_same_level(clock_mhz, cur_value);
 
-		for (i = 0; i < single_dpm_table->count; i++)
 			*offset += sysfs_emit_at(buf, *offset, "%d: %uMhz %s\n",
 					i, single_dpm_table->dpm_levels[i].value,
 					(clocks.num_levels == 1) ? "*" :
-					(aldebaran_freqs_in_same_level(
-								       clocks.data[i].clocks_in_khz / 1000,
-								       cur_value) ? "*" : ""));
+					(freq_match) ? "*" : "");
+		}
 		break;
 
 	default:
Signature · 1 line
2.34.1
#10 lore raw

PATCH 7/8 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2

In reply to Darren Powell

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

---
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 27 +++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +13 -14
index 75833bc3d4c4..b315353adfdf 100644
@@ -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;
Signature · 1 line
2.34.1
#11 lore raw

PATCH 8/8 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

In reply to Darren Powell

split switch statement into two and consolidate the common code for printing most of the types of clock speeds

---
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 82 ++++++-------------
 1 file changed, 27 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +27 -55
index b315353adfdf..9d37800bfae9 100644
@@ -788,17 +788,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 			freq_values[2] = max_clk;
 			freq_values[1] = cur_value;
 		}
-
-		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,
-				(freq_match) ? "*" : "");
-		}
-
 		break;
 
 	case SMU_OD_MCLK:
@@ -813,16 +802,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 
 		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
 		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-
-		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,
-					(freq_match) ? "*" : "");
-		}
 		break;
 
 	case SMU_SOCCLK:
@@ -834,16 +813,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 
 		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
 		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-
-		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,
-					(freq_match) ? "*" : "");
-		}
 		break;
 
 	case SMU_FCLK:
@@ -855,16 +824,6 @@ 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 < 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,
-					(freq_match) ? "*" : "");
-		}
 		break;
 
 	case SMU_VCLK:
@@ -876,16 +835,6 @@ 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 < 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,
-					(freq_match) ? "*" : "");
-		}
 		break;
 
 	case SMU_DCLK:
@@ -897,21 +846,44 @@ 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);
+		break;
+
+	default:
+		return -EINVAL;
+	}
 
+	switch (type) {
+	case SMU_OD_SCLK:
+	case SMU_SCLK:
+		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,
+				(freq_match) ? "*" : "");
+		}
+		break;
+
+	case SMU_OD_MCLK:
+	case SMU_MCLK:
+	case SMU_SOCCLK:
+	case SMU_FCLK:
+	case SMU_VCLK:
+	case SMU_DCLK:
 		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,
-					(freq_match) ? "*" : "");
+				i, clock_mhz,
+				(freq_match) ? "*" : "");
 		}
 		break;
-
 	default:
 		return -EINVAL;
-		break;
 	}
 
 	return 0;
Signature · 1 line
2.34.1
#12 lore raw

Re: [PATCH 8/8] amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

Quoted 112 lines · Darren Powell

split switch statement into two and consolidate the common code for printing most of the types of clock speeds

---
  .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 82 ++++++-------------
  1 file changed, 27 insertions(+), 55 deletions(-)
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +9 -51
index b315353adfdf..9d37800bfae9 100644
@@ -788,17 +788,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
  			freq_values[2] = max_clk;
  			freq_values[1] = cur_value;
  		}
-
-		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,
-				(freq_match) ? "*" : "");
-		}
-
  		break;
 
  	case SMU_OD_MCLK:
@@ -813,16 +802,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 
  		single_dpm_table = &(dpm_context->dpm_tables.uclk_table);
  		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-
-		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,
-					(freq_match) ? "*" : "");
-		}
  		break;
 
  	case SMU_SOCCLK:
@@ -834,16 +813,6 @@ static int aldebaran_emit_clk_levels(struct smu_context *smu,
 
  		single_dpm_table = &(dpm_context->dpm_tables.soc_table);
  		aldebaran_get_clk_table(smu, &clocks, single_dpm_table);
-
-		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,
-					(freq_match) ? "*" : "");
-		}
  		break;
 
  	case SMU_FCLK:
@@ -855,16 +824,6 @@ 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 < 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,
-					(freq_match) ? "*" : "");
-		}
  		break;
 
  	case SMU_VCLK:
@@ -876,16 +835,6 @@ 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 < 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,
-					(freq_match) ? "*" : "");
-		}
  		break;
 
  	case SMU_DCLK:
@@ -897,21 +846,44 @@ 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);
+		break;
+
+	default:
+		return -EINVAL;
+	}
 
+	switch (type) {
+	case SMU_OD_SCLK:
+	case SMU_SCLK:
+		for (i = 0; i < display_levels; i++) {

drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c static int aldebaran_emit_clk_levels(struct smu_context *smu, · line 868

Quoted 10 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +10 -0
+			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,
+				(freq_match) ? "*" : "");
+		}
+		break;
+

Similar nits as in arcturus patches. Keep this as part of original switch and below ones as some inline func or goto.

Thanks,
Lijo

Quoted 25 lines
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +8 -4
+	case SMU_OD_MCLK:
+	case SMU_MCLK:
+	case SMU_SOCCLK:
+	case SMU_FCLK:
+	case SMU_VCLK:
+	case SMU_DCLK:
  		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,
-					(freq_match) ? "*" : "");
+				i, clock_mhz,
+				(freq_match) ? "*" : "");
  		}
  		break;
-
  	default:
  		return -EINVAL;
-		break;
  	}
 
  	return 0;
#13 lore raw

Re: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

In reply to Darren Powell

Hi all,
Just looking for anyone who could RB or ACK this patch set so I can submit it?
Thanks
Darren
________________________________
From: Powell, Darren <[email protected]>
Sent: Thursday, April 27, 2023 2:27 AM
To: [email protected] <[email protected]>
Cc: Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; Yu, Lang <[email protected]>; Huang, Ray <[email protected]>; [email protected] <[email protected]>; Powell, Darren <[email protected]>
Subject: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

== Description ==
Scnprintf use within the kernel is not recommended, but simple sysfs_emit replacement has not been successful due to the page alignment requirement of the function. This patch set implements a new api "emit_clock_levels" to facilitate passing both the base and offset to the device rather than just the write pointer.

This patch set replaces print_clock_levels for arcturus and aldebaran platforms with emit_clock_levels, and also optimizes the code to reduce the code duplication for each different clock. This was spread into three parts to show more clearly the changes made to the code, followed by combining the common code into a second switch statement. It is similar to previous work on vega10 to implement emit_clk_levels
commit a63e6b83 ("amdgpu/pm: Implement emit_clk_levels for vega10")
with the addition of the optimization to reduce code duplication.

== Patch Summary ==
linux: ([email protected]:agd5f) origin/amd-staging-drm-next @ 2d8c6b82e241
+ 9a269da4c047 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for arcturus
+ 51ce0fcc9599 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1
+ dcaa5b7551dd amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2
+ 1d16d820e4ee amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3
+ b374fbf6013d amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran
+ 2ecf48d3e83c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1
+ fd8c21e1d1e4 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2
+ a67ce808f18c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

== System Summary ==
* DESKTOP(AMD Ryzen9 7900 + NAVI10(731f/ca), BIOS: 1.11)
+ ISO(Ubuntu 22.04.2 LTS)
+ Kernel(6.1.11-20230412-fdoagd5f-g2d8c6b82e241)

== 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}

lspci -nn | grep "VGA\|Display" > $LOGFILE
printf 'OD enabled = %X\n' "$(( cat /sys/module/amdgpu/parameters/ppfeaturemask & 0x4000 ))" >> $LOGFILE FILES="pp_od_clk_voltage
pp_dpm_sclk
pp_dpm_mclk
pp_dpm_pcie
pp_dpm_socclk
pp_dpm_fclk
pp_dpm_dcefclk
pp_dpm_vclk
pp_dpm_dclk "

for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE

Darren Powell (8):
amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
arcturus
amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
aldebaran
amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 166 ++++++----------
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 181 +++++++-----------
 2 files changed, 132 insertions(+), 215 deletions(-)

base-commit: 2d8c6b82e241f2d1a802ae6bbc24c127e689c724 --
2.34.1

Reviewed-by Evan Quan [email protected]
#14 lore raw

RE: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

[AMD Official Use Only - General]

The series looks good to me.

However better to split the changes of patch1 into two separate patches on your submission. Replace print_clock_levels with emit_clock_levels for arcturus
* replace .print_clk_levels with .emit_clk_levels in arcturus_ppt_funcs
* added extra parameter int *offset
* removed var size, uses arg *offset instead
* removed call to smu_cmn_get_sysfs_buf
* errors are returned to caller
* returns 0 on success
Those changes are included in one patch.
additional incidental changes
* changed type of var i, now to remove comparing mismatch types
* renamed var s/now/cur_value/
* switch statement default now returns -EINVAL
* RAS Recovery returns -EBUSY
While those are included in another patch.

Same applied to patch5.

BR,
Evan
From: Powell, Darren <[email protected]>
Sent: Friday, July 28, 2023 3:51 AM
To: [email protected]
Cc: Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; Yu, Lang <[email protected]>; Huang, Ray <[email protected]>
Subject: Re: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

Hi all,
Just looking for anyone who could RB or ACK this patch set so I can submit it?
Thanks
Darren
________________________________
From: Powell, Darren <[email protected]<mailto:[email protected]>>
Sent: Thursday, April 27, 2023 2:27 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Lazar, Lijo <[email protected]<mailto:[email protected]>>; Quan, Evan <[email protected]<mailto:[email protected]>>; Yu, Lang <[email protected]<mailto:[email protected]>>; Huang, Ray <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; Powell, Darren <[email protected]<mailto:[email protected]>>
Subject: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

== Description ==
Scnprintf use within the kernel is not recommended, but simple sysfs_emit replacement has not been successful due to the page alignment requirement of the function. This patch set implements a new api "emit_clock_levels" to facilitate passing both the base and offset to the device rather than just the write pointer.

This patch set replaces print_clock_levels for arcturus and aldebaran platforms with emit_clock_levels, and also optimizes the code to reduce the code duplication for each different clock. This was spread into three parts to show more clearly the changes made to the code, followed by combining the common code into a second switch statement. It is similar to previous work on vega10 to implement emit_clk_levels
commit a63e6b83 ("amdgpu/pm: Implement emit_clk_levels for vega10")
with the addition of the optimization to reduce code duplication.

== Patch Summary ==
linux: ([email protected]:agd5f<mailto:[email protected]:agd5f>) origin/amd-staging-drm-next @ 2d8c6b82e241
+ 9a269da4c047 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for arcturus
+ 51ce0fcc9599 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1
+ dcaa5b7551dd amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2
+ 1d16d820e4ee amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3
+ b374fbf6013d amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran
+ 2ecf48d3e83c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1
+ fd8c21e1d1e4 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2
+ a67ce808f18c amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

== System Summary ==
* DESKTOP(AMD Ryzen9 7900 + NAVI10(731f/ca), BIOS: 1.11)
+ ISO(Ubuntu 22.04.2 LTS)
+ Kernel(6.1.11-20230412-fdoagd5f-g2d8c6b82e241)

== 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}

lspci -nn | grep "VGA\|Display" > $LOGFILE
printf 'OD enabled = %X\n' "$(( cat /sys/module/amdgpu/parameters/ppfeaturemask & 0x4000 ))" >> $LOGFILE FILES="pp_od_clk_voltage
pp_dpm_sclk
pp_dpm_mclk
pp_dpm_pcie
pp_dpm_socclk
pp_dpm_fclk
pp_dpm_dcefclk
pp_dpm_vclk
pp_dpm_dclk "

for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE

Darren Powell (8):
amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
arcturus
amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for
aldebaran
amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

 .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 166 ++++++----------
 .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 181 +++++++-----------
 2 files changed, 132 insertions(+), 215 deletions(-)

base-commit: 2d8c6b82e241f2d1a802ae6bbc24c127e689c724 --
2.34.1

Reviewed-by
#15 lore raw

Re: [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

In reply to Powell, Darren
Quoted 3 lines · Darren

Hi all,
  Just looking for anyone who could RB or ACK this patch set so I can
submit it?

Apart from a few nits mentioned, the series looks good to me.

Thanks,
Lijo

Quoted 95 lines

Thanks
Darren
------------------------------------------------------------------------
*From:* Powell, Darren <[email protected]>
*Sent:* Thursday, April 27, 2023 2:27 AM
*To:* [email protected] <[email protected]>
*Cc:* Lazar, Lijo <[email protected]>; Quan, Evan <[email protected]>; Yu, Lang <[email protected]>; Huang, Ray <[email protected]>; [email protected] <[email protected]>; Powell, Darren <[email protected]> *Subject:* [PATCH 0/8] amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

amdgpu/pm: Implement emit_clock_levels for arcturus,aldebaran

== Description ==
Scnprintf use within the kernel is not recommended, but simple sysfs_emit replacement has not been successful due to the page alignment requirement of the function. This patch set implements a new api "emit_clock_levels" to facilitate passing both the base and offset to the device rather than just the write pointer.

This patch set replaces print_clock_levels for arcturus and aldebaran platforms with emit_clock_levels, and also optimizes the code to reduce the code duplication for each different clock. This was spread into three parts to show more clearly the changes made to the code, followed by combining the common code into a second switch statement. It is similar to previous work on vega10 to implement emit_clk_levels
 commit a63e6b83 ("amdgpu/pm: Implement emit_clk_levels for vega10")
with the addition of the optimization to reduce code duplication.

== Patch Summary ==
   linux: ([email protected]:agd5f)
origin/amd-staging-drm-next @ 2d8c6b82e241
    + 9a269da4c047 amdgpu/pm: Replace print_clock_levels with
emit_clock_levels for arcturus
    + 51ce0fcc9599 amdgpu/pm: Optimize emit_clock_levels for arcturus -
part 1
    + dcaa5b7551dd amdgpu/pm: Optimize emit_clock_levels for arcturus -
part 2
    + 1d16d820e4ee amdgpu/pm: Optimize emit_clock_levels for arcturus -
part 3
    + b374fbf6013d amdgpu/pm: Replace print_clock_levels with
emit_clock_levels for aldebaran
    + 2ecf48d3e83c amdgpu/pm: Optimize emit_clock_levels for aldebaran
- part 1
    + fd8c21e1d1e4 amdgpu/pm: Optimize emit_clock_levels for aldebaran
- part 2
    + a67ce808f18c amdgpu/pm: Optimize emit_clock_levels for aldebaran
- part 3

== System Summary ==
 * DESKTOP(AMD Ryzen9 7900 + NAVI10(731f/ca), BIOS: 1.11)
  + ISO(Ubuntu 22.04.2 LTS)
  + Kernel(6.1.11-20230412-fdoagd5f-g2d8c6b82e241)

== 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}

lspci -nn | grep "VGA\|Display"  > $LOGFILE
printf 'OD enabled = %X\n' "$(( cat /sys/module/amdgpu/parameters/ppfeaturemask & 0x4000 ))" >> $LOGFILE FILES="pp_od_clk_voltage
pp_dpm_sclk
pp_dpm_mclk
pp_dpm_pcie
pp_dpm_socclk
pp_dpm_fclk
pp_dpm_dcefclk
pp_dpm_vclk
pp_dpm_dclk "

for f in $FILES
do
  echo === $f === >> $LOGFILE
  cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE

Darren Powell (8):
  amdgpu/pm: Replace print_clock_levels with emit_clock_levels for arcturus
  amdgpu/pm: Optimize emit_clock_levels for arcturus - part 1 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 2 amdgpu/pm: Optimize emit_clock_levels for arcturus - part 3 amdgpu/pm: Replace print_clock_levels with emit_clock_levels for aldebaran
  amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 1 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 2 amdgpu/pm: Optimize emit_clock_levels for aldebaran - part 3

  .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 166 ++++++----------
  .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c    | 181 +++++++-----------
  2 files changed, 132 insertions(+), 215 deletions(-)

base-commit: 2d8c6b82e241f2d1a802ae6bbc24c127e689c724

Signature · 1 line
2.34.1