diff --git a/src/Cpu.cpp b/src/Cpu.cpp index eba993b37..f8fb092ca 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0; int Cpu::m_totalThreads = 0; -int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage) +int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage) { if (m_totalThreads == 1) { return 1; @@ -54,7 +54,18 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage) } int count = 0; - const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1); + int size = 2048; + + if (algo == xmrig::CRYPTONIGHT_LITE) { + size = 1024; + } + else if (algo == xmrig::CRYPTONIGHT_HEAVY) { + size = 4096; + } + + if (doubleHash) { + size *= 2; + } if (cache) { count = cache / size; diff --git a/src/Cpu.h b/src/Cpu.h index 9444274d2..118c7b7d3 100644 --- a/src/Cpu.h +++ b/src/Cpu.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 XMRig , * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,9 @@ #include +#include "xmrig.h" + + class Cpu { public: @@ -37,7 +40,7 @@ public: BMI2 = 4 }; - static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage); + static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage); static void init(); static void setAffinity(int id, uint64_t mask); diff --git a/src/Mem.cpp b/src/Mem.cpp index f5da7865c..9de79dbd5 100644 --- a/src/Mem.cpp +++ b/src/Mem.cpp @@ -27,8 +27,8 @@ #include "crypto/CryptoNight.h" +#include "crypto/CryptoNight_constants.h" #include "Mem.h" -#include "xmrig.h" bool Mem::m_doubleHash = false; @@ -48,10 +48,13 @@ cryptonight_ctx *Mem::create(int threadId) } # endif - cryptonight_ctx *ctx = reinterpret_cast(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]); + const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory() + : xmrig::cn_select_memory(); + + cryptonight_ctx *ctx = reinterpret_cast(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]); const int ratio = m_doubleHash ? 2 : 1; - ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)]; + ctx->memory = &m_memory[size * (threadId * ratio + 1)]; return ctx; } diff --git a/src/Mem.h b/src/Mem.h index 18914d688..73947b42d 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -30,6 +30,9 @@ #include +#include "xmrig.h" + + struct cryptonight_ctx; @@ -42,7 +45,7 @@ public: Lock = 4 }; - static bool allocate(int algo, int threads, bool doubleHash, bool enabled); + static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled); static cryptonight_ctx *create(int threadId); static void *calloc(size_t num, size_t size); static void release(); diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 7978d241f..0dd833d7f 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -40,7 +40,7 @@ #include "xmrig.h" -bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) +bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -49,6 +49,10 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1; m_size = MONERO_MEMORY * (threads * ratio + 1); + if (algo == xmrig::CRYPTONIGHT_HEAVY) { + m_size *= 2; + } + if (!enabled) { m_memory = static_cast(_mm_malloc(m_size, 16)); return true; diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index 6cc0a6eee..ec30e3e82 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -145,7 +145,7 @@ static BOOL TrySetLockPagesPrivilege() { } -bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) +bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -154,6 +154,10 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1; m_size = MONERO_MEMORY * (threads * ratio + 1); + if (algo == xmrig::CRYPTONIGHT_HEAVY) { + m_size *= 2; + } + if (!enabled) { m_memory = static_cast(_mm_malloc(m_size, 16)); return true; diff --git a/src/workers/SingleWorker.cpp b/src/workers/SingleWorker.cpp index 2ff356c88..5757ef77e 100644 --- a/src/workers/SingleWorker.cpp +++ b/src/workers/SingleWorker.cpp @@ -116,7 +116,7 @@ bool SingleWorker::selfTest() } # endif - return false; + return true; }