[PATCH] drm/amdgpu: Use signed arithmetic for overdrive clock calculations

Donny Yang work at kota.moe
Fri Jan 13 08:52:39 UTC 2017


Signed-off-by: Donny Yang <work at kota.moe>
---
 drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c | 70 +++++++-----------------
 1 file changed, 21 insertions(+), 49 deletions(-)

diff --git a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
index a74f60a5..f6c01e19 100644
--- a/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
+++ b/drivers/gpu/drm/amd/powerplay/hwmgr/smu7_hwmgr.c
@@ -3349,7 +3349,8 @@ static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
 	struct smu7_dpm_table *dpm_table = &data->dpm_table;
 
 	struct smu7_dpm_table *golden_dpm_table = &data->golden_dpm_table;
-	uint32_t dpm_count, clock_percent;
+	uint32_t dpm_count;
+	int32_t clock_percent;
 	uint32_t i;
 
 	if (0 == data->need_update_smu7_dpm_table)
@@ -3371,32 +3372,16 @@ static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
 				return -EINVAL);
 			dpm_count = dpm_table->sclk_table.count < 2 ? 0 : dpm_table->sclk_table.count - 2;
 
+			clock_percent =
+				((sclk
+				- golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
+				) * 100)
+				/ golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
 			for (i = dpm_count; i > 1; i--) {
-				if (sclk > golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value) {
-					clock_percent =
-					      ((sclk
-						- golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value
-						) * 100)
-						/ golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
-
-					dpm_table->sclk_table.dpm_levels[i].value =
-							golden_dpm_table->sclk_table.dpm_levels[i].value +
-							(golden_dpm_table->sclk_table.dpm_levels[i].value *
-								clock_percent)/100;
-
-				} else if (golden_dpm_table->sclk_table.dpm_levels[dpm_table->sclk_table.count-1].value > sclk) {
-					clock_percent =
-						((golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count - 1].value
-						- sclk) * 100)
-						/ golden_dpm_table->sclk_table.dpm_levels[golden_dpm_table->sclk_table.count-1].value;
-
-					dpm_table->sclk_table.dpm_levels[i].value =
-							golden_dpm_table->sclk_table.dpm_levels[i].value -
-							(golden_dpm_table->sclk_table.dpm_levels[i].value *
-									clock_percent) / 100;
-				} else
-					dpm_table->sclk_table.dpm_levels[i].value =
-							golden_dpm_table->sclk_table.dpm_levels[i].value;
+				dpm_table->sclk_table.dpm_levels[i].value =
+						golden_dpm_table->sclk_table.dpm_levels[i].value +
+						(golden_dpm_table->sclk_table.dpm_levels[i].value *
+								clock_percent) / 100;
 			}
 		}
 	}
@@ -3414,30 +3399,17 @@ static int smu7_populate_and_upload_sclk_mclk_dpm_levels(
 					"Divide by 0!",
 					return -EINVAL);
 			dpm_count = dpm_table->mclk_table.count < 2 ? 0 : dpm_table->mclk_table.count - 2;
+
+			clock_percent =
+				((mclk
+				- golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value
+				) * 100)
+				/ golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
 			for (i = dpm_count; i > 1; i--) {
-				if (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value < mclk) {
-					clock_percent = ((mclk -
-					golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value) * 100)
-					/ golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
-
-					dpm_table->mclk_table.dpm_levels[i].value =
-							golden_dpm_table->mclk_table.dpm_levels[i].value +
-							(golden_dpm_table->mclk_table.dpm_levels[i].value *
-							clock_percent) / 100;
-
-				} else if (golden_dpm_table->mclk_table.dpm_levels[dpm_table->mclk_table.count-1].value > mclk) {
-					clock_percent = (
-					 (golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value - mclk)
-					* 100)
-					/ golden_dpm_table->mclk_table.dpm_levels[golden_dpm_table->mclk_table.count-1].value;
-
-					dpm_table->mclk_table.dpm_levels[i].value =
-							golden_dpm_table->mclk_table.dpm_levels[i].value -
-							(golden_dpm_table->mclk_table.dpm_levels[i].value *
-									clock_percent) / 100;
-				} else
-					dpm_table->mclk_table.dpm_levels[i].value =
-							golden_dpm_table->mclk_table.dpm_levels[i].value;
+				dpm_table->mclk_table.dpm_levels[i].value =
+						golden_dpm_table->mclk_table.dpm_levels[i].value +
+						(golden_dpm_table->mclk_table.dpm_levels[i].value *
+						clock_percent) / 100;
 			}
 		}
 	}
-- 
2.11.0



More information about the amd-gfx mailing list