Skip to content

Commit

Permalink
algos: move cmdline algo/alias parser in a func
Browse files Browse the repository at this point in the history
  • Loading branch information
tpruvot committed Oct 15, 2015
1 parent e5d1cf8 commit c3d10db
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 33 deletions.
38 changes: 38 additions & 0 deletions algos.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef ALGOS_H
#define ALGOS_H

#include <string.h>
#include "compat.h"

enum sha_algos {
ALGO_BLAKECOIN = 0,
ALGO_BLAKE,
Expand Down Expand Up @@ -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
38 changes: 9 additions & 29 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c3d10db

Please sign in to comment.