Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Turn work_restart array into a bool in thr_info #210

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ int gpur_thr_id;
static int api_thr_id;
static int total_threads;

struct work_restart *work_restart = NULL;

static pthread_mutex_t hash_lock;
static pthread_mutex_t qd_lock;
static pthread_mutex_t *stgd_lock;
Expand Down Expand Up @@ -2376,16 +2374,25 @@ static bool queue_request(struct thr_info *thr, bool needed);

static void restart_threads(void)
{
int i, stale;
int i, j, stale;
struct cgpu_info *cgpu;
struct thr_info *thr;

/* Discard staged work that is now stale */
stale = discard_stale();

for (i = 0; i < stale; i++)
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];
thr->work_restart = true;
}
}
}

static void set_curblock(char *hexstr, unsigned char *hash)
Expand Down Expand Up @@ -3774,7 +3781,7 @@ void *miner_thread(void *userdata)
gettimeofday(&tv_lastupdate, NULL);

while (1) {
work_restart[thr_id].restart = 0;
mythr->work_restart = false;
if (api->free_work && likely(work->pool))
api->free_work(mythr, work);
if (unlikely(!get_work(work, requested, mythr, thr_id))) {
Expand Down Expand Up @@ -3830,7 +3837,7 @@ void *miner_thread(void *userdata)

gettimeofday(&getwork_start, NULL);

if (unlikely(work_restart[thr_id].restart)) {
if (unlikely(mythr->work_restart)) {

/* Apart from device_thread 0, we stagger the
* starting of every next thread to try and get
Expand Down Expand Up @@ -5035,10 +5042,6 @@ int main(int argc, char *argv[])
#endif // defined(unix)

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));
if (!thr_info)
quit(1, "Failed to calloc thr_info");
Expand Down
26 changes: 12 additions & 14 deletions driver-cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,51 +81,51 @@ extern int dev_from_id(int thr_id);


/* 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,
const unsigned char *ptarget,
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 *phash1, unsigned char *phash,
const unsigned char *ptarget,
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 *phash1, unsigned char *phash,
const unsigned char *target,
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,
const unsigned char *target,
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,
const unsigned char *target,
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,
const unsigned char *target,
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,
const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_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,
const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_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,
const unsigned char *ptarget,
uint32_t max_nonce, uint32_t *last_nonce,
Expand Down Expand Up @@ -224,8 +224,7 @@ double bench_algo_stage3(
memset(&work, 0, sizeof(work));
memcpy(&work, &bench_block, min_size);

struct work_restart dummy;
work_restart = &dummy;
struct thr_info dummy = {0};

struct timeval end;
struct timeval start;
Expand All @@ -236,7 +235,7 @@ double bench_algo_stage3(
{
sha256_func func = sha256_funcs[algo];
(*func)(
0,
&dummy,
work.midstate,
work.data,
work.hash1,
Expand All @@ -248,7 +247,6 @@ double bench_algo_stage3(
);
}
gettimeofday(&end, 0);
work_restart = NULL;

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;
Expand Down Expand Up @@ -797,7 +795,7 @@ static uint64_t cpu_scanhash(struct thr_info *thr, struct work *work, uint64_t m
{
sha256_func func = sha256_funcs[opt_algo];
rc = (*func)(
thr_id,
thr,
work->midstate,
work->data,
work->hash1,
Expand Down
2 changes: 1 addition & 1 deletion driver-cpu.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef __DEVICE_CPU_H__
#define __DEVICE_CPU_H__

#include "miner.h" /* for work_restart, TODO: re-factor dependency */
#include "miner.h"

#include "config.h"
#include <stdbool.h>
Expand Down
22 changes: 7 additions & 15 deletions driver-icarus.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static int icarus_open(const char *devpath)
#endif
}

static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, int thr_id, 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;
int rc = 0;
Expand All @@ -279,23 +279,15 @@ static int icarus_gets(unsigned char *buf, int fd, struct timeval *tv_finish, in
}

rc++;
if (rc >= read_count) {
if (rc >= read_count || thr->work_restart) {
if (opt_debug) {
applog(LOG_DEBUG,
"Icarus Read: No data in %.2f seconds",
"Icarus Read: %s %.2f seconds",
thr->work_restart ? "Work restart at" : "No data in",
(float)rc/(float)TIME_FACTOR);
}
return 1;
}

if (thr_id >= 0 && work_restart[thr_id].restart) {
if (opt_debug) {
applog(LOG_DEBUG,
"Icarus Read: Work restart at %.2f seconds",
(float)(rc)/(float)TIME_FACTOR);
}
return 1;
}
}
}

Expand Down Expand Up @@ -449,7 +441,8 @@ static bool icarus_detect_one(const char *devpath)
gettimeofday(&tv_start, NULL);

memset(nonce_bin, 0, sizeof(nonce_bin));
icarus_gets(nonce_bin, fd, &tv_finish, -1, 1);
struct thr_info dummy = {0};
icarus_gets(nonce_bin, fd, &tv_finish, &dummy, 1);

icarus_close(fd);

Expand Down Expand Up @@ -542,7 +535,6 @@ static bool icarus_prepare(struct thr_info *thr)
static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
__maybe_unused uint64_t max_nonce)
{
const int thr_id = thr->id;
struct cgpu_info *icarus;
int fd;
int ret;
Expand Down Expand Up @@ -597,7 +589,7 @@ static uint64_t icarus_scanhash(struct thr_info *thr, struct work *work,
/* Icarus will return 4 bytes (ICARUS_READ_SIZE) nonces or nothing */
memset(nonce_bin, 0, sizeof(nonce_bin));
info = icarus_info[icarus->device_id];
ret = icarus_gets(nonce_bin, fd, &tv_finish, thr_id, info->read_count);
ret = icarus_gets(nonce_bin, fd, &tv_finish, thr, info->read_count);

work->blk.nonce = 0xffffffff;
memcpy((char *)&nonce, nonce_bin, sizeof(nonce_bin));
Expand Down
6 changes: 3 additions & 3 deletions driver-ztex.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ static uint64_t ztex_scanhash(struct thr_info *thr, struct work *work,
overflow = false;

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

if (work_restart[thr->id].restart) {
if (thr->work_restart) {
applog(LOG_DEBUG, "%s: New work detected", ztex->repr);
break;
}
Expand Down
10 changes: 3 additions & 7 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ struct thr_info {
bool pause;
bool getwork;
double rolling;

bool work_restart;
};

extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
Expand Down Expand Up @@ -525,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 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 *phash1, unsigned char *phash,
const unsigned char *ptarget,
Expand All @@ -540,11 +542,6 @@ extern bool fulltest(const unsigned char *hash, const unsigned char *target);

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 kill_work(void);
Expand Down Expand Up @@ -584,7 +581,6 @@ extern int num_processors;
extern int hw_errors;
extern bool use_syslog;
extern struct thr_info *thr_info;
extern struct work_restart *work_restart;
extern struct cgpu_info gpus[MAX_GPUDEVICES];
extern int gpu_threads;
extern double total_secs;
Expand Down
4 changes: 2 additions & 2 deletions sha256_4way.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static const unsigned int pSHA256InitState[8] =
{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 *phash1, unsigned char *phash,
const unsigned char *ptarget,
Expand Down Expand Up @@ -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;
return false;
Expand Down
4 changes: 2 additions & 2 deletions sha256_altivec_4way.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static const unsigned int pSHA256InitState[8] =
{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 *phash1, unsigned char *phash,
const unsigned char *ptarget,
Expand Down Expand Up @@ -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;
return false;
Expand Down
10 changes: 4 additions & 6 deletions sha256_cryptopp.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void runhash(void *state, const void *input, const void *init)
}

/* 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 *hash1, unsigned char *hash,
const unsigned char *target,
Expand All @@ -105,8 +105,6 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,

data += 64;

work_restart[thr_id].restart = 0;

while (1) {
n++;
*nonce = n;
Expand All @@ -119,7 +117,7 @@ bool scanhash_cryptopp(int thr_id, const unsigned char *midstate,
return true;
}

if ((n >= max_nonce) || work_restart[thr_id].restart) {
if ((n >= max_nonce) || thr->work_restart) {
*last_nonce = n;
return false;
}
Expand Down Expand Up @@ -577,7 +575,7 @@ static void runhash32(void *state, const void *input, const void *init)
}

/* 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 *hash1, unsigned char *hash,
const unsigned char *target,
Expand All @@ -601,7 +599,7 @@ bool scanhash_asm32(int thr_id, const unsigned char *midstate,
return true;
}

if ((n >= max_nonce) || work_restart[thr_id].restart) {
if ((n >= max_nonce) || thr->work_restart) {
*last_nonce = n;
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions sha256_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const uint32_t sha256_init_state[8] = {
};

/* 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,
const unsigned char *target,
uint32_t max_nonce, uint32_t *last_nonce,
Expand All @@ -265,7 +265,7 @@ bool scanhash_c(int thr_id, const unsigned char *midstate, unsigned char *data,
return true;
}

if ((n >= max_nonce) || work_restart[thr_id].restart) {
if ((n >= max_nonce) || thr->work_restart) {
*last_nonce = n;
return false;
}
Expand Down
Loading