Browse Source

Allow device drivers to implement their own minerloop

Luke Dashjr 13 years ago
parent
commit
2649cf7e3f
2 changed files with 11 additions and 4 deletions
  1. 6 4
      miner.c
  2. 5 0
      miner.h

+ 6 - 4
miner.c

@@ -6446,7 +6446,7 @@ void request_work(struct thr_info *thr)
 }
 
 // FIXME: Make this non-blocking
-static struct work *get_work(struct thr_info *thr)
+struct work *get_work(struct thr_info *thr)
 {
 	const int thr_id = thr->id;
 	struct cgpu_info *cgpu = thr->cgpu;
@@ -6585,7 +6585,7 @@ void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
 	submit_work_async(work, &tv_work_found);
 }
 
-static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)
+bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)
 {
 	if (wdiff->tv_sec > opt_scantime ||
 	    work->blk.nonce >= MAXTHREADS - hashes ||
@@ -6757,8 +6757,10 @@ void *miner_thread(void *userdata)
 	applog(LOG_DEBUG, "Popping ping in miner thread");
 	tq_pop(mythr->q, NULL); /* Wait for a ping to start */
 
-	// FIXME: allow device drivers to override this
-	minerloop(mythr);
+	if (api->minerloop)
+		api->minerloop(mythr);
+	else
+		minerloop(mythr);
 
 out:
 	if (api->thread_shutdown)

+ 5 - 0
miner.h

@@ -287,6 +287,7 @@ struct device_api {
 
 	// Thread-specific functions
 	bool (*thread_prepare)(struct thr_info *);
+	void (*minerloop)(struct thr_info *);
 	uint64_t (*can_limit_work)(struct thr_info *);
 	bool (*thread_init)(struct thr_info *);
 	bool (*prepare_work)(struct thr_info *, struct work *);
@@ -1083,10 +1084,14 @@ enum test_nonce2_result {
 	TNR_HIGH,
 	TNR_BAD,
 };
+extern void request_work(struct thr_info *);
+extern struct work *get_work(struct thr_info *);
 extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
 #define test_nonce(work, nonce, checktarget)  (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
 #define test_nonce2(work, nonce)  (_test_nonce2(work, nonce, true))
 extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
+extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
+extern bool hashes_done(struct thr_info *, int64_t hashes, struct timeval *tvp_hashes, uint32_t *max_nonce);
 extern void tailsprintf(char *f, const char *fmt, ...);
 extern void wlogprint(const char *f, ...);
 extern int curses_int(const char *query);