Make the work given in benchmark mode deterministic on a per-device basis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
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*);