Commit dff1a81da71f5845e3bc59c4d283fbc04d16f734

Con Kolivas 2011-09-11T11:25:28

Use a re-entrant value to store what fanspeed we're trying to set in case the card doesn't support small changes. Force it to a multiple of 10% if it fails on trying to speed up the fan.

diff --git a/adl.c b/adl.c
index 9a73fd2..e3f6187 100644
--- a/adl.c
+++ b/adl.c
@@ -797,6 +797,9 @@ static int set_fanspeed(int gpu, int iFanSpeed)
 	lock_adl();
 	if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
 		goto out;
+	/* Store what fanspeed we're actually aiming for for re-entrant changes
+	 * in case this device does not support fine setting changes */
+	ga->targetfan = iFanSpeed;
 	ga->lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
 	if ((ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE) &&
 		!(ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE)) {
@@ -868,15 +871,15 @@ void gpu_autotune(int gpu, bool *enable)
 			if (opt_debug)
 				applog(LOG_DEBUG, "Temperature over target, increasing fanspeed");
 			if (temp > ga->targettemp + opt_hysteresis)
-				newpercent = fanpercent + 10;
+				newpercent = ga->targetfan + 10;
 			else
-				newpercent = fanpercent + 5;
+				newpercent = ga->targetfan + 5;
 			if (newpercent > top)
 				newpercent = top;
 		} else if (fanpercent > bot && temp < ga->targettemp - opt_hysteresis) {
 			if (opt_debug)
 				applog(LOG_DEBUG, "Temperature %d degrees below target, decreasing fanspeed", opt_hysteresis);
-			newpercent = fanpercent - 1;
+			newpercent = ga->targetfan - 1;
 		}
 
 		if (newpercent > 100)
@@ -887,6 +890,15 @@ void gpu_autotune(int gpu, bool *enable)
 			fan_optimal = false;
 			applog(LOG_INFO, "Setting GPU %d fan percentage to %d", gpu, newpercent);
 			set_fanspeed(gpu, newpercent);
+			if (newpercent > fanpercent) {
+				int changefan = gpu_fanspeed(gpu);
+
+				if (changefan < newpercent) {
+					newpercent += 10;
+					newpercent -= newpercent % 10;
+					set_fanspeed(gpu, newpercent);
+				}
+			}
 		}
 	}
 
diff --git a/miner.h b/miner.h
index 0567139..ce2a6b6 100644
--- a/miner.h
+++ b/miner.h
@@ -179,6 +179,7 @@ struct gpu_adl {
 	bool autoengine;
 	bool managed; /* Were the values ever changed on this card */
 
+	int targetfan;
 	int targettemp;
 	int overtemp;
 	int cutofftemp;