Change timeouts to time-vals for accuracy.
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
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 276ffcf..9231583 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -21,11 +21,14 @@
#include "miner.h"
#define BITFORCE_SLEEP_MS 500
-#define BITFORCE_TIMEOUT_MS 10000
-#define BITFORCE_LONG_TIMEOUT_MS 15000
+#define BITFORCE_TIMEOUT_S 7
+#define BITFORCE_TIMEOUT_MS (BITFORCE_TIMEOUT_S * 1000)
+#define BITFORCE_LONG_TIMEOUT_S 15
+#define BITFORCE_LONG_TIMEOUT_MS (BITFORCE_LONG_TIMEOUT_S * 1000)
#define BITFORCE_CHECK_INTERVAL_MS 10
#define WORK_CHECK_INTERVAL_MS 50
#define MAX_START_DELAY_US 100000
+#define tv_to_ms(tval) (tval.tv_sec * 1000 + tval.tv_usec / 1000)
struct device_api bitforce_api;
@@ -332,6 +335,7 @@ re_send:
return false;
}
+ gettimeofday(&bitforce->work_start_tv, NULL);
return true;
}
@@ -340,6 +344,8 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
struct cgpu_info *bitforce = thr->cgpu;
int fdDev = bitforce->device_fd;
unsigned int delay_time_ms;
+ struct timeval elapsed;
+ struct timeval now;
char pdevbuf[0x100];
char *pnoncebuf;
uint32_t nonce;
@@ -348,7 +354,7 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
if (!fdDev)
return 0;
- while (bitforce->wait_ms < BITFORCE_LONG_TIMEOUT_MS) {
+ while (1) {
if (unlikely(thr->work_restart))
return 1;
@@ -357,6 +363,15 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
mutex_unlock(&bitforce->device_mutex);
+ gettimeofday(&now, NULL);
+ timersub(&now, &bitforce->work_start_tv, &elapsed);
+
+ if (elapsed.tv_sec >= BITFORCE_LONG_TIMEOUT_S) {
+ applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
+ tv_to_ms(elapsed), BITFORCE_LONG_TIMEOUT_MS);
+ return 0;
+ }
+
if (pdevbuf[0] && strncasecmp(pdevbuf, "B", 1)) /* BFL does not respond during throttling */
break;
@@ -366,9 +381,9 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
bitforce->wait_ms += delay_time_ms;
}
- if (bitforce->wait_ms >= BITFORCE_TIMEOUT_MS) {
+ if (elapsed.tv_sec > BITFORCE_TIMEOUT_S) {
applog(LOG_ERR, "BFL%i: took %dms - longer than %dms", bitforce->device_id,
- bitforce->wait_ms, BITFORCE_TIMEOUT_MS);
+ tv_to_ms(elapsed), BITFORCE_TIMEOUT_MS);
bitforce->device_last_not_well = time(NULL);
bitforce->device_not_well_reason = REASON_DEV_OVER_HEAT;
bitforce->dev_over_heat_count++;
diff --git a/miner.h b/miner.h
index 50a1ca2..4acb8f9 100644
--- a/miner.h
+++ b/miner.h
@@ -320,6 +320,7 @@ struct cgpu_info {
int device_fd;
};
#ifdef USE_BITFORCE
+ struct timeval work_start_tv;
unsigned int wait_ms;
unsigned int sleep_ms;
uint32_t nonces;