Browse Source

DevAPI: add_cgpu_slave for more elegant multi-device threads

Luke Dashjr 12 years ago
parent
commit
de942d5894
3 changed files with 24 additions and 12 deletions
  1. 18 0
      deviceapi.c
  2. 1 0
      deviceapi.h
  3. 5 12
      driver-metabank.c

+ 18 - 0
deviceapi.c

@@ -708,6 +708,24 @@ void add_cgpu_live(void *p)
 	add_cgpu(p);
 }
 
+bool add_cgpu_slave(struct cgpu_info *cgpu, struct cgpu_info *prev_cgpu)
+{
+	int old_total_devices = total_devices_new;
+	
+	if (!prev_cgpu)
+		return add_cgpu(cgpu);
+	
+	while (prev_cgpu->next_proc)
+		prev_cgpu = prev_cgpu->next_proc;
+	
+	if (!add_cgpu(cgpu))
+		return false;
+	
+	prev_cgpu->next_proc = devices_new[old_total_devices];
+	
+	return true;
+}
+
 int _serial_detect(struct device_drv *api, detectone_func_t detectone, autoscan_func_t autoscan, int flags)
 {
 	struct string_elist *iter, *tmp;

+ 1 - 0
deviceapi.h

@@ -34,6 +34,7 @@ extern void minerloop_queue(struct thr_info *);
 extern void *miner_thread(void *);
 
 extern void add_cgpu_live(void*);
+extern bool add_cgpu_slave(struct cgpu_info *, struct cgpu_info *master);
 
 typedef bool(*detectone_func_t)(const char*);
 typedef int(*autoscan_func_t)();

+ 5 - 12
driver-metabank.c

@@ -48,7 +48,7 @@ int metabank_autodetect()
 {
 	RUNONCE(0);
 	
-	struct cgpu_info *cgpu = NULL, *proc1 = NULL;
+	struct cgpu_info *cgpu = NULL, *proc1 = NULL, *prev_cgpu = NULL;
 	struct bitfury_device **devicelist, *bitfury;
 	struct spi_port *port;
 	int i, j;
@@ -111,11 +111,12 @@ int metabank_autodetect()
 					.procs = chip_n,
 					.device_data = devicelist,
 				};
-				add_cgpu(cgpu);
+				add_cgpu_slave(cgpu, prev_cgpu);
 				
 				proc_count += chip_n;
 				if (!proc1)
 					proc1 = cgpu;
+				prev_cgpu = cgpu;
 			}
 			else
 				free(port);
@@ -141,7 +142,7 @@ bool metabank_init(struct thr_info *thr)
 	struct bitfury_device *bitfury;
 	int devid;
 	
-	for (proc = get_devices(devid = thr->cgpu->cgminer_id); ; proc = next_proc)
+	for (proc = thr->cgpu; proc; proc = proc->next_proc)
 	{
 		devicelist = proc->device_data;
 		bitfury = devicelist[proc->proc_id];
@@ -151,16 +152,8 @@ bool metabank_init(struct thr_info *thr)
 		bitfury->osc6_bits = 54;
 		send_reinit(bitfury->spi, bitfury->slot, bitfury->fasync, bitfury->osc6_bits);
 		
-		if (!proc->next_proc)
+		if (proc->proc_id == proc->procs - 1)
 			free(devicelist);
-		
-		if (++devid < total_devices
-		 && (next_proc = get_devices(devid))
-		 && next_proc->drv == &metabank_drv
-		 && !next_proc->threads)
-			proc->next_proc = next_proc;
-		else
-			break;
 	}
 	
 	return true;