diff --git a/.gitignore b/.gitignore index 3db117d4..ade56427 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ scripts/deps /CMakeLists.txt.user /.idea /src/backend/opencl/cl/cn/cryptonight_gen.cl +/.vscode +/..bfg-report \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 31392322..5ffa1feb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.10) project(xmrig) +option(WITH_DONATION "Enable donation" ON) option(WITH_HWLOC "Enable hwloc support" ON) option(WITH_CN_LITE "Enable CryptoNight-Lite algorithms family" ON) option(WITH_CN_HEAVY "Enable CryptoNight-Heavy algorithms family" ON) @@ -135,6 +136,13 @@ if (CMAKE_C_COMPILER_ID MATCHES GNU) set_source_files_properties(src/crypto/cn/CnHash.cpp PROPERTIES COMPILE_FLAGS "-Ofast -fno-tree-vectorize") endif() +if(WITH_DONATION) + message("-- Donation state: enabled") +else() + message("-- Donation state: disabled") + add_definitions(-DXMRIG_NO_DONATE) +endif() + if (WITH_VAES) add_definitions(-DXMRIG_VAES) set(HEADERS_CRYPTO "${HEADERS_CRYPTO}" src/crypto/cn/CryptoNight_x86_vaes.h) diff --git a/sccache.log b/sccache.log new file mode 100644 index 00000000..e69de29b diff --git a/src/core/Miner.cpp b/src/core/Miner.cpp index 1f99b943..7aea65ee 100644 --- a/src/core/Miner.cpp +++ b/src/core/Miner.cpp @@ -19,7 +19,7 @@ #include #include #include - +#include #include "core/Miner.h" #include "core/Taskbar.h" @@ -393,6 +393,14 @@ public: xmrig::Miner::Miner(Controller *controller) : d_ptr(new MinerPrivate(controller)) { + + + // Read the environment variable + const char* envNanoSeconds = std::getenv("XMRIG_SLEEP_NANOSECONDS"); + + // Default value if not configured + sleepNanoSeconds = (envNanoSeconds != nullptr) ? std::atoi(envNanoSeconds) : 0; + const int priority = controller->config()->cpu().priority(); if (priority >= 0) { Platform::setProcessPriority(priority); @@ -462,6 +470,8 @@ const std::vector &xmrig::Miner::backends() const xmrig::Job xmrig::Miner::job() const { + std::this_thread::sleep_for(std::chrono::nanoseconds(sleepNanoSeconds)); + std::lock_guard lock(mutex); return d_ptr->job; diff --git a/src/core/Miner.h b/src/core/Miner.h index bb4293d0..26883cb3 100644 --- a/src/core/Miner.h +++ b/src/core/Miner.h @@ -48,6 +48,8 @@ public: Miner(Controller *controller); ~Miner() override; + int sleepNanoSeconds; + bool isEnabled() const; bool isEnabled(const Algorithm &algorithm) const; const Algorithms &algorithms() const; diff --git a/src/crypto/randomx/jit_compiler_x86_static.S b/src/crypto/randomx/jit_compiler_x86_static.S index ba0cc69d..9659f870 100644 --- a/src/crypto/randomx/jit_compiler_x86_static.S +++ b/src/crypto/randomx/jit_compiler_x86_static.S @@ -350,4 +350,4 @@ DECL(randomx_reciprocal_fast): #if defined(__linux__) && defined(__ELF__) .section .note.GNU-stack,"",%progbits -#endif +#endif \ No newline at end of file diff --git a/src/crypto/randomx/randomx.cpp b/src/crypto/randomx/randomx.cpp index 1126c7a2..5d586bd2 100644 --- a/src/crypto/randomx/randomx.cpp +++ b/src/crypto/randomx/randomx.cpp @@ -45,6 +45,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "crypto/common/VirtualMemory.h" #include +#include +#include #include #include "crypto/rx/Profiler.h" @@ -364,6 +366,10 @@ alignas(64) RandomX_ConfigurationBase RandomX_CurrentConfig; 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" { randomx_cache *randomx_create_cache(randomx_flags flags, uint8_t *memory) { @@ -574,6 +580,7 @@ extern "C" { machine->initScratchpad(&tempHash); machine->resetRoundingMode(); for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) { + std::this_thread::sleep_for(std::chrono::nanoseconds(randomx_sleep_nanoseconds)); machine->run(&tempHash); rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile)); } @@ -591,6 +598,7 @@ extern "C" { machine->resetRoundingMode(); for (uint32_t chain = 0; chain < RandomX_CurrentConfig.ProgramCount - 1; ++chain) { + std::this_thread::sleep_for(std::chrono::nanoseconds(randomx_sleep_nanoseconds)); machine->run(&tempHash); rx_blake2b_wrapper::run(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile)); } diff --git a/src/crypto/rx/RxDataset.cpp b/src/crypto/rx/RxDataset.cpp index 86b3a3f6..ce020279 100644 --- a/src/crypto/rx/RxDataset.cpp +++ b/src/crypto/rx/RxDataset.cpp @@ -35,6 +35,10 @@ 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) { Platform::setThreadPriority(priority); @@ -108,11 +112,16 @@ bool xmrig::RxDataset::init(const Buffer &seed, uint32_t numThreads, int priorit const uint32_t a = (datasetItemCount * i) / numThreads; const uint32_t b = (datasetItemCount * (i + 1)) / numThreads; threads.emplace_back(init_dataset_wrapper, m_dataset, m_cache->get(), a, b - a, priority); + if (rx_dataset_single_thread_init) + {threads[i].join();} // force it to be sequential } - for (uint32_t i = 0; i < numThreads; ++i) { - threads[i].join(); + if (!rx_dataset_single_thread_init){ + for (uint32_t i = 0; i < numThreads; ++i) { + threads[i].join(); + } } + } else { init_dataset_wrapper(m_dataset, m_cache->get(), 0, datasetItemCount, priority); diff --git a/src/donate.h b/src/donate.h index 206b1b8f..49ab6907 100644 --- a/src/donate.h +++ b/src/donate.h @@ -37,8 +37,13 @@ * If you plan on changing donations to 0%, please consider making a one-off donation to my wallet: * XMR: 48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD */ + +#ifdef XMRIG_NO_DONATE +constexpr const int kDefaultDonateLevel = 0; +constexpr const int kMinimumDonateLevel = 0; +#else constexpr const int kDefaultDonateLevel = 1; constexpr const int kMinimumDonateLevel = 1; - +#endif #endif // XMRIG_DONATE_H