Browse Source

Import hash_driver_work minerloop from cgminer as of c57b15196a900f018e875bd1435036fbce372d3d

Con Kolivas 12 years ago
parent
commit
0b40d037c2
2 changed files with 55 additions and 0 deletions
  1. 54 0
      miner.c
  2. 1 0
      miner.h

+ 54 - 0
miner.c

@@ -9942,6 +9942,60 @@ void hash_queued_work(struct thr_info *mythr)
 	// cgpu->deven = DEV_DISABLED; set in miner_thread
 }
 
+/* This version of hash_work is for devices drivers that want to do their own
+ * work management entirely, usually by using get_work(). Note that get_work
+ * is a blocking function and will wait indefinitely if no work is available
+ * so this must be taken into consideration in the driver. */
+void hash_driver_work(struct thr_info *mythr)
+{
+	struct timeval tv_start = {0, 0}, tv_end;
+	struct cgpu_info *cgpu = mythr->cgpu;
+	struct device_drv *drv = cgpu->drv;
+	const int thr_id = mythr->id;
+	int64_t hashes_done = 0;
+	
+	while (likely(!cgpu->shutdown))
+	{
+		struct timeval diff;
+		int64_t hashes;
+		
+		mythr->work_update = false;
+		
+		hashes = drv->scanwork(mythr);
+		
+		/* Reset the bool here in case the driver looks for it
+		 * synchronously in the scanwork loop. */
+		mythr->work_restart = false;
+		
+		if (unlikely(hashes == -1))
+		{
+			applog(LOG_ERR, "%s %d failure, disabling!", drv->name, cgpu->device_id);
+			cgpu->deven = DEV_DISABLED;
+			dev_error(cgpu, REASON_THREAD_ZERO_HASH);
+			break;
+		}
+		
+		hashes_done += hashes;
+		cgtime(&tv_end);
+		timersub(&tv_end, &tv_start, &diff);
+		/* Update the hashmeter at most 5 times per second */
+		if ((hashes_done && (diff.tv_sec > 0 || diff.tv_usec > 200000)) ||
+		    diff.tv_sec >= opt_log_interval)
+		{
+			hashmeter(thr_id, &diff, hashes_done);
+			hashes_done = 0;
+			copy_time(&tv_start, &tv_end);
+		}
+		
+		if (unlikely(mythr->pause || cgpu->deven != DEV_ENABLED))
+			mt_disable(mythr, thr_id, drv);
+		
+		if (mythr->work_update)
+			drv->update_work(cgpu);
+	}
+	cgpu->deven = DEV_DISABLED;
+}
+
 // Called by minerloop, when it is re-enabling a processor
 void mt_disable_finish(struct thr_info *mythr)
 {

+ 1 - 0
miner.h

@@ -1475,6 +1475,7 @@ extern void __work_completed(struct cgpu_info *cgpu, struct work *work);
 extern void work_completed(struct cgpu_info *cgpu, struct work *work);
 extern struct work *take_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
 extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
+extern void hash_driver_work(struct thr_info *mythr);
 extern void hash_queued_work(struct thr_info *mythr);
 extern void get_statline3(char *buf, size_t bufsz, struct cgpu_info *, bool for_curses, bool opt_show_procs);
 extern void tailsprintf(char *buf, size_t bufsz, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 3, 4);