Commit 0ae3f718248e0f144c20920141e0b8b26152450c

Con Kolivas 2011-09-23T10:45:43

Check last temperature we reached and don't change fan speed if it's already correcting.

diff --git a/adl.c b/adl.c
index 2877448..3f27d99 100644
--- a/adl.c
+++ b/adl.c
@@ -79,6 +79,7 @@ static int iNumberAdapters;
 static LPAdapterInfo lpInfo = NULL;
 
 static int set_fanspeed(int gpu, int iFanSpeed);
+static float __gpu_temp(struct gpu_adl *ga);
 
 static inline void lock_adl(void)
 {
@@ -326,10 +327,11 @@ void init_adl(int nDevs)
 			ga->autoengine = true;
 			ga->managed = true;
 		}
+		ga->lasttemp = __gpu_temp(ga);
 	}
 }
 
-static inline float __gpu_temp(struct gpu_adl *ga)
+static float __gpu_temp(struct gpu_adl *ga)
 {
 	if (ADL_Overdrive5_Temperature_Get(ga->iAdapterIndex, 0, &ga->lpTemperature) != ADL_OK)
 		return -1;
@@ -828,7 +830,7 @@ void gpu_autotune(int gpu, bool *enable)
 		if (temp > ga->overtemp && fanpercent < iMax) {
 			applog(LOG_WARNING, "Overheat detected on GPU %d, increasing fan to 100%", gpu);
 			newpercent = iMax;
-		} else if (temp > ga->targettemp && fanpercent < top) {
+		} else if (temp > ga->targettemp && fanpercent < top && temp >= ga->lasttemp) {
 			if (opt_debug)
 				applog(LOG_DEBUG, "Temperature over target, increasing fanspeed");
 			if (temp > ga->targettemp + opt_hysteresis)
@@ -837,7 +839,7 @@ void gpu_autotune(int gpu, bool *enable)
 				newpercent = ga->targetfan + 5;
 			if (newpercent > top)
 				newpercent = top;
-		} else if (fanpercent > bot && temp < ga->targettemp - opt_hysteresis) {
+		} else if (fanpercent > bot && temp < ga->targettemp - opt_hysteresis && temp <= ga->lasttemp) {
 			if (opt_debug)
 				applog(LOG_DEBUG, "Temperature %d degrees below target, decreasing fanspeed", opt_hysteresis);
 			newpercent = ga->targetfan - 1;
@@ -882,6 +884,7 @@ void gpu_autotune(int gpu, bool *enable)
 			set_engineclock(gpu, newengine);
 		}
 	}
+	ga->lasttemp = temp;
 }
 
 void set_defaultfan(int gpu)
diff --git a/miner.h b/miner.h
index 3c9d376..5fa8331 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 lasttemp;
 	int targetfan;
 	int targettemp;
 	int overtemp;