aboutsummaryrefslogtreecommitdiff
path: root/cpu-miner.c
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2011-03-17 23:22:10 -0400
committerJeff Garzik <jgarzik@pobox.com>2011-03-17 23:22:10 -0400
commit6818c6928a95af2cda225176ccc54bc6424e8103 (patch)
tree5e35cd6505c46b436de6e47964e6744bd8454e7b /cpu-miner.c
parent33e5b54928ee1e4b1bcc35a46ff44d42cb4fbe8a (diff)
Improve max nonce auto-adjustment with some basic algebra.
Diffstat (limited to 'cpu-miner.c')
-rw-r--r--cpu-miner.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/cpu-miner.c b/cpu-miner.c
index 7cd6e74..c7a6672 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -500,6 +500,7 @@ static void *miner_thread(void *userdata)
struct work work __attribute__((aligned(128)));
unsigned long hashes_done;
struct timeval tv_start, tv_end, diff;
+ uint64_t max64;
bool rc;
/* obtain new work from internal workio thread */
@@ -576,14 +577,10 @@ static void *miner_thread(void *userdata)
hashmeter(thr_id, &diff, hashes_done);
/* adjust max_nonce to meet target scan time */
- if (diff.tv_sec > (opt_scantime * 2))
- max_nonce /= 2; /* large decrease */
- else if ((diff.tv_sec > opt_scantime) &&
- (max_nonce > 1500000))
- max_nonce -= 1000000; /* small decrease */
- else if ((diff.tv_sec < opt_scantime) &&
- (max_nonce < 0xffffec76))
- max_nonce += 100000; /* small increase */
+ max64 = ((uint64_t)hashes_done * opt_scantime) / diff.tv_sec;
+ if (max64 > 0xfffffffaULL)
+ max64 = 0xfffffffaULL;
+ max_nonce = max64;
/* if nonce found, submit work */
if (rc && !submit_work(mythr, &work))