mirror of
https://github.com/GOSTSec/sgminer
synced 2025-02-05 11:34:16 +00:00
Use low latency usb transfers on the avalon, sleeping up to half a buffer's worth only if no data is returning to increase hashrate, abolish lost work and decrease CPU.
This commit is contained in:
parent
e487d3d2f0
commit
7c683cf2b1
@ -229,7 +229,7 @@ static bool avalon_decode_nonce(struct thr_info *thr, struct cgpu_info *avalon,
|
|||||||
static void wait_avalon_ready(struct cgpu_info *avalon)
|
static void wait_avalon_ready(struct cgpu_info *avalon)
|
||||||
{
|
{
|
||||||
while (avalon_buffer_full(avalon)) {
|
while (avalon_buffer_full(avalon)) {
|
||||||
nmsleep(AVALON_READ_TIMEOUT);
|
nmsleep(40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,11 +240,6 @@ static int avalon_read(struct cgpu_info *avalon, unsigned char *buf,
|
|||||||
char readbuf[AVALON_READBUF_SIZE];
|
char readbuf[AVALON_READBUF_SIZE];
|
||||||
int err, amount, ofs = 2, cp;
|
int err, amount, ofs = 2, cp;
|
||||||
|
|
||||||
/* If the buffer is ready to take more work, yield once in case the
|
|
||||||
* write thread is waiting to be scheduled. */
|
|
||||||
if (!avalon_buffer_full(avalon))
|
|
||||||
nmsleep(AVALON_READ_TIMEOUT);
|
|
||||||
|
|
||||||
err = usb_read_once_timeout(avalon, readbuf, readsize, &amount, timeout, ep);
|
err = usb_read_once_timeout(avalon, readbuf, readsize, &amount, timeout, ep);
|
||||||
applog(LOG_DEBUG, "%s%i: Get avalon read got err %d",
|
applog(LOG_DEBUG, "%s%i: Get avalon read got err %d",
|
||||||
avalon->drv->name, avalon->device_id, err);
|
avalon->drv->name, avalon->device_id, err);
|
||||||
@ -493,7 +488,7 @@ static void avalon_initialise(struct cgpu_info *avalon)
|
|||||||
|
|
||||||
// Set latency
|
// Set latency
|
||||||
err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
|
err = usb_transfer(avalon, FTDI_TYPE_OUT, FTDI_REQUEST_LATENCY,
|
||||||
AVALON_READ_TIMEOUT, interface, C_LATENCY);
|
AVALON_LATENCY, interface, C_LATENCY);
|
||||||
|
|
||||||
applog(LOG_DEBUG, "%s%i: latency got err %d",
|
applog(LOG_DEBUG, "%s%i: latency got err %d",
|
||||||
avalon->drv->name, avalon->device_id, err);
|
avalon->drv->name, avalon->device_id, err);
|
||||||
@ -742,18 +737,20 @@ static void *avalon_get_results(void *userdata)
|
|||||||
{
|
{
|
||||||
struct cgpu_info *avalon = (struct cgpu_info *)userdata;
|
struct cgpu_info *avalon = (struct cgpu_info *)userdata;
|
||||||
struct avalon_info *info = avalon->device_data;
|
struct avalon_info *info = avalon->device_data;
|
||||||
|
int offset = 0, read_delay = 0, ret = 0;
|
||||||
const int rsize = AVALON_FTDI_READSIZE;
|
const int rsize = AVALON_FTDI_READSIZE;
|
||||||
char readbuf[AVALON_READBUF_SIZE];
|
char readbuf[AVALON_READBUF_SIZE];
|
||||||
struct thr_info *thr = info->thr;
|
struct thr_info *thr = info->thr;
|
||||||
|
struct timeval tv_start, tv_end;
|
||||||
char threadname[24];
|
char threadname[24];
|
||||||
int offset = 0;
|
|
||||||
|
|
||||||
snprintf(threadname, 24, "ava_recv/%d", avalon->device_id);
|
snprintf(threadname, 24, "ava_recv/%d", avalon->device_id);
|
||||||
RenameThread(threadname);
|
RenameThread(threadname);
|
||||||
|
|
||||||
while (likely(!avalon->shutdown)) {
|
while (likely(!avalon->shutdown)) {
|
||||||
unsigned char buf[rsize];
|
unsigned char buf[rsize];
|
||||||
int ret;
|
struct timeval tv_diff;
|
||||||
|
int us_diff;
|
||||||
|
|
||||||
if (offset >= (int)AVALON_READ_SIZE)
|
if (offset >= (int)AVALON_READ_SIZE)
|
||||||
avalon_parse_results(avalon, info, thr, readbuf, &offset);
|
avalon_parse_results(avalon, info, thr, readbuf, &offset);
|
||||||
@ -773,6 +770,20 @@ static void *avalon_get_results(void *userdata)
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* As the usb read returns after just 1ms, sleep long enough
|
||||||
|
* to leave the interface idle for writes to occur, but do not
|
||||||
|
* sleep if we have been receiving data as more may be coming. */
|
||||||
|
if (ret < 1) {
|
||||||
|
cgtime(&tv_end);
|
||||||
|
timersub(&tv_end, &tv_start, &tv_diff);
|
||||||
|
/* Assume it has not been > 1 second so ignore tv_sec */
|
||||||
|
us_diff = tv_diff.tv_usec;
|
||||||
|
read_delay = AVALON_READ_TIMEOUT * 1000 - us_diff;
|
||||||
|
if (likely(read_delay >= 1000))
|
||||||
|
nusleep(read_delay);
|
||||||
|
}
|
||||||
|
|
||||||
|
cgtime(&tv_start);
|
||||||
ret = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT,
|
ret = avalon_read(avalon, buf, rsize, AVALON_READ_TIMEOUT,
|
||||||
C_AVALON_READ);
|
C_AVALON_READ);
|
||||||
|
|
||||||
|
@ -34,7 +34,8 @@
|
|||||||
#define AVALON_FTDI_READSIZE 510
|
#define AVALON_FTDI_READSIZE 510
|
||||||
#define AVALON_READBUF_SIZE 8192
|
#define AVALON_READBUF_SIZE 8192
|
||||||
#define AVALON_RESET_TIMEOUT 100
|
#define AVALON_RESET_TIMEOUT 100
|
||||||
#define AVALON_READ_TIMEOUT 10
|
#define AVALON_READ_TIMEOUT 18 /* Enough to only half fill the buffer */
|
||||||
|
#define AVALON_LATENCY 1
|
||||||
|
|
||||||
struct avalon_task {
|
struct avalon_task {
|
||||||
uint8_t reset :1;
|
uint8_t reset :1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user