Commit b431ea4e1f7e30735b879d9cc20c3bdb6b180e1b

Con Kolivas 2013-10-31T12:09:23

Merge branch 'master' into kncminer

diff --git a/ASIC-README b/ASIC-README
index a56666c..f495d29 100644
--- a/ASIC-README
+++ b/ASIC-README
@@ -105,7 +105,7 @@ ASIC SPECIFIC COMMANDS
 --bitburner-fury-options <arg> Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq
 --bitburner-fury-voltage <arg> Set BitBurner Fury core voltage, in millivolts
 --bitburner-voltage <arg> Set BitBurner (Avalon) core voltage, in millivolts
---klondike-options <arg> Set klondike options clock:temp1:temp2:fan
+--klondike-options <arg> Set klondike options clock:temptarget
 
 
 AVALON AND BITBURNER DEVICES
diff --git a/README b/README
index 0a96dee..7f32794 100644
--- a/README
+++ b/README
@@ -227,6 +227,7 @@ ASIC only options:
 --bitburner-fury-options <arg> Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq
 --bitburner-fury-voltage <arg> Set BitBurner Fury core voltage, in millivolts
 --bitburner-voltage <arg> Set BitBurner (Avalon) core voltage, in millivolts
+--klondike-options <arg> Set klondike options clock:temptarget
 
 See ASIC-README for more information regarding these.
 
diff --git a/cgminer.c b/cgminer.c
index 62d3718..5ef3d47 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1270,7 +1270,7 @@ static struct opt_table opt_config_table[] = {
 #ifdef USE_KLONDIKE
 	OPT_WITH_ARG("--klondike-options",
 		     set_klondike_options, NULL, NULL,
-		     "Set klondike options clock:temp1:temp2:fan"),
+		     "Set klondike options clock:temptarget"),
 #endif
 	OPT_WITHOUT_ARG("--load-balance",
 		     set_loadbalance, &pool_strategy,
diff --git a/driver-klondike.c b/driver-klondike.c
index 8648dde..a445bf4 100644
--- a/driver-klondike.c
+++ b/driver-klondike.c
@@ -208,6 +208,7 @@ typedef struct jobque {
 	int workqc;
 	struct timeval last_update;
 	bool overheat;
+	bool flushed;
 	int late_update_count;
 	int late_update_sequential;
 } JOBQUE;
@@ -315,7 +316,7 @@ static KLIST *allocate_kitem(struct cgpu_info *klncgpu)
 	cg_wunlock(&klninfo->klist_lock);
 
 	if (ran_out > 0)
-		applog(LOG_ERR, "%s", errbuf);
+		applog(LOG_WARNING, "%s", errbuf);
 
 	return kitem;
 }
@@ -709,32 +710,14 @@ static bool klondike_init(struct cgpu_info *klncgpu)
 
 	// boundaries are checked by device, with valid values returned
 	if (opt_klondike_options != NULL) {
-		int hashclock, fantarget;
-		double temp1, temp2;
+		int hashclock;
+		double temptarget;
 
-		sscanf(opt_klondike_options, "%d:%lf:%lf:%d",
-						&hashclock,
-						&temp1, &temp2,
-						&fantarget);
+		sscanf(opt_klondike_options, "%d:%lf", &hashclock, &temptarget);
 		SET_HASHCLOCK(kline.cfg.hashclock, hashclock);
-		kline.cfg.temptarget = cvtCToKln(temp1);
-		kline.cfg.tempcritical = cvtCToKln(temp2);
-		if (fantarget < 0) {
-			applog(LOG_WARNING,
-				"%s%i: %s options invalid fantarget < 0 using 0",
-				klncgpu->drv->name,
-				klncgpu->device_id,
-				klncgpu->drv->dname);
-			fantarget = 0;
-		} else if (fantarget > 100) {
-			applog(LOG_WARNING,
-				"%s%i: %s options invalid fantarget > 100 using 100",
-				klncgpu->drv->name,
-				klncgpu->device_id,
-				klncgpu->drv->dname);
-			fantarget = 100;
-		}
-		kline.cfg.fantarget = (int)(255 * fantarget / 100);
+		kline.cfg.temptarget = cvtCToKln(temptarget);
+		kline.cfg.tempcritical = 0; // hard code for old firmware
+		kline.cfg.fantarget = 0xff; // hard code for old firmware
 		size = sizeof(kline.cfg) - 2;
 	}
 
@@ -838,6 +821,7 @@ static bool klondike_detect_one(struct libusb_device *dev, struct usb_find_devic
 					break;
 				update_usb_stats(klncgpu);
 				applog(LOG_DEBUG, "Klondike cgpu added");
+				rwlock_init(&klninfo->stat_lock);
 				cglock_init(&klninfo->klist_lock);
 				return true;
 			}
@@ -985,7 +969,9 @@ static void *klondike_get_replies(void *userdata)
 		}
 		if (!err && recd == REPLY_SIZE) {
 			cgtime(&(kitem->tv_when));
+			rd_lock(&(klninfo->stat_lock));
 			kitem->block_seq = klninfo->block_seq;
+			rd_unlock(&(klninfo->stat_lock));
 			if (opt_log_level <= READ_DEBUG) {
 				hexdata = bin2hex((unsigned char *)&(kitem->kline.hd.dev), recd-1);
 				applog(READ_DEBUG, "%s%i:%d reply [%c:%s]",
@@ -1022,11 +1008,32 @@ static void *klondike_get_replies(void *userdata)
 					klondike_check_nonce(klncgpu, kitem);
 					display_kline(klncgpu, &kitem->kline, msg_reply);
 					break;
-				case KLN_CMD_STATUS:
 				case KLN_CMD_WORK:
+					// We can't do/check this until it's initialised
+					if (klninfo->initialised) {
+						dev = kitem->kline.ws.dev;
+						if (kitem->kline.ws.workqc == 0) {
+							bool idle = false;
+							rd_lock(&(klninfo->stat_lock));
+							if (klninfo->jobque[dev].flushed == false)
+								idle = true;
+							slaves = klninfo->status[0].kline.ws.slavecount;
+							rd_unlock(&(klninfo->stat_lock));
+							if (idle)
+								applog(LOG_WARNING, "%s%i:%d went idle before work was sent",
+										    klncgpu->drv->name,
+										    klncgpu->device_id,
+										    dev);
+						}
+						wr_lock(&(klninfo->stat_lock));
+						klninfo->jobque[dev].flushed = false;
+						wr_unlock(&(klninfo->stat_lock));
+					}
+				case KLN_CMD_STATUS:
 				case KLN_CMD_ABORT:
 					// We can't do/check this until it's initialised
 					if (klninfo->initialised) {
+						isc = 0;
 						dev = kitem->kline.ws.dev;
 						wr_lock(&(klninfo->stat_lock));
 						klninfo->jobque[dev].workqc = (int)(kitem->kline.ws.workqc);
@@ -1066,9 +1073,10 @@ static void *klondike_get_replies(void *userdata)
 								klninfo->jobque[dev].overheat = true;
 								wr_unlock(&(klninfo->stat_lock));
 
-								applog(LOG_ERR, "%s%i:%d Critical overheat (%.0fC)",
-										klncgpu->drv->name, klncgpu->device_id,
-										dev, temp);
+								applog(LOG_WARNING, "%s%i:%d Critical overheat (%.0fC)",
+										    klncgpu->drv->name,
+										    klncgpu->device_id,
+										    dev, temp);
 
 								zero_kline(&kline);
 								kline.hd.cmd = KLN_CMD_ABORT;
@@ -1121,13 +1129,13 @@ static void klondike_flush_work(struct cgpu_info *klncgpu)
 	KLINE kline;
 	int slaves, dev;
 
+	wr_lock(&(klninfo->stat_lock));
 	klninfo->block_seq++;
+	slaves = klninfo->status[0].kline.ws.slavecount;
+	wr_unlock(&(klninfo->stat_lock));
 
 	applog(LOG_DEBUG, "%s%i: flushing work",
 			  klncgpu->drv->name, klncgpu->device_id);
-	rd_lock(&(klninfo->stat_lock));
-	slaves = klninfo->status[0].kline.ws.slavecount;
-	rd_unlock(&(klninfo->stat_lock));
 	zero_kline(&kline);
 	kline.hd.cmd = KLN_CMD_ABORT;
 	for (dev = 0; dev <= slaves; dev++) {
@@ -1138,6 +1146,7 @@ static void klondike_flush_work(struct cgpu_info *klncgpu)
 			memcpy((void *)&(klninfo->status[dev]),
 				kitem,
 				sizeof(klninfo->status[dev]));
+			klninfo->jobque[dev].flushed = true;
 			wr_unlock(&(klninfo->stat_lock));
 			kitem = release_kitem(klncgpu, kitem);
 		}
@@ -1285,14 +1294,14 @@ static bool klondike_queue_full(struct cgpu_info *klncgpu)
 			seq = ++klninfo->jobque[dev].late_update_sequential;
 			rd_unlock(&(klninfo->stat_lock));
 			if (seq < LATE_UPDATE_LIMIT) {
-				applog(LOG_ERR, "%s%i:%d late update",
+				applog(LOG_DEBUG, "%s%i:%d late update",
 						klncgpu->drv->name, klncgpu->device_id, dev);
 				klondike_get_stats(klncgpu);
 				goto que;
 			} else {
-				applog(LOG_ERR, "%s%i:%d late update (%d) reached - attempting reset",
-						klncgpu->drv->name, klncgpu->device_id,
-						dev, LATE_UPDATE_LIMIT);
+				applog(LOG_WARNING, "%s%i:%d late update (%d) reached - attempting reset",
+						    klncgpu->drv->name, klncgpu->device_id,
+						    dev, LATE_UPDATE_LIMIT);
 				control_init(klncgpu);
 				kln_enable(klncgpu);
 				klondike_get_stats(klncgpu);
@@ -1332,9 +1341,9 @@ tryagain:
 				if (temp <= KLN_COOLED_DOWN) {
 					klninfo->jobque[dev].overheat = false;
 					rd_unlock(&(klninfo->stat_lock));
-					applog(LOG_ERR, "%s%i:%d Overheat recovered (%.0fC)",
-							klncgpu->drv->name, klncgpu->device_id,
-							dev, temp);
+					applog(LOG_WARNING, "%s%i:%d Overheat recovered (%.0fC)",
+							    klncgpu->drv->name, klncgpu->device_id,
+							    dev, temp);
 					kln_enable(klncgpu);
 					goto tryagain;
 				} else {