Browse Source

Merge commit 'c99636f' into cg_merges_20121207

Conflicts:
	driver-ztex.c
	findnonce.c
	miner.c
	miner.h
Luke Dashjr 13 years ago
parent
commit
702260075c
4 changed files with 37 additions and 80 deletions
  1. 2 4
      driver-cpu.c
  2. 4 4
      driver-ztex.c
  3. 30 71
      miner.c
  4. 1 1
      miner.h

+ 2 - 4
driver-cpu.c

@@ -75,7 +75,7 @@ static inline void affine_to_cpu(int __maybe_unused id, int __maybe_unused cpu)
 
 
 
 
 /* TODO: resolve externals */
 /* TODO: resolve externals */
-extern bool submit_work_sync(struct thr_info *thr, const struct work *work_in, struct timeval *tv);
+extern void submit_work_async(const struct work *work_in, struct timeval *tv);
 extern char *set_int_range(const char *arg, int *i, int min, int max);
 extern char *set_int_range(const char *arg, int *i, int min, int max);
 extern int dev_from_id(int thr_id);
 extern int dev_from_id(int thr_id);
 
 
@@ -838,9 +838,7 @@ CPUSearch:
 	/* if nonce found, submit work */
 	/* if nonce found, submit work */
 	if (unlikely(rc)) {
 	if (unlikely(rc)) {
 		applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id));
 		applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id));
-		if (unlikely(!submit_work_sync(thr, work, NULL))) {
-			applog(LOG_ERR, "Failed to submit_work_sync in miner_thread %d", thr_id);
-		}
+		submit_work_async(work, NULL);
 		work->blk.nonce = last_nonce + 1;
 		work->blk.nonce = last_nonce + 1;
 		goto CPUSearch;
 		goto CPUSearch;
 	}
 	}

+ 4 - 4
driver-ztex.c

@@ -186,7 +186,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	int backlog_p = 0, backlog_max;
 	int backlog_p = 0, backlog_max;
 	uint32_t *lastnonce;
 	uint32_t *lastnonce;
 	uint32_t nonce, noncecnt = 0;
 	uint32_t nonce, noncecnt = 0;
-	bool overflow, found, rv;
+	bool overflow, found;
 	struct libztex_hash_data hdata[GOLDEN_BACKLOG];
 	struct libztex_hash_data hdata[GOLDEN_BACKLOG];
 
 
 	ztex = thr->cgpu->device_ztex;
 	ztex = thr->cgpu->device_ztex;
@@ -295,9 +295,9 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 							backlog_p = 0;
 							backlog_p = 0;
 						nonce = le32toh(nonce);
 						nonce = le32toh(nonce);
 						work->blk.nonce = 0xffffffff;
 						work->blk.nonce = 0xffffffff;
-						if ( (rv = test_nonce(work, nonce, false)) )
-						rv = submit_nonce(thr, work, nonce);
-						applog(LOG_DEBUG, "%s: submitted %0.8x (from N%dE%d) %d", ztex->repr, nonce, i, j, rv);
+						if (test_nonce(work, nonce, false))
+							submit_nonce(thr, work, nonce);
+						applog(LOG_DEBUG, "%s: submitted %0.8x (from N%dE%d)", ztex->repr, nonce, i, j);
 					}
 					}
 				}
 				}
 			}
 			}

+ 30 - 71
miner.c

@@ -81,7 +81,6 @@
 
 
 enum workio_commands {
 enum workio_commands {
 	WC_GET_WORK,
 	WC_GET_WORK,
-	WC_SUBMIT_WORK,
 };
 };
 
 
 struct workio_cmd {
 struct workio_cmd {
@@ -3044,12 +3043,8 @@ static void workio_cmd_free(struct workio_cmd *wc)
 		return;
 		return;
 
 
 	switch (wc->cmd) {
 	switch (wc->cmd) {
-	case WC_SUBMIT_WORK:
-		if (wc->work)
-		free_work(wc->work);
-		break;
-	default: /* do nothing */
-		break;
+		default: /* do nothing */
+			break;
 	}
 	}
 
 
 	memset(wc, 0, sizeof(*wc));	/* poison */
 	memset(wc, 0, sizeof(*wc));	/* poison */
@@ -3817,9 +3812,9 @@ static void free_sws(struct submit_work_state *sws)
 	free(sws);
 	free(sws);
 }
 }
 
 
-static void *submit_work_thread(void *userdata)
+static void *submit_work_thread(__maybe_unused void *userdata)
 {
 {
-	struct workio_cmd *wc = (struct workio_cmd *)userdata;
+	struct workio_cmd *wc;
 	int wip = 0;
 	int wip = 0;
 	CURLM *curlm;
 	CURLM *curlm;
 	long curlm_timeout_ms = -1;
 	long curlm_timeout_ms = -1;
@@ -3836,16 +3831,6 @@ static void *submit_work_thread(void *userdata)
 	curl_multi_setopt(curlm, CURLMOPT_TIMERFUNCTION, my_curl_timer_set);
 	curl_multi_setopt(curlm, CURLMOPT_TIMERFUNCTION, my_curl_timer_set);
 	curl_multi_setopt(curlm, CURLMOPT_TIMERDATA, &curlm_timeout_ms);
 	curl_multi_setopt(curlm, CURLMOPT_TIMERDATA, &curlm_timeout_ms);
 
 
-	if ( (sws = begin_submission(wc)) ) {
-		if (sws->ce)
-			curl_multi_add_handle(curlm, sws->ce->curl);
-		else
-		if (sws->s)
-			write_sws = sws;
-		++wip;
-		++total_submitting;
-	}
-
 	fd_set rfds, wfds, efds;
 	fd_set rfds, wfds, efds;
 	int maxfd;
 	int maxfd;
 	struct timeval timeout, *timeoutp;
 	struct timeval timeout, *timeoutp;
@@ -3964,21 +3949,6 @@ static void *submit_work_thread(void *userdata)
 	return NULL;
 	return NULL;
 }
 }
 
 
-/* We try to reuse curl handles as much as possible, but if there is already
- * work queued to be submitted, we start generating extra handles to submit
- * the shares to avoid ever increasing backlogs. This allows us to scale to
- * any size hardware */
-static bool workio_submit_work(struct workio_cmd *wc)
-{
-	pthread_t submit_thread;
-
-	if (unlikely(pthread_create(&submit_thread, NULL, submit_work_thread, (void *)wc))) {
-		applog(LOG_ERR, "Failed to create submit_work_thread");
-		return false;
-	}
-	return true;
-}
-
 /* Find the pool that currently has the highest priority */
 /* Find the pool that currently has the highest priority */
 static struct pool *priority_pool(int choice)
 static struct pool *priority_pool(int choice)
 {
 {
@@ -5350,21 +5320,6 @@ static void *workio_thread(void *userdata)
 		case WC_GET_WORK:
 		case WC_GET_WORK:
 			ok = workio_get_work(wc);
 			ok = workio_get_work(wc);
 			break;
 			break;
-		case WC_SUBMIT_WORK:
-		{
-			mutex_lock(&submitting_lock);
-			if (submitting) {
-				list_add_tail(&wc->list, &submit_waiting);
-				(void)write(submit_waiting_notifier[1], "\0", 1);
-				mutex_unlock(&submitting_lock);
-				break;
-			}
-			++submitting;
-			mutex_unlock(&submitting_lock);
-
-			ok = workio_submit_work(wc);
-			break;
-		}
 		default:
 		default:
 			ok = false;
 			ok = false;
 			break;
 			break;
@@ -6422,35 +6377,40 @@ out:
 	work->mined = true;
 	work->mined = true;
 }
 }
 
 
-bool submit_work_sync(struct thr_info *thr, struct work *work_in, struct timeval *tv_work_found)
+void submit_work_async(struct work *work_in, struct timeval *tv_work_found)
 {
 {
 	struct workio_cmd *wc;
 	struct workio_cmd *wc;
+	struct work *work = copy_work(work_in);
+	pthread_t submit_thread;
+	bool was_submitting;
+
+	if (tv_work_found)
+		memcpy(&(work->tv_work_found), tv_work_found, sizeof(struct timeval));
+	applog(LOG_DEBUG, "Pushing submit work to work thread");
 
 
 	/* fill out work request message */
 	/* fill out work request message */
 	wc = calloc(1, sizeof(*wc));
 	wc = calloc(1, sizeof(*wc));
 	if (unlikely(!wc)) {
 	if (unlikely(!wc)) {
-		applog(LOG_ERR, "Failed to calloc wc in submit_work_sync");
-		return false;
+		applog(LOG_ERR, "Failed to calloc wc in submit_work_async");
+		return;
 	}
 	}
 
 
-	wc->work = copy_work(work_in);
-	wc->cmd = WC_SUBMIT_WORK;
-	wc->thr = thr;
-	if (tv_work_found)
-		memcpy(&(wc->work->tv_work_found), tv_work_found, sizeof(struct timeval));
+	wc->work = work;
 
 
-	applog(LOG_DEBUG, "Pushing submit work to work thread");
+	mutex_lock(&submitting_lock);
+	list_add_tail(&wc->list, &submit_waiting);
+	was_submitting = submitting;
+	if (!submitting)
+		++submitting;
+	mutex_unlock(&submitting_lock);
 
 
-	/* send solution to workio thread */
-	if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
-		applog(LOG_ERR, "Failed to tq_push work in submit_work_sync");
-		goto err_out;
+	if (was_submitting) {
+		(void)write(submit_waiting_notifier[1], "\0", 1);
+		return;
 	}
 	}
 
 
-	return true;
-err_out:
-	workio_cmd_free(wc);
-	return false;
+	if (unlikely(pthread_create(&submit_thread, NULL, submit_work_thread, NULL)))
+		quit(1, "Failed to create submit_work_thread");
 }
 }
 
 
 enum test_nonce2_result hashtest2(struct work *work, bool checktarget)
 enum test_nonce2_result hashtest2(struct work *work, bool checktarget)
@@ -6499,7 +6459,7 @@ enum test_nonce2_result _test_nonce2(struct work *work, uint32_t nonce, bool che
 	return hashtest2(work, checktarget);
 	return hashtest2(work, checktarget);
 }
 }
 
 
-bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
+void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 {
 {
 	struct timeval tv_work_found;
 	struct timeval tv_work_found;
 	gettimeofday(&tv_work_found, NULL);
 	gettimeofday(&tv_work_found, NULL);
@@ -6525,8 +6485,7 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 
 
 			if (thr->cgpu->api->hw_error)
 			if (thr->cgpu->api->hw_error)
 				thr->cgpu->api->hw_error(thr);
 				thr->cgpu->api->hw_error(thr);
-
-			return false;
+			return;
 		}
 		}
 		case TNR_HIGH:
 		case TNR_HIGH:
 			// Share above target, normal
 			// Share above target, normal
@@ -6536,11 +6495,11 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 				scrypt_diff(work);
 				scrypt_diff(work);
 			else
 			else
 				share_diff(work);
 				share_diff(work);
-			return true;
+			return;
 		case TNR_GOOD:
 		case TNR_GOOD:
 			break;
 			break;
 	}
 	}
-	return submit_work_sync(thr, work, &tv_work_found);
+	submit_work_async(work, &tv_work_found);
 }
 }
 
 
 static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)
 static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)

+ 1 - 1
miner.h

@@ -1074,7 +1074,7 @@ enum test_nonce2_result {
 extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
 extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
 #define test_nonce(work, nonce, checktarget)  (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
 #define test_nonce(work, nonce, checktarget)  (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
 #define test_nonce2(work, nonce)  (_test_nonce2(work, nonce, true))
 #define test_nonce2(work, nonce)  (_test_nonce2(work, nonce, true))
-bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
+extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
 extern void tailsprintf(char *f, const char *fmt, ...);
 extern void tailsprintf(char *f, const char *fmt, ...);
 extern void wlogprint(const char *f, ...);
 extern void wlogprint(const char *f, ...);
 extern int curses_int(const char *query);
 extern int curses_int(const char *query);