Browse Source

Replace UNIX-only work_restart_fd pipe with portable work_restart_notifier

Luke Dashjr 13 years ago
parent
commit
3a98ef1f00
5 changed files with 11 additions and 27 deletions
  1. 1 1
      driver-cairnsmore.c
  2. 5 6
      driver-icarus.c
  3. 2 18
      miner.c
  4. 1 2
      miner.h
  5. 2 0
      util.c

+ 1 - 1
driver-cairnsmore.c

@@ -86,7 +86,7 @@ bool cairnsmore_supports_dynclock(int fd)
 		struct timeval tv_finish;
 		struct timeval tv_finish;
 		struct thr_info dummy = {
 		struct thr_info dummy = {
 			.work_restart = false,
 			.work_restart = false,
-			.work_restart_fd = -1,
+			.work_restart_notifier = {-1, -1},
 		};
 		};
 		icarus_gets((unsigned char*)&nonce, fd, &tv_finish, &dummy, 1);
 		icarus_gets((unsigned char*)&nonce, fd, &tv_finish, &dummy, 1);
 	}
 	}

+ 5 - 6
driver-icarus.c

@@ -198,7 +198,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 	};
 	};
 	struct epoll_event evr[2];
 	struct epoll_event evr[2];
 	int epoll_timeout = ICARUS_READ_FAULT_DECISECONDS * 100;
 	int epoll_timeout = ICARUS_READ_FAULT_DECISECONDS * 100;
-	if (thr && thr->work_restart_fd != -1) {
+	if (thr && thr->work_restart_notifier[1] != -1) {
 	epollfd = epoll_create(2);
 	epollfd = epoll_create(2);
 	if (epollfd != -1) {
 	if (epollfd != -1) {
 		if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev)) {
 		if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev)) {
@@ -206,8 +206,8 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 			epollfd = -1;
 			epollfd = -1;
 		}
 		}
 		{
 		{
-			ev.data.fd = thr->work_restart_fd;
-			if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, thr->work_restart_fd, &ev))
+			ev.data.fd = thr->work_restart_notifier[0];
+			if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, thr->work_restart_notifier[0], &ev))
 				applog(LOG_ERR, "Icarus: Error adding work restart fd to epoll");
 				applog(LOG_ERR, "Icarus: Error adding work restart fd to epoll");
 			else
 			else
 			{
 			{
@@ -231,8 +231,7 @@ int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct th
 			else
 			else
 			{
 			{
 				if (ret)
 				if (ret)
-					// work restart trigger
-					(void)read(thr->work_restart_fd, buf, read_amount);
+					notifier_read(thr->work_restart_notifier);
 				ret = 0;
 				ret = 0;
 			}
 			}
 		}
 		}
@@ -696,7 +695,7 @@ static bool icarus_prepare(struct thr_info *thr)
 	if (epollfd != -1)
 	if (epollfd != -1)
 	{
 	{
 		close(epollfd);
 		close(epollfd);
-		thr->work_restart_fd = 0;
+		notifier_init(thr->work_restart_notifier);
 	}
 	}
 #endif
 #endif
 
 

+ 2 - 18
miner.c

@@ -4333,10 +4333,8 @@ static void restart_threads(void)
 	for (i = 0; i < mining_threads; i++)
 	for (i = 0; i < mining_threads; i++)
 	{
 	{
 		thr = &thr_info[i];
 		thr = &thr_info[i];
-		fd = thr->_work_restart_fd_w;
 		thr->work_restart = true;
 		thr->work_restart = true;
-		if (fd != -1)
-			(void)write(fd, "\0", 1);
+		notifier_wake(thr->work_restart_notifier);
 	}
 	}
 
 
 	mutex_lock(&restart_lock);
 	mutex_lock(&restart_lock);
@@ -8148,7 +8146,7 @@ begin_bench:
 			thr->id = k;
 			thr->id = k;
 			thr->cgpu = cgpu;
 			thr->cgpu = cgpu;
 			thr->device_thread = j;
 			thr->device_thread = j;
-			thr->work_restart_fd = thr->_work_restart_fd_w = -1;
+			thr->work_restart_notifier[1] = -1;
 			thr->_job_transition_in_progress = true;
 			thr->_job_transition_in_progress = true;
 			timerclear(&thr->tv_morework);
 			timerclear(&thr->tv_morework);
 
 
@@ -8178,20 +8176,6 @@ begin_bench:
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 				continue;
 				continue;
 
 
-			if (!thr->work_restart_fd)
-			{
-#if defined(unix)
-				int pipefd[2];
-				if (!pipe(pipefd))
-				{
-					thr->work_restart_fd = pipefd[0];
-					thr->_work_restart_fd_w = pipefd[1];
-				}
-				else
-#endif
-					thr->work_restart_fd = -1;
-			}
-
 			thread_reportout(thr);
 			thread_reportout(thr);
 
 
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))

+ 1 - 2
miner.h

@@ -571,8 +571,7 @@ struct thr_info {
 	uint32_t _max_nonce;
 	uint32_t _max_nonce;
 
 
 	bool	work_restart;
 	bool	work_restart;
-	int		work_restart_fd;
-	int		_work_restart_fd_w;
+	int work_restart_notifier[2];
 };
 };
 
 
 extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
 extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);

+ 2 - 0
util.c

@@ -1819,6 +1819,8 @@ void notifier_init(int pipefd[2])
 
 
 void notifier_wake(int fd[2])
 void notifier_wake(int fd[2])
 {
 {
+	if (fd[1] == -1)
+		return;
 #ifdef WIN32
 #ifdef WIN32
 	(void)send(fd[1], "\0", 1, 0);
 	(void)send(fd[1], "\0", 1, 0);
 #else
 #else