Commit 0a3095ae2a6b022f1623a597f18ba8a4b886d539

Con Kolivas 2014-05-10T22:22:06

Make the work given in benchmark mode deterministic on a per-device basis

diff --git a/cgminer.c b/cgminer.c
index 98c9c7b..46e4aa7 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3468,19 +3468,6 @@ static unsigned char bench_target[32];
  * diff 32+ share every 32 work items. */
 static void get_benchmark_work(struct work *work)
 {
-	static int hidiff = 0, lodiff = 0;
-	static int direction = 1;
-
-	lodiff += direction;
-	if (lodiff < 1)
-		direction = 1;
-	if (lodiff > 15) {
-		direction = -1;
-		if (++hidiff > 15)
-			hidiff = 0;
-		memcpy(work, &bench_hidiff_bins[hidiff][0], 160);
-	} else
-		memcpy(work, &bench_lodiff_bins[lodiff][0], 160);
 	work->work_difficulty = 32;
 	memcpy(work->target, bench_target, 32);
 	work->drv_rolllimit = 0;
@@ -7004,8 +6991,23 @@ int share_work_tdiff(struct cgpu_info *cgpu)
 	return last_getwork - cgpu->last_device_valid_work;
 }
 
+static void set_benchmark_work(struct cgpu_info *cgpu, struct work *work)
+{
+	cgpu->lodiff += cgpu->direction;
+	if (cgpu->lodiff < 1)
+		cgpu->direction = 1;
+	if (cgpu->lodiff > 15) {
+		cgpu->direction = -1;
+		if (++cgpu->hidiff > 15)
+			cgpu->hidiff = 0;
+		memcpy(work, &bench_hidiff_bins[cgpu->hidiff][0], 160);
+	} else
+		memcpy(work, &bench_lodiff_bins[cgpu->lodiff][0], 160);
+}
+
 struct work *get_work(struct thr_info *thr, const int thr_id)
 {
+	struct cgpu_info *cgpu = thr->cgpu;
 	struct work *work = NULL;
 	time_t diff_t;
 
@@ -7025,14 +7027,17 @@ struct work *get_work(struct thr_info *thr, const int thr_id)
 	 * device failures. */
 	if (diff_t > 0) {
 		applog(LOG_DEBUG, "Get work blocked for %d seconds", (int)diff_t);
-		thr->cgpu->last_device_valid_work += diff_t;
+		cgpu->last_device_valid_work += diff_t;
 	}
 	applog(LOG_DEBUG, "Got work from get queue to get work for thread %d", thr_id);
 
 	work->thr_id = thr_id;
+	if (opt_benchmark)
+		set_benchmark_work(cgpu, work);
+
 	thread_reportin(thr);
 	work->mined = true;
-	work->device_diff = MIN(thr->cgpu->drv->max_diff, work->work_difficulty);
+	work->device_diff = MIN(cgpu->drv->max_diff, work->work_difficulty);
 	return work;
 }
 
diff --git a/miner.h b/miner.h
index 3189842..7b79010 100644
--- a/miner.h
+++ b/miner.h
@@ -517,6 +517,11 @@ struct cgpu_info {
 	bool shutdown;
 
 	struct timeval dev_start_tv;
+
+	/* For benchmarking only */
+	int hidiff;
+	int lodiff;
+	int direction;
 };
 
 extern bool add_cgpu(struct cgpu_info*);