Browse Source

pools: initial implementation of pool state machines.

moved enable_pool(), disable_pool() and other functions related to
state. These could probably be factored out altogether.

Pool state default is now "enabled" - it was previosly "disabled",
but there was an unconditional function call to enable all pools
in main() previously. It was factored out by joe's earlier commits,
so not visible in this one.
nfactor-troky
Noel Maersk 11 years ago
parent
commit
64fc8324b8
  1. 7
      miner.h
  2. 198
      sgminer.c

7
miner.h

@ -1136,12 +1136,12 @@ struct curl_ent {
struct timeval tv; struct timeval tv;
}; };
/* Disabled needs to be the lowest enum as a freshly calloced value will then /* The lowest enum of a freshly calloced value is the default */
* equal disabled */
enum pool_state { enum pool_state {
POOL_DISABLED,
POOL_ENABLED, POOL_ENABLED,
POOL_DISABLED,
POOL_REJECTING, POOL_REJECTING,
POOL_HIDDEN,
}; };
struct stratum_work { struct stratum_work {
@ -1185,7 +1185,6 @@ struct pool {
bool idle; bool idle;
bool lagging; bool lagging;
bool probed; bool probed;
bool start_disabled;
enum pool_state state; enum pool_state state;
bool submit_old; bool submit_old;
bool remove_at_start; bool remove_at_start;

198
sgminer.c

@ -749,48 +749,74 @@ static char *set_poolname(char *arg)
return NULL; return NULL;
} }
static char *set_disable_pool(char *arg) static void enable_pool(struct pool *pool)
{ {
struct pool *pool; if (pool->state != POOL_ENABLED)
int len, disabled; enabled_pools++;
pool->state = POOL_ENABLED;
}
while ((json_array_index + 1) > total_pools) static void disable_pool(struct pool *pool)
add_pool(); {
pool = pools[json_array_index]; if (pool->state == POOL_ENABLED)
enabled_pools--;
pool->state = POOL_DISABLED;
}
len = strlen(arg); static void reject_pool(struct pool *pool)
if (len < 1) {
{ if (pool->state == POOL_ENABLED)
disabled = 1; enabled_pools--;
} pool->state = POOL_REJECTING;
else }
{
disabled = atoi(arg); /* We can't remove the memory used for this struct pool because there may
* still be work referencing it. We just remove it from the pools list */
void remove_pool(struct pool *pool)
{
int i, last_pool = total_pools - 1;
struct pool *other;
/* Boost priority of any lower prio than this one */
for (i = 0; i < total_pools; i++) {
other = pools[i];
if (other->prio > pool->prio)
other->prio--;
} }
pool->start_disabled = (disabled > 0);
return NULL; if (pool->pool_no < last_pool) {
/* Swap the last pool for this one */
(pools[last_pool])->pool_no = pool->pool_no;
pools[pool->pool_no] = pools[last_pool];
}
/* Give it an invalid number */
pool->pool_no = total_pools;
pool->removed = true;
total_pools--;
} }
static char *set_remove_pool(char *arg) static char *set_pool_state(char *arg)
{ {
struct pool *pool; struct pool *pool;
int len, remove;
/* TODO: consider using j_a_i everywhere */
while ((json_array_index + 1) > total_pools) while ((json_array_index + 1) > total_pools)
add_pool(); add_pool();
pool = pools[json_array_index]; pool = pools[json_array_index];
len = strlen(arg); applog(LOG_INFO, "Setting pool %s state to %s", pool->poolname, arg);
if (len < 1)
{ if (strcmp(arg, "disabled") == 0) {
remove = 1; pool->state = POOL_DISABLED;
} } else if (strcmp(arg, "enabled") == 0) {
else pool->state = POOL_ENABLED;
{ } else if (strcmp(arg, "hidden") == 0) {
remove = atoi(arg); pool->state = POOL_HIDDEN;
} else if (strcmp(arg, "rejecting") == 0) {
pool->state = POOL_REJECTING;
} else {
pool->state = POOL_ENABLED;
} }
pool->remove_at_start = (remove > 0);
return NULL; return NULL;
} }
@ -1078,12 +1104,6 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--device|-d", OPT_WITH_ARG("--device|-d",
set_devices, NULL, NULL, set_devices, NULL, NULL,
"Select device to use, one value, range and/or comma separated (e.g. 0-2,4) default: all"), "Select device to use, one value, range and/or comma separated (e.g. 0-2,4) default: all"),
OPT_WITH_ARG("--disable-pool",
set_disable_pool, NULL, NULL,
"Start the pool in a disabled state, so that it is not automatically chosen for mining"),
OPT_WITH_ARG("--remove-pool",
set_remove_pool, NULL, NULL,
"Allow the pool configuration to remain in the config file, but exclude it from the pools available at runtime"),
OPT_WITHOUT_ARG("--disable-rejecting", OPT_WITHOUT_ARG("--disable-rejecting",
opt_set_bool, &opt_disable_pool, opt_set_bool, &opt_disable_pool,
"Automatically disable pools that continually reject shares"), "Automatically disable pools that continually reject shares"),
@ -1257,6 +1277,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--socks-proxy", OPT_WITH_ARG("--socks-proxy",
opt_set_charp, NULL, &opt_socks_proxy, opt_set_charp, NULL, &opt_socks_proxy,
"Set socks4 proxy (host:port)"), "Set socks4 proxy (host:port)"),
OPT_WITH_ARG("--state",
set_pool_state, NULL, NULL,
"Specify pool state at startup (default: enabled)"),
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
OPT_WITHOUT_ARG("--syslog", OPT_WITHOUT_ARG("--syslog",
opt_set_bool, &use_syslog, opt_set_bool, &use_syslog,
@ -1301,7 +1324,7 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--user|-u", OPT_WITH_ARG("--user|-u",
set_user, NULL, NULL, set_user, NULL, NULL,
"Username for bitcoin JSON-RPC server"), "Username for bitcoin JSON-RPC server"),
OPT_WITH_ARG("--vectors|-v", OPT_WITH_ARG("--vectors",
set_vector, NULL, NULL, set_vector, NULL, NULL,
opt_hidden), opt_hidden),
/* All current kernels only support vectors=1 */ /* All current kernels only support vectors=1 */
@ -2347,30 +2370,6 @@ void logwin_update(void)
} }
#endif #endif
static void enable_pool(struct pool *pool)
{
if (pool->state != POOL_ENABLED) {
enabled_pools++;
pool->state = POOL_ENABLED;
}
}
#ifdef HAVE_CURSES
static void disable_pool(struct pool *pool)
{
if (pool->state == POOL_ENABLED)
enabled_pools--;
pool->state = POOL_DISABLED;
}
#endif
static void reject_pool(struct pool *pool)
{
if (pool->state == POOL_ENABLED)
enabled_pools--;
pool->state = POOL_REJECTING;
}
static void restart_threads(void); static void restart_threads(void);
/* Theoretically threads could race when modifying accepted and /* Theoretically threads could race when modifying accepted and
@ -4078,31 +4077,6 @@ static void display_pool_summary(struct pool *pool)
} }
#endif #endif
/* We can't remove the memory used for this struct pool because there may
* still be work referencing it. We just remove it from the pools list */
void remove_pool(struct pool *pool)
{
int i, last_pool = total_pools - 1;
struct pool *other;
/* Boost priority of any lower prio than this one */
for (i = 0; i < total_pools; i++) {
other = pools[i];
if (other->prio > pool->prio)
other->prio--;
}
if (pool->pool_no < last_pool) {
/* Swap the last pool for this one */
(pools[last_pool])->pool_no = pool->pool_no;
pools[pool->pool_no] = pools[last_pool];
}
/* Give it an invalid number */
pool->pool_no = total_pools;
pool->removed = true;
total_pools--;
}
/* add a mutex if this needs to be thread safe in the future */ /* add a mutex if this needs to be thread safe in the future */
static struct JE { static struct JE {
char *buf; char *buf;
@ -4489,17 +4463,22 @@ updated:
if (pool->state != POOL_ENABLED) if (pool->state != POOL_ENABLED)
wattron(logwin, A_DIM); wattron(logwin, A_DIM);
wlogprint("%d: ", pool->pool_no); wlogprint("%d: ", pool->pool_no);
switch (pool->state) { switch (pool->state) {
case POOL_ENABLED: case POOL_ENABLED:
wlogprint("Enabled "); wlogprint("Enabled ");
break; break;
case POOL_DISABLED: case POOL_DISABLED:
wlogprint("Disabled "); wlogprint("Disabled ");
break; break;
case POOL_REJECTING: case POOL_REJECTING:
wlogprint("Rejecting "); wlogprint("Rejecting ");
break; break;
case POOL_HIDDEN:
default:
break;
} }
disp_name = pool->poolname; disp_name = pool->poolname;
if (strlen(disp_name) < 1) if (strlen(disp_name) < 1)
{ {
@ -7758,7 +7737,7 @@ int main(int argc, char *argv[])
if (opt_benchmark) { if (opt_benchmark) {
struct pool *pool; struct pool *pool;
// FIXME: executes always (leftover from SHA256d days // FIXME: executes always (leftover from SHA256d days)
quit(1, "Cannot use benchmark mode with scrypt"); quit(1, "Cannot use benchmark mode with scrypt");
pool = add_pool(); pool = add_pool();
pool->rpc_url = malloc(255); pool->rpc_url = malloc(255);
@ -7956,29 +7935,28 @@ int main(int argc, char *argv[])
if (opt_benchmark) if (opt_benchmark)
goto begin_bench; goto begin_bench;
/* Remove any pools that are in the configuration, but have been marked to be /* Set pool state */
* removed at miner startup in order to reduce clutter in the pool management */
for (i = 0; i < total_pools; i++) { for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i]; struct pool *pool = pools[i];
if (pool->remove_at_start) switch (pool->state) {
{ case POOL_DISABLED:
remove_pool(pool);
}
}
/* Enable or disable all the 'remaining' pools */
for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i];
if (pool->start_disabled)
{
disable_pool(pool); disable_pool(pool);
} break;
else case POOL_ENABLED:
{
enable_pool(pool); enable_pool(pool);
break;
case POOL_HIDDEN:
remove_pool(pool);
break;
case POOL_REJECTING:
reject_pool(pool);
break;
default:
enable_pool(pool);
break;
} }
pool->idle = true; pool->idle = true;
} }

Loading…
Cancel
Save