Merge pull request #1823 from SChernykh/dev
RandomX: added parameter for scratchpad prefetch mode
This commit is contained in:
commit
0f09883429
7 changed files with 71 additions and 2 deletions
|
@ -21,7 +21,8 @@
|
|||
"rdmsr": true,
|
||||
"wrmsr": true,
|
||||
"cache_qos": false,
|
||||
"numa": true
|
||||
"numa": true,
|
||||
"scratchpad_prefetch_mode": 1
|
||||
},
|
||||
"cpu": {
|
||||
"enabled": true,
|
||||
|
|
|
@ -51,7 +51,12 @@ R"===(
|
|||
"randomx": {
|
||||
"init": -1,
|
||||
"mode": "auto",
|
||||
"numa": true
|
||||
"1gb-pages": false,
|
||||
"rdmsr": true,
|
||||
"wrmsr": true,
|
||||
"cache_qos": false,
|
||||
"numa": true,
|
||||
"scratchpad_prefetch_mode": 1
|
||||
},
|
||||
"cpu": {
|
||||
"enabled": true,
|
||||
|
|
|
@ -211,6 +211,13 @@ RandomX_ConfigurationBase::RandomX_ConfigurationBase()
|
|||
static uint32_t Log2(size_t value) { return (value > 1) ? (Log2(value / 2) + 1) : 0; }
|
||||
#endif
|
||||
|
||||
static int scratchpadPrefetchMode = 1;
|
||||
|
||||
void randomx_set_scratchpad_prefetch_mode(int mode)
|
||||
{
|
||||
scratchpadPrefetchMode = mode;
|
||||
}
|
||||
|
||||
void RandomX_ConfigurationBase::Apply()
|
||||
{
|
||||
const uint32_t ScratchpadL1Mask_Calculated = (ScratchpadL1_Size / sizeof(uint64_t) - 1) * 8;
|
||||
|
@ -240,6 +247,36 @@ void RandomX_ConfigurationBase::Apply()
|
|||
*(uint32_t*)(codePrefetchScratchpadTweaked + 4) = ScratchpadL3Mask64_Calculated;
|
||||
*(uint32_t*)(codePrefetchScratchpadTweaked + 18) = ScratchpadL3Mask64_Calculated;
|
||||
|
||||
// Apply scratchpad prefetch mode
|
||||
{
|
||||
uint32_t* a = (uint32_t*)(codePrefetchScratchpadTweaked + 8);
|
||||
uint32_t* b = (uint32_t*)(codePrefetchScratchpadTweaked + 22);
|
||||
|
||||
switch (scratchpadPrefetchMode)
|
||||
{
|
||||
case 0:
|
||||
*a = 0x00401F0FUL; // 4-byte nop
|
||||
*b = 0x00401F0FUL; // 4-byte nop
|
||||
break;
|
||||
|
||||
case 1:
|
||||
default:
|
||||
*a = 0x060C180FUL; // prefetcht0 [rsi+rax]
|
||||
*b = 0x160C180FUL; // prefetcht0 [rsi+rdx]
|
||||
break;
|
||||
|
||||
case 2:
|
||||
*a = 0x0604180FUL; // prefetchnta [rsi+rax]
|
||||
*b = 0x1604180FUL; // prefetchnta [rsi+rdx]
|
||||
break;
|
||||
|
||||
case 3:
|
||||
*a = 0x060C8B48UL; // mov rcx, [rsi+rax]
|
||||
*b = 0x160C8B48UL; // mov rcx, [rsi+rdx]
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define JIT_HANDLE(x, prev) randomx::JitCompilerX86::engine[k] = &randomx::JitCompilerX86::h_##x
|
||||
|
||||
#elif defined(XMRIG_ARMv8)
|
||||
|
|
|
@ -200,6 +200,8 @@ void randomx_apply_config(const T& config)
|
|||
RandomX_CurrentConfig.Apply();
|
||||
}
|
||||
|
||||
void randomx_set_scratchpad_prefetch_mode(int mode);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "base/io/log/Log.h"
|
||||
#include "crypto/rx/RxConfig.h"
|
||||
#include "crypto/rx/RxQueue.h"
|
||||
#include "crypto/randomx/randomx.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
@ -99,6 +100,8 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
|
|||
return true;
|
||||
}
|
||||
|
||||
randomx_set_scratchpad_prefetch_mode(config.scratchpadPrefetchMode());
|
||||
|
||||
if (isReady(seed)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@ static const char *kCacheQoS = "cache_qos";
|
|||
static const char *kNUMA = "numa";
|
||||
#endif
|
||||
|
||||
static const char *kScratchpadPrefetchMode = "scratchpad_prefetch_mode";
|
||||
|
||||
static const std::array<const char *, RxConfig::ModeMax> modeNames = { "auto", "fast", "light" };
|
||||
|
||||
|
||||
|
@ -118,6 +120,11 @@ bool xmrig::RxConfig::read(const rapidjson::Value &value)
|
|||
}
|
||||
# endif
|
||||
|
||||
const int mode = Json::getInt(value, kScratchpadPrefetchMode, static_cast<int>(m_scratchpadPrefetchMode));
|
||||
if ((mode >= ScratchpadPrefetchOff) && (mode < ScratchpadPrefetchMax)) {
|
||||
m_scratchpadPrefetchMode = static_cast<ScratchpadPrefetchMode>(mode);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -171,6 +178,8 @@ rapidjson::Value xmrig::RxConfig::toJSON(rapidjson::Document &doc) const
|
|||
}
|
||||
# endif
|
||||
|
||||
obj.AddMember(StringRef(kScratchpadPrefetchMode), static_cast<int>(m_scratchpadPrefetchMode), allocator);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,14 @@ public:
|
|||
ModeMax
|
||||
};
|
||||
|
||||
enum ScratchpadPrefetchMode : uint32_t {
|
||||
ScratchpadPrefetchOff,
|
||||
ScratchpadPrefetchT0,
|
||||
ScratchpadPrefetchNTA,
|
||||
ScratchpadPrefetchMov,
|
||||
ScratchpadPrefetchMax,
|
||||
};
|
||||
|
||||
bool read(const rapidjson::Value &value);
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
|
||||
|
@ -68,6 +76,8 @@ public:
|
|||
inline bool cacheQoS() const { return m_cacheQoS; }
|
||||
inline Mode mode() const { return m_mode; }
|
||||
|
||||
inline ScratchpadPrefetchMode scratchpadPrefetchMode() const { return m_scratchpadPrefetchMode; }
|
||||
|
||||
# ifdef XMRIG_FEATURE_MSR
|
||||
const char *msrPresetName() const;
|
||||
const MsrItems &msrPreset() const;
|
||||
|
@ -94,6 +104,8 @@ private:
|
|||
int m_threads = -1;
|
||||
Mode m_mode = AutoMode;
|
||||
|
||||
ScratchpadPrefetchMode m_scratchpadPrefetchMode = ScratchpadPrefetchT0;
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
std::vector<uint32_t> m_nodeset;
|
||||
# endif
|
||||
|
|
Loading…
Reference in a new issue