Commit 49a7d9184f6890295ef974356bcd8e25bf65ae81

Con Kolivas 2014-02-13T20:55:20

Store the cointerra maximum temperature in the cgpu struct as an exponentially changing value based on the maximum temperature.

diff --git a/driver-cointerra.c b/driver-cointerra.c
index 27993d8..9d49760 100644
--- a/driver-cointerra.c
+++ b/driver-cointerra.c
@@ -435,8 +435,12 @@ static void u16array_from_msg(uint16_t *u16, int entries, int var, char *buf)
 		u16[i] = hu16_from_msg(buf, var + j);
 }
 
-static void cta_parse_statread(struct cointerra_info *info, char *buf)
+static void cta_parse_statread(struct cgpu_info *cointerra, struct cointerra_info *info,
+			       char *buf)
 {
+	float max_temp = 0;
+	int i;
+
 	mutex_lock(&info->lock);
 	u16array_from_msg(info->coretemp, CTA_CORES, CTA_STAT_CORETEMPS, buf);
 	info->ambtemp_low = hu16_from_msg(buf, CTA_STAT_AMBTEMP_LOW);
@@ -450,6 +454,15 @@ static void cta_parse_statread(struct cointerra_info *info, char *buf)
 	info->inactive = hu16_from_msg(buf, CTA_STAT_INACTIVE);
 	info->active = hu16_from_msg(buf, CTA_STAT_ACTIVE);
 	mutex_unlock(&info->lock);
+
+	for (i = 0; i < CTA_CORES; i++) {
+		if (info->coretemp[i] > max_temp)
+			max_temp = info->coretemp[i];
+	}
+	max_temp /= 100.0;
+	/* Store the max temperature in the cgpu struct as an exponentially
+	 * changing value. */
+	cointerra->temp = cointerra->temp * 0.63 + max_temp * 0.37;
 }
 
 static void u8array_from_msg(uint8_t *u8, int entries, int var, char *buf)
@@ -561,7 +574,7 @@ static void cta_parse_msg(struct thr_info *thr, struct cgpu_info *cointerra,
 		case CTA_RECV_STATREAD:
 			applog(LOG_DEBUG, "%s %d: Status readings message received",
 			       cointerra->drv->name, cointerra->device_id);
-			cta_parse_statread(info, buf);
+			cta_parse_statread(cointerra, info, buf);
 			break;
 		case CTA_RECV_STATSET:
 			applog(LOG_DEBUG, "%s %d: Status settings message received",
@@ -1074,21 +1087,18 @@ static struct api_data *cta_api_stats(struct cgpu_info *cgpu)
 static void cta_statline_before(char *buf, size_t bufsiz, struct cgpu_info *cointerra)
 {
 	struct cointerra_info *info = cointerra->device_data;
-	double max_temp = 0, max_volt = 0;
+	double max_volt = 0;
 	int freq = 0, i;
 
 	for (i = 0; i < CTA_CORES; i++) {
-		if (info->coretemp[i] > max_temp)
-			max_temp = info->coretemp[i];
 		if (info->corevolts[i] > max_volt)
 			max_volt = info->corevolts[i];
 		if (info->corefreqs[i] > freq)
 			freq = info->corefreqs[i];
 	}
-	max_temp /= 100;
 	max_volt /= 100;
 
-	tailsprintf(buf, bufsiz, "%3d %3.1fC %2.1fV | ", freq, max_temp, max_volt);
+	tailsprintf(buf, bufsiz, "%3d %3.1fC %2.1fV | ", freq, cointerra->temp, max_volt);
 }
 
 struct device_drv cointerra_drv = {