Browse Source

Merge commit '9bec1e1' into bfgminer

Luke Dashjr 13 years ago
parent
commit
1db0118251
7 changed files with 84 additions and 153 deletions
  1. 10 24
      diablo120823.cl
  2. 10 24
      diakgcn120823.cl
  3. 39 46
      miner.c
  4. 3 0
      miner.h
  5. 10 24
      phatk120823.cl
  6. 8 21
      poclbm120823.cl
  7. 4 14
      scrypt120823.cl

+ 10 - 24
diablo120823.cl

@@ -1245,49 +1245,35 @@ void search(
 #define FOUND (0x0F)
 #define FOUND (0x0F)
 
 
 #if defined(OCL1)
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 #endif
 
 
 #if defined(VECTORS4)
 #if defined(VECTORS4)
 	bool result = any(ZA[924] == 0x136032EDU);
 	bool result = any(ZA[924] == 0x136032EDU);
 
 
 	if (result) {
 	if (result) {
-		uint found;
-
 		if (ZA[924].x == 0x136032EDU)
 		if (ZA[924].x == 0x136032EDU)
-			SETFOUND(found, Znonce.x);
+			SETFOUND(Znonce.x);
 		if (ZA[924].y == 0x136032EDU)
 		if (ZA[924].y == 0x136032EDU)
-			SETFOUND(found, Znonce.y);
+			SETFOUND(Znonce.y);
 		if (ZA[924].z == 0x136032EDU)
 		if (ZA[924].z == 0x136032EDU)
-			SETFOUND(found, Znonce.z);
+			SETFOUND(Znonce.z);
 		if (ZA[924].w == 0x136032EDU)
 		if (ZA[924].w == 0x136032EDU)
-			SETFOUND(found, Znonce.w);
+			SETFOUND(Znonce.w);
 	}
 	}
 #elif defined(VECTORS2)
 #elif defined(VECTORS2)
 	bool result = any(ZA[924] == 0x136032EDU);
 	bool result = any(ZA[924] == 0x136032EDU);
 
 
 	if (result) {
 	if (result) {
-		uint found;
-
 		if (ZA[924].x == 0x136032EDU)
 		if (ZA[924].x == 0x136032EDU)
-			SETFOUND(found, Znonce.x);
+			SETFOUND(Znonce.x);
 		if (ZA[924].y == 0x136032EDU)
 		if (ZA[924].y == 0x136032EDU)
-			SETFOUND(found, Znonce.y);
+			SETFOUND(Znonce.y);
 	}
 	}
 #else
 #else
-	if (ZA[924] == 0x136032EDU) {
-		uint found;
-
-		SETFOUND(found, Znonce);
-	}
+	if (ZA[924] == 0x136032EDU)
+		SETFOUND(Znonce);
 #endif
 #endif
 }
 }

+ 10 - 24
diakgcn120823.cl

@@ -574,45 +574,31 @@ __kernel
 #define FOUND (0x0F)
 #define FOUND (0x0F)
 
 
 #if defined(OCL1)
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 #endif
 
 
 #ifdef VECTORS4
 #ifdef VECTORS4
 	if ((V[7].x == 0x136032edU) ^ (V[7].y == 0x136032edU) ^ (V[7].z == 0x136032edU) ^ (V[7].w == 0x136032edU)) {
 	if ((V[7].x == 0x136032edU) ^ (V[7].y == 0x136032edU) ^ (V[7].z == 0x136032edU) ^ (V[7].w == 0x136032edU)) {
-		uint found;
-
 		if (V[7].x == 0x136032edU)
 		if (V[7].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (V[7].y == 0x136032edU)
 		if (V[7].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 		if (V[7].z == 0x136032edU)
 		if (V[7].z == 0x136032edU)
-			SETFOUND(found, nonce.z);
+			SETFOUND(nonce.z);
 		if (V[7].w == 0x136032edU)
 		if (V[7].w == 0x136032edU)
-			SETFOUND(found, nonce.w);
+			SETFOUND(nonce.w);
 	}
 	}
 #elif defined VECTORS2
 #elif defined VECTORS2
 	if ((V[7].x == 0x136032edU) + (V[7].y == 0x136032edU)) {
 	if ((V[7].x == 0x136032edU) + (V[7].y == 0x136032edU)) {
-		uint found;
-
 		if (V[7].x == 0x136032edU)
 		if (V[7].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (V[7].y == 0x136032edU)
 		if (V[7].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 	}
 	}
 #else
 #else
-	if (V[7] == 0x136032edU) {
-		uint found;
-
-		SETFOUND(found, nonce);
-	}
+	if (V[7] == 0x136032edU)
+		SETFOUND(nonce);
 #endif
 #endif
 }
 }

+ 39 - 46
miner.c

@@ -70,6 +70,7 @@ struct workio_cmd {
 	enum workio_commands	cmd;
 	enum workio_commands	cmd;
 	struct thr_info		*thr;
 	struct thr_info		*thr;
 	struct work		*work;
 	struct work		*work;
+	struct pool		*pool;
 	bool			needed;
 	bool			needed;
 
 
 	struct list_head list;
 	struct list_head list;
@@ -202,7 +203,6 @@ int total_accepted, total_rejected, total_diff1;
 float total_accepted_weighed;
 float total_accepted_weighed;
 int total_getworks, total_stale, total_discarded;
 int total_getworks, total_stale, total_discarded;
 static int total_queued, staged_rollable;
 static int total_queued, staged_rollable;
-static int queued_getworks;
 unsigned int new_blocks;
 unsigned int new_blocks;
 unsigned int found_blocks;
 unsigned int found_blocks;
 
 
@@ -2439,17 +2439,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
 /* This is overkill, but at least we'll know accurately how much work is
  * queued to prevent ever being left without work */
  * queued to prevent ever being left without work */
-static void inc_queued(void)
+static void inc_queued(struct pool *pool)
 {
 {
 	mutex_lock(&qd_lock);
 	mutex_lock(&qd_lock);
 	total_queued++;
 	total_queued++;
+	pool->queued++;
 	mutex_unlock(&qd_lock);
 	mutex_unlock(&qd_lock);
 }
 }
 
 
-static void dec_queued(void)
+static void dec_queued(struct pool *pool)
 {
 {
 	mutex_lock(&qd_lock);
 	mutex_lock(&qd_lock);
 	total_queued--;
 	total_queued--;
+	pool->queued--;
 	mutex_unlock(&qd_lock);
 	mutex_unlock(&qd_lock);
 }
 }
 
 
@@ -2568,32 +2570,26 @@ out:
 	return cloned;
 	return cloned;
 }
 }
 
 
+static bool queue_request(struct thr_info *thr, bool needed);
+
 static void *get_work_thread(void *userdata)
 static void *get_work_thread(void *userdata)
 {
 {
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
 	struct workio_cmd *wc = (struct workio_cmd *)userdata;
-	int ts, tq, maxq = opt_queue + mining_threads;
 	struct pool *pool = current_pool();
 	struct pool *pool = current_pool();
 	struct work *ret_work= NULL;
 	struct work *ret_work= NULL;
 	struct curl_ent *ce = NULL;
 	struct curl_ent *ce = NULL;
-	bool lagging = false;
 
 
 	pthread_detach(pthread_self());
 	pthread_detach(pthread_self());
 	rename_thr("bfg-get_work");
 	rename_thr("bfg-get_work");
 
 
 	applog(LOG_DEBUG, "Creating extra get work thread");
 	applog(LOG_DEBUG, "Creating extra get work thread");
 
 
-retry:
-	tq = global_queued();
-	ts = total_staged();
-
-	if (ts >= maxq)
-		goto out;
-
-	if (ts >= opt_queue && tq >= maxq)
-		goto out;
+	pool = wc->pool;
 
 
-	if (clone_available())
+	if (clone_available()) {
+		dec_queued(pool);
 		goto out;
 		goto out;
+	}
 
 
 	ret_work = make_work();
 	ret_work = make_work();
 	if (wc->thr)
 	if (wc->thr)
@@ -2605,32 +2601,19 @@ retry:
 		get_benchmark_work(ret_work);
 		get_benchmark_work(ret_work);
 		ret_work->queued = true;
 		ret_work->queued = true;
 	} else {
 	} else {
-
-		if (!ts)
-			lagging = true;
-		pool = ret_work->pool = select_pool(lagging);
-
-		inc_queued();
+		ret_work->pool = wc->pool;
 
 
 		if (!ce)
 		if (!ce)
 			ce = pop_curl_entry(pool);
 			ce = pop_curl_entry(pool);
 
 
-		/* Check that we haven't staged work via other threads while
-		 * waiting for a curl entry */
-		if (total_staged() >= maxq) {
-			dec_queued();
-			free_work(ret_work);
-			goto out;
-		}
-
 		/* obtain new work from bitcoin via JSON-RPC */
 		/* obtain new work from bitcoin via JSON-RPC */
 		if (!get_upstream_work(ret_work, ce->curl)) {
 		if (!get_upstream_work(ret_work, ce->curl)) {
 			/* pause, then restart work-request loop */
 			/* pause, then restart work-request loop */
 			applog(LOG_DEBUG, "json_rpc_call failed on get work, retrying");
 			applog(LOG_DEBUG, "json_rpc_call failed on get work, retrying");
-			lagging = true;
-			dec_queued();
+			dec_queued(pool);
+			queue_request(ret_work->thr, wc->needed);
 			free_work(ret_work);
 			free_work(ret_work);
-			goto retry;
+			goto out;
 		}
 		}
 
 
 		ret_work->queued = true;
 		ret_work->queued = true;
@@ -2649,9 +2632,6 @@ out:
 	workio_cmd_free(wc);
 	workio_cmd_free(wc);
 	if (ce)
 	if (ce)
 		push_curl_entry(ce, pool);
 		push_curl_entry(ce, pool);
-	mutex_lock(&control_lock);
-	queued_getworks--;
-	mutex_unlock(&control_lock);
 	return NULL;
 	return NULL;
 }
 }
 
 
@@ -2897,8 +2877,6 @@ static struct pool *priority_pool(int choice)
 	return ret;
 	return ret;
 }
 }
 
 
-static bool queue_request(struct thr_info *thr, bool needed);
-
 void switch_pools(struct pool *selected)
 void switch_pools(struct pool *selected)
 {
 {
 	struct pool *pool, *last_pool;
 	struct pool *pool, *last_pool;
@@ -2999,6 +2977,7 @@ static void discard_stale(void)
 	HASH_ITER(hh, staged_work, work, tmp) {
 	HASH_ITER(hh, staged_work, work, tmp) {
 		if (stale_work(work, false)) {
 		if (stale_work(work, false)) {
 			HASH_DEL(staged_work, work);
 			HASH_DEL(staged_work, work);
+			work->pool->staged--;
 			discard_work(work);
 			discard_work(work);
 			stale++;
 			stale++;
 		}
 		}
@@ -3288,9 +3267,11 @@ static bool hash_push(struct work *work)
 	pthread_cond_signal(&getq->cond);
 	pthread_cond_signal(&getq->cond);
 	mutex_unlock(stgd_lock);
 	mutex_unlock(stgd_lock);
 
 
+	work->pool->staged++;
+
 	if (work->queued) {
 	if (work->queued) {
 		work->queued = false;
 		work->queued = false;
-		dec_queued();
+		dec_queued(work->pool);
 	}
 	}
 
 
 	return rc;
 	return rc;
@@ -4342,18 +4323,28 @@ static void pool_resus(struct pool *pool)
 
 
 static bool queue_request(struct thr_info *thr, bool needed)
 static bool queue_request(struct thr_info *thr, bool needed)
 {
 {
+	int ts, tq, maxq = opt_queue + mining_threads;
+	struct pool *pool, *cp;
 	struct workio_cmd *wc;
 	struct workio_cmd *wc;
-	bool doq = true;
 
 
-	mutex_lock(&control_lock);
-	if (queued_getworks > (mining_threads + opt_queue) * 2)
-		doq = false;
+	ts = total_staged();
+	tq = global_queued();
+	if (ts && ts + tq >= maxq)
+		return true;
+
+	cp = current_pool();
+	if ((!needed || opt_fail_only) && (cp->staged + cp->queued >= maxq))
+		return true;
+
+	if (needed && !ts)
+		pool = select_pool(true);
 	else
 	else
-		queued_getworks++;
-	mutex_unlock(&control_lock);
-	if (!doq)
+		pool = cp;
+	if (pool->staged + pool->queued >= maxq)
 		return true;
 		return true;
-	
+
+	inc_queued(pool);
+
 	/* 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)) {
@@ -4363,6 +4354,7 @@ static bool queue_request(struct thr_info *thr, bool needed)
 
 
 	wc->cmd = WC_GET_WORK;
 	wc->cmd = WC_GET_WORK;
 	wc->thr = thr;
 	wc->thr = thr;
+	wc->pool = pool;
 	wc->needed = needed;
 	wc->needed = needed;
 
 
 	applog(LOG_DEBUG, "Queueing getwork request to work thread");
 	applog(LOG_DEBUG, "Queueing getwork request to work thread");
@@ -4398,6 +4390,7 @@ static struct work *hash_pop(const struct timespec *abstime)
 		} else
 		} else
 			work = staged_work;
 			work = staged_work;
 		HASH_DEL(staged_work, work);
 		HASH_DEL(staged_work, work);
+		work->pool->staged--;
 		if (work_rollable(work))
 		if (work_rollable(work))
 			staged_rollable--;
 			staged_rollable--;
 	}
 	}

+ 3 - 0
miner.h

@@ -787,6 +787,9 @@ struct pool {
 	int solved;
 	int solved;
 	int diff1;
 	int diff1;
 
 
+	int queued;
+	int staged;
+
 	bool submit_fail;
 	bool submit_fail;
 	bool idle;
 	bool idle;
 	bool lagging;
 	bool lagging;

+ 10 - 24
phatk120823.cl

@@ -390,47 +390,33 @@ void search(	const uint state0, const uint state1, const uint state2, const uint
 #define FOUND (0x0F)
 #define FOUND (0x0F)
 
 
 #if defined(OCL1)
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 #endif
 
 
 #ifdef VECTORS4
 #ifdef VECTORS4
 	bool result = W[117].x & W[117].y & W[117].z & W[117].w;
 	bool result = W[117].x & W[117].y & W[117].z & W[117].w;
 	if (!result) {
 	if (!result) {
-		uint found;
-
 		if (!W[117].x)
 		if (!W[117].x)
-			SETFOUND(found, W[3].x);
+			SETFOUND(W[3].x);
 		if (!W[117].y)
 		if (!W[117].y)
-			SETFOUND(found, W[3].y);
+			SETFOUND(W[3].y);
 		if (!W[117].z)
 		if (!W[117].z)
-			SETFOUND(found, W[3].z);
+			SETFOUND(W[3].z);
 		if (!W[117].w)
 		if (!W[117].w)
-			SETFOUND(found, W[3].w);
+			SETFOUND(W[3].w);
 	}
 	}
 #elif defined VECTORS2
 #elif defined VECTORS2
 	bool result = W[117].x & W[117].y;
 	bool result = W[117].x & W[117].y;
 	if (!result) {
 	if (!result) {
-		uint found;
-
 		if (!W[117].x)
 		if (!W[117].x)
-			SETFOUND(found, W[3].x);
+			SETFOUND(W[3].x);
 		if (!W[117].y)
 		if (!W[117].y)
-			SETFOUND(found, W[3].y);
+			SETFOUND(W[3].y);
 	}
 	}
 #else
 #else
-	if (!W[117]) {
-		uint found;
-
-		SETFOUND(found, W[3]);
-	}
+	if (!W[117])
+		SETFOUND(W[3]);
 #endif
 #endif
 }
 }

+ 8 - 21
poclbm120823.cl

@@ -1324,39 +1324,26 @@ Vals[2]+=ch(Vals[1],Vals[4],Vals[3]);
 #define FOUND (0x0F)
 #define FOUND (0x0F)
 
 
 #if defined(OCL1)
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 #endif
 
 
 #if defined(VECTORS2) || defined(VECTORS4)
 #if defined(VECTORS2) || defined(VECTORS4)
-
 	if (any(Vals[2] == 0x136032edU)) {
 	if (any(Vals[2] == 0x136032edU)) {
-		uint found;
-
 		if (Vals[2].x == 0x136032edU)
 		if (Vals[2].x == 0x136032edU)
-			SETFOUND(found, nonce.x);
+			SETFOUND(nonce.x);
 		if (Vals[2].y == 0x136032edU)
 		if (Vals[2].y == 0x136032edU)
-			SETFOUND(found, nonce.y);
+			SETFOUND(nonce.y);
 #if defined(VECTORS4)
 #if defined(VECTORS4)
 		if (Vals[2].z == 0x136032edU)
 		if (Vals[2].z == 0x136032edU)
-			SETFOUND(found, nonce.z);
+			SETFOUND(nonce.z);
 		if (Vals[2].w == 0x136032edU)
 		if (Vals[2].w == 0x136032edU)
-			SETFOUND(found, nonce.w);
+			SETFOUND(nonce.w);
 #endif
 #endif
 	}
 	}
 #else
 #else
-	if (Vals[2] == 0x136032edU) {
-		uint found;
-
-		SETFOUND(found, nonce);
-	}
+	if (Vals[2] == 0x136032edU)
+		SETFOUND(nonce);
 #endif
 #endif
 }
 }

+ 4 - 14
scrypt120823.cl

@@ -685,16 +685,9 @@ void scrypt_core(uint4 X[8], __global uint4*restrict lookup)
 #define FOUND (0x0F)
 #define FOUND (0x0F)
 
 
 #if defined(OCL1)
 #if defined(OCL1)
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		(Xfound) = output[FOUND];	\
-		output[FOUND] += 1;		\
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[output[FOUND]++] = Xnonce
 #else
 #else
-	#define SETFOUND(Xfound, Xnonce) do {	\
-		Xfound = atomic_add(&output[FOUND], 1); \
-		output[Xfound] = Xnonce;	\
-	} while (0)
+	#define SETFOUND(Xnonce) output[atomic_add(&output[FOUND], 1)] = Xnonce
 #endif
 #endif
 
 
 __attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
 __attribute__((reqd_work_group_size(WORKSIZE, 1, 1)))
@@ -734,11 +727,8 @@ const uint4 midstate0, const uint4 midstate16, const uint target)
 	SHA256(&ostate0,&ostate1, tmp0, tmp1, (uint4)(0x80000000U, 0U, 0U, 0U), (uint4)(0U, 0U, 0U, 0x300U));
 	SHA256(&ostate0,&ostate1, tmp0, tmp1, (uint4)(0x80000000U, 0U, 0U, 0U), (uint4)(0U, 0U, 0U, 0x300U));
 
 
 	bool result = (EndianSwap(ostate1.w) <= target);
 	bool result = (EndianSwap(ostate1.w) <= target);
-	if (result) {
-		uint found;
-
-		SETFOUND(found, gid);
-	}
+	if (result)
+		SETFOUND(gid);
 }
 }
 
 
 /*-
 /*-