Browse Source

Merge commit 'ccee686' into HEAD

Conflicts:
	driver-ztex.c
Luke Dashjr 13 years ago
parent
commit
b7240984e1
2 changed files with 51 additions and 42 deletions
  1. 45 41
      driver-ztex.c
  2. 6 1
      libztex.c

+ 45 - 41
driver-ztex.c

@@ -145,9 +145,8 @@ static bool ztex_updateFreq(struct thr_info *thr)
 	return rv;
 	return rv;
 }
 }
 
 
-static bool ztex_checkNonce(struct libztex_device *ztex,
-                            struct work *work,
-                            struct libztex_hash_data *hdata)
+
+static uint32_t ztex_checkNonce(struct work *work, uint32_t nonce)
 {
 {
 	uint32_t *data32 = (uint32_t *)(work->data);
 	uint32_t *data32 = (uint32_t *)(work->data);
 	unsigned char swap[80];
 	unsigned char swap[80];
@@ -156,24 +155,14 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
 	unsigned char hash2[32];
 	unsigned char hash2[32];
 	uint32_t *hash2_32 = (uint32_t *)hash2;
 	uint32_t *hash2_32 = (uint32_t *)hash2;
 
 
-	hdata->nonce = le32toh(hdata->nonce);
-	hdata->hash7 = le32toh(hdata->hash7);
-
-	work->data[64 + 12 + 0] = (hdata->nonce >> 0) & 0xff;
-	work->data[64 + 12 + 1] = (hdata->nonce >> 8) & 0xff;
-	work->data[64 + 12 + 2] = (hdata->nonce >> 16) & 0xff;
-	work->data[64 + 12 + 3] = (hdata->nonce >> 24) & 0xff;
+	swap32[76/4] = htonl(nonce);
 
 
-	swap32yes(swap32, data32, 80 / 4);
+	swap32yes(swap32, data32, 76 / 4);
 
 
 	sha2(swap, 80, hash1);
 	sha2(swap, 80, hash1);
 	sha2(hash1, 32, hash2);
 	sha2(hash1, 32, hash2);
-	if (htobe32(hash2_32[7]) != ((hdata->hash7 + 0x5be0cd19) & 0xFFFFFFFF)) {
-		dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
-		applog(LOG_DEBUG, "%s: checkNonce failed for %08x", ztex->repr, hdata->nonce);
-		return false;
-	}
-	return true;
+
+	return htonl(hash2_32[7]);
 }
 }
 
 
 static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
@@ -232,9 +221,11 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	}
 	}
 
 
 	overflow = false;
 	overflow = false;
+	int count = 0;
 
 
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
 	while (!(overflow || thr->work_restart)) {
 	while (!(overflow || thr->work_restart)) {
+		count++;
 		nmsleep(250);
 		nmsleep(250);
 		if (thr->work_restart) {
 		if (thr->work_restart) {
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
@@ -265,10 +256,9 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		}
 		}
 
 
 		dclk_gotNonces(&ztex->dclk);
 		dclk_gotNonces(&ztex->dclk);
- 
+
 		for (i = 0; i < ztex->numNonces; i++) {
 		for (i = 0; i < ztex->numNonces; i++) {
 			nonce = hdata[i].nonce;
 			nonce = hdata[i].nonce;
-			nonce = le32toh(nonce);
 			if (nonce > noncecnt)
 			if (nonce > noncecnt)
 				noncecnt = nonce;
 				noncecnt = nonce;
 			if (((0xffffffff - nonce) < (nonce - lastnonce[i])) || nonce < lastnonce[i]) {
 			if (((0xffffffff - nonce) < (nonce - lastnonce[i])) || nonce < lastnonce[i]) {
@@ -276,33 +266,47 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 				overflow = true;
 				overflow = true;
 			} else
 			} else
 				lastnonce[i] = nonce;
 				lastnonce[i] = nonce;
-			nonce = htole32(nonce);
-			if (!ztex_checkNonce(ztex, work, &hdata[i])) {
-				thr->cgpu->hw_errors++;
-				++hw_errors;
-				continue;
+
+			if (ztex_checkNonce(work, nonce) != (hdata->hash7 + 0x5be0cd19)) {
+				applog(LOG_DEBUG, "%s: checkNonce failed for %08X", ztex->repr, nonce);
+
+				// do not count errors in the first 500ms after sendHashData (2x250 wait time)
+				if (count > 2) {
+					dclk_errorCount(&ztex->dclk, 1.0 / ztex->numNonces);
+					thr->cgpu->hw_errors++;
+					++hw_errors;
+				}
 			}
 			}
+
 			for (j=0; j<=ztex->extraSolutions; j++) {
 			for (j=0; j<=ztex->extraSolutions; j++) {
 				nonce = hdata[i].goldenNonce[j];
 				nonce = hdata[i].goldenNonce[j];
-				if (nonce > 0) {
-					found = false;
-					for (k = 0; k < backlog_max; k++) {
-						if (backlog[k] == nonce) {
-							found = true;
-							break;
-						}
-					}
-					if (!found) {
-						backlog[backlog_p++] = nonce;
-						if (backlog_p >= backlog_max)
-							backlog_p = 0;
-						nonce = le32toh(nonce);
-						work->blk.nonce = 0xffffffff;
-						if (test_nonce(work, nonce, false))
-							submit_nonce(thr, work, nonce);
-						applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
+
+				if (nonce == ztex->offsNonces) {
+					continue;
+				}
+
+				// precheck the extraSolutions since they often fail
+				if (j > 0 && ztex_checkNonce(work, nonce) != 0) {
+					continue;
+				}
+
+				found = false;
+				for (k = 0; k < backlog_max; k++) {
+					if (backlog[k] == nonce) {
+						found = true;
+						break;
 					}
 					}
 				}
 				}
+				if (!found) {
+					backlog[backlog_p++] = nonce;
+
+					if (backlog_p >= backlog_max)
+						backlog_p = 0;
+
+					work->blk.nonce = 0xffffffff;
+					submit_nonce(thr, work, nonce);
+					applog(LOG_DEBUG, "%s: submitted %08x (from N%dE%d)", ztex->repr, nonce, i, j);
+				}
 			}
 			}
 		}
 		}
 	}
 	}

+ 6 - 1
libztex.c

@@ -883,11 +883,16 @@ int libztex_readHashData(struct libztex_device *ztex, struct libztex_hash_data n
 		//applog(LOG_DEBUG, "W %d:0 %0.8x", i, nonces[i].goldenNonce[0]);
 		//applog(LOG_DEBUG, "W %d:0 %0.8x", i, nonces[i].goldenNonce[0]);
 
 
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
 		memcpy((char*)&nonces[i].nonce, &rbuf[(i*bufsize)+4], 4);
-		nonces[i].nonce -= ztex->offsNonces;
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
 		memcpy((char*)&nonces[i].hash7, &rbuf[(i*bufsize)+8], 4);
 
 
+		nonces[i].nonce = htole32(nonces[i].nonce);
+		nonces[i].hash7 = htole32(nonces[i].hash7);
+
+		nonces[i].nonce -= ztex->offsNonces;
+
 		for (j=0; j<ztex->extraSolutions; j++) {
 		for (j=0; j<ztex->extraSolutions; j++) {
 			memcpy((char*)&nonces[i].goldenNonce[j+1], &rbuf[(i*bufsize)+12+(j*4)], 4);
 			memcpy((char*)&nonces[i].goldenNonce[j+1], &rbuf[(i*bufsize)+12+(j*4)], 4);
+			nonces[i].goldenNonce[j+1] = htole32(nonces[i].goldenNonce[j+1]);
 			nonces[i].goldenNonce[j+1] -= ztex->offsNonces;
 			nonces[i].goldenNonce[j+1] -= ztex->offsNonces;
 			//applog(LOG_DEBUG, "W %d:%d %0.8x", i, j+1, nonces[i].goldenNonce[j+1]);
 			//applog(LOG_DEBUG, "W %d:%d %0.8x", i, j+1, nonces[i].goldenNonce[j+1]);
 		}
 		}