From 7418f5e211cb73d0104791e1759effee9b9f2eb3 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 27 Jul 2012 21:15:19 +0000 Subject: [PATCH 1/4] strtok_ts: Thread-safe strtok that work on POSIX or Windows --- compat.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compat.h b/compat.h index c6e38d8a..19a14f0d 100644 --- a/compat.h +++ b/compat.h @@ -9,6 +9,10 @@ #include +// NOTE: Windows strtok uses a thread-local static buffer, so this is safe +#define SETUP_STRTOK_TS /*nothing needed*/ +#define strtok_ts strtok + #include "miner.h" // for timersub static inline int nanosleep(const struct timespec *req, struct timespec *rem) @@ -72,8 +76,13 @@ typedef long suseconds_t; #endif #define PTH(thr) ((thr)->pth.p) -#else +#else /* ! WIN32 */ + #define PTH(thr) ((thr)->pth) + +#define SETUP_STRTOK_TS char*_strtok_ts_saveptr +#define strtok_ts(str, delim) strtok_r(str, delim, &_strtok_ts_saveptr) + #endif /* WIN32 */ #endif /* __COMPAT_H__ */ From 8326d2dcaf3b9d4e4b1a52998f68a6b565642d23 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 27 Jul 2012 20:03:25 +0000 Subject: [PATCH 2/4] RPC: New "poolpriority" command to set the order of pool priorities --- API-README | 4 ++++ api.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/API-README b/API-README index df905ef3..a00a0dcc 100644 --- a/API-README +++ b/API-README @@ -174,6 +174,10 @@ The list of requests - a (*) means it requires privileged access - and replies a Use '\\' to get a '\' and '\,' to include a comma inside URL, USR or PASS + poolpriority|N,... (*) + none There is no reply section just the STATUS section + stating the results of changing pool priorities + disablepool|N (*) none There is no reply section just the STATUS section stating the results of disabling pool N diff --git a/api.c b/api.c index d2f01487..86de3c80 100644 --- a/api.c +++ b/api.c @@ -339,6 +339,7 @@ static const char *JSON_PARAMETER = "parameter"; #define MSG_ACCDENY 45 #define MSG_ACCOK 46 #define MSG_ENAPOOL 47 +#define MSG_POOLPRIO 73 #define MSG_DISPOOL 48 #define MSG_ALRENAP 49 #define MSG_ALRDISP 50 @@ -501,6 +502,7 @@ struct CODES { { SEVERITY_ERR, MSG_ACCDENY, PARAM_STR, "Access denied to '%s' command" }, { SEVERITY_SUCC, MSG_ACCOK, PARAM_NONE, "Privileged access OK" }, { SEVERITY_SUCC, MSG_ENAPOOL, PARAM_POOL, "Enabling pool %d:'%s'" }, + { SEVERITY_SUCC, MSG_POOLPRIO,PARAM_NONE, "Changed pool priorities" }, { SEVERITY_SUCC, MSG_DISPOOL, PARAM_POOL, "Disabling pool %d:'%s'" }, { SEVERITY_INFO, MSG_ALRENAP, PARAM_POOL, "Pool %d:'%s' already enabled" }, { SEVERITY_INFO, MSG_ALRDISP, PARAM_POOL, "Pool %d:'%s' already disabled" }, @@ -2132,6 +2134,39 @@ static void enablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __ strcpy(io_buffer, message(MSG_ENAPOOL, id, NULL, isjson)); } +static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group) +{ + SETUP_STRTOK_TS; + int total_pools_ = total_pools; // Keep a local copy, to be more threadsafe + char *a; + int i, prio = 0; + + if (total_pools_ == 0) { + strcpy(io_buffer, message(MSG_NOPOOL, 0, NULL, isjson)); + return; + } + + bool pools_changed[total_pools_]; + for (i = 0; i < total_pools_; ++i) + pools_changed[i] = false; + + a = strtok_ts(param, ","); + do { + i = atoi(a); + pools[i]->prio = prio++; + pools_changed[i] = true; + } while ( (a = strtok_ts(NULL, ",")) ); + + for (i = 0; i < total_pools_; ++i) + if (!pools_changed[i]) + pools[i]->prio = prio++; + + if (current_pool()->prio) + switch_pools(NULL); + + strcpy(io_buffer, message(MSG_POOLPRIO, 0, NULL, isjson)); +} + static void disablepool(__maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group) { struct pool *pool; @@ -2663,6 +2698,7 @@ struct CMDS { { "cpucount", cpucount, false }, { "switchpool", switchpool, true }, { "addpool", addpool, true }, + { "poolpriority", poolpriority, true }, { "enablepool", enablepool, true }, { "disablepool", disablepool, true }, { "removepool", removepool, true }, From 5ef9c139240f17270d5124101b9972b955d070c9 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 27 Jul 2012 20:53:59 +0000 Subject: [PATCH 3/4] Bugfix: API: Report errors from poolpriority command --- api.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/api.c b/api.c index 86de3c80..4e1da9a7 100644 --- a/api.c +++ b/api.c @@ -2139,7 +2139,7 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson, SETUP_STRTOK_TS; int total_pools_ = total_pools; // Keep a local copy, to be more threadsafe char *a; - int i, prio = 0; + int i, prio = 0, e = -1; if (total_pools_ == 0) { strcpy(io_buffer, message(MSG_NOPOOL, 0, NULL, isjson)); @@ -2152,7 +2152,11 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson, a = strtok_ts(param, ","); do { - i = atoi(a); + i = strtol(a, &a, 10); + if (unlikely(*a > 0x20 || i < 0 || i >= total_pools)) { + e = (*a > 0x20) ? -2 : i; + continue; + } pools[i]->prio = prio++; pools_changed[i] = true; } while ( (a = strtok_ts(NULL, ",")) ); @@ -2164,6 +2168,14 @@ static void poolpriority(__maybe_unused SOCKETTYPE c, char *param, bool isjson, if (current_pool()->prio) switch_pools(NULL); + if (e != -1) { + if (e == -2) + strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson)); + else + strcpy(io_buffer, message(MSG_INVPID, e, NULL, isjson)); + return; + } + strcpy(io_buffer, message(MSG_POOLPRIO, 0, NULL, isjson)); } From 0c985b24110112dcfcbe1c543562260458a07202 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 27 Jul 2012 23:42:05 +0000 Subject: [PATCH 4/4] RPC: Writeup on poolpriority command usage --- API-README | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/API-README b/API-README index a00a0dcc..6ea5a539 100644 --- a/API-README +++ b/API-README @@ -177,6 +177,7 @@ The list of requests - a (*) means it requires privileged access - and replies a poolpriority|N,... (*) none There is no reply section just the STATUS section stating the results of changing pool priorities + See usage below disablepool|N (*) none There is no reply section just the STATUS section @@ -274,8 +275,15 @@ The list of requests - a (*) means it requires privileged access - and replies a When you enable, disable or restart a GPU or PGA, you will also get Thread messages in the cgminer status window -When you switch to a different pool to the current one, you will get a -'Switching to URL' message in the cgminer status windows +The 'poolpriority' command can be used to reset the priority order of pools. +Each pool should be listed by id number in order of preference (first = most +preferred). Any pools not listed will be prioritized after the ones that are, +in an undefined order. If the priority change affects the miner's preference +for mining, it may switch immediately. + +When you switch to a different pool to the current one (including by priority +change), you will get a 'Switching to URL' message in the cgminer status +windows Obviously, the JSON format is simply just the names as given before the '=' with the values after the '='