From 1a7a87c2a67b3fc5911e68f1300f81f59bc956cc Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 11 May 2013 20:29:48 +1000 Subject: [PATCH] Use a discrete device target for scrypt that dynamically changes to ensure we still report a work utility even if no shares are submitted such as in solo mining. --- cgminer.c | 23 ++++++++++++++++++++++- driver-opencl.c | 2 +- miner.h | 4 ++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/cgminer.c b/cgminer.c index 04d00db2..0964f529 100644 --- a/cgminer.c +++ b/cgminer.c @@ -5566,7 +5566,26 @@ static void hash_sole_work(struct thr_info *mythr) "mining thread %d", thr_id); break; } - work->device_diff = MIN(drv->max_diff, work->work_difficulty); + work->device_diff = MIN(drv->working_diff, work->work_difficulty); +#ifdef USE_SCRYPT + /* Dynamically adjust the working diff even if the target + * diff is very high to ensure we can still validate scrypt is + * returning shares. */ + if (opt_scrypt) { + double wu; + + wu = total_diff1 / total_secs * 60; + if (wu > 30 && drv->working_diff < drv->max_diff && + drv->working_diff < work->work_difficulty) { + drv->working_diff++; + applog(LOG_DEBUG, "Driver %s working diff changed to %.0f", + drv->dname, drv->working_diff); + work->device_diff = MIN(drv->working_diff, work->work_difficulty); + } else if (drv->working_diff > work->work_difficulty) + drv->working_diff = work->work_difficulty; + set_target(work->device_target, work->device_diff); + } +#endif do { cgtime(&tv_start); @@ -6821,6 +6840,8 @@ void fill_device_drv(struct cgpu_info *cgpu) drv->queue_full = &noop_queue_full; if (!drv->max_diff) drv->max_diff = 1; + if (!drv->working_diff) + drv->working_diff = 1; } void enable_device(struct cgpu_info *cgpu) diff --git a/driver-opencl.c b/driver-opencl.c index 8168aa95..de63b139 100644 --- a/driver-opencl.c +++ b/driver-opencl.c @@ -1081,7 +1081,7 @@ static cl_int queue_scrypt_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_u cl_uint le_target; cl_int status = 0; - le_target = *(cl_uint *)(blk->work->target + 28); + le_target = *(cl_uint *)(blk->work->device_target + 28); clState->cldata = blk->work->data; status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, 80, clState->cldata, 0, NULL,NULL); diff --git a/miner.h b/miner.h index d76b44c0..471b3727 100644 --- a/miner.h +++ b/miner.h @@ -336,6 +336,7 @@ struct device_drv { /* Highest target diff the device supports */ double max_diff; + double working_diff; }; extern struct device_drv *copy_drv(struct device_drv*); @@ -1161,6 +1162,9 @@ struct work { unsigned char target[32]; unsigned char hash[32]; +#ifdef USE_SCRYPT + unsigned char device_target[32]; +#endif double device_diff; uint64_t share_diff;