Browse Source

Bugfix: bitforce: Use common code for end of job_get_results, so queue results don't short-circuit timing code

Luke Dashjr 13 years ago
parent
commit
74c96b4f1b
1 changed files with 11 additions and 10 deletions
  1. 11 10
      driver-bitforce.c

+ 11 - 10
driver-bitforce.c

@@ -653,6 +653,7 @@ void bitforce_job_get_results(struct thr_info *thr, struct work *work)
 	struct timeval now;
 	char *pdevbuf = &data->noncebuf[0];
 	bool stale;
+	int count;
 
 	gettimeofday(&now, NULL);
 	timersub(&now, &bitforce->work_start_tv, &elapsed);
@@ -680,7 +681,6 @@ void bitforce_job_get_results(struct thr_info *thr, struct work *work)
 
 	while (1) {
 		const char *cmd = (data->proto == BFP_QUEUE) ? "ZOX" : "ZFX";
-		int count;
 		mutex_lock(mutexp);
 		bitforce_cmd1(fdDev, bitforce->proc_id, pdevbuf, sizeof(data->noncebuf), cmd);
 		if (!strncasecmp(pdevbuf, "COUNT:", 6))
@@ -731,12 +731,6 @@ void bitforce_job_get_results(struct thr_info *thr, struct work *work)
 			goto out;
 		}
 
-		if (count > 0)
-		{
-			applog(LOG_DEBUG, "%"PRIpreprv": waited %dms until %s", bitforce->proc_repr, bitforce->wait_ms, pdevbuf);
-			goto out;
-		}
-
 		if (pdevbuf[0] && strncasecmp(pdevbuf, "B", 1)) /* BFL does not respond during throttling */
 			break;
 
@@ -755,6 +749,13 @@ noqr:
 		return;
 	}
 
+	if (count < 0 && pdevbuf[0] == 'N')
+		count = strncasecmp(pdevbuf, "NONCE-FOUND", 11) ? 1 : 0;
+	// At this point, 'count' is:
+	//   negative, in case of some kind of error
+	//   zero, if NO-NONCE (FPGA either completed with no results, or rebooted)
+	//   positive, if at least one job completed successfully
+
 	if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
 		applog(LOG_ERR, "%"PRIpreprv": took %lums - longer than %lums", bitforce->proc_repr,
 			tv_to_ms(elapsed), (unsigned long)BITFORCE_TIMEOUT_MS);
@@ -766,9 +767,9 @@ noqr:
 		 * are no results. But check first, just in case we're wrong about it
 		 * throttling.
 		 */
-		if (strncasecmp(pdevbuf, "NONCE-FOUND", 11))
+		if (count > 0)
 			goto out;
-	} else if (!strncasecmp(pdevbuf, "N", 1)) {/* Hashing complete (NONCE-FOUND or NO-NONCE) */
+	} else if (count >= 0) {/* Hashing complete (NONCE-FOUND or NO-NONCE) */
 		/* Simple timing adjustment. Allow a few polls to cope with
 		 * OS timer delays being variably reliable. wait_ms will
 		 * always equal sleep_ms when we've waited greater than or
@@ -793,7 +794,7 @@ noqr:
 	}
 
 	applog(LOG_DEBUG, "%"PRIpreprv": waited %dms until %s", bitforce->proc_repr, bitforce->wait_ms, pdevbuf);
-	if (strncasecmp(pdevbuf, "NONCE-FOUND", 11) && (pdevbuf[2] != '-') && strncasecmp(pdevbuf, "I", 1)) {
+	if (count < 0 && strncasecmp(pdevbuf, "I", 1)) {
 		bitforce->hw_errors++;
 		++hw_errors;
 		applog(LOG_WARNING, "%"PRIpreprv": Error: Get result reports: %s", bitforce->proc_repr, pdevbuf);