RandomX: added huge-pages-jit config parameter

Set to false by default, gives 0.2% boost on Ryzen 7 3700X with 16 threads, but hashrate might be unstable on Ryzen between launches. Use with caution.
This commit is contained in:
SChernykh 2020-10-07 17:42:55 +02:00
parent a8466a139c
commit 44dcded866
23 changed files with 62 additions and 26 deletions

View file

@ -43,7 +43,7 @@ struct randomx_dataset {
/* Global scope for C binding */
struct randomx_cache {
uint8_t* memory = nullptr;
randomx::JitCompiler* jit;
randomx::JitCompiler* jit = nullptr;
randomx::CacheInitializeFunc* initialize;
randomx::DatasetInitFunc* datasetInit;
randomx::SuperscalarProgram programs[RANDOMX_CACHE_MAX_ACCESSES];

View file

@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "crypto/randomx/reciprocal.h"
#include "crypto/randomx/virtual_memory.hpp"
void randomx_set_huge_pages_jit(bool) {}
namespace ARMV8A {
constexpr uint32_t B = 0x14000000;
@ -89,7 +91,7 @@ static size_t CalcDatasetItemSize()
constexpr uint32_t IntRegMap[8] = { 4, 5, 6, 7, 12, 13, 14, 15 };
JitCompilerA64::JitCompilerA64()
JitCompilerA64::JitCompilerA64(bool)
: code((uint8_t*) allocExecutableMemory(CodeSize + CalcDatasetItemSize()))
, literalPos(ImulRcpLiteralsEnd)
, num32bitLiterals(0)

View file

@ -46,7 +46,7 @@ namespace randomx {
class JitCompilerA64 {
public:
JitCompilerA64();
explicit JitCompilerA64(bool);
~JitCompilerA64();
void prepare() {}

View file

@ -41,7 +41,7 @@ namespace randomx {
class JitCompilerFallback {
public:
JitCompilerFallback() {
explicit JitCompilerFallback(bool) {
throw std::runtime_error("JIT compilation is not supported on this platform");
}
void prepare() {}

View file

@ -49,6 +49,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# include <cpuid.h>
#endif
static bool hugePagesJIT = false;
void randomx_set_huge_pages_jit(bool hugePages)
{
hugePagesJIT = hugePages;
}
namespace randomx {
/*
@ -175,8 +182,9 @@ namespace randomx {
# endif
static std::atomic<size_t> codeOffset;
constexpr size_t codeOffsetIncrement = 59 * 64;
JitCompilerX86::JitCompilerX86() {
JitCompilerX86::JitCompilerX86(bool hugePagesEnable) {
BranchesWithin32B = xmrig::Cpu::info()->jccErratum();
int32_t info[4];
@ -186,9 +194,11 @@ namespace randomx {
cpuid(0x80000001, info);
hasXOP = ((info[2] & (1 << 11)) != 0);
allocatedCode = (uint8_t*)allocExecutableMemory(CodeSize * 2);
allocatedCode = (uint8_t*)allocExecutableMemory(CodeSize * 2, hugePagesJIT && hugePagesEnable);
// Shift code base address to improve caching - all threads will use different L2/L3 cache sets
code = allocatedCode + (codeOffset.fetch_add(59 * 64) % CodeSize);
code = allocatedCode + (codeOffset.fetch_add(codeOffsetIncrement) % CodeSize);
memcpy(code, codePrologue, prologueSize);
if (hasXOP) {
memcpy(code + prologueSize, codeLoopLoadXOP, loopLoadXOPSize);
@ -207,6 +217,7 @@ namespace randomx {
}
JitCompilerX86::~JitCompilerX86() {
codeOffset.fetch_sub(codeOffsetIncrement);
freePagedMemory(allocatedCode, CodeSize);
}

View file

@ -47,7 +47,7 @@ namespace randomx {
class JitCompilerX86 {
public:
JitCompilerX86();
explicit JitCompilerX86(bool hugePagesEnable);
~JitCompilerX86();
void prepare();
void generateProgram(Program&, ProgramConfiguration&, uint32_t);

View file

@ -381,7 +381,7 @@ extern "C" {
break;
case RANDOMX_FLAG_JIT:
cache->jit = new randomx::JitCompiler();
cache->jit = new randomx::JitCompiler(false);
cache->initialize = &randomx::initCacheCompile;
cache->datasetInit = cache->jit->getDatasetInitFunc();
cache->memory = memory;

View file

@ -169,6 +169,7 @@ void randomx_apply_config(const T& config)
}
void randomx_set_scratchpad_prefetch_mode(int mode);
void randomx_set_huge_pages_jit(bool hugePages);
#if defined(__cplusplus)
extern "C" {

View file

@ -33,8 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "crypto/randomx/virtual_memory.hpp"
void* allocExecutableMemory(std::size_t bytes) {
void *mem = xmrig::VirtualMemory::allocateExecutableMemory(bytes);
void* allocExecutableMemory(std::size_t bytes, bool hugePages) {
void *mem = xmrig::VirtualMemory::allocateExecutableMemory(bytes, hugePages);
if (mem == nullptr) {
throw std::runtime_error("Failed to allocate executable memory");
}

View file

@ -30,6 +30,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstddef>
void* allocExecutableMemory(std::size_t);
void* allocExecutableMemory(std::size_t, bool);
void* allocLargePagesMemory(std::size_t);
void freePagedMemory(void*, std::size_t);

View file

@ -58,7 +58,7 @@ namespace randomx {
protected:
void execute();
JitCompiler compiler;
JitCompiler compiler{ true };
};
using CompiledVmDefault = CompiledVm<1>;