Backport changes from xmrig-aeon.

This commit is contained in:
XMRig 2017-04-30 02:56:47 +03:00
parent 3de7983826
commit caf7cda1d5
4 changed files with 31 additions and 67 deletions

View file

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
#include <mm_malloc.h>
#ifndef BUILD_TEST
# include "xmrig.h"
@ -35,7 +36,6 @@
#include "crypto/c_skein.h"
#include "cryptonight.h"
#include "options.h"
#include "utils/applog.h"
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() {
char output[32];
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) malloc(sizeof(struct cryptonight_ctx));
ctx->memory = (uint8_t *) malloc(MEMORY);
struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16);
ctx->memory = (uint8_t *) _mm_malloc(MEMORY, 16);
cryptonight_hash_ctx(test_input, sizeof(test_input), output, ctx);
free(ctx->memory);
free(ctx);
_mm_free(ctx->memory);
_mm_free(ctx);
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
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 n = *nonceptr - 1;
const uint32_t first_nonce = n + 1;
do {
*nonceptr = ++n;
cryptonight_hash_ctx(blob, blob_size, hash, ctx);
(*hashes_done)++;
if (unlikely(hash[7] < target)) {
*hashes_done = n - first_nonce + 1;
return true;
return 1;
}
} 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;
}
#endif

View file

@ -329,18 +329,11 @@ bool stratum_authorize(struct stratum_ctx *sctx, const char *user, const char *p
return false;
}
login_decode(sctx, val);
job(sctx, json_object_get(result, "job"));
// json_t *job = json_object_get(result, "job");
//pthread_mutex_lock(&sctx->work_lock);
//if (job) {
// job_decode(sctx, job);
//}
//pthread_mutex_unlock(&sctx->work_lock);
if (login_decode(sctx, val) && job(sctx, json_object_get(result, "job"))) {
pthread_mutex_lock(&sctx->sock_lock);
sctx->ready = true;
pthread_mutex_unlock(&sctx->sock_lock);
}
json_decref(val);
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));
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"));
if (!s) {
applog(LOG_ERR, "JSON invalid status");

View file

@ -93,7 +93,7 @@ const char * persistent_memory_allocate() {
persistent_memory = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
if (!persistent_memory) {
persistent_memory = _mm_malloc(size, 4096);
persistent_memory = _mm_malloc(size, 16);
}
else {
persistent_memory_flags |= MEMORY_HUGEPAGES_ENABLED;

53
xmrig.c
View file

@ -70,14 +70,6 @@ static bool g_want_donate = false;
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
* @param dest
@ -149,7 +141,6 @@ static bool submit_upstream_work(struct work *work) {
return false;
}
return true;
}
@ -164,7 +155,6 @@ static void workio_cmd_free(struct workio_cmd *wc) {
return;
}
work_free(wc->work);
free(wc->work);
memset(wc, 0, sizeof(*wc)); /* poison */
@ -265,7 +255,7 @@ static bool should_pause(int thr_id) {
*/
static void *miner_thread(void *userdata) {
struct thr_info *mythr = userdata;
int thr_id = mythr->id;
const int thr_id = mythr->id;
struct work work = { { 0 } };
uint32_t max_nonce;
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);
}
uint32_t *nonceptr = (uint32_t*) (((char*)work.blob) + 39);
uint32_t *nonceptr = NULL;
uint32_t hash[8] __attribute__((aligned(32)));
while (1) {
unsigned long hashes_done;
struct timeval tv_start;
int64_t max64;
int rc;
if (should_pause(thr_id)) {
sleep(1);
continue;
@ -292,46 +277,38 @@ static void *miner_thread(void *userdata) {
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)) {
work_free(&work);
if (memcmp(work.job_id, stratum_ctx->g_work.job_id, 64)) {
work_copy(&work, &stratum_ctx->g_work);
nonceptr = (uint32_t*) (((char*) work.blob) + 39);
*nonceptr = 0xffffffffU / opt_n_threads * thr_id;
} else {
++(*nonceptr);
}
pthread_mutex_unlock(&stratum_ctx->work_lock);
work_restart[thr_id].restart = 0;
/* adjust max_nonce to meet target scan time */
max64 = LP_SCANTIME;
//max64 *= thr_hashrates[thr_id];
if (max64 <= 0) {
max64 = 0x40LL;
}
if (*nonceptr + max64 > end_nonce) {
if (*nonceptr + LP_SCANTIME > end_nonce) {
max_nonce = end_nonce;
} else {
max_nonce = *nonceptr + max64;
max_nonce = *nonceptr + LP_SCANTIME;
}
hashes_done = 0;
gettimeofday(&tv_start, NULL );
unsigned long hashes_done = 0;
struct timeval tv_start;
gettimeofday(&tv_start, NULL);
/* 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);
memcpy(work.hash, hash, 32);
/* if nonce found, submit work */
if (rc && !submit_work(mythr, &work)) {
if (!rc) {
continue;
}
memcpy(work.hash, hash, 32);
submit_work(mythr, &work);
++(*nonceptr);
}
tq_freeze(mythr->q);