Browse Source

bifury: Prune jobs older than 16 queued, to eventually clean up discarded work (from flushes)

Luke Dashjr 12 years ago
parent
commit
bf6c672d44
1 changed files with 17 additions and 1 deletions
  1. 17 1
      driver-bifury.c

+ 17 - 1
driver-bifury.c

@@ -25,6 +25,8 @@
 #include "miner.h"
 #include "miner.h"
 #include "util.h"
 #include "util.h"
 
 
+#define BIFURY_MAX_QUEUED 0x10
+
 BFG_REGISTER_DRIVER(bifury_drv)
 BFG_REGISTER_DRIVER(bifury_drv)
 
 
 const char bifury_init_cmds[] = "flush\ntarget ffffffff\nmaxroll 0\n";
 const char bifury_init_cmds[] = "flush\ntarget ffffffff\nmaxroll 0\n";
@@ -227,7 +229,7 @@ void bifury_common_error(struct cgpu_info * const dev, const enum dev_reason rea
 }
 }
 
 
 static
 static
-bool bifury_queue_append(struct thr_info * const thr, struct work * const work)
+bool bifury_queue_append(struct thr_info * const thr, struct work *work)
 {
 {
 	const struct cgpu_info * const dev = thr->cgpu->device;
 	const struct cgpu_info * const dev = thr->cgpu->device;
 	struct bifury_state * const state = dev->device_data;
 	struct bifury_state * const state = dev->device_data;
@@ -247,6 +249,20 @@ bool bifury_queue_append(struct thr_info * const thr, struct work * const work)
 		return false;
 		return false;
 	}
 	}
 	HASH_ADD(hh, master_thr->work_list, device_id, sizeof(work->device_id), work);
 	HASH_ADD(hh, master_thr->work_list, device_id, sizeof(work->device_id), work);
+	int prunequeue = HASH_COUNT(master_thr->work_list) - BIFURY_MAX_QUEUED;
+	if (prunequeue > 0)
+	{
+		struct work *tmp;
+		applog(LOG_DEBUG, "%s: Pruning %d old work item%s",
+		       dev->dev_repr, prunequeue, prunequeue == 1 ? "" : "s");
+		HASH_ITER(hh, master_thr->work_list, work, tmp)
+		{
+			HASH_DEL(master_thr->work_list, work);
+			free_work(work);
+			if (--prunequeue < 1)
+				break;
+		}
+	}
 	bifury_set_queue_full(dev, state->needwork - 1);
 	bifury_set_queue_full(dev, state->needwork - 1);
 	return true;
 	return true;
 }
 }