Browse Source

Replace mining thread queues (which were only used for wakeup pings) with notifiers (which can be used with select and co)

This reverts 7d544d91737bce167ca070714e23184e7768a257, with the assumption that multithread processors are all-or-nothing.
Luke Dashjr 13 years ago
parent
commit
e4121d7c1f
4 changed files with 23 additions and 17 deletions
  1. 9 17
      miner.c
  2. 1 0
      miner.h
  3. 12 0
      util.c
  4. 1 0
      util.h

+ 9 - 17
miner.c

@@ -6620,9 +6620,9 @@ void mt_disable_finish(struct thr_info *mythr)
 	int thr_id = mythr->id;
 	const struct device_api *api = mythr->cgpu->api;
 	
-	applog(LOG_DEBUG, "Popping wakeup ping in miner thread");
+	applog(LOG_DEBUG, "Waiting for wakeup notification in miner thread");
 	do {
-		tq_pop(mythr->q, NULL); /* Ignore ping that's popped */
+		notifier_read(mythr->notifier);
 	} while (mythr->pause);
 	thread_reportin(mythr);
 	applog(LOG_WARNING, "Thread %d being re-enabled", thr_id);
@@ -6917,7 +6917,7 @@ void *miner_thread(void *userdata)
 
 	thread_reportout(mythr);
 	applog(LOG_DEBUG, "Popping ping in miner thread");
-	tq_pop(mythr->q, NULL); /* Wait for a ping to start */
+	notifier_read(mythr->notifier);  // Wait for a notification to start
 
 	if (api->minerloop)
 		api->minerloop(mythr);
@@ -6930,7 +6930,7 @@ out:
 
 	thread_reportin(mythr);
 	applog(LOG_ERR, "Thread %d failure, exiting", thr_id);
-	tq_freeze(mythr->q);
+	notifier_destroy(mythr->notifier);
 
 	return NULL;
 }
@@ -7277,9 +7277,8 @@ static void *watchpool_thread(void __maybe_unused *userdata)
 
 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);
+	applog(LOG_DEBUG, "Waking up thread %d", thr->id);
+	notifier_wake(thr->notifier);
 }
 
 void proc_enable(struct cgpu_info *cgpu)
@@ -7383,12 +7382,7 @@ static void *watchdog_thread(void __maybe_unused *userdata)
 		for (i = 0; i < total_devices; ++i) {
 			struct cgpu_info *cgpu = devices[i];
 			struct thr_info *thr;
-			int threadobjs = cgpu->threads ?: 1;
-			for (int thrid = 0; thrid < threadobjs; ++thrid) {
-				thr = cgpu->thr[thrid];
-				if (!thr->q->frozen)
-					break;
-			}
+			thr = cgpu->thr[0];
 			enum dev_enable *denable;
 			char *dev_str = cgpu->proc_repr;
 			int gpu;
@@ -8498,13 +8492,11 @@ begin_bench:
 	for (i = 0; i < total_devices; ++i) {
 		struct cgpu_info *cgpu = devices[i];
 		if (!cgpu->threads)
-			cgpu->thr[0]->q = cgpu->device->thr[0]->q;
+			memcpy(&cgpu->thr[0]->notifier, &cgpu->device->thr[0]->notifier, sizeof(cgpu->thr[0]->notifier));
 		for (j = 0; j < cgpu->threads; ++j) {
 			thr = cgpu->thr[j];
 
-			thr->q = tq_new();
-			if (!thr->q)
-				quit(1, "tq_new failed in starting %"PRIpreprv" mining thread (#%d)", cgpu->proc_repr, i);
+			notifier_init(thr->notifier);
 
 			/* Enable threads for devices set not to mine but disable
 			 * their queue in case we wish to enable them later */

+ 1 - 0
miner.h

@@ -562,6 +562,7 @@ struct thr_info {
 	struct timeval tv_morework;
 	struct timeval tv_jobstart;
 	struct timeval tv_poll;
+	int notifier[2];
 
 	bool	work_restart;
 	int		work_restart_fd;

+ 12 - 0
util.c

@@ -1835,3 +1835,15 @@ void notifier_read(int fd[2])
 	(void)read(fd[0], buf, sizeof(buf));
 #endif
 }
+
+void notifier_destroy(int fd[2])
+{
+#ifdef WIN32
+	closesocket(fd[0]);
+	closesocket(fd[1]);
+#else
+	close(fd[0]);
+	close(fd[1]);
+#endif
+	fd[0] = fd[1] = INVSOCK;
+}

+ 1 - 0
util.h

@@ -73,6 +73,7 @@ void RenameThread(const char* name);
 extern void notifier_init(int pipefd[2]);
 extern void notifier_wake(int fd[2]);
 extern void notifier_read(int fd[2]);
+extern void notifier_destroy(int fd[2]);
 
 /* Align a size_t to 4 byte boundaries for fussy arches */
 static inline void align_len(size_t *len)