Browse Source

Begin tearing down the old workio command queues by removing submit commands from there and submit them asynchronously via their own threads.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
c99636f21b
  1. 67
      cgminer.c
  2. 6
      driver-cpu.c
  3. 6
      driver-ztex.c
  4. 6
      findnonce.c
  5. 2
      miner.h

67
cgminer.c

@ -64,7 +64,6 @@
enum workio_commands { enum workio_commands {
WC_GET_WORK, WC_GET_WORK,
WC_SUBMIT_WORK,
}; };
struct workio_cmd { struct workio_cmd {
@ -2737,11 +2736,8 @@ static void workio_cmd_free(struct workio_cmd *wc)
return; return;
switch (wc->cmd) { switch (wc->cmd) {
case WC_SUBMIT_WORK: default: /* do nothing */
free_work(wc->work); break;
break;
default: /* do nothing */
break;
} }
memset(wc, 0, sizeof(*wc)); /* poison */ memset(wc, 0, sizeof(*wc)); /* poison */
@ -3284,8 +3280,7 @@ static void check_solve(struct work *work)
static void *submit_work_thread(void *userdata) static void *submit_work_thread(void *userdata)
{ {
struct workio_cmd *wc = (struct workio_cmd *)userdata; struct work *work = (struct work *)userdata;
struct work *work = wc->work;
struct pool *pool = work->pool; struct pool *pool = work->pool;
bool resubmit = false; bool resubmit = false;
struct curl_ent *ce; struct curl_ent *ce;
@ -3374,25 +3369,9 @@ static void *submit_work_thread(void *userdata)
} }
push_curl_entry(ce, pool); push_curl_entry(ce, pool);
out: out:
workio_cmd_free(wc);
return NULL; return NULL;
} }
/* We try to reuse curl handles as much as possible, but if there is already
* work queued to be submitted, we start generating extra handles to submit
* the shares to avoid ever increasing backlogs. This allows us to scale to
* any size hardware */
static bool workio_submit_work(struct workio_cmd *wc)
{
pthread_t submit_thread;
if (unlikely(pthread_create(&submit_thread, NULL, submit_work_thread, (void *)wc))) {
applog(LOG_ERR, "Failed to create submit_work_thread");
return false;
}
return true;
}
/* Find the pool that currently has the highest priority */ /* Find the pool that currently has the highest priority */
static struct pool *priority_pool(int choice) static struct pool *priority_pool(int choice)
{ {
@ -4482,9 +4461,6 @@ static void *workio_thread(void *userdata)
case WC_GET_WORK: case WC_GET_WORK:
ok = workio_get_work(wc); ok = workio_get_work(wc);
break; break;
case WC_SUBMIT_WORK:
ok = workio_submit_work(wc);
break;
default: default:
ok = false; ok = false;
break; break;
@ -5454,35 +5430,16 @@ out:
work->mined = true; work->mined = true;
} }
bool submit_work_sync(struct thr_info *thr, struct work *work_in, struct timeval *tv_work_found) void submit_work_async(struct work *work_in, struct timeval *tv_work_found)
{ {
struct workio_cmd *wc; struct work *work = copy_work(work_in);
pthread_t submit_thread;
/* fill out work request message */
wc = calloc(1, sizeof(*wc));
if (unlikely(!wc)) {
applog(LOG_ERR, "Failed to calloc wc in submit_work_sync");
return false;
}
wc->work = copy_work(work_in);
wc->cmd = WC_SUBMIT_WORK;
wc->thr = thr;
if (tv_work_found) if (tv_work_found)
memcpy(&(wc->work->tv_work_found), tv_work_found, sizeof(struct timeval)); memcpy(&(work->tv_work_found), tv_work_found, sizeof(struct timeval));
applog(LOG_DEBUG, "Pushing submit work to work thread"); applog(LOG_DEBUG, "Pushing submit work to work thread");
if (unlikely(pthread_create(&submit_thread, NULL, submit_work_thread, (void *)work)))
/* send solution to workio thread */ quit(1, "Failed to create submit_work_thread");
if (unlikely(!tq_push(thr_info[work_thr_id].q, wc))) {
applog(LOG_ERR, "Failed to tq_push work in submit_work_sync");
goto err_out;
}
return true;
err_out:
workio_cmd_free(wc);
return false;
} }
static bool hashtest(struct thr_info *thr, struct work *work) static bool hashtest(struct thr_info *thr, struct work *work)
@ -5552,7 +5509,7 @@ static bool test_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
return hashtest(thr, work); return hashtest(thr, work);
} }
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce) void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
{ {
struct timeval tv_work_found; struct timeval tv_work_found;
gettimeofday(&tv_work_found, NULL); gettimeofday(&tv_work_found, NULL);
@ -5566,9 +5523,9 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
/* Do one last check before attempting to submit the work */ /* Do one last check before attempting to submit the work */
/* Side effect: sets work->data for us */ /* Side effect: sets work->data for us */
if (!test_nonce(thr, work, nonce)) if (!test_nonce(thr, work, nonce))
return true; return;
return submit_work_sync(thr, work, &tv_work_found); submit_work_async(work, &tv_work_found);
} }
static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes) static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)

6
driver-cpu.c

@ -75,7 +75,7 @@ static inline void affine_to_cpu(int __maybe_unused id, int __maybe_unused cpu)
/* TODO: resolve externals */ /* TODO: resolve externals */
extern bool submit_work_sync(struct thr_info *thr, const struct work *work_in, struct timeval *tv); extern void submit_work_async(const struct work *work_in, struct timeval *tv);
extern char *set_int_range(const char *arg, int *i, int min, int max); extern char *set_int_range(const char *arg, int *i, int min, int max);
extern int dev_from_id(int thr_id); extern int dev_from_id(int thr_id);
@ -831,9 +831,7 @@ CPUSearch:
/* if nonce found, submit work */ /* if nonce found, submit work */
if (unlikely(rc)) { if (unlikely(rc)) {
applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id)); applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id));
if (unlikely(!submit_work_sync(thr, work, NULL))) { submit_work_async(work, NULL);
applog(LOG_ERR, "Failed to submit_work_sync in miner_thread %d", thr_id);
}
work->blk.nonce = last_nonce + 1; work->blk.nonce = last_nonce + 1;
goto CPUSearch; goto CPUSearch;
} }

6
driver-ztex.c

@ -195,7 +195,7 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
int backlog_p = 0, backlog_max; int backlog_p = 0, backlog_max;
uint32_t *lastnonce; uint32_t *lastnonce;
uint32_t nonce, noncecnt = 0; uint32_t nonce, noncecnt = 0;
bool overflow, found, rv; bool overflow, found;
struct libztex_hash_data hdata[GOLDEN_BACKLOG]; struct libztex_hash_data hdata[GOLDEN_BACKLOG];
ztex = thr->cgpu->device_ztex; ztex = thr->cgpu->device_ztex;
@ -310,8 +310,8 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
nonce = swab32(nonce); nonce = swab32(nonce);
#endif #endif
work->blk.nonce = 0xffffffff; work->blk.nonce = 0xffffffff;
rv = submit_nonce(thr, work, nonce); submit_nonce(thr, work, nonce);
applog(LOG_DEBUG, "%s: submitted %0.8x %d", ztex->repr, nonce, rv); applog(LOG_DEBUG, "%s: submitted %0.8x", ztex->repr, nonce);
} }
} }
} }

6
findnonce.c

@ -216,10 +216,8 @@ static void *postcalc_hash(void *userdata)
applog(LOG_DEBUG, "OCL NONCE %u found in slot %d", nonce, entry); applog(LOG_DEBUG, "OCL NONCE %u found in slot %d", nonce, entry);
if (opt_scrypt) if (opt_scrypt)
send_scrypt_nonce(pcd, nonce); send_scrypt_nonce(pcd, nonce);
else { else
if (unlikely(submit_nonce(thr, &pcd->work, nonce) == false)) submit_nonce(thr, &pcd->work, nonce);
applog(LOG_ERR, "Failed to submit work, exiting");
}
} }
free(pcd); free(pcd);

2
miner.h

@ -1036,7 +1036,7 @@ struct modminer_fpga_state {
#endif #endif
extern void get_datestamp(char *, struct timeval *); extern void get_datestamp(char *, struct timeval *);
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce); extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
extern void tailsprintf(char *f, const char *fmt, ...); extern void tailsprintf(char *f, const char *fmt, ...);
extern void wlogprint(const char *f, ...); extern void wlogprint(const char *f, ...);
extern int curses_int(const char *query); extern int curses_int(const char *query);

Loading…
Cancel
Save