Modify te scanhash API to use an int64_t and return -1 on error, allowing zero to be a valid return value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
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*);
};