From c3d10db873b8a05c7225664a245c82689556aa69 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 15 Oct 2015 08:33:55 +0200 Subject: [PATCH] algos: move cmdline algo/alias parser in a func --- algos.h | 38 ++++++++++++++++++++++++++++++++++++++ ccminer.cpp | 38 +++++++++----------------------------- miner.h | 3 +-- stats.cpp | 4 ++-- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/algos.h b/algos.h index 7aac20f..b3fb381 100644 --- a/algos.h +++ b/algos.h @@ -1,6 +1,9 @@ #ifndef ALGOS_H #define ALGOS_H +#include +#include "compat.h" + enum sha_algos { ALGO_BLAKECOIN = 0, ALGO_BLAKE, @@ -83,5 +86,40 @@ static const char *algo_names[] = { "" }; +// string to int/enum +static inline int algo_to_int(char* arg) +{ + int i; + + for (i = 0; i < ALGO_COUNT; i++) { + if (algo_names[i] && !strcasecmp(arg, algo_names[i])) { + return i; + } + } + + if (i == ALGO_COUNT) { + // some aliases... + if (!strcasecmp("all", arg)) + i = ALGO_AUTO; + else if (!strcasecmp("flax", arg)) + i = ALGO_C11; + else if (!strcasecmp("diamond", arg)) + i = ALGO_DMD_GR; + else if (!strcasecmp("doom", arg)) + i = ALGO_LUFFA; + else if (!strcasecmp("lyra2re", arg)) + i = ALGO_LYRA2; + else if (!strcasecmp("lyra2rev2", arg)) + i = ALGO_LYRA2v2; + else if (!strcasecmp("whirl", arg)) + i = ALGO_WHIRLPOOL; + else if (!strcasecmp("ziftr", arg)) + i = ALGO_ZR5; + else + i = -1; + } + + return i; +} #endif diff --git a/ccminer.cpp b/ccminer.cpp index 5cb91e9..83b67ed 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -1959,7 +1959,7 @@ static void *miner_thread(void *userdata) for (int i = 0; i < opt_n_threads && thr_hashrates[i]; i++) hashrate += stats_get_speed(i, thr_hashrates[i]); pthread_mutex_unlock(&stats_lock); - if (opt_benchmark && bench_algo == -1) { + if (opt_benchmark && bench_algo == -1 && loopcnt > 2) { format_hashrate(hashrate, s); applog(LOG_NOTICE, "Total: %s", s); } @@ -2352,35 +2352,15 @@ void parse_arg(int key, char *arg) case 'a': /* --algo */ p = strstr(arg, ":"); // optional factor if (p) *p = '\0'; - for (i = 0; i < ALGO_COUNT; i++) { - if (algo_names[i] && !strcasecmp(arg, algo_names[i])) { - opt_algo = (enum sha_algos)i; - break; - } - } - if (i == ALGO_COUNT) { - // some aliases... - if (!strcasecmp("all", arg)) - i = opt_algo = ALGO_AUTO; - else if (!strcasecmp("flax", arg)) - i = opt_algo = ALGO_C11; - else if (!strcasecmp("diamond", arg)) - i = opt_algo = ALGO_DMD_GR; - else if (!strcasecmp("doom", arg)) - i = opt_algo = ALGO_LUFFA; - else if (!strcasecmp("lyra2re", arg)) - i = opt_algo = ALGO_LYRA2; - else if (!strcasecmp("lyra2rev2", arg)) - i = opt_algo = ALGO_LYRA2v2; - else if (!strcasecmp("whirl", arg)) - i = opt_algo = ALGO_WHIRLPOOL; - else if (!strcasecmp("ziftr", arg)) - i = opt_algo = ALGO_ZR5; - else - applog(LOG_ERR, "Unknown algo parameter '%s'", arg); - } - if (i == ALGO_COUNT) + + i = algo_to_int(arg); + if (i >= 0) + opt_algo = (enum sha_algos)i; + else { + applog(LOG_ERR, "Unknown algo parameter '%s'", arg); show_usage_and_exit(1); + } + if (p) { opt_nfactor = atoi(p + 1); if (opt_algo == ALGO_SCRYPT_JANE) { diff --git a/miner.h b/miner.h index 63964ad..8fc526a 100644 --- a/miner.h +++ b/miner.h @@ -299,7 +299,7 @@ extern int scanhash_scrypt_jane(int thr_id, struct work *work, uint32_t max_nonc unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end); /* free device allocated memory per algo */ -void miner_free_device(int thr_id); +void algo_free_all(int thr_id); extern void free_blake256(int thr_id); extern void free_bmw(int thr_id); @@ -556,7 +556,6 @@ void bench_free(); bool bench_algo_switch_next(int thr_id); void bench_set_throughput(int thr_id, uint32_t throughput); void bench_display_results(); -void algo_free_all(int thr_id); struct stratum_job { char *job_id; diff --git a/stats.cpp b/stats.cpp index 4dd84a2..b58f997 100644 --- a/stats.cpp +++ b/stats.cpp @@ -32,8 +32,8 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8 return; // first hash rates are often erroneous - if (uid < opt_n_threads * 2) - return; + //if (uid < opt_n_threads * 2) + // return; memset(&data, 0, sizeof(data)); data.uid = (uint32_t) uid;