Browse Source

Merge branch 'onestringminer' into bfgminer

Luke Dashjr 12 years ago
parent
commit
f593623790
5 changed files with 154 additions and 52 deletions
  1. 87 33
      driver-bifury.c
  2. 5 14
      driver-knc.c
  3. 6 3
      driver-opencl.c
  4. 54 2
      util.c
  5. 2 0
      util.h

+ 87 - 33
driver-bifury.c

@@ -9,6 +9,8 @@
 
 #include "config.h"
 
+#include <ctype.h>
+#include <limits.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -25,9 +27,8 @@
 #include "miner.h"
 #include "util.h"
 
-#define BIFURY_MAX_QUEUED 0x10
-
 BFG_REGISTER_DRIVER(bifury_drv)
+static const struct bfg_set_device_definition bifury_set_device_funcs[];
 
 const char bifury_init_cmds[] = "flush\ntarget ffffffff\nmaxroll 0\n";
 
@@ -74,6 +75,8 @@ struct bifury_state {
 	bool has_needwork;
 	uint8_t *osc6_bits;
 	bool send_clock;
+	unsigned max_queued;
+	bool free_after_job;
 };
 
 static
@@ -82,6 +85,27 @@ bool bifury_lowl_match(const struct lowlevel_device_info * const info)
 	return lowlevel_match_product(info, "bi\xe2\x80\xa2""fury");
 }
 
+const char *bifury_init_chips(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
+{
+	int *procs_p = proc->device_data;
+	
+	if (!setting || !*setting)
+		return "missing setting";
+	
+	const int val = atoi(setting);
+	if (val < 1)
+		return "invalid setting";
+	
+	*procs_p = val;
+	
+	return NULL;
+}
+
+static const struct bfg_set_device_definition bifury_set_device_funcs_probe[] = {
+	{"chips", bifury_init_chips, NULL},
+	{NULL},
+};
+
 static
 bool bifury_detect_one(const char * const devpath)
 {
@@ -155,10 +179,13 @@ bool bifury_detect_one(const char * const devpath)
 	if (serial_claim_v(devpath, &bifury_drv))
 		return false;
 	
+	drv_set_defaults(&bifury_drv, bifury_set_device_funcs_probe, &chips, devpath, detectone_meta_info.serial, 1);
+	
 	cgpu = malloc(sizeof(*cgpu));
 	*cgpu = (struct cgpu_info){
 		.drv = &bifury_drv,
 		.device_path = strdup(devpath),
+		.set_device_funcs = bifury_set_device_funcs,
 		.deven = DEV_ENABLED,
 		.procs = chips,
 		.threads = 1,
@@ -245,6 +272,8 @@ bool bifury_thread_init(struct thr_info *master_thr)
 	*state = (struct bifury_state){
 		.buf = BYTES_INIT,
 		.osc6_bits = malloc(sizeof(*state->osc6_bits) * dev->procs),
+		.max_queued = dev->procs * 4,
+		.free_after_job = true,
 	};
 	for (int i = 0; i < dev->procs; ++i)
 		state->osc6_bits[i] = 54;
@@ -304,7 +333,7 @@ bool bifury_queue_append(struct thr_info * const thr, struct work *work)
 		return false;
 	}
 	HASH_ADD(hh, master_thr->work_list, device_id, sizeof(work->device_id), work);
-	int prunequeue = HASH_COUNT(master_thr->work_list) - BIFURY_MAX_QUEUED;
+	int prunequeue = HASH_COUNT(master_thr->work_list) - state->max_queued;
 	if (prunequeue > 0)
 	{
 		struct work *tmp;
@@ -418,8 +447,11 @@ void bifury_handle_cmd(struct cgpu_info * const dev, const char * const cmd)
 			else
 				applog(LOG_DEBUG, "%s: Unknown chip id: %s",
 				       dev->dev_repr, cmd);
-			HASH_DEL(master_thr->work_list, work);
-			free_work(work);
+			if (state->free_after_job)
+			{
+				HASH_DEL(master_thr->work_list, work);
+				free_work(work);
+			}
 		}
 		else
 			applog(LOG_WARNING, "%s: Unknown job id: %s",
@@ -503,38 +535,54 @@ struct api_data *bifury_api_device_status(struct cgpu_info * const proc)
 	return root;
 }
 
-char *bifury_set_device(struct cgpu_info * const proc, char * const option, char * const setting, char * const replybuf)
+const char *bifury_set_osc6_bits(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
 {
 	struct bifury_state * const state = proc->device_data;
 	
-	if (!strcasecmp(option, "help"))
-	{
-		sprintf(replybuf, "osc6_bits: range 33-63 (slow to fast)");
-		return replybuf;
-	}
+	if (!setting || !*setting)
+		return "missing setting";
 	
-	if (!strcasecmp(option, "osc6_bits"))
-	{
-		if (!setting || !*setting)
-		{
-			sprintf(replybuf, "missing setting");
-			return replybuf;
-		}
-		const uint8_t val = atoi(setting);
-		if (val < 33 || val > 63)
-		{
-			sprintf(replybuf, "invalid setting");
-			return replybuf;
-		}
-		
-		state->osc6_bits[proc->proc_id] = val;
-		state->send_clock = true;
-		
-		return NULL;
-	}
+	const int val = atoi(setting);
+	if (val < 33 || val > 63)
+		return "invalid setting";
+	
+	state->osc6_bits[proc->proc_id] = val;
+	state->send_clock = true;
 	
-	sprintf(replybuf, "Unknown option: %s", option);
-	return replybuf;
+	return NULL;
+}
+
+const char *bifury_set_max_queued(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
+{
+	struct bifury_state * const state = proc->device_data;
+	
+	if (!setting || !*setting)
+		return "missing setting";
+	
+	const long val = strtol(setting, NULL, 0);
+	if (val < 1 || val > UINT_MAX)
+		return "invalid setting";
+	
+	state->max_queued = val;
+	
+	return NULL;
+}
+
+const char *bifury_set_free_after_job(struct cgpu_info * const proc, const char * const option, const char * const setting, char * const replybuf, enum bfg_set_device_replytype * const success)
+{
+	struct bifury_state * const state = proc->device_data;
+	
+	if (!setting || !*setting)
+		return "missing setting";
+	
+	char *end;
+	const bool val = bfg_strtobool(setting, &end, 0);
+	if (end[0] && !isspace(end[0]))
+		return "invalid setting";
+	
+	state->free_after_job = val;
+	
+	return NULL;
 }
 
 #ifdef HAVE_CURSES
@@ -572,6 +620,13 @@ void bifury_wlogprint_status(struct cgpu_info * const proc)
 }
 #endif
 
+static const struct bfg_set_device_definition bifury_set_device_funcs[] = {
+	{"max_queued", bifury_set_max_queued, NULL},
+	{"free_after_job", bifury_set_free_after_job, NULL},
+	{"osc6_bits", bifury_set_osc6_bits, "range 33-63 (slow to fast)"},
+	{NULL},
+};
+
 struct device_drv bifury_drv = {
 	.dname = "bifury",
 	.name = "BIF",
@@ -589,7 +644,6 @@ struct device_drv bifury_drv = {
 	.poll = bifury_poll,
 	
 	.get_api_extra_device_status = bifury_api_device_status,
-	.set_device = bifury_set_device,
 	
 #ifdef HAVE_CURSES
 	.proc_wlogprint_status = bifury_wlogprint_status,

+ 5 - 14
driver-knc.c

@@ -31,6 +31,7 @@
 #include "logging.h"
 #include "lowl-spi.h"
 #include "miner.h"
+#include "util.h"
 
 #define KNC_POLL_INTERVAL_US 10000
 #define KNC_SPI_SPEED 3000000
@@ -825,21 +826,11 @@ const char *knc_set_use_dcdc(struct cgpu_info *proc, const char * const optname,
 {
 	int core_index_on_die = proc->proc_id % KNC_CORES_PER_DIE;
 	bool nv;
+	char *end;
 	
-	if (!(strcasecmp(newvalue, "no") && strcasecmp(newvalue, "false") && strcasecmp(newvalue, "0") && strcasecmp(newvalue, "off") && strcasecmp(newvalue, "disable")))
-		nv = false;
-	else
-	if (!(strcasecmp(newvalue, "yes") && strcasecmp(newvalue, "true") && strcasecmp(newvalue, "on") && strcasecmp(newvalue, "enable")))
-		nv = true;
-	else
-	{
-		char *p;
-		strtol(newvalue, &p, 0);
-		if (newvalue[0] && !p[0])
-			nv = true;
-		else
-			return "Usage: use_dcdc=yes/no";
-	}
+	nv = bfg_strtobool(newvalue, &end, 0);
+	if (!(newvalue[0] && !end[0]))
+		return "Usage: use_dcdc=yes/no";
 	
 	if (core_index_on_die)
 	{

+ 6 - 3
driver-opencl.c

@@ -432,9 +432,12 @@ static
 const char *opencl_init_binary(struct cgpu_info * const proc, const char * const optname, const char * const newvalue, char * const replybuf, enum bfg_set_device_replytype * const out_success)
 {
 	struct opencl_device_data * const data = proc->device_data;
+	char *end;
+	bool nv;
 	
-	if (!(strcasecmp(newvalue, "no") && strcasecmp(newvalue, "never") && strcasecmp(newvalue, "none")))
-		data->opt_opencl_binaries = OBU_NONE;
+	nv = bfg_strtobool(newvalue, &end, 0);
+	if (newvalue[0] && !end[0])
+		data->opt_opencl_binaries = nv ? OBU_LOADSAVE : OBU_NONE;
 	else
 	if (!(strcasecmp(newvalue, "load") && strcasecmp(newvalue, "read")))
 		data->opt_opencl_binaries = OBU_LOAD;
@@ -442,7 +445,7 @@ const char *opencl_init_binary(struct cgpu_info * const proc, const char * const
 	if (!(strcasecmp(newvalue, "save") && strcasecmp(newvalue, "write")))
 		data->opt_opencl_binaries = OBU_SAVE;
 	else
-	if (!(strcasecmp(newvalue, "yes") && strcasecmp(newvalue, "always") && strcasecmp(newvalue, "both")))
+	if (!(strcasecmp(newvalue, "both")))
 		data->opt_opencl_binaries = OBU_LOADSAVE;
 	else
 	if (!(strcasecmp(newvalue, "default")))

+ 54 - 2
util.c

@@ -2058,6 +2058,53 @@ void test_domain_funcs()
 	_test_get_regd_domain("2001:db8::1", "2001:db8::1");
 }
 
+struct bfg_strtobool_keyword {
+	bool val;
+	const char *keyword;
+};
+
+bool bfg_strtobool(const char * const s, char ** const endptr, __maybe_unused const int opts)
+{
+	struct bfg_strtobool_keyword keywords[] = {
+		{false, "false"},
+		{false, "never"},
+		{false, "none"},
+		{false, "off"},
+		{false, "no"},
+		{false, "0"},
+		
+		{true , "always"},
+		{true , "true"},
+		{true , "yes"},
+		{true , "on"},
+	};
+	
+	const int total_keywords = sizeof(keywords) / sizeof(*keywords);
+	for (int i = 0; i < total_keywords; ++i)
+	{
+		const size_t kwlen = strlen(keywords[i].keyword);
+		if (!strncasecmp(keywords[i].keyword, s, kwlen))
+		{
+			if (endptr)
+				*endptr = (char*)&s[kwlen];
+			return keywords[i].val;
+		}
+	}
+	
+	char *lend;
+	strtol(s, &lend, 0);
+	if (lend > s)
+	{
+		if (endptr)
+			*endptr = lend;
+		// Any number other than "0" is intentionally considered true, including 0x0
+		return true;
+	}
+	
+	*endptr = (char*)s;
+	return false;
+}
+
 bool uri_get_param_bool(const char * const uri, const char * const param, const bool defval)
 {
 	const char *start = strchr(uri, '#');
@@ -2081,8 +2128,10 @@ nextmatch:
 	if (q[0] == '=')
 	{
 		++q;
-		if (q[0] == '0' && !isCalpha(q[1]))
-			foundval = false;
+		char *end;
+		bool v = bfg_strtobool(q, &end, 0);
+		if (end > q && !isCalpha(end[0]))
+			foundval = v;
 	}
 	if (invert)
 		foundval = !foundval;
@@ -2114,6 +2163,9 @@ void test_uri_get_param()
 	_test_uri_get_param("stratum+tcp://footest/#redirect=1,foo=0", "redirect", false, true);
 	_test_uri_get_param("stratum+tcp://footest/#foo=1,noredirect=0,foo=1", "redirect", false, true);
 	_test_uri_get_param("stratum+tcp://footest/#bar=0,noredirect=1,foo=0", "redirect", true, false);
+	_test_uri_get_param("stratum+tcp://footest/#redirect=false", "redirect", true, false);
+	_test_uri_get_param("stratum+tcp://footest/#redirect=no", "redirect", true, false);
+	_test_uri_get_param("stratum+tcp://footest/#redirect=yes", "redirect", false, true);
 }
 
 void stratum_probe_transparency(struct pool *pool)

+ 2 - 0
util.h

@@ -119,6 +119,8 @@ extern const char *extract_domain(size_t *out_len, const char *uri, size_t urile
 extern bool match_domains(const char *a, size_t alen, const char *b, size_t blen);
 extern void test_domain_funcs();
 
+extern bool bfg_strtobool(const char *, char **endptr, int opts);
+
 extern bool uri_get_param_bool(const char *uri, const char *param, bool defval);
 extern void test_uri_get_param();