Make postcalc_hash asynchronous as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
diff --git a/cpu-miner.c b/cpu-miner.c
index 1369efb..1ea2fd0 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -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)
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;
}
diff --git a/findnonce.c b/findnonce.c
index 3c310fc..8434f7b 100644
--- a/findnonce.c
+++ b/findnonce.c
@@ -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) {
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
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);
}
diff --git a/findnonce.h b/findnonce.h
index 8c6b9af..7ca8f70 100644
--- a/findnonce.h
+++ b/findnonce.h
@@ -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__*/
diff --git a/miner.h b/miner.h
index 1b7ab1d..dfe5037 100644
--- a/miner.h
+++ b/miner.h
@@ -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;
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, ...);