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 41b2a16214..1416dd33fb 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; @@ -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, @@ -6236,7 +6239,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; @@ -6268,13 +6271,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 +6291,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 +6303,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 +6633,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; } @@ -7141,6 +7150,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 +7439,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 +7746,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); @@ -7900,10 +7912,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); @@ -9337,7 +9349,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) @@ -9373,6 +9385,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) 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" diff --git a/driver-bitmain.c b/driver-bitmain.c index 6b3a450ec6..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; @@ -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) { @@ -1289,30 +1291,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_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) { #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 { @@ -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, }; 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 diff --git a/miner.h b/miner.h index d999d16509..134d463f8b 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*); @@ -998,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;