Commit 618b3e8b116c9ac95f8bd9a24bff96369ace8bdf

Con Kolivas 2012-08-23T23:50:38

Track queued and staged per pool once again for future use.

diff --git a/cgminer.c b/cgminer.c
index 29362c9..31ab609 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2252,17 +2252,19 @@ static void push_curl_entry(struct curl_ent *ce, struct pool *pool)
 
 /* This is overkill, but at least we'll know accurately how much work is
  * queued to prevent ever being left without work */
-static void inc_queued(void)
+static void inc_queued(struct pool *pool)
 {
 	mutex_lock(&qd_lock);
 	total_queued++;
+	pool->queued++;
 	mutex_unlock(&qd_lock);
 }
 
-static void dec_queued(void)
+static void dec_queued(struct pool *pool)
 {
 	mutex_lock(&qd_lock);
 	total_queued--;
+	pool->queued--;
 	mutex_unlock(&qd_lock);
 }
 
@@ -2422,7 +2424,7 @@ retry:
 			lagging = true;
 		pool = ret_work->pool = select_pool(lagging);
 
-		inc_queued();
+		inc_queued(pool);
 
 		if (!ce)
 			ce = pop_curl_entry(pool);
@@ -2430,7 +2432,7 @@ retry:
 		/* Check that we haven't staged work via other threads while
 		 * waiting for a curl entry */
 		if (total_staged() >= maxq) {
-			dec_queued();
+			dec_queued(pool);
 			free_work(ret_work);
 			goto out;
 		}
@@ -2440,7 +2442,7 @@ retry:
 			/* pause, then restart work-request loop */
 			applog(LOG_DEBUG, "json_rpc_call failed on get work, retrying");
 			lagging = true;
-			dec_queued();
+			dec_queued(pool);
 			free_work(ret_work);
 			goto retry;
 		}
@@ -2725,6 +2727,7 @@ static void discard_stale(void)
 	HASH_ITER(hh, staged_work, work, tmp) {
 		if (stale_work(work, false)) {
 			HASH_DEL(staged_work, work);
+			work->pool->staged--;
 			discard_work(work);
 			stale++;
 		}
@@ -2931,9 +2934,11 @@ static bool hash_push(struct work *work)
 	pthread_cond_signal(&getq->cond);
 	mutex_unlock(stgd_lock);
 
+	work->pool->staged++;
+
 	if (work->queued) {
 		work->queued = false;
-		dec_queued();
+		dec_queued(work->pool);
 	}
 
 	return rc;
@@ -3926,17 +3931,7 @@ static void pool_resus(struct pool *pool)
 static bool queue_request(struct thr_info *thr, bool needed)
 {
 	struct workio_cmd *wc;
-	bool doq = true;
 
-	mutex_lock(&control_lock);
-	if (queued_getworks > (mining_threads + opt_queue) * 2)
-		doq = false;
-	else
-		queued_getworks++;
-	mutex_unlock(&control_lock);
-	if (!doq)
-		return true;
-	
 	/* fill out work request message */
 	wc = calloc(1, sizeof(*wc));
 	if (unlikely(!wc)) {
@@ -3981,6 +3976,7 @@ static struct work *hash_pop(const struct timespec *abstime)
 		} else
 			work = staged_work;
 		HASH_DEL(staged_work, work);
+		work->pool->staged--;
 		if (work_rollable(work))
 			staged_rollable--;
 	}
diff --git a/miner.h b/miner.h
index 91fe7ce..2141724 100644
--- a/miner.h
+++ b/miner.h
@@ -732,6 +732,9 @@ struct pool {
 	int solved;
 	int diff1;
 
+	int queued;
+	int staged;
+
 	bool submit_fail;
 	bool idle;
 	bool lagging;