Update code

This commit is contained in:
Your Name 2024-05-05 17:31:22 +08:00
parent ce09c5b089
commit b9af8762d0
8 changed files with 50 additions and 108 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ scripts/deps
/CMakeLists.txt.user /CMakeLists.txt.user
/.idea /.idea
/src/backend/opencl/cl/cn/cryptonight_gen.cl /src/backend/opencl/cl/cn/cryptonight_gen.cl
/.vscode

View file

@ -32,7 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* https://github.com/P-H-C/phc-winner-argon2 * https://github.com/P-H-C/phc-winner-argon2
* Copyright 2015 * Copyright 2015
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
*/ */
#include <new> #include <new>
#include <algorithm> #include <algorithm>
@ -40,8 +40,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstring> #include <cstring>
#include <limits> #include <limits>
#include <cstring> #include <cstring>
#include <thread>
#include <chrono>
#include "crypto/randomx/common.hpp" #include "crypto/randomx/common.hpp"
#include "crypto/randomx/dataset.hpp" #include "crypto/randomx/dataset.hpp"
@ -56,35 +54,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "3rdparty/argon2/include/argon2.h" #include "3rdparty/argon2/include/argon2.h"
#include "3rdparty/argon2/lib/core.h" #include "3rdparty/argon2/lib/core.h"
// static_assert(RANDOMX_ARGON_MEMORY % (RANDOMX_ARGON_LANES * ARGON2_SYNC_POINTS) == 0, "RANDOMX_ARGON_MEMORY - invalid value"); //static_assert(RANDOMX_ARGON_MEMORY % (RANDOMX_ARGON_LANES * ARGON2_SYNC_POINTS) == 0, "RANDOMX_ARGON_MEMORY - invalid value");
static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unexpected value of ARGON2_BLOCK_SIZE"); static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unexpected value of ARGON2_BLOCK_SIZE");
namespace randomx namespace randomx {
{
template <class Allocator> template<class Allocator>
void deallocCache(randomx_cache *cache) void deallocCache(randomx_cache* cache) {
{ if (cache->memory != nullptr) {
if (cache->memory != nullptr)
{
Allocator::freeMemory(cache->memory, RANDOMX_CACHE_MAX_SIZE); Allocator::freeMemory(cache->memory, RANDOMX_CACHE_MAX_SIZE);
} }
delete cache->jit; delete cache->jit;
} }
template void deallocCache<DefaultAllocator>(randomx_cache *cache); template void deallocCache<DefaultAllocator>(randomx_cache* cache);
template void deallocCache<LargePageAllocator>(randomx_cache *cache); template void deallocCache<LargePageAllocator>(randomx_cache* cache);
void initCache(randomx_cache *cache, const void *key, size_t keySize) void initCache(randomx_cache* cache, const void* key, size_t keySize) {
{
argon2_context context; argon2_context context;
context.out = nullptr; context.out = nullptr;
context.outlen = 0; context.outlen = 0;
context.pwd = CONST_CAST(uint8_t *) key; context.pwd = CONST_CAST(uint8_t *)key;
context.pwdlen = (uint32_t)keySize; context.pwdlen = (uint32_t)keySize;
context.salt = CONST_CAST(uint8_t *) RandomX_CurrentConfig.ArgonSalt; context.salt = CONST_CAST(uint8_t *)RandomX_CurrentConfig.ArgonSalt;
context.saltlen = (uint32_t)strlen(RandomX_CurrentConfig.ArgonSalt); context.saltlen = (uint32_t)strlen(RandomX_CurrentConfig.ArgonSalt);
context.secret = nullptr; context.secret = nullptr;
context.secretlen = 0; context.secretlen = 0;
@ -102,28 +96,25 @@ namespace randomx
argon2_ctx_mem(&context, Argon2_d, cache->memory, RandomX_CurrentConfig.ArgonMemory * 1024); argon2_ctx_mem(&context, Argon2_d, cache->memory, RandomX_CurrentConfig.ArgonMemory * 1024);
randomx::Blake2Generator gen(key, keySize); randomx::Blake2Generator gen(key, keySize);
for (uint32_t i = 0; i < RandomX_CurrentConfig.CacheAccesses; ++i) for (uint32_t i = 0; i < RandomX_CurrentConfig.CacheAccesses; ++i) {
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
randomx::generateSuperscalar(cache->programs[i], gen); randomx::generateSuperscalar(cache->programs[i], gen);
} }
} }
void initCacheCompile(randomx_cache *cache, const void *key, size_t keySize) void initCacheCompile(randomx_cache* cache, const void* key, size_t keySize) {
{
initCache(cache, key, keySize); initCache(cache, key, keySize);
#ifdef XMRIG_SECURE_JIT # ifdef XMRIG_SECURE_JIT
cache->jit->enableWriting(); cache->jit->enableWriting();
#endif # endif
cache->jit->generateSuperscalarHash(cache->programs); cache->jit->generateSuperscalarHash(cache->programs);
cache->jit->generateDatasetInitCode(); cache->jit->generateDatasetInitCode();
cache->datasetInit = cache->jit->getDatasetInitFunc(); cache->datasetInit = cache->jit->getDatasetInitFunc();
#ifdef XMRIG_SECURE_JIT # ifdef XMRIG_SECURE_JIT
cache->jit->enableExecution(); cache->jit->enableExecution();
#endif # endif
} }
constexpr uint64_t superscalarMul0 = 6364136223846793005ULL; constexpr uint64_t superscalarMul0 = 6364136223846793005ULL;
@ -135,16 +126,14 @@ namespace randomx
constexpr uint64_t superscalarAdd6 = 3398623926847679864ULL; constexpr uint64_t superscalarAdd6 = 3398623926847679864ULL;
constexpr uint64_t superscalarAdd7 = 9549104520008361294ULL; constexpr uint64_t superscalarAdd7 = 9549104520008361294ULL;
static inline uint8_t *getMixBlock(uint64_t registerValue, uint8_t *memory) static inline uint8_t* getMixBlock(uint64_t registerValue, uint8_t *memory) {
{
const uint32_t mask = (RandomX_CurrentConfig.ArgonMemory * randomx::ArgonBlockSize) / CacheLineSize - 1; const uint32_t mask = (RandomX_CurrentConfig.ArgonMemory * randomx::ArgonBlockSize) / CacheLineSize - 1;
return memory + (registerValue & mask) * CacheLineSize; return memory + (registerValue & mask) * CacheLineSize;
} }
void initDatasetItem(randomx_cache *cache, uint8_t *out, uint64_t itemNumber) void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t itemNumber) {
{
int_reg_t rl[8]; int_reg_t rl[8];
uint8_t *mixBlock; uint8_t* mixBlock;
uint64_t registerValue = itemNumber; uint64_t registerValue = itemNumber;
rl[0] = (itemNumber + 1) * superscalarMul0; rl[0] = (itemNumber + 1) * superscalarMul0;
rl[1] = rl[0] ^ superscalarAdd1; rl[1] = rl[0] ^ superscalarAdd1;
@ -154,22 +143,15 @@ namespace randomx
rl[5] = rl[0] ^ superscalarAdd5; rl[5] = rl[0] ^ superscalarAdd5;
rl[6] = rl[0] ^ superscalarAdd6; rl[6] = rl[0] ^ superscalarAdd6;
rl[7] = rl[0] ^ superscalarAdd7; rl[7] = rl[0] ^ superscalarAdd7;
for (unsigned i = 0; i < RandomX_CurrentConfig.CacheAccesses; ++i) for (unsigned i = 0; i < RandomX_CurrentConfig.CacheAccesses; ++i) {
{
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
mixBlock = getMixBlock(registerValue, cache->memory); mixBlock = getMixBlock(registerValue, cache->memory);
rx_prefetch_nta(mixBlock); rx_prefetch_nta(mixBlock);
SuperscalarProgram &prog = cache->programs[i]; SuperscalarProgram& prog = cache->programs[i];
executeSuperscalar(rl, prog); executeSuperscalar(rl, prog);
for (unsigned q = 0; q < 8; ++q) for (unsigned q = 0; q < 8; ++q)
{
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
rl[q] ^= load64_native(mixBlock + 8 * q); rl[q] ^= load64_native(mixBlock + 8 * q);
}
registerValue = rl[prog.getAddressRegister()]; registerValue = rl[prog.getAddressRegister()];
} }
@ -177,12 +159,8 @@ namespace randomx
memcpy(out, &rl, CacheLineSize); memcpy(out, &rl, CacheLineSize);
} }
void initDataset(randomx_cache *cache, uint8_t *dataset, uint32_t startItem, uint32_t endItem) void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startItem, uint32_t endItem) {
{
for (uint32_t itemNumber = startItem; itemNumber < endItem; ++itemNumber, dataset += CacheLineSize) for (uint32_t itemNumber = startItem; itemNumber < endItem; ++itemNumber, dataset += CacheLineSize)
{
std::this_thread::sleep_for(std::chrono::milliseconds(1));
initDatasetItem(cache, dataset, itemNumber); initDatasetItem(cache, dataset, itemNumber);
}
} }
} }

View file

@ -24,12 +24,6 @@
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;# .section .data
;# nanosecs:
;# .quad 0, 10000
;# .extern usleep
.intel_syntax noprefix .intel_syntax noprefix
#if defined(__APPLE__) #if defined(__APPLE__)
.text .text
@ -179,17 +173,6 @@ DECL(randomx_dataset_init):
push rcx ;# max. block index push rcx ;# max. block index
#endif #endif
init_block_loop: init_block_loop:
;# mov rax, 35
;# mov rdi, nanosecs
;# xor rsi, rsi
;# syscall
;# push 100000
;# call usleep
;# add esp,4
prefetchw byte ptr [rsi] prefetchw byte ptr [rsi]
mov rbx, rbp mov rbx, rbp
.byte 232 ;# 0xE8 = call .byte 232 ;# 0xE8 = call
@ -245,16 +228,6 @@ DECL(randomx_dataset_init_avx2_prologue):
randomx_dataset_init_avx2_prologue_loop_begin: randomx_dataset_init_avx2_prologue_loop_begin:
#include "asm/program_sshash_avx2_loop_begin.inc" #include "asm/program_sshash_avx2_loop_begin.inc"
;# mov rax, 35
;# mov rdi, nanosecs
;# xor rsi, rsi
;# syscall
;# push 100000
;# call usleep
;# add esp,4
;# init integer registers (lane 0) ;# init integer registers (lane 0)
lea r8, [rbp+1] lea r8, [rbp+1]
imul r8, qword ptr [r0_avx2_mul+rip] imul r8, qword ptr [r0_avx2_mul+rip]
@ -377,4 +350,4 @@ DECL(randomx_reciprocal_fast):
#if defined(__linux__) && defined(__ELF__) #if defined(__linux__) && defined(__ELF__)
.section .note.GNU-stack,"",%progbits .section .note.GNU-stack,"",%progbits
#endif #endif

View file

@ -24,9 +24,6 @@
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
; section .data
; secs dq 5,0
IFDEF RAX IFDEF RAX
_RANDOMX_JITX86_STATIC SEGMENT PAGE READ EXECUTE _RANDOMX_JITX86_STATIC SEGMENT PAGE READ EXECUTE
@ -169,13 +166,6 @@ randomx_dataset_init PROC
mov rbp, r8 ;# block index mov rbp, r8 ;# block index
push r9 ;# max. block index push r9 ;# max. block index
init_block_loop: init_block_loop:
;# call usleep function
; mov rax, 35 ;# load the number of microseconds to sleep into eax
; mov rdi, secs ;# push the argument onto the stack
; xor rsi, rsi
; syscall ;# call the usleep function
prefetchw byte ptr [rsi] prefetchw byte ptr [rsi]
mov rbx, rbp mov rbx, rbp
db 232 ;# 0xE8 = call db 232 ;# 0xE8 = call
@ -222,12 +212,6 @@ ALIGN 64
loop_begin: loop_begin:
include asm/program_sshash_avx2_loop_begin.inc include asm/program_sshash_avx2_loop_begin.inc
;# call usleep function
; mov rax, 35 ;# load the number of microseconds to sleep into eax
; mov rdi, secs ;# push the argument onto the stack
; xor rsi, rsi
; syscall ;# call the usleep function
;# init integer registers (lane 0) ;# init integer registers (lane 0)
lea r8, [rbp+1] lea r8, [rbp+1]
imul r8, qword ptr [r0_avx2_mul] imul r8, qword ptr [r0_avx2_mul]

View file

@ -365,6 +365,10 @@ alignas(64) RandomX_ConfigurationBase RandomX_CurrentConfig;
static std::mutex vm_pool_mutex; static std::mutex vm_pool_mutex;
const char* envRandomXNanoSeconds = std::getenv("XMRIG_RANDOMX_SLEEP_NANOSECONDS");
int randomx_sleep_nanoseconds = (envRandomXNanoSeconds != nullptr) ? std::atoi(envRandomXNanoSeconds) : 0;
extern "C" { extern "C" {
randomx_cache *randomx_create_cache(randomx_flags flags, uint8_t *memory) { randomx_cache *randomx_create_cache(randomx_flags flags, uint8_t *memory) {
@ -389,12 +393,6 @@ extern "C" {
cache->initialize = &randomx::initCacheCompile; cache->initialize = &randomx::initCacheCompile;
cache->datasetInit = nullptr; cache->datasetInit = nullptr;
cache->memory = memory; cache->memory = memory;
// cache->jit = nullptr;
// cache->initialize = &randomx::initCache;
// cache->datasetInit = &randomx::initDataset;
// cache->memory = memory;
break; break;
default: default:
@ -581,7 +579,7 @@ extern "C" {
machine->initScratchpad(&tempHash); machine->initScratchpad(&tempHash);
machine->resetRoundingMode(); machine->resetRoundingMode();
for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) { for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::nanoseconds(randomx_sleep_nanoseconds));
machine->run(&tempHash); machine->run(&tempHash);
rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile)); rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile));
} }
@ -599,7 +597,7 @@ extern "C" {
machine->resetRoundingMode(); machine->resetRoundingMode();
for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) { for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) {
std::this_thread::sleep_for(std::chrono::milliseconds(1)); std::this_thread::sleep_for(std::chrono::nanoseconds(randomx_sleep_nanoseconds));
machine->run(&tempHash); machine->run(&tempHash);
rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile)); rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile));
} }

View file

@ -26,9 +26,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <thread>
#include <chrono>
#include "crypto/randomx/configuration.h" #include "crypto/randomx/configuration.h"
#include "crypto/randomx/program.hpp" #include "crypto/randomx/program.hpp"
#include "crypto/randomx/blake2/endian.h" #include "crypto/randomx/blake2/endian.h"
@ -852,8 +849,6 @@ namespace randomx {
void executeSuperscalar(int_reg_t(&r)[8], SuperscalarProgram& prog) { void executeSuperscalar(int_reg_t(&r)[8], SuperscalarProgram& prog) {
for (unsigned j = 0; j < prog.getSize(); ++j) { for (unsigned j = 0; j < prog.getSize(); ++j) {
// std::this_thread::sleep_for(std::chrono::milliseconds(1));
Instruction& instr = prog(j); Instruction& instr = prog(j);
switch ((SuperscalarInstructionType)instr.opcode) switch ((SuperscalarInstructionType)instr.opcode)
{ {

View file

@ -35,6 +35,10 @@
namespace xmrig { namespace xmrig {
const char* envRXDatasetSingleThreadInit = std::getenv("XMRIG_RX_DATASET_SINGLE_THREAD_INIT");
bool rx_dataset_single_thread_init = (envRXDatasetSingleThreadInit != nullptr);
static void init_dataset_wrapper(randomx_dataset *dataset, randomx_cache *cache, uint32_t startItem, uint32_t itemCount, int priority) static void init_dataset_wrapper(randomx_dataset *dataset, randomx_cache *cache, uint32_t startItem, uint32_t itemCount, int priority)
{ {
Platform::setThreadPriority(priority); Platform::setThreadPriority(priority);
@ -108,12 +112,16 @@ bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads, int priorit
const uint32_t a = (datasetItemCount * i) / numThreads; const uint32_t a = (datasetItemCount * i) / numThreads;
const uint32_t b = (datasetItemCount * (i + 1)) / numThreads; const uint32_t b = (datasetItemCount * (i + 1)) / numThreads;
threads.emplace_back(init_dataset_wrapper, m_dataset, m_cache->get(), a, b - a, priority); threads.emplace_back(init_dataset_wrapper, m_dataset, m_cache->get(), a, b - a, priority);
threads[i].join(); // force it to be sequential if (rx_dataset_single_thread_init)
{threads[i].join();} // force it to be sequential
}
if (!rx_dataset_single_thread_init){
for (uint32_t i = 0; i < numThreads; ++i) {
threads[i].join();
}
} }
// for (uint32_t i = 0; i < numThreads; ++i) {
// threads[i].join();
// }
} }
else { else {
init_dataset_wrapper(m_dataset, m_cache->get(), 0, datasetItemCount, priority); init_dataset_wrapper(m_dataset, m_cache->get(), 0, datasetItemCount, priority);

View file

@ -37,8 +37,13 @@
* If you plan on changing donations to 0%, please consider making a one-off donation to my wallet: * If you plan on changing donations to 0%, please consider making a one-off donation to my wallet:
* XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD * XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD
*/ */
#ifdef XMRIG_NO_DONATE
constexpr const int kDefaultDonateLevel = 0; constexpr const int kDefaultDonateLevel = 0;
constexpr const int kMinimumDonateLevel = 0; constexpr const int kMinimumDonateLevel = 0;
#else
constexpr const int kDefaultDonateLevel = 1;
constexpr const int kMinimumDonateLevel = 1;
#endif
#endif // XMRIG_DONATE_H #endif // XMRIG_DONATE_H