Browse Source

Merge commit 'fd7b21e' into bfgminer

Conflicts:
	driver-bitforce.c
	miner.c
	miner.h
Luke Dashjr 13 years ago
parent
commit
826755ab24
3 changed files with 49 additions and 4 deletions
  1. 13 2
      driver-bitforce.c
  2. 31 2
      miner.c
  3. 5 0
      miner.h

+ 13 - 2
driver-bitforce.c

@@ -139,6 +139,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 
 
 	char pdevbuf[0x100];
 	char pdevbuf[0x100];
 	unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>";
 	unsigned char ob[61] = ">>>>>>>>12345678901234567890123456789012123456789012>>>>>>>>";
+	struct timeval tdiff;
 	int i;
 	int i;
 	char *pnoncebuf;
 	char *pnoncebuf;
 	char *s;
 	char *s;
@@ -196,7 +197,12 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 	}
 	}
 
 
 	i = 0;
 	i = 0;
-	while (1) {
+	/* Start looking for results. Stupid polling every 10ms... */
+	tdiff.tv_sec = 0;
+	tdiff.tv_usec = 10000;
+	while (42) {
+		int rc = restart_wait(&tdiff);
+
 		BFwrite(fdDev, "ZFX", 3);
 		BFwrite(fdDev, "ZFX", 3);
 		BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
 		BFgets(pdevbuf, sizeof(pdevbuf), fdDev);
 		if (unlikely(!pdevbuf[0])) {
 		if (unlikely(!pdevbuf[0])) {
@@ -205,8 +211,13 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 		}
 		}
 		if (pdevbuf[0] != 'B')
 		if (pdevbuf[0] != 'B')
 		    break;
 		    break;
-		usleep(10000);
+		if (!rc)
+			return 0;
 		i += 10;
 		i += 10;
+
+		/* After 2/3 of the average cycle time (~3.4s), request more work */
+		if (i == 3400)
+			queue_request(thr, false);
 	}
 	}
 	applog(LOG_DEBUG, "BitForce waited %dms until %s\n", i, pdevbuf);
 	applog(LOG_DEBUG, "BitForce waited %dms until %s\n", i, pdevbuf);
 	work->blk.nonce = 0xffffffff;
 	work->blk.nonce = 0xffffffff;

+ 31 - 2
miner.c

@@ -173,6 +173,9 @@ pthread_rwlock_t netacc_lock;
 static pthread_mutex_t lp_lock;
 static pthread_mutex_t lp_lock;
 static pthread_cond_t lp_cond;
 static pthread_cond_t lp_cond;
 
 
+pthread_mutex_t restart_lock;
+pthread_cond_t restart_cond;
+
 double total_mhashes_done;
 double total_mhashes_done;
 static struct timeval total_tv_start, total_tv_end;
 static struct timeval total_tv_start, total_tv_end;
 
 
@@ -2488,8 +2491,26 @@ static void discard_stale(void)
 	subtract_queued(nonclone);
 	subtract_queued(nonclone);
 }
 }
 
 
-static bool queue_request(struct thr_info *thr, bool needed);
+bool queue_request(struct thr_info *thr, bool needed);
 
 
+/* A generic wait function for threads that poll that will wait a specified
+ * time tdiff waiting on the pthread conditional that is broadcast when a
+ * work restart is required. Returns the value of pthread_cond_timedwait
+ * which is zero if the condition was met or ETIMEDOUT if not.
+ */
+int restart_wait(struct timeval *tdiff)
+{
+	struct timeval now, then;
+	struct timespec abstime;
+
+	gettimeofday(&now, NULL);
+	timeradd(&now, tdiff, &then);
+	abstime.tv_sec = then.tv_sec;
+	abstime.tv_nsec = then.tv_usec * 1000;
+	mutex_lock(&restart_lock);
+	return pthread_cond_timedwait(&restart_cond, &restart_lock, &abstime);
+}
+	
 static void restart_threads(void)
 static void restart_threads(void)
 {
 {
 	int i, j, fd;
 	int i, j, fd;
@@ -2513,6 +2534,10 @@ static void restart_threads(void)
 				write(fd, "\0", 1);
 				write(fd, "\0", 1);
 		}
 		}
 	}
 	}
+
+	mutex_lock(&restart_lock);
+	pthread_cond_broadcast(&restart_cond);
+	mutex_unlock(&restart_lock);
 }
 }
 
 
 static void set_curblock(char *hexstr, unsigned char *hash)
 static void set_curblock(char *hexstr, unsigned char *hash)
@@ -3604,7 +3629,7 @@ static void control_tclear(bool *var)
 
 
 static bool queueing;
 static bool queueing;
 
 
-static bool queue_request(struct thr_info *thr, bool needed)
+bool queue_request(struct thr_info *thr, bool needed)
 {
 {
 	struct workio_cmd *wc;
 	struct workio_cmd *wc;
 	struct timeval now;
 	struct timeval now;
@@ -5069,6 +5094,10 @@ int main(int argc, char *argv[])
 	if (unlikely(pthread_cond_init(&lp_cond, NULL)))
 	if (unlikely(pthread_cond_init(&lp_cond, NULL)))
 		quit(1, "Failed to pthread_cond_init lp_cond");
 		quit(1, "Failed to pthread_cond_init lp_cond");
 
 
+	mutex_init(&restart_lock);
+	if (unlikely(pthread_cond_init(&restart_cond, NULL)))
+		quit(1, "Failed to pthread_cond_init restart_cond");
+
 	sprintf(packagename, "%s %s", PACKAGE, VERSION);
 	sprintf(packagename, "%s %s", PACKAGE, VERSION);
 
 
 #ifdef WANT_CPUMINE
 #ifdef WANT_CPUMINE

+ 5 - 0
miner.h

@@ -556,7 +556,12 @@ extern bool fulltest(const unsigned char *hash, const unsigned char *target);
 
 
 extern int opt_scantime;
 extern int opt_scantime;
 
 
+extern pthread_mutex_t restart_lock;
+extern pthread_cond_t restart_cond;
+
 extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportin(struct thr_info *thr);
+extern bool queue_request(struct thr_info *thr, bool needed);
+extern int restart_wait(struct timeval *tdiff);
 
 
 extern void kill_work(void);
 extern void kill_work(void);