Browse Source

Make postcalc_hash asynchronous as well.

nfactor-troky
Con Kolivas 14 years ago
parent
commit
a45c54aaf8
  1. 16
      cpu-miner.c
  2. 38
      findnonce.c
  3. 20
      findnonce.h
  4. 31
      miner.h

16
cpu-miner.c

@ -277,20 +277,6 @@ static struct option options[] = { @@ -277,20 +277,6 @@ static struct option options[] = {
{ "userpass", 1, NULL, 1002 },
};
struct work {
unsigned char data[128];
unsigned char hash1[64];
unsigned char midstate[32];
unsigned char target[32];
unsigned char hash[32];
uint32_t output[1];
uint32_t res_nonce;
uint32_t valid;
dev_blk_ctx blk;
};
static bool jobj_binary(const json_t *obj, const char *key,
void *buf, size_t buflen)
{
@ -964,7 +950,7 @@ static void *gpuminer_thread(void *userdata) @@ -964,7 +950,7 @@ static void *gpuminer_thread(void *userdata)
for (i = 0; i < 127; i++) {
if (res[i]) {
applog(LOG_INFO, "GPU %d found something?", gpu_from_thr_id(thr_id));
postcalc_hash(mythr, &work->blk, work, res[i]);
postcalc_hash_async(mythr, work, res[i]);
} else
break;
}

38
findnonce.c

@ -9,9 +9,12 @@ @@ -9,9 +9,12 @@
#include <stdio.h>
#include <inttypes.h>
#include <pthread.h>
#include <string.h>
#include "ocl.h"
#include "findnonce.h"
#include "miner.h"
const uint32_t SHA256_K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
@ -131,8 +134,21 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) { @@ -131,8 +134,21 @@ void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data) {
R(E, F, G, H, A, B, C, D, P(u+4), SHA256_K[u+4]); \
R(D, E, F, G, H, A, B, C, P(u+5), SHA256_K[u+5])
void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, uint32_t start)
struct pc_data {
struct thr_info *thr;
struct work work;
uint32_t start;
pthread_t pth;
};
static void *postcalc_hash(void *userdata)
{
struct pc_data *pcd = (struct pc_data *)userdata;
struct thr_info *thr = pcd->thr;
dev_blk_ctx *blk = &pcd->work.blk;
struct work *work = &pcd->work;
uint32_t start = pcd->start;
cl_uint A, B, C, D, E, F, G, H;
cl_uint W[16];
cl_uint nonce;
@ -185,4 +201,24 @@ void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, ui @@ -185,4 +201,24 @@ void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, ui
out:
if (unlikely(best_g == ~0))
applog(LOG_ERR, "No best_g found! Error in OpenCL code?");
free(pcd);
}
void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t start)
{
struct pc_data *pcd = malloc(sizeof(struct pc_data));
if (unlikely(!pcd)) {
applog(LOG_ERR, "Failed to malloc pc_data in postcalc_hash_async");
return;
}
pcd->thr = thr;
memcpy(&pcd->work, work, sizeof(struct work));
pcd->start = start;
if (pthread_create(&pcd->pth, NULL, postcalc_hash, (void *)pcd)) {
applog(LOG_ERR, "Failed to create postcalc_hash thread");
return;
}
pthread_detach(pcd->pth);
}

20
findnonce.h

@ -1,22 +1,10 @@ @@ -1,22 +1,10 @@
#ifdef __APPLE_CC__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#ifndef __FINDNONCE_H__
#define __FINDNONCE_H__
#include "miner.h"
#define MAXTHREADS (0xFFFFFFFF)
#define BUFFERSIZE (sizeof(uint32_t) * 128)
typedef struct {
cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
} dev_blk_ctx;
extern void precalc_hash(dev_blk_ctx *blk, uint32_t *state, uint32_t *data);
extern void postcalc_hash(struct thr_info *thr, dev_blk_ctx *blk, struct work *work, uint32_t start);
extern void postcalc_hash_async(struct thr_info *thr, struct work *work, uint32_t start);
#endif /*__FINDNONCE_H__*/

31
miner.h

@ -9,6 +9,11 @@ @@ -9,6 +9,11 @@
#include <pthread.h>
#include <jansson.h>
#include <curl/curl.h>
#ifdef __APPLE_CC__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#ifdef STDC_HEADERS
# include <stdlib.h>
@ -194,7 +199,31 @@ extern bool use_syslog; @@ -194,7 +199,31 @@ extern bool use_syslog;
extern struct thr_info *thr_info;
extern int longpoll_thr_id;
extern struct work_restart *work_restart;
struct work;
typedef struct {
cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
} dev_blk_ctx;
struct work {
unsigned char data[128];
unsigned char hash1[64];
unsigned char midstate[32];
unsigned char target[32];
unsigned char hash[32];
uint32_t output[1];
uint32_t res_nonce;
uint32_t valid;
dev_blk_ctx blk;
};
bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
extern void applog(int prio, const char *fmt, ...);

Loading…
Cancel
Save