Browse Source

Bugfix: Limit active submission threads to 0x40 so we don't overflow

Luke Dashjr 13 years ago
parent
commit
57aa649fd7
1 changed files with 42 additions and 3 deletions
  1. 42 3
      cgminer.c

+ 42 - 3
cgminer.c

@@ -71,6 +71,8 @@ struct workio_cmd {
 	struct thr_info		*thr;
 	struct work		*work;
 	bool			lagging;
+
+	struct list_head list;
 };
 
 struct strategies strategies[] = {
@@ -177,6 +179,10 @@ static struct timeval total_tv_start, total_tv_end;
 
 pthread_mutex_t control_lock;
 
+static pthread_mutex_t submitting_lock;
+static int submitting;
+static struct list_head submit_waiting;
+
 int hw_errors;
 int total_accepted, total_rejected;
 int total_getworks, total_stale, total_discarded;
@@ -2222,16 +2228,21 @@ static void submit_discard_share(struct work *work)
 static void *submit_work_thread(void *userdata)
 {
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
-	struct work *work = wc->work;
-	struct pool *pool = work->pool;
+	struct work *work;
+	struct pool *pool;
 	struct curl_ent *ce;
-	int failures = 0;
+	int failures;
 	time_t staleexpire;
 
 	pthread_detach(pthread_self());
 
 	applog(LOG_DEBUG, "Creating extra submit work thread");
 
+next_submit:
+	work = wc->work;
+	pool = work->pool;
+	failures = 0;
+
 	check_solve(work);
 
 	if (stale_work(work, true)) {
@@ -2287,6 +2298,18 @@ static void *submit_work_thread(void *userdata)
 	push_curl_entry(ce, pool);
 out:
 	workio_cmd_free(wc);
+
+	mutex_lock(&submitting_lock);
+	if (!list_empty(&submit_waiting)) {
+		applog(LOG_DEBUG, "submit_work continuing with queued submission");
+		wc = list_entry(submit_waiting.next, struct workio_cmd, list);
+		list_del(&wc->list);
+		mutex_unlock(&submitting_lock);
+		goto next_submit;
+	}
+	--submitting;
+	mutex_unlock(&submitting_lock);
+
 	return NULL;
 }
 
@@ -3285,8 +3308,23 @@ static void *workio_thread(void *userdata)
 			ok = workio_get_work(wc);
 			break;
 		case WC_SUBMIT_WORK:
+		{
+			mutex_lock(&submitting_lock);
+			if (submitting >= 0x40) {
+				if (list_empty(&submit_waiting))
+					applog(LOG_WARNING, "workio_thread queuing submissions");
+				else
+					applog(LOG_DEBUG, "workio_thread queuing submission");
+				list_add_tail(&wc->list, &submit_waiting);
+				mutex_unlock(&submitting_lock);
+				break;
+			}
+			++submitting;
+			mutex_unlock(&submitting_lock);
+
 			ok = workio_submit_work(wc);
 			break;
+		}
 		default:
 			ok = false;
 			break;
@@ -5035,6 +5073,7 @@ int main(int argc, char *argv[])
 	strcpy(current_block, block->hash);
 
 	INIT_LIST_HEAD(&scan_devices);
+	INIT_LIST_HEAD(&submit_waiting);
 
 #ifdef HAVE_OPENCL
 	memset(gpus, 0, sizeof(gpus));