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 @@ @@ -64,7 +64,6 @@
enum workio_commands {
WC_GET_WORK,
WC_SUBMIT_WORK,
};
struct workio_cmd {
@ -2737,11 +2736,8 @@ static void workio_cmd_free(struct workio_cmd *wc) @@ -2737,11 +2736,8 @@ static void workio_cmd_free(struct workio_cmd *wc)
return;
switch (wc->cmd) {
case WC_SUBMIT_WORK:
free_work(wc->work);
break;
default: /* do nothing */
break;
default: /* do nothing */
break;
}
memset(wc, 0, sizeof(*wc)); /* poison */
@ -3284,8 +3280,7 @@ static void check_solve(struct work *work) @@ -3284,8 +3280,7 @@ static void check_solve(struct work *work)
static void *submit_work_thread(void *userdata)
{
struct workio_cmd *wc = (struct workio_cmd *)userdata;
struct work *work = wc->work;
struct work *work = (struct work *)userdata;
struct pool *pool = work->pool;
bool resubmit = false;
struct curl_ent *ce;
@ -3374,25 +3369,9 @@ static void *submit_work_thread(void *userdata) @@ -3374,25 +3369,9 @@ static void *submit_work_thread(void *userdata)
}
push_curl_entry(ce, pool);
out:
workio_cmd_free(wc);
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 */
static struct pool *priority_pool(int choice)
{
@ -4482,9 +4461,6 @@ static void *workio_thread(void *userdata) @@ -4482,9 +4461,6 @@ static void *workio_thread(void *userdata)
case WC_GET_WORK:
ok = workio_get_work(wc);
break;
case WC_SUBMIT_WORK:
ok = workio_submit_work(wc);
break;
default:
ok = false;
break;
@ -5454,35 +5430,16 @@ out: @@ -5454,35 +5430,16 @@ out:
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;
/* 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;
}
struct work *work = copy_work(work_in);
pthread_t submit_thread;
wc->work = copy_work(work_in);
wc->cmd = WC_SUBMIT_WORK;
wc->thr = thr;
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");
/* send solution to workio 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;
if (unlikely(pthread_create(&submit_thread, NULL, submit_work_thread, (void *)work)))
quit(1, "Failed to create submit_work_thread");
}
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) @@ -5552,7 +5509,7 @@ static bool test_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
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;
gettimeofday(&tv_work_found, NULL);
@ -5566,9 +5523,9 @@ bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce) @@ -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 */
/* Side effect: sets work->data for us */
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)

6
driver-cpu.c

@ -75,7 +75,7 @@ static inline void affine_to_cpu(int __maybe_unused id, int __maybe_unused cpu) @@ -75,7 +75,7 @@ static inline void affine_to_cpu(int __maybe_unused id, int __maybe_unused cpu)
/* 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 int dev_from_id(int thr_id);
@ -831,9 +831,7 @@ CPUSearch: @@ -831,9 +831,7 @@ CPUSearch:
/* if nonce found, submit work */
if (unlikely(rc)) {
applog(LOG_DEBUG, "CPU %d found something?", dev_from_id(thr_id));
if (unlikely(!submit_work_sync(thr, work, NULL))) {
applog(LOG_ERR, "Failed to submit_work_sync in miner_thread %d", thr_id);
}
submit_work_async(work, NULL);
work->blk.nonce = last_nonce + 1;
goto CPUSearch;
}

6
driver-ztex.c

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

6
findnonce.c

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

2
miner.h

@ -1036,7 +1036,7 @@ struct modminer_fpga_state { @@ -1036,7 +1036,7 @@ struct modminer_fpga_state {
#endif
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 wlogprint(const char *f, ...);
extern int curses_int(const char *query);

Loading…
Cancel
Save