From 2f86a02d612289c10d5a64a389cd8c2db57da8b3 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 7 Oct 2014 09:03:17 +1100 Subject: [PATCH 01/16] Allow arbitrary clamping of lower device diffs for slow controllers by driver --- cgminer.c | 3 +++ miner.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/cgminer.c b/cgminer.c index 41b2a16214..2f88df13cf 100644 --- a/cgminer.c +++ b/cgminer.c @@ -7141,6 +7141,7 @@ bool submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *r work->mined = true; work->device_diff = MIN(drv->max_diff, work->work_difficulty); + work->device_diff = MAX(drv->min_diff, work->device_diff); ret = submit_nonce(thr, work, nonce); free_work(work); @@ -7429,6 +7430,7 @@ struct work *get_work(struct thr_info *thr, const int thr_id) thread_reportin(thr); work->mined = true; work->device_diff = MIN(cgpu->drv->max_diff, work->work_difficulty); + work->device_diff = MAX(cgpu->drv->min_diff, work->device_diff); return work; } @@ -7735,6 +7737,7 @@ static void hash_sole_work(struct thr_info *mythr) break; } work->device_diff = MIN(drv->max_diff, work->work_difficulty); + work->device_diff = MAX(drv->min_diff, work->device_diff); do { cgtime(&tv_start); diff --git a/miner.h b/miner.h index d999d16509..2f79ece855 100644 --- a/miner.h +++ b/miner.h @@ -367,6 +367,9 @@ struct device_drv { /* Highest target diff the device supports */ double max_diff; + + /* Lowest diff the controller can safely run at */ + double min_diff; }; extern struct device_drv *copy_drv(struct device_drv*); From 52ee94011b87d5e5a54dddcc5ccf949a49ce273f Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Mon, 6 Oct 2014 15:18:45 -0700 Subject: [PATCH 02/16] add mindiff to bitmain driver --- driver-bitmain.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-bitmain.c b/driver-bitmain.c index 6b3a450ec6..43aba3eb43 100644 --- a/driver-bitmain.c +++ b/driver-bitmain.c @@ -2494,4 +2494,5 @@ struct device_drv bitmain_drv = { .get_statline_before = get_bitmain_statline_before, .reinit_device = bitmain_init, .thread_shutdown = bitmain_shutdown, + .min_diff = 16, }; From 7ff402681170e672ad3bb6c954b45680c787cb28 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 7 Oct 2014 09:22:30 +1100 Subject: [PATCH 03/16] Set min_diff to 1 --- cgminer.c | 1 + 1 file changed, 1 insertion(+) diff --git a/cgminer.c b/cgminer.c index 2f88df13cf..8a955660e3 100644 --- a/cgminer.c +++ b/cgminer.c @@ -9376,6 +9376,7 @@ void null_device_drv(struct device_drv *drv) drv->zero_stats = &noop_zero_stats; drv->max_diff = 1; + drv->min_diff = 1; } void enable_device(struct cgpu_info *cgpu) From dd3a7d349a73c3125e09976eb05c68522739c777 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 15:34:39 +1100 Subject: [PATCH 04/16] Expand lowmem to not track stratum shares --- cgminer.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/cgminer.c b/cgminer.c index 8a955660e3..4369b0cba9 100644 --- a/cgminer.c +++ b/cgminer.c @@ -6268,13 +6268,15 @@ static bool parse_stratum_response(struct pool *pool, char *s) id = json_integer_value(id_val); - mutex_lock(&sshare_lock); - HASH_FIND_INT(stratum_shares, &id, sshare); - if (sshare) { - HASH_DEL(stratum_shares, sshare); - pool->sshares--; + if (!opt_lowmem) { + mutex_lock(&sshare_lock); + HASH_FIND_INT(stratum_shares, &id, sshare); + if (sshare) { + HASH_DEL(stratum_shares, sshare); + pool->sshares--; + } + mutex_unlock(&sshare_lock); } - mutex_unlock(&sshare_lock); if (!sshare) { double pool_diff; @@ -6286,7 +6288,8 @@ static bool parse_stratum_response(struct pool *pool, char *s) cg_runlock(&pool->data_lock); if (json_is_true(res_val)) { - applog(LOG_NOTICE, "Accepted untracked stratum share from pool %d", pool->pool_no); + applog(LOG_NOTICE, "Accepted%s stratum share from pool %d", + opt_lowmem ? "" : " untracked", pool->pool_no); /* We don't know what device this came from so we can't * attribute the work to the relevant cgpu */ @@ -6297,7 +6300,8 @@ static bool parse_stratum_response(struct pool *pool, char *s) pool->diff_accepted += pool_diff; mutex_unlock(&stats_lock); } else { - applog(LOG_NOTICE, "Rejected untracked stratum share from pool %d", pool->pool_no); + applog(LOG_NOTICE, "Rejected %s stratum share from pool %d", + opt_lowmem ? "" : " untracked", pool->pool_no); mutex_lock(&stats_lock); total_rejected++; @@ -6626,12 +6630,14 @@ static void *stratum_sthread(void *userdata) if (pool_tclear(pool, &pool->submit_fail)) applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no); - mutex_lock(&sshare_lock); - HASH_ADD_INT(stratum_shares, id, sshare); - pool->sshares++; - mutex_unlock(&sshare_lock); + if (!opt_lowmem) { + mutex_lock(&sshare_lock); + HASH_ADD_INT(stratum_shares, id, sshare); + pool->sshares++; + mutex_unlock(&sshare_lock); - applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db"); + applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db"); + } submitted = true; break; } From 692abd8cdc8ed67e6c9cdbc0fb0172e0ca5f2fc7 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 15:40:57 +1100 Subject: [PATCH 05/16] Notify but still submit stale shares in bitmain --- driver-bitmain.c | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/driver-bitmain.c b/driver-bitmain.c index 43aba3eb43..aafac562e7 100644 --- a/driver-bitmain.c +++ b/driver-bitmain.c @@ -1289,30 +1289,28 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info free(ob_hex); } - if(work->work_block < info->last_work_block) { - applog(LOG_ERR, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id); - } else { - if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) { - cg_logwork_uint32(work, rxnoncedata.nonces[j].nonce, true); - if(opt_bitmain_hwerror) { + if(work->work_block < info->last_work_block) + applog(LOG_NOTICE, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id); + if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) { + cg_logwork_uint32(work, rxnoncedata.nonces[j].nonce, true); + if(opt_bitmain_hwerror) { #ifndef BITMAIN_CALC_DIFF1 - mutex_lock(&info->qlock); - idiff = (int)work->sdiff; - info->nonces+=idiff; - info->auto_nonces+=idiff; - mutex_unlock(&info->qlock); - inc_work_status(thr, pool, idiff); + mutex_lock(&info->qlock); + idiff = (int)work->sdiff; + info->nonces+=idiff; + info->auto_nonces+=idiff; + mutex_unlock(&info->qlock); + inc_work_status(thr, pool, idiff); #endif - } else { - mutex_lock(&info->qlock); - info->nonces++; - info->auto_nonces++; - mutex_unlock(&info->qlock); - } - } else { - //bitmain_inc_nvw(info, thr); - applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id); - } + } else { + mutex_lock(&info->qlock); + info->nonces++; + info->auto_nonces++; + mutex_unlock(&info->qlock); + } + } else { + //bitmain_inc_nvw(info, thr); + applog(LOG_ERR, "BitMain: bitmain_decode_nonce error work(%d)", rxnoncedata.nonces[j].work_id); } free_work(work); } else { From ee0a6b0a68f7f2e62ab0c19b6c620d984c8f57c1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 16:27:30 +1100 Subject: [PATCH 06/16] Make work stale error debug for bitmain --- driver-bitmain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-bitmain.c b/driver-bitmain.c index aafac562e7..2cf20f1a68 100644 --- a/driver-bitmain.c +++ b/driver-bitmain.c @@ -1290,7 +1290,7 @@ static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info } if(work->work_block < info->last_work_block) - applog(LOG_NOTICE, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id); + applog(LOG_DEBUG, "BitMain: bitmain_parse_rxnonce work(%d) nonce stale", rxnoncedata.nonces[j].work_id); if (bitmain_decode_nonce(thr, bitmain, info, rxnoncedata.nonces[j].nonce, work)) { cg_logwork_uint32(work, rxnoncedata.nonces[j].nonce, true); if(opt_bitmain_hwerror) { From e423dd03e35ccf6c436d058ac702b81dd4da0ea6 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 16:42:10 +1100 Subject: [PATCH 07/16] Fix implicit warning --- driver-bitmain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/driver-bitmain.c b/driver-bitmain.c index 2cf20f1a68..0c98e7c4b5 100644 --- a/driver-bitmain.c +++ b/driver-bitmain.c @@ -1095,6 +1095,8 @@ static void bitmain_update_temps(struct cgpu_info *bitmain, struct bitmain_info } } +extern void cg_logwork_uint32(struct work *work, uint32_t nonce, bool ok); + static void bitmain_parse_results(struct cgpu_info *bitmain, struct bitmain_info *info, struct thr_info *thr, uint8_t *buf, int *offset) { From 566c085bc0c04ccd00504df7169aaf9216aaa4b5 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 13 Oct 2014 23:06:22 +1100 Subject: [PATCH 08/16] Change default max queue back to 1 in line with speed of most current asic controllers --- cgminer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 4369b0cba9..1f80a6089f 100644 --- a/cgminer.c +++ b/cgminer.c @@ -160,7 +160,7 @@ bool opt_loginput; bool opt_compact; const int opt_cutofftemp = 95; int opt_log_interval = 5; -int opt_queue = 9999; +int opt_queue = 1; static int max_queue = 1; int opt_scantime = -1; int opt_expiry = 120; From ec1222ad0a8881d4cbac6385c9dc039e65c94816 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 17:24:43 +1100 Subject: [PATCH 09/16] Set sshare to null to avoid undefined --- cgminer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 1f80a6089f..14570c24b8 100644 --- a/cgminer.c +++ b/cgminer.c @@ -6236,7 +6236,7 @@ static void stratum_share_result(json_t *val, json_t *res_val, json_t *err_val, static bool parse_stratum_response(struct pool *pool, char *s) { json_t *val = NULL, *err_val, *res_val, *id_val; - struct stratum_share *sshare; + struct stratum_share *sshare = NULL; json_error_t err; bool ret = false; int id; From fcc2ef0f91586648d9609f9a4d8977388e7c652d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 14 Oct 2014 17:26:06 +1100 Subject: [PATCH 10/16] Cosmetic fix --- cgminer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 14570c24b8..02d43a5f60 100644 --- a/cgminer.c +++ b/cgminer.c @@ -6300,7 +6300,7 @@ static bool parse_stratum_response(struct pool *pool, char *s) pool->diff_accepted += pool_diff; mutex_unlock(&stats_lock); } else { - applog(LOG_NOTICE, "Rejected %s stratum share from pool %d", + applog(LOG_NOTICE, "Rejected%s stratum share from pool %d", opt_lowmem ? "" : " untracked", pool->pool_no); mutex_lock(&stats_lock); From 823b7fd7759764bd1fe9383b778e43a343aeee8c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 17 Oct 2014 15:02:39 +1100 Subject: [PATCH 11/16] Enable building libusb without udev --- configure.ac | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 599d6d8c48..9939c92f1d 100644 --- a/configure.ac +++ b/configure.ac @@ -434,7 +434,14 @@ if test "x$want_usbutils" != xfalse; then AC_CONFIG_SUBDIRS([compat/libusb-1.0]) LIBUSB_LIBS="compat/libusb-1.0/libusb/.libs/libusb-1.0.a" if test "x$have_linux" = "xtrue"; then - LIBUSB_LIBS+=" -ludev" + AC_ARG_ENABLE([udev], + [AC_HELP_STRING([--disable-udev],[Disable building libusb with udev])], + [udev=$enableval] + ) + + if test "x$udev" != xno; then + LIBUSB_LIBS+=" -ludev" + fi fi if test "x$have_darwin" = "xtrue"; then LIBUSB_LIBS+=" -lobjc" From a69e86a2d2d5a4adec2daea088ef2eca1bebfdb6 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 18 Oct 2014 13:14:08 +1100 Subject: [PATCH 12/16] Wake gws on get queued --- cgminer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 02d43a5f60..5ec04517fc 100644 --- a/cgminer.c +++ b/cgminer.c @@ -7909,10 +7909,10 @@ struct work *get_queued(struct cgpu_info *cgpu) work = cgpu->unqueued_work; if (unlikely(stale_work(work, false))) { discard_work(work); - wake_gws(); } else __add_queued(cgpu, work); cgpu->unqueued_work = NULL; + wake_gws(); } wr_unlock(&cgpu->qlock); From fc4937169fe912e3f05d32ec923c514f40c0c11e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 18 Oct 2014 15:14:33 +1100 Subject: [PATCH 13/16] Set driver max diff to large value if unset --- cgminer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cgminer.c b/cgminer.c index 5ec04517fc..78cdfd60f3 100644 --- a/cgminer.c +++ b/cgminer.c @@ -9346,7 +9346,7 @@ void fill_device_drv(struct device_drv *drv) if (!drv->zero_stats) drv->zero_stats = &noop_zero_stats; if (!drv->max_diff) - drv->max_diff = 1; + drv->max_diff = 0xffffffffull; } void null_device_drv(struct device_drv *drv) From 667272f9c8fb1ada53c6bec5aa27927fcdb14568 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 18 Oct 2014 15:15:07 +1100 Subject: [PATCH 14/16] Set S4 to device_diff not pool diff --- driver-bitmain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-bitmain.c b/driver-bitmain.c index 0c98e7c4b5..98175a8715 100644 --- a/driver-bitmain.c +++ b/driver-bitmain.c @@ -594,7 +594,7 @@ static int bitmain_set_txtask(uint8_t * sendbuf, memcpy(bm->works[cursendcount].data2, works[index]->data + 64, 12); if(cursendcount == 0) { - pooldiff = (unsigned int)(works[index]->sdiff); + pooldiff = (unsigned int)(works[index]->device_diff); difftmp = pooldiff; while(1) { difftmp = difftmp >> 1; From 083edcd8c759db87b8a0540877e4946da6ae0aaf Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 18 Oct 2014 17:04:13 +1100 Subject: [PATCH 15/16] Increase s4 array size --- driver-bitmain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/driver-bitmain.h b/driver-bitmain.h index 6a5e633d39..1584429dc7 100644 --- a/driver-bitmain.h +++ b/driver-bitmain.h @@ -291,7 +291,7 @@ struct bitmain_info { }; #define BITMAIN_READ_SIZE 12 -#define BITMAIN_ARRAY_SIZE 16384 +#define BITMAIN_ARRAY_SIZE 32768 #define BTM_GETS_ERROR -1 #define BTM_GETS_OK 0 From 2b2b516341ec42b78b4c9c407eb2346d41007ec3 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 30 Sep 2014 15:59:42 +1000 Subject: [PATCH 16/16] Implement support for mining.suggest_difficulty --- README | 1 + cgminer.c | 5 ++++- miner.h | 1 + util.c | 5 +++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README b/README index 6e67c20e56..473c850b90 100644 --- a/README +++ b/README @@ -275,6 +275,7 @@ Options for both config file and command line: --sharelog Append share log to file --shares Quit after mining N shares (default: unlimited) --socks-proxy Set socks4 proxy (host:port) +--suggest-diff Suggest miner difficulty for pool to user (default: none) --syslog Use system log for output messages (default: standard error) --temp-cutoff Temperature where a device will be automatically disabled, one value or comma separated list (default: 95) --text-only|-T Disable ncurses formatted screen output diff --git a/cgminer.c b/cgminer.c index 78cdfd60f3..1416dd33fb 100644 --- a/cgminer.c +++ b/cgminer.c @@ -438,7 +438,7 @@ struct stratum_share { static struct stratum_share *stratum_shares = NULL; char *opt_socks_proxy = NULL; - +int opt_suggest_diff; static const char def_conf[] = "cgminer.conf"; static char *default_config; static bool config_loaded; @@ -1735,6 +1735,9 @@ static struct opt_table opt_config_table[] = { OPT_WITH_ARG("--socks-proxy", opt_set_charp, NULL, &opt_socks_proxy, "Set socks4 proxy (host:port)"), + OPT_WITH_ARG("--suggest-diff", + opt_set_intval, NULL, &opt_suggest_diff, + "Suggest miner difficulty for pool to user (default: none)"), #ifdef HAVE_SYSLOG_H OPT_WITHOUT_ARG("--syslog", opt_set_bool, &use_syslog, diff --git a/miner.h b/miner.h index 2f79ece855..134d463f8b 100644 --- a/miner.h +++ b/miner.h @@ -1001,6 +1001,7 @@ extern bool opt_protocol; extern bool have_longpoll; extern char *opt_kernel_path; extern char *opt_socks_proxy; +extern int opt_suggest_diff; extern char *cgminer_path; extern bool opt_fail_only; extern bool opt_lowmem; diff --git a/util.c b/util.c index bbe3138aaa..05d16527b9 100644 --- a/util.c +++ b/util.c @@ -2187,6 +2187,11 @@ bool auth_stratum(struct pool *pool) pool->probed = true; successful_connect = true; + if (opt_suggest_diff) { + sprintf(s, "{\"id\": %d, \"method\": \"mining.suggest_difficulty(%d)\", \"params\": []}", + swork_id++, opt_suggest_diff); + stratum_send(pool, s, strlen(s)); + } out: json_decref(val); return ret;