Browse Source

bitmain: Prune old work eventually

Luke Dashjr 10 years ago
parent
commit
f809f4f71d
2 changed files with 24 additions and 0 deletions
  1. 23 0
      driver-bitmain.c
  2. 1 0
      driver-bitmain.h

+ 23 - 0
driver-bitmain.c

@@ -820,6 +820,9 @@ static void bitmain_set_fifo_space(struct cgpu_info * const dev, const int fifo_
 	struct thr_info * const master_thr = dev->thr[0];
 	struct thr_info * const master_thr = dev->thr[0];
 	struct bitmain_info * const info = dev->device_data;
 	struct bitmain_info * const info = dev->device_data;
 	
 	
+	if (unlikely(fifo_space > info->max_fifo_space))
+		info->max_fifo_space = fifo_space;
+	
 	info->fifo_space = fifo_space;
 	info->fifo_space = fifo_space;
 	master_thr->queue_full = !fifo_space;
 	master_thr->queue_full = !fifo_space;
 }
 }
@@ -1056,6 +1059,24 @@ static void bitmain_running_reset(struct cgpu_info *bitmain, struct bitmain_info
 	info->reset = false;
 	info->reset = false;
 }
 }
 
 
+static void bitmain_prune_old_work(struct cgpu_info * const dev)
+{
+	struct thr_info * const master_thr = dev->thr[0];
+	struct bitmain_info * const info = dev->device_data;
+	
+	const size_t retain_work_items = info->max_fifo_space * 2;
+	const size_t queued_work_items = HASH_COUNT(master_thr->work_list);
+	if (queued_work_items > retain_work_items) {
+		size_t remove_work_items = queued_work_items - retain_work_items;
+		while (remove_work_items--) {
+			// Deletes the first item insertion-order
+			struct work * const work = master_thr->work_list;
+			HASH_DEL(master_thr->work_list, work);
+			free_work(work);
+		}
+	}
+}
+
 static void bitmain_poll(struct thr_info * const thr)
 static void bitmain_poll(struct thr_info * const thr)
 {
 {
 	struct cgpu_info *bitmain = thr->cgpu;
 	struct cgpu_info *bitmain = thr->cgpu;
@@ -1129,6 +1150,8 @@ static void bitmain_poll(struct thr_info * const thr)
 	}
 	}
 	
 	
 	info->readbuf_offset = offset;
 	info->readbuf_offset = offset;
+	
+	bitmain_prune_old_work(bitmain);
 }
 }
 
 
 static void bitmain_init(struct cgpu_info *bitmain)
 static void bitmain_init(struct cgpu_info *bitmain)

+ 1 - 0
driver-bitmain.h

@@ -261,6 +261,7 @@ struct bitmain_info {
 	pthread_mutex_t qlock;
 	pthread_mutex_t qlock;
 	pthread_cond_t qcond;
 	pthread_cond_t qcond;
 	int fifo_space;
 	int fifo_space;
+	int max_fifo_space;
 	int hw_version[4];
 	int hw_version[4];
 	unsigned int last_work_block;
 	unsigned int last_work_block;
 	struct timeval last_status_time;
 	struct timeval last_status_time;