Browse Source

bitmain: Migrate BITMAIN_MAX_WORK_QUEUE_NUM/bitmain_work_poll_prio to runtime poll_prio_threshold

Luke Dashjr 10 years ago
parent
commit
f3e902d290
2 changed files with 21 additions and 6 deletions
  1. 20 2
      driver-bitmain.c
  2. 1 4
      driver-bitmain.h

+ 20 - 2
driver-bitmain.c

@@ -44,7 +44,6 @@
 
 const bool opt_bitmain_hwerror = true;
 const unsigned bitmain_poll_interval_us = 10000;
-const unsigned bitmain_work_poll_prio = 1024;
 
 BFG_REGISTER_DRIVER(bitmain_drv)
 static const struct bfg_set_device_definition bitmain_set_device_funcs_init[];
@@ -80,6 +79,8 @@ struct cgpu_info *btm_alloc_cgpu(struct device_drv *drv, int threads)
 		.voltage[0] = BITMAIN_DEFAULT_VOLTAGE0,
 		.voltage[1] = BITMAIN_DEFAULT_VOLTAGE1,
 		
+		.poll_prio_threshold = UINT_MAX,
+		
 		.diff = 255,
 		.lowest_goal_diff = 255,
 		.work_restart = true,
@@ -1521,7 +1522,7 @@ static bool bitmain_queue_append(struct thr_info * const thr, struct work * cons
 	info->fifo_space -= info->ready_to_queue;
 	info->ready_to_queue = 0;
 	
-	if (info->max_fifo_space - info->fifo_space > bitmain_work_poll_prio) {
+	if (info->max_fifo_space - info->fifo_space > info->poll_prio_threshold) {
 		bitmain_poll(master_thr);
 	}
 	
@@ -1769,9 +1770,21 @@ static const char *bitmain_set_packet_max_work_opt(struct cgpu_info * const proc
 	return NULL;
 }
 
+static
+const char *bitmain_set_poll_prio_threshold_opt(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 bitmain_info *info = proc->device_data;
+	const int i = atoi(newvalue);
+	if (i < 0)
+		return "Invalid setting";
+	info->poll_prio_threshold = i;
+	return NULL;
+}
+
 static const char *bitmain_set_model(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 cgpu_info * const dev = proc->device;
+	struct bitmain_info * const info = dev->device_data;
 	
 	if (toupper(newvalue[0]) != 'S') {
 unknown_model:
@@ -1789,16 +1802,20 @@ unknown_model:
 	switch (Sn) {
 		case 1:
 			bitmain_set_packet_max_work(dev, 8);
+			info->poll_prio_threshold = 0x40;
 			break;
 		case 2:
 			bitmain_set_packet_max_work(dev, 0x40);
+			info->poll_prio_threshold = 0x1000;
 			break;
 		case 3:
 			bitmain_set_packet_max_work(dev, 8);
+			info->poll_prio_threshold = 0x400;
 			break;
 		case 4:
 		case 5:
 			bitmain_set_packet_max_work(dev, 0x40);
+			info->poll_prio_threshold = 0x1000;
 			break;
 	}
 	return NULL;
@@ -1812,6 +1829,7 @@ static const struct bfg_set_device_definition bitmain_set_device_funcs_init[] =
 	{"reg_data", bitmain_set_reg_data, "reg_data (eg: x0d82)"},
 	{"voltage", bitmain_set_voltage, "voltage (must be specified as 'x' and hex data; eg: x0725)"},
 	{"packet_max_work", bitmain_set_packet_max_work_opt, NULL},
+	{"poll_prio_threshold", bitmain_set_poll_prio_threshold_opt, NULL},
 	{NULL},
 };
 

+ 1 - 4
driver-bitmain.h

@@ -63,7 +63,6 @@
 #define BITMAIN_LATENCY 1
 
 #ifdef BITMAIN_TYPE_S1
-#define BITMAIN_MAX_WORK_QUEUE_NUM 64
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 1
 #define BITMAIN_MAX_NONCE_NUM      8
 #define BITMAIN_MAX_CHAIN_NUM      8
@@ -75,7 +74,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S2
-#define BITMAIN_MAX_WORK_QUEUE_NUM 4096
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
 #define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      16
@@ -87,7 +85,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S3
-#define BITMAIN_MAX_WORK_QUEUE_NUM 1024
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 2
 #define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      8
@@ -99,7 +96,6 @@
 #endif
 
 #ifdef BITMAIN_TYPE_S4
-#define BITMAIN_MAX_WORK_QUEUE_NUM 4096
 #define BITMAIN_MAX_DEAL_QUEUE_NUM 32
 #define BITMAIN_MAX_NONCE_NUM      128
 #define BITMAIN_MAX_CHAIN_NUM      16
@@ -225,6 +221,7 @@ struct bitmain_info {
 	uint8_t reg_data[4];
 	
 	unsigned packet_max_work;  // BITMAIN_MAX_WORK_NUM
+	unsigned poll_prio_threshold;  // BITMAIN_MAX_WORK_QUEUE_NUM
 
 	int fan_num;
 	int fan[BITMAIN_MAX_FAN_NUM];