Browse Source

Fine tune the reading of results in bitfury driver to not lose any across work restarts or corrupt due to store results not parsed during restart.

Con Kolivas 12 years ago
parent
commit
0b64d438ef
2 changed files with 14 additions and 16 deletions
  1. 14 15
      driver-bitfury.c
  2. 0 1
      driver-bitfury.h

+ 14 - 15
driver-bitfury.c

@@ -224,13 +224,12 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 {
 {
 	struct cgpu_info *bitfury = thr->cgpu;
 	struct cgpu_info *bitfury = thr->cgpu;
 	struct bitfury_info *info = bitfury->device_data;
 	struct bitfury_info *info = bitfury->device_data;
+	int amount, i, aged = 0, total = 0, ms_diff;
 	struct work *work, *tmp;
 	struct work *work, *tmp;
-	int amount, i, aged = 0;
 	struct timeval tv_now;
 	struct timeval tv_now;
 	double nonce_rate;
 	double nonce_rate;
 	int64_t ret = 0;
 	int64_t ret = 0;
 	char buf[45];
 	char buf[45];
-	int ms_diff;
 
 
 	work = get_queue_work(thr, bitfury, thr->id);
 	work = get_queue_work(thr, bitfury, thr->id);
 	if (unlikely(thr->work_restart)) {
 	if (unlikely(thr->work_restart)) {
@@ -248,27 +247,28 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 	cgtime(&tv_now);
 	cgtime(&tv_now);
 	ms_diff = 600 - ms_tdiff(&tv_now, &info->tv_start);
 	ms_diff = 600 - ms_tdiff(&tv_now, &info->tv_start);
 	if (ms_diff > 0) {
 	if (ms_diff > 0) {
-		usb_read_timeout_cancellable(bitfury, info->buf, 512, &amount, ms_diff, C_BF1_GETRES);
-		info->tot += amount;
+		usb_read_timeout_cancellable(bitfury, info->buf, 512, &amount, ms_diff,
+					     C_BF1_GETRES);
+		total += amount;
 	}
 	}
 
 
-	if (unlikely(thr->work_restart))
-		goto out;
-
 	/* Now look for the bulk of the previous work results, they will come
 	/* Now look for the bulk of the previous work results, they will come
 	 * in a batch following the first data. */
 	 * in a batch following the first data. */
 	cgtime(&tv_now);
 	cgtime(&tv_now);
 	ms_diff = BF1WAIT - ms_tdiff(&tv_now, &info->tv_start);
 	ms_diff = BF1WAIT - ms_tdiff(&tv_now, &info->tv_start);
-	if (unlikely(ms_diff < 10))
+	/* If a work restart was sent, just empty the buffer. */
+	if (unlikely(ms_diff < 10 || thr->work_restart))
 		ms_diff = 10;
 		ms_diff = 10;
-	usb_read_once_timeout_cancellable(bitfury, info->buf + info->tot, BF1MSGSIZE,
+	usb_read_once_timeout_cancellable(bitfury, info->buf + total, BF1MSGSIZE,
 					  &amount, ms_diff, C_BF1_GETRES);
 					  &amount, ms_diff, C_BF1_GETRES);
-	info->tot += amount;
+	total += amount;
 	while (amount) {
 	while (amount) {
-		usb_read_once_timeout(bitfury, info->buf + info->tot, 512, &amount, 10, C_BF1_GETRES);
-		info->tot += amount;
+		usb_read_once_timeout(bitfury, info->buf + total, 512, &amount, 10,
+				      C_BF1_GETRES);
+		total += amount;
 	};
 	};
 
 
+	/* Don't send whatever work we've stored if we got a restart */
 	if (unlikely(thr->work_restart))
 	if (unlikely(thr->work_restart))
 		goto out;
 		goto out;
 
 
@@ -280,9 +280,10 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 	/* Get response acknowledging work */
 	/* Get response acknowledging work */
 	usb_read(bitfury, buf, BF1MSGSIZE, &amount, C_BF1_GETWORK);
 	usb_read(bitfury, buf, BF1MSGSIZE, &amount, C_BF1_GETWORK);
 
 
+out:
 	/* Search for what work the nonce matches in order of likelihood. Last
 	/* Search for what work the nonce matches in order of likelihood. Last
 	 * entry is end of result marker. */
 	 * entry is end of result marker. */
-	for (i = 0; i < info->tot - BF1MSGSIZE; i += BF1MSGSIZE) {
+	for (i = 0; i < total - BF1MSGSIZE; i += BF1MSGSIZE) {
 		bool found = false;
 		bool found = false;
 		uint32_t nonce;
 		uint32_t nonce;
 
 
@@ -304,8 +305,6 @@ static int64_t bitfury_scanwork(struct thr_info *thr)
 			inc_hw_errors(thr);
 			inc_hw_errors(thr);
 	}
 	}
 
 
-	info->tot = 0;
-out:
 	cgtime(&tv_now);
 	cgtime(&tv_now);
 
 
 	/* This iterates over the hashlist finding work started more than 6
 	/* This iterates over the hashlist finding work started more than 6

+ 0 - 1
driver-bitfury.h

@@ -19,7 +19,6 @@ struct bitfury_info {
 	char product[8];
 	char product[8];
 	uint32_t serial;
 	uint32_t serial;
 	char buf[512];
 	char buf[512];
-	int tot;
 	int nonces;
 	int nonces;
 	int total_nonces;
 	int total_nonces;
 	double saved_nonces;
 	double saved_nonces;