Browse Source

Since scrypt miners tend to work at actual share difficulty, use that for diff1 counting

Luke Dashjr 12 years ago
parent
commit
f25f16e99b
4 changed files with 38 additions and 15 deletions
  1. 3 0
      driver-cpu.c
  2. 1 0
      driver-opencl.c
  3. 19 13
      miner.c
  4. 15 2
      miner.h

+ 3 - 0
driver-cpu.c

@@ -816,6 +816,9 @@ static bool cpu_thread_init(struct thr_info *thr)
 
 
 	cgpu->kname = algo_names[opt_algo];
 	cgpu->kname = algo_names[opt_algo];
 	
 	
+	if (opt_algo == ALGO_SCRYPT)
+		cgpu->min_nonce_diff = 1./0x10000;
+	
 	/* Set worker threads to nice 19 and then preferentially to SCHED_IDLE
 	/* Set worker threads to nice 19 and then preferentially to SCHED_IDLE
 	 * and if that fails, then SCHED_BATCH. No need for this to be an
 	 * and if that fails, then SCHED_BATCH. No need for this to be an
 	 * error if it fails */
 	 * error if it fails */

+ 1 - 0
driver-opencl.c

@@ -1610,6 +1610,7 @@ static bool opencl_thread_init(struct thr_info *thr)
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT
 		case KL_SCRYPT:
 		case KL_SCRYPT:
 			thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
 			thrdata->queue_kernel_parameters = &queue_scrypt_kernel;
+			gpu->min_nonce_diff = 1./0x10000;
 			break;
 			break;
 #endif
 #endif
 		default:
 		default:

+ 19 - 13
miner.c

@@ -159,10 +159,8 @@ int opt_g_threads = -1;
 #ifdef USE_SCRYPT
 #ifdef USE_SCRYPT
 static char detect_algo = 1;
 static char detect_algo = 1;
 bool opt_scrypt;
 bool opt_scrypt;
-float nonce_diff = 1;
 #else
 #else
 static char detect_algo;
 static char detect_algo;
-const float nonce_diff = 1;
 #endif
 #endif
 bool opt_restart = true;
 bool opt_restart = true;
 
 
@@ -8902,6 +8900,20 @@ struct work *get_work(struct thr_info *thr)
 	if (timercmp(&tv_get, &pool_stats->getwork_wait_min, <))
 	if (timercmp(&tv_get, &pool_stats->getwork_wait_min, <))
 		pool_stats->getwork_wait_min = tv_get;
 		pool_stats->getwork_wait_min = tv_get;
 	++pool_stats->getwork_calls;
 	++pool_stats->getwork_calls;
+	
+	if (work->work_difficulty < 1)
+	{
+		if (unlikely(work->work_difficulty < cgpu->min_nonce_diff))
+		{
+			applog(LOG_WARNING, "%"PRIpreprv": Using work with lower difficulty than device supports",
+			       cgpu->proc_repr);
+			work->nonce_diff = cgpu->min_nonce_diff;
+		}
+		else
+			work->nonce_diff = work->work_difficulty;
+	}
+	else
+		work->nonce_diff = 1;
 
 
 	return work;
 	return work;
 }
 }
@@ -8928,7 +8940,7 @@ static void submit_work_async2(struct work *work, struct timeval *tv_work_found)
 	_submit_work_async(work);
 	_submit_work_async(work);
 }
 }
 
 
-void inc_hw_errors2(struct thr_info *thr, const struct work *work, const uint32_t *bad_nonce_p)
+void inc_hw_errors3(struct thr_info *thr, const struct work *work, const uint32_t *bad_nonce_p, float nonce_diff)
 {
 {
 	struct cgpu_info * const cgpu = thr->cgpu;
 	struct cgpu_info * const cgpu = thr->cgpu;
 	
 	
@@ -8956,11 +8968,6 @@ void inc_hw_errors2(struct thr_info *thr, const struct work *work, const uint32_
 		thr->cgpu->drv->hw_error(thr);
 		thr->cgpu->drv->hw_error(thr);
 }
 }
 
 
-void inc_hw_errors(struct thr_info *thr, const struct work *work, const uint32_t bad_nonce)
-{
-	inc_hw_errors2(thr, work, work ? &bad_nonce : NULL);
-}
-
 enum test_nonce2_result hashtest2(struct work *work, bool checktarget)
 enum test_nonce2_result hashtest2(struct work *work, bool checktarget)
 {
 {
 	uint32_t *hash2_32 = (uint32_t *)&work->hash[0];
 	uint32_t *hash2_32 = (uint32_t *)&work->hash[0];
@@ -9032,9 +9039,9 @@ bool submit_noffset_nonce(struct thr_info *thr, struct work *work_in, uint32_t n
 		}
 		}
 	
 	
 	mutex_lock(&stats_lock);
 	mutex_lock(&stats_lock);
-	total_diff1       += nonce_diff;
-	thr ->cgpu->diff1 += nonce_diff;
-	work->pool->diff1 += nonce_diff;
+	total_diff1       += work->nonce_diff;
+	thr ->cgpu->diff1 += work->nonce_diff;
+	work->pool->diff1 += work->nonce_diff;
 	thr->cgpu->last_device_valid_work = time(NULL);
 	thr->cgpu->last_device_valid_work = time(NULL);
 	mutex_unlock(&stats_lock);
 	mutex_unlock(&stats_lock);
 	
 	
@@ -10638,6 +10645,7 @@ void allocate_cgpu(struct cgpu_info *cgpu, unsigned int *kp)
 	}
 	}
 
 
 	cgpu->max_hashes = 0;
 	cgpu->max_hashes = 0;
+	BFGINIT(cgpu->min_nonce_diff, 1);
 
 
 	// Setup thread structs before starting any of the threads, in case they try to interact
 	// Setup thread structs before starting any of the threads, in case they try to interact
 	for (j = 0; j < threadobj; ++j, ++*kp) {
 	for (j = 0; j < threadobj; ++j, ++*kp) {
@@ -11509,8 +11517,6 @@ int main(int argc, char *argv[])
 		applog(LOG_NOTICE, "Detected scrypt algorithm");
 		applog(LOG_NOTICE, "Detected scrypt algorithm");
 		opt_scrypt = true;
 		opt_scrypt = true;
 	}
 	}
-	if (opt_scrypt)
-		nonce_diff = 1. / 0x10000;
 #endif
 #endif
 	detect_algo = 0;
 	detect_algo = 0;
 
 

+ 15 - 2
miner.h

@@ -589,6 +589,9 @@ struct cgpu_info {
 
 
 	bool disable_watchdog;
 	bool disable_watchdog;
 	bool shutdown;
 	bool shutdown;
+	
+	// Lowest difficulty supported for finding nonces
+	float min_nonce_diff;
 };
 };
 
 
 extern void renumber_cgpu(struct cgpu_info *);
 extern void renumber_cgpu(struct cgpu_info *);
@@ -1373,6 +1376,7 @@ struct work {
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 	
 	
 	double		work_difficulty;
 	double		work_difficulty;
+	float		nonce_diff;
 
 
 	// Allow devices to identify work if multiple sub-devices
 	// Allow devices to identify work if multiple sub-devices
 	// DEPRECATED: New code should be using multiple processors instead
 	// DEPRECATED: New code should be using multiple processors instead
@@ -1404,9 +1408,18 @@ extern void get_datestamp(char *, size_t, time_t);
 extern void stratum_work_cpy(struct stratum_work *dst, const struct stratum_work *src);
 extern void stratum_work_cpy(struct stratum_work *dst, const struct stratum_work *src);
 extern void stratum_work_clean(struct stratum_work *);
 extern void stratum_work_clean(struct stratum_work *);
 extern void gen_stratum_work2(struct work *, struct stratum_work *, const char *nonce1);
 extern void gen_stratum_work2(struct work *, struct stratum_work *, const char *nonce1);
-extern void inc_hw_errors2(struct thr_info *thr, const struct work *work, const uint32_t *bad_nonce_p);
+extern void inc_hw_errors3(struct thr_info *thr, const struct work *work, const uint32_t *bad_nonce_p, float nonce_diff);
+static inline
+void inc_hw_errors2(struct thr_info * const thr, const struct work * const work, const uint32_t *bad_nonce_p)
+{
+	inc_hw_errors3(thr, work, bad_nonce_p, work ? work->nonce_diff : 1.);
+}
 #define UNKNOWN_NONCE ((uint32_t*)inc_hw_errors2)
 #define UNKNOWN_NONCE ((uint32_t*)inc_hw_errors2)
-extern void inc_hw_errors(struct thr_info *, const struct work *, const uint32_t bad_nonce);
+static inline
+void inc_hw_errors(struct thr_info * const thr, const struct work * const work, const uint32_t bad_nonce)
+{
+	inc_hw_errors2(thr, work, work ? &bad_nonce : NULL);
+}
 #define inc_hw_errors_only(thr)  inc_hw_errors(thr, NULL, 0)
 #define inc_hw_errors_only(thr)  inc_hw_errors(thr, NULL, 0)
 enum test_nonce2_result {
 enum test_nonce2_result {
 	TNR_GOOD = 1,
 	TNR_GOOD = 1,