Skip to content

Commit

Permalink
Merge branch 'feature-cryptonight-heavy' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xmrig committed Apr 3, 2018
2 parents 44d5639 + 6b710ff commit 7003559
Show file tree
Hide file tree
Showing 42 changed files with 1,182 additions and 377 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# v2.6.0-beta1
- [#476](https://github.com/xmrig/xmrig/issues/476) **Added Cryptonight-Heavy support for Sumokoin ASIC resistance fork.**
- HTTP server now runs in main loop, it make possible easy extend API without worry about thread synchronization.
- Added initial graceful reload support, miner will reload configuration if config file changed, disabled by default until it will be fully implemented and tested.
- Added API endpoint `PUT /1/config` to update current config.
- Added API endpoint `GET /1/config` to get current active config.
- Added API endpoint `GET /1/threads` to get current active threads configuration.
- API endpoint `GET /` now deprecated, use `GET /1/summary` instead.
- Added `--api-no-ipv6` and similar config option to disable IPv6 support for HTTP API.
- Added `--api-no-restricted` to enable full access to api, this option has no effect if `--api-access-token` not specified.
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(xmrig)

option(WITH_LIBCPUID "Use Libcpuid" ON)
option(WITH_AEON "CryptoNight-Lite support" ON)
option(WITH_SUMO "CryptoNight-Heavy support" ON)
option(WITH_HTTPD "HTTP REST API" ON)
option(BUILD_STATIC "Build static binary" OFF)

Expand Down Expand Up @@ -32,6 +33,7 @@ set(HEADERS
src/interfaces/ILogBackend.h
src/interfaces/IStrategy.h
src/interfaces/IStrategyListener.h
src/interfaces/IThread.h
src/interfaces/IWatcherListener.h
src/interfaces/IWorker.h
src/log/ConsoleLog.h
Expand All @@ -52,6 +54,7 @@ set(HEADERS
src/Platform.h
src/Summary.h
src/version.h
src/workers/CpuThread.h
src/workers/DoubleWorker.h
src/workers/Handle.h
src/workers/Hashrate.h
Expand All @@ -68,6 +71,7 @@ set(HEADERS_CRYPTO
src/crypto/c_keccak.h
src/crypto/c_skein.h
src/crypto/CryptoNight.h
src/crypto/CryptoNight_constants.h
src/crypto/CryptoNight_monero.h
src/crypto/CryptoNight_test.h
src/crypto/groestl_tables.h
Expand Down Expand Up @@ -106,6 +110,7 @@ set(SOURCES
src/net/Url.cpp
src/Platform.cpp
src/Summary.cpp
src/workers/CpuThread.cpp
src/workers/DoubleWorker.cpp
src/workers/Handle.cpp
src/workers/Hashrate.cpp
Expand All @@ -121,7 +126,6 @@ set(SOURCES_CRYPTO
src/crypto/c_blake256.c
src/crypto/c_jh.c
src/crypto/c_skein.c
src/crypto/CryptoNight.cpp
)

if (WIN32)
Expand Down Expand Up @@ -200,6 +204,10 @@ if (NOT WITH_AEON)
add_definitions(/DXMRIG_NO_AEON)
endif()

if (NOT WITH_SUMO)
add_definitions(/DXMRIG_NO_SUMO)
endif()

if (WITH_HTTPD)
find_package(MHD)

Expand Down
9 changes: 2 additions & 7 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,8 @@ int App::exec()

background();

if (!CryptoNight::init(m_controller->config()->algorithm(), m_controller->config()->algoVariant(), m_controller->config()->isDoubleHash())) {
LOG_ERR("\"%s\" hash self-test failed.", m_controller->config()->algoName());
return 1;
}

Mem::allocate(m_controller->config()->algorithm(),
m_controller->config()->threads(),
m_controller->config()->threadsCount(),
m_controller->config()->isDoubleHash(),
m_controller->config()->isHugePages()
);
Expand Down Expand Up @@ -136,7 +131,7 @@ int App::exec()
m_httpd->start();
# endif

Workers::start(m_controller->config()->affinity(), m_controller->config()->priority(), m_controller);
Workers::start(m_controller);

m_controller->network()->connect();

Expand Down
19 changes: 15 additions & 4 deletions src/Cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 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 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 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
Expand Down Expand Up @@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0;
int Cpu::m_totalThreads = 0;


int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
{
if (m_totalThreads == 1) {
return 1;
Expand All @@ -54,7 +54,18 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
}

int count = 0;
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
int size = 2048;

if (algo == xmrig::CRYPTONIGHT_LITE) {
size = 1024;
}
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
size = 4096;
}

if (doubleHash) {
size *= 2;
}

if (cache) {
count = cache / size;
Expand Down
9 changes: 6 additions & 3 deletions src/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 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 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 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
Expand All @@ -28,6 +28,9 @@
#include <stdint.h>


#include "xmrig.h"


class Cpu
{
public:
Expand All @@ -37,7 +40,7 @@ class Cpu
BMI2 = 4
};

static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage);
static void init();
static void setAffinity(int id, uint64_t mask);

Expand Down
2 changes: 1 addition & 1 deletion src/Cpu_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int Cpu::m_totalCores = 0;
int Cpu::m_totalThreads = 0;


int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
{
return m_totalThreads;
}
Expand Down
11 changes: 7 additions & 4 deletions src/Mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@


#include "crypto/CryptoNight.h"
#include "crypto/CryptoNight_constants.h"
#include "Mem.h"
#include "xmrig.h"


bool Mem::m_doubleHash = false;
Expand All @@ -43,15 +43,18 @@ alignas(16) uint8_t *Mem::m_memory = nullptr;
cryptonight_ctx *Mem::create(int threadId)
{
# ifndef XMRIG_NO_AEON
if (m_algo == xmrig::ALGO_CRYPTONIGHT_LITE) {
if (m_algo == xmrig::CRYPTONIGHT_LITE) {
return createLite(threadId);
}
# endif

cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory<xmrig::CRYPTONIGHT_HEAVY>()
: xmrig::cn_select_memory<xmrig::CRYPTONIGHT>();

cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]);

const int ratio = m_doubleHash ? 2 : 1;
ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
ctx->memory = &m_memory[size * (threadId * ratio + 1)];

return ctx;
}
Expand Down
5 changes: 4 additions & 1 deletion src/Mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <stdint.h>


#include "xmrig.h"


struct cryptonight_ctx;


Expand All @@ -42,7 +45,7 @@ class Mem
Lock = 4
};

static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled);
static cryptonight_ctx *create(int threadId);
static void *calloc(size_t num, size_t size);
static void release();
Expand Down
8 changes: 6 additions & 2 deletions src/Mem_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,19 @@
#include "xmrig.h"


bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
{
m_algo = algo;
m_threads = threads;
m_doubleHash = doubleHash;

const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
m_size = MONERO_MEMORY * (threads * ratio + 1);

if (algo == xmrig::CRYPTONIGHT_HEAVY) {
m_size *= 2;
}

if (!enabled) {
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
return true;
Expand Down
8 changes: 6 additions & 2 deletions src/Mem_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,19 @@ static BOOL TrySetLockPagesPrivilege() {
}


bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
{
m_algo = algo;
m_threads = threads;
m_doubleHash = doubleHash;

const int ratio = (doubleHash && algo != xmrig::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
m_size = MONERO_MEMORY * (threads * ratio + 1);

if (algo == xmrig::CRYPTONIGHT_HEAVY) {
m_size *= 2;
}

if (!enabled) {
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/Summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static void print_threads(xmrig::Config *config)
}

Log::i()->text(config->isColors() ? "\x1B[01;32m * \x1B[01;37mTHREADS: \x1B[01;36m%d\x1B[01;37m, %s, av=%d, %sdonate=%d%%%s" : " * THREADS: %d, %s, av=%d, %sdonate=%d%%%s",
config->threads(),
config->threadsCount(),
config->algoName(),
config->algoVariant(),
config->isColors() && config->donateLevel() == 0 ? "\x1B[01;31m" : "",
Expand Down
26 changes: 23 additions & 3 deletions src/api/ApiRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "core/Config.h"
#include "core/Controller.h"
#include "Cpu.h"
#include "interfaces/IThread.h"
#include "Mem.h"
#include "net/Job.h"
#include "Platform.h"
Expand Down Expand Up @@ -67,7 +68,7 @@ static inline double normalize(double d)
ApiRouter::ApiRouter(xmrig::Controller *controller) :
m_controller(controller)
{
m_threads = controller->config()->threads();
m_threads = controller->config()->threadsCount();
m_hashrate = new double[m_threads * 3]();

memset(m_totalHashrate, 0, sizeof(m_totalHashrate));
Expand All @@ -87,7 +88,6 @@ ApiRouter::~ApiRouter()
void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &reply) const
{
rapidjson::Document doc;
doc.SetObject();

if (req.match("/1/config")) {
if (req.isRestricted()) {
Expand All @@ -100,6 +100,14 @@ void ApiRouter::ApiRouter::get(const xmrig::HttpRequest &req, xmrig::HttpReply &
return finalize(reply, doc);
}

if (req.match("/1/threads")) {
getThreads(doc);

return finalize(reply, doc);
}

doc.SetObject();

getIdentify(doc);
getMiner(doc);
getHashrate(doc);
Expand Down Expand Up @@ -144,7 +152,7 @@ void ApiRouter::tick(const NetworkState &network)

void ApiRouter::onConfigChanged(xmrig::Config *config, xmrig::Config *previousConfig)
{
// updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
updateWorkerId(config->apiWorkerId(), previousConfig->apiWorkerId());
}


Expand Down Expand Up @@ -288,6 +296,18 @@ void ApiRouter::getResults(rapidjson::Document &doc) const
}


void ApiRouter::getThreads(rapidjson::Document &doc) const
{
doc.SetArray();

const std::vector<xmrig::IThread *> &threads = m_controller->config()->threads();

for (const xmrig::IThread *thread : threads) {
doc.PushBack(thread->toAPI(doc), doc.GetAllocator());
}
}


void ApiRouter::setWorkerId(const char *id)
{
memset(m_workerId, 0, sizeof(m_workerId));
Expand Down
1 change: 1 addition & 0 deletions src/api/ApiRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class ApiRouter : public xmrig::IControllerListener
void getIdentify(rapidjson::Document &doc) const;
void getMiner(rapidjson::Document &doc) const;
void getResults(rapidjson::Document &doc) const;
void getThreads(rapidjson::Document &doc) const;
void setWorkerId(const char *id);
void updateWorkerId(const char *id, const char *previousId);

Expand Down
10 changes: 5 additions & 5 deletions src/core/CommonConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static const char *algoNames[] = {


xmrig::CommonConfig::CommonConfig() :
m_algorithm(CRYPTONIGHT),
m_adjusted(false),
m_apiIPv6(true),
m_apiRestricted(true),
Expand All @@ -63,7 +64,6 @@ xmrig::CommonConfig::CommonConfig() :
m_fileName(nullptr),
m_logFile(nullptr),
m_userAgent(nullptr),
m_algorithm(ALGO_CRYPTONIGHT),
m_apiPort(0),
m_donateLevel(kDefaultDonateLevel),
m_printTime(60),
Expand Down Expand Up @@ -95,9 +95,9 @@ xmrig::CommonConfig::~CommonConfig()
}


const char *xmrig::CommonConfig::algoName() const
const char *xmrig::CommonConfig::algoName(Algo algorithm)
{
return algoNames[m_algorithm];
return algoNames[algorithm];
}


Expand Down Expand Up @@ -367,15 +367,15 @@ void xmrig::CommonConfig::setAlgo(const char *algo)
if (strcasecmp(algo, "cryptonight-light") == 0) {
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");

m_algorithm = ALGO_CRYPTONIGHT_LITE;
m_algorithm = CRYPTONIGHT_LITE;
return;
}

const size_t size = sizeof(algoNames) / sizeof((algoNames)[0]);

for (size_t i = 0; i < size; i++) {
if (algoNames[i] && strcasecmp(algo, algoNames[i]) == 0) {
m_algorithm = (int) i;
m_algorithm = static_cast<Algo>(i);
break;
}
}
Expand Down
Loading

0 comments on commit 7003559

Please sign in to comment.