Commit 1eb18061f83008031a63c4557387dfe559e5c544

Con Kolivas 2013-10-21T12:42:54

Limit the number of work items we queue at any one time in the hashfast driver and do not keep updating the job count during the scanwork() loop to prevent indefinitely changing our tail.

diff --git a/driver-hashfast.c b/driver-hashfast.c
index 1a93d11..a730159 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -666,17 +666,16 @@ static bool hfa_prepare(struct thr_info *thr)
 }
 
 /* Figure out how many jobs to send. */
-static int __hfa_jobs(struct hashfast_info *info)
-{
-	return info->usb_init_base.inflight_target - HF_SEQUENCE_DISTANCE(info->hash_sequence, info->device_sequence_tail);
-}
-
 static int hfa_jobs(struct hashfast_info *info)
 {
 	int ret;
 
 	mutex_lock(&info->lock);
-	ret = __hfa_jobs(info);
+	ret = info->usb_init_base.inflight_target - HF_SEQUENCE_DISTANCE(info->hash_sequence, info->device_sequence_tail);
+	/* Place an upper limit on how many jobs to queue to prevent sending
+	 * more  work than the device can use after a period of outage. */
+	if (ret > info->usb_init_base.inflight_target)
+		ret = info->usb_init_base.inflight_target;
 	mutex_unlock(&info->lock);
 
 	return ret;
@@ -711,7 +710,7 @@ restart:
 		jobs = hfa_jobs(info);
 	}
 
-	while (jobs > 0) {
+	while (jobs-- > 0) {
 		struct hf_hash_usb op_hash_data;
 		struct work *work;
 		uint64_t intdiff;
@@ -748,8 +747,7 @@ restart:
 
 		mutex_lock(&info->lock);
 		info->hash_sequence = sequence;
-		*(info->works + info->hash_sequence) = work;
-		jobs = __hfa_jobs(info);
+		info->works[info->hash_sequence] = work;
 		mutex_unlock(&info->lock);
 
 		applog(LOG_DEBUG, "HFA %d: OP_HASH sequence %d search_difficulty %d work_difficulty %g",