Commit d6f3b6171f8ac83f34a703c87174ad5db6640ba5

Con Kolivas 2014-03-14T15:20:09

Send per-core hashrates at regular ~5min intervals back to cta devices.

diff --git a/driver-cointerra.c b/driver-cointerra.c
index 0fab09d..8a2ef98 100644
--- a/driver-cointerra.c
+++ b/driver-cointerra.c
@@ -11,6 +11,7 @@
 
 #include "miner.h"
 #include "driver-cointerra.h"
+#include <math.h>
 
 static const char *cointerra_hdr = "ZZ";
 
@@ -935,6 +936,31 @@ static void cta_zero_corehashes(struct cointerra_info *info)
 	cgtime(&info->core_hash_start);
 }
 
+/* Send per core hashrate calculations at regular intervals ~every 5 minutes */
+static void cta_send_corehashes(struct cgpu_info *cointerra, struct cointerra_info *info,
+				double corehash_time)
+{
+	uint16_t core_ghs[CTA_CORES];
+	double k[CTA_CORES];
+	char buf[CTA_MSG_SIZE];
+	int i, offset;
+
+	for (i = 0; i < CTA_CORES; i++) {
+		k[i] = (double)info->tot_core_hashes[i] / ((double)32 * (double)0x100000000ull);
+		k[i] = sqrt(k[i]) + 1;
+		k[i] *= k[i];
+		k[i] = k[i] * 32 * ((double)0x100000000ull / (double)1000000000) / corehash_time;
+		core_ghs[i] = k[i];
+	}
+	cta_gen_message(buf, CTA_SEND_COREHASHRATE);
+	offset = CTA_CORE_HASHRATES;
+	for (i = 0; i < CTA_CORES; i++) {
+		msg_from_hu16(buf, offset, core_ghs[i]);
+		offset += 2; // uint16_t
+	}
+	cta_send_msg(cointerra, buf);
+}
+
 static int64_t cta_scanwork(struct thr_info *thr)
 {
 	struct cgpu_info *cointerra = thr->cgpu;
@@ -997,6 +1023,7 @@ static int64_t cta_scanwork(struct thr_info *thr)
 
 	corehash_time = tdiff(&now, &info->core_hash_start);
 	if (corehash_time > 300) {
+		cta_send_corehashes(cointerra, info, corehash_time);
 		cta_zero_corehashes(info);
 	}
 
diff --git a/driver-cointerra.h b/driver-cointerra.h
index 1acdf37..e989cf5 100644
--- a/driver-cointerra.h
+++ b/driver-cointerra.h
@@ -48,6 +48,7 @@
 #define CTA_WORK_NROLL		53
 #define CTA_WORK_DIFFBITS	55
 #define CTA_REQWORK_REQUESTS	3
+#define CTA_CORE_HASHRATES	3
 
 /* Received message types */
 #define CTA_RECV_UNUSED		0
@@ -69,6 +70,7 @@
 #define CTA_SEND_REQUEST	4
 #define CTA_SEND_FMATCH		5
 #define CTA_SEND_IDENTIFY	6
+#define CTA_SEND_COREHASHRATE	7
 
 /* Types of reset in CTA_RESET_TYPE */
 #define CTA_RESET_NONE		0