Browse Source

algos: move cmdline algo/alias parser in a func

2upstream
Tanguy Pruvot 9 years ago
parent
commit
c3d10db873
  1. 38
      algos.h
  2. 38
      ccminer.cpp
  3. 3
      miner.h
  4. 4
      stats.cpp

38
algos.h

@ -1,6 +1,9 @@
#ifndef ALGOS_H #ifndef ALGOS_H
#define ALGOS_H #define ALGOS_H
#include <string.h>
#include "compat.h"
enum sha_algos { enum sha_algos {
ALGO_BLAKECOIN = 0, ALGO_BLAKECOIN = 0,
ALGO_BLAKE, 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 #endif

38
ccminer.cpp

@ -1959,7 +1959,7 @@ static void *miner_thread(void *userdata)
for (int i = 0; i < opt_n_threads && thr_hashrates[i]; i++) for (int i = 0; i < opt_n_threads && thr_hashrates[i]; i++)
hashrate += stats_get_speed(i, thr_hashrates[i]); hashrate += stats_get_speed(i, thr_hashrates[i]);
pthread_mutex_unlock(&stats_lock); pthread_mutex_unlock(&stats_lock);
if (opt_benchmark && bench_algo == -1) { if (opt_benchmark && bench_algo == -1 && loopcnt > 2) {
format_hashrate(hashrate, s); format_hashrate(hashrate, s);
applog(LOG_NOTICE, "Total: %s", s); applog(LOG_NOTICE, "Total: %s", s);
} }
@ -2352,35 +2352,15 @@ void parse_arg(int key, char *arg)
case 'a': /* --algo */ case 'a': /* --algo */
p = strstr(arg, ":"); // optional factor p = strstr(arg, ":"); // optional factor
if (p) *p = '\0'; if (p) *p = '\0';
for (i = 0; i < ALGO_COUNT; i++) {
if (algo_names[i] && !strcasecmp(arg, algo_names[i])) { i = algo_to_int(arg);
opt_algo = (enum sha_algos)i; if (i >= 0)
break; opt_algo = (enum sha_algos)i;
} else {
} applog(LOG_ERR, "Unknown algo parameter '%s'", arg);
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)
show_usage_and_exit(1); show_usage_and_exit(1);
}
if (p) { if (p) {
opt_nfactor = atoi(p + 1); opt_nfactor = atoi(p + 1);
if (opt_algo == ALGO_SCRYPT_JANE) { if (opt_algo == ALGO_SCRYPT_JANE) {

3
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); unsigned char *scratchbuf, struct timeval *tv_start, struct timeval *tv_end);
/* free device allocated memory per algo */ /* 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_blake256(int thr_id);
extern void free_bmw(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); bool bench_algo_switch_next(int thr_id);
void bench_set_throughput(int thr_id, uint32_t throughput); void bench_set_throughput(int thr_id, uint32_t throughput);
void bench_display_results(); void bench_display_results();
void algo_free_all(int thr_id);
struct stratum_job { struct stratum_job {
char *job_id; char *job_id;

4
stats.cpp

@ -32,8 +32,8 @@ void stats_remember_speed(int thr_id, uint32_t hashcount, double hashrate, uint8
return; return;
// first hash rates are often erroneous // first hash rates are often erroneous
if (uid < opt_n_threads * 2) //if (uid < opt_n_threads * 2)
return; // return;
memset(&data, 0, sizeof(data)); memset(&data, 0, sizeof(data));
data.uid = (uint32_t) uid; data.uid = (uint32_t) uid;

Loading…
Cancel
Save