Browse Source

Merge commit '95b2020' into cg_queuedwork

Conflicts:
	miner.c
Luke Dashjr 13 years ago
parent
commit
2ff6e0ce4e
2 changed files with 28 additions and 1 deletions
  1. 23 1
      miner.c
  2. 5 0
      miner.h

+ 23 - 1
miner.c

@@ -6948,6 +6948,25 @@ void mt_disable_start(struct thr_info *mythr)
 	thread_reportout(mythr);
 }
 
+/* Create a hashtable of work items for devices with a queue. The device
+ * driver must have a custom queue_full function or it will default to true
+ * and put only one work item in the queue. Work items should not be removed
+ * from this hashtable until they are no longer in use anywhere. Once a work
+ * item is physically queued on the device itself, the work->queued flag
+ * should be set under cgpu->qlock write lock to prevent it being dereferenced
+ * while still in use. */
+static void fill_queue(struct thr_info *mythr, struct cgpu_info *cgpu, struct device_drv *drv, const int thr_id)
+{
+	thread_reportout(mythr);
+	do {
+		struct work *work = get_work(mythr);
+
+		wr_lock(&cgpu->qlock);
+		HASH_ADD_INT(cgpu->queued_work, id, work);
+		wr_unlock(&cgpu->qlock);
+	} while (drv->queue_full && !drv->queue_full(cgpu));
+}
+
 /* This version of hash work is for devices that are fast enough to always
  * perform a full nonce range and need a queue to maintain the device busy.
  * Work creation and destruction is not done from within this function
@@ -6967,7 +6986,7 @@ static void hash_queued_work(struct thr_info *mythr)
 
 		mythr->work_restart = false;
 
-		//fill_queue(mythr, cgpu, drv, thr_id);
+		fill_queue(mythr, cgpu, drv, thr_id);
 
 		thread_reportin(mythr);
 		hashes = drv->scanwork(mythr);
@@ -8011,6 +8030,9 @@ void register_device(struct cgpu_info *cgpu)
 		gpu_threads += cgpu->threads;
 	}
 #endif
+
+	rwlock_init(&cgpu->qlock);
+	cgpu->queued_work = NULL;
 }
 
 struct _cgpu_devid_counter {

+ 5 - 0
miner.h

@@ -294,6 +294,8 @@ struct device_drv {
 #endif
 	int64_t (*scanhash)(struct thr_info *, struct work *, int64_t);
 	int64_t (*scanwork)(struct thr_info *);
+	bool (*queue_full)(struct cgpu_info *);
+
 	void (*hw_error)(struct thr_info *);
 	void (*thread_shutdown)(struct thr_info *);
 	void (*thread_enable)(struct thr_info *);
@@ -525,6 +527,9 @@ struct cgpu_info {
 	int dev_throttle_count;
 
 	struct cgminer_stats cgminer_stats;
+
+	pthread_rwlock_t qlock;
+	struct work *queued_work;
 };
 
 extern void renumber_cgpu(struct cgpu_info *);