Browse Source

pool switch: add thr_id param to handle a future barrier

Switching to a pool with a different algo will require a barrier
to free ressources, like what was made in the global benchmark.

add also the algo in pool structure...
master
Tanguy Pruvot 9 years ago
parent
commit
e12d666d36
  1. 2
      algos.h
  2. 6
      api.cpp
  3. 1
      bench.cpp
  4. 10
      ccminer.cpp
  5. 2
      cuda.cpp
  6. 5
      miner.h
  7. 19
      pools.cpp

2
algos.h

@ -45,6 +45,8 @@ enum sha_algos {
ALGO_COUNT ALGO_COUNT
}; };
extern volatile enum sha_algos opt_algo;
static const char *algo_names[] = { static const char *algo_names[] = {
"blakecoin", "blakecoin",
"blake", "blake",

6
api.cpp

@ -409,13 +409,13 @@ static char *remote_switchpool(char *params)
return buffer; return buffer;
if (!params || strlen(params) == 0) { if (!params || strlen(params) == 0) {
// rotate pool test // rotate pool test
ret = pool_switch_next(); ret = pool_switch_next(-1);
} else { } else {
int n = atoi(params); int n = atoi(params);
if (n == cur_pooln) if (n == cur_pooln)
ret = true; ret = true;
else if (n < num_pools) else if (n < num_pools)
ret = pool_switch(n); ret = pool_switch(-1, n);
} }
sprintf(buffer, "%s|", ret ? "ok" : "fail"); sprintf(buffer, "%s|", ret ? "ok" : "fail");
return buffer; return buffer;
@ -433,7 +433,7 @@ static char *remote_seturl(char *params)
return buffer; return buffer;
if (!params || strlen(params) == 0) { if (!params || strlen(params) == 0) {
// rotate pool test // rotate pool test
ret = pool_switch_next(); ret = pool_switch_next(-1);
} else { } else {
ret = pool_switch_url(params); ret = pool_switch_url(params);
} }

1
bench.cpp

@ -21,7 +21,6 @@ static pthread_barrier_t algo_barr;
static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t bench_lock = PTHREAD_MUTEX_INITIALIZER;
extern double thr_hashrates[MAX_GPUS]; extern double thr_hashrates[MAX_GPUS];
extern volatile enum sha_algos opt_algo;
void bench_init(int threads) void bench_init(int threads)
{ {

10
ccminer.cpp

@ -1181,7 +1181,7 @@ static void *workio_thread(void *userdata)
if (!ok && num_pools > 1 && opt_pool_failover) { if (!ok && num_pools > 1 && opt_pool_failover) {
if (opt_debug_threads) if (opt_debug_threads)
applog(LOG_DEBUG, "%s died, failover", __func__); applog(LOG_DEBUG, "%s died, failover", __func__);
ok = pool_switch_next(); ok = pool_switch_next(-1);
tq_push(wc->thr->q, NULL); // get_work() will return false tq_push(wc->thr->q, NULL); // get_work() will return false
} }
@ -1633,7 +1633,7 @@ static void *miner_thread(void *userdata)
// conditional pool switch // conditional pool switch
if (num_pools > 1 && conditional_pool_rotate) { if (num_pools > 1 && conditional_pool_rotate) {
if (!pool_is_switching) if (!pool_is_switching)
pool_switch_next(); pool_switch_next(thr_id);
else if (time(NULL) - firstwork_time > 35) { else if (time(NULL) - firstwork_time > 35) {
if (!opt_quiet) if (!opt_quiet)
applog(LOG_WARNING, "Pool switching timed out..."); applog(LOG_WARNING, "Pool switching timed out...");
@ -1670,7 +1670,7 @@ static void *miner_thread(void *userdata)
if (!pool_is_switching) { if (!pool_is_switching) {
if (!opt_quiet) if (!opt_quiet)
applog(LOG_INFO, "Pool mining timeout of %ds reached, rotate...", opt_time_limit); applog(LOG_INFO, "Pool mining timeout of %ds reached, rotate...", opt_time_limit);
pool_switch_next(); pool_switch_next(thr_id);
} else if (passed > 35) { } else if (passed > 35) {
// ensure we dont stay locked if pool_is_switching is not reset... // ensure we dont stay locked if pool_is_switching is not reset...
applog(LOG_WARNING, "Pool switch to %d timed out...", cur_pooln); applog(LOG_WARNING, "Pool switch to %d timed out...", cur_pooln);
@ -2233,7 +2233,7 @@ wait_stratum_url:
if (opt_retries >= 0 && ++failures > opt_retries) { if (opt_retries >= 0 && ++failures > opt_retries) {
if (num_pools > 1 && opt_pool_failover) { if (num_pools > 1 && opt_pool_failover) {
applog(LOG_WARNING, "Stratum connect timeout, failover..."); applog(LOG_WARNING, "Stratum connect timeout, failover...");
pool_switch_next(); pool_switch_next(-1);
} else { } else {
applog(LOG_ERR, "...terminating workio thread"); applog(LOG_ERR, "...terminating workio thread");
//tq_push(thr_info[work_thr_id].q, NULL); //tq_push(thr_info[work_thr_id].q, NULL);
@ -3079,7 +3079,7 @@ int main(int argc, char *argv[])
if (opt_debug) if (opt_debug)
pool_dump_infos(); pool_dump_infos();
cur_pooln = pool_get_first_valid(0); cur_pooln = pool_get_first_valid(0);
pool_switch(cur_pooln); pool_switch(-1, cur_pooln);
flags = !opt_benchmark && strncmp(rpc_url, "https:", 6) flags = !opt_benchmark && strncmp(rpc_url, "https:", 6)
? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL) ? (CURL_GLOBAL_ALL & ~CURL_GLOBAL_SSL)

2
cuda.cpp

@ -151,7 +151,7 @@ uint32_t cuda_default_throughput(int thr_id, uint32_t defcount)
//int dev_id = device_map[thr_id % MAX_GPUS]; //int dev_id = device_map[thr_id % MAX_GPUS];
uint32_t throughput = gpus_intensity[thr_id] ? gpus_intensity[thr_id] : defcount; uint32_t throughput = gpus_intensity[thr_id] ? gpus_intensity[thr_id] : defcount;
if (gpu_threads > 1 && throughput == defcount) throughput /= (gpu_threads-1); if (gpu_threads > 1 && throughput == defcount) throughput /= (gpu_threads-1);
api_set_throughput(thr_id, throughput); if (api_thr_id != -1) api_set_throughput(thr_id, throughput);
//gpulog(LOG_INFO, thr_id, "throughput %u", throughput); //gpulog(LOG_INFO, thr_id, "throughput %u", throughput);
return throughput; return throughput;
} }

5
miner.h

@ -653,6 +653,7 @@ struct pool_infos {
#define POOL_ST_DISABLED 4 #define POOL_ST_DISABLED 4
#define POOL_ST_REMOVED 8 #define POOL_ST_REMOVED 8
uint16_t status; uint16_t status;
int algo;
char name[64]; char name[64];
// credentials // credentials
char url[256]; char url[256];
@ -691,8 +692,8 @@ void pool_init_defaults(void);
void pool_set_creds(int pooln); void pool_set_creds(int pooln);
void pool_set_attr(int pooln, const char* key, char* arg); void pool_set_attr(int pooln, const char* key, char* arg);
bool pool_switch_url(char *params); bool pool_switch_url(char *params);
bool pool_switch(int pooln); bool pool_switch(int thr_id, int pooln);
bool pool_switch_next(void); bool pool_switch_next(int thr_id);
int pool_get_first_valid(int startfrom); int pool_get_first_valid(int startfrom);
bool parse_pool_array(json_t *obj); bool parse_pool_array(json_t *obj);
void pool_dump_infos(void); void pool_dump_infos(void);

19
pools.cpp

@ -9,6 +9,7 @@
#include "miner.h" #include "miner.h"
#include "compat.h" #include "compat.h"
#include "algos.h"
// to move in miner.h // to move in miner.h
extern bool allow_gbt; extern bool allow_gbt;
@ -50,6 +51,7 @@ struct opt_config_array {
{ CFG_POOL, "user", NULL }, { CFG_POOL, "user", NULL },
{ CFG_POOL, "pass", NULL }, { CFG_POOL, "pass", NULL },
{ CFG_POOL, "userpass", NULL }, { CFG_POOL, "userpass", NULL },
{ CFG_POOL, "algo", NULL },
{ CFG_POOL, "name", "pool-name" }, { CFG_POOL, "name", "pool-name" },
{ CFG_POOL, "scantime", "pool-scantime" }, { CFG_POOL, "scantime", "pool-scantime" },
{ CFG_POOL, "max-diff", "pool-max-diff" }, { CFG_POOL, "max-diff", "pool-max-diff" },
@ -74,7 +76,8 @@ void pool_set_creds(int pooln)
p->id = pooln; p->id = pooln;
p->status |= POOL_ST_DEFINED; p->status |= POOL_ST_DEFINED;
// init pool options as "unset" // init pool options as "unset"
// until cmdline is not fully parsed... // until cmdline is fully parsed...
p->algo = -1;
p->max_diff = -1.; p->max_diff = -1.;
p->max_rate = -1.; p->max_rate = -1.;
p->scantime = -1; p->scantime = -1;
@ -102,6 +105,7 @@ void pool_init_defaults()
struct pool_infos *p; struct pool_infos *p;
for (int i=0; i<num_pools; i++) { for (int i=0; i<num_pools; i++) {
p = &pools[i]; p = &pools[i];
if (p->algo == -1) p->algo = (int) opt_algo;
if (p->max_diff == -1.) p->max_diff = opt_max_diff; if (p->max_diff == -1.) p->max_diff = opt_max_diff;
if (p->max_rate == -1.) p->max_rate = opt_max_rate; if (p->max_rate == -1.) p->max_rate = opt_max_rate;
if (p->scantime == -1) p->scantime = opt_scantime; if (p->scantime == -1) p->scantime = opt_scantime;
@ -113,7 +117,10 @@ void pool_init_defaults()
void pool_set_attr(int pooln, const char* key, char* arg) void pool_set_attr(int pooln, const char* key, char* arg)
{ {
struct pool_infos *p = &pools[pooln]; struct pool_infos *p = &pools[pooln];
if (!strcasecmp(key, "algo")) {
p->algo = algo_to_int(arg);
return;
}
if (!strcasecmp(key, "name")) { if (!strcasecmp(key, "name")) {
snprintf(p->name, sizeof(p->name), "%s", arg); snprintf(p->name, sizeof(p->name), "%s", arg);
return; return;
@ -144,7 +151,7 @@ void pool_set_attr(int pooln, const char* key, char* arg)
} }
// pool switching code // pool switching code
bool pool_switch(int pooln) bool pool_switch(int thr_id, int pooln)
{ {
int prevn = cur_pooln; int prevn = cur_pooln;
struct pool_infos *prev = &pools[cur_pooln]; struct pool_infos *prev = &pools[cur_pooln];
@ -255,11 +262,11 @@ int pool_get_first_valid(int startfrom)
} }
// switch to next available pool // switch to next available pool
bool pool_switch_next() bool pool_switch_next(int thr_id)
{ {
if (num_pools > 1) { if (num_pools > 1) {
int pooln = pool_get_first_valid(cur_pooln+1); int pooln = pool_get_first_valid(cur_pooln+1);
return pool_switch(pooln); return pool_switch(thr_id, pooln);
} else { } else {
// no switch possible // no switch possible
if (!opt_quiet) if (!opt_quiet)
@ -279,7 +286,7 @@ bool pool_switch_url(char *params)
cur_pooln = prevn; cur_pooln = prevn;
if (nextn == prevn) if (nextn == prevn)
return false; return false;
return pool_switch(nextn); return pool_switch(-1, nextn);
} }
// Parse pools array in json config // Parse pools array in json config

Loading…
Cancel
Save