Commit ebeaf15f18aa92622127d8d4f0ccddfaa2e251c7

Paul Sheppard 2012-06-09T19:30:32

Added idle mode Idle is only set by pgadisable, so GPU/CPU is unaffected. For Icarus/Ztex, in scanhash the thread is immediately set disabled then returns.

diff --git a/api.c b/api.c
index b644149..3e6501a 100644
--- a/api.c
+++ b/api.c
@@ -167,6 +167,7 @@ static const char *SICK = "Sick";
 static const char *NOSTART = "NoStart";
 static const char *DISABLED = "Disabled";
 static const char *ALIVE = "Alive";
+static const char *IDLE = "Idle";
 static const char *REJECTING = "Rejecting";
 static const char *UNKNOWN = "Unknown";
 #define _DYNAMIC "D"
@@ -879,7 +880,7 @@ static void pgastatus(int pga, bool isjson)
 
 		cgpu->utility = cgpu->accepted / ( total_secs ? total_secs : 1 ) * 60;
 
-		if (cgpu->deven != DEV_DISABLED)
+		if (cgpu->deven == DEV_ENABLED)
 			enabled = (char *)YES;
 		else
 			enabled = (char *)NO;
@@ -890,6 +891,8 @@ static void pgastatus(int pga, bool isjson)
 			status = (char *)SICK;
 		else if (cgpu->status == LIFE_NOSTART)
 			status = (char *)NOSTART;
+		else if (cgpu->deven == DEV_IDLE)
+			status = (char *)IDLE;
 		else
 			status = (char *)ALIVE;
 
@@ -1092,7 +1095,7 @@ static void pgaenable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
 
 	struct cgpu_info *cgpu = devices[dev];
 
-	if (cgpu->deven != DEV_DISABLED) {
+	if (cgpu->deven == DEV_ENABLED) {
 		strcpy(io_buffer, message(MSG_PGALRENA, id, NULL, isjson));
 		return;
 	}
@@ -1143,12 +1146,12 @@ static void pgadisable(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
 
 	struct cgpu_info *cgpu = devices[dev];
 
-	if (cgpu->deven == DEV_DISABLED) {
+	if (cgpu->deven != DEV_ENABLED) {
 		strcpy(io_buffer, message(MSG_PGALRDIS, id, NULL, isjson));
 		return;
 	}
 
-	cgpu->deven = DEV_DISABLED;
+	cgpu->deven = DEV_IDLE;
 
 	strcpy(io_buffer, message(MSG_PGADIS, id, NULL, isjson));
 }
diff --git a/cgminer.c b/cgminer.c
index a9f8445..ad1259e 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -2643,22 +2643,15 @@ void remove_pool(struct pool *pool)
 
 void write_config(FILE *fcfg)
 {
-	int i = 0;
-	int j = 0;
+	int i;
 
-	/* Write pool values in priority order */
+	/* Write pool values */
 	fputs("{\n\"pools\" : [", fcfg);
-	while((j < total_pools) && (i < total_pools)) {
-	    if(pools[i]->prio == j) {
-		    fprintf(fcfg, "%s\n\t{\n\t\t\"url\" : \"%s\",", i > 0 ? "," : "", pools[i]->rpc_url);
-		    fprintf(fcfg, "\n\t\t\"user\" : \"%s\",", pools[i]->rpc_user);
-		    fprintf(fcfg, "\n\t\t\"pass\" : \"%s\"\n\t}", pools[i]->rpc_pass);       
-            j++;
-            i=0;
-        }
-        else
-            i++;
-    }
+	for(i = 0; i < total_pools; i++) {
+		fprintf(fcfg, "%s\n\t{\n\t\t\"url\" : \"%s\",", i > 0 ? "," : "", pools[i]->rpc_url);
+		fprintf(fcfg, "\n\t\t\"user\" : \"%s\",", pools[i]->rpc_user);
+		fprintf(fcfg, "\n\t\t\"pass\" : \"%s\"\n\t}", pools[i]->rpc_pass);
+		}
 	fputs("\n]\n", fcfg);
 
 	if (nDevs) {
@@ -3925,7 +3918,7 @@ void *miner_thread(void *userdata)
 				tv_lastupdate = tv_end;
 			}
 
-			if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED)) {
+			if (unlikely(mythr->pause || cgpu->deven == DEV_DISABLED || cgpu->deven == DEV_RECOVER)) {
 				applog(LOG_WARNING, "Thread %d being disabled", thr_id);
 disabled:
 				mythr->rolling = mythr->cgpu->rolling = 0;
diff --git a/driver-icarus.c b/driver-icarus.c
index 75ab5e3..630b66b 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -566,6 +566,12 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	uint32_t values;
 	uint64_t hash_count_range;
 
+	/* Device developer can make use of idle state, until then, disable and return */
+	if (thr->cgpu->deven == DEV_IDLE) {
+		thr->cgpu->deven = DEV_DISABLED;
+		return 1;
+	}
+
 	elapsed.tv_sec = elapsed.tv_usec = 0;
 
 	icarus = thr->cgpu;
diff --git a/driver-ztex.c b/driver-ztex.c
index c881cd7..91f7a7b 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -199,6 +199,12 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	bool overflow, found, rv;
 	struct libztex_hash_data hdata[GOLDEN_BACKLOG];
 
+	/* Device developer can make use of idle state, until then, disable and return */
+	if (thr->cgpu->deven == DEV_IDLE) {
+		thr->cgpu->deven = DEV_DISABLED;
+		return 1;
+	}
+	
 	ztex = thr->cgpu->device_ztex;
 
 	memcpy(sendbuf, work->data + 64, 12);
diff --git a/miner.h b/miner.h
index ec9d725..f5f7122 100644
--- a/miner.h
+++ b/miner.h
@@ -250,6 +250,7 @@ enum dev_enable {
 	DEV_ENABLED,
 	DEV_DISABLED,
 	DEV_RECOVER,
+	DEV_IDLE,
 };
 
 enum cl_kernels {