Simple auto sleep-time calibration. Optimises the sleep time while waiting for the BFL work to finish. Takes ~5 mins to settle to the correct time for each unit, then will continue to make adjustments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 0a2fc82..9b76fd4 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -20,13 +20,10 @@
#include "fpgautils.h"
#include "miner.h"
-/* @832MH/s wait time is ~4500ms
- @864MH/s wait time is ~4430ms
--> @896MH/s wait time will be ~4350ms */
-#define BITFORCE_SLEEP_MS 4300
+#define BITFORCE_SLEEP_MS 2000
#define BITFORCE_TIMEOUT_MS 15000
#define BITFORCE_CHECK_INTERVAL_MS 10
-#define WORK_CHECK_INTERVAL_MS 100
+#define WORK_CHECK_INTERVAL_MS 50
struct device_api bitforce_api;
@@ -84,6 +81,7 @@ static bool bitforce_detect_one(const char *devpath)
bitforce->device_path = strdup(devpath);
bitforce->deven = DEV_ENABLED;
bitforce->threads = 1;
+ bitforce->sleep_ms = BITFORCE_SLEEP_MS;
if (likely((!memcmp(pdevbuf, ">>>ID: ", 7)) && (s = strstr(pdevbuf + 3, ">>>"))))
{
s[0] = '\0';
@@ -273,9 +271,8 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
char pdevbuf[0x100];
char *pnoncebuf;
uint32_t nonce;
- unsigned int wait_ms = BITFORCE_SLEEP_MS;
- while (wait_ms < BITFORCE_TIMEOUT_MS) {
+ while (bitforce->wait_ms < BITFORCE_TIMEOUT_MS) {
mutex_lock(&bitforce->device_mutex);
BFwrite(fdDev, "ZFX", 3);
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
@@ -288,17 +285,24 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (pdevbuf[0] != 'B')
break;
usleep(BITFORCE_CHECK_INTERVAL_MS*1000);
- wait_ms += BITFORCE_CHECK_INTERVAL_MS;
+ bitforce->wait_ms += BITFORCE_CHECK_INTERVAL_MS;
}
- if (wait_ms >= BITFORCE_TIMEOUT_MS) {
+ if (bitforce->wait_ms >= BITFORCE_TIMEOUT_MS) {
applog(LOG_ERR, "BFL%i took longer than 15s");
bitforce->device_last_not_well = time(NULL);
bitforce->device_not_well_reason = REASON_THREAD_ZERO_HASH;
bitforce->thread_zero_hash_count++;
return 1;
+ } else {
+ /* Simple timing adjustment */
+ // applog(LOG_WARNING, "BFL%i: Waited: %ums, sleep is:%ums", bitforce->device_id, bitforce->wait_ms, bitforce->sleep_ms);
+ if (bitforce->wait_ms > (bitforce->sleep_ms + WORK_CHECK_INTERVAL_MS))
+ bitforce->sleep_ms += WORK_CHECK_INTERVAL_MS;
+ else if (bitforce->wait_ms == bitforce->sleep_ms)
+ bitforce->sleep_ms -= WORK_CHECK_INTERVAL_MS;
}
- applog(LOG_DEBUG, "BFL%i: waited %dms until %s\n", bitforce->device_id, wait_ms, pdevbuf);
+ applog(LOG_DEBUG, "BFL%i: waited %dms until %s", bitforce->device_id, bitforce->wait_ms, pdevbuf);
work->blk.nonce = 0xffffffff;
if (pdevbuf[2] == '-')
return 0xffffffff; /* No valid nonce found */
@@ -344,16 +348,16 @@ static void biforce_thread_enable(struct thr_info *thr)
static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
{
struct cgpu_info *bitforce = thr->cgpu;
- unsigned int wait_ms = 0;
+ bitforce->wait_ms = 0;
if (!bitforce_send_work(thr, work))
return 0;
- while (wait_ms < BITFORCE_SLEEP_MS) {
+ while (bitforce->wait_ms < bitforce->sleep_ms) {
usleep(WORK_CHECK_INTERVAL_MS*1000);
- wait_ms += WORK_CHECK_INTERVAL_MS;
+ 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, wait_ms);
+ 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.
}
}
diff --git a/miner.h b/miner.h
index a71447b..71ece03 100644
--- a/miner.h
+++ b/miner.h
@@ -315,6 +315,10 @@ struct cgpu_info {
#endif
int device_fd;
};
+#ifdef USE_BITFORCE
+ unsigned int wait_ms;
+ unsigned int sleep_ms;
+#endif
pthread_mutex_t device_mutex;
enum dev_enable deven;