Browse Source

Bugfix: Cleanup handling of complete device/driver failure

Luke Dashjr 12 years ago
parent
commit
882e06480e
4 changed files with 31 additions and 8 deletions
  1. 12 3
      deviceapi.c
  2. 2 0
      driver-modminer.c
  3. 16 5
      miner.c
  4. 1 0
      miner.h

+ 12 - 3
deviceapi.c

@@ -580,12 +580,21 @@ void *miner_thread(void *userdata)
 		minerloop_scanhash(mythr);
 	__thr_being_msg(LOG_NOTICE, mythr, "shutting down");
 
-out:
-	cgpu->deven = DEV_DISABLED;
+out: ;
+	struct cgpu_info *proc = cgpu;
+	do
+	{
+		proc->deven = DEV_DISABLED;
+		proc->status = LIFE_DEAD2;
+	}
+	while ( (proc = proc->next_proc) && !proc->threads);
+	mythr->getwork = 0;
+	mythr->has_pth = false;
+	nmsleep(1000);
+	
 	if (drv->thread_shutdown)
 		drv->thread_shutdown(mythr);
 
-	thread_reportin(mythr);
 	notifier_destroy(mythr->notifier);
 
 	return NULL;

+ 2 - 0
driver-modminer.c

@@ -795,6 +795,8 @@ modminer_scanhash(struct thr_info*thr, struct work*work, int64_t __maybe_unused
 static void
 modminer_fpga_shutdown(struct thr_info *thr)
 {
+	for (struct cgpu_info *proc = thr->cgpu->device; proc; proc = proc->next_proc)
+		proc->status = LIFE_DEAD2;
 	free(thr->cgpu_data);
 	thr->cgpu_data = NULL;
 }

+ 16 - 5
miner.c

@@ -2232,6 +2232,17 @@ double stats_elapsed(struct cgminer_stats *stats)
 	return elapsed;
 }
 
+bool drv_ready(struct cgpu_info *cgpu)
+{
+	switch (cgpu->status) {
+		case LIFE_INIT:
+		case LIFE_DEAD2:
+			return false;
+		default:
+			return true;
+	}
+}
+
 double cgpu_utility(struct cgpu_info *cgpu)
 {
 	double dev_runtime = cgpu_runtime(cgpu);
@@ -2475,7 +2486,7 @@ void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_
 		return;
 	}
 	
-	if (drv->get_dev_statline_before || drv->get_statline_before)
+	if ((drv->get_dev_statline_before || drv->get_statline_before) && likely(drv_ready(cgpu)))
 	{
 		if (drv->get_dev_statline_before && drv->get_statline_before)
 			statline_func = opt_show_procs ? drv->get_statline_before : drv->get_dev_statline_before;
@@ -2505,7 +2516,7 @@ void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_
 					if (proc->deven == DEV_RECOVER)
 						cHrStatsI = 3;
 				case 3:
-					if (proc->status == LIFE_SICK || proc->status == LIFE_DEAD)
+					if (proc->status == LIFE_SICK || proc->status == LIFE_DEAD || proc->status == LIFE_DEAD2)
 					{
 						cHrStatsI = 1;
 						all_off = false;
@@ -2516,7 +2527,7 @@ void get_statline3(char *buf, struct cgpu_info *cgpu, bool for_curses, bool opt_
 				case 1:
 					break;
 			}
-			if (likely(proc->status != LIFE_DEAD))
+			if (likely(proc->status != LIFE_DEAD && proc->status != LIFE_DEAD2))
 				all_dead = false;
 			if (opt_show_procs)
 				break;
@@ -6016,7 +6027,7 @@ refresh:
 			case '\n':
 				goto out;
 			default:
-				if (drv->proc_tui_handle_choice && likely(cgpu->status != LIFE_INIT))
+				if (drv->proc_tui_handle_choice && likely(drv_ready(cgpu)))
 				{
 					msg = drv->proc_tui_handle_choice(cgpu, input);
 					if (msg)
@@ -8084,7 +8095,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			char *dev_str = cgpu->proc_repr;
 			int gpu;
 
-			if (cgpu->drv->get_stats && likely(cgpu->status != LIFE_INIT))
+			if (cgpu->drv->get_stats && likely(drv_ready(cgpu)))
 			  cgpu->drv->get_stats(cgpu);
 
 			gpu = cgpu->device_id;

+ 1 - 0
miner.h

@@ -216,6 +216,7 @@ enum alive {
 	LIFE_INIT,
 	LIFE_WAIT,
 	LIFE_INIT2,  // Still initializing, but safe to call functions
+	LIFE_DEAD2,  // Totally dead, NOT safe to call functions
 };