Don't pause after failed getwork, set lagging flag and reassess.
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
diff --git a/cgminer.c b/cgminer.c
index a844576..2fa1f96 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2380,13 +2380,15 @@ static void *get_work_thread(void *userdata)
struct workio_cmd *wc = (struct workio_cmd *)userdata;
int ts, tq, maxq = opt_queue + mining_threads;
struct pool *pool = current_pool();
+ struct work *ret_work= NULL;
struct curl_ent *ce = NULL;
- struct work *ret_work;
+ bool lagging = false;
pthread_detach(pthread_self());
applog(LOG_DEBUG, "Creating extra get work thread");
+retry:
tq = global_queued();
ts = total_staged();
@@ -2399,30 +2401,33 @@ static void *get_work_thread(void *userdata)
if (clone_available())
goto out;
- ret_work = make_work();
+ if (!ret_work)
+ ret_work = make_work();
if (wc->thr)
ret_work->thr = wc->thr;
else
ret_work->thr = NULL;
- if (opt_benchmark)
+ if (opt_benchmark) {
get_benchmark_work(ret_work);
- else {
- bool lagging = false;
+ ret_work->queued = true;
+ } else {
if (ts <= opt_queue)
lagging = true;
pool = ret_work->pool = select_pool(lagging);
inc_queued();
-
- ce = pop_curl_entry(pool);
+
+ if (!ce)
+ ce = pop_curl_entry(pool);
/* obtain new work from bitcoin via JSON-RPC */
- while (!get_upstream_work(ret_work, ce->curl)) {
+ if (!get_upstream_work(ret_work, ce->curl)) {
/* pause, then restart work-request loop */
- applog(LOG_DEBUG, "json_rpc_call failed on get work, retry after %d seconds",
- opt_fail_pause);
- sleep(opt_fail_pause);
+ applog(LOG_DEBUG, "json_rpc_call failed on get work, retrying");
+ lagging = true;
+ dec_queued();
+ goto retry;
}
ret_work->queued = true;
@@ -2438,6 +2443,8 @@ static void *get_work_thread(void *userdata)
}
out:
+ if (ret_work && !ret_work->queued)
+ free_work(ret_work);
workio_cmd_free(wc);
if (ce)
push_curl_entry(ce, pool);