From c96b64576cfa9ee21369dd71fd20fdd4adb3dc02 Mon Sep 17 00:00:00 2001 From: BenDroid Date: Thu, 30 Nov 2017 22:11:58 +0100 Subject: [PATCH] Revert "Integrated thread based double hash mode" This reverts commit e264c5f8b55109abe9c0e24fc33737c532c956dd. --- index.html | 2 +- src/Mem.cpp | 63 ++++++++++++++++++++++++---------- src/Mem.h | 10 ++++-- src/Mem_unix.cpp | 30 ++++++---------- src/Mem_win.cpp | 20 +++-------- src/Options.cpp | 24 +++---------- src/Options.h | 3 -- src/Summary.cpp | 19 +++-------- src/cc/CCClient.cpp | 2 +- src/crypto/CryptoNight.cpp | 64 ++++++++++++++--------------------- src/crypto/CryptoNight.h | 4 +-- src/crypto/CryptoNight_test.h | 2 ++ src/log/ConsoleLog.cpp | 27 +++++++-------- src/workers/DoubleWorker.cpp | 7 ++-- src/workers/SingleWorker.cpp | 10 +++--- src/workers/Workers.cpp | 4 +-- src/workers/Workers.h | 2 +- 17 files changed, 133 insertions(+), 160 deletions(-) diff --git a/index.html b/index.html index 3a42983d..88048abf 100644 --- a/index.html +++ b/index.html @@ -282,7 +282,7 @@ function isOnline(lastStatus) { Algo Hashrate - Hashrate 1m + Hashrate 5m Hashrate 60m Hashrate Highest diff --git a/src/Mem.cpp b/src/Mem.cpp index 05a2f31b..4437c673 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -30,29 +30,58 @@ #include "Options.h" -bool Mem::m_doubleHash = false; -int Mem::m_algo = 0; -int Mem::m_flags = 0; -int Mem::m_threads = 0; -size_t Mem::m_memorySize = 0; -uint8_t *Mem::m_memory = nullptr; -int64_t Mem::m_doubleHashThreadMask = -1L; +bool Mem::m_doubleHash = false; +int Mem::m_algo = 0; +int Mem::m_flags = 0; +int Mem::m_threads = 0; +size_t Mem::m_offset = 0; +uint8_t *Mem::m_memory = nullptr; + cryptonight_ctx *Mem::create(int threadId) { - size_t scratchPadSize = m_algo == Options::ALGO_CRYPTONIGHT ? MEMORY : MEMORY_LITE; - - size_t offset = 0; - for (int i=0; i < threadId; i++) { - offset += sizeof(cryptonight_ctx); - offset += isDoubleHash(i) ? scratchPadSize*2 : scratchPadSize; +# ifndef XMRIG_NO_AEON + if (m_algo == Options::ALGO_CRYPTONIGHT_LITE) { + return createLite(threadId); } +# endif - auto* ctx = reinterpret_cast(&m_memory[offset]); + cryptonight_ctx *ctx = reinterpret_cast(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); - size_t memOffset = offset+sizeof(cryptonight_ctx); - - ctx->memory = &m_memory[memOffset]; + const int ratio = m_doubleHash ? 2 : 1; + ctx->memory = &m_memory[MEMORY * (threadId * ratio + 1)]; return ctx; } + + + +void *Mem::calloc(size_t num, size_t size) +{ + void *mem = &m_memory[m_offset]; + m_offset += (num * size); + + memset(mem, 0, num * size); + + return mem; +} + + +#ifndef XMRIG_NO_AEON +cryptonight_ctx *Mem::createLite(int threadId) { + cryptonight_ctx *ctx; + + if (!m_doubleHash) { + const size_t offset = MEMORY * (threadId + 1); + + ctx = reinterpret_cast(&m_memory[offset + MEMORY_LITE]); + ctx->memory = &m_memory[offset]; + return ctx; + } + + ctx = reinterpret_cast(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); + ctx->memory = &m_memory[MEMORY * (threadId + 1)]; + + return ctx; +} +#endif diff --git a/src/Mem.h b/src/Mem.h index 1325907f..dcd3a970 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -45,9 +45,10 @@ public: static bool allocate(const Options* options); static cryptonight_ctx *create(int threadId); + static void *calloc(size_t num, size_t size); static void release(); - static inline bool isDoubleHash(int threadId) { return m_doubleHash && (m_doubleHashThreadMask == -1L || ((m_doubleHashThreadMask >> threadId) & 1)); } + static inline bool isDoubleHash() { return m_doubleHash; } static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } static inline bool isHugepagesEnabled() { return (m_flags & HugepagesEnabled) != 0; } static inline int flags() { return m_flags; } @@ -58,9 +59,12 @@ private: static int m_algo; static int m_flags; static int m_threads; - static int64_t m_doubleHashThreadMask; - static size_t m_memorySize; + static size_t m_offset; VAR_ALIGN(16, static uint8_t *m_memory); + +# ifndef XMRIG_NO_AEON + static cryptonight_ctx *createLite(int threadId); +# endif }; diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index e119f720..d48c2833 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -38,22 +38,12 @@ bool Mem::allocate(const Options* options) m_algo = options->algo(); m_threads = options->threads(); m_doubleHash = options->doubleHash(); - m_doubleHashThreadMask = options->doubleHashThreadMask(); - m_memorySize = 0; - size_t scratchPadSize = m_algo == Options::ALGO_CRYPTONIGHT ? MEMORY : MEMORY_LITE; - for (int i=0; i < m_threads; i++) { - m_memorySize += sizeof(cryptonight_ctx); - - if (isDoubleHash(i)) { - m_memorySize += scratchPadSize*2; - } else { - m_memorySize += scratchPadSize; - } - } + const int ratio = (m_doubleHash && m_algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; + const size_t size = MEMORY * (m_threads * ratio + 1); if (!options->hugePages()) { - m_memory = static_cast(_mm_malloc(m_memorySize, 16)); + m_memory = static_cast(_mm_malloc(size, 16)); return true; } @@ -64,20 +54,20 @@ bool Mem::allocate(const Options* options) # elif defined(__FreeBSD__) m_memory = static_cast(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0)); # else - m_memory = static_cast(mmap(0, m_memorySize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); + m_memory = static_cast(mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, 0, 0)); # endif if (m_memory == MAP_FAILED) { - m_memory = static_cast(_mm_malloc(m_memorySize, 16)); + m_memory = static_cast(_mm_malloc(size, 16)); return true; } m_flags |= HugepagesEnabled; - if (madvise(m_memory, m_memorySize, MADV_RANDOM | MADV_WILLNEED) != 0) { + if (madvise(m_memory, size, MADV_RANDOM | MADV_WILLNEED) != 0) { LOG_ERR("madvise failed"); } - if (mlock(m_memory, m_memorySize) == 0) { + if (mlock(m_memory, size) == 0) { m_flags |= Lock; } @@ -87,12 +77,14 @@ bool Mem::allocate(const Options* options) void Mem::release() { + const int size = MEMORY * (m_threads + 1); + if (m_flags & HugepagesEnabled) { if (m_flags & Lock) { - munlock(m_memory, m_memorySize); + munlock(m_memory, size); } - munmap(m_memory, m_memorySize); + munmap(m_memory, size); } else { _mm_free(m_memory); diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index ad9744e9..9348c0dd 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -149,22 +149,12 @@ bool Mem::allocate(const Options* options) m_algo = options->algo(); m_threads = options->threads(); m_doubleHash = options->doubleHash(); - m_doubleHashThreadMask = options->doubleHashThreadMask(); - m_memorySize = 0; - size_t scratchPadSize = m_algo == Options::ALGO_CRYPTONIGHT ? MEMORY : MEMORY_LITE; - for (int i=0; i < m_threads; i++) { - m_memorySize += sizeof(cryptonight_ctx); - - if (isDoubleHash(i)) { - m_memorySize += scratchPadSize*2; - } else { - m_memorySize += scratchPadSize; - } - } + const int ratio = (m_doubleHash && m_algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; + const size_t size = MEMORY * (m_threads * ratio + 1); if (!options->hugePages()) { - m_memory = static_cast(_mm_malloc(m_memorySize, 16)); + m_memory = static_cast(_mm_malloc(size, 16)); return true; } @@ -172,9 +162,9 @@ bool Mem::allocate(const Options* options) m_flags |= HugepagesAvailable; } - m_memory = static_cast(VirtualAlloc(NULL, m_memorySize, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); + m_memory = static_cast(VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE)); if (!m_memory) { - m_memory = static_cast(_mm_malloc(m_memorySize, 16)); + m_memory = static_cast(_mm_malloc(size, 16)); } else { m_flags |= HugepagesEnabled; diff --git a/src/Options.cpp b/src/Options.cpp index 61f2f3f3..0a6909e9 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -70,7 +70,6 @@ Options:\n" -k, --keepalive send keepalived for prevent timeout (need pool support)\n\ -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ - --doublehash-thread-mask for av=2/4 only, limits doublehash to given threads (mask), (default: all threads)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-huge-pages disable huge pages support\n\ @@ -159,7 +158,6 @@ static struct option const options[] = { { "cc-client-config-folder", 1, nullptr, 4009 }, { "cc-custom-dashboard", 1, nullptr, 4010 }, { "daemonized", 0, nullptr, 4011 }, - { "doublehash-thread-mask", 1, nullptr, 4013 }, { 0, 0, 0, 0 } }; @@ -182,7 +180,6 @@ static struct option const config_options[] = { { "syslog", 0, nullptr, 'S' }, { "threads", 1, nullptr, 't' }, { "user-agent", 1, nullptr, 1008 }, - { "doublehash-thread-mask", 1, nullptr, 4013 }, { 0, 0, 0, 0 } }; @@ -284,8 +281,7 @@ Options::Options(int argc, char **argv) : m_threads(0), m_ccUpdateInterval(10), m_ccPort(0), - m_affinity(-1L), - m_doubleHashThreadMask(-1L) + m_affinity(-1L) { m_pools.push_back(new Url()); @@ -532,14 +528,9 @@ bool Options::parseArg(int key, const char *arg) break; case 1020: { /* --cpu-affinity */ - const char *p = strstr(arg, "0x"); - return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); - } - - case 4013: { /* --doublehash-thread-mask */ - const char *p = strstr(arg, "0x"); - return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); - } + const char *p = strstr(arg, "0x"); + return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); + } case 1008: /* --user-agent */ free(m_userAgent); @@ -643,7 +634,6 @@ bool Options::parseArg(int key, uint64_t arg) m_ccPort = (int) arg; } break; - case 4012: /* --cc-update-interval-s */ if (arg < 1) { showUsage(1); @@ -652,12 +642,6 @@ bool Options::parseArg(int key, uint64_t arg) m_ccUpdateInterval = (int) arg; break; - - case 4013: /* --doublehash-thread-mask */ - if (arg) { - m_doubleHashThreadMask = arg; - } - break; default: break; } diff --git a/src/Options.h b/src/Options.h index 5402af32..ad0ab60f 100644 --- a/src/Options.h +++ b/src/Options.h @@ -88,8 +88,6 @@ public: inline int ccUpdateInterval() const { return m_ccUpdateInterval; } inline int ccPort() const { return m_ccPort; } inline int64_t affinity() const { return m_affinity; } - inline int64_t doubleHashThreadMask() const { return m_doubleHashThreadMask; } - inline void setColors(bool colors) { m_colors = colors; } inline static void release() { delete m_self; } @@ -157,7 +155,6 @@ private: int m_ccUpdateInterval; int m_ccPort; int64_t m_affinity; - int64_t m_doubleHashThreadMask; std::vector m_pools; }; diff --git a/src/Summary.cpp b/src/Summary.cpp index 503bb67e..c47eec9c 100644 --- a/src/Summary.cpp +++ b/src/Summary.cpp @@ -91,30 +91,21 @@ static void print_cpu() static void print_threads() { - char dhtMaskBuf[64]; - if (Options::i()->doubleHashThreadMask() != -1L) { - snprintf(dhtMaskBuf, 64, ", doubleHashThreadMask=0x%" PRIX64, Options::i()->doubleHashThreadMask()); - } - else { - dhtMaskBuf[0] = '\0'; - } - - char affBuf[32]; + char buf[32]; if (Options::i()->affinity() != -1L) { - snprintf(affBuf, 32, ", affinity=0x%" PRIX64, Options::i()->affinity()); + snprintf(buf, 32, ", affinity=0x%" PRIX64, Options::i()->affinity()); } else { - affBuf[0] = '\0'; + buf[0] = '\0'; } - Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s%s", + Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s", Options::i()->threads(), Options::i()->algoName(), Options::i()->algoVariant(), Options::i()->colors() && Options::i()->donateLevel() == 0 ? "\x1B[01;31m" : "", Options::i()->donateLevel(), - affBuf, - dhtMaskBuf); + buf); } diff --git a/src/cc/CCClient.cpp b/src/cc/CCClient.cpp index a61cf36b..30c672bd 100644 --- a/src/cc/CCClient.cpp +++ b/src/cc/CCClient.cpp @@ -77,7 +77,7 @@ CCClient::CCClient(Options* options, uv_async_t* async) m_clientStatus.setHugepagesEnabled(Mem::isHugepagesEnabled()); m_clientStatus.setHugepages(Mem::isHugepagesAvailable()); - m_clientStatus.setDoubleHashMode(m_options->doubleHash()); + m_clientStatus.setDoubleHashMode(Mem::isDoubleHash()); m_clientStatus.setVersion(Version::string()); m_clientStatus.setCpuBrand(Cpu::brand()); diff --git a/src/crypto/CryptoNight.cpp b/src/crypto/CryptoNight.cpp index e1c774f0..c4e56678 100644 --- a/src/crypto/CryptoNight.cpp +++ b/src/crypto/CryptoNight.cpp @@ -30,8 +30,7 @@ #include "Options.h" -void (*cryptonight_hash_ctx_s)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr; -void (*cryptonight_hash_ctx_d)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr; +void (*cryptonight_hash_ctx)(const void *input, size_t size, void *output, cryptonight_ctx *ctx) = nullptr; static void cryptonight_av1_aesni(const void *input, size_t size, void *output, struct cryptonight_ctx *ctx) { @@ -94,43 +93,40 @@ void (*cryptonight_variations[4])(const void *input, size_t size, void *output, #endif -void CryptoNight::hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx) +bool CryptoNight::hash(const Job &job, JobResult &result, cryptonight_ctx *ctx) { - cryptonight_hash_ctx_s(input, size, output, ctx); + cryptonight_hash_ctx(job.blob(), job.size(), result.result, ctx); + + return *reinterpret_cast(result.result + 24) < job.target(); } -void CryptoNight::hashDouble(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx) -{ - cryptonight_hash_ctx_d(input, size, output, ctx); -} bool CryptoNight::init(int algo, int variant) { - if (variant < 1 || variant > 4) - { + if (variant < 1 || variant > 4) { return false; } - int index = 0; +# ifndef XMRIG_NO_AEON + const int index = algo == Options::ALGO_CRYPTONIGHT_LITE ? (variant + 3) : (variant - 1); +# else + const int index = variant - 1; +# endif - if (variant == 3 || variant == 4) - { - index = 4; - } - - if (algo == Options::ALGO_CRYPTONIGHT_LITE) { - index += 4; - } - - cryptonight_hash_ctx_s = cryptonight_variations[index]; - cryptonight_hash_ctx_d = cryptonight_variations[index+1]; + cryptonight_hash_ctx = cryptonight_variations[index]; return selfTest(algo); } -bool CryptoNight::selfTest(int algo) + +void CryptoNight::hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx) { - if (cryptonight_hash_ctx_d == nullptr) { + cryptonight_hash_ctx(input, size, output, ctx); +} + + +bool CryptoNight::selfTest(int algo) { + if (cryptonight_hash_ctx == nullptr) { return false; } @@ -139,22 +135,14 @@ bool CryptoNight::selfTest(int algo) struct cryptonight_ctx *ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16); ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16); - cryptonight_hash_ctx_d(test_input, 76, output, ctx); + cryptonight_hash_ctx(test_input, 76, output, ctx); _mm_free(ctx->memory); _mm_free(ctx); - bool resultSingle = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 32) == 0; - - ctx = (struct cryptonight_ctx*) _mm_malloc(sizeof(struct cryptonight_ctx), 16); - ctx->memory = (uint8_t *) _mm_malloc(MEMORY * 2, 16); - - cryptonight_hash_ctx_d(test_input, 76, output, ctx); - - _mm_free(ctx->memory); - _mm_free(ctx); - - bool resultDouble = memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, 64) == 0; - - return resultSingle && resultDouble; +# ifndef XMRIG_NO_AEON + return memcmp(output, algo == Options::ALGO_CRYPTONIGHT_LITE ? test_output1 : test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0; +# else + return memcmp(output, test_output0, (Options::i()->doubleHash() ? 64 : 32)) == 0; +# endif } diff --git a/src/crypto/CryptoNight.h b/src/crypto/CryptoNight.h index f562b21c..64fc0fd1 100644 --- a/src/crypto/CryptoNight.h +++ b/src/crypto/CryptoNight.h @@ -50,9 +50,9 @@ class JobResult; class CryptoNight { public: - static void hash(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx); + static bool hash(const Job &job, JobResult &result, cryptonight_ctx *ctx); static bool init(int algo, int variant); - static void hashDouble(const uint8_t* input, size_t size, uint8_t* output, cryptonight_ctx* ctx); + static void hash(const uint8_t *input, size_t size, uint8_t *output, cryptonight_ctx *ctx); private: static bool selfTest(int algo); diff --git a/src/crypto/CryptoNight_test.h b/src/crypto/CryptoNight_test.h index 3da686a0..b2985379 100644 --- a/src/crypto/CryptoNight_test.h +++ b/src/crypto/CryptoNight_test.h @@ -47,12 +47,14 @@ const static uint8_t test_output0[64] = { }; +#ifndef XMRIG_NO_AEON const static uint8_t test_output1[64] = { 0x28, 0xA2, 0x2B, 0xAD, 0x3F, 0x93, 0xD1, 0x40, 0x8F, 0xCA, 0x47, 0x2E, 0xB5, 0xAD, 0x1C, 0xBE, 0x75, 0xF2, 0x1D, 0x05, 0x3C, 0x8C, 0xE5, 0xB3, 0xAF, 0x10, 0x5A, 0x57, 0x71, 0x3E, 0x21, 0xDD, 0x36, 0x95, 0xB4, 0xB5, 0x3B, 0xB0, 0x03, 0x58, 0xB0, 0xAD, 0x38, 0xDC, 0x16, 0x0F, 0xEB, 0x9E, 0x00, 0x4E, 0xEC, 0xE0, 0x9B, 0x83, 0xA7, 0x2E, 0xF6, 0xBA, 0x98, 0x64, 0xD3, 0x51, 0x0C, 0x88, }; +#endif #endif /* __CRYPTONIGHT_TEST_H__ */ diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index fbc988be..ef8516eb 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -28,8 +28,6 @@ #include #include -#include "Options.h" - #ifdef WIN32 # include # include @@ -41,18 +39,16 @@ ConsoleLog::ConsoleLog(bool colors) : - m_colors(colors), - m_stream(nullptr) + m_colors(colors), + m_stream(nullptr) { if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { - Options::i()->setColors(false); - m_colors = false; return; } uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL); m_uvBuf.base = m_buf; - m_stream = reinterpret_cast(&m_tty); + m_stream = reinterpret_cast(&m_tty); # ifdef WIN32 HANDLE handle = GetStdHandle(STD_INPUT_HANDLE); @@ -69,6 +65,10 @@ ConsoleLog::ConsoleLog(bool colors) : void ConsoleLog::message(int level, const char* fmt, va_list args) { + if (!isWritable()) { + return; + } + time_t now = time(nullptr); tm stime; @@ -113,7 +113,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) m_colors ? color : "", fmt, m_colors ? Log::kCL_N : "" - ); + ); print(args); } @@ -121,6 +121,10 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { + if (!isWritable()) { + return; + } + snprintf(m_fmt, sizeof(m_fmt) - 1, "%s%s\n", fmt, m_colors ? Log::kCL_N : ""); print(args); @@ -145,10 +149,5 @@ void ConsoleLog::print(va_list args) return; } - if (!isWritable()) { - fprintf(stdout, m_buf); - fflush(stdout); - } else { - uv_try_write(m_stream, &m_uvBuf, 1); - } + uv_try_write(m_stream, &m_uvBuf, 1); } diff --git a/src/workers/DoubleWorker.cpp b/src/workers/DoubleWorker.cpp index b8aa91ba..46d6f366 100644 --- a/src/workers/DoubleWorker.cpp +++ b/src/workers/DoubleWorker.cpp @@ -82,18 +82,17 @@ void DoubleWorker::start() } m_count += 2; - *Job::nonce(m_state->blob) = ++m_state->nonce1; *Job::nonce(m_state->blob + m_state->job.size()) = ++m_state->nonce2; - CryptoNight::hashDouble(m_state->blob, m_state->job.size(), m_hash, m_ctx); + CryptoNight::hash(m_state->blob, m_state->job.size(), m_hash, m_ctx); if (*reinterpret_cast(m_hash + 24) < m_state->job.target()) { - Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff()), m_id); + Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce1, m_hash, m_state->job.diff())); } if (*reinterpret_cast(m_hash + 32 + 24) < m_state->job.target()) { - Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce2, m_hash + 32, m_state->job.diff()), m_id); + Workers::submit(JobResult(m_state->job.poolId(), m_state->job.id(), m_state->nonce2, m_hash + 32, m_state->job.diff())); } std::this_thread::yield(); diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index 242936bf..ecb566f8 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -60,10 +60,8 @@ void SingleWorker::start() m_count++; *m_job.nonce() = ++m_result.nonce; - CryptoNight::hash(m_job.blob(), m_job.size(), m_result.result, m_ctx); - - if (*reinterpret_cast(m_result.result + 24) < m_job.target()) { - Workers::submit(m_result, m_id); + if (CryptoNight::hash(m_job, m_result, m_ctx)) { + Workers::submit(m_result); } std::this_thread::yield(); @@ -105,10 +103,10 @@ void SingleWorker::consumeJob() m_result = m_job; if (m_job.isNicehash()) { - m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / (m_threads * 2) * m_id); + m_result.nonce = (*m_job.nonce() & 0xff000000U) + (0xffffffU / m_threads * m_id); } else { - m_result.nonce = 0xffffffffU / (m_threads * 2) * m_id; + m_result.nonce = 0xffffffffU / m_threads * m_id; } } diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 3480e43c..81e073bc 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -140,7 +140,7 @@ void Workers::stop() } -void Workers::submit(const JobResult &result, int threadId) +void Workers::submit(const JobResult &result) { uv_mutex_lock(&m_mutex); m_queue.push_back(result); @@ -153,7 +153,7 @@ void Workers::submit(const JobResult &result, int threadId) void Workers::onReady(void *arg) { auto handle = static_cast(arg); - if (Mem::isDoubleHash(handle->threadId())) { + if (Mem::isDoubleHash()) { handle->setWorker(new DoubleWorker(handle)); } else { diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 22a2b376..e76d0a62 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -48,7 +48,7 @@ public: static void setJob(const Job &job); static void start(int64_t affinity, int priority); static void stop(); - static void submit(const JobResult &result, int threadId); + static void submit(const JobResult &result); static inline bool isEnabled() { return m_enabled; } static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }