From 355a87e10b289f11f07423ae31d82e6ddac35295 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 10:49:17 -0400 Subject: [PATCH 1/3] Bugfix: Calculate Icarus timeout-exhausted nonce count correctly We're only waiting 8 seconds for results from Icarus, but actually exhausing the nonce space requires 11.3 --- driver-icarus.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/driver-icarus.c b/driver-icarus.c index 4aab784a..a5e3955a 100644 --- a/driver-icarus.c +++ b/driver-icarus.c @@ -290,8 +290,11 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin)); - if (nonce == 0 && ret) - return 0xffffffff; + if (nonce == 0 && ret) { + t = time(NULL) - t; + // Approximately how much of the nonce Icarus scans in 1 second... + return 0x16a7a561 * t; + } #ifndef __BIG_ENDIAN__ nonce = swab32(nonce); From 11234c3353f3e891d8cbed24a455588ebe3ec662 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 14:19:22 -0400 Subject: [PATCH 2/3] Icarus: Use gettimeofday to more accurately measure scanhash time, and calibrate scan time estimate based on actual data --- driver-icarus.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/driver-icarus.c b/driver-icarus.c index a5e3955a..e6f9ebcb 100644 --- a/driver-icarus.c +++ b/driver-icarus.c @@ -251,7 +251,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, char *ob_hex, *nonce_hex; uint32_t nonce; uint32_t hash_count; - time_t t = 0; + struct timeval tv_start, tv_end, diff; icarus = thr->cgpu; fd = icarus->device_fd; @@ -264,13 +264,15 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, #ifndef WIN32 tcflush(fd, TCOFLUSH); #endif + + gettimeofday(&tv_start, NULL); + ret = icarus_write(fd, ob_bin, sizeof(ob_bin)); if (ret) return 0; /* This should never happen */ ob_hex = bin2hex(ob_bin, sizeof(ob_bin)); if (ob_hex) { - t = time(NULL); applog(LOG_DEBUG, "Icarus %s send: %s", icarus->device_id, ob_hex); free(ob_hex); @@ -280,20 +282,25 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, memset(nonce_bin, 0, sizeof(nonce_bin)); ret = icarus_gets(nonce_bin, sizeof(nonce_bin), fd); + gettimeofday(&tv_end, NULL); + timeval_subtract(&diff, &tv_end, &tv_start); + nonce_hex = bin2hex(nonce_bin, sizeof(nonce_bin)); if (nonce_hex) { - t = time(NULL) - t; - applog(LOG_DEBUG, "Icarus %d return (elapse %d seconds): %s", - icarus->device_id, t, nonce_hex); + applog(LOG_DEBUG, "Icarus %d returned (in %d.%06d seconds): %s", + icarus->device_id, diff.tv_sec, diff.tv_usec, nonce_hex); free(nonce_hex); } memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin)); if (nonce == 0 && ret) { - t = time(NULL) - t; + if (unlikely(diff.tv_sec > 12 || (diff.tv_sec == 11 && diff.tv_usec > 300067))) + return 0xffffffff; // Approximately how much of the nonce Icarus scans in 1 second... - return 0x16a7a561 * t; + // 0x16a7a561 would be if it was exactly 380 MH/s + // 0x168b7b4b was the average over a 201-sample period based on time to find actual shares + return (0x168b7b4b * diff.tv_sec) + (0x17a * diff.tv_usec); } #ifndef __BIG_ENDIAN__ @@ -312,6 +319,8 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, hash_count <<= 1; } + applog(LOG_DEBUG, "0x%x hashes in %d.%06d seconds", hash_count, diff.tv_sec, diff.tv_usec); + return hash_count; } From b4ba9c3f00609301afde4e735233ef932b496864 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 21 Apr 2012 19:55:11 -0400 Subject: [PATCH 3/3] Bugfix: Icarus: Invalidate old job, even if no nonce found in it --- driver-icarus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver-icarus.c b/driver-icarus.c index e6f9ebcb..86015110 100644 --- a/driver-icarus.c +++ b/driver-icarus.c @@ -294,6 +294,8 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin)); + work->blk.nonce = 0xffffffff; + if (nonce == 0 && ret) { if (unlikely(diff.tv_sec > 12 || (diff.tv_sec == 11 && diff.tv_usec > 300067))) return 0xffffffff; @@ -306,7 +308,6 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work, #ifndef __BIG_ENDIAN__ nonce = swab32(nonce); #endif - work->blk.nonce = 0xffffffff; submit_nonce(thr, work, nonce); hash_count = (nonce & 0x7fffffff);