Sleep in avalon send task on return to the function to allow other code to work during the sleep period.
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
diff --git a/driver-avalon.c b/driver-avalon.c
index 72359d4..d51b88f 100644
--- a/driver-avalon.c
+++ b/driver-avalon.c
@@ -142,13 +142,12 @@ static int avalon_write(struct cgpu_info *avalon, char *buf, ssize_t len, int ep
return AVA_SEND_OK;
}
-static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *avalon)
+static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *avalon,
+ struct avalon_info *info)
{
uint8_t buf[AVALON_WRITE_SIZE + 4 * AVALON_DEFAULT_ASIC_NUM];
int delay, ret, i, ep = C_AVALON_TASK;
- struct avalon_info *info;
- cgtimer_t ts_start;
uint32_t nonce_range;
size_t nr_len;
@@ -189,7 +188,6 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
tt |= ((buf[4] & 0x80) ? (1 << 0) : 0);
buf[4] = tt;
#endif
- info = avalon->device_data;
delay = nr_len * 10 * 1000000;
delay = delay / info->baud;
delay += 4000;
@@ -202,11 +200,14 @@ static int avalon_send_task(const struct avalon_task *at, struct cgpu_info *aval
applog(LOG_DEBUG, "Avalon: Sent(%u):", (unsigned int)nr_len);
hexdump(buf, nr_len);
}
- cgsleep_prepare_r(&ts_start);
+ /* Sleep from the last time we sent data */
+ cgsleep_us_r(&info->cgsent, info->send_delay);
+
+ cgsleep_prepare_r(&info->cgsent);
ret = avalon_write(avalon, (char *)buf, nr_len, ep);
- cgsleep_us_r(&ts_start, delay);
- applog(LOG_DEBUG, "Avalon: Sent: Buffer delay: %dus", delay);
+ applog(LOG_DEBUG, "Avalon: Sent: Buffer delay: %dus", info->send_delay);
+ info->send_delay = delay;
return ret;
}
@@ -319,7 +320,7 @@ static int avalon_reset(struct cgpu_info *avalon, bool initial)
AVALON_DEFAULT_FREQUENCY);
wait_avalon_ready(avalon);
- ret = avalon_send_task(&at, avalon);
+ ret = avalon_send_task(&at, avalon, info);
if (unlikely(ret == AVA_SEND_ERROR))
return -1;
@@ -560,7 +561,7 @@ static void avalon_idle(struct cgpu_info *avalon, struct avalon_info *info)
avalon_init_task(&at, 0, 0, info->fan_pwm, info->timeout,
info->asic_count, info->miner_count, 1, 1,
info->frequency);
- avalon_send_task(&at, avalon);
+ avalon_send_task(&at, avalon, info);
}
applog(LOG_WARNING, "%s%i: Idling %d miners", avalon->drv->name, avalon->device_id, i);
wait_avalon_ready(avalon);
@@ -1148,7 +1149,7 @@ static void *avalon_send_tasks(void *userdata)
avalon_reset_auto(info);
}
- ret = avalon_send_task(&at, avalon);
+ ret = avalon_send_task(&at, avalon, info);
if (unlikely(ret == AVA_SEND_ERROR)) {
/* Send errors are fatal */
diff --git a/driver-avalon.h b/driver-avalon.h
index ea32bc0..0a11161 100644
--- a/driver-avalon.h
+++ b/driver-avalon.h
@@ -144,8 +144,10 @@ struct avalon_info {
pthread_mutex_t lock;
pthread_mutex_t qlock;
cgsem_t qsem;
- int nonces;
+ cgtimer_t cgsent;
+ int send_delay;
+ int nonces;
int auto_queued;
int auto_nonces;
int auto_hw;