Limit the duration we wait for reads in BF1 based on time already elapsed to account for other delays such as work restart messages or out of work.
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
diff --git a/driver-bitfury.c b/driver-bitfury.c
index 84ac35a..b0b41a1 100644
--- a/driver-bitfury.c
+++ b/driver-bitfury.c
@@ -189,8 +189,10 @@ static int64_t bitfury_scanhash(struct thr_info *thr, struct work *work,
{
struct cgpu_info *bitfury = thr->cgpu;
struct bitfury_info *info = bitfury->device_data;
+ struct timeval tv_now;
int amount, i;
char buf[45];
+ int ms_diff;
buf[0] = 'W';
memcpy(buf + 1, work->midstate, 32);
@@ -199,14 +201,23 @@ static int64_t bitfury_scanhash(struct thr_info *thr, struct work *work,
/* New results may spill out from the latest work, making us drop out
* too early so read whatever we get for the first half nonce and then
* look for the results to prev work. */
- usb_read_timeout(bitfury, info->buf, 512, &amount, 600, C_BF1_GETRES);
- info->tot += amount;
+ cgtime(&tv_now);
+ ms_diff = 600 - ms_tdiff(&tv_now, &info->tv_start);
+ if (ms_diff > 0) {
+ usb_read_timeout(bitfury, info->buf, 512, &amount, ms_diff, C_BF1_GETRES);
+ info->tot += amount;
+ }
+
if (unlikely(thr->work_restart))
goto cascade;
/* Now look for the bulk of the previous work results, they will come
* in a batch following the first data. */
- usb_read_once_timeout(bitfury, info->buf + info->tot, 7, &amount, 1000, C_BF1_GETRES);
+ cgtime(&tv_now);
+ ms_diff = BF1WAIT - ms_tdiff(&tv_now, &info->tv_start);
+ if (unlikely(ms_diff < 10))
+ ms_diff = 10;
+ usb_read_once_timeout(bitfury, info->buf + info->tot, 7, &amount, ms_diff, C_BF1_GETRES);
info->tot += amount;
while (amount) {
usb_read_once_timeout(bitfury, info->buf + info->tot, 512, &amount, 10, C_BF1_GETRES);
@@ -218,6 +229,7 @@ static int64_t bitfury_scanhash(struct thr_info *thr, struct work *work,
/* Send work */
usb_write(bitfury, buf, 45, &amount, C_BF1_REQWORK);
+ cgtime(&info->tv_start);
/* Get response acknowledging work */
usb_read(bitfury, buf, 7, &amount, C_BF1_GETWORK);
diff --git a/driver-bitfury.h b/driver-bitfury.h
index 4cc1300..db13323 100644
--- a/driver-bitfury.h
+++ b/driver-bitfury.h
@@ -23,6 +23,7 @@ struct bitfury_info {
char buf[512];
int tot;
int nonces;
+ struct timeval tv_start;
};
#endif /* BITFURY_H */
diff --git a/util.c b/util.c
index c0feaaf..ecece48 100644
--- a/util.c
+++ b/util.c
@@ -1074,6 +1074,12 @@ double us_tdiff(struct timeval *end, struct timeval *start)
return end->tv_sec * 1000000 + end->tv_usec - start->tv_sec * 1000000 - start->tv_usec;
}
+/* Returns the milliseconds difference between end and start times */
+int ms_tdiff(struct timeval *end, struct timeval *start)
+{
+ return end->tv_sec * 1000 + end->tv_usec / 1000 - start->tv_sec * 1000 - start->tv_usec / 1000;
+}
+
/* Returns the seconds difference between end and start times as a double */
double tdiff(struct timeval *end, struct timeval *start)
{
diff --git a/util.h b/util.h
index 96157fa..5a3d968 100644
--- a/util.h
+++ b/util.h
@@ -98,6 +98,7 @@ void cgsleep_us_r(cgtimer_t *ts_start, int64_t us);
int cgtimer_to_ms(cgtimer_t *cgt);
void cgtimer_sub(cgtimer_t *a, cgtimer_t *b, cgtimer_t *res);
double us_tdiff(struct timeval *end, struct timeval *start);
+int ms_tdiff(struct timeval *end, struct timeval *start);
double tdiff(struct timeval *end, struct timeval *start);
bool stratum_send(struct pool *pool, char *s, ssize_t len);
bool sock_full(struct pool *pool);