From 4153d907d414a467e3a37f100f7a739fd6fa033c Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 29 Oct 2013 19:17:44 +1100 Subject: [PATCH 1/7] klondike - fix isc uninit warning --- driver-klondike.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-klondike.c b/driver-klondike.c index 8648ddef..deb87f12 100644 --- a/driver-klondike.c +++ b/driver-klondike.c @@ -1027,6 +1027,7 @@ static void *klondike_get_replies(void *userdata) 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); From b4eb870af00246256da3cd9a688d14dce9f122a0 Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 29 Oct 2013 19:37:26 +1100 Subject: [PATCH 2/7] klondike - downgrade 'late update' but add an idle detect - and correct error levels --- driver-klondike.c | 54 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/driver-klondike.c b/driver-klondike.c index deb87f12..bcd38992 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; } @@ -985,7 +986,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,8 +1025,27 @@ 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) { + 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_lock(&(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_lock(&(klninfo->stat_lock)); + } + case KLN_CMD_STATUS: case KLN_CMD_ABORT: // We can't do/check this until it's initialised if (klninfo->initialised) { @@ -1067,9 +1089,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; @@ -1122,13 +1145,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++) { @@ -1139,6 +1162,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); } @@ -1286,14 +1310,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); @@ -1333,9 +1357,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 { From 5ce372e5df6d7884dfa2f2753f274df2fe07f050 Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 29 Oct 2013 20:48:21 +1100 Subject: [PATCH 3/7] klondike - fix another uninit dev warning --- driver-klondike.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-klondike.c b/driver-klondike.c index bcd38992..f38314cb 100644 --- a/driver-klondike.c +++ b/driver-klondike.c @@ -1028,6 +1028,7 @@ static void *klondike_get_replies(void *userdata) 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)); From 3e93b268faf7b68d2d645e84427a13c010faded7 Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 29 Oct 2013 19:46:35 +1100 Subject: [PATCH 4/7] klondike - change options to clock and temptarget only --- ASIC-README | 2 +- README | 1 + cgminer.c | 2 +- driver-klondike.c | 30 ++++++------------------------ 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/ASIC-README b/ASIC-README index a56666cb..f495d29f 100644 --- a/ASIC-README +++ b/ASIC-README @@ -105,7 +105,7 @@ ASIC SPECIFIC COMMANDS --bitburner-fury-options Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq --bitburner-fury-voltage Set BitBurner Fury core voltage, in millivolts --bitburner-voltage Set BitBurner (Avalon) core voltage, in millivolts ---klondike-options Set klondike options clock:temp1:temp2:fan +--klondike-options Set klondike options clock:temptarget AVALON AND BITBURNER DEVICES diff --git a/README b/README index 0a96dee1..7f327940 100644 --- a/README +++ b/README @@ -227,6 +227,7 @@ ASIC only options: --bitburner-fury-options Override avalon-options for BitBurner Fury boards baud:miners:asic:timeout:freq --bitburner-fury-voltage Set BitBurner Fury core voltage, in millivolts --bitburner-voltage Set BitBurner (Avalon) core voltage, in millivolts +--klondike-options Set klondike options clock:temptarget See ASIC-README for more information regarding these. diff --git a/cgminer.c b/cgminer.c index f4cb7d6d..6cba29fc 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 f38314cb..54743d64 100644 --- a/driver-klondike.c +++ b/driver-klondike.c @@ -710,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; } From f75fdbbbbe2c74dc02f08c0e9b9a06db8c1decfc Mon Sep 17 00:00:00 2001 From: Vitalii Demianets Date: Thu, 22 Aug 2013 16:02:02 +0200 Subject: [PATCH 5/7] Improve performance of work generation by optimizing hex2bin and bin2hex sprintf is a very expensive function, do direct translation instead. --- util.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/util.c b/util.c index 032a82ca..d3d2897f 100644 --- a/util.c +++ b/util.c @@ -588,10 +588,13 @@ char *get_proxy(char *url, struct pool *pool) void __bin2hex(char *s, const unsigned char *p, size_t len) { int i; + static const char hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - for (i = 0; i < (int)len; i++) - sprintf(s + (i * 2), "%02x", (unsigned int)p[i]); - + for (i = 0; i < (int)len; i++) { + *s++ = hex[p[i] >> 4]; + *s++ = hex[p[i] & 0xF]; + } + *s++ = '\0'; } /* Returns a malloced array string of a binary value of arbitrary length. The @@ -615,33 +618,48 @@ char *bin2hex(const unsigned char *p, size_t len) } /* Does the reverse of bin2hex but does not allocate any ram */ +static const int hex2bin_tbl[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; bool hex2bin(unsigned char *p, const char *hexstr, size_t len) { + int nibble1, nibble2; + unsigned char idx; bool ret = false; while (*hexstr && len) { - char hex_byte[4]; - unsigned int v; - if (unlikely(!hexstr[1])) { applog(LOG_ERR, "hex2bin str truncated"); return ret; } - memset(hex_byte, 0, 4); - hex_byte[0] = hexstr[0]; - hex_byte[1] = hexstr[1]; + idx = *hexstr++; + nibble1 = hex2bin_tbl[idx]; + idx = *hexstr++; + nibble2 = hex2bin_tbl[idx]; - if (unlikely(sscanf(hex_byte, "%x", &v) != 1)) { - applog(LOG_INFO, "hex2bin sscanf '%s' failed", hex_byte); + if (unlikely((nibble1 < 0) || (nibble2 < 0))) { + applog(LOG_ERR, "hex2bin scan failed"); return ret; } - *p = (unsigned char) v; - - p++; - hexstr += 2; - len--; + *p++ = (((unsigned char)nibble1) << 4) | ((unsigned char)nibble2); + --len; } if (likely(len == 0 && *hexstr == 0)) From 75230ed80814f2a7f11ef7d78040c19203ab0759 Mon Sep 17 00:00:00 2001 From: Kano Date: Tue, 29 Oct 2013 22:30:34 +1100 Subject: [PATCH 6/7] klondike - better to unlock locks than to lock them twice :) --- driver-klondike.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/driver-klondike.c b/driver-klondike.c index 54743d64..807e7042 100644 --- a/driver-klondike.c +++ b/driver-klondike.c @@ -1017,7 +1017,7 @@ static void *klondike_get_replies(void *userdata) if (klninfo->jobque[dev].flushed == false) idle = true; slaves = klninfo->status[0].kline.ws.slavecount; - rd_lock(&(klninfo->stat_lock)); + rd_unlock(&(klninfo->stat_lock)); if (idle) applog(LOG_WARNING, "%s%i:%d went idle before work was sent", klncgpu->drv->name, @@ -1026,7 +1026,7 @@ static void *klondike_get_replies(void *userdata) } wr_lock(&(klninfo->stat_lock)); klninfo->jobque[dev].flushed = false; - wr_lock(&(klninfo->stat_lock)); + wr_unlock(&(klninfo->stat_lock)); } case KLN_CMD_STATUS: case KLN_CMD_ABORT: From f562174a39738a5906de0d11a690bbc12a5b1461 Mon Sep 17 00:00:00 2001 From: Kano Date: Wed, 30 Oct 2013 11:44:52 +1100 Subject: [PATCH 7/7] klondike - initialise stat_lock --- driver-klondike.c | 1 + 1 file changed, 1 insertion(+) diff --git a/driver-klondike.c b/driver-klondike.c index 807e7042..a445bf4e 100644 --- a/driver-klondike.c +++ b/driver-klondike.c @@ -821,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; }