Merge branch 'dev'

This commit is contained in:
XMRig 2020-10-19 03:20:21 +07:00
commit 6dd281b508
No known key found for this signature in database
GPG key ID: 446A53638BE94409
108 changed files with 7387 additions and 6377 deletions

View file

@ -1,3 +1,17 @@
# v6.4.0
- [#1862](https://github.com/xmrig/xmrig/pull/1862) **RandomX: removed `rx/loki` algorithm.**
- [#1890](https://github.com/xmrig/xmrig/pull/1890) **Added `argon2/chukwav2` algorithm.**
- [#1895](https://github.com/xmrig/xmrig/pull/1895) [#1897](https://github.com/xmrig/xmrig/pull/1897) **Added [benchmark and stress test](https://github.com/xmrig/xmrig/blob/dev/doc/BENCHMARK.md).**
- [#1864](https://github.com/xmrig/xmrig/pull/1864) RandomX: improved software AES performance.
- [#1870](https://github.com/xmrig/xmrig/pull/1870) RandomX: fixed unexpected resume due to disconnect during dataset init.
- [#1872](https://github.com/xmrig/xmrig/pull/1872) RandomX: fixed `randomx_create_vm` call.
- [#1875](https://github.com/xmrig/xmrig/pull/1875) RandomX: fixed crash on x86.
- [#1876](https://github.com/xmrig/xmrig/pull/1876) RandomX: added `huge-pages-jit` config parameter.
- [#1881](https://github.com/xmrig/xmrig/pull/1881) Fixed possible race condition in hashrate counting code.
- [#1882](https://github.com/xmrig/xmrig/pull/1882) [#1886](https://github.com/xmrig/xmrig/pull/1886) [#1887](https://github.com/xmrig/xmrig/pull/1887) [#1893](https://github.com/xmrig/xmrig/pull/1893) General code improvements.
- [#1885](https://github.com/xmrig/xmrig/pull/1885) Added more precise hashrate calculation.
- [#1889](https://github.com/xmrig/xmrig/pull/1889) Fixed libuv performance issue on Linux.
# v6.3.5
- [#1845](https://github.com/xmrig/xmrig/pull/1845) [#1861](https://github.com/xmrig/xmrig/pull/1861) Fixed ARM build and added CMake option `WITH_SSE4_1`.
- [#1846](https://github.com/xmrig/xmrig/pull/1846) KawPow: fixed OpenCL memory leak.

View file

@ -25,6 +25,7 @@ option(WITH_STRICT_CACHE "Enable strict checks for OpenCL cache" ON)
option(WITH_INTERLEAVE_DEBUG_LOG "Enable debug log for threads interleave" OFF)
option(WITH_PROFILING "Enable profiling for developers" OFF)
option(WITH_SSE4_1 "Enable SSE 4.1 for Blake2" ON)
option(WITH_BENCHMARK "Enable builtin RandomX benchmark and stress test" ON)
option(BUILD_STATIC "Build static binary" OFF)
option(ARM_TARGET "Force use specific ARM target 8 or 7" 0)

View file

@ -64,8 +64,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Oi /DNDEBUG /GL")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Ob1 /GL")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Ob1 /GL")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/Ob1 /Zi")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/Ob1 /Zi")
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)

View file

@ -62,6 +62,10 @@ if (WITH_RANDOMX)
)
# cheat because cmake and ccache hate each other
set_property(SOURCE src/crypto/randomx/jit_compiler_a64_static.S PROPERTY LANGUAGE C)
else()
list(APPEND SOURCES_CRYPTO
src/crypto/randomx/jit_compiler_fallback.cpp
)
endif()
if (WITH_SSE4_1)

29
doc/BENCHMARK.md Normal file
View file

@ -0,0 +1,29 @@
# Embedded benchmark
You can run with XMRig with the following commands:
```
xmrig --bench=1M
xmrig --bench=10M
xmrig --bench=1M -a rx/wow
xmrig --bench=10M -a rx/wow
```
This will run between 1 and 10 million RandomX hashes, depending on `bench` parameter, and print the time it took. First two commands use Monero variant (2 MB per thread, best for Zen2/Zen3 CPUs), second two commands use Wownero variant (1 MB per thread, useful for Intel and 1st gen Zen/Zen+ CPUs).
Checksum of all the hashes will be also printed to check stability of your hardware: if it's green then it's correct, if it's red then there was hardware error during computation. No Internet connection is required for the benchmark.
Double check that you see `Huge pages 100%` both for dataset and for all threads, and also check for `msr register values ... has been set successfully` - without this result will be far from the best. Running as administrator is required for MSR and huge pages to be set up properly.
![Benchmark example](https://i.imgur.com/PST3BYc.png)
### Benchmark with custom config
You can run benchmark with any configuration you want. Just start without command line parameteres, use regular config.json and add `"benchmark":"1M",` on the next line after pool url.
# Stress test
You can also run continuous stress-test that is as close to the real RandomX mining as possible and doesn't require any configuration:
```
xmrig --stress
xmrig --stress -a rx/wow
```
This will require Internet connection and will run indefinitely.

View file

@ -49,7 +49,6 @@ function rx()
'../cn/algorithm.cl',
'randomx_constants_monero.h',
'randomx_constants_wow.h',
'randomx_constants_loki.h',
'randomx_constants_arqma.h',
'randomx_constants_keva.h',
'aes.cl',

View file

@ -0,0 +1,103 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend/common/Benchmark.h"
#include "backend/common/interfaces/IWorker.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/tools/Chrono.h"
#include <algorithm>
namespace xmrig {
static uint64_t hashCheck[2][10] = {
{ 0x898B6E0431C28A6BULL, 0xEE9468F8B40926BCULL, 0xC2BC5D11724813C0ULL, 0x3A2C7B285B87F941ULL, 0x3B5BD2C3A16B450EULL, 0x5CD0602F20C5C7C4ULL, 0x101DE939474B6812ULL, 0x52B765A1B156C6ECULL, 0x323935102AB6B45CULL, 0xB5231262E2792B26ULL },
{ 0x0F3E5400B39EA96AULL, 0x85944CCFA2752D1FULL, 0x64AFFCAE991811BAULL, 0x3E4D0B836D3B13BAULL, 0xEB7417D621271166ULL, 0x97FFE10C0949FFA5ULL, 0x84CAC0F8879A4BA1ULL, 0xA1B79F031DA2459FULL, 0x9B65226DA873E65DULL, 0x0F9E00C5A511C200ULL },
};
} // namespace xmrig
bool xmrig::Benchmark::finish(uint64_t totalHashCount)
{
m_reset = true;
m_current = totalHashCount;
if (m_done < m_workers) {
return false;
}
const double dt = (m_doneTime - m_startTime) / 1000.0;
uint64_t checkData = 0;
const uint32_t N = (m_end / 1000000) - 1;
if (((m_algo == Algorithm::RX_0) || (m_algo == Algorithm::RX_WOW)) && ((m_end % 1000000) == 0) && (N < 10)) {
checkData = hashCheck[(m_algo == Algorithm::RX_0) ? 0 : 1][N];
}
const char *color = checkData ? ((m_data == checkData) ? GREEN_BOLD_S : RED_BOLD_S) : BLACK_BOLD_S;
LOG_NOTICE("%s " WHITE_BOLD("benchmark finished in ") CYAN_BOLD("%.3f seconds") WHITE_BOLD_S " hash sum = " CLEAR "%s%016" PRIX64 CLEAR, Tags::bench(), dt, color, m_data);
LOG_INFO("%s " WHITE_BOLD("press ") MAGENTA_BOLD("Ctrl+C") WHITE_BOLD(" to exit"), Tags::bench());
return true;
}
void xmrig::Benchmark::start()
{
m_startTime = Chrono::steadyMSecs();
}
void xmrig::Benchmark::printProgress() const
{
if (!m_startTime || !m_current) {
return;
}
const double dt = (Chrono::steadyMSecs() - m_startTime) / 1000.0;
const double percent = static_cast<double>(m_current) / m_end * 100.0;
LOG_NOTICE("%s " MAGENTA_BOLD("%5.2f%% ") CYAN_BOLD("%" PRIu64) CYAN("/%" PRIu64) BLACK_BOLD(" (%.3fs)"), Tags::bench(), percent, m_current, m_end, dt);
}
void xmrig::Benchmark::tick(IWorker *worker)
{
if (m_reset) {
m_data = 0;
m_done = 0;
m_reset = false;
}
const uint64_t doneTime = worker->benchDoneTime();
if (!doneTime) {
return;
}
++m_done;
m_data ^= worker->benchData();
m_doneTime = std::max(doneTime, m_doneTime);
}

View file

@ -0,0 +1,62 @@
/* XMRig
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_BENCHMARK_H
#define XMRIG_BENCHMARK_H
#include "base/tools/Object.h"
#include "base/crypto/Algorithm.h"
namespace xmrig {
class IWorker;
class Benchmark
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Benchmark)
Benchmark(uint32_t end, const Algorithm &algo, size_t workers) : m_algo(algo), m_workers(workers), m_end(end) {}
~Benchmark() = default;
bool finish(uint64_t totalHashCount);
void printProgress() const;
void start();
void tick(IWorker *worker);
private:
bool m_reset = false;
const Algorithm m_algo = Algorithm::RX_0;
const size_t m_workers = 0;
const uint64_t m_end = 0;
uint32_t m_done = 0;
uint64_t m_current = 0;
uint64_t m_data = 0;
uint64_t m_doneTime = 0;
uint64_t m_startTime = 0;
};
} // namespace xmrig
#endif /* XMRIG_BENCHMARK_H */

View file

@ -48,13 +48,13 @@ inline static const char *format(double h, char *buf, size_t size)
xmrig::Hashrate::Hashrate(size_t threads) :
m_threads(threads)
m_threads(threads + 1)
{
m_counts = new uint64_t*[threads];
m_timestamps = new uint64_t*[threads];
m_top = new uint32_t[threads];
m_counts = new uint64_t*[m_threads];
m_timestamps = new uint64_t*[m_threads];
m_top = new uint32_t[m_threads];
for (size_t i = 0; i < threads; i++) {
for (size_t i = 0; i < m_threads; i++) {
m_counts[i] = new uint64_t[kBucketSize]();
m_timestamps[i] = new uint64_t[kBucketSize]();
m_top[i] = 0;
@ -77,17 +77,8 @@ xmrig::Hashrate::~Hashrate()
double xmrig::Hashrate::calc(size_t ms) const
{
double result = 0.0;
double data;
for (size_t i = 0; i < m_threads; ++i) {
data = calc(i, ms);
if (std::isnormal(data)) {
result += data;
}
}
return result;
const double data = calc(0, ms);
return std::isnormal(data) ? data : 0.0;
}
@ -102,7 +93,7 @@ double xmrig::Hashrate::calc(size_t threadId, size_t ms) const
uint64_t earliestStamp = 0;
bool haveFullSet = false;
const uint64_t timeStampLimit = xmrig::Chrono::highResolutionMSecs() - ms;
const uint64_t timeStampLimit = xmrig::Chrono::steadyMSecs() - ms;
uint64_t* timestamps = m_timestamps[threadId];
uint64_t* counts = m_counts[threadId];
@ -183,9 +174,9 @@ rapidjson::Value xmrig::Hashrate::toJSON(size_t threadId, rapidjson::Document &d
auto &allocator = doc.GetAllocator();
Value out(kArrayType);
out.PushBack(normalize(calc(threadId, ShortInterval)), allocator);
out.PushBack(normalize(calc(threadId, MediumInterval)), allocator);
out.PushBack(normalize(calc(threadId, LargeInterval)), allocator);
out.PushBack(normalize(calc(threadId + 1, ShortInterval)), allocator);
out.PushBack(normalize(calc(threadId + 1, MediumInterval)), allocator);
out.PushBack(normalize(calc(threadId + 1, LargeInterval)), allocator);
return out;
}

View file

@ -0,0 +1,63 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backend/common/HashrateInterpolator.h"
uint64_t xmrig::HashrateInterpolator::interpolate(uint64_t timeStamp) const
{
timeStamp -= LagMS;
std::lock_guard<std::mutex> l(m_lock);
const size_t N = m_data.size();
if (N < 2) {
return 0;
}
for (size_t i = 0; i < N - 1; ++i) {
const auto& a = m_data[i];
const auto& b = m_data[i + 1];
if (a.second <= timeStamp && timeStamp <= b.second) {
return a.first + static_cast<int64_t>(b.first - a.first) * (timeStamp - a.second) / (b.second - a.second);
}
}
return 0;
}
void xmrig::HashrateInterpolator::addDataPoint(uint64_t count, uint64_t timeStamp)
{
std::lock_guard<std::mutex> l(m_lock);
// Clean up old data
while (!m_data.empty() && (timeStamp - m_data.front().second > LagMS * 2)) {
m_data.pop_front();
}
m_data.emplace_back(count, timeStamp);
}

View file

@ -0,0 +1,57 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_HASHRATE_INTERPOLATOR_H
#define XMRIG_HASHRATE_INTERPOLATOR_H
#include <mutex>
#include <deque>
#include <utility>
namespace xmrig {
class HashrateInterpolator
{
public:
enum {
LagMS = 4000,
};
uint64_t interpolate(uint64_t timeStamp) const;
void addDataPoint(uint64_t count, uint64_t timeStamp);
private:
// Buffer of hashrate counters, used for linear interpolation of past data
mutable std::mutex m_lock;
std::deque<std::pair<uint64_t, uint64_t>> m_data;
};
} // namespace xmrig
#endif /* XMRIG_HASHRATE_INTERPOLATOR_H */

View file

@ -32,9 +32,7 @@
xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
m_affinity(affinity),
m_id(id),
m_hashCount(0),
m_timestamp(0)
m_id(id)
{
m_node = VirtualMemory::bindToNUMANode(affinity);
@ -45,6 +43,23 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
void xmrig::Worker::storeStats()
{
m_hashCount.store(m_count, std::memory_order_relaxed);
m_timestamp.store(Chrono::highResolutionMSecs(), std::memory_order_relaxed);
// Get index which is unused now
const uint32_t index = m_index.load(std::memory_order_relaxed) ^ 1;
// Fill in the data for that index
m_hashCount[index] = m_count;
m_timestamp[index] = Chrono::steadyMSecs();
// Switch to that index
// All data will be in memory by the time it completes thanks to std::memory_order_seq_cst
m_index.fetch_xor(1, std::memory_order_seq_cst);
}
void xmrig::Worker::getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const
{
const uint32_t index = m_index.load(std::memory_order_relaxed);
hashCount = m_hashCount[index];
timeStamp = m_timestamp[index];
}

View file

@ -44,19 +44,31 @@ public:
inline const VirtualMemory *memory() const override { return nullptr; }
inline size_t id() const override { return m_id; }
inline uint64_t hashCount() const override { return m_hashCount.load(std::memory_order_relaxed); }
inline uint64_t timestamp() const override { return m_timestamp.load(std::memory_order_relaxed); }
inline uint64_t rawHashes() const override { return m_count; }
inline void jobEarlyNotification(const Job&) override {}
void getHashrateData(uint64_t& hashCount, uint64_t& timeStamp) const override;
# ifdef XMRIG_FEATURE_BENCHMARK
inline uint64_t benchData() const override { return m_benchData; }
inline uint64_t benchDoneTime() const override { return m_benchDoneTime; }
# endif
protected:
void storeStats();
const int64_t m_affinity;
const size_t m_id;
std::atomic<uint64_t> m_hashCount;
std::atomic<uint64_t> m_timestamp;
uint32_t m_node = 0;
uint64_t m_count = 0;
std::atomic<uint32_t> m_index = {};
uint32_t m_node = 0;
uint64_t m_count = 0;
uint64_t m_hashCount[2] = {};
uint64_t m_timestamp[2] = {};
# ifdef XMRIG_FEATURE_BENCHMARK
uint64_t m_benchData = 0;
uint64_t m_benchDoneTime = 0;
# endif
};

View file

@ -68,7 +68,7 @@ public:
{
m_rounds[index()]++;
if ((m_rounds[index()] % rounds) == 0) {
if ((m_rounds[index()] & (rounds - 1)) == 0) {
for (size_t i = 0; i < N; ++i) {
if (!Nonce::next(index(), nonce(i), rounds * roundSize, nonceMask())) {
return false;
@ -130,7 +130,7 @@ inline bool xmrig::WorkerJob<1>::nextRound(uint32_t rounds, uint32_t roundSize)
uint32_t* n = nonce();
if ((m_rounds[index()] % rounds) == 0) {
if ((m_rounds[index()] & (rounds - 1)) == 0) {
if (!Nonce::next(index(), n, rounds * roundSize, nonceMask())) {
return false;
}

View file

@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@ -29,7 +29,11 @@
#include "backend/common/Workers.h"
#include "backend/cpu/CpuWorker.h"
#include "base/io/log/Log.h"
#include "base/io/log/Tags.h"
#include "base/net/stratum/Pool.h"
#include "base/tools/Chrono.h"
#include "base/tools/Object.h"
#include "core/Miner.h"
#ifdef XMRIG_FEATURE_OPENCL
@ -42,6 +46,11 @@
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
# include "backend/common/Benchmark.h"
#endif
namespace xmrig {
@ -51,17 +60,12 @@ public:
XMRIG_DISABLE_COPY_MOVE(WorkersPrivate)
WorkersPrivate() = default;
WorkersPrivate() = default;
~WorkersPrivate() = default;
inline ~WorkersPrivate()
{
delete hashrate;
}
Hashrate *hashrate = nullptr;
IBackend *backend = nullptr;
IBackend *backend = nullptr;
std::shared_ptr<Benchmark> benchmark;
std::shared_ptr<Hashrate> hashrate;
};
@ -83,10 +87,77 @@ xmrig::Workers<T>::~Workers()
}
template<class T>
xmrig::Benchmark *xmrig::Workers<T>::benchmark() const
{
return d_ptr->benchmark.get();
}
template<class T>
static void getHashrateData(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t& timeStamp)
{
worker->getHashrateData(hashCount, timeStamp);
}
template<>
void getHashrateData<xmrig::CpuLaunchData>(xmrig::IWorker* worker, uint64_t& hashCount, uint64_t&)
{
hashCount = worker->rawHashes();
}
template<class T>
bool xmrig::Workers<T>::tick(uint64_t)
{
if (!d_ptr->hashrate) {
return true;
}
uint64_t ts = Chrono::steadyMSecs();
bool totalAvailable = true;
uint64_t totalHashCount = 0;
for (Thread<T> *handle : m_workers) {
IWorker *worker = handle->worker();
if (worker) {
uint64_t hashCount;
getHashrateData<T>(worker, hashCount, ts);
d_ptr->hashrate->add(handle->id() + 1, hashCount, ts);
const uint64_t n = worker->rawHashes();
if (n == 0) {
totalAvailable = false;
}
totalHashCount += n;
# ifdef XMRIG_FEATURE_BENCHMARK
if (d_ptr->benchmark) {
d_ptr->benchmark->tick(worker);
}
# endif
}
}
if (totalAvailable) {
d_ptr->hashrate->add(0, totalHashCount, Chrono::steadyMSecs());
}
# ifdef XMRIG_FEATURE_BENCHMARK
if (d_ptr->benchmark && d_ptr->benchmark->finish(totalHashCount)) {
return false;
}
# endif
return true;
}
template<class T>
const xmrig::Hashrate *xmrig::Workers<T>::hashrate() const
{
return d_ptr->hashrate;
return d_ptr->hashrate.get();
}
@ -100,21 +171,35 @@ void xmrig::Workers<T>::setBackend(IBackend *backend)
template<class T>
void xmrig::Workers<T>::start(const std::vector<T> &data)
{
# ifdef XMRIG_FEATURE_BENCHMARK
if (!data.empty() && data.front().benchSize) {
d_ptr->benchmark = std::make_shared<Benchmark>(data.front().benchSize, data.front().algorithm, data.size());
}
# endif
for (const T &item : data) {
m_workers.push_back(new Thread<T>(d_ptr->backend, m_workers.size(), item));
}
d_ptr->hashrate = new Hashrate(m_workers.size());
d_ptr->hashrate = std::make_shared<Hashrate>(m_workers.size());
Nonce::touch(T::backend());
for (Thread<T> *worker : m_workers) {
worker->start(Workers<T>::onReady);
// This sleep is important for optimal caching!
// Threads must allocate scratchpads in order so that adjacent cores will use adjacent scratchpads
// Sub-optimal caching can result in up to 0.5% hashrate penalty
std::this_thread::sleep_for(std::chrono::milliseconds(20));
# ifdef XMRIG_FEATURE_BENCHMARK
if (!d_ptr->benchmark)
# endif
{
std::this_thread::sleep_for(std::chrono::milliseconds(20));
}
}
# ifdef XMRIG_FEATURE_BENCHMARK
if (d_ptr->benchmark) {
d_ptr->benchmark->start();
}
# endif
}
@ -130,25 +215,7 @@ void xmrig::Workers<T>::stop()
m_workers.clear();
Nonce::touch(T::backend());
delete d_ptr->hashrate;
d_ptr->hashrate = nullptr;
}
template<class T>
void xmrig::Workers<T>::tick(uint64_t)
{
if (!d_ptr->hashrate) {
return;
}
for (Thread<T> *handle : m_workers) {
if (!handle->worker()) {
continue;
}
d_ptr->hashrate->add(handle->id(), handle->worker()->hashCount(), handle->worker()->timestamp());
}
d_ptr->hashrate.reset();
}

View file

@ -6,8 +6,8 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
@ -29,7 +29,6 @@
#include "backend/common/Thread.h"
#include "backend/cpu/CpuLaunchData.h"
#include "base/tools/Object.h"
#ifdef XMRIG_FEATURE_OPENCL
@ -48,6 +47,7 @@ namespace xmrig {
class Hashrate;
class WorkersPrivate;
class Job;
class Benchmark;
template<class T>
@ -59,12 +59,13 @@ public:
Workers();
~Workers();
Benchmark *benchmark() const;
bool tick(uint64_t ticks);
const Hashrate *hashrate() const;
void jobEarlyNotification(const Job&);
void setBackend(IBackend *backend);
void start(const std::vector<T> &data);
void stop();
void tick(uint64_t ticks);
void jobEarlyNotification(const Job&);
private:
static IWorker *create(Thread<T> *handle);

View file

@ -1,5 +1,6 @@
set(HEADERS_BACKEND_COMMON
src/backend/common/Hashrate.h
src/backend/common/HashrateInterpolator.h
src/backend/common/Tags.h
src/backend/common/interfaces/IBackend.h
src/backend/common/interfaces/IRxListener.h
@ -15,7 +16,13 @@ set(HEADERS_BACKEND_COMMON
set(SOURCES_BACKEND_COMMON
src/backend/common/Hashrate.cpp
src/backend/common/HashrateInterpolator.cpp
src/backend/common/Threads.cpp
src/backend/common/Worker.cpp
src/backend/common/Workers.cpp
)
if (WITH_RANDOMX AND WITH_BENCHMARK)
list(APPEND HEADERS_BACKEND_COMMON src/backend/common/Benchmark.h)
list(APPEND SOURCES_BACKEND_COMMON src/backend/common/Benchmark.cpp)
endif()

View file

@ -36,6 +36,7 @@ namespace xmrig {
class Algorithm;
class Benchmark;
class Hashrate;
class IApiRequest;
class IWorker;
@ -60,12 +61,17 @@ public:
virtual void setJob(const Job &job) = 0;
virtual void start(IWorker *worker, bool ready) = 0;
virtual void stop() = 0;
virtual void tick(uint64_t ticks) = 0;
virtual bool tick(uint64_t ticks) = 0;
# ifdef XMRIG_FEATURE_API
virtual rapidjson::Value toJSON(rapidjson::Document &doc) const = 0;
virtual void handleRequest(IApiRequest &request) = 0;
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
virtual Benchmark *benchmark() const = 0;
virtual void printBenchProgress() const = 0;
# endif
};

View file

@ -42,14 +42,19 @@ class IWorker
public:
virtual ~IWorker() = default;
virtual bool selfTest() = 0;
virtual const VirtualMemory *memory() const = 0;
virtual size_t id() const = 0;
virtual size_t intensity() const = 0;
virtual uint64_t hashCount() const = 0;
virtual uint64_t timestamp() const = 0;
virtual void start() = 0;
virtual void jobEarlyNotification(const Job&) = 0;
virtual bool selfTest() = 0;
virtual const VirtualMemory *memory() const = 0;
virtual size_t id() const = 0;
virtual size_t intensity() const = 0;
virtual uint64_t rawHashes() const = 0;
virtual void getHashrateData(uint64_t&, uint64_t&) const = 0;
virtual void start() = 0;
virtual void jobEarlyNotification(const Job&) = 0;
# ifdef XMRIG_FEATURE_BENCHMARK
virtual uint64_t benchData() const = 0;
virtual uint64_t benchDoneTime() const = 0;
# endif
};

View file

@ -55,6 +55,11 @@
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
# include "backend/common/Benchmark.h"
#endif
namespace xmrig {
@ -304,9 +309,9 @@ void xmrig::CpuBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %7s | %7s | %7s |",
i,
data.affinity,
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval), num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval), num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval), num + 8, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval), num + 8 * 2, sizeof num / 3)
);
i++;
@ -335,7 +340,7 @@ void xmrig::CpuBackend::setJob(const Job &job)
const CpuConfig &cpu = d_ptr->controller->config()->cpu();
std::vector<CpuLaunchData> threads = cpu.get(d_ptr->controller->miner(), job.algorithm());
std::vector<CpuLaunchData> threads = cpu.get(d_ptr->controller->miner(), job.algorithm(), d_ptr->controller->config()->pools().benchSize());
if (!d_ptr->threads.empty() && d_ptr->threads.size() == threads.size() && std::equal(d_ptr->threads.begin(), d_ptr->threads.end(), threads.begin())) {
return;
}
@ -387,9 +392,9 @@ void xmrig::CpuBackend::stop()
}
void xmrig::CpuBackend::tick(uint64_t ticks)
bool xmrig::CpuBackend::tick(uint64_t ticks)
{
d_ptr->workers.tick(ticks);
return d_ptr->workers.tick(ticks);
}
@ -459,3 +464,20 @@ void xmrig::CpuBackend::handleRequest(IApiRequest &request)
}
}
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
xmrig::Benchmark *xmrig::CpuBackend::benchmark() const
{
return d_ptr->workers.benchmark();
}
void xmrig::CpuBackend::printBenchProgress() const
{
auto benchmark = d_ptr->workers.benchmark();
if (benchmark) {
benchmark->printProgress();
}
}
#endif

View file

@ -63,13 +63,18 @@ protected:
void setJob(const Job &job) override;
void start(IWorker *worker, bool ready) override;
void stop() override;
void tick(uint64_t ticks) override;
bool tick(uint64_t ticks) override;
# ifdef XMRIG_FEATURE_API
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
void handleRequest(IApiRequest &request) override;
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
Benchmark *benchmark() const override;
void printBenchProgress() const override;
# endif
private:
CpuBackendPrivate *d_ptr;
};

View file

@ -34,25 +34,27 @@
namespace xmrig {
static const char *kEnabled = "enabled";
static const char *kHugePages = "huge-pages";
static const char *kHwAes = "hw-aes";
static const char *kMaxThreadsHint = "max-threads-hint";
static const char *kMemoryPool = "memory-pool";
static const char *kPriority = "priority";
static const char *kYield = "yield";
const char *CpuConfig::kEnabled = "enabled";
const char *CpuConfig::kField = "cpu";
const char *CpuConfig::kHugePages = "huge-pages";
const char *CpuConfig::kHugePagesJit = "huge-pages-jit";
const char *CpuConfig::kHwAes = "hw-aes";
const char *CpuConfig::kMaxThreadsHint = "max-threads-hint";
const char *CpuConfig::kMemoryPool = "memory-pool";
const char *CpuConfig::kPriority = "priority";
const char *CpuConfig::kYield = "yield";
#ifdef XMRIG_FEATURE_ASM
static const char *kAsm = "asm";
const char *CpuConfig::kAsm = "asm";
#endif
#ifdef XMRIG_ALGO_ARGON2
static const char *kArgon2Impl = "argon2-impl";
const char *CpuConfig::kArgon2Impl = "argon2-impl";
#endif
#ifdef XMRIG_ALGO_ASTROBWT
static const char* kAstroBWTMaxSize = "astrobwt-max-size";
static const char* kAstroBWTAVX2 = "astrobwt-avx2";
const char *CpuConfig::kAstroBWTMaxSize = "astrobwt-max-size";
const char *CpuConfig::kAstroBWTAVX2 = "astrobwt-avx2";
#endif
@ -76,6 +78,7 @@ rapidjson::Value xmrig::CpuConfig::toJSON(rapidjson::Document &doc) const
obj.AddMember(StringRef(kEnabled), m_enabled, allocator);
obj.AddMember(StringRef(kHugePages), m_hugePages, allocator);
obj.AddMember(StringRef(kHugePagesJit), m_hugePagesJit, allocator);
obj.AddMember(StringRef(kHwAes), m_aes == AES_AUTO ? Value(kNullType) : Value(m_aes == AES_HW), allocator);
obj.AddMember(StringRef(kPriority), priority() != -1 ? Value(priority()) : Value(kNullType), allocator);
obj.AddMember(StringRef(kMemoryPool), m_memoryPool < 1 ? Value(m_memoryPool < 0) : Value(m_memoryPool), allocator);
@ -110,7 +113,7 @@ size_t xmrig::CpuConfig::memPoolSize() const
}
std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, const Algorithm &algorithm) const
std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, const Algorithm &algorithm, uint32_t benchSize) const
{
std::vector<CpuLaunchData> out;
const CpuThreads &threads = m_threads.get(algorithm);
@ -122,7 +125,7 @@ std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, cons
out.reserve(threads.count());
for (const CpuThread &thread : threads.data()) {
out.emplace_back(miner, algorithm, *this, thread);
out.emplace_back(miner, algorithm, *this, thread, benchSize);
}
return out;
@ -132,10 +135,11 @@ std::vector<xmrig::CpuLaunchData> xmrig::CpuConfig::get(const Miner *miner, cons
void xmrig::CpuConfig::read(const rapidjson::Value &value)
{
if (value.IsObject()) {
m_enabled = Json::getBool(value, kEnabled, m_enabled);
m_hugePages = Json::getBool(value, kHugePages, m_hugePages);
m_limit = Json::getUint(value, kMaxThreadsHint, m_limit);
m_yield = Json::getBool(value, kYield, m_yield);
m_enabled = Json::getBool(value, kEnabled, m_enabled);
m_hugePages = Json::getBool(value, kHugePages, m_hugePages);
m_hugePagesJit = Json::getBool(value, kHugePagesJit, m_hugePagesJit);
m_limit = Json::getUint(value, kMaxThreadsHint, m_limit);
m_yield = Json::getBool(value, kYield, m_yield);
setAesMode(Json::getValue(value, kHwAes));
setPriority(Json::getInt(value, kPriority, -1));

View file

@ -44,16 +44,40 @@ public:
AES_SOFT
};
static const char *kEnabled;
static const char *kField;
static const char *kHugePages;
static const char *kHugePagesJit;
static const char *kHwAes;
static const char *kMaxThreadsHint;
static const char *kMemoryPool;
static const char *kPriority;
static const char *kYield;
# ifdef XMRIG_FEATURE_ASM
static const char *kAsm;
# endif
# ifdef XMRIG_ALGO_ARGON2
static const char *kArgon2Impl;
# endif
# ifdef XMRIG_ALGO_ASTROBWT
static const char *kAstroBWTMaxSize;
static const char *kAstroBWTAVX2;
# endif
CpuConfig() = default;
bool isHwAES() const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t memPoolSize() const;
std::vector<CpuLaunchData> get(const Miner *miner, const Algorithm &algorithm) const;
std::vector<CpuLaunchData> get(const Miner *miner, const Algorithm &algorithm, uint32_t benchSize) const;
void read(const rapidjson::Value &value);
inline bool isEnabled() const { return m_enabled; }
inline bool isHugePages() const { return m_hugePages; }
inline bool isHugePagesJit() const { return m_hugePagesJit; }
inline bool isShouldSave() const { return m_shouldSave; }
inline bool isYield() const { return m_yield; }
inline const Assembly &assembly() const { return m_assembly; }
@ -76,6 +100,7 @@ private:
bool m_astrobwtAVX2 = false;
bool m_enabled = true;
bool m_hugePages = true;
bool m_hugePagesJit = false;
bool m_shouldSave = false;
bool m_yield = true;
int m_astrobwtMaxSize = 550;

View file

@ -145,7 +145,7 @@ size_t inline generate<Algorithm::RANDOM_X>(Threads<CpuThreads> &threads, uint32
template<>
size_t inline generate<Algorithm::ARGON2>(Threads<CpuThreads> &threads, uint32_t limit)
{
return generate("argon2", threads, Algorithm::AR2_CHUKWA, limit);
return generate("argon2", threads, Algorithm::AR2_CHUKWA_V2, limit);
}
#endif

View file

@ -32,7 +32,7 @@
#include <algorithm>
xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread) :
xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread, uint32_t benchSize) :
algorithm(algorithm),
assembly(config.assembly()),
astrobwtAVX2(config.astrobwtAVX2()),
@ -43,6 +43,7 @@ xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorit
priority(config.priority()),
affinity(thread.affinity()),
miner(miner),
benchSize(benchSize),
intensity(std::min<uint32_t>(thread.intensity(), algorithm.maxIntensity()))
{
}

View file

@ -44,12 +44,12 @@ class Miner;
class CpuLaunchData
{
public:
CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread);
CpuLaunchData(const Miner *miner, const Algorithm &algorithm, const CpuConfig &config, const CpuThread &thread, uint32_t benchSize);
bool isEqual(const CpuLaunchData &other) const;
CnHash::AlgoVariant av() const;
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
inline constexpr static Nonce::Backend backend() { return Nonce::CPU; }
inline bool operator!=(const CpuLaunchData &other) const { return !isEqual(other); }
inline bool operator==(const CpuLaunchData &other) const { return isEqual(other); }
@ -66,6 +66,7 @@ public:
const int priority;
const int64_t affinity;
const Miner *miner;
const uint32_t benchSize;
const uint32_t intensity;
};

View file

@ -29,6 +29,7 @@
#include "backend/cpu/CpuWorker.h"
#include "base/tools/Chrono.h"
#include "core/Miner.h"
#include "crypto/cn/CnCtx.h"
#include "crypto/cn/CryptoNight_test.h"
@ -57,9 +58,9 @@ static constexpr uint32_t kReserveCount = 32768;
template<size_t N>
inline bool nextRound(WorkerJob<N> &job)
inline bool nextRound(WorkerJob<N> &job, uint32_t benchSize)
{
if (!job.nextRound(kReserveCount, 1)) {
if (!job.nextRound(benchSize ? 1 : kReserveCount, 1)) {
JobResults::done(job.currentJob());
return false;
@ -84,6 +85,7 @@ xmrig::CpuWorker<N>::CpuWorker(size_t id, const CpuLaunchData &data) :
m_av(data.av()),
m_astrobwtMaxSize(data.astrobwtMaxSize * 1000),
m_miner(data.miner),
m_benchSize(data.benchSize),
m_ctx()
{
m_memory = new VirtualMemory(m_algorithm.l3() * N, data.hugePages, false, true, m_node);
@ -180,6 +182,7 @@ bool xmrig::CpuWorker<N>::selfTest()
# ifdef XMRIG_ALGO_ARGON2
if (m_algorithm.family() == Algorithm::ARGON2) {
return verify(Algorithm::AR2_CHUKWA, argon2_chukwa_test_out) &&
verify(Algorithm::AR2_CHUKWA_V2, argon2_chukwa_v2_test_out) &&
verify(Algorithm::AR2_WRKZ, argon2_wrkz_test_out);
}
# endif
@ -211,23 +214,12 @@ void xmrig::CpuWorker<N>::start()
consumeJob();
}
uint64_t storeStatsMask = 7;
# ifdef XMRIG_ALGO_RANDOMX
bool first = true;
uint64_t tempHash[8] = {};
// RandomX is faster, we don't need to store stats so often
if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) {
storeStatsMask = 63;
}
alignas(16) uint64_t tempHash[8] = {};
# endif
while (!Nonce::isOutdated(Nonce::CPU, m_job.sequence())) {
if ((m_count & storeStatsMask) == 0) {
storeStats();
}
const Job &job = m_job.currentJob();
if (job.algorithm().l3() != m_algorithm.l3()) {
@ -248,7 +240,7 @@ void xmrig::CpuWorker<N>::start()
randomx_calculate_hash_first(m_vm, tempHash, m_job.blob(), job.size());
}
if (!nextRound(m_job)) {
if (!nextRound(m_job, m_benchSize)) {
break;
}
@ -268,14 +260,28 @@ void xmrig::CpuWorker<N>::start()
fn(job.algorithm())(m_job.blob(), job.size(), m_hash, m_ctx, job.height());
}
if (!nextRound(m_job)) {
if (!nextRound(m_job, m_benchSize)) {
break;
};
}
if (valid) {
for (size_t i = 0; i < N; ++i) {
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < job.target()) {
const uint64_t value = *reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24);
# ifdef XMRIG_FEATURE_BENCHMARK
if (m_benchSize) {
if (current_job_nonces[i] < m_benchSize) {
m_benchData ^= value;
}
else {
m_benchDoneTime = Chrono::steadyMSecs();
return;
}
}
else
# endif
if (value < job.target()) {
JobResults::submit(job, current_job_nonces[i], m_hash + (i * 32));
}
}
@ -372,7 +378,7 @@ void xmrig::CpuWorker<N>::consumeJob()
return;
}
m_job.add(m_miner->job(), kReserveCount, Nonce::CPU);
m_job.add(m_miner->job(), m_benchSize ? 1 : kReserveCount, Nonce::CPU);
# ifdef XMRIG_ALGO_RANDOMX
if (m_job.currentJob().algorithm().family() == Algorithm::RANDOM_X) {

View file

@ -73,6 +73,7 @@ private:
void allocateCnCtx();
void consumeJob();
alignas(16) uint8_t m_hash[N * 32]{ 0 };
const Algorithm m_algorithm;
const Assembly m_assembly;
const bool m_astrobwtAVX2;
@ -81,8 +82,8 @@ private:
const CnHash::AlgoVariant m_av;
const int m_astrobwtMaxSize;
const Miner *m_miner;
const uint32_t m_benchSize;
cryptonight_ctx *m_ctx[N];
uint8_t m_hash[N * 32]{ 0 };
VirtualMemory *m_memory = nullptr;
WorkerJob<N> m_job;

View file

@ -409,9 +409,9 @@ void xmrig::CudaBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") GREEN(" %s"),
i,
data.thread.affinity(),
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.name().data()
@ -421,9 +421,9 @@ void xmrig::CudaBackend::printHashrate(bool details)
}
Log::print(WHITE_BOLD_S "| - | - | %8s | %8s | %8s |",
Hashrate::format(hashrate()->calc(Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3)
Hashrate::format(hashrate_short * scale, num, sizeof num / 3),
Hashrate::format(hashrate_medium * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large * scale, num + 16 * 2, sizeof num / 3)
);
}
@ -501,9 +501,9 @@ void xmrig::CudaBackend::stop()
}
void xmrig::CudaBackend::tick(uint64_t ticks)
bool xmrig::CudaBackend::tick(uint64_t ticks)
{
d_ptr->workers.tick(ticks);
return d_ptr->workers.tick(ticks);
}

View file

@ -63,13 +63,18 @@ protected:
void setJob(const Job &job) override;
void start(IWorker *worker, bool ready) override;
void stop() override;
void tick(uint64_t ticks) override;
bool tick(uint64_t ticks) override;
# ifdef XMRIG_FEATURE_API
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
void handleRequest(IApiRequest &request) override;
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
inline Benchmark *benchmark() const override { return nullptr; }
inline void printBenchProgress() const override {}
# endif
private:
CudaBackendPrivate *d_ptr;
};

View file

@ -30,9 +30,9 @@
xmrig::CudaLaunchData::CudaLaunchData(const Miner *miner, const Algorithm &algorithm, const CudaThread &thread, const CudaDevice &device) :
algorithm(algorithm),
miner(miner),
device(device),
thread(thread)
thread(thread),
miner(miner)
{
}

View file

@ -54,9 +54,10 @@ public:
static const char *tag();
const Algorithm algorithm;
const Miner *miner;
const CudaDevice &device;
const CudaThread thread;
const Miner *miner;
const uint32_t benchSize = 0;
};

View file

@ -62,7 +62,6 @@ std::atomic<bool> CudaWorker::ready;
static inline bool isReady() { return !Nonce::isPaused() && CudaWorker::ready; }
static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / intensity + 1; }
} // namespace xmrig
@ -120,6 +119,12 @@ xmrig::CudaWorker::~CudaWorker()
}
uint64_t xmrig::CudaWorker::rawHashes() const
{
return m_hashrateData.interpolate(Chrono::steadyMSecs());
}
void xmrig::CudaWorker::jobEarlyNotification(const Job& job)
{
if (m_runner) {
@ -170,8 +175,7 @@ void xmrig::CudaWorker::start()
JobResults::submit(m_job.currentJob(), foundNonce, foundCount, m_deviceIndex);
}
const size_t batch_size = intensity();
if (!Nonce::isOutdated(Nonce::CUDA, m_job.sequence()) && !m_job.nextRound(roundSize(batch_size), batch_size)) {
if (!Nonce::isOutdated(Nonce::CUDA, m_job.sequence()) && !m_job.nextRound(1, intensity())) {
JobResults::done(m_job.currentJob());
}
@ -192,8 +196,7 @@ bool xmrig::CudaWorker::consumeJob()
return false;
}
const size_t batch_size = intensity();
m_job.add(m_miner->job(), roundSize(batch_size) * batch_size, Nonce::CUDA);
m_job.add(m_miner->job(), intensity(), Nonce::CUDA);
return m_runner->set(m_job.currentJob(), m_job.blob());
}
@ -207,5 +210,8 @@ void xmrig::CudaWorker::storeStats()
m_count += m_runner ? m_runner->processedHashes() : 0;
const uint64_t timeStamp = Chrono::steadyMSecs();
m_hashrateData.addDataPoint(m_count, timeStamp);
Worker::storeStats();
}

View file

@ -27,6 +27,7 @@
#define XMRIG_CUDAWORKER_H
#include "backend/common/HashrateInterpolator.h"
#include "backend/common/Worker.h"
#include "backend/common/WorkerJob.h"
#include "backend/cuda/CudaLaunchData.h"
@ -49,6 +50,7 @@ public:
~CudaWorker() override;
uint64_t rawHashes() const override;
void jobEarlyNotification(const Job&) override;
static std::atomic<bool> ready;
@ -67,6 +69,8 @@ private:
ICudaRunner *m_runner = nullptr;
WorkerJob<1> m_job;
uint32_t m_deviceIndex;
HashrateInterpolator m_hashrateData;
};

View file

@ -385,9 +385,9 @@ void xmrig::OclBackend::printHashrate(bool details)
Log::print("| %8zu | %8" PRId64 " | %8s | %8s | %8s |" CYAN_BOLD(" #%u") YELLOW(" %s") " %s",
i,
data.affinity,
Hashrate::format(hashrate()->calc(i, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(i + 1, Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3),
data.device.index(),
data.device.topology().toString().data(),
data.device.printableName().data()
@ -397,9 +397,9 @@ void xmrig::OclBackend::printHashrate(bool details)
}
Log::print(WHITE_BOLD_S "| - | - | %8s | %8s | %8s |",
Hashrate::format(hashrate()->calc(Hashrate::ShortInterval) * scale, num, sizeof num / 3),
Hashrate::format(hashrate()->calc(Hashrate::MediumInterval) * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate()->calc(Hashrate::LargeInterval) * scale, num + 16 * 2, sizeof num / 3)
Hashrate::format(hashrate_short * scale, num, sizeof num / 3),
Hashrate::format(hashrate_medium * scale, num + 16, sizeof num / 3),
Hashrate::format(hashrate_large * scale, num + 16 * 2, sizeof num / 3)
);
}
@ -485,9 +485,9 @@ void xmrig::OclBackend::stop()
}
void xmrig::OclBackend::tick(uint64_t ticks)
bool xmrig::OclBackend::tick(uint64_t ticks)
{
d_ptr->workers.tick(ticks);
return d_ptr->workers.tick(ticks);
}

View file

@ -63,13 +63,18 @@ protected:
void setJob(const Job &job) override;
void start(IWorker *worker, bool ready) override;
void stop() override;
void tick(uint64_t ticks) override;
bool tick(uint64_t ticks) override;
# ifdef XMRIG_FEATURE_API
rapidjson::Value toJSON(rapidjson::Document &doc) const override;
void handleRequest(IApiRequest &request) override;
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
inline Benchmark *benchmark() const override { return nullptr; }
inline void printBenchProgress() const override {}
# endif
private:
OclBackendPrivate *d_ptr;
};

View file

@ -67,6 +67,7 @@ public:
const OclDevice device;
const OclPlatform platform;
const OclThread thread;
const uint32_t benchSize = 0;
};

View file

@ -56,12 +56,10 @@
namespace xmrig {
static constexpr uint32_t kReserveCount = 32768;
std::atomic<bool> OclWorker::ready;
static inline bool isReady() { return !Nonce::isPaused() && OclWorker::ready; }
static inline uint32_t roundSize(uint32_t intensity) { return kReserveCount / intensity + 1; }
static inline void printError(size_t id, const char *error)
@ -78,7 +76,6 @@ xmrig::OclWorker::OclWorker(size_t id, const OclLaunchData &data) :
Worker(id, data.affinity, -1),
m_algorithm(data.algorithm),
m_miner(data.miner),
m_intensity(data.thread.intensity()),
m_sharedData(OclSharedState::get(data.device.index())),
m_deviceIndex(data.device.index())
{
@ -140,6 +137,12 @@ xmrig::OclWorker::~OclWorker()
}
uint64_t xmrig::OclWorker::rawHashes() const
{
return m_hashrateData.interpolate(Chrono::steadyMSecs());
}
void xmrig::OclWorker::jobEarlyNotification(const Job& job)
{
if (m_runner) {
@ -164,8 +167,6 @@ void xmrig::OclWorker::start()
{
cl_uint results[0x100];
const uint32_t runnerRoundSize = m_runner->roundSize();
while (Nonce::sequence(Nonce::OPENCL) > 0) {
if (!isReady()) {
m_sharedData.setResumeCounter(0);
@ -204,7 +205,7 @@ void xmrig::OclWorker::start()
JobResults::submit(m_job.currentJob(), results, results[0xFF], m_deviceIndex);
}
if (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence()) && !m_job.nextRound(roundSize(runnerRoundSize), runnerRoundSize)) {
if (!Nonce::isOutdated(Nonce::OPENCL, m_job.sequence()) && !m_job.nextRound(1, intensity())) {
JobResults::done(m_job.currentJob());
}
@ -225,7 +226,7 @@ bool xmrig::OclWorker::consumeJob()
return false;
}
m_job.add(m_miner->job(), roundSize(m_intensity) * m_intensity, Nonce::OPENCL);
m_job.add(m_miner->job(), intensity(), Nonce::OPENCL);
try {
m_runner->set(m_job.currentJob(), m_job.blob());
@ -247,8 +248,11 @@ void xmrig::OclWorker::storeStats(uint64_t t)
}
m_count += m_runner->processedHashes();
const uint64_t timeStamp = Chrono::steadyMSecs();
m_sharedData.setRunTime(Chrono::steadyMSecs() - t);
m_hashrateData.addDataPoint(m_count, timeStamp);
m_sharedData.setRunTime(timeStamp - t);
Worker::storeStats();
}

View file

@ -27,6 +27,7 @@
#define XMRIG_OCLWORKER_H
#include "backend/common/HashrateInterpolator.h"
#include "backend/common/Worker.h"
#include "backend/common/WorkerJob.h"
#include "backend/opencl/OclLaunchData.h"
@ -50,6 +51,7 @@ public:
~OclWorker() override;
uint64_t rawHashes() const override;
void jobEarlyNotification(const Job&) override;
static std::atomic<bool> ready;
@ -65,11 +67,12 @@ private:
const Algorithm m_algorithm;
const Miner *m_miner;
const uint32_t m_intensity;
IOclRunner *m_runner = nullptr;
OclSharedData &m_sharedData;
WorkerJob<1> m_job;
uint32_t m_deviceIndex;
HashrateInterpolator m_hashrateData;
};

View file

@ -19,11 +19,11 @@
#define ALGO_CN_CCX 18
#define ALGO_RX_0 19
#define ALGO_RX_WOW 20
#define ALGO_RX_LOKI 21
#define ALGO_RX_ARQMA 22
#define ALGO_RX_SFX 23
#define ALGO_RX_KEVA 24
#define ALGO_AR2_CHUKWA 25
#define ALGO_RX_ARQMA 21
#define ALGO_RX_SFX 22
#define ALGO_RX_KEVA 23
#define ALGO_AR2_CHUKWA 24
#define ALGO_AR2_CHUKWA_V2 25
#define ALGO_AR2_WRKZ 26
#define ALGO_ASTROBWT_DERO 27
#define ALGO_KAWPOW_RVN 28

File diff suppressed because it is too large Load diff

View file

@ -4,8 +4,6 @@
#include "randomx_constants_monero.h"
#elif (ALGO == ALGO_RX_WOW)
#include "randomx_constants_wow.h"
#elif (ALGO == ALGO_RX_LOKI)
#include "randomx_constants_loki.h"
#elif (ALGO == ALGO_RX_ARQMA)
#include "randomx_constants_arqma.h"
#elif (ALGO == ALGO_RX_KEVA)

File diff suppressed because it is too large Load diff

View file

@ -1,96 +0,0 @@
/*
Copyright (c) 2019 SChernykh
This file is part of RandomX OpenCL.
RandomX OpenCL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RandomX OpenCL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RandomX OpenCL. If not, see <http://www.gnu.org/licenses/>.
*/
//Dataset base size in bytes. Must be a power of 2.
#define RANDOMX_DATASET_BASE_SIZE 2147483648
//Dataset extra size. Must be divisible by 64.
#define RANDOMX_DATASET_EXTRA_SIZE 33554368
//Scratchpad L3 size in bytes. Must be a power of 2.
#define RANDOMX_SCRATCHPAD_L3 2097152
//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3.
#define RANDOMX_SCRATCHPAD_L2 262144
//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2.
#define RANDOMX_SCRATCHPAD_L1 16384
//Jump condition mask size in bits.
#define RANDOMX_JUMP_BITS 8
//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16.
#define RANDOMX_JUMP_OFFSET 8
//Integer instructions
#define RANDOMX_FREQ_IADD_RS 25
#define RANDOMX_FREQ_IADD_M 7
#define RANDOMX_FREQ_ISUB_R 16
#define RANDOMX_FREQ_ISUB_M 7
#define RANDOMX_FREQ_IMUL_R 16
#define RANDOMX_FREQ_IMUL_M 4
#define RANDOMX_FREQ_IMULH_R 4
#define RANDOMX_FREQ_IMULH_M 1
#define RANDOMX_FREQ_ISMULH_R 4
#define RANDOMX_FREQ_ISMULH_M 1
#define RANDOMX_FREQ_IMUL_RCP 8
#define RANDOMX_FREQ_INEG_R 2
#define RANDOMX_FREQ_IXOR_R 15
#define RANDOMX_FREQ_IXOR_M 5
#define RANDOMX_FREQ_IROR_R 8
#define RANDOMX_FREQ_IROL_R 2
#define RANDOMX_FREQ_ISWAP_R 4
//Floating point instructions
#define RANDOMX_FREQ_FSWAP_R 4
#define RANDOMX_FREQ_FADD_R 16
#define RANDOMX_FREQ_FADD_M 5
#define RANDOMX_FREQ_FSUB_R 16
#define RANDOMX_FREQ_FSUB_M 5
#define RANDOMX_FREQ_FSCAL_R 6
#define RANDOMX_FREQ_FMUL_R 32
#define RANDOMX_FREQ_FDIV_M 4
#define RANDOMX_FREQ_FSQRT_R 6
//Control instructions
#define RANDOMX_FREQ_CBRANCH 16
#define RANDOMX_FREQ_CFROUND 1
//Store instruction
#define RANDOMX_FREQ_ISTORE 16
//No-op instruction
#define RANDOMX_FREQ_NOP 0
#define RANDOMX_DATASET_ITEM_SIZE 64
#define RANDOMX_PROGRAM_SIZE 320
#define HASH_SIZE 64
#define ENTROPY_SIZE (128 + RANDOMX_PROGRAM_SIZE * 8)
#define REGISTERS_SIZE 256
#define IMM_BUF_SIZE (RANDOMX_PROGRAM_SIZE * 4 - REGISTERS_SIZE)
#define IMM_INDEX_COUNT ((IMM_BUF_SIZE / 4) - 2)
#define VM_STATE_SIZE (REGISTERS_SIZE + IMM_BUF_SIZE + RANDOMX_PROGRAM_SIZE * 4)
#define ROUNDING_MODE (RANDOMX_FREQ_CFROUND ? -1 : 0)
// Scratchpad L1/L2/L3 bits
#define LOC_L1 (32 - 14)
#define LOC_L2 (32 - 18)
#define LOC_L3 (32 - 21)

View file

@ -127,6 +127,7 @@ elseif (APPLE)
)
else()
set(SOURCES_OS
src/base/io/Async.cpp
src/base/io/json/Json_unix.cpp
src/base/kernel/Platform_unix.cpp
)
@ -226,11 +227,16 @@ endif()
if (WITH_PROFILING)
add_definitions(/DXMRIG_FEATURE_PROFILING)
list(APPEND HEADERS_BASE
src/base/tools/Profiler.h
)
list(APPEND SOURCES_BASE
src/base/tools/Profiler.cpp
)
list(APPEND HEADERS_BASE src/base/tools/Profiler.h)
list(APPEND SOURCES_BASE src/base/tools/Profiler.cpp)
endif()
if (WITH_RANDOMX AND WITH_BENCHMARK)
add_definitions(/DXMRIG_FEATURE_BENCHMARK)
list(APPEND HEADERS_BASE src/base/net/stratum/NullClient.h)
list(APPEND SOURCES_BASE src/base/net/stratum/NullClient.cpp)
else()
remove_definitions(/DXMRIG_FEATURE_BENCHMARK)
endif()

View file

@ -105,8 +105,6 @@ static AlgoName const algorithm_names[] = {
{ "RandomX", "rx", Algorithm::RX_0 },
{ "randomx/wow", "rx/wow", Algorithm::RX_WOW },
{ "RandomWOW", nullptr, Algorithm::RX_WOW },
{ "randomx/loki", "rx/loki", Algorithm::RX_LOKI },
{ "RandomXL", nullptr, Algorithm::RX_LOKI },
{ "randomx/arq", "rx/arq", Algorithm::RX_ARQ },
{ "RandomARQ", nullptr, Algorithm::RX_ARQ },
{ "randomx/sfx", "rx/sfx", Algorithm::RX_SFX },
@ -117,6 +115,8 @@ static AlgoName const algorithm_names[] = {
# ifdef XMRIG_ALGO_ARGON2
{ "argon2/chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "chukwa", nullptr, Algorithm::AR2_CHUKWA },
{ "argon2/chukwav2", nullptr, Algorithm::AR2_CHUKWA_V2 },
{ "chukwav2", nullptr, Algorithm::AR2_CHUKWA_V2 },
{ "argon2/wrkz", nullptr, Algorithm::AR2_WRKZ },
# endif
# ifdef XMRIG_ALGO_ASTROBWT
@ -160,7 +160,6 @@ size_t xmrig::Algorithm::l2() const
# ifdef XMRIG_ALGO_RANDOMX
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return 0x40000;
@ -208,7 +207,6 @@ size_t xmrig::Algorithm::l3() const
if (f == RANDOM_X) {
switch (m_id) {
case RX_0:
case RX_LOKI:
case RX_SFX:
return oneMiB * 2;
@ -231,6 +229,9 @@ size_t xmrig::Algorithm::l3() const
case AR2_CHUKWA:
return oneMiB / 2;
case AR2_CHUKWA_V2:
return oneMiB;
case AR2_WRKZ:
return oneMiB / 4;
@ -331,7 +332,6 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
# ifdef XMRIG_ALGO_RANDOMX
case RX_0:
case RX_WOW:
case RX_LOKI:
case RX_ARQ:
case RX_SFX:
case RX_KEVA:
@ -340,6 +340,7 @@ xmrig::Algorithm::Family xmrig::Algorithm::family(Id id)
# ifdef XMRIG_ALGO_ARGON2
case AR2_CHUKWA:
case AR2_CHUKWA_V2:
case AR2_WRKZ:
return ARGON2;
# endif

View file

@ -66,11 +66,11 @@ public:
CN_CCX, // "cn/ccx" Conceal (CCX)
RX_0, // "rx/0" RandomX (reference configuration).
RX_WOW, // "rx/wow" RandomWOW (Wownero).
RX_LOKI, // "rx/loki" RandomXL (Loki).
RX_ARQ, // "rx/arq" RandomARQ (Arqma).
RX_SFX, // "rx/sfx" RandomSFX (Safex Cash).
RX_KEVA, // "rx/keva" RandomKEVA (Keva).
AR2_CHUKWA, // "argon2/chukwa" Argon2id (Chukwa).
AR2_CHUKWA_V2, // "argon2/chukwav2" Argon2id (Chukwa v2).
AR2_WRKZ, // "argon2/wrkz" Argon2id (WRKZ)
ASTROBWT_DERO, // "astrobwt" AstroBWT (Dero)
KAWPOW_RVN, // "kawpow/rvn" KawPow (RVN)

98
src/base/io/Async.cpp Normal file
View file

@ -0,0 +1,98 @@
/* XMRig
* Copyright (c) 2015-2020 libuv project contributors.
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/io/Async.h"
#if defined(XMRIG_UV_PERFORMANCE_BUG)
#include <sys/eventfd.h>
#include <sys/poll.h>
#include <unistd.h>
#include <cstdlib>
namespace xmrig {
uv_async_t::~uv_async_t()
{
close(m_fd);
}
static void on_schedule(uv_poll_t *handle, int status, int events)
{
static uint64_t val;
uv_async_t *async = reinterpret_cast<uv_async_t *>(handle);
for (;;) {
int r = read(async->m_fd, &val, sizeof(val));
if (r == sizeof(val))
continue;
if (r != -1)
break;
if (errno == EAGAIN || errno == EWOULDBLOCK)
break;
if (errno == EINTR)
continue;
abort();
}
if (async->m_cb) {
(*async->m_cb)(async);
}
}
int uv_async_init(uv_loop_t *loop, uv_async_t *async, uv_async_cb cb)
{
int fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (fd < 0) {
return uv_translate_sys_error(errno);
}
uv_poll_init(loop, (uv_poll_t *)async, fd);
uv_poll_start((uv_poll_t *)async, POLLIN, on_schedule);
async->m_cb = cb;
async->m_fd = fd;
return 0;
}
int uv_async_send(uv_async_t *async)
{
static const uint64_t val = 1;
int r;
do {
r = write(async->m_fd, &val, sizeof(val));
}
while (r == -1 && errno == EINTR);
if (r == sizeof(val) || (r == 1 && (errno == EAGAIN || errno == EWOULDBLOCK))) {
return 0;
}
abort();
}
} // namespace xmrig
#endif

52
src/base/io/Async.h Normal file
View file

@ -0,0 +1,52 @@
/* XMRig
* Copyright (c) 2015-2020 libuv project contributors.
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_ASYNC_H
#define XMRIG_ASYNC_H
#include <uv.h>
// since 2019.05.16, Version 1.29.0 (Stable)
#if (UV_VERSION_MAJOR >= 1) && (UV_VERSION_MINOR >= 29) && defined(__linux__)
#define XMRIG_UV_PERFORMANCE_BUG
namespace xmrig {
struct uv_async_t: uv_poll_t
{
typedef void (*uv_async_cb)(uv_async_t* handle);
~uv_async_t();
int m_fd = -1;
uv_async_cb m_cb = nullptr;
};
using uv_async_cb = uv_async_t::uv_async_cb;
extern int uv_async_init(uv_loop_t *loop, uv_async_t *async, uv_async_cb cb);
extern int uv_async_send(uv_async_t *async);
} // namespace xmrig
#endif
#endif /* XMRIG_ASYNC_H */

View file

@ -103,6 +103,7 @@ private:
#define WHITE_S CSI "0;37m" // another name for LT.GRAY
#define WHITE_BOLD_S CSI "1;37m" // actually white
#define RED_BG_BOLD_S CSI "41;1m"
#define GREEN_BG_BOLD_S CSI "42;1m"
#define YELLOW_BG_BOLD_S CSI "43;1m"
#define BLUE_BG_S CSI "44m"
@ -130,6 +131,7 @@ private:
#define WHITE(x) WHITE_S x CLEAR
#define WHITE_BOLD(x) WHITE_BOLD_S x CLEAR
#define RED_BG_BOLD(x) RED_BG_BOLD_S x CLEAR
#define GREEN_BG_BOLD(x) GREEN_BG_BOLD_S x CLEAR
#define YELLOW_BG_BOLD(x) YELLOW_BG_BOLD_S x CLEAR
#define BLUE_BG(x) BLUE_BG_S x CLEAR

View file

@ -70,6 +70,16 @@ const char *xmrig::Tags::randomx()
return tag;
}
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
const char *xmrig::Tags::bench()
{
static const char *tag = GREEN_BG_BOLD(WHITE_BOLD_S " bench ");
return tag;
}
#endif
#endif

View file

@ -40,6 +40,9 @@ public:
# ifdef XMRIG_ALGO_RANDOMX
static const char *randomx();
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
static const char *bench();
# endif
# endif
# ifdef XMRIG_PROXY_PROJECT

View file

@ -151,7 +151,9 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
}
break;
case IConfig::UrlKey: /* --url */
case IConfig::UrlKey: /* --url */
case IConfig::StressKey: /* --stress */
case IConfig::BenchKey: /* --bench */
{
if (!doc.HasMember(Pools::kPools)) {
doc.AddMember(rapidjson::StringRef(Pools::kPools), rapidjson::kArrayType, doc.GetAllocator());
@ -162,7 +164,20 @@ void xmrig::BaseTransform::transform(rapidjson::Document &doc, int key, const ch
array.PushBack(rapidjson::kObjectType, doc.GetAllocator());
}
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
# ifdef XMRIG_FEATURE_BENCHMARK
if (key != IConfig::UrlKey) {
set(doc, array[array.Size() - 1], Pool::kUrl, (key == IConfig::BenchKey) ? "benchmark" :
# ifdef XMRIG_FEATURE_TLS
"stratum+ssl://randomx.xmrig.com:443"
# else
"randomx.xmrig.com:3333"
# endif
);
} else
# endif
{
set(doc, array[array.Size() - 1], Pool::kUrl, arg);
}
break;
}

View file

@ -77,6 +77,8 @@ public:
TitleKey = 1037,
NoTitleKey = 1038,
PauseOnBatteryKey = 1041,
StressKey = 1042,
BenchKey = 1043,
// xmrig common
CPUPriorityKey = 1021,

View file

@ -6,9 +6,9 @@
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
* Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2019 Howard Chu <https://github.com/hyc>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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

View file

@ -0,0 +1,62 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "base/net/stratum/NullClient.h"
#include "3rdparty/rapidjson/document.h"
#include "base/kernel/interfaces/IClientListener.h"
xmrig::NullClient::NullClient(IClientListener* listener) :
m_listener(listener)
{
m_job.setAlgorithm(Algorithm::RX_0);
std::vector<char> blob(112 * 2 + 1, '0');
blob.back() = '\0';
m_job.setBlob(blob.data());
blob[Job::kMaxSeedSize * 2] = '\0';
m_job.setSeedHash(blob.data());
m_job.setDiff(uint64_t(-1));
m_job.setHeight(1);
m_job.setId("00000000");
}
void xmrig::NullClient::connect()
{
m_listener->onLoginSuccess(this);
rapidjson::Value params;
m_listener->onJobReceived(this, m_job, params);
}
void xmrig::NullClient::setPool(const Pool& pool)
{
m_pool = pool;
if (!m_pool.algorithm().isValid()) {
m_pool.setAlgo(Algorithm::RX_0);
}
m_job.setAlgorithm(m_pool.algorithm().id());
}

View file

@ -0,0 +1,77 @@
/* XMRig
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_NULLCLIENT_H
#define XMRIG_NULLCLIENT_H
#include "base/net/stratum/Client.h"
namespace xmrig {
class NullClient : public IClient
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(NullClient)
NullClient(IClientListener* listener);
~NullClient() override = default;
inline bool disconnect() override { return true; }
inline bool hasExtension(Extension extension) const noexcept override { return false; }
inline bool isEnabled() const override { return true; }
inline bool isTLS() const override { return false; }
inline const char *mode() const override { return "benchmark"; }
inline const char *tag() const override { return "null"; }
inline const char *tlsFingerprint() const override { return nullptr; }
inline const char *tlsVersion() const override { return nullptr; }
inline const Job &job() const override { return m_job; }
inline const Pool &pool() const override { return m_pool; }
inline const String &ip() const override { return m_ip; }
inline int id() const override { return 0; }
inline int64_t send(const rapidjson::Value& obj, Callback callback) override { return 0; }
inline int64_t send(const rapidjson::Value& obj) override { return 0; }
inline int64_t sequence() const override { return 0; }
inline int64_t submit(const JobResult& result) override { return 0; }
inline void connect(const Pool& pool) override { setPool(pool); }
inline void deleteLater() override {}
inline void setAlgo(const Algorithm& algo) override {}
inline void setEnabled(bool enabled) override {}
inline void setProxy(const ProxyUrl& proxy) override {}
inline void setQuiet(bool quiet) override {}
inline void setRetries(int retries) override {}
inline void setRetryPause(uint64_t ms) override {}
inline void tick(uint64_t now) override {}
void connect() override;
void setPool(const Pool& pool) override;
private:
IClientListener* m_listener;
Job m_job;
Pool m_pool;
String m_ip;
};
} /* namespace xmrig */
#endif /* XMRIG_NULLCLIENT_H */

View file

@ -50,6 +50,16 @@
#endif
#ifdef XMRIG_FEATURE_BENCHMARK
# include "base/net/stratum/NullClient.h"
#endif
#ifdef _MSC_VER
# define strcasecmp _stricmp
#endif
namespace xmrig {
@ -72,9 +82,11 @@ const char *Pool::kSOCKS5 = "socks5";
const char *Pool::kTls = "tls";
const char *Pool::kUrl = "url";
const char *Pool::kUser = "user";
const char *Pool::kNicehashHost = "nicehash.com";
const char *Pool::kNicehashHost = "nicehash.com";
#ifdef XMRIG_FEATURE_BENCHMARK
const char *Pool::kBenchmark = "benchmark";
#endif
}
@ -125,20 +137,22 @@ xmrig::Pool::Pool(const rapidjson::Value &object) :
m_flags.set(FLAG_NICEHASH, Json::getBool(object, kNicehash) || m_url.host().contains(kNicehashHost));
m_flags.set(FLAG_TLS, Json::getBool(object, kTls) || m_url.isTLS());
setKeepAlive(Json::getValue(object, kKeepalive));
# ifdef XMRIG_FEATURE_BENCHMARK
if (setBenchSize(Json::getString(object, kBenchmark, nullptr))) {
m_mode = MODE_BENCHMARK;
return;
}
# endif
if (m_daemon.isValid()) {
m_mode = MODE_SELF_SELECT;
}
else if (Json::getBool(object, kDaemon)) {
m_mode = MODE_DAEMON;
}
const rapidjson::Value &keepalive = Json::getValue(object, kKeepalive);
if (keepalive.IsInt()) {
setKeepAlive(keepalive.GetInt());
}
else if (keepalive.IsBool()) {
setKeepAlive(keepalive.GetBool());
}
}
@ -217,6 +231,11 @@ xmrig::IClient *xmrig::Pool::createClient(int id, IClientListener *listener) con
client = new AutoClient(id, Platform::userAgent(), listener);
}
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
else if (m_mode == MODE_BENCHMARK) {
client = new NullClient(listener);
}
# endif
assert(client != nullptr);
@ -307,3 +326,34 @@ void xmrig::Pool::print() const
LOG_DEBUG ("keepAlive: %d", m_keepAlive);
}
#endif
void xmrig::Pool::setKeepAlive(const rapidjson::Value &value)
{
if (value.IsInt()) {
setKeepAlive(value.GetInt());
}
else if (value.IsBool()) {
setKeepAlive(value.GetBool());
}
}
#ifdef XMRIG_FEATURE_BENCHMARK
bool xmrig::Pool::setBenchSize(const char *benchmark)
{
if (!benchmark) {
return false;
}
const auto size = strtoul(benchmark, nullptr, 10);
if (size < 1 || size > 10) {
return false;
}
const std::string s = std::to_string(size) + "M";
m_benchSize = strcasecmp(benchmark, s.c_str()) == 0 ? size * 1000000 : 0;
return m_benchSize > 0;
}
#endif

View file

@ -50,7 +50,10 @@ public:
MODE_POOL,
MODE_DAEMON,
MODE_SELF_SELECT,
MODE_AUTO_ETH
MODE_AUTO_ETH,
# ifdef XMRIG_FEATURE_BENCHMARK
MODE_BENCHMARK,
# endif
};
static const String kDefaultPassword;
@ -73,6 +76,10 @@ public:
static const char *kUser;
static const char *kNicehashHost;
# ifdef XMRIG_FEATURE_BENCHMARK
static const char *kBenchmark;
# endif
constexpr static int kKeepAliveTimeout = 60;
constexpr static uint16_t kDefaultPort = 3333;
constexpr static uint64_t kDefaultPollInterval = 1000;
@ -105,6 +112,10 @@ public:
inline void setRigId(const String &rigId) { m_rigId = rigId; }
inline void setUser(const String &user) { m_user = user; }
# ifdef XMRIG_FEATURE_BENCHMARK
inline uint32_t benchSize() const { return m_benchSize; }
# endif
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
inline bool operator==(const Pool &other) const { return isEqual(other); }
@ -129,6 +140,8 @@ private:
inline void setKeepAlive(bool enable) { setKeepAlive(enable ? kKeepAliveTimeout : 0); }
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
void setKeepAlive(const rapidjson::Value &value);
Algorithm m_algorithm;
Coin m_coin;
int m_keepAlive = 0;
@ -142,6 +155,12 @@ private:
uint64_t m_pollInterval = kDefaultPollInterval;
Url m_daemon;
Url m_url;
# ifdef XMRIG_FEATURE_BENCHMARK
bool setBenchSize(const char *benchmark);
uint32_t m_benchSize = 0;
# endif
};

View file

@ -141,6 +141,18 @@ void xmrig::Pools::load(const IJsonReader &reader)
}
uint32_t xmrig::Pools::benchSize() const
{
# ifdef XMRIG_FEATURE_BENCHMARK
if (m_data.size() == 1 && m_data.front().mode() == Pool::MODE_BENCHMARK) {
return m_data.front().benchSize();
}
# endif
return 0;
}
void xmrig::Pools::print() const
{
size_t i = 1;

View file

@ -58,7 +58,7 @@ public:
Pools();
inline const std::vector<Pool> &data() const { return m_data; }
inline int donateLevel() const { return m_donateLevel; }
inline int donateLevel() const { return benchSize() ? 0 : m_donateLevel; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
inline ProxyDonate proxyDonate() const { return m_proxyDonate; }
@ -70,6 +70,7 @@ public:
IStrategy *createStrategy(IStrategyListener *listener) const;
rapidjson::Value toJSON(rapidjson::Document &doc) const;
size_t active() const;
uint32_t benchSize() const;
void load(const IJsonReader &reader);
void print() const;

View file

@ -38,12 +38,7 @@ void xmrig::LineReader::parse(char *data, size_t size)
return;
}
if (!m_buf) {
return getline(data, size);
}
add(data, size);
getline(m_buf, m_pos);
getline(data, size);
}
@ -60,6 +55,7 @@ void xmrig::LineReader::reset()
void xmrig::LineReader::add(const char *data, size_t size)
{
if (size > NetBuffer::kChunkSize - m_pos) {
// it breakes correctness silently for long lines
return;
}
@ -85,7 +81,12 @@ void xmrig::LineReader::getline(char *data, size_t size)
end++;
const auto len = static_cast<size_t>(end - start);
if (len > 1) {
if (m_pos) {
add(start, len);
m_listener->onLine(m_buf, m_pos - 1);
m_pos = 0;
}
else if (len > 1) {
m_listener->onLine(start, len - 1);
}
@ -97,7 +98,5 @@ void xmrig::LineReader::getline(char *data, size_t size)
return reset();
}
if (!m_buf || m_buf != data) {
add(start, remaining);
}
add(start, remaining);
}

View file

@ -27,6 +27,7 @@
"cpu": {
"enabled": true,
"huge-pages": true,
"huge-pages-jit": false,
"hw-aes": null,
"priority": null,
"memory-pool": false,

View file

@ -134,8 +134,6 @@ public:
Nonce::pause(true);
}
active = true;
if (reset) {
Nonce::reset(job.index());
}
@ -146,7 +144,7 @@ public:
Nonce::touch();
if (enabled) {
if (active && enabled) {
Nonce::pause(false);
}
@ -205,7 +203,7 @@ public:
continue;
}
for (size_t i = 0; i < hr->threads(); i++) {
for (size_t i = 1; i < hr->threads(); i++) {
Value thread(kArrayType);
thread.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::ShortInterval)), allocator);
thread.PushBack(Hashrate::normalize(hr->calc(i, Hashrate::MediumInterval)), allocator);
@ -244,30 +242,8 @@ public:
# endif
void printHashrate(bool details)
static inline void printProfile()
{
char num[16 * 4] = { 0 };
double speed[3] = { 0.0 };
for (auto backend : backends) {
const auto hashrate = backend->hashrate();
if (hashrate) {
speed[0] += hashrate->calc(Hashrate::ShortInterval);
speed[1] += hashrate->calc(Hashrate::MediumInterval);
speed[2] += hashrate->calc(Hashrate::LargeInterval);
}
backend->printHashrate(details);
}
double scale = 1.0;
const char* h = "H/s";
if ((speed[0] >= 1e6) || (speed[1] >= 1e6) || (speed[2] >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
scale = 1e-6;
h = "MH/s";
}
# ifdef XMRIG_FEATURE_PROFILING
ProfileScopeData* data[ProfileScopeData::MAX_DATA_COUNT];
@ -305,6 +281,41 @@ public:
i = n1;
}
# endif
}
void printHashrate(bool details)
{
char num[16 * 4] = { 0 };
double speed[3] = { 0.0 };
uint32_t count = 0;
for (auto backend : backends) {
const auto hashrate = backend->hashrate();
if (hashrate) {
++count;
speed[0] += hashrate->calc(Hashrate::ShortInterval);
speed[1] += hashrate->calc(Hashrate::MediumInterval);
speed[2] += hashrate->calc(Hashrate::LargeInterval);
}
backend->printHashrate(details);
}
if (!count) {
return;
}
printProfile();
double scale = 1.0;
const char* h = "H/s";
if ((speed[0] >= 1e6) || (speed[1] >= 1e6) || (speed[2] >= 1e6) || (maxHashrate[algorithm] >= 1e6)) {
scale = 1e-6;
h = "MH/s";
}
LOG_INFO("%s " WHITE_BOLD("speed") " 10s/60s/15m " CYAN_BOLD("%s") CYAN(" %s %s ") CYAN_BOLD("%s") " max " CYAN_BOLD("%s %s"),
Tags::miner(),
@ -313,6 +324,12 @@ public:
Hashrate::format(speed[2] * scale, num + 16 * 2, sizeof(num) / 4), h,
Hashrate::format(maxHashrate[algorithm] * scale, num + 16 * 3, sizeof(num) / 4), h
);
# ifdef XMRIG_FEATURE_BENCHMARK
for (auto backend : backends) {
backend->printBenchProgress();
}
# endif
}
@ -536,6 +553,8 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
mutex.unlock();
d_ptr->active = true;
if (ready) {
d_ptr->handleJobChange();
}
@ -573,8 +592,12 @@ void xmrig::Miner::onTimer(const Timer *)
double maxHashrate = 0.0;
const auto healthPrintTime = d_ptr->controller->config()->healthPrintTime();
bool stopMiner = false;
for (IBackend *backend : d_ptr->backends) {
backend->tick(d_ptr->ticks);
if (!backend->tick(d_ptr->ticks)) {
stopMiner = true;
}
if (healthPrintTime && d_ptr->ticks && (d_ptr->ticks % (healthPrintTime * 2)) == 0 && backend->isEnabled()) {
backend->printHealth();
@ -607,6 +630,10 @@ void xmrig::Miner::onTimer(const Timer *)
setEnabled(true);
}
}
if (stopMiner) {
stop();
}
}

View file

@ -53,11 +53,6 @@
namespace xmrig {
static const char *kCPU = "cpu";
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRandomX = "randomx";
#endif
#ifdef XMRIG_FEATURE_OPENCL
static const char *kOcl = "opencl";
@ -176,10 +171,10 @@ bool xmrig::Config::read(const IJsonReader &reader, const char *fileName)
return false;
}
d_ptr->cpu.read(reader.getValue(kCPU));
d_ptr->cpu.read(reader.getValue(CpuConfig::kField));
# ifdef XMRIG_ALGO_RANDOMX
if (!d_ptr->rx.read(reader.getValue(kRandomX))) {
if (!d_ptr->rx.read(reader.getValue(RxConfig::kField))) {
m_upgrade = true;
}
# endif
@ -220,10 +215,10 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
doc.AddMember(StringRef(kTitle), title().toJSON(), allocator);
# ifdef XMRIG_ALGO_RANDOMX
doc.AddMember(StringRef(kRandomX), rx().toJSON(doc), allocator);
doc.AddMember(StringRef(RxConfig::kField), rx().toJSON(doc), allocator);
# endif
doc.AddMember(StringRef(kCPU), cpu().toJSON(doc), allocator);
doc.AddMember(StringRef(CpuConfig::kField), cpu().toJSON(doc), allocator);
# ifdef XMRIG_FEATURE_OPENCL
doc.AddMember(StringRef(kOcl), cl().toJSON(doc), allocator);

View file

@ -24,25 +24,28 @@
#include "base/kernel/interfaces/IConfig.h"
#include "backend/cpu/CpuConfig.h"
#include "base/net/stratum/Pool.h"
#include "base/net/stratum/Pools.h"
#include "core/config/ConfigTransform.h"
#include "crypto/cn/CnHash.h"
#ifdef XMRIG_ALGO_RANDOMX
# include "crypto/rx/RxConfig.h"
#endif
namespace xmrig
{
static const char *kAffinity = "affinity";
static const char *kAsterisk = "*";
static const char *kCpu = "cpu";
static const char *kEnabled = "enabled";
static const char *kIntensity = "intensity";
static const char *kThreads = "threads";
#ifdef XMRIG_ALGO_RANDOMX
static const char *kRandomX = "randomx";
#endif
#ifdef XMRIG_FEATURE_OPENCL
static const char *kOcl = "opencl";
#endif
@ -102,8 +105,8 @@ void xmrig::ConfigTransform::finalize(rapidjson::Document &doc)
if (m_threads) {
doc.AddMember("version", 1, allocator);
if (!doc.HasMember(kCpu)) {
doc.AddMember(StringRef(kCpu), Value(kObjectType), allocator);
if (!doc.HasMember(CpuConfig::kField)) {
doc.AddMember(StringRef(CpuConfig::kField), Value(kObjectType), allocator);
}
Value profile(kObjectType);
@ -111,7 +114,7 @@ void xmrig::ConfigTransform::finalize(rapidjson::Document &doc)
profile.AddMember(StringRef(kThreads), m_threads, allocator);
profile.AddMember(StringRef(kAffinity), m_affinity, allocator);
doc[kCpu].AddMember(StringRef(kAsterisk), profile, doc.GetAllocator());
doc[CpuConfig::kField].AddMember(StringRef(kAsterisk), profile, doc.GetAllocator());
}
# ifdef XMRIG_FEATURE_OPENCL
@ -143,55 +146,57 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
}
case IConfig::CPUMaxThreadsKey: /* --cpu-max-threads-hint */
return set(doc, kCpu, "max-threads-hint", static_cast<uint64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kMaxThreadsHint, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::MemoryPoolKey: /* --cpu-memory-pool */
return set(doc, kCpu, "memory-pool", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kMemoryPool, static_cast<int64_t>(strtol(arg, nullptr, 10)));
case IConfig::YieldKey: /* --cpu-no-yield */
return set(doc, kCpu, "yield", false);
return set(doc, CpuConfig::kField, CpuConfig::kYield, false);
case IConfig::Argon2ImplKey: /* --argon2-impl */
return set(doc, kCpu, "argon2-impl", arg);
return set(doc, CpuConfig::kField, CpuConfig::kArgon2Impl, arg);
# ifdef XMRIG_FEATURE_ASM
case IConfig::AssemblyKey: /* --asm */
return set(doc, kCpu, "asm", arg);
return set(doc, CpuConfig::kField, CpuConfig::kAsm, arg);
# endif
# ifdef XMRIG_ALGO_ASTROBWT
case IConfig::AstroBWTMaxSizeKey: /* --astrobwt-max-size */
return set(doc, kCpu, "astrobwt-max-size", static_cast<uint64_t>(strtol(arg, nullptr, 10)));
return set(doc, CpuConfig::kField, CpuConfig::kAstroBWTMaxSize, static_cast<uint64_t>(strtol(arg, nullptr, 10)));
case IConfig::AstroBWTAVX2Key: /* --astrobwt-avx2 */
return set(doc, kCpu, "astrobwt-avx2", true);
return set(doc, CpuConfig::kField, CpuConfig::kAstroBWTAVX2, true);
# endif
# ifdef XMRIG_ALGO_RANDOMX
case IConfig::RandomXInitKey: /* --randomx-init */
return set(doc, kRandomX, "init", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, RxConfig::kField, RxConfig::kInit, static_cast<int64_t>(strtol(arg, nullptr, 10)));
# ifdef XMRIG_FEATURE_HWLOC
case IConfig::RandomXNumaKey: /* --randomx-no-numa */
return set(doc, kRandomX, "numa", false);
return set(doc, RxConfig::kField, RxConfig::kNUMA, false);
# endif
case IConfig::RandomXModeKey: /* --randomx-mode */
return set(doc, kRandomX, "mode", arg);
return set(doc, RxConfig::kField, RxConfig::kMode, arg);
case IConfig::RandomX1GbPagesKey: /* --randomx-1gb-pages */
return set(doc, kRandomX, "1gb-pages", true);
return set(doc, RxConfig::kField, RxConfig::kOneGbPages, true);
case IConfig::RandomXWrmsrKey: /* --randomx-wrmsr */
if (arg == nullptr) {
return set(doc, kRandomX, "wrmsr", true);
return set(doc, RxConfig::kField, RxConfig::kWrmsr, true);
}
return set(doc, kRandomX, "wrmsr", static_cast<int64_t>(strtol(arg, nullptr, 10)));
return set(doc, RxConfig::kField, RxConfig::kWrmsr, static_cast<int64_t>(strtol(arg, nullptr, 10)));
case IConfig::RandomXRdmsrKey: /* --randomx-no-rdmsr */
return set(doc, kRandomX, "rdmsr", false);
return set(doc, RxConfig::kField, RxConfig::kRdmsr, false);
case IConfig::RandomXCacheQoSKey: /* --cache-qos */
return set(doc, kRandomX, "cache_qos", true);
return set(doc, RxConfig::kField, RxConfig::kCacheQoS, true);
# endif
# ifdef XMRIG_FEATURE_OPENCL
@ -243,6 +248,21 @@ void xmrig::ConfigTransform::transform(rapidjson::Document &doc, int key, const
return set(doc, "health-print-time", static_cast<uint64_t>(strtol(arg, nullptr, 10)));
# endif
# ifdef XMRIG_FEATURE_BENCHMARK
case IConfig::StressKey: /* --stress */
case IConfig::BenchKey: /* --bench */
set(doc, CpuConfig::kField, CpuConfig::kHugePagesJit, true);
set(doc, CpuConfig::kField, CpuConfig::kPriority, 2);
set(doc, CpuConfig::kField, CpuConfig::kYield, false);
add(doc, Pools::kPools, Pool::kUser, Pool::kBenchmark);
if (key == IConfig::BenchKey) {
add(doc, Pools::kPools, Pool::kBenchmark, arg);
}
break;
# endif
default:
break;
}
@ -253,10 +273,10 @@ void xmrig::ConfigTransform::transformBoolean(rapidjson::Document &doc, int key,
{
switch (key) {
case IConfig::HugePagesKey: /* --no-huge-pages */
return set(doc, kCpu, "huge-pages", enable);
return set(doc, CpuConfig::kField, CpuConfig::kHugePages, enable);
case IConfig::CPUKey: /* --no-cpu */
return set(doc, kCpu, kEnabled, enable);
return set(doc, CpuConfig::kField, kEnabled, enable);
default:
break;
@ -279,11 +299,11 @@ void xmrig::ConfigTransform::transformUint64(rapidjson::Document &doc, int key,
case IConfig::AVKey: /* --av */
m_intensity = intensity(arg);
set(doc, kCpu, "hw-aes", isHwAes(arg));
set(doc, CpuConfig::kField, CpuConfig::kHwAes, isHwAes(arg));
break;
case IConfig::CPUPriorityKey: /* --cpu-priority */
return set(doc, kCpu, "priority", arg);
return set(doc, CpuConfig::kField, CpuConfig::kPriority, arg);
default:
break;

View file

@ -61,6 +61,7 @@ R"===(
"cpu": {
"enabled": true,
"huge-pages": true,
"huge-pages-jit": false,
"hw-aes": null,
"priority": null,
"memory-pool": false,

View file

@ -96,6 +96,11 @@ static const option options[] = {
{ "title", 1, nullptr, IConfig::TitleKey },
{ "no-title", 0, nullptr, IConfig::NoTitleKey },
{ "pause-on-battery", 0, nullptr, IConfig::PauseOnBatteryKey },
# ifdef XMRIG_FEATURE_BENCHMARK
{ "stress", 0, nullptr, IConfig::StressKey },
{ "bench", 1, nullptr, IConfig::BenchKey },
{ "benchmark", 1, nullptr, IConfig::BenchKey },
# endif
# ifdef XMRIG_FEATURE_TLS
{ "tls", 0, nullptr, IConfig::TlsKey },
{ "tls-fingerprint", 1, nullptr, IConfig::FingerprintKey },

View file

@ -179,6 +179,11 @@ static inline const std::string &usage()
# endif
u += " --pause-on-battery pause mine on battery power\n";
# ifdef XMRIG_FEATURE_BENCHMARK
u += " --stress run continuous stress test to check system stability\n";
u += " --bench=N run benchmark in offline mode, N can be between 1M and 10M\n";
# endif
return u;
}

View file

@ -40,6 +40,9 @@ inline void single_hash(const uint8_t *__restrict__ input, size_t size, uint8_t
if (ALGO == Algorithm::AR2_CHUKWA) {
argon2id_hash_raw_ex(3, 512, 1, input, size, input, 16, output, 32, ctx[0]->memory);
}
else if (ALGO == Algorithm::AR2_CHUKWA_V2) {
argon2id_hash_raw_ex(4, 1024, 1, input, size, input, 16, output, 32, ctx[0]->memory);
}
else if (ALGO == Algorithm::AR2_WRKZ) {
argon2id_hash_raw_ex(4, 256, 1, input, size, input, 16, output, 32, ctx[0]->memory);
}

View file

@ -39,7 +39,7 @@ void xmrig::CnCtx::create(cryptonight_ctx **ctx, uint8_t *memory, size_t size, s
cryptonight_ctx *c = static_cast<cryptonight_ctx *>(_mm_malloc(sizeof(cryptonight_ctx), 4096));
c->memory = memory + (i * size);
c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(VirtualMemory::allocateExecutableMemory(0x4000));
c->generated_code = reinterpret_cast<cn_mainloop_fun_ms_abi>(VirtualMemory::allocateExecutableMemory(0x4000, false));
c->generated_code_data.algo = Algorithm::INVALID;
c->generated_code_data.height = std::numeric_limits<uint64_t>::max();

View file

@ -139,7 +139,7 @@ static void patchCode(T dst, U src, const uint32_t iterations, const uint32_t ma
static void patchAsmVariants()
{
const int allocation_size = 81920;
auto base = static_cast<uint8_t *>(VirtualMemory::allocateExecutableMemory(allocation_size));
auto base = static_cast<uint8_t *>(VirtualMemory::allocateExecutableMemory(allocation_size, false));
cn_half_mainloop_ivybridge_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x0000);
cn_half_mainloop_ryzen_asm = reinterpret_cast<cn_mainloop_fun> (base + 0x1000);
@ -273,10 +273,12 @@ xmrig::CnHash::CnHash()
ADD_FN(Algorithm::CN_CCX);
# ifdef XMRIG_ALGO_ARGON2
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE_SOFT][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_WRKZ>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE_SOFT][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_WRKZ>;
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_CHUKWA][AV_SINGLE_SOFT][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA>;
m_map[Algorithm::AR2_CHUKWA_V2][AV_SINGLE][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA_V2>;
m_map[Algorithm::AR2_CHUKWA_V2][AV_SINGLE_SOFT][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_CHUKWA_V2>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_WRKZ>;
m_map[Algorithm::AR2_WRKZ][AV_SINGLE_SOFT][Assembly::NONE] = argon2::single_hash<Algorithm::AR2_WRKZ>;
# endif
# ifdef XMRIG_ALGO_ASTROBWT

View file

@ -385,6 +385,20 @@ const static uint8_t argon2_chukwa_test_out[160] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// "argon2/chukwav2"
const static uint8_t argon2_chukwa_v2_test_out[160] = {
0x77, 0xCF, 0x69, 0x58, 0xB3, 0x53, 0x6E, 0x1F, 0x9F, 0x0D, 0x1E, 0xA1, 0x65, 0xF2, 0x28, 0x11,
0xCA, 0x7B, 0xC4, 0x87, 0xEA, 0x9F, 0x52, 0x03, 0x0B, 0x50, 0x50, 0xC1, 0x7F, 0xCD, 0xD8, 0xF5,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// "argon2/wrkz"
const static uint8_t argon2_wrkz_test_out[160] = {
0x35, 0xE0, 0x83, 0xD4, 0xB9, 0xC6, 0x4C, 0x2A, 0x68, 0x82, 0x0A, 0x43, 0x1F, 0x61, 0x31, 0x19,

View file

@ -47,7 +47,11 @@ xmrig::MemoryPool::MemoryPool(size_t size, bool hugePages, uint32_t node)
return;
}
m_memory = new VirtualMemory(size * pageSize, hugePages, false, false, node);
constexpr size_t alignment = 1 << 24;
m_memory = new VirtualMemory(size * pageSize + alignment, hugePages, false, false, node);
m_alignOffset = (alignment - (((size_t)m_memory->scratchpad()) % alignment)) % alignment;
}
@ -71,7 +75,7 @@ uint8_t *xmrig::MemoryPool::get(size_t size, uint32_t)
return nullptr;
}
uint8_t *out = m_memory->scratchpad() + m_offset;
uint8_t *out = m_memory->scratchpad() + m_alignOffset + m_offset;
m_offset += size;
++m_refs;

View file

@ -54,6 +54,7 @@ protected:
private:
size_t m_refs = 0;
size_t m_offset = 0;
size_t m_alignOffset = 0;
VirtualMemory *m_memory = nullptr;
};

View file

@ -28,28 +28,14 @@
namespace xmrig {
std::atomic<bool> Nonce::m_paused;
std::atomic<uint64_t> Nonce::m_sequence[Nonce::MAX];
std::atomic<bool> Nonce::m_paused = {true};
std::atomic<uint64_t> Nonce::m_sequence[Nonce::MAX] = { {1}, {1}, {1} };
std::atomic<uint64_t> Nonce::m_nonces[2] = { {0}, {0} };
static Nonce nonce;
} // namespace xmrig
xmrig::Nonce::Nonce()
{
m_paused = true;
for (auto &i : m_sequence) {
i = 1;
}
}
bool xmrig::Nonce::next(uint8_t index, uint32_t *nonce, uint32_t reserveCount, uint64_t mask)
{
mask &= 0x7FFFFFFFFFFFFFFFULL;

View file

@ -43,8 +43,6 @@ public:
};
Nonce();
static inline bool isOutdated(Backend backend, uint64_t sequence) { return m_sequence[backend].load(std::memory_order_relaxed) != sequence; }
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed); }
static inline uint64_t sequence(Backend backend) { return m_sequence[backend].load(std::memory_order_relaxed); }

View file

@ -61,7 +61,7 @@ public:
static bool isHugepagesAvailable();
static bool isOneGbPagesAvailable();
static uint32_t bindToNUMANode(int64_t affinity);
static void *allocateExecutableMemory(size_t size);
static void *allocateExecutableMemory(size_t size, bool hugePages);
static void *allocateLargePagesMemory(size_t size);
static void *allocateOneGbPagesMemory(size_t size);
static void destroy();

View file

@ -63,12 +63,41 @@ bool xmrig::VirtualMemory::isOneGbPagesAvailable()
}
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size, bool hugePages)
{
# if defined(__APPLE__)
void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0);
# elif defined(__FreeBSD__)
void *mem = nullptr;
if (hugePages) {
mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER | MAP_PREFAULT_READ, -1, 0);
}
if (!mem) {
mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
}
# else
void *mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
# if defined(MAP_HUGE_2MB)
constexpr int flag_2mb = MAP_HUGE_2MB;
# elif defined(MAP_HUGE_SHIFT)
constexpr int flag_2mb = (21 << MAP_HUGE_SHIFT);
# else
constexpr int flag_2mb = 0;
# endif
void *mem = nullptr;
if (hugePages) {
mem = mmap(0, align(size), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE | flag_2mb, -1, 0);
}
if (!mem) {
mem = mmap(0, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
}
# endif
return mem == MAP_FAILED ? nullptr : mem;

View file

@ -162,9 +162,19 @@ bool xmrig::VirtualMemory::isOneGbPagesAvailable()
}
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size, bool hugePages)
{
return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
void* result = nullptr;
if (hugePages) {
result = VirtualAlloc(nullptr, align(size), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_EXECUTE_READWRITE);
}
if (!result) {
result = VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
}
return result;
}

View file

@ -26,8 +26,13 @@ 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.
*/
#include <thread>
#include <vector>
#include "crypto/randomx/aes_hash.hpp"
#include "crypto/randomx/soft_aes.h"
#include "crypto/randomx/randomx.h"
#include "base/tools/Chrono.h"
#include "base/tools/Profiler.h"
#define AES_HASH_1R_STATE0 0xd7983aad, 0xcc82db47, 0x9fa856de, 0x92b52c0d
@ -214,7 +219,7 @@ void fillAes4Rx4(void *state, size_t outputSize, void *buffer) {
template void fillAes4Rx4<true>(void *state, size_t outputSize, void *buffer);
template void fillAes4Rx4<false>(void *state, size_t outputSize, void *buffer);
template<int softAes>
template<int softAes, int unroll>
void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state) {
PROFILE_SCOPE(RandomX_AES);
@ -260,7 +265,7 @@ void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, voi
rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + k * 4 + 2, fill_state2); \
rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + k * 4 + 3, fill_state3);
switch(softAes) {
switch (softAes) {
case 0:
HASH_STATE(0);
HASH_STATE(1);
@ -277,13 +282,51 @@ void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, voi
break;
default:
HASH_STATE(0);
FILL_STATE(0);
rx_prefetch_t0(prefetchPtr);
switch (unroll) {
case 4:
HASH_STATE(0);
FILL_STATE(0);
rx_prefetch_t0(prefetchPtr);
scratchpadPtr += 64;
prefetchPtr += 64;
HASH_STATE(1);
FILL_STATE(1);
rx_prefetch_t0(prefetchPtr + 64);
HASH_STATE(2);
FILL_STATE(2);
rx_prefetch_t0(prefetchPtr + 64 * 2);
HASH_STATE(3);
FILL_STATE(3);
rx_prefetch_t0(prefetchPtr + 64 * 3);
scratchpadPtr += 64 * 4;
prefetchPtr += 64 * 4;
break;
case 2:
HASH_STATE(0);
FILL_STATE(0);
rx_prefetch_t0(prefetchPtr);
HASH_STATE(1);
FILL_STATE(1);
rx_prefetch_t0(prefetchPtr + 64);
scratchpadPtr += 64 * 2;
prefetchPtr += 64 * 2;
break;
default:
HASH_STATE(0);
FILL_STATE(0);
rx_prefetch_t0(prefetchPtr);
scratchpadPtr += 64;
prefetchPtr += 64;
break;
}
break;
}
}
@ -317,6 +360,53 @@ void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, voi
rx_store_vec_i128((rx_vec_i128*)hash + 3, hash_state3);
}
template void hashAndFillAes1Rx4<0>(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state);
template void hashAndFillAes1Rx4<1>(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state);
template void hashAndFillAes1Rx4<2>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
template void hashAndFillAes1Rx4<0,2>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
template void hashAndFillAes1Rx4<1,1>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
template void hashAndFillAes1Rx4<2,1>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
template void hashAndFillAes1Rx4<2,2>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
template void hashAndFillAes1Rx4<2,4>(void* scratchpad, size_t scratchpadSize, void* hash, void* fill_state);
hashAndFillAes1Rx4_impl* softAESImpl = &hashAndFillAes1Rx4<1,1>;
void SelectSoftAESImpl(size_t threadsCount)
{
constexpr int test_length_ms = 100;
const std::vector<hashAndFillAes1Rx4_impl *> impl = {
&hashAndFillAes1Rx4<1,1>,
&hashAndFillAes1Rx4<2,1>,
&hashAndFillAes1Rx4<2,2>,
&hashAndFillAes1Rx4<2,4>,
};
size_t fast_idx = 0;
double fast_speed = 0.0;
for (size_t run = 0; run < 3; ++run) {
for (size_t i = 0; i < impl.size(); ++i) {
const uint64_t t1 = xmrig::Chrono::highResolutionMSecs();
std::vector<uint32_t> count(threadsCount, 0);
std::vector<std::thread> threads;
for (size_t t = 0; t < threadsCount; ++t) {
threads.emplace_back([&, t]() {
std::vector<uint8_t> scratchpad(10 * 1024);
alignas(16) uint8_t hash[64] = {};
alignas(16) uint8_t state[64] = {};
do {
(*impl[i])(scratchpad.data(), scratchpad.size(), hash, state);
++count[t];
} while (xmrig::Chrono::highResolutionMSecs() - t1 < test_length_ms);
});
}
uint32_t total = 0;
for (size_t t = 0; t < threadsCount; ++t) {
threads[t].join();
total += count[t];
}
const uint64_t t2 = xmrig::Chrono::highResolutionMSecs();
const double speed = total * 1e3 / (t2 - t1);
if (speed > fast_speed) {
fast_idx = i;
fast_speed = speed;
}
}
}
softAESImpl = impl[fast_idx];
}

View file

@ -30,6 +30,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstddef>
typedef void (hashAndFillAes1Rx4_impl)(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state);
extern hashAndFillAes1Rx4_impl* softAESImpl;
inline hashAndFillAes1Rx4_impl* GetSoftAESImpl()
{
return softAESImpl;
}
void SelectSoftAESImpl(size_t threadsCount);
template<int softAes>
void hashAes1Rx4(const void *input, size_t inputSize, void *hash);
@ -39,5 +50,5 @@ void fillAes1Rx4(void *state, size_t outputSize, void *buffer);
template<int softAes>
void fillAes4Rx4(void *state, size_t outputSize, void *buffer);
template<int softAes>
template<int softAes, int unroll>
void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state);

View file

@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define RANDOMX_DATASET_MAX_SIZE 2181038080
// Increase it if some configs use larger programs
#define RANDOMX_PROGRAM_MAX_SIZE 320
#define RANDOMX_PROGRAM_MAX_SIZE 256
// Increase it if some configs use larger scratchpad
#define RANDOMX_SCRATCHPAD_L3_MAX_SIZE 2097152

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

View file

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

View file

@ -0,0 +1,37 @@
/*
* Copyright 2018-2019, tevador <tevador@gmail.com>
* Copyright 2018-2020, SChernykh <https://github.com/SChernykh>
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
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.
*/
#pragma once
void randomx_set_huge_pages_jit(bool)
{
}

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

@ -76,18 +76,6 @@ RandomX_ConfigurationWownero::RandomX_ConfigurationWownero()
fillAes4Rx4_Key[7] = fillAes4Rx4_Key[3];
}
RandomX_ConfigurationLoki::RandomX_ConfigurationLoki()
{
ArgonIterations = 4;
ArgonLanes = 2;
ArgonSalt = "RandomXL\x12";
ProgramSize = 320;
ProgramCount = 7;
RANDOMX_FREQ_IADD_RS = 25;
RANDOMX_FREQ_CBRANCH = 16;
}
RandomX_ConfigurationArqma::RandomX_ConfigurationArqma()
{
ArgonIterations = 1;
@ -365,7 +353,6 @@ typedef void(randomx::JitCompilerX86::* InstructionGeneratorX86_2)(const randomx
RandomX_ConfigurationMonero RandomX_MoneroConfig;
RandomX_ConfigurationWownero RandomX_WowneroConfig;
RandomX_ConfigurationLoki RandomX_LokiConfig;
RandomX_ConfigurationArqma RandomX_ArqmaConfig;
RandomX_ConfigurationSafex RandomX_SafexConfig;
RandomX_ConfigurationKeva RandomX_KevaConfig;
@ -394,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

@ -147,14 +147,12 @@ struct RandomX_ConfigurationBase
struct RandomX_ConfigurationMonero : public RandomX_ConfigurationBase {};
struct RandomX_ConfigurationWownero : public RandomX_ConfigurationBase { RandomX_ConfigurationWownero(); };
struct RandomX_ConfigurationLoki : public RandomX_ConfigurationBase { RandomX_ConfigurationLoki(); };
struct RandomX_ConfigurationArqma : public RandomX_ConfigurationBase { RandomX_ConfigurationArqma(); };
struct RandomX_ConfigurationSafex : public RandomX_ConfigurationBase { RandomX_ConfigurationSafex(); };
struct RandomX_ConfigurationKeva : public RandomX_ConfigurationBase { RandomX_ConfigurationKeva(); };
extern RandomX_ConfigurationMonero RandomX_MoneroConfig;
extern RandomX_ConfigurationWownero RandomX_WowneroConfig;
extern RandomX_ConfigurationLoki RandomX_LokiConfig;
extern RandomX_ConfigurationArqma RandomX_ArqmaConfig;
extern RandomX_ConfigurationSafex RandomX_SafexConfig;
extern RandomX_ConfigurationKeva RandomX_KevaConfig;
@ -171,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

@ -28,9 +28,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "crypto/randomx/soft_aes.h"
#include "crypto/randomx/aes_hash.hpp"
#include "base/tools/Chrono.h"
#include <vector>
alignas(64) uint32_t lutEnc0[256];
alignas(64) uint32_t lutEnc1[256];
@ -120,47 +117,3 @@ static struct SAESInitializer
}
}
} aes_initializer;
static uint32_t softAESImpl = 1;
uint32_t GetSoftAESImpl()
{
return softAESImpl;
}
void SelectSoftAESImpl()
{
constexpr int test_length_ms = 100;
double speed[2] = {};
for (int run = 0; run < 3; ++run) {
for (int i = 0; i < 2; ++i) {
std::vector<uint8_t> scratchpad(10 * 1024);
uint8_t hash[64] = {};
uint8_t state[64] = {};
uint64_t t1, t2;
uint32_t count = 0;
t1 = xmrig::Chrono::highResolutionMSecs();
do {
if (i == 0) {
hashAndFillAes1Rx4<1>(scratchpad.data(), scratchpad.size(), hash, state);
}
else {
hashAndFillAes1Rx4<2>(scratchpad.data(), scratchpad.size(), hash, state);
}
++count;
t2 = xmrig::Chrono::highResolutionMSecs();
} while (t2 - t1 < test_length_ms);
const double x = count * 1e3 / (t2 - t1);
if (x > speed[i]) {
speed[i] = x;
}
}
}
softAESImpl = (speed[0] > speed[1]) ? 1 : 2;
}

View file

@ -41,9 +41,6 @@ extern uint32_t lutDec1[256];
extern uint32_t lutDec2[256];
extern uint32_t lutDec3[256];
uint32_t GetSoftAESImpl();
void SelectSoftAESImpl();
template<int soft> rx_vec_i128 aesenc(rx_vec_i128 in, rx_vec_i128 key);
template<int soft> rx_vec_i128 aesdec(rx_vec_i128 in, rx_vec_i128 key);

View file

@ -119,15 +119,10 @@ namespace randomx {
template<int softAes>
void VmBase<softAes>::hashAndFill(void* out, uint64_t (&fill_state)[8]) {
if (!softAes) {
hashAndFillAes1Rx4<0>(scratchpad, ScratchpadSize, &reg.a, fill_state);
hashAndFillAes1Rx4<0, 2>(scratchpad, ScratchpadSize, &reg.a, fill_state);
}
else {
if (GetSoftAESImpl() == 1) {
hashAndFillAes1Rx4<1>(scratchpad, ScratchpadSize, &reg.a, fill_state);
}
else {
hashAndFillAes1Rx4<2>(scratchpad, ScratchpadSize, &reg.a, fill_state);
}
(*GetSoftAESImpl())(scratchpad, ScratchpadSize, &reg.a, fill_state);
}
rx_blake2b_wrapper::run(out, RANDOMX_HASH_SIZE, &reg, sizeof(RegisterFile));

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>;

View file

@ -26,14 +26,12 @@
#include "crypto/rx/Rx.h"
#include "backend/common/Tags.h"
#include "backend/cpu/CpuConfig.h"
#include "backend/cpu/CpuThreads.h"
#include "base/io/log/Log.h"
#include "crypto/rx/RxConfig.h"
#include "crypto/rx/RxQueue.h"
#include "crypto/randomx/randomx.h"
#include "crypto/randomx/soft_aes.h"
#include "crypto/randomx/aes_hash.hpp"
namespace xmrig {
@ -102,6 +100,7 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
}
randomx_set_scratchpad_prefetch_mode(config.scratchpadPrefetchMode());
randomx_set_huge_pages_jit(cpu.isHugePagesJit());
if (isReady(seed)) {
return true;
@ -115,7 +114,7 @@ bool xmrig::Rx::init(const T &seed, const RxConfig &config, const CpuConfig &cpu
if (!osInitialized) {
setupMainLoopExceptionFrame();
if (!cpu.isHwAES()) {
SelectSoftAESImpl();
SelectSoftAESImpl(cpu.threads().get(seed.algorithm()).count());
}
osInitialized = true;
}

View file

@ -43,9 +43,6 @@ const RandomX_ConfigurationBase *xmrig::RxAlgo::base(Algorithm::Id algorithm)
case Algorithm::RX_WOW:
return &RandomX_WowneroConfig;
case Algorithm::RX_LOKI:
return &RandomX_LokiConfig;
case Algorithm::RX_ARQ:
return &RandomX_ArqmaConfig;

Some files were not shown because too many files have changed in this diff Show more