Browse Source

Bugfix: Unify all mining thread wakeup to mt_enable (simplifying and fixing code)

- When reinitializing a GPU, `init` was being set on the last processor instead of the GPU being reinitialized
- When enabling devices based on scheduled time, disabled ones were left with threads paused
Luke Dashjr 13 years ago
parent
commit
399491f863
4 changed files with 47 additions and 98 deletions
  1. 6 30
      api.c
  2. 16 48
      driver-opencl.c
  3. 23 20
      miner.c
  4. 2 0
      miner.h

+ 6 - 30
api.c

@@ -573,9 +573,6 @@ struct CODES {
 
 static int my_thr_id = 0;
 static bool bye;
-#if defined(HAVE_OPENCL) || defined(HAVE_AN_FPGA)
-static bool ping = true;
-#endif
 
 // Used to control quit restart access to shutdown variables
 static pthread_mutex_t quit_restart_lock;
@@ -1681,10 +1678,7 @@ static void pgadev(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *p
 static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
 {
 	int numpga = numpgas();
-	struct thr_info *thr;
-	int pga;
 	int id;
-	int i;
 
 	if (numpga == 0) {
 		message(io_data, MSG_PGANON, 0, NULL, isjson);
@@ -1725,15 +1719,7 @@ static void pgaenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 	}
 #endif
 
-	for (i = 0; i < mining_threads; i++) {
-		pga = thr_info[i].cgpu->cgminer_id;
-		if (pga == dev) {
-			thr = &thr_info[i];
-			cgpu->deven = DEV_ENABLED;
-			applog(LOG_DEBUG, "API: pushing ping (%d) to thread %d", ping, thr->id);
-			tq_push(thr->q, &ping);
-		}
-	}
+	proc_enable(cgpu);
 
 	message(io_data, MSG_PGAENA, id, NULL, isjson);
 }
@@ -1997,10 +1983,7 @@ static void summary(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __mayb
 #ifdef HAVE_OPENCL
 static void gpuenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char *param, bool isjson, __maybe_unused char group)
 {
-	struct thr_info *thr;
-	int gpu;
 	int id;
-	int i;
 
 	if (gpu_threads == 0) {
 		message(io_data, MSG_GPUNON, 0, NULL, isjson);
@@ -2026,19 +2009,12 @@ static void gpuenable(struct io_data *io_data, __maybe_unused SOCKETTYPE c, char
 		return;
 	}
 
-	for (i = 0; i < gpu_threads; i++) {
-		gpu = thr_info[i].cgpu->device_id;
-		if (gpu == id) {
-			thr = &thr_info[i];
-			if (thr->cgpu->status != LIFE_WELL) {
-				message(io_data, MSG_GPUMRE, id, NULL, isjson);
-				return;
-			}
-			gpus[id].deven = DEV_ENABLED;
-			applog(LOG_DEBUG, "API: pushing ping (%d) to thread %d", ping, thr->id);
-			tq_push(thr->q, &ping);
-		}
+	if (gpus[id].status != LIFE_WELL)
+	{
+		message(io_data, MSG_GPUMRE, id, NULL, isjson);
+		return;
 	}
+	proc_enable(&gpus[id]);
 
 	message(io_data, MSG_GPUREN, id, NULL, isjson);
 }

+ 16 - 48
driver-opencl.c

@@ -824,7 +824,7 @@ void pause_dynamic_threads(int gpu)
 
 		thr->pause = cgpu->dynamic;
 		if (!cgpu->dynamic && cgpu->deven != DEV_DISABLED)
-			tq_push(thr->q, &ping);
+			mt_enable(thr);
 	}
 }
 
@@ -957,26 +957,17 @@ retry:
 			wlogprint("Invalid selection\n");
 			goto retry;
 		}
+		cgpu = &gpus[selected];
 		if (gpus[selected].deven != DEV_DISABLED) {
 			wlogprint("Device already enabled\n");
 			goto retry;
 		}
 		gpus[selected].deven = DEV_ENABLED;
-		for (i = 0; i < mining_threads; ++i) {
-			thr = &thr_info[i];
-			cgpu = thr->cgpu;
-			if (cgpu->api != &opencl_api)
-				continue;
-			if (dev_from_id(i) != selected)
-				continue;
-			if (cgpu->status != LIFE_WELL) {
-				wlogprint("Must restart device before enabling it");
-				goto retry;
-			}
-			applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
-
-			tq_push(thr->q, &ping);
+		if (cgpu->status != LIFE_WELL) {
+			wlogprint("Must restart device before enabling it");
+			goto retry;
 		}
+		proc_enable(cgpu);
 		goto retry;
 	} if (!strncasecmp(&input, "d", 1)) {
 		if (selected)
@@ -1333,7 +1324,7 @@ void *reinit_gpu(void *userdata)
 	struct timeval now;
 	char name[256];
 	int thr_id;
-	int gpu;
+	int i;
 
 	pthread_detach(pthread_self());
 	RenameThread("reinit_gpu");
@@ -1348,21 +1339,10 @@ select_cgpu:
 		goto out;
 	}
 
-	gpu = cgpu->device_id;
-
-	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
-		thr = &thr_info[thr_id];
-		cgpu = thr->cgpu;
-		if (cgpu->api != &opencl_api)
-			continue;
-		if (dev_from_id(thr_id) != gpu)
-			continue;
-
-		thr = &thr_info[thr_id];
-		if (!thr) {
-			applog(LOG_WARNING, "No reference to thread %d exists", thr_id);
-			continue;
-		}
+	for (i = 0; i < cgpu->threads; ++i)
+	{
+		thr = cgpu->thr[i];
+		thr_id = thr->id;
 
 		thr->rolling = thr->cgpu->rolling = 0;
 		/* Reports the last time we tried to revive a sick GPU */
@@ -1373,15 +1353,12 @@ select_cgpu:
 			applog(LOG_WARNING, "Thread %d no longer exists", thr_id);
 	}
 
-	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
+	for (i = 0; i < cgpu->threads; ++i)
+	{
 		int virtual_gpu;
 
-		thr = &thr_info[thr_id];
-		cgpu = thr->cgpu;
-		if (cgpu->api != &opencl_api)
-			continue;
-		if (dev_from_id(thr_id) != gpu)
-			continue;
+		thr = cgpu->thr[i];
+		thr_id = thr->id;
 
 		virtual_gpu = cgpu->virtual_gpu;
 		/* Lose this ram cause we may get stuck here! */
@@ -1412,16 +1389,7 @@ select_cgpu:
 	gettimeofday(&now, NULL);
 	get_datestamp(cgpu->init, &now);
 
-	for (thr_id = 0; thr_id < mining_threads; ++thr_id) {
-		thr = &thr_info[thr_id];
-		cgpu = thr->cgpu;
-		if (cgpu->api != &opencl_api)
-			continue;
-		if (dev_from_id(thr_id) != gpu)
-			continue;
-
-		tq_push(thr->q, &ping);
-	}
+	proc_enable(cgpu);
 
 	goto select_cgpu;
 out:

+ 23 - 20
miner.c

@@ -311,8 +311,6 @@ static int include_count;
 	static int forkpid;
 #endif // defined(unix)
 
-bool ping = true;
-
 struct sigaction termhandler, inthandler;
 
 struct thread_q *getq;
@@ -7277,19 +7275,24 @@ static void *watchpool_thread(void __maybe_unused *userdata)
 	return NULL;
 }
 
-void device_recovered(struct cgpu_info *cgpu)
+void mt_enable(struct thr_info *thr)
+{
+	static const bool ping = true;
+	applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
+	tq_push(thr->q, (void*)&ping);
+}
+
+void proc_enable(struct cgpu_info *cgpu)
 {
-	struct thr_info *thr;
 	int j;
 
 	cgpu->deven = DEV_ENABLED;
-	for (j = 0; j < cgpu->threads; ++j) {
-		thr = cgpu->thr[j];
-		applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
-		tq_push(thr->q, &ping);
-	}
+	for (j = cgpu->threads ?: 1; j--; )
+		mt_enable(cgpu->thr[j]);
 }
 
+#define device_recovered(cgpu)  proc_enable(cgpu)
+
 /* Makes sure the hashmeter keeps going even if mining threads stall, updates
  * the screen at regular intervals, and restarts threads if they appear to have
  * died. */
@@ -7363,13 +7366,17 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 			for (i = 0; i < mining_threads; i++) {
 				struct thr_info *thr;
 				thr = &thr_info[i];
-
+				thr->pause = false;
+			}
+			
+			for (i = 0; i < total_devices; ++i)
+			{
+				struct cgpu_info *cgpu = devices[i];
+				
 				/* Don't touch disabled devices */
-				if (thr->cgpu->deven == DEV_DISABLED)
+				if (cgpu->deven == DEV_DISABLED)
 					continue;
-				thr->pause = false;
-				if (thr->cgpu->threads)
-					tq_push(thr->q, &ping);
+				proc_enable(cgpu);
 			}
 		}
 
@@ -8501,12 +8508,6 @@ begin_bench:
 
 			/* Enable threads for devices set not to mine but disable
 			 * their queue in case we wish to enable them later */
-			if (cgpu->deven != DEV_DISABLED) {
-				applog(LOG_DEBUG, "Pushing ping to thread %d", thr->id);
-
-				tq_push(thr->q, &ping);
-			}
-
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 				continue;
 
@@ -8529,6 +8530,8 @@ begin_bench:
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
 				quit(1, "thread %d create failed", thr->id);
 		}
+		if (cgpu->deven == DEV_ENABLED)
+			proc_enable(cgpu);
 	}
 
 #ifdef HAVE_OPENCL

+ 2 - 0
miner.h

@@ -788,6 +788,8 @@ extern int stale_wait(unsigned int mstime, struct work*, bool checkend);
 extern void kill_work(void);
 extern void app_restart(void);
 
+extern void mt_enable(struct thr_info *thr);
+extern void proc_enable(struct cgpu_info *);
 extern void reinit_device(struct cgpu_info *cgpu);
 
 #ifdef HAVE_ADL