Browse Source

Merge remote-tracking branch 'kanoi/master' into bfgminer

Luke Dashjr 13 years ago
parent
commit
eaaa924e5d
3 changed files with 72 additions and 44 deletions
  1. 16 6
      API-README
  2. 55 28
      api.c
  3. 1 10
      compat.h

+ 16 - 6
API-README

@@ -39,7 +39,7 @@ To give an IP address/subnet access to a group you use the group letter
 in front of the IP address instead of W: e.g. P:192.168.0/32
 An IP address/subnet can only be a member of one group
 A sample API group would be:
- --api-groups P:switchpool:enablepool:addpool:disablepool:removepool:*
+ --api-groups P:switchpool:enablepool:addpool:disablepool:removepool.poolpriority:*
 This would create a group 'P' that can do all current pool commands and all
 non-priviliged commands - the '*' means all non-priviledged commands
 Without the '*' the group would only have access to the pool commands
@@ -276,11 +276,14 @@ 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 BFGMiner status window
 
-The 'poolpriority' command can be used to reset the priority order of pools.
+The 'poolpriority' command can be used to reset the priority order of multiple
+pools with a single command - 'switchpool' only sets a single pool to first priority
 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.
+preferred)
+Any pools not listed will be prioritised after the ones that are listed, in the
+priority order they were originally
+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 BFGMiner status
@@ -322,7 +325,14 @@ miner.php - an example web page to access the API
 Feature Changelog for external applications using the API:
 
 
-API V1.14
+API V1.15
+
+Added API commands:
+ 'poolpriority'
+
+----------
+
+API V1.14 (cgminer v2.5.0)
 
 Modified API commands:
  'stats' - more icarus timing stats added

+ 55 - 28
api.c

@@ -166,7 +166,7 @@ static const char SEPARATOR = '|';
 #define SEPSTR "|"
 static const char GPUSEP = ',';
 
-static const char *APIVERSION = "1.14";
+static const char *APIVERSION = "1.15";
 static const char *DEAD = "Dead";
 static const char *SICK = "Sick";
 static const char *NOSTART = "NoStart";
@@ -340,7 +340,6 @@ 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
@@ -374,6 +373,8 @@ static const char *JSON_PARAMETER = "parameter";
 #define MSG_MINESTATS 70
 #define MSG_MISCHK 71
 #define MSG_CHECK 72
+#define MSG_POOLPRIO 73
+#define MSG_DUPPID 74
 
 enum code_severity {
 	SEVERITY_ERR,
@@ -387,6 +388,7 @@ enum code_parameters {
 	PARAM_GPU,
 	PARAM_PGA,
 	PARAM_CPU,
+	PARAM_PID,
 	PARAM_GPUMAX,
 	PARAM_PGAMAX,
 	PARAM_CPUMAX,
@@ -504,6 +506,7 @@ struct CODES {
  { 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_ERR,   MSG_DUPPID,	PARAM_PID,	"Duplicate pool specified %d" },
  { 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" },
@@ -1085,6 +1088,7 @@ static char *message(int messageid, int paramid, char *param2, bool isjson)
 				case PARAM_GPU:
 				case PARAM_PGA:
 				case PARAM_CPU:
+				case PARAM_PID:
 					sprintf(buf, codes[i].description, paramid);
 					break;
 				case PARAM_POOL:
@@ -2058,46 +2062,69 @@ static void enablepool(__maybe_unused SOCKETTYPE c, char *param, bool 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, e = -1;
+	char *ptr, *next;
+	int i, pr, prio = 0;
 
-	if (total_pools_ == 0) {
+	// TODO: all cgminer code needs a mutex added everywhere for change
+	//	access to total_pools and also parts of the pools[] array,
+	//	just copying total_pools here wont solve that
+
+	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)
+	if (param == NULL || *param == '\0') {
+		strcpy(io_buffer, message(MSG_MISPID, 0, NULL, isjson));
+		return;
+	}
+
+	bool pools_changed[total_pools];
+	int new_prio[total_pools];
+	for (i = 0; i < total_pools; ++i)
 		pools_changed[i] = false;
 
-	a = strtok_ts(param, ",");
-	do {
-		i = strtol(a, &a, 10);
-		if (unlikely(*a > 0x20 || i < 0 || i >= total_pools)) {
-			e = (*a > 0x20) ? -2 : i;
-			continue;
+	next = param;
+	while (next && *next) {
+		ptr = next;
+		next = strchr(ptr, ',');
+		if (next)
+			*(next++) = '\0';
+
+		i = atoi(ptr);
+		if (i < 0 || i >= total_pools) {
+			strcpy(io_buffer, message(MSG_INVPID, i, NULL, isjson));
+			return;
+		}
+
+		if (pools_changed[i]) {
+			strcpy(io_buffer, message(MSG_DUPPID, i, NULL, isjson));
+			return;
 		}
-		pools[i]->prio = prio++;
+
 		pools_changed[i] = true;
-	} while ( (a = strtok_ts(NULL, ",")) );
+		new_prio[i] = prio++;
+	}
+
+	// Only change them if no errors
+	for (i = 0; i < total_pools; i++) {
+		if (pools_changed[i])
+			pools[i]->prio = new_prio[i];
+	}
 
-	for (i = 0; i < total_pools_; ++i)
-		if (!pools_changed[i])
-			pools[i]->prio = prio++;
+	// In priority order, cycle through the unchanged pools and append them
+	for (pr = 0; pr < total_pools; pr++)
+		for (i = 0; i < total_pools; i++) {
+			if (!pools_changed[i] && pools[i]->prio == pr) {
+				pools[i]->prio = prio++;
+				pools_changed[i] = true;
+				break;
+			}
+		}
 
 	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));
 }
 

+ 1 - 10
compat.h

@@ -9,10 +9,6 @@
 
 #include <windows.h>
 
-// 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)
@@ -75,13 +71,8 @@ typedef long suseconds_t;
 #endif
 
 #define PTH(thr) ((thr)->pth.p)
-#else /* ! WIN32 */
-
+#else
 #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__ */