Browse Source

Merge branch 'work_restart' into bfgminer

Luke Dashjr 14 years ago
parent
commit
78bb4ea409
14 changed files with 118 additions and 69 deletions
  1. 12 14
      driver-cpu.c
  2. 1 1
      driver-cpu.h
  3. 49 13
      driver-icarus.c
  4. 3 3
      driver-ztex.c
  5. 30 11
      miner.c
  6. 5 7
      miner.h
  7. 2 2
      sha256_4way.c
  8. 2 2
      sha256_altivec_4way.c
  9. 4 6
      sha256_cryptopp.c
  10. 2 2
      sha256_generic.c
  11. 2 2
      sha256_sse2_amd64.c
  12. 2 2
      sha256_sse2_i386.c
  13. 2 2
      sha256_sse4_amd64.c
  14. 2 2
      sha256_via.c

+ 12 - 14
driver-cpu.c

@@ -81,51 +81,51 @@ extern int dev_from_id(int thr_id);
 
 
 
 
 /* chipset-optimized hash functions */
 /* chipset-optimized hash functions */
-extern bool ScanHash_4WaySSE2(int, const unsigned char *pmidstate,
+extern bool ScanHash_4WaySSE2(struct thr_info*, const unsigned char *pmidstate,
 	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
 	unsigned char *pdata, unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 
 
-extern bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
+extern bool ScanHash_altivec_4way(struct thr_info*, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 
 
-extern bool scanhash_via(int, const unsigned char *pmidstate,
+extern bool scanhash_via(struct thr_info*, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *target,
 	const unsigned char *target,
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 	uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 
 
-extern bool scanhash_c(int, const unsigned char *midstate, unsigned char *data,
+extern bool scanhash_c(struct thr_info*, const unsigned char *midstate, unsigned char *data,
 	      unsigned char *hash1, unsigned char *hash,
 	      unsigned char *hash1, unsigned char *hash,
 	      const unsigned char *target,
 	      const unsigned char *target,
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 
 
-extern bool scanhash_cryptopp(int, const unsigned char *midstate,unsigned char *data,
+extern bool scanhash_cryptopp(struct thr_info*, const unsigned char *midstate,unsigned char *data,
 	      unsigned char *hash1, unsigned char *hash,
 	      unsigned char *hash1, unsigned char *hash,
 	      const unsigned char *target,
 	      const unsigned char *target,
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t n);
 
 
-extern bool scanhash_asm32(int, const unsigned char *midstate,unsigned char *data,
+extern bool scanhash_asm32(struct thr_info*, const unsigned char *midstate,unsigned char *data,
 	      unsigned char *hash1, unsigned char *hash,
 	      unsigned char *hash1, unsigned char *hash,
 	      const unsigned char *target,
 	      const unsigned char *target,
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 	      uint32_t max_nonce, uint32_t *last_nonce, uint32_t nonce);
 
 
-extern bool scanhash_sse2_64(int, const unsigned char *pmidstate, unsigned char *pdata,
+extern bool scanhash_sse2_64(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
 	uint32_t max_nonce, uint32_t *last_nonce,
 	uint32_t max_nonce, uint32_t *last_nonce,
 	uint32_t nonce);
 	uint32_t nonce);
 
 
-extern bool scanhash_sse4_64(int, const unsigned char *pmidstate, unsigned char *pdata,
+extern bool scanhash_sse4_64(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
 	uint32_t max_nonce, uint32_t *last_nonce,
 	uint32_t max_nonce, uint32_t *last_nonce,
 	uint32_t nonce);
 	uint32_t nonce);
 
 
-extern bool scanhash_sse2_32(int, const unsigned char *pmidstate, unsigned char *pdata,
+extern bool scanhash_sse2_32(struct thr_info*, const unsigned char *pmidstate, unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
 	uint32_t max_nonce, uint32_t *last_nonce,
 	uint32_t max_nonce, uint32_t *last_nonce,
@@ -224,8 +224,7 @@ double bench_algo_stage3(
 	memset(&work, 0, sizeof(work));
 	memset(&work, 0, sizeof(work));
 	memcpy(&work, &bench_block, min_size);
 	memcpy(&work, &bench_block, min_size);
 
 
-	struct work_restart dummy;
-	work_restart = &dummy;
+	struct thr_info dummy = {0};
 
 
 	struct timeval end;
 	struct timeval end;
 	struct timeval start;
 	struct timeval start;
@@ -236,7 +235,7 @@ double bench_algo_stage3(
 			{
 			{
 				sha256_func func = sha256_funcs[algo];
 				sha256_func func = sha256_funcs[algo];
 				(*func)(
 				(*func)(
-					0,
+					&dummy,
 					work.midstate,
 					work.midstate,
 					work.data,
 					work.data,
 					work.hash1,
 					work.hash1,
@@ -248,7 +247,6 @@ double bench_algo_stage3(
 				);
 				);
 			}
 			}
 	gettimeofday(&end, 0);
 	gettimeofday(&end, 0);
-	work_restart = NULL;
 
 
 	uint64_t usec_end = ((uint64_t)end.tv_sec)*1000*1000 + end.tv_usec;
 	uint64_t usec_end = ((uint64_t)end.tv_sec)*1000*1000 + end.tv_usec;
 	uint64_t usec_start = ((uint64_t)start.tv_sec)*1000*1000 + start.tv_usec;
 	uint64_t usec_start = ((uint64_t)start.tv_sec)*1000*1000 + start.tv_usec;
@@ -797,7 +795,7 @@ CPUSearch:
 	{
 	{
 		sha256_func func = sha256_funcs[opt_algo];
 		sha256_func func = sha256_funcs[opt_algo];
 		rc = (*func)(
 		rc = (*func)(
-			thr_id,
+			thr,
 			work->midstate,
 			work->midstate,
 			work->data,
 			work->data,
 			work->hash1,
 			work->hash1,

+ 1 - 1
driver-cpu.h

@@ -1,7 +1,7 @@
 #ifndef __DEVICE_CPU_H__
 #ifndef __DEVICE_CPU_H__
 #define __DEVICE_CPU_H__
 #define __DEVICE_CPU_H__
 
 
-#include "miner.h" /* for work_restart, TODO: re-factor dependency */
+#include "miner.h"
 
 
 #include "config.h"
 #include "config.h"
 #include <stdbool.h>
 #include <stdbool.h>

+ 49 - 13
driver-icarus.c

@@ -29,6 +29,8 @@
  *      nonce range is completely calculated.
  *      nonce range is completely calculated.
  */
  */
 
 
+#include "config.h"
+
 #include <limits.h>
 #include <limits.h>
 #include <pthread.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -264,7 +266,7 @@ static int icarus_open2(const char *devpath, __maybe_unused bool purge)
 
 
 #define icarus_open(devpath)  icarus_open2(devpath, false)
 #define icarus_open(devpath)  icarus_open2(devpath, false)
 
 
-static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, volatile unsigned long *wr, int read_count)
+static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, struct thr_info*thr, int read_count)
 {
 {
 	ssize_t ret = 0;
 	ssize_t ret = 0;
 	int rc = 0;
 	int rc = 0;
@@ -273,8 +275,10 @@ static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, vo
 	bool first = true;
 	bool first = true;
 
 
 #ifdef HAVE_EPOLL
 #ifdef HAVE_EPOLL
-	struct epoll_event ev, evr;
-	epollfd = epoll_create(1);
+	struct epoll_event ev;
+	struct epoll_event evr[2];
+	int epoll_timeout = ICARUS_READ_FAULT_DECISECONDS * 100;
+	epollfd = epoll_create(2);
 	if (epollfd != -1) {
 	if (epollfd != -1) {
 		ev.events = EPOLLIN;
 		ev.events = EPOLLIN;
 		ev.data.fd = fd;
 		ev.data.fd = fd;
@@ -282,14 +286,37 @@ static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, vo
 			close(epollfd);
 			close(epollfd);
 			epollfd = -1;
 			epollfd = -1;
 		}
 		}
+		if (thr->work_restart_fd != -1)
+		{
+			ev.data.fd = thr->work_restart_fd;
+			if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, thr->work_restart_fd, &ev))
+				applog(LOG_ERR, "Icarus: Error adding work restart fd to epoll");
+			else
+			{
+				epoll_timeout *= read_count;
+				read_count = 1;
+			}
+		}
 	}
 	}
+	else
+		applog(LOG_ERR, "Icarus: Error creating epoll");
 #endif
 #endif
 
 
 	// Read reply 1 byte at a time to get earliest tv_finish
 	// Read reply 1 byte at a time to get earliest tv_finish
 	while (true) {
 	while (true) {
 #ifdef HAVE_EPOLL
 #ifdef HAVE_EPOLL
-		if (epollfd != -1 && epoll_wait(epollfd, &evr, 1, ICARUS_READ_FAULT_DECISECONDS * 100) != 1)
-			ret = 0;
+		if (epollfd != -1 && (ret = epoll_wait(epollfd, evr, 2, epoll_timeout)) != -1)
+		{
+			if (ret == 1 && evr[0].data.fd == fd)
+				ret = read(fd, buf, 1);
+			else
+			{
+				if (ret)
+					// work restart trigger
+					(void)read(thr->work_restart_fd, buf, read_amount);
+				ret = 0;
+			}
+		}
 		else
 		else
 #endif
 #endif
 		ret = read(fd, buf, 1);
 		ret = read(fd, buf, 1);
@@ -312,14 +339,14 @@ static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, vo
 		}
 		}
 			
 			
 		rc++;
 		rc++;
-		if (rc >= read_count || *wr) {
+		if (rc >= read_count || thr->work_restart) {
 			if (epollfd != -1)
 			if (epollfd != -1)
 				close(epollfd);
 				close(epollfd);
 			if (opt_debug) {
 			if (opt_debug) {
 				rc *= ICARUS_READ_FAULT_DECISECONDS;
 				rc *= ICARUS_READ_FAULT_DECISECONDS;
 				applog(LOG_DEBUG,
 				applog(LOG_DEBUG,
 			        "Icarus Read: %s %d.%d seconds",
 			        "Icarus Read: %s %d.%d seconds",
-			        (*wr) ? "Work restart at" : "No data in",
+			        thr->work_restart ? "Work restart at" : "No data in",
 			        rc / 10, rc % 10);
 			        rc / 10, rc % 10);
 			}
 			}
 			return 1;
 			return 1;
@@ -474,9 +501,11 @@ static bool icarus_detect_one(const char *devpath)
 	icarus_write(fd, ob_bin, sizeof(ob_bin));
 	icarus_write(fd, ob_bin, sizeof(ob_bin));
 
 
 	memset(nonce_bin, 0, sizeof(nonce_bin));
 	memset(nonce_bin, 0, sizeof(nonce_bin));
-	volatile unsigned long wr = 0;
+	struct thr_info dummy = {
+		.work_restart_fd = -1,
+	};
 	struct timeval tv_finish;
 	struct timeval tv_finish;
-	icarus_gets(nonce_bin, fd, &tv_finish, &wr, 1);
+	icarus_gets(nonce_bin, fd, &tv_finish, &dummy, 1);
 
 
 	icarus_close(fd);
 	icarus_close(fd);
 
 
@@ -571,14 +600,21 @@ static bool icarus_prepare(struct thr_info *thr)
 	thr->cgpu_data = state = calloc(1, sizeof(*state));
 	thr->cgpu_data = state = calloc(1, sizeof(*state));
 	state->firstrun = true;
 	state->firstrun = true;
 
 
+#ifdef HAVE_EPOLL
+	int epollfd = epoll_create(2);
+	if (epollfd != -1)
+	{
+		close(epollfd);
+		thr->work_restart_fd = 0;
+	}
+#endif
+
 	return true;
 	return true;
 }
 }
 
 
 static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 				__maybe_unused uint64_t max_nonce)
 				__maybe_unused uint64_t max_nonce)
 {
 {
-	volatile unsigned long *wr = &work_restart[thr->id].restart;
-
 	struct cgpu_info *icarus;
 	struct cgpu_info *icarus;
 	int fd;
 	int fd;
 	int ret, lret;
 	int ret, lret;
@@ -623,8 +659,8 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
 		{
 		{
 			/* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
 			/* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
 			info = icarus_info[icarus->device_id];
 			info = icarus_info[icarus->device_id];
-			lret = icarus_gets(nonce_bin, fd, &tv_finish, wr, info->read_count);
-			if (lret && *wr) {
+			lret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count);
+			if (lret && thr->work_restart) {
 				// The prepared work is invalid, and the current work is abandoned
 				// The prepared work is invalid, and the current work is abandoned
 				// Go back to the main loop to get the next work, and stuff
 				// Go back to the main loop to get the next work, and stuff
 				// Returning to the main loop will clear work_restart, so use a flag...
 				// Returning to the main loop will clear work_restart, so use a flag...

+ 3 - 3
driver-ztex.c

@@ -241,9 +241,9 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	overflow = false;
 	overflow = false;
 
 
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
 	applog(LOG_DEBUG, "%s: entering poll loop", ztex->repr);
-	while (!(overflow || work_restart[thr->id].restart)) {
+	while (!(overflow || thr->work_restart)) {
 		usleep(250000);
 		usleep(250000);
-		if (work_restart[thr->id].restart) {
+		if (thr->work_restart) {
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
 			break;
 			break;
 		}
 		}
@@ -266,7 +266,7 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 		}
 		}
 		ztex_releaseFpga(ztex);
 		ztex_releaseFpga(ztex);
 
 
-		if (work_restart[thr->id].restart) {
+		if (thr->work_restart) {
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
 			applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
 			break;
 			break;
 		}
 		}

+ 30 - 11
miner.c

@@ -154,8 +154,6 @@ int gpur_thr_id;
 static int api_thr_id;
 static int api_thr_id;
 static int total_threads;
 static int total_threads;
 
 
-struct work_restart *work_restart = NULL;
-
 static pthread_mutex_t hash_lock;
 static pthread_mutex_t hash_lock;
 static pthread_mutex_t qd_lock;
 static pthread_mutex_t qd_lock;
 static pthread_mutex_t *stgd_lock;
 static pthread_mutex_t *stgd_lock;
@@ -2394,7 +2392,9 @@ static bool queue_request(struct thr_info *thr, bool needed);
 
 
 static void restart_threads(void)
 static void restart_threads(void)
 {
 {
-	int i, stale;
+	int i, j, stale, fd;
+	struct cgpu_info *cgpu;
+	struct thr_info *thr;
 
 
 	/* Discard staged work that is now stale */
 	/* Discard staged work that is now stale */
 	stale = discard_stale();
 	stale = discard_stale();
@@ -2402,8 +2402,18 @@ static void restart_threads(void)
 	for (i = 0; i < stale; i++)
 	for (i = 0; i < stale; i++)
 		queue_request(NULL, true);
 		queue_request(NULL, true);
 
 
-	for (i = 0; i < mining_threads; i++)
-		work_restart[i].restart = 1;
+	for (i = 0; i < total_devices; ++i)
+	{
+		cgpu = devices[i];
+		for (j = 0; j < cgpu->threads; ++j)
+		{
+			thr = &cgpu->thread[j];
+			fd = thr->_work_restart_fd_w;
+			thr->work_restart = true;
+			if (fd != -1)
+				write(fd, "\0", 1);
+		}
+	}
 }
 }
 
 
 static void set_curblock(char *hexstr, unsigned char *hash)
 static void set_curblock(char *hexstr, unsigned char *hash)
@@ -3800,7 +3810,7 @@ void *miner_thread(void *userdata)
 	gettimeofday(&tv_lastupdate, NULL);
 	gettimeofday(&tv_lastupdate, NULL);
 
 
 	while (1) {
 	while (1) {
-		work_restart[thr_id].restart = 0;
+		mythr->work_restart = false;
 		if (api->free_work && likely(work->pool))
 		if (api->free_work && likely(work->pool))
 			api->free_work(mythr, work);
 			api->free_work(mythr, work);
 		if (unlikely(!get_work(work, requested, mythr, thr_id))) {
 		if (unlikely(!get_work(work, requested, mythr, thr_id))) {
@@ -3856,7 +3866,7 @@ void *miner_thread(void *userdata)
 
 
 			gettimeofday(&getwork_start, NULL);
 			gettimeofday(&getwork_start, NULL);
 
 
-			if (unlikely(work_restart[thr_id].restart)) {
+			if (unlikely(mythr->work_restart)) {
 
 
 				/* Apart from device_thread 0, we stagger the
 				/* Apart from device_thread 0, we stagger the
 				 * starting of every next thread to try and get
 				 * starting of every next thread to try and get
@@ -5100,10 +5110,6 @@ int main(int argc, char *argv[])
 	#endif // defined(unix)
 	#endif // defined(unix)
 
 
 	total_threads = mining_threads + 7;
 	total_threads = mining_threads + 7;
-	work_restart = calloc(total_threads, sizeof(*work_restart));
-	if (!work_restart)
-		quit(1, "Failed to calloc work_restart");
-
 	thr_info = calloc(total_threads, sizeof(*thr));
 	thr_info = calloc(total_threads, sizeof(*thr));
 	if (!thr_info)
 	if (!thr_info)
 		quit(1, "Failed to calloc thr_info");
 		quit(1, "Failed to calloc thr_info");
@@ -5215,6 +5221,7 @@ begin_bench:
 			thr->id = k;
 			thr->id = k;
 			thr->cgpu = cgpu;
 			thr->cgpu = cgpu;
 			thr->device_thread = j;
 			thr->device_thread = j;
+			thr->work_restart_fd = thr->_work_restart_fd_w = -1;
 
 
 			thr->q = tq_new();
 			thr->q = tq_new();
 			if (!thr->q)
 			if (!thr->q)
@@ -5231,6 +5238,18 @@ begin_bench:
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 			if (cgpu->api->thread_prepare && !cgpu->api->thread_prepare(thr))
 				continue;
 				continue;
 
 
+			if (!thr->work_restart_fd)
+			{
+				int pipefd[2];
+				if (!pipe(pipefd))
+				{
+					thr->work_restart_fd = pipefd[0];
+					thr->_work_restart_fd_w = pipefd[1];
+				}
+				else
+					thr->work_restart_fd = -1;
+			}
+
 			thread_reportout(thr);
 			thread_reportout(thr);
 
 
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))
 			if (unlikely(thr_info_create(thr, NULL, miner_thread, thr)))

+ 5 - 7
miner.h

@@ -390,6 +390,10 @@ struct thr_info {
 	bool	pause;
 	bool	pause;
 	bool	getwork;
 	bool	getwork;
 	double	rolling;
 	double	rolling;
+
+	bool	work_restart;
+	int		work_restart_fd;
+	int		_work_restart_fd_w;
 };
 };
 
 
 extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
 extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
@@ -523,7 +527,7 @@ extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern char *bin2hex(const unsigned char *p, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
 extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
 
 
-typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
+typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -538,11 +542,6 @@ extern bool fulltest(const unsigned char *hash, const unsigned char *target);
 
 
 extern int opt_scantime;
 extern int opt_scantime;
 
 
-struct work_restart {
-	volatile unsigned long	restart;
-	char			padding[128 - sizeof(unsigned long)];
-};
-
 extern void thread_reportin(struct thr_info *thr);
 extern void thread_reportin(struct thr_info *thr);
 
 
 extern void kill_work(void);
 extern void kill_work(void);
@@ -582,7 +581,6 @@ extern int num_processors;
 extern int hw_errors;
 extern int hw_errors;
 extern bool use_syslog;
 extern bool use_syslog;
 extern struct thr_info *thr_info;
 extern struct thr_info *thr_info;
-extern struct work_restart *work_restart;
 extern struct cgpu_info gpus[MAX_GPUDEVICES];
 extern struct cgpu_info gpus[MAX_GPUDEVICES];
 extern int gpu_threads;
 extern int gpu_threads;
 extern double total_secs;
 extern double total_secs;

+ 2 - 2
sha256_4way.c

@@ -100,7 +100,7 @@ static const unsigned int pSHA256InitState[8] =
 {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
 {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
 
 
 
 
-bool ScanHash_4WaySSE2(int thr_id, const unsigned char *pmidstate,
+bool ScanHash_4WaySSE2(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -139,7 +139,7 @@ bool ScanHash_4WaySSE2(int thr_id, const unsigned char *pmidstate,
             }
             }
         }
         }
 
 
-        if ((nonce >= max_nonce) || work_restart[thr_id].restart)
+        if ((nonce >= max_nonce) || thr->work_restart)
         {
         {
             *last_nonce = nonce;
             *last_nonce = nonce;
             return false;
             return false;

+ 2 - 2
sha256_altivec_4way.c

@@ -73,7 +73,7 @@ static const unsigned int pSHA256InitState[8] =
 {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
 {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
 
 
 
 
-bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
+bool ScanHash_altivec_4way(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -111,7 +111,7 @@ bool ScanHash_altivec_4way(int thr_id, const unsigned char *pmidstate,
             }
             }
         }
         }
 
 
-        if ((nonce >= max_nonce) || work_restart[thr_id].restart)
+        if ((nonce >= max_nonce) || thr->work_restart)
         {
         {
             *last_nonce = nonce;
             *last_nonce = nonce;
             return false;
             return false;

+ 4 - 6
sha256_cryptopp.c

@@ -93,7 +93,7 @@ static void runhash(void *state, const void *input, const void *init)
 }
 }
 
 
 /* suspiciously similar to ScanHash* from bitcoin */
 /* suspiciously similar to ScanHash* from bitcoin */
-bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
+bool scanhash_cryptopp(struct thr_info*thr, const unsigned char *midstate,
 		unsigned char *data,
 		unsigned char *data,
 	        unsigned char *hash1, unsigned char *hash,
 	        unsigned char *hash1, unsigned char *hash,
 		const unsigned char *target,
 		const unsigned char *target,
@@ -105,8 +105,6 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
 
 
 	data += 64;
 	data += 64;
 
 
-	work_restart[thr_id].restart = 0;
-
 	while (1) {
 	while (1) {
 		n++;
 		n++;
 		*nonce = n;
 		*nonce = n;
@@ -119,7 +117,7 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
 			return true;
 			return true;
 		}
 		}
 
 
-		if ((n >= max_nonce) || work_restart[thr_id].restart) {
+		if ((n >= max_nonce) || thr->work_restart) {
 			*last_nonce = n;
 			*last_nonce = n;
 			return false;
 			return false;
 		}
 		}
@@ -577,7 +575,7 @@ static void runhash32(void *state, const void *input, const void *init)
 }
 }
 
 
 /* suspiciously similar to ScanHash* from bitcoin */
 /* suspiciously similar to ScanHash* from bitcoin */
-bool scanhash_asm32(int thr_id, const unsigned char *midstate,
+bool scanhash_asm32(struct thr_info*thr, const unsigned char *midstate,
 		unsigned char *data,
 		unsigned char *data,
 	        unsigned char *hash1, unsigned char *hash,
 	        unsigned char *hash1, unsigned char *hash,
 		const unsigned char *target,
 		const unsigned char *target,
@@ -601,7 +599,7 @@ bool scanhash_asm32(int thr_id, const unsigned char *midstate,
 			return true;
 			return true;
 		}
 		}
 
 
-		if ((n >= max_nonce) || work_restart[thr_id].restart) {
+		if ((n >= max_nonce) || thr->work_restart) {
 			*last_nonce = n;
 			*last_nonce = n;
 			return false;
 			return false;
 		}
 		}

+ 2 - 2
sha256_generic.c

@@ -239,7 +239,7 @@ const uint32_t sha256_init_state[8] = {
 };
 };
 
 
 /* suspiciously similar to ScanHash* from bitcoin */
 /* suspiciously similar to ScanHash* from bitcoin */
-bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
+bool scanhash_c(struct thr_info*thr, const unsigned char *midstate, unsigned char *data,
 	        unsigned char *hash1, unsigned char *hash,
 	        unsigned char *hash1, unsigned char *hash,
 		const unsigned char *target,
 		const unsigned char *target,
 	        uint32_t max_nonce, uint32_t *last_nonce,
 	        uint32_t max_nonce, uint32_t *last_nonce,
@@ -265,7 +265,7 @@ bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
 			return true;
 			return true;
 		}
 		}
 
 
-		if ((n >= max_nonce) || work_restart[thr_id].restart) {
+		if ((n >= max_nonce) || thr->work_restart) {
 			*last_nonce = n;
 			*last_nonce = n;
 			return false;
 			return false;
 		}
 		}

+ 2 - 2
sha256_sse2_amd64.c

@@ -48,7 +48,7 @@ const uint32_t sha256_init[8]__attribute__((aligned(0x100))) =
 __m128i g_4sha256_k[64];
 __m128i g_4sha256_k[64];
 __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
 __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
 
 
-bool scanhash_sse2_64(int thr_id, const unsigned char *pmidstate,
+bool scanhash_sse2_64(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -119,7 +119,7 @@ bool scanhash_sse2_64(int thr_id, const unsigned char *pmidstate,
 		}
 		}
 	}
 	}
 
 
-        if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart))
+        if (unlikely((nonce >= max_nonce) || thr->work_restart))
         {
         {
 			*last_nonce = nonce;
 			*last_nonce = nonce;
 			return false;
 			return false;

+ 2 - 2
sha256_sse2_i386.c

@@ -48,7 +48,7 @@ const uint32_t sha256_32init[8]__attribute__((aligned(0x100))) =
 __m128i g_4sha256_k[64];
 __m128i g_4sha256_k[64];
 __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
 __m128i sha256_consts_m128i[64]__attribute__((aligned(0x1000)));
 
 
-bool scanhash_sse2_32(int thr_id, const unsigned char *pmidstate,
+bool scanhash_sse2_32(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -111,7 +111,7 @@ bool scanhash_sse2_32(int thr_id, const unsigned char *pmidstate,
 	    }
 	    }
 	}
 	}
 
 
-	if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart)) {
+	if (unlikely((nonce >= max_nonce) || thr->work_restart)) {
 		*last_nonce = nonce;
 		*last_nonce = nonce;
 		return false;
 		return false;
 	}
 	}

+ 2 - 2
sha256_sse4_amd64.c

@@ -47,7 +47,7 @@ static uint32_t g_sha256_hinit[8] =
 
 
 __m128i g_4sha256_k[64];
 __m128i g_4sha256_k[64];
 
 
-bool scanhash_sse4_64(int thr_id, const unsigned char *pmidstate,
+bool scanhash_sse4_64(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *pdata,
 	unsigned char *pdata,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *ptarget,
 	const unsigned char *ptarget,
@@ -118,7 +118,7 @@ bool scanhash_sse4_64(int thr_id, const unsigned char *pmidstate,
 		}
 		}
 	}
 	}
 
 
-        if (unlikely((nonce >= max_nonce) || work_restart[thr_id].restart))
+        if (unlikely((nonce >= max_nonce) || thr->work_restart))
         {
         {
 			*last_nonce = nonce;
 			*last_nonce = nonce;
 			return false;
 			return false;

+ 2 - 2
sha256_via.c

@@ -19,7 +19,7 @@ static void via_sha256(void *hash, void *buf, unsigned len)
 		     :"memory");
 		     :"memory");
 }
 }
 
 
-bool scanhash_via(int thr_id, const unsigned char *pmidstate,
+bool scanhash_via(struct thr_info*thr, const unsigned char *pmidstate,
 	unsigned char *data_inout,
 	unsigned char *data_inout,
 	unsigned char *phash1, unsigned char *phash,
 	unsigned char *phash1, unsigned char *phash,
 	const unsigned char *target,
 	const unsigned char *target,
@@ -74,7 +74,7 @@ bool scanhash_via(int thr_id, const unsigned char *pmidstate,
 			return true;
 			return true;
 		}
 		}
 
 
-		if ((n >= max_nonce) || work_restart[thr_id].restart) {
+		if ((n >= max_nonce) || thr->work_restart) {
 			*last_nonce = n;
 			*last_nonce = n;
 			return false;
 			return false;
 		}
 		}