Backport changes from xmrig-aeon.
This commit is contained in:
parent
3de7983826
commit
caf7cda1d5
4 changed files with 31 additions and 67 deletions
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <mm_malloc.h>
|
||||||
|
|
||||||
#ifndef BUILD_TEST
|
#ifndef BUILD_TEST
|
||||||
# include "xmrig.h"
|
# include "xmrig.h"
|
||||||
|
@ -35,7 +36,6 @@
|
||||||
#include "crypto/c_skein.h"
|
#include "crypto/c_skein.h"
|
||||||
#include "cryptonight.h"
|
#include "cryptonight.h"
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "utils/applog.h"
|
|
||||||
|
|
||||||
|
|
||||||
const static char test_input[76] = {
|
const static char test_input[76] = {
|
||||||
|
@ -68,13 +68,13 @@ void (*cryptonight_hash_ctx)(const void* input, size_t size, void* output, struc
|
||||||
static bool self_test() {
|
static bool self_test() {
|
||||||
char output[32];
|
char output[32];
|
||||||
|
|
||||||
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx));
|
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16);
|
||||||
ctx->memory = (uint8_t *) malloc(MEMORY);
|
ctx->memory = (uint8_t *) _mm_malloc(MEMORY, 16);
|
||||||
|
|
||||||
cryptonight_hash_ctx(test_input, sizeof(test_input), output, ctx);
|
cryptonight_hash_ctx(test_input, sizeof(test_input), output, ctx);
|
||||||
|
|
||||||
free(ctx->memory);
|
_mm_free(ctx->memory);
|
||||||
free(ctx);
|
_mm_free(ctx);
|
||||||
|
|
||||||
return memcmp(output, test_output, 32) == 0;
|
return memcmp(output, test_output, 32) == 0;
|
||||||
}
|
}
|
||||||
|
@ -139,20 +139,18 @@ void (* const extra_hashes[4])(const void *, size_t, char *) = {do_blake_hash, d
|
||||||
#ifndef BUILD_TEST
|
#ifndef BUILD_TEST
|
||||||
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) {
|
int scanhash_cryptonight(int thr_id, uint32_t *hash, uint32_t *restrict blob, size_t blob_size, uint32_t target, uint32_t max_nonce, unsigned long *restrict hashes_done, struct cryptonight_ctx *restrict ctx) {
|
||||||
uint32_t *nonceptr = (uint32_t*) (((char*) blob) + 39);
|
uint32_t *nonceptr = (uint32_t*) (((char*) blob) + 39);
|
||||||
uint32_t n = *nonceptr - 1;
|
|
||||||
const uint32_t first_nonce = n + 1;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
*nonceptr = ++n;
|
|
||||||
cryptonight_hash_ctx(blob, blob_size, hash, ctx);
|
cryptonight_hash_ctx(blob, blob_size, hash, ctx);
|
||||||
|
(*hashes_done)++;
|
||||||
|
|
||||||
if (unlikely(hash[7] < target)) {
|
if (unlikely(hash[7] < target)) {
|
||||||
*hashes_done = n - first_nonce + 1;
|
return 1;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
} while (likely((n <= max_nonce && !work_restart[thr_id].restart)));
|
|
||||||
|
|
||||||
*hashes_done = n - first_nonce + 1;
|
(*nonceptr)++;
|
||||||
|
} while (likely(((*nonceptr) < max_nonce && !work_restart[thr_id].restart)));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
21
stratum.c
21
stratum.c
|
@ -329,18 +329,11 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
login_decode(sctx, val);
|
if (login_decode(sctx, val) && job(sctx, json_object_get(result, "job"))) {
|
||||||
|
pthread_mutex_lock(&sctx->sock_lock);
|
||||||
job(sctx, json_object_get(result, "job"));
|
sctx->ready = true;
|
||||||
// json_t *job = json_object_get(result, "job");
|
pthread_mutex_unlock(&sctx->sock_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//pthread_mutex_lock(&sctx->work_lock);
|
|
||||||
//if (job) {
|
|
||||||
// job_decode(sctx, job);
|
|
||||||
//}
|
|
||||||
//pthread_mutex_unlock(&sctx->work_lock);
|
|
||||||
|
|
||||||
json_decref(val);
|
json_decref(val);
|
||||||
return true;
|
return true;
|
||||||
|
@ -609,10 +602,6 @@ static bool login_decode(struct stratum_ctx *sctx, const json_t *val) {
|
||||||
memset(&sctx->id, 0, sizeof(sctx->id));
|
memset(&sctx->id, 0, sizeof(sctx->id));
|
||||||
memcpy(&sctx->id, id, strlen(id));
|
memcpy(&sctx->id, id, strlen(id));
|
||||||
|
|
||||||
pthread_mutex_lock(&sctx->sock_lock);
|
|
||||||
sctx->ready = true;
|
|
||||||
pthread_mutex_unlock(&sctx->sock_lock);
|
|
||||||
|
|
||||||
const char *s = json_string_value(json_object_get(res, "status"));
|
const char *s = json_string_value(json_object_get(res, "status"));
|
||||||
if (!s) {
|
if (!s) {
|
||||||
applog(LOG_ERR, "JSON invalid status");
|
applog(LOG_ERR, "JSON invalid status");
|
||||||
|
|
|
@ -93,7 +93,7 @@ const char * persistent_memory_allocate() {
|
||||||
|
|
||||||
persistent_memory = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
|
persistent_memory = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||||
if (!persistent_memory) {
|
if (!persistent_memory) {
|
||||||
persistent_memory = _mm_malloc(size, 4096);
|
persistent_memory = _mm_malloc(size, 16);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
persistent_memory_flags |= MEMORY_HUGEPAGES_ENABLED;
|
persistent_memory_flags |= MEMORY_HUGEPAGES_ENABLED;
|
||||||
|
|
53
xmrig.c
53
xmrig.c
|
@ -70,14 +70,6 @@ static bool g_want_donate = false;
|
||||||
static void workio_cmd_free(struct workio_cmd *wc);
|
static void workio_cmd_free(struct workio_cmd *wc);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief work_free
|
|
||||||
* @param w
|
|
||||||
*/
|
|
||||||
static inline void work_free(struct work *w) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief work_copy
|
* @brief work_copy
|
||||||
* @param dest
|
* @param dest
|
||||||
|
@ -149,7 +141,6 @@ static bool submit_upstream_work(struct work *work) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +155,6 @@ static void workio_cmd_free(struct workio_cmd *wc) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
work_free(wc->work);
|
|
||||||
free(wc->work);
|
free(wc->work);
|
||||||
|
|
||||||
memset(wc, 0, sizeof(*wc)); /* poison */
|
memset(wc, 0, sizeof(*wc)); /* poison */
|
||||||
|
@ -265,7 +255,7 @@ static bool should_pause(int thr_id) {
|
||||||
*/
|
*/
|
||||||
static void *miner_thread(void *userdata) {
|
static void *miner_thread(void *userdata) {
|
||||||
struct thr_info *mythr = userdata;
|
struct thr_info *mythr = userdata;
|
||||||
int thr_id = mythr->id;
|
const int thr_id = mythr->id;
|
||||||
struct work work = { { 0 } };
|
struct work work = { { 0 } };
|
||||||
uint32_t max_nonce;
|
uint32_t max_nonce;
|
||||||
uint32_t end_nonce = 0xffffffffU / opt_n_threads * (thr_id + 1) - 0x20;
|
uint32_t end_nonce = 0xffffffffU / opt_n_threads * (thr_id + 1) - 0x20;
|
||||||
|
@ -276,15 +266,10 @@ static void *miner_thread(void *userdata) {
|
||||||
affine_to_cpu_mask(thr_id, (unsigned long) opt_affinity);
|
affine_to_cpu_mask(thr_id, (unsigned long) opt_affinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t *nonceptr = (uint32_t*) (((char*)work.blob) + 39);
|
uint32_t *nonceptr = NULL;
|
||||||
uint32_t hash[8] __attribute__((aligned(32)));
|
uint32_t hash[8] __attribute__((aligned(32)));
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
unsigned long hashes_done;
|
|
||||||
struct timeval tv_start;
|
|
||||||
int64_t max64;
|
|
||||||
int rc;
|
|
||||||
|
|
||||||
if (should_pause(thr_id)) {
|
if (should_pause(thr_id)) {
|
||||||
sleep(1);
|
sleep(1);
|
||||||
continue;
|
continue;
|
||||||
|
@ -292,46 +277,38 @@ static void *miner_thread(void *userdata) {
|
||||||
|
|
||||||
pthread_mutex_lock(&stratum_ctx->work_lock);
|
pthread_mutex_lock(&stratum_ctx->work_lock);
|
||||||
|
|
||||||
if (memcmp(work.blob, stratum_ctx->g_work.blob, 39) || memcmp(((uint8_t*) work.blob) + 43, ((uint8_t*) stratum_ctx->g_work.blob) + 43, 33)) {
|
if (memcmp(work.job_id, stratum_ctx->g_work.job_id, 64)) {
|
||||||
work_free(&work);
|
|
||||||
work_copy(&work, &stratum_ctx->g_work);
|
work_copy(&work, &stratum_ctx->g_work);
|
||||||
nonceptr = (uint32_t*) (((char*) work.blob) + 39);
|
nonceptr = (uint32_t*) (((char*) work.blob) + 39);
|
||||||
*nonceptr = 0xffffffffU / opt_n_threads * thr_id;
|
*nonceptr = 0xffffffffU / opt_n_threads * thr_id;
|
||||||
} else {
|
|
||||||
++(*nonceptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&stratum_ctx->work_lock);
|
pthread_mutex_unlock(&stratum_ctx->work_lock);
|
||||||
|
|
||||||
work_restart[thr_id].restart = 0;
|
work_restart[thr_id].restart = 0;
|
||||||
|
|
||||||
/* adjust max_nonce to meet target scan time */
|
if (*nonceptr + LP_SCANTIME > end_nonce) {
|
||||||
max64 = LP_SCANTIME;
|
|
||||||
|
|
||||||
//max64 *= thr_hashrates[thr_id];
|
|
||||||
if (max64 <= 0) {
|
|
||||||
max64 = 0x40LL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*nonceptr + max64 > end_nonce) {
|
|
||||||
max_nonce = end_nonce;
|
max_nonce = end_nonce;
|
||||||
} else {
|
} else {
|
||||||
max_nonce = *nonceptr + max64;
|
max_nonce = *nonceptr + LP_SCANTIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashes_done = 0;
|
unsigned long hashes_done = 0;
|
||||||
gettimeofday(&tv_start, NULL );
|
|
||||||
|
struct timeval tv_start;
|
||||||
|
gettimeofday(&tv_start, NULL);
|
||||||
|
|
||||||
/* scan nonces for a proof-of-work hash */
|
/* scan nonces for a proof-of-work hash */
|
||||||
rc = scanhash_cryptonight(thr_id, hash, work.blob, work.blob_size, work.target, max_nonce, &hashes_done, persistentctx);
|
const int rc = scanhash_cryptonight(thr_id, hash, work.blob, work.blob_size, work.target, max_nonce, &hashes_done, persistentctx);
|
||||||
stats_add_hashes(thr_id, &tv_start, hashes_done);
|
stats_add_hashes(thr_id, &tv_start, hashes_done);
|
||||||
|
|
||||||
memcpy(work.hash, hash, 32);
|
if (!rc) {
|
||||||
|
|
||||||
/* if nonce found, submit work */
|
|
||||||
if (rc && !submit_work(mythr, &work)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(work.hash, hash, 32);
|
||||||
|
submit_work(mythr, &work);
|
||||||
|
++(*nonceptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
tq_freeze(mythr->q);
|
tq_freeze(mythr->q);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue