Commit 5c7e03084a29636dee4b181c436100e7b5e9c29a

ckolivas 2012-07-11T22:59:58

Modify te scanhash API to use an int64_t and return -1 on error, allowing zero to be a valid return value.

diff --git a/cgminer.c b/cgminer.c
index 59b2111..509e353 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4018,8 +4018,8 @@ void *miner_thread(void *userdata)
 	struct timeval tv_start, tv_end, tv_workstart, tv_lastupdate;
 	struct timeval diff, sdiff, wdiff = {0, 0};
 	uint32_t max_nonce = api->can_limit_work ? api->can_limit_work(mythr) : 0xffffffff;
-	unsigned long long hashes_done = 0;
-	unsigned long long hashes;
+	int64_t hashes_done = 0;
+	int64_t hashes;
 	struct work *work = make_work();
 	const time_t request_interval = opt_scantime * 2 / 3 ? : 1;
 	unsigned const long request_nonce = MAXTHREADS / 3 * 2;
@@ -4101,7 +4101,7 @@ void *miner_thread(void *userdata)
 
 			gettimeofday(&getwork_start, NULL);
 
-			if (unlikely(!hashes)) {
+			if (unlikely(hashes == -1)) {
 				applog(LOG_ERR, "%s %d failure, disabling!", api->name, cgpu->device_id);
 				cgpu->deven = DEV_DISABLED;
 
diff --git a/driver-bitforce.c b/driver-bitforce.c
index 703ddc5..e66ae7d 100644
--- a/driver-bitforce.c
+++ b/driver-bitforce.c
@@ -331,7 +331,7 @@ re_send:
 	return true;
 }
 
-static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
+static int64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 {
 	struct cgpu_info *bitforce = thr->cgpu;
 	int fdDev = bitforce->device_fd;
@@ -340,13 +340,12 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 	char *pnoncebuf;
 	uint32_t nonce;
 
-
 	if (!fdDev)
-		return 0;
+		return -1;
 
 	while (bitforce->wait_ms < BITFORCE_LONG_TIMEOUT_MS) {
 		if (unlikely(thr->work_restart))
-			return 1;
+			return 0;
 
 		mutex_lock(&bitforce->device_mutex);
 		BFwrite(fdDev, "ZFX", 3);
@@ -370,7 +369,7 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 		bitforce->dev_over_heat_count++;
 
 		if (!pdevbuf[0])           /* Only return if we got nothing after timeout - there still may be results */
-			return 1;
+			return 0;
 	} else if (!strncasecmp(pdevbuf, "N", 1)) {/* Hashing complete (NONCE-FOUND or NO-NONCE) */
 		    /* Simple timing adjustment. Allow a few polls to cope with
 		     * OS timer delays being variably reliable. wait_ms will
@@ -394,10 +393,10 @@ static uint64_t bitforce_get_result(struct thr_info *thr, struct work *work)
 	if (!strncasecmp(&pdevbuf[2], "-", 1))
 		return bitforce->nonces;   /* No valid nonce found */
 	else if (!strncasecmp(pdevbuf, "I", 1))
-		return 1;          /* Device idle */
+		return 0;          /* Device idle */
 	else if (strncasecmp(pdevbuf, "NONCE-FOUND", 11)) {
 		applog(LOG_WARNING, "BFL%i: Error: Get result reports: %s", bitforce->device_id, pdevbuf);
-		return 1;
+		return 0;
 	}
 
 	pnoncebuf = &pdevbuf[12];
@@ -439,11 +438,11 @@ static void biforce_thread_enable(struct thr_info *thr)
 	bitforce_init(bitforce);
 }
 
-static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint64_t __maybe_unused max_nonce)
+static int64_t bitforce_scanhash(struct thr_info *thr, struct work *work, int64_t __maybe_unused max_nonce)
 {
 	struct cgpu_info *bitforce = thr->cgpu;
 	unsigned int sleep_time;
-	uint64_t ret;
+	int64_t ret;
 
 	ret = bitforce_send_work(thr, work);
 
@@ -452,7 +451,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 		work before full scan is up */
 		sleep_time = (2 * bitforce->sleep_ms) / 3;
 		if (!restart_wait(sleep_time))
-			return 1;
+			return 0;
 
 		bitforce->wait_ms = sleep_time;
 		queue_request(thr, false);
@@ -460,13 +459,13 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 		/* Now wait athe final 1/3rd; no bitforce should be finished by now */
 		sleep_time = bitforce->sleep_ms - sleep_time;
 		if (!restart_wait(sleep_time))
-			return 1;
+			return 0;
 
 		bitforce->wait_ms += sleep_time;
 	} else {
 		sleep_time = bitforce->sleep_ms;
 		if (!restart_wait(sleep_time))
-			return 1;
+			return 0;
 
 		bitforce->wait_ms = sleep_time;
 	}
@@ -475,7 +474,7 @@ static uint64_t bitforce_scanhash(struct thr_info *thr, struct work *work, uint6
 		ret = bitforce_get_result(thr, work);
 
 	if (!ret) {
-		ret = 1;
+		ret = 0;
 		applog(LOG_ERR, "BFL%i: Comms error", bitforce->device_id);
 		bitforce->device_last_not_well = time(NULL);
 		bitforce->device_not_well_reason = REASON_DEV_COMMS_ERROR;
diff --git a/driver-cpu.c b/driver-cpu.c
index fb41669..09ca478 100644
--- a/driver-cpu.c
+++ b/driver-cpu.c
@@ -777,7 +777,7 @@ static bool cpu_thread_init(struct thr_info *thr)
 	return true;
 }
 
-static uint64_t cpu_scanhash(struct thr_info *thr, struct work *work, uint64_t max_nonce)
+static int64_t cpu_scanhash(struct thr_info *thr, struct work *work, int64_t max_nonce)
 {
 	const int thr_id = thr->id;
 
diff --git a/driver-icarus.c b/driver-icarus.c
index bcb7d18..5f2c78a 100644
--- a/driver-icarus.c
+++ b/driver-icarus.c
@@ -474,8 +474,8 @@ static bool icarus_prepare(struct thr_info *thr)
 	return true;
 }
 
-static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
-				__maybe_unused uint64_t max_nonce)
+static int64_t icarus_scanhash(struct thr_info *thr, struct work *work,
+				__maybe_unused int64_t max_nonce)
 {
 	struct cgpu_info *icarus;
 	int fd;
@@ -486,7 +486,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	unsigned char ob_bin[64], nonce_bin[ICARUS_READ_SIZE];
 	char *ob_hex;
 	uint32_t nonce;
-	uint64_t hash_count;
+	int64_t hash_count;
 	struct timeval tv_start, tv_finish, elapsed;
 	struct timeval tv_history_start, tv_history_finish;
 	double Ti, Xi;
@@ -496,9 +496,9 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 	int count;
 	double Hs, W, fullnonce;
 	int read_count;
-	uint64_t estimate_hashes;
+	int64_t estimate_hashes;
 	uint32_t values;
-	uint64_t hash_count_range;
+	int64_t hash_count_range;
 
 	elapsed.tv_sec = elapsed.tv_usec = 0;
 
@@ -515,7 +515,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 #endif
 	ret = icarus_write(fd, ob_bin, sizeof(ob_bin));
 	if (ret)
-		return 0;	/* This should never happen */
+		return -1;	/* This should never happen */
 
 	gettimeofday(&tv_start, NULL);
 
diff --git a/driver-modminer.c b/driver-modminer.c
index 88bc3f2..ff96ee4 100644
--- a/driver-modminer.c
+++ b/driver-modminer.c
@@ -480,11 +480,11 @@ modminer_process_results(struct thr_info*thr)
 	return hashes;
 }
 
-static uint64_t
-modminer_scanhash(struct thr_info*thr, struct work*work, uint64_t __maybe_unused max_nonce)
+static int64_t
+modminer_scanhash(struct thr_info*thr, struct work*work, int64_t __maybe_unused max_nonce)
 {
 	struct modminer_fpga_state *state = thr->cgpu_data;
-	uint64_t hashes = 1;
+	int64_t hashes = 0;
 	bool startwork;
 
 	startwork = modminer_prepare_next_work(state, work);
@@ -492,15 +492,14 @@ modminer_scanhash(struct thr_info*thr, struct work*work, uint64_t __maybe_unused
 		hashes = modminer_process_results(thr);
 		if (work_restart(thr)) {
 			state->work_running = false;
-			return 1;
+			return 0;
 		}
-	}
-	else
+	} else
 		state->work_running = true;
 
 	if (startwork) {
 		if (!modminer_start_work(thr))
-			return 0;
+			return -1;
 		memcpy(&state->running_work, work, sizeof(state->running_work));
 	}
 
diff --git a/driver-opencl.c b/driver-opencl.c
index 2cda939..91e43ff 100644
--- a/driver-opencl.c
+++ b/driver-opencl.c
@@ -986,7 +986,7 @@ static cl_int queue_diablo_kernel(_clState *clState, dev_blk_ctx *blk, cl_uint t
 }
 
 static void set_threads_hashes(unsigned int vectors, unsigned int *threads,
-			       unsigned int *hashes, size_t *globalThreads,
+			       int64_t *hashes, size_t *globalThreads,
 			       unsigned int minthreads, int intensity)
 {
 	*threads = 1 << (15 + intensity);
@@ -1338,8 +1338,8 @@ static bool opencl_prepare_work(struct thr_info __maybe_unused *thr, struct work
 
 extern int opt_dynamic_interval;
 
-static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
-				uint64_t __maybe_unused max_nonce)
+static int64_t opencl_scanhash(struct thr_info *thr, struct work *work,
+				int64_t __maybe_unused max_nonce)
 {
 	const int thr_id = thr->id;
 	struct opencl_thread_data *thrdata = thr->cgpu_data;
@@ -1352,7 +1352,7 @@ static uint64_t opencl_scanhash(struct thr_info *thr, struct work *work,
 	size_t globalThreads[1];
 	size_t localThreads[1] = { clState->wsize };
 	unsigned int threads;
-	unsigned int hashes;
+	int64_t hashes;
 
 	/* This finish flushes the readbuffer set with CL_FALSE later */
 	gettimeofday(&gpu->tv_gpustart, NULL);
diff --git a/driver-ztex.c b/driver-ztex.c
index e2b3755..a6e1101 100644
--- a/driver-ztex.c
+++ b/driver-ztex.c
@@ -185,8 +185,8 @@ static bool ztex_checkNonce(struct libztex_device *ztex,
 	return true;
 }
 
-static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
-                              __maybe_unused uint64_t max_nonce)
+static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
+                              __maybe_unused int64_t max_nonce)
 {
 	struct libztex_device *ztex;
 	unsigned char sendbuf[44];
@@ -215,7 +215,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 			ztex_disable(thr);
 			applog(LOG_ERR, "%s: Failed to send hash data with err %d, giving up", ztex->repr, i);
 			ztex_releaseFpga(ztex);
-			return 0;
+			return -1;
 		}
 	}
 	ztex_releaseFpga(ztex);
@@ -225,7 +225,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	lastnonce = malloc(sizeof(uint32_t)*ztex->numNonces);
 	if (lastnonce == NULL) {
 		applog(LOG_ERR, "%s: failed to allocate lastnonce[%d]", ztex->repr, ztex->numNonces);
-		return 0;
+		return -1;
 	}
 	memset(lastnonce, 0, sizeof(uint32_t)*ztex->numNonces);
 	
@@ -233,7 +233,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	backlog = malloc(sizeof(uint32_t) * backlog_max);
 	if (backlog == NULL) {
 		applog(LOG_ERR, "%s: failed to allocate backlog[%d]", ztex->repr, backlog_max);
-		return 0;
+		return -1;
 	}
 	memset(backlog, 0, sizeof(uint32_t) * backlog_max);
 	
@@ -260,7 +260,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 				free(lastnonce);
 				free(backlog);
 				ztex_releaseFpga(ztex);
-				return 0;
+				return -1;
 			}
 		}
 		ztex_releaseFpga(ztex);
@@ -330,7 +330,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		free(lastnonce);
 		free(backlog);
 		
-		return 0;
+		return -1;
 	}
 
 	applog(LOG_DEBUG, "%s: exit %1.8X", ztex->repr, noncecnt);
@@ -340,7 +340,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	free(lastnonce);
 	free(backlog);
 	
-	return noncecnt > 0? noncecnt: 1;
+	return noncecnt;
 }
 
 static void ztex_statline_before(char *buf, struct cgpu_info *cgpu)
diff --git a/miner.h b/miner.h
index 50a1ca2..a77ebae 100644
--- a/miner.h
+++ b/miner.h
@@ -244,7 +244,7 @@ struct device_api {
 	bool (*thread_init)(struct thr_info*);
 	void (*free_work)(struct thr_info*, struct work*);
 	bool (*prepare_work)(struct thr_info*, struct work*);
-	uint64_t (*scanhash)(struct thr_info*, struct work*, uint64_t);
+	int64_t (*scanhash)(struct thr_info*, struct work*, int64_t);
 	void (*thread_shutdown)(struct thr_info*);
 	void (*thread_enable)(struct thr_info*);
 };