Commit ad5b470b0461dc61727c35dc64e33765947696f9

Paul Sheppard 2012-07-02T14:27:19

Fine-tune timing adjustment. Also remove old work_restart timing.

diff --git a/driver-bitforce.c b/driver-bitforce.c
index 5328077..d0c99c2 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -316,10 +316,13 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 		return 1;
 	} else if (pdevbuf[0] == 'N') {/* Hashing complete (NONCE-FOUND or NO-NONCE) */
 	    /* Simple timing adjustment */
-		if (bitforce->wait_ms > (bitforce->sleep_ms + WORK_CHECK_INTERVAL_MS))
-			bitforce->sleep_ms += WORK_CHECK_INTERVAL_MS;
+        delay_time_ms = bitforce->sleep_ms;
+		if (bitforce->wait_ms > (bitforce->sleep_ms + BITFORCE_CHECK_INTERVAL_MS))
+			bitforce->sleep_ms += (unsigned int) ((double) (bitforce->wait_ms - bitforce->sleep_ms) / 1.6);
 		else if (bitforce->wait_ms == bitforce->sleep_ms)
-			bitforce->sleep_ms -= WORK_CHECK_INTERVAL_MS;		
+			bitforce->sleep_ms -= BITFORCE_CHECK_INTERVAL_MS;
+        if (delay_time_ms != bitforce->sleep_ms)
+		  applog(LOG_DEBUG, "BFL%i: Wait time changed to: %d. Waited: %d", bitforce->device_id, bitforce->sleep_ms, bitforce->wait_ms);
 	}
 
 	applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf);
@@ -392,16 +395,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 	if (!restart_wait(&tdiff))
 		return 1;
 	bitforce->wait_ms += sleep_time;
-/*
-	while (bitforce->wait_ms < bitforce->sleep_ms) {
-		usleep(WORK_CHECK_INTERVAL_MS*1000);
-		bitforce->wait_ms += WORK_CHECK_INTERVAL_MS;
-		if (work_restart[thr->id].restart) {
-			applog(LOG_DEBUG, "BFL%i: Work restart, discarding after %dms", bitforce->device_id, bitforce->wait_ms);
-			return 1; //we have discarded all work; equivilent to 0 hashes done.
-		}
-	}
-*/
+
 	if (ret)
 		ret = bitforce_get_result(thr, work);