From 9975b4e4cd41ddd16a1deab02629fc6ded77f934 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 14 Aug 2017 08:41:54 +0300 Subject: [PATCH 01/26] Backport unified client timer from proxy project. --- src/interfaces/IStrategy.h | 1 + src/log/Log.h | 6 ++- src/net/Client.cpp | 51 +++++++++++++++++------ src/net/Client.h | 7 +++- src/net/Network.cpp | 24 ++++++++++- src/net/Network.h | 9 +++- src/net/strategies/DonateStrategy.cpp | 6 +++ src/net/strategies/DonateStrategy.h | 1 + src/net/strategies/FailoverStrategy.cpp | 8 ++++ src/net/strategies/FailoverStrategy.h | 1 + src/net/strategies/SinglePoolStrategy.cpp | 6 +++ src/net/strategies/SinglePoolStrategy.h | 1 + src/version.h | 6 +-- 13 files changed, 105 insertions(+), 22 deletions(-) diff --git a/src/interfaces/IStrategy.h b/src/interfaces/IStrategy.h index b7f5d652..660529ea 100644 --- a/src/interfaces/IStrategy.h +++ b/src/interfaces/IStrategy.h @@ -41,6 +41,7 @@ public: virtual void connect() = 0; virtual void resume() = 0; virtual void stop() = 0; + virtual void tick(uint64_t now) = 0; }; diff --git a/src/log/Log.h b/src/log/Log.h index 16e94e0b..e193125f 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -77,10 +77,14 @@ private: #ifdef APP_DEBUG # define LOG_DEBUG(x, ...) Log::i()->message(Log::DEBUG, x, ##__VA_ARGS__) +#else +# define LOG_DEBUG(x, ...) +#endif + +#if defined(APP_DEBUG) || defined(APP_DEVEL) # define LOG_DEBUG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__) # define LOG_DEBUG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__) #else -# define LOG_DEBUG(x, ...) # define LOG_DEBUG_ERR(x, ...) # define LOG_DEBUG_WARN(x, ...) #endif diff --git a/src/net/Client.cpp b/src/net/Client.cpp index bc44c7dd..2c6e3ba4 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -56,13 +56,14 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_failures(0), m_recvBufPos(0), m_state(UnconnectedState), + m_expire(0), m_stream(nullptr), m_socket(nullptr) { memset(m_ip, 0, sizeof(m_ip)); memset(&m_hints, 0, sizeof(m_hints)); - m_resolver.data = m_responseTimer.data = m_retriesTimer.data = m_keepAliveTimer.data = this; + m_resolver.data = this; m_hints.ai_family = PF_INET; m_hints.ai_socktype = SOCK_STREAM; @@ -71,10 +72,10 @@ Client::Client(int id, const char *agent, IClientListener *listener) : m_recvBuf.base = static_cast(malloc(kRecvBufSize)); m_recvBuf.len = kRecvBufSize; - auto loop = uv_default_loop(); - uv_timer_init(loop, &m_retriesTimer); - uv_timer_init(loop, &m_responseTimer); - uv_timer_init(loop, &m_keepAliveTimer); +# ifndef XMRIG_PROXY_PROJECT + m_keepAliveTimer.data = this; + uv_timer_init(uv_default_loop(), &m_keepAliveTimer); +# endif } @@ -93,7 +94,7 @@ Client::~Client() int64_t Client::send(char *data, size_t size) { LOG_DEBUG("[%s:%u] send (%d bytes): \"%s\"", m_url.host(), m_url.port(), size ? size : strlen(data), data); - if (state() != ConnectedState) { + if (state() != ConnectedState || !uv_is_writable(m_stream)) { LOG_DEBUG_ERR("[%s:%u] send failed, invalid state: %d", m_url.host(), m_url.port(), m_state); return -1; } @@ -108,8 +109,7 @@ int64_t Client::send(char *data, size_t size) delete req; }); - uv_timer_start(&m_responseTimer, [](uv_timer_t *handle) { getClient(handle->data)->close(); }, kResponseTimeout, 0); - + m_expire = uv_now(uv_default_loop()) + kResponseTimeout; return m_sequence++; } @@ -134,9 +134,11 @@ void Client::connect(const Url *url) void Client::disconnect() { +# ifndef XMRIG_PROXY_PROJECT uv_timer_stop(&m_keepAliveTimer); - uv_timer_stop(&m_responseTimer); - uv_timer_stop(&m_retriesTimer); +# endif + + m_expire = 0; m_failures = -1; close(); @@ -153,6 +155,24 @@ void Client::setUrl(const Url *url) } +void Client::tick(uint64_t now) +{ + if (m_expire == 0 || now < m_expire) { + return; + } + + if (m_state == ConnectedState) { + LOG_DEBUG_ERR("[%s:%u] timeout", m_url.host(), m_url.port()); + close(); + } + + + if (m_state == ConnectingState) { + connect(); + } +} + + int64_t Client::submit(const JobResult &result) { char *req = static_cast(malloc(345)); @@ -231,6 +251,7 @@ int Client::resolve(const char *host) { setState(HostLookupState); + m_expire = 0; m_recvBufPos = 0; if (m_failures == -1) { @@ -432,10 +453,11 @@ void Client::reconnect() { setState(ConnectingState); - uv_timer_stop(&m_responseTimer); +# ifndef XMRIG_PROXY_PROJECT if (m_url.isKeepAlive()) { uv_timer_stop(&m_keepAliveTimer); } +# endif if (m_failures == -1) { return m_listener->onClose(this, -1); @@ -444,7 +466,7 @@ void Client::reconnect() m_failures++; m_listener->onClose(this, m_failures); - uv_timer_start(&m_retriesTimer, [](uv_timer_t *handle) { getClient(handle->data)->connect(); }, m_retryPause, 0); + m_expire = uv_now(uv_default_loop()) + m_retryPause; } @@ -462,12 +484,15 @@ void Client::setState(SocketState state) void Client::startTimeout() { - uv_timer_stop(&m_responseTimer); + m_expire = 0; + +# ifndef XMRIG_PROXY_PROJECT if (!m_url.isKeepAlive()) { return; } uv_timer_start(&m_keepAliveTimer, [](uv_timer_t *handle) { getClient(handle->data)->ping(); }, kKeepAliveTimeout, 0); +# endif } diff --git a/src/net/Client.h b/src/net/Client.h index b04c2c3b..b7eda325 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -62,6 +62,7 @@ public: void connect(const Url *url); void disconnect(); void setUrl(const Url *url); + void tick(uint64_t now); inline bool isReady() const { return m_state == ConnectedState && m_failures == 0; } inline const char *host() const { return m_url.host(); } @@ -112,14 +113,16 @@ private: SocketState m_state; static int64_t m_sequence; std::map m_results; + uint64_t m_expire; Url m_url; uv_buf_t m_recvBuf; uv_getaddrinfo_t m_resolver; uv_stream_t *m_stream; uv_tcp_t *m_socket; + +# ifndef XMRIG_PROXY_PROJECT uv_timer_t m_keepAliveTimer; - uv_timer_t m_responseTimer; - uv_timer_t m_retriesTimer; +# endif }; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 86c5ee7a..2e6ec298 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -39,7 +39,6 @@ Network::Network(const Options *options) : - m_donateActive(false), m_options(options), m_donate(nullptr), m_accepted(0), @@ -62,6 +61,11 @@ Network::Network(const Options *options) : if (m_options->donateLevel() > 0) { m_donate = new DonateStrategy(m_agent, this); } + + m_timer.data = this; + uv_timer_init(uv_default_loop(), &m_timer); + + uv_timer_start(&m_timer, Network::onTick, kTickInterval, kTickInterval); } @@ -164,3 +168,21 @@ void Network::setJob(Client *client, const Job &job) Workers::setJob(job); } + + +void Network::tick() +{ + const uint64_t now = uv_now(uv_default_loop()); + + m_strategy->tick(now); + + if (m_donate) { + m_donate->tick(now); + } +} + + +void Network::onTick(uv_timer_t *handle) +{ + static_cast(handle->data)->tick(); +} diff --git a/src/net/Network.h b/src/net/Network.h index 21046df9..ba1982e1 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -57,15 +57,20 @@ protected: void onResultAccepted(Client *client, int64_t seq, uint32_t diff, uint64_t ms, const char *error) override; private: - void setJob(Client *client, const Job &job); + constexpr static int kTickInterval = 1 * 1000; + + void setJob(Client *client, const Job &job); + void tick(); + + static void onTick(uv_timer_t *handle); - bool m_donateActive; char *m_agent; const Options *m_options; IStrategy *m_donate; IStrategy *m_strategy; uint64_t m_accepted; uint64_t m_rejected; + uv_timer_t m_timer; }; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index d87e83de..c3468016 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -69,6 +69,12 @@ void DonateStrategy::stop() } +void DonateStrategy::tick(uint64_t now) +{ + m_client->tick(now); +} + + void DonateStrategy::onClose(Client *client, int failures) { } diff --git a/src/net/strategies/DonateStrategy.h b/src/net/strategies/DonateStrategy.h index 1c7597ef..b54b0b17 100644 --- a/src/net/strategies/DonateStrategy.h +++ b/src/net/strategies/DonateStrategy.h @@ -49,6 +49,7 @@ public: int64_t submit(const JobResult &result) override; void connect() override; void stop() override; + void tick(uint64_t now) override; protected: void onClose(Client *client, int failures) override; diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 380cf981..37afffec 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -74,6 +74,14 @@ void FailoverStrategy::stop() } +void FailoverStrategy::tick(uint64_t now) +{ + for (Client *client : m_pools) { + client->tick(now); + } +} + + void FailoverStrategy::onClose(Client *client, int failures) { if (failures == -1) { diff --git a/src/net/strategies/FailoverStrategy.h b/src/net/strategies/FailoverStrategy.h index f0fa0514..616a08d7 100644 --- a/src/net/strategies/FailoverStrategy.h +++ b/src/net/strategies/FailoverStrategy.h @@ -49,6 +49,7 @@ public: void connect() override; void resume() override; void stop() override; + void tick(uint64_t now) override; protected: void onClose(Client *client, int failures) override; diff --git a/src/net/strategies/SinglePoolStrategy.cpp b/src/net/strategies/SinglePoolStrategy.cpp index b1a6941e..f38405f4 100644 --- a/src/net/strategies/SinglePoolStrategy.cpp +++ b/src/net/strategies/SinglePoolStrategy.cpp @@ -66,6 +66,12 @@ void SinglePoolStrategy::stop() } +void SinglePoolStrategy::tick(uint64_t now) +{ + m_client->tick(now); +} + + void SinglePoolStrategy::onClose(Client *client, int failures) { if (!isActive()) { diff --git a/src/net/strategies/SinglePoolStrategy.h b/src/net/strategies/SinglePoolStrategy.h index 51b1a88d..c09d0305 100644 --- a/src/net/strategies/SinglePoolStrategy.h +++ b/src/net/strategies/SinglePoolStrategy.h @@ -46,6 +46,7 @@ public: void connect() override; void resume() override; void stop() override; + void tick(uint64_t now) override; protected: void onClose(Client *client, int failures) override; diff --git a/src/version.h b/src/version.h index 3d197ee3..81e95391 100644 --- a/src/version.h +++ b/src/version.h @@ -27,14 +27,14 @@ #define APP_ID "xmrig" #define APP_NAME "XMRig" #define APP_DESC "Monero (XMR) CPU miner" -#define APP_VERSION "2.2.1" +#define APP_VERSION "2.3.0-dev" #define APP_DOMAIN "xmrig.com" #define APP_SITE "www.xmrig.com" #define APP_COPYRIGHT "Copyright (C) 2016-2017 xmrig.com" #define APP_VER_MAJOR 2 -#define APP_VER_MINOR 2 -#define APP_VER_BUILD 1 +#define APP_VER_MINOR 3 +#define APP_VER_BUILD 0 #define APP_VER_REV 0 #ifdef _MSC_VER From a07b0e595338b1f9fe23bc89664c589c08c1c90a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 14 Aug 2017 09:30:41 +0300 Subject: [PATCH 02/26] Fix Visual Studio warnings. --- CMakeLists.txt | 2 ++ src/3rdparty/getopt/getopt.h | 2 +- src/3rdparty/jansson/dump.c | 2 ++ src/3rdparty/jansson/hashtable.c | 2 ++ src/3rdparty/jansson/load.c | 2 +- src/Cpu.cpp | 2 +- src/Cpu.h | 4 ++-- src/Mem.h | 4 ++-- src/Mem_win.cpp | 3 +-- src/Options.cpp | 16 ++++++++-------- src/crypto/CryptoNight_p.h | 6 +++--- src/crypto/c_blake256.c | 2 +- src/log/ConsoleLog.cpp | 8 +++----- src/log/FileLog.cpp | 2 +- src/net/Client.cpp | 8 ++++---- src/net/Job.cpp | 2 +- src/net/Job.h | 6 +++--- src/net/Network.cpp | 1 + src/net/Url.cpp | 2 +- src/net/strategies/FailoverStrategy.cpp | 2 +- src/workers/Hashrate.cpp | 4 ++-- 21 files changed, 43 insertions(+), 39 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d189e8..4ac3ae5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,6 +159,8 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC) set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Ot /Oi /MT /GL") + add_definitions(/D_CRT_SECURE_NO_WARNINGS) + add_definitions(/D_CRT_NONSTDC_NO_WARNINGS) elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang) diff --git a/src/3rdparty/getopt/getopt.h b/src/3rdparty/getopt/getopt.h index 0cb88895..bcbff179 100644 --- a/src/3rdparty/getopt/getopt.h +++ b/src/3rdparty/getopt/getopt.h @@ -56,7 +56,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#pragma warning(disable:4996); +#pragma warning(disable:4996) #define __GETOPT_H__ diff --git a/src/3rdparty/jansson/dump.c b/src/3rdparty/jansson/dump.c index a23fabb7..a332241d 100644 --- a/src/3rdparty/jansson/dump.c +++ b/src/3rdparty/jansson/dump.c @@ -5,6 +5,8 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#pragma warning(disable:4090) + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/src/3rdparty/jansson/hashtable.c b/src/3rdparty/jansson/hashtable.c index c819319a..e79f83cd 100644 --- a/src/3rdparty/jansson/hashtable.c +++ b/src/3rdparty/jansson/hashtable.c @@ -5,6 +5,8 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#pragma warning(disable:4334) + #if HAVE_CONFIG_H #include #endif diff --git a/src/3rdparty/jansson/load.c b/src/3rdparty/jansson/load.c index c212489a..6b3d1e25 100644 --- a/src/3rdparty/jansson/load.c +++ b/src/3rdparty/jansson/load.c @@ -1034,8 +1034,8 @@ json_t *json_loadf(FILE *input, size_t flags, json_error_t *error) static int fd_get_func(int *fd) { - uint8_t c; #ifdef HAVE_UNISTD_H + uint8_t c; if (read(*fd, &c, 1) == 1) return c; #endif diff --git a/src/Cpu.cpp b/src/Cpu.cpp index e8f7ee17..2e79b6df 100644 --- a/src/Cpu.cpp +++ b/src/Cpu.cpp @@ -68,7 +68,7 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage) } if (((float) count / m_totalThreads * 100) > maxCpuUsage) { - count = ceil((float) m_totalThreads * (maxCpuUsage / 100.0)); + count = (int) ceil((float) m_totalThreads * (maxCpuUsage / 100.0)); } return count < 1 ? 1 : count; diff --git a/src/Cpu.h b/src/Cpu.h index 8b7c3643..9444274d 100644 --- a/src/Cpu.h +++ b/src/Cpu.h @@ -41,8 +41,8 @@ public: static void init(); static void setAffinity(int id, uint64_t mask); - static inline bool hasAES() { return m_flags & AES; } - static inline bool isX64() { return m_flags & X86_64; } + static inline bool hasAES() { return (m_flags & AES) != 0; } + static inline bool isX64() { return (m_flags & X86_64) != 0; } static inline const char *brand() { return m_brand; } static inline int cores() { return m_totalCores; } static inline int l2() { return m_l2_cache; } diff --git a/src/Mem.h b/src/Mem.h index 58b91ac7..050fd8e8 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -50,8 +50,8 @@ public: static void release(); static inline bool isDoubleHash() { return m_doubleHash; } - static inline bool isHugepagesAvailable() { return m_flags & HugepagesAvailable; } - static inline bool isHugepagesEnabled() { return m_flags & HugepagesEnabled; } + static inline bool isHugepagesAvailable() { return (m_flags & HugepagesAvailable) != 0; } + static inline bool isHugepagesEnabled() { return (m_flags & HugepagesEnabled) != 0; } static inline int flags() { return m_flags; } static inline int threads() { return m_threads; } diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index f47b6ae4..cfdb501b 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -85,9 +85,8 @@ static BOOL SetLockPagesPrivilege() { static LSA_UNICODE_STRING StringToLsaUnicodeString(LPCTSTR string) { LSA_UNICODE_STRING lsaString; - DWORD dwLen = 0; - dwLen = wcslen(string); + DWORD dwLen = (DWORD) wcslen(string); lsaString.Buffer = (LPWSTR) string; lsaString.Length = (USHORT)((dwLen) * sizeof(WCHAR)); lsaString.MaximumLength = (USHORT)((dwLen + 1) * sizeof(WCHAR)); diff --git a/src/Options.cpp b/src/Options.cpp index 1a1e1c69..e79231d5 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -371,7 +371,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_retries = arg; + m_retries = (int) arg; break; case 'R': /* --retry-pause */ @@ -380,7 +380,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_retryPause = arg; + m_retryPause = (int) arg; break; case 't': /* --threads */ @@ -389,7 +389,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_threads = arg; + m_threads = (int) arg; break; case 'v': /* --av */ @@ -398,7 +398,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_algoVariant = arg; + m_algoVariant = (int) arg; break; case 1003: /* --donate-level */ @@ -407,7 +407,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_donateLevel = arg; + m_donateLevel = (int) arg; break; case 1004: /* --max-cpu-usage */ @@ -416,7 +416,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_maxCpuUsage = arg; + m_maxCpuUsage = (int) arg; break; case 1007: /* --print-time */ @@ -425,7 +425,7 @@ bool Options::parseArg(int key, uint64_t arg) return false; } - m_printTime = arg; + m_printTime = (int) arg; break; case 1020: /* --cpu-affinity */ @@ -609,7 +609,7 @@ bool Options::setAlgo(const char *algo) { for (size_t i = 0; i < ARRAY_SIZE(algo_names); i++) { if (algo_names[i] && !strcmp(algo, algo_names[i])) { - m_algo = i; + m_algo = (int) i; break; } diff --git a/src/crypto/CryptoNight_p.h b/src/crypto/CryptoNight_p.h index a74a4ee0..b85a9da6 100644 --- a/src/crypto/CryptoNight_p.h +++ b/src/crypto/CryptoNight_p.h @@ -311,7 +311,7 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output) template inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx) { - keccak(static_cast(input), size, ctx->state0, 200); + keccak(static_cast(input), (int) size, ctx->state0, 200); cn_explode_scratchpad((__m128i*) ctx->state0, (__m128i*) ctx->memory); @@ -365,8 +365,8 @@ inline void cryptonight_hash(const void *__restrict__ input, size_t size, void * template inline void cryptonight_double_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, struct cryptonight_ctx *__restrict__ ctx) { - keccak((const uint8_t *) input, size, ctx->state0, 200); - keccak((const uint8_t *) input + size, size, ctx->state1, 200); + keccak((const uint8_t *) input, (int) size, ctx->state0, 200); + keccak((const uint8_t *) input + size, (int) size, ctx->state1, 200); const uint8_t* l0 = ctx->memory; const uint8_t* l1 = ctx->memory + MEM; diff --git a/src/crypto/c_blake256.c b/src/crypto/c_blake256.c index 0b484b94..00a84c22 100644 --- a/src/crypto/c_blake256.c +++ b/src/crypto/c_blake256.c @@ -148,7 +148,7 @@ void blake256_update(state *S, const uint8_t *data, uint64_t datalen) { if (datalen > 0) { memcpy((void *) (S->buf + left), (void *) data, datalen >> 3); - S->buflen = (left << 3) + datalen; + S->buflen = (left << 3) + (int) datalen; } else { S->buflen = 0; } diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index 51e8040a..b641c0e6 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -92,8 +92,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) } } - const size_t len = 64 + strlen(fmt) + 2; - char *buf = new char[len]; + char *buf = new char[64 + strlen(fmt) + 2]; sprintf(buf, "[%d-%02d-%02d %02d:%02d:%02d]%s %s%s\n", stime.tm_year + 1900, @@ -113,8 +112,7 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { - const int len = 64 + strlen(fmt) + 2; - char *buf = new char[len]; + char *buf = new char[64 + strlen(fmt) + 2]; sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : ""); @@ -129,7 +127,7 @@ void ConsoleLog::print(char *fmt, va_list args) uv_buf_t buf; buf.base = strdup(m_buf); - buf.len = strlen(buf.base); + buf.len = (ULONG) strlen(buf.base); uv_write_t *req = new uv_write_t; req->data = buf.base; diff --git a/src/log/FileLog.cpp b/src/log/FileLog.cpp index 224c600d..9a8711a4 100644 --- a/src/log/FileLog.cpp +++ b/src/log/FileLog.cpp @@ -88,7 +88,7 @@ void FileLog::onWrite(uv_fs_t *req) void FileLog::write(char *data, size_t size) { - uv_buf_t buf = uv_buf_init(data, size); + uv_buf_t buf = uv_buf_init(data, (unsigned int) size); uv_fs_t *req = static_cast(malloc(sizeof(uv_fs_t))); req->data = buf.base; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index 2c6e3ba4..a129ddb0 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -99,7 +99,7 @@ int64_t Client::send(char *data, size_t size) return -1; } - uv_buf_t buf = uv_buf_init(data, size ? size : strlen(data)); + uv_buf_t buf = uv_buf_init(data, (unsigned int) (size ? size : strlen(data))); uv_write_t *req = new uv_write_t; req->data = buf.base; @@ -464,7 +464,7 @@ void Client::reconnect() } m_failures++; - m_listener->onClose(this, m_failures); + m_listener->onClose(this, (int) m_failures); m_expire = uv_now(uv_default_loop()) + m_retryPause; } @@ -501,7 +501,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t auto client = getClient(handle->data); buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; - buf->len = client->m_recvBuf.len - client->m_recvBufPos; + buf->len = client->m_recvBuf.len - (ULONG) client->m_recvBufPos; } @@ -548,7 +548,7 @@ void Client::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) auto client = getClient(stream->data); if (nread < 0) { if (nread != UV_EOF && !client->m_quiet) { - LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror(nread)); + LOG_ERR("[%s:%u] read error: \"%s\"", client->m_url.host(), client->m_url.port(), uv_strerror((int) nread)); } return client->close();; diff --git a/src/net/Job.cpp b/src/net/Job.cpp index 4929aaf5..bce65e62 100644 --- a/src/net/Job.cpp +++ b/src/net/Job.cpp @@ -82,7 +82,7 @@ bool Job::setBlob(const char *blob) return false; } - if (!fromHex(blob, m_size * 2, m_blob)) { + if (!fromHex(blob, (int) m_size * 2, m_blob)) { return false; } diff --git a/src/net/Job.h b/src/net/Job.h index e7fca53e..1b2f732a 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -44,9 +44,9 @@ public: inline const char *id() const { return m_id; } inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } + inline size_t size() const { return m_size; } inline uint32_t *nonce() { return reinterpret_cast(m_blob + 39); } - inline uint32_t diff() const { return m_diff; } - inline uint32_t size() const { return m_size; } + inline uint32_t diff() const { return (uint32_t) m_diff; } inline uint64_t target() const { return m_target; } inline void setNicehash(bool nicehash) { m_nicehash = nicehash; } @@ -67,7 +67,7 @@ private: int m_poolId; VAR_ALIGN(16, char m_id[64]); VAR_ALIGN(16, uint8_t m_blob[84]); // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk. - uint32_t m_size; + size_t m_size; uint64_t m_diff; uint64_t m_target; diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 2e6ec298..a5132c73 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -21,6 +21,7 @@ * along with this program. If not, see . */ +#pragma warning(disable:4244) #include #include diff --git a/src/net/Url.cpp b/src/net/Url.cpp index 82b788d9..a0024d26 100644 --- a/src/net/Url.cpp +++ b/src/net/Url.cpp @@ -121,7 +121,7 @@ bool Url::parse(const char *url) memcpy(m_host, base, size - 1); m_host[size - 1] = '\0'; - m_port = strtol(port, nullptr, 10); + m_port = (uint16_t) strtol(port, nullptr, 10); return true; } diff --git a/src/net/strategies/FailoverStrategy.cpp b/src/net/strategies/FailoverStrategy.cpp index 37afffec..e25b8c58 100644 --- a/src/net/strategies/FailoverStrategy.cpp +++ b/src/net/strategies/FailoverStrategy.cpp @@ -140,7 +140,7 @@ void FailoverStrategy::onResultAccepted(Client *client, int64_t seq, uint32_t di void FailoverStrategy::add(const Url *url, const char *agent) { - Client *client = new Client(m_pools.size(), agent, this); + Client *client = new Client((int) m_pools.size(), agent, this); client->setUrl(url); client->setRetryPause(Options::i()->retryPause() * 1000); diff --git a/src/workers/Hashrate.cpp b/src/workers/Hashrate.cpp index 4c373156..5bc65698 100644 --- a/src/workers/Hashrate.cpp +++ b/src/workers/Hashrate.cpp @@ -127,8 +127,8 @@ double Hashrate::calc(size_t threadId, size_t ms) const } double hashes, time; - hashes = lastestHashCnt - earliestHashCount; - time = lastestStamp - earliestStamp; + hashes = (double) lastestHashCnt - earliestHashCount; + time = (double) lastestStamp - earliestStamp; time /= 1000.0; return hashes / time; From eb140fd30f811a833a819a9ddba3d7839a162b91 Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 14 Aug 2017 09:53:48 +0300 Subject: [PATCH 03/26] Fix gcc warnings. --- src/3rdparty/jansson/dump.c | 2 ++ src/3rdparty/jansson/hashtable.c | 2 ++ src/net/Network.cpp | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/3rdparty/jansson/dump.c b/src/3rdparty/jansson/dump.c index a332241d..59b9b2c7 100644 --- a/src/3rdparty/jansson/dump.c +++ b/src/3rdparty/jansson/dump.c @@ -5,7 +5,9 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#ifdef _MSC_VER #pragma warning(disable:4090) +#endif #ifndef _GNU_SOURCE #define _GNU_SOURCE diff --git a/src/3rdparty/jansson/hashtable.c b/src/3rdparty/jansson/hashtable.c index e79f83cd..dcc1687b 100644 --- a/src/3rdparty/jansson/hashtable.c +++ b/src/3rdparty/jansson/hashtable.c @@ -5,7 +5,9 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#ifdef _MSC_VER #pragma warning(disable:4334) +#endif #if HAVE_CONFIG_H #include diff --git a/src/net/Network.cpp b/src/net/Network.cpp index a5132c73..04ce2ae7 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -21,7 +21,9 @@ * along with this program. If not, see . */ +#ifdef _MSC_VER #pragma warning(disable:4244) +#endif #include #include From 61859dfe14b7045d5df02f142666509949a0a24d Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 15 Aug 2017 03:04:46 +0300 Subject: [PATCH 04/26] Add class Platform. --- CMakeLists.txt | 12 +++--- src/App.cpp | 8 +++- src/Options.h | 2 + src/Platform.cpp | 28 +++++++++++++ src/Platform.h | 41 +++++++++++++++++++ src/{net/Network_mac.cpp => Platform_mac.cpp} | 21 ++++++++-- .../Network_unix.cpp => Platform_unix.cpp} | 20 +++++++-- src/{net/Network_win.cpp => Platform_win.cpp} | 22 ++++++++-- src/net/Network.cpp | 9 ++-- src/net/Network.h | 3 -- 10 files changed, 141 insertions(+), 25 deletions(-) create mode 100644 src/Platform.cpp create mode 100644 src/Platform.h rename src/{net/Network_mac.cpp => Platform_mac.cpp} (85%) rename src/{net/Network_unix.cpp => Platform_unix.cpp} (87%) rename src/{net/Network_win.cpp => Platform_win.cpp} (90%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ac3ae5a..04fccdc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,12 +28,13 @@ set(HEADERS src/net/Job.h src/net/JobResult.h src/net/Network.h - src/net/SubmitResult.h - src/net/Url.h src/net/strategies/DonateStrategy.h src/net/strategies/FailoverStrategy.h src/net/strategies/SinglePoolStrategy.h + src/net/SubmitResult.h + src/net/Url.h src/Options.h + src/Platform.h src/Summary.h src/version.h src/workers/DoubleWorker.h @@ -73,6 +74,7 @@ set(SOURCES src/net/strategies/SinglePoolStrategy.cpp src/net/Url.cpp src/Options.cpp + src/Platform.cpp src/Summary.cpp src/workers/DoubleWorker.cpp src/workers/Handle.cpp @@ -100,7 +102,7 @@ if (WIN32) src/App_win.cpp src/Cpu_win.cpp src/Mem_win.cpp - src/net/Network_win.cpp + src/Platform_win.cpp ) add_definitions(/DWIN32) @@ -110,14 +112,14 @@ elseif (APPLE) src/App_unix.cpp src/Cpu_mac.cpp src/Mem_unix.cpp - src/net/Network_mac.cpp + src/Platform_mac.cpp ) else() set(SOURCES_OS src/App_unix.cpp src/Cpu_unix.cpp src/Mem_unix.cpp - src/net/Network_unix.cpp + src/Platform_unix.cpp ) set(EXTRA_LIBS pthread) diff --git a/src/App.cpp b/src/App.cpp index de6f2785..e4af60bf 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -36,6 +36,7 @@ #include "Mem.h" #include "net/Network.h" #include "Options.h" +#include "Platform.h" #include "Summary.h" #include "version.h" #include "workers/Workers.h" @@ -80,6 +81,8 @@ App::App(int argc, char **argv) : } # endif + Platform::init(); + m_network = new Network(m_options); uv_signal_init(uv_default_loop(), &m_signal); @@ -120,10 +123,11 @@ int App::exec() uv_loop_close(uv_default_loop()); uv_tty_reset_mode(); - free(m_network); - free(m_options); + delete m_network; + Options::release(); Mem::release(); + Platform::release(); return r; } diff --git a/src/Options.h b/src/Options.h index 7a6a7339..3735fca0 100644 --- a/src/Options.h +++ b/src/Options.h @@ -69,6 +69,8 @@ public: inline int threads() const { return m_threads; } inline int64_t affinity() const { return m_affinity; } + inline static void release() { delete m_self; } + const char *algoName() const; private: diff --git a/src/Platform.cpp b/src/Platform.cpp new file mode 100644 index 00000000..aa0c5706 --- /dev/null +++ b/src/Platform.cpp @@ -0,0 +1,28 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2016-2017 XMRig + * + * + * 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 . + */ + + +#include "Platform.h" + + +char *Platform::m_userAgent = nullptr; diff --git a/src/Platform.h b/src/Platform.h new file mode 100644 index 00000000..cc798fca --- /dev/null +++ b/src/Platform.h @@ -0,0 +1,41 @@ +/* XMRig + * Copyright 2010 Jeff Garzik + * Copyright 2012-2014 pooler + * Copyright 2014 Lucas Jones + * Copyright 2014-2016 Wolf9466 + * Copyright 2016 Jay D Dee + * Copyright 2016-2017 XMRig + * + * + * 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 . + */ + +#ifndef __PLATFORM_H__ +#define __PLATFORM_H__ + + +class Platform +{ +public: + static void init(); + static void release(); + + static inline const char *userAgent() { return m_userAgent; } + +private: + static char *m_userAgent; +}; + + +#endif /* __PLATFORM_H__ */ diff --git a/src/net/Network_mac.cpp b/src/Platform_mac.cpp similarity index 85% rename from src/net/Network_mac.cpp rename to src/Platform_mac.cpp index c3c42a3e..a25d1ac1 100644 --- a/src/net/Network_mac.cpp +++ b/src/Platform_mac.cpp @@ -23,17 +23,32 @@ #include +#include -#include "net/Network.h" + +#include "Platform.h" #include "version.h" -char *Network::userAgent() +static inline char *createUserAgent() { const size_t max = 128; - char *buf = static_cast(malloc(max)); + char *buf = new char[max]; snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__); return buf; } + + +void Platform::init() +{ + m_userAgent = createUserAgent(); +} + + +void Platform::release() +{ + delete [] m_userAgent; +} + diff --git a/src/net/Network_unix.cpp b/src/Platform_unix.cpp similarity index 87% rename from src/net/Network_unix.cpp rename to src/Platform_unix.cpp index 546d1b8a..6da3a197 100644 --- a/src/net/Network_unix.cpp +++ b/src/Platform_unix.cpp @@ -23,17 +23,18 @@ #include +#include -#include "net/Network.h" +#include "Platform.h" #include "version.h" -char *Network::userAgent() +static inline char *createUserAgent() { const size_t max = 128; - char *buf = static_cast(malloc(max)); + char *buf = new char[max]; int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); # if defined(__x86_64__) @@ -48,3 +49,16 @@ char *Network::userAgent() return buf; } + + +void Platform::init() +{ + m_userAgent = createUserAgent(); +} + + +void Platform::release() +{ + delete [] m_userAgent; +} + diff --git a/src/net/Network_win.cpp b/src/Platform_win.cpp similarity index 90% rename from src/net/Network_win.cpp rename to src/Platform_win.cpp index 6ae5e322..7fbe0c8c 100644 --- a/src/net/Network_win.cpp +++ b/src/Platform_win.cpp @@ -24,9 +24,10 @@ #include #include +#include -#include "net/Network.h" +#include "Platform.h" #include "version.h" @@ -48,12 +49,12 @@ static inline OSVERSIONINFOEX winOsVersion() } -char *Network::userAgent() +static inline char *createUserAgent() { const auto osver = winOsVersion(); - const size_t max = 128; + const size_t max = 160; - char *buf = static_cast(malloc(max)); + char *buf = new char[max]; int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion); # if defined(__x86_64__) || defined(_M_AMD64) @@ -70,3 +71,16 @@ char *Network::userAgent() return buf; } + + +void Platform::init() +{ + m_userAgent = createUserAgent(); +} + + +void Platform::release() +{ + delete [] m_userAgent; +} + diff --git a/src/net/Network.cpp b/src/net/Network.cpp index 04ce2ae7..d732c774 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -38,6 +38,7 @@ #include "net/strategies/SinglePoolStrategy.h" #include "net/Url.h" #include "Options.h" +#include "Platform.h" #include "workers/Workers.h" @@ -50,19 +51,18 @@ Network::Network(const Options *options) : srand(time(0) ^ (uintptr_t) this); Workers::setListener(this); - m_agent = userAgent(); const std::vector &pools = options->pools(); if (pools.size() > 1) { - m_strategy = new FailoverStrategy(pools, m_agent, this); + m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this); } else { - m_strategy = new SinglePoolStrategy(pools.front(), m_agent, this); + m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this); } if (m_options->donateLevel() > 0) { - m_donate = new DonateStrategy(m_agent, this); + m_donate = new DonateStrategy(Platform::userAgent(), this); } m_timer.data = this; @@ -74,7 +74,6 @@ Network::Network(const Options *options) : Network::~Network() { - free(m_agent); } diff --git a/src/net/Network.h b/src/net/Network.h index ba1982e1..33806f63 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -47,8 +47,6 @@ public: void connect(); void stop(); - static char *userAgent(); - protected: void onActive(Client *client) override; void onJob(Client *client, const Job &job) override; @@ -64,7 +62,6 @@ private: static void onTick(uv_timer_t *handle); - char *m_agent; const Options *m_options; IStrategy *m_donate; IStrategy *m_strategy; From c40f212e23e1b03c9e84a7538bb55703fcc3e32b Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 15 Aug 2017 03:13:11 +0300 Subject: [PATCH 05/26] Fix Linux build. --- src/log/ConsoleLog.cpp | 2 +- src/net/Client.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index b641c0e6..7b044590 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -127,7 +127,7 @@ void ConsoleLog::print(char *fmt, va_list args) uv_buf_t buf; buf.base = strdup(m_buf); - buf.len = (ULONG) strlen(buf.base); + buf.len = strlen(buf.base); uv_write_t *req = new uv_write_t; req->data = buf.base; diff --git a/src/net/Client.cpp b/src/net/Client.cpp index a129ddb0..fde7f480 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -501,7 +501,7 @@ void Client::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t auto client = getClient(handle->data); buf->base = &client->m_recvBuf.base[client->m_recvBufPos]; - buf->len = client->m_recvBuf.len - (ULONG) client->m_recvBufPos; + buf->len = client->m_recvBuf.len - client->m_recvBufPos; } From f05a3284743d01e1081e5ae66284950947b203dd Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 15 Aug 2017 08:19:55 +0300 Subject: [PATCH 06/26] Added --cpu-priority option. --- src/App.cpp | 3 +- src/Options.cpp | 11 ++++++ src/Options.h | 2 ++ src/Platform.h | 2 ++ src/Platform_mac.cpp | 12 +++++++ src/Platform_unix.cpp | 12 +++++++ src/Platform_win.cpp | 74 +++++++++++++++++++++++++++++++++++++++++ src/config.json | 1 + src/net/Job.h | 1 + src/net/JobResult.h | 9 +++++ src/workers/Handle.cpp | 3 +- src/workers/Handle.h | 4 ++- src/workers/Worker.cpp | 2 ++ src/workers/Workers.cpp | 4 +-- src/workers/Workers.h | 2 +- 15 files changed, 136 insertions(+), 6 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index e4af60bf..28e61df3 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -82,6 +82,7 @@ App::App(int argc, char **argv) : # endif Platform::init(); + Platform::setProcessPriority(m_options->priority()); m_network = new Network(m_options); @@ -115,7 +116,7 @@ int App::exec() Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash()); Summary::print(); - Workers::start(m_options->affinity()); + Workers::start(m_options->affinity(), m_options->priority()); m_network->connect(); diff --git a/src/Options.cpp b/src/Options.cpp index e79231d5..832ed09a 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -63,6 +63,7 @@ Options:\n\ -r, --retries=N number of times to retry before switch to backup server (default: 5)\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ + --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-color disable colored output\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ -B, --background run the miner in the background\n\ @@ -91,6 +92,7 @@ static struct option const options[] = { { "background", 0, nullptr, 'B' }, { "config", 1, nullptr, 'c' }, { "cpu-affinity", 1, nullptr, 1020 }, + { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, { "help", 0, nullptr, 'h' }, { "keepalive", 0, nullptr ,'k' }, @@ -118,6 +120,7 @@ static struct option const config_options[] = { { "av", 1, nullptr, 'v' }, { "background", 0, nullptr, 'B' }, { "cpu-affinity", 1, nullptr, 1020 }, + { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, { "log-file", 1, nullptr, 'l' }, { "max-cpu-usage", 1, nullptr, 1004 }, @@ -211,6 +214,7 @@ Options::Options(int argc, char **argv) : m_donateLevel(kDonateLevel), m_maxCpuUsage(75), m_printTime(60), + m_priority(-1), m_retries(5), m_retryPause(5), m_threads(0), @@ -326,6 +330,7 @@ bool Options::parseArg(int key, const char *arg) case 1003: /* --donate-level */ case 1004: /* --max-cpu-usage */ case 1007: /* --print-time */ + case 1021: /* --cpu-priority */ return parseArg(key, strtol(arg, nullptr, 10)); case 'B': /* --background */ @@ -434,6 +439,12 @@ bool Options::parseArg(int key, uint64_t arg) } break; + case 1021: /* --cpu-priority */ + if (arg <= 5) { + m_priority = (int) arg; + } + break; + default: break; } diff --git a/src/Options.h b/src/Options.h index 3735fca0..0e57100e 100644 --- a/src/Options.h +++ b/src/Options.h @@ -64,6 +64,7 @@ public: inline int algoVariant() const { return m_algoVariant; } inline int donateLevel() const { return m_donateLevel; } inline int printTime() const { return m_printTime; } + inline int priority() const { return m_priority; } inline int retries() const { return m_retries; } inline int retryPause() const { return m_retryPause; } inline int threads() const { return m_threads; } @@ -109,6 +110,7 @@ private: int m_donateLevel; int m_maxCpuUsage; int m_printTime; + int m_priority; int m_retries; int m_retryPause; int m_threads; diff --git a/src/Platform.h b/src/Platform.h index cc798fca..cc6fd879 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -30,6 +30,8 @@ class Platform public: static void init(); static void release(); + static void setProcessPriority(int priority); + static void setThreadPriority(int priority); static inline const char *userAgent() { return m_userAgent; } diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index a25d1ac1..456e6f74 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -52,3 +52,15 @@ void Platform::release() delete [] m_userAgent; } + +void Platform::setProcessPriority(int priority) +{ + +} + + +void Platform::setThreadPriority(int priority) +{ + +} + diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 6da3a197..861fe873 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -62,3 +62,15 @@ void Platform::release() delete [] m_userAgent; } + +void Platform::setProcessPriority(int priority) +{ + +} + + + +void Platform::setThreadPriority(int priority) +{ + +} diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index 7fbe0c8c..7943b662 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -84,3 +84,77 @@ void Platform::release() delete [] m_userAgent; } + +void Platform::setProcessPriority(int priority) +{ + if (priority == -1) { + return; + } + + DWORD prio = IDLE_PRIORITY_CLASS; + switch (priority) + { + case 1: + prio = BELOW_NORMAL_PRIORITY_CLASS; + break; + + case 2: + prio = NORMAL_PRIORITY_CLASS; + break; + + case 3: + prio = ABOVE_NORMAL_PRIORITY_CLASS; + break; + + case 4: + prio = HIGH_PRIORITY_CLASS; + break; + + case 5: + prio = REALTIME_PRIORITY_CLASS; + + default: + break; + } + + SetPriorityClass(GetCurrentProcess(), prio); +} + + + +void Platform::setThreadPriority(int priority) +{ + if (priority == -1) { + return; + } + + int prio = THREAD_PRIORITY_IDLE; + switch (priority) + { + case 1: + prio = THREAD_PRIORITY_BELOW_NORMAL; + break; + + case 2: + prio = THREAD_PRIORITY_NORMAL; + break; + + case 3: + prio = THREAD_PRIORITY_ABOVE_NORMAL; + break; + + case 4: + prio = THREAD_PRIORITY_HIGHEST; + break; + + case 5: + prio = THREAD_PRIORITY_TIME_CRITICAL; + break; + + default: + break; + } + + SetThreadPriority(GetCurrentThread(), prio); +} + diff --git a/src/config.json b/src/config.json index a0ce1a3b..afc2936b 100644 --- a/src/config.json +++ b/src/config.json @@ -4,6 +4,7 @@ "background": false, "colors": true, "cpu-affinity": null, + "cpu-priority": null, "donate-level": 5, "log-file": null, "max-cpu-usage": 75, diff --git a/src/net/Job.h b/src/net/Job.h index 1b2f732a..86160584 100644 --- a/src/net/Job.h +++ b/src/net/Job.h @@ -42,6 +42,7 @@ public: inline bool isNicehash() const { return m_nicehash; } inline bool isValid() const { return m_size > 0 && m_diff > 0; } inline const char *id() const { return m_id; } + inline const uint32_t *nonce() const { return reinterpret_cast(m_blob + 39); } inline const uint8_t *blob() const { return m_blob; } inline int poolId() const { return m_poolId; } inline size_t size() const { return m_size; } diff --git a/src/net/JobResult.h b/src/net/JobResult.h index 9ced3cac..de3b17ad 100644 --- a/src/net/JobResult.h +++ b/src/net/JobResult.h @@ -43,6 +43,15 @@ public: } + inline JobResult(const Job &job) : poolId(0), diff(0), nonce(0) + { + memcpy(jobId, job.id(), sizeof(jobId)); + poolId = job.poolId(); + diff = job.diff(); + nonce = *job.nonce(); + } + + inline JobResult &operator=(const Job &job) { memcpy(jobId, job.id(), sizeof(jobId)); poolId = job.poolId(); diff --git a/src/workers/Handle.cpp b/src/workers/Handle.cpp index 8b748cd3..c461cee7 100644 --- a/src/workers/Handle.cpp +++ b/src/workers/Handle.cpp @@ -25,7 +25,8 @@ #include "workers/Handle.h" -Handle::Handle(int threadId, int threads, int64_t affinity) : +Handle::Handle(int threadId, int threads, int64_t affinity, int priority) : + m_priority(priority), m_threadId(threadId), m_threads(threads), m_affinity(affinity), diff --git a/src/workers/Handle.h b/src/workers/Handle.h index a663fbe9..9faae0d0 100644 --- a/src/workers/Handle.h +++ b/src/workers/Handle.h @@ -35,10 +35,11 @@ class IWorker; class Handle { public: - Handle(int threadId, int threads, int64_t affinity); + Handle(int threadId, int threads, int64_t affinity, int priority); void join(); void start(void (*callback) (void *)); + inline int priority() const { return m_priority; } inline int threadId() const { return m_threadId; } inline int threads() const { return m_threads; } inline int64_t affinity() const { return m_affinity; } @@ -46,6 +47,7 @@ public: inline void setWorker(IWorker *worker) { m_worker = worker; } private: + int m_priority; int m_threadId; int m_threads; int64_t m_affinity; diff --git a/src/workers/Worker.cpp b/src/workers/Worker.cpp index 583c1d45..02646ced 100644 --- a/src/workers/Worker.cpp +++ b/src/workers/Worker.cpp @@ -26,6 +26,7 @@ #include "Cpu.h" #include "Mem.h" +#include "Platform.h" #include "workers/Handle.h" #include "workers/Worker.h" @@ -42,6 +43,7 @@ Worker::Worker(Handle *handle) : Cpu::setAffinity(m_id, handle->affinity()); } + Platform::setThreadPriority(handle->priority()); m_ctx = Mem::create(m_id); } diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index b056c826..e51f5d22 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -98,7 +98,7 @@ void Workers::setJob(const Job &job) } -void Workers::start(int64_t affinity) +void Workers::start(int64_t affinity, int priority) { const int threads = Mem::threads(); m_hashrate = new Hashrate(threads); @@ -114,7 +114,7 @@ void Workers::start(int64_t affinity) uv_timer_start(&m_timer, Workers::onTick, 500, 500); for (int i = 0; i < threads; ++i) { - Handle *handle = new Handle(i, threads, affinity); + Handle *handle = new Handle(i, threads, affinity, priority); m_workers.push_back(handle); handle->start(Workers::onReady); } diff --git a/src/workers/Workers.h b/src/workers/Workers.h index 0caf22a2..e76d0a62 100644 --- a/src/workers/Workers.h +++ b/src/workers/Workers.h @@ -46,7 +46,7 @@ public: static void printHashrate(bool detail); static void setEnabled(bool enabled); static void setJob(const Job &job); - static void start(int64_t affinity); + static void start(int64_t affinity, int priority); static void stop(); static void submit(const JobResult &result); From ad0d876b18ab3f9715c5679eabba761efbfe37ed Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 15 Aug 2017 09:03:10 +0300 Subject: [PATCH 07/26] Added support --cpu-priority support for Linux. --- src/Platform_unix.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 861fe873..0873e954 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -22,7 +22,9 @@ */ +#include #include +#include #include @@ -65,12 +67,51 @@ void Platform::release() void Platform::setProcessPriority(int priority) { - } void Platform::setThreadPriority(int priority) { + if (priority == -1) { + return; + } + int prio = 19; + switch (priority) + { + case 1: + prio = 5; + break; + + case 2: + prio = 0; + break; + + case 3: + prio = -5; + break; + + case 4: + prio = -10; + break; + + case 5: + prio = -15; + break; + + default: + break; + } + + setpriority(PRIO_PROCESS, 0, prio); + + if (priority == 0) { + sched_param param; + param.sched_priority = 0; + + if (sched_setscheduler(0, SCHED_IDLE, ¶m) != 0) { + sched_setscheduler(0, SCHED_BATCH, ¶m); + } + } } From 1b0ddae4ebf4631ac275518f43cb40c7829580f5 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 12:22:35 +0300 Subject: [PATCH 08/26] Fixed: failed open default config file if path contains non English characters. --- src/Options.cpp | 45 +++++++++++++------------------------------- src/Platform.cpp | 35 +++++++++++++++++++++++++++++++++- src/Platform.h | 2 ++ src/Platform_win.cpp | 1 + 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 832ed09a..9d2e3504 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -38,6 +38,7 @@ #include "donate.h" #include "net/Url.h" #include "Options.h" +#include "Platform.h" #include "version.h" @@ -154,34 +155,6 @@ static const char *algo_names[] = { }; -static char *defaultConfigName() -{ - size_t size = 512; - char *buf = new char[size]; - - if (uv_exepath(buf, &size) < 0) { - delete [] buf; - return nullptr; - } - - if (size < 500) { -# ifdef WIN32 - char *p = strrchr(buf, '\\'); -# else - char *p = strrchr(buf, '/'); -# endif - - if (p) { - strcpy(p + 1, "config.json"); - return buf; - } - } - - delete [] buf; - return nullptr; -} - - Options *Options::parse(int argc, char **argv) { Options *options = new Options(argc, argv); @@ -241,9 +214,7 @@ Options::Options(int argc, char **argv) : } if (!m_pools[0]->isValid()) { - char *fileName = defaultConfigName(); - parseConfig(fileName); - delete [] fileName; + parseConfig(Platform::defaultConfigName()); } if (!m_pools[0]->isValid()) { @@ -508,8 +479,18 @@ Url *Options::parseUrl(const char *arg) const void Options::parseConfig(const char *fileName) { + uv_fs_t req; + const int fd = uv_fs_open(uv_default_loop(), &req, fileName, O_RDONLY, 0644, nullptr); + if (fd < 0) { + fprintf(stderr, "unable to open %s: %s\n", fileName, uv_strerror(fd)); + return; + } + json_error_t err; - json_t *config = json_load_file(fileName, 0, &err); + json_t *config = json_loadfd(fd, 0, &err); + + uv_fs_close(uv_default_loop(), &req, fd, nullptr); + uv_fs_req_cleanup(&req); if (!json_is_object(config)) { if (config) { diff --git a/src/Platform.cpp b/src/Platform.cpp index aa0c5706..57c655fa 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -22,7 +22,40 @@ */ +#include + + #include "Platform.h" -char *Platform::m_userAgent = nullptr; +char *Platform::m_defaultConfigName = nullptr; +char *Platform::m_userAgent = nullptr; + + +const char *Platform::defaultConfigName() +{ + size_t size = 520; + + if (m_defaultConfigName == nullptr) { + m_defaultConfigName = new char[size]; + } + + if (uv_exepath(m_defaultConfigName, &size) < 0) { + return nullptr; + } + + if (size < 500) { +# ifdef WIN32 + char *p = strrchr(m_defaultConfigName, '\\'); +# else + char *p = strrchr(m_defaultConfigName, '/'); +# endif + + if (p) { + strcpy(p + 1, "config.json"); + return m_defaultConfigName; + } + } + + return nullptr; +} diff --git a/src/Platform.h b/src/Platform.h index cc6fd879..1c1d5ce9 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -28,6 +28,7 @@ class Platform { public: + static const char *defaultConfigName(); static void init(); static void release(); static void setProcessPriority(int priority); @@ -36,6 +37,7 @@ public: static inline const char *userAgent() { return m_userAgent; } private: + static char *m_defaultConfigName; static char *m_userAgent; }; diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index 7943b662..3d520586 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -81,6 +81,7 @@ void Platform::init() void Platform::release() { + delete [] m_defaultConfigName; delete [] m_userAgent; } From 79ffb95f05dd4ff74f805b37957c375c408901e6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 12:57:05 +0300 Subject: [PATCH 09/26] Added support for --cpu-priority for OS X. --- src/Platform_mac.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index 456e6f74..f57c7ea1 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -23,6 +23,7 @@ #include +#include #include @@ -61,6 +62,37 @@ void Platform::setProcessPriority(int priority) void Platform::setThreadPriority(int priority) { + if (priority == -1) { + return; + } + int prio = 19; + switch (priority) + { + case 1: + prio = 5; + break; + + case 2: + prio = 0; + break; + + case 3: + prio = -5; + break; + + case 4: + prio = -10; + break; + + case 5: + prio = -15; + break; + + default: + break; + } + + setpriority(PRIO_PROCESS, 0, prio); } From 27f02d5f9f5e8e2888b70a3661562b6073a3762c Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 13:19:14 +0300 Subject: [PATCH 10/26] Added option --user-agent. --- src/App.cpp | 2 +- src/Options.cpp | 11 ++++++++++- src/Options.h | 2 ++ src/Platform.h | 2 +- src/Platform_mac.cpp | 4 ++-- src/Platform_unix.cpp | 4 ++-- src/Platform_win.cpp | 4 ++-- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 28e61df3..83ead3af 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -81,7 +81,7 @@ App::App(int argc, char **argv) : } # endif - Platform::init(); + Platform::init(m_options->userAgent()); Platform::setProcessPriority(m_options->priority()); m_network = new Network(m_options); diff --git a/src/Options.cpp b/src/Options.cpp index 9d2e3504..95d099d5 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -67,6 +67,7 @@ Options:\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ --no-color disable colored output\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ + --user-agent set custom user-agent string for pool\n\ -B, --background run the miner in the background\n\ -c, --config=FILE load a JSON-format configuration file\n\ -l, --log-file=FILE log all output to a file\n" @@ -110,6 +111,7 @@ static struct option const options[] = { { "threads", 1, nullptr, 't' }, { "url", 1, nullptr, 'o' }, { "user", 1, nullptr, 'u' }, + { "user-agent", 1, nullptr, 1008 }, { "userpass", 1, nullptr, 'O' }, { "version", 0, nullptr, 'V' }, { 0, 0, 0, 0 } @@ -120,6 +122,7 @@ static struct option const config_options[] = { { "algo", 1, nullptr, 'a' }, { "av", 1, nullptr, 'v' }, { "background", 0, nullptr, 'B' }, + { "colors", 0, nullptr, 2000 }, { "cpu-affinity", 1, nullptr, 1020 }, { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, @@ -131,7 +134,7 @@ static struct option const config_options[] = { { "safe", 0, nullptr, 1005 }, { "syslog", 0, nullptr, 'S' }, { "threads", 1, nullptr, 't' }, - { "colors", 0, nullptr, 2000 }, + { "user-agent", 1, nullptr, 1008 }, { 0, 0, 0, 0 } }; @@ -182,6 +185,7 @@ Options::Options(int argc, char **argv) : m_safe(false), m_syslog(false), m_logFile(nullptr), + m_userAgent(nullptr), m_algo(0), m_algoVariant(0), m_donateLevel(kDonateLevel), @@ -329,6 +333,11 @@ bool Options::parseArg(int key, const char *arg) return parseArg(key, p ? strtoull(p, nullptr, 16) : strtoull(arg, nullptr, 10)); } + case 1008: /* --user-agent */ + free(m_userAgent); + m_userAgent = strdup(arg); + break; + default: showUsage(1); return false; diff --git a/src/Options.h b/src/Options.h index 0e57100e..ae2a2928 100644 --- a/src/Options.h +++ b/src/Options.h @@ -59,6 +59,7 @@ public: inline bool doubleHash() const { return m_doubleHash; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } + inline const char *userAgent() const { return m_userAgent; } inline const std::vector &pools() const { return m_pools; } inline int algo() const { return m_algo; } inline int algoVariant() const { return m_algoVariant; } @@ -105,6 +106,7 @@ private: bool m_safe; bool m_syslog; char *m_logFile; + char *m_userAgent; int m_algo; int m_algoVariant; int m_donateLevel; diff --git a/src/Platform.h b/src/Platform.h index 1c1d5ce9..87c8cc4d 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -29,7 +29,7 @@ class Platform { public: static const char *defaultConfigName(); - static void init(); + static void init(const char *userAgent); static void release(); static void setProcessPriority(int priority); static void setThreadPriority(int priority); diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index f57c7ea1..3b5daef5 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -42,9 +42,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); } diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 0873e954..5a8271ab 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -53,9 +53,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); } diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index 3d520586..e61dc773 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -73,9 +73,9 @@ static inline char *createUserAgent() } -void Platform::init() +void Platform::init(const char *userAgent) { - m_userAgent = createUserAgent(); + m_userAgent = userAgent ? strdup(userAgent) : createUserAgent(); } From 8bba0df054614a7d76f693e21e088aa210d15f55 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 14:21:12 +0300 Subject: [PATCH 11/26] Added option --no-huge-pages. --- src/App.cpp | 2 +- src/Mem.h | 2 +- src/Mem_unix.cpp | 7 ++++++- src/Mem_win.cpp | 7 ++++++- src/Options.cpp | 13 ++++++++++++- src/Options.h | 2 ++ 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index 83ead3af..c172c045 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -113,7 +113,7 @@ int App::exec() return 1; } - Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash()); + Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash(), m_options->hugePages()); Summary::print(); Workers::start(m_options->affinity(), m_options->priority()); diff --git a/src/Mem.h b/src/Mem.h index 050fd8e8..58dba848 100644 --- a/src/Mem.h +++ b/src/Mem.h @@ -44,7 +44,7 @@ public: Lock = 4 }; - static bool allocate(int algo, int threads, bool doubleHash); + static bool allocate(int 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(); diff --git a/src/Mem_unix.cpp b/src/Mem_unix.cpp index 6de2bd40..7c41fd16 100644 --- a/src/Mem_unix.cpp +++ b/src/Mem_unix.cpp @@ -33,7 +33,7 @@ #include "Options.h" -bool Mem::allocate(int algo, int threads, bool doubleHash) +bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -42,6 +42,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash) const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const size_t size = MEMORY * (threads * ratio + 1); + if (!enabled) { + m_memory = static_cast(_mm_malloc(size, 16)); + return true; + } + m_flags |= HugepagesAvailable; # if defined(__APPLE__) diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index cfdb501b..3d0e2ee0 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -144,7 +144,7 @@ static BOOL TrySetLockPagesPrivilege() { } -bool Mem::allocate(int algo, int threads, bool doubleHash) +bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled) { m_algo = algo; m_threads = threads; @@ -153,6 +153,11 @@ bool Mem::allocate(int algo, int threads, bool doubleHash) const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1; const size_t size = MEMORY * (threads * ratio + 1); + if (!enabled) { + m_memory = static_cast(_mm_malloc(size, 16)); + return true; + } + if (TrySetLockPagesPrivilege()) { m_flags |= HugepagesAvailable; } diff --git a/src/Options.cpp b/src/Options.cpp index 95d099d5..15493e25 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -65,6 +65,7 @@ Options:\n\ -R, --retry-pause=N time to pause between retries (default: 5)\n\ --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\ --cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\ + --no-huge-pages disable huge pages support\n\ --no-color disable colored output\n\ --donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\ --user-agent set custom user-agent string for pool\n\ @@ -102,6 +103,7 @@ static struct option const options[] = { { "max-cpu-usage", 1, nullptr, 1004 }, { "nicehash", 0, nullptr, 1006 }, { "no-color", 0, nullptr, 1002 }, + { "no-huge-pages", 0, nullptr, 1009 }, { "pass", 1, nullptr, 'p' }, { "print-time", 1, nullptr, 1007 }, { "retries", 1, nullptr, 'r' }, @@ -126,6 +128,7 @@ static struct option const config_options[] = { { "cpu-affinity", 1, nullptr, 1020 }, { "cpu-priority", 1, nullptr, 1021 }, { "donate-level", 1, nullptr, 1003 }, + { "huge-pages", 0, nullptr, 1009 }, { "log-file", 1, nullptr, 'l' }, { "max-cpu-usage", 1, nullptr, 1004 }, { "print-time", 1, nullptr, 1007 }, @@ -181,6 +184,7 @@ Options::Options(int argc, char **argv) : m_background(false), m_colors(true), m_doubleHash(false), + m_hugePages(true), m_ready(false), m_safe(false), m_syslog(false), @@ -311,11 +315,14 @@ bool Options::parseArg(int key, const char *arg) case 'B': /* --background */ case 'k': /* --keepalive */ case 'S': /* --syslog */ - case 1002: /* --no-color */ case 1005: /* --safe */ case 1006: /* --nicehash */ return parseBoolean(key, true); + case 1002: /* --no-color */ + case 1009: /* --no-huge-pages */ + return parseBoolean(key, false); + case 'V': /* --version */ showVersion(); return false; @@ -462,6 +469,10 @@ bool Options::parseBoolean(int key, bool enable) m_pools.back()->setNicehash(enable); break; + case 1009: /* --no-huge-pages */ + m_hugePages = enable; + break; + case 2000: /* colors */ m_colors = enable; break; diff --git a/src/Options.h b/src/Options.h index ae2a2928..e85441d9 100644 --- a/src/Options.h +++ b/src/Options.h @@ -57,6 +57,7 @@ public: inline bool background() const { return m_background; } inline bool colors() const { return m_colors; } inline bool doubleHash() const { return m_doubleHash; } + inline bool hugePages() const { return m_hugePages; } inline bool syslog() const { return m_syslog; } inline const char *logFile() const { return m_logFile; } inline const char *userAgent() const { return m_userAgent; } @@ -102,6 +103,7 @@ private: bool m_background; bool m_colors; bool m_doubleHash; + bool m_hugePages; bool m_ready; bool m_safe; bool m_syslog; From beb9af43139312536b2861122689cc5e6de4af93 Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 14:44:35 +0300 Subject: [PATCH 12/26] Fixed, message "Huge pages support was successfully enabled, but reboot required to use it" was not shown in release builds. --- src/Mem_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mem_win.cpp b/src/Mem_win.cpp index 3d0e2ee0..a4f92cfe 100644 --- a/src/Mem_win.cpp +++ b/src/Mem_win.cpp @@ -123,7 +123,7 @@ static BOOL ObtainLockPagesPrivilege() { LSA_UNICODE_STRING str = StringToLsaUnicodeString(_T(SE_LOCK_MEMORY_NAME)); if (LsaAddAccountRights(handle, user->User.Sid, &str, 1) == 0) { - LOG_DEBUG("Huge pages support was successfully enabled, but reboot required to use it"); + LOG_NOTICE("Huge pages support was successfully enabled, but reboot required to use it"); result = TRUE; } From e049b80f1a877f3ae9d592a82f3528637f877c0d Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 14:49:37 +0300 Subject: [PATCH 13/26] Fixed linux build. --- src/Platform.cpp | 1 + src/Platform_unix.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Platform.cpp b/src/Platform.cpp index 57c655fa..4ddb1429 100644 --- a/src/Platform.cpp +++ b/src/Platform.cpp @@ -22,6 +22,7 @@ */ +#include #include diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 5a8271ab..6a65193c 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include From 9cb7d727c2699df7d06501e62e08c853bc2bd66b Mon Sep 17 00:00:00 2001 From: XMRig Date: Wed, 16 Aug 2017 15:14:21 +0300 Subject: [PATCH 14/26] Force close connection if IP address banned. --- src/net/Client.cpp | 24 +++++++++++++++++++++++- src/net/Client.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/net/Client.cpp b/src/net/Client.cpp index fde7f480..c2518be9 100644 --- a/src/net/Client.cpp +++ b/src/net/Client.cpp @@ -199,6 +199,28 @@ int64_t Client::submit(const JobResult &result) } +bool Client::isCriticalError(const char *message) +{ + if (!message) { + return false; + } + + if (strncasecmp(message, "Unauthenticated", 15) == 0) { + return true; + } + + if (strncasecmp(message, "your IP is banned", 17) == 0) { + return true; + } + + if (strncasecmp(message, "IP Address currently banned", 27) == 0) { + return true; + } + + return false; +} + + bool Client::parseJob(const json_t *params, int *code) { if (!json_is_object(params)) { @@ -405,7 +427,7 @@ void Client::parseResponse(int64_t id, const json_t *result, const json_t *error LOG_ERR("[%s:%u] error: \"%s\", code: %" PRId64, m_url.host(), m_url.port(), message, json_integer_value(json_object_get(error, "code"))); } - if (id == 1 || (message && strncasecmp(message, "Unauthenticated", 15) == 0)) { + if (id == 1 || isCriticalError(message)) { close(); } diff --git a/src/net/Client.h b/src/net/Client.h index b7eda325..f554e341 100644 --- a/src/net/Client.h +++ b/src/net/Client.h @@ -77,6 +77,7 @@ public: private: constexpr static size_t kRecvBufSize = 4096; + bool isCriticalError(const char *message); bool parseJob(const json_t *params, int *code); bool parseLogin(const json_t *result, int *code); int resolve(const char *host); From e3dd4a6581626825be0e04b1426a1138459db46c Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 17 Aug 2017 06:43:32 +0300 Subject: [PATCH 15/26] Fixed config load for MSVC. --- src/3rdparty/jansson/dump.c | 8 +++++++- src/3rdparty/jansson/hashtable_seed.c | 2 +- src/3rdparty/jansson/jansson_private_config.h | 4 +--- src/3rdparty/jansson/load.c | 7 ++++++- src/Options.cpp | 2 ++ 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/3rdparty/jansson/dump.c b/src/3rdparty/jansson/dump.c index 59b9b2c7..a92fdf7d 100644 --- a/src/3rdparty/jansson/dump.c +++ b/src/3rdparty/jansson/dump.c @@ -19,10 +19,16 @@ #include #include #include -#ifdef HAVE_UNISTD_H + +#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) #include #endif +#if defined(_MSC_VER) +#include +typedef SSIZE_T ssize_t; +#endif + #include "jansson.h" #include "strbuffer.h" #include "utf.h" diff --git a/src/3rdparty/jansson/hashtable_seed.c b/src/3rdparty/jansson/hashtable_seed.c index 8aed5406..5caeec97 100644 --- a/src/3rdparty/jansson/hashtable_seed.c +++ b/src/3rdparty/jansson/hashtable_seed.c @@ -21,7 +21,7 @@ #include #endif -#ifdef HAVE_UNISTD_H +#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) #include #endif diff --git a/src/3rdparty/jansson/jansson_private_config.h b/src/3rdparty/jansson/jansson_private_config.h index 671993d9..22800f84 100644 --- a/src/3rdparty/jansson/jansson_private_config.h +++ b/src/3rdparty/jansson/jansson_private_config.h @@ -92,9 +92,7 @@ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ -#ifndef _MSC_VER -# define HAVE_UNISTD_H 1 -#endif +#define HAVE_UNISTD_H 1 /* Define to 1 if the system has the type 'unsigned long long int'. */ #define HAVE_UNSIGNED_LONG_LONG_INT 1 diff --git a/src/3rdparty/jansson/load.c b/src/3rdparty/jansson/load.c index 6b3d1e25..b124244f 100644 --- a/src/3rdparty/jansson/load.c +++ b/src/3rdparty/jansson/load.c @@ -17,10 +17,15 @@ #include #include #include -#ifdef HAVE_UNISTD_H + +#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) #include #endif +#ifdef _MSC_VER +#define STDIN_FILENO 0 +#endif + #include "jansson.h" #include "strbuffer.h" #include "utf.h" diff --git a/src/Options.cpp b/src/Options.cpp index 15493e25..36d570b4 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -506,6 +506,8 @@ void Options::parseConfig(const char *fileName) return; } + uv_fs_req_cleanup(&req); + json_error_t err; json_t *config = json_loadfd(fd, 0, &err); From fc1d6c7e84f20e3afe1139d46a572f65ecfb8186 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 17 Aug 2017 07:33:21 +0300 Subject: [PATCH 16/26] Better fix for MSVC. --- src/3rdparty/jansson/dump.c | 18 +++++++++--------- src/3rdparty/jansson/hashtable_seed.c | 2 +- src/3rdparty/jansson/jansson_private_config.h | 4 +++- src/3rdparty/jansson/load.c | 12 ++++++------ src/Platform_mac.cpp | 14 ++++++++++++-- src/Platform_unix.cpp | 11 ++++++++++- src/Platform_win.cpp | 9 +++++++++ 7 files changed, 50 insertions(+), 20 deletions(-) diff --git a/src/3rdparty/jansson/dump.c b/src/3rdparty/jansson/dump.c index a92fdf7d..0f8996e7 100644 --- a/src/3rdparty/jansson/dump.c +++ b/src/3rdparty/jansson/dump.c @@ -20,13 +20,10 @@ #include #include -#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) -#include -#endif - -#if defined(_MSC_VER) -#include -typedef SSIZE_T ssize_t; +#if defined(HAVE_UNISTD_H) +# include +#elif defined(_MSC_VER) +# include #endif #include "jansson.h" @@ -72,10 +69,13 @@ static int dump_to_file(const char *buffer, size_t size, void *data) static int dump_to_fd(const char *buffer, size_t size, void *data) { int *dest = (int *)data; -#ifdef HAVE_UNISTD_H +# if defined(HAVE_UNISTD_H) if(write(*dest, buffer, size) == (ssize_t)size) return 0; -#endif +# elif (defined(_MSC_VER)) + if (write(*dest, buffer, (unsigned int) size) == (int) size) + return 0; +# endif return -1; } diff --git a/src/3rdparty/jansson/hashtable_seed.c b/src/3rdparty/jansson/hashtable_seed.c index 5caeec97..8aed5406 100644 --- a/src/3rdparty/jansson/hashtable_seed.c +++ b/src/3rdparty/jansson/hashtable_seed.c @@ -21,7 +21,7 @@ #include #endif -#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) +#ifdef HAVE_UNISTD_H #include #endif diff --git a/src/3rdparty/jansson/jansson_private_config.h b/src/3rdparty/jansson/jansson_private_config.h index 22800f84..671993d9 100644 --- a/src/3rdparty/jansson/jansson_private_config.h +++ b/src/3rdparty/jansson/jansson_private_config.h @@ -92,7 +92,9 @@ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 +#ifndef _MSC_VER +# define HAVE_UNISTD_H 1 +#endif /* Define to 1 if the system has the type 'unsigned long long int'. */ #define HAVE_UNSIGNED_LONG_LONG_INT 1 diff --git a/src/3rdparty/jansson/load.c b/src/3rdparty/jansson/load.c index b124244f..d9399696 100644 --- a/src/3rdparty/jansson/load.c +++ b/src/3rdparty/jansson/load.c @@ -18,12 +18,12 @@ #include #include -#if defined(HAVE_UNISTD_H) && !defined(_MSC_VER) -#include -#endif - -#ifdef _MSC_VER -#define STDIN_FILENO 0 +#if defined(HAVE_UNISTD_H) +# include +#elif defined(_MSC_VER) +# include +# define HAVE_UNISTD_H +# define STDIN_FILENO 0 #endif #include "jansson.h" diff --git a/src/Platform_mac.cpp b/src/Platform_mac.cpp index 3b5daef5..5e53aacb 100644 --- a/src/Platform_mac.cpp +++ b/src/Platform_mac.cpp @@ -30,13 +30,23 @@ #include "Platform.h" #include "version.h" +#ifdef XMRIG_NVIDIA_PROJECT +# include "nvidia/cryptonight.h" +#endif + static inline char *createUserAgent() { - const size_t max = 128; + const size_t max = 160; char *buf = new char[max]; - snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__); + +# ifdef XMRIG_NVIDIA_PROJECT + const int cudaVersion = cuda_get_runtime_version(); + snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s CUDA/%d.%d clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, __clang_major__, __clang_minor__, __clang_patchlevel__); +# else + snprintf(buf, max, "%s/%s (Macintosh; Intel Mac OS X) libuv/%s clang/%d.%d.%d", APP_NAME, APP_VERSION, uv_version_string(), __clang_major__, __clang_minor__, __clang_patchlevel__); +# endif return buf; } diff --git a/src/Platform_unix.cpp b/src/Platform_unix.cpp index 6a65193c..27d8de37 100644 --- a/src/Platform_unix.cpp +++ b/src/Platform_unix.cpp @@ -32,10 +32,14 @@ #include "Platform.h" #include "version.h" +#ifdef XMRIG_NVIDIA_PROJECT +# include "nvidia/cryptonight.h" +#endif + static inline char *createUserAgent() { - const size_t max = 128; + const size_t max = 160; char *buf = new char[max]; int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION); @@ -46,6 +50,11 @@ static inline char *createUserAgent() length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string()); # endif +# ifdef XMRIG_NVIDIA_PROJECT + const int cudaVersion = cuda_get_runtime_version(); + length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); +# endif + # ifdef __GNUC__ length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # endif diff --git a/src/Platform_win.cpp b/src/Platform_win.cpp index e61dc773..880bdd98 100644 --- a/src/Platform_win.cpp +++ b/src/Platform_win.cpp @@ -30,6 +30,10 @@ #include "Platform.h" #include "version.h" +#ifdef XMRIG_NVIDIA_PROJECT +# include "nvidia/cryptonight.h" +#endif + static inline OSVERSIONINFOEX winOsVersion() { @@ -63,6 +67,11 @@ static inline char *createUserAgent() length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string()); # endif +# ifdef XMRIG_NVIDIA_PROJECT + const int cudaVersion = cuda_get_runtime_version(); + length += snprintf(buf + length, max - length, " CUDA/%d.%d", cudaVersion / 1000, cudaVersion % 100); +# endif + # ifdef __GNUC__ length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__); # elif _MSC_VER From 168b1aac2f9c44c1e4dea213bb1f4d3523475eb5 Mon Sep 17 00:00:00 2001 From: xmrig Date: Thu, 17 Aug 2017 18:11:03 +0300 Subject: [PATCH 17/26] Update CHANGELOG.md --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dfc18bd..27ec78ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# v2.3.0 +- Added `--cpu-priority` option (0 idle, 2 normal to 5 highest). +- Added `--user-agent` option, to set custom user-agent string for pool. For example `cpuminer-multi/0.1`. +- Added `--no-huge-pages` option, to disable huge pages support. +- Force reconnect if pool block miner IP address. helps switch to backup pool. +- Fixed: failed open default config file if path contains non English characters. +- Fixed: message "Huge pages support was successfully enabled, but reboot required to use it" was not shown in release builds. + # v2.2.1 - Fixed [terminal issues](https://github.com/xmrig/xmrig-proxy/issues/2#issuecomment-319914085) after exit on Linux and OS X. From 60224ccd236fbc4da43d30d3e7198803dc059c18 Mon Sep 17 00:00:00 2001 From: XMRig Date: Thu, 17 Aug 2017 18:54:41 +0300 Subject: [PATCH 18/26] Fix error if stdout not available. --- src/log/ConsoleLog.cpp | 19 ++++++++++++++++++- src/log/ConsoleLog.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/log/ConsoleLog.cpp b/src/log/ConsoleLog.cpp index 7b044590..6439eb07 100644 --- a/src/log/ConsoleLog.cpp +++ b/src/log/ConsoleLog.cpp @@ -40,7 +40,10 @@ ConsoleLog::ConsoleLog(bool colors) : m_colors(colors) { - uv_tty_init(uv_default_loop(), &m_tty, 1, 0); + if (uv_tty_init(uv_default_loop(), &m_tty, 1, 0) < 0) { + return; + } + uv_tty_set_mode(&m_tty, UV_TTY_MODE_NORMAL); # ifdef WIN32 @@ -58,6 +61,10 @@ ConsoleLog::ConsoleLog(bool colors) : void ConsoleLog::message(int level, const char* fmt, va_list args) { + if (!isWritable()) { + return; + } + time_t now = time(nullptr); tm stime; @@ -112,6 +119,10 @@ void ConsoleLog::message(int level, const char* fmt, va_list args) void ConsoleLog::text(const char* fmt, va_list args) { + if (!isWritable()) { + return; + } + char *buf = new char[64 + strlen(fmt) + 2]; sprintf(buf, "%s%s\n", fmt, m_colors ? Log::kCL_N : ""); @@ -120,6 +131,12 @@ void ConsoleLog::text(const char* fmt, va_list args) } +bool ConsoleLog::isWritable() const +{ + return uv_is_writable(reinterpret_cast(&m_tty)) == 1 && uv_guess_handle(1) == UV_TTY; +} + + void ConsoleLog::print(char *fmt, va_list args) { vsnprintf(m_buf, sizeof(m_buf) - 1, fmt, args); diff --git a/src/log/ConsoleLog.h b/src/log/ConsoleLog.h index b96b5e50..e3d06e60 100644 --- a/src/log/ConsoleLog.h +++ b/src/log/ConsoleLog.h @@ -40,6 +40,7 @@ public: void text(const char *fmt, va_list args) override; private: + bool isWritable() const; void print(char *fmt, va_list args); bool m_colors; From b5897b336a47999c7b8c140f6c9ca34a404deddd Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 18 Aug 2017 04:44:02 +0300 Subject: [PATCH 19/26] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27ec78ad..8d465c52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ - Added `--no-huge-pages` option, to disable huge pages support. - Force reconnect if pool block miner IP address. helps switch to backup pool. - Fixed: failed open default config file if path contains non English characters. -- Fixed: message "Huge pages support was successfully enabled, but reboot required to use it" was not shown in release builds. +- Fixed: error occurred if try use unavailable stdin or stdout, regression since version 2.2.0. +- Fixed: message about huge pages support successfully enabled on Windows was not shown in release builds. # v2.2.1 - Fixed [terminal issues](https://github.com/xmrig/xmrig-proxy/issues/2#issuecomment-319914085) after exit on Linux and OS X. From e3e52f6d06bac2bd9c733c12b983aa087a5d6feb Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 18 Aug 2017 06:08:35 +0300 Subject: [PATCH 20/26] #62 Don't send the login to the dev pool. --- src/net/strategies/DonateStrategy.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index c3468016..0f981451 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -24,17 +24,31 @@ #include "interfaces/IStrategyListener.h" #include "net/Client.h" +#include "net/Job.h" #include "net/strategies/DonateStrategy.h" #include "Options.h" +extern "C" +{ +#include "crypto/c_keccak.h" +} + + DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) : m_active(false), m_donateTime(Options::i()->donateLevel() * 60 * 1000), m_idleTime((100 - Options::i()->donateLevel()) * 60 * 1000), m_listener(listener) { - Url *url = new Url("fee.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, Options::i()->pools().front()->user(), nullptr, false, true); + uint8_t hash[200]; + char userId[65] = { 0 }; + const char *user = Options::i()->pools().front()->user(); + + keccak(reinterpret_cast(user), static_cast(strlen(user)), hash, sizeof(hash)); + Job::toHex(hash, 32, userId); + + Url *url = new Url("fee.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, userId, nullptr, false, true); m_client = new Client(-1, agent, this); m_client->setUrl(url); From d53a47b12f68a4f90519d9792725f691aaeee685 Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 18 Aug 2017 06:47:51 +0300 Subject: [PATCH 21/26] Update README.md --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7811f711..2a714540 100644 --- a/README.md +++ b/README.md @@ -30,17 +30,17 @@ Originally based on cpuminer-multi with heavy optimizations/rewrites and removin ## Download * Binary releases: https://github.com/xmrig/xmrig/releases * Git tree: https://github.com/xmrig/xmrig.git - * Clone with `git clone https://github.com/xmrig/xmrig.git` + * Clone with `git clone https://github.com/xmrig/xmrig.git` :hammer: [Build instructions](https://github.com/xmrig/xmrig/wiki/Build). ## Usage ### Basic example ``` -xmrig.exe -o xmr-eu.dwarfpool.com:8005 -u YOUR_WALLET -p x -k +xmrig.exe -o pool.minemonero.pro:5555 -u YOUR_WALLET -p x -k ``` ### Failover ``` -xmrig.exe -o pool.supportxmr.com:5555 -u YOUR_WALLET1 -k -o xmr-eu.dwarfpool.com:8005 -u YOUR_WALLET2 -p x -k +xmrig.exe -o pool.minemonero.pro:5555 -u YOUR_WALLET1 -p x -k -o pool.supportxmr.com:5555 -u YOUR_WALLET2 -p x -k ``` For failover you can add multiple pools, maximum count not limited. @@ -56,19 +56,25 @@ For failover you can add multiple pools, maximum count not limited. -k, --keepalive send keepalived for prevent timeout (need pool support) -r, --retries=N number of times to retry before switch to backup server (default: 5) -R, --retry-pause=N time to pause between retries (default: 5) - --cpu-affinity set process affinity to cpu core(s), mask 0x3 for cores 0 and 1 + --cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1 + --cpu-priority set process priority (0 idle, 2 normal to 5 highest) + --no-huge-pages disable huge pages support --no-color disable colored output --donate-level=N donate level, default 5% (5 minutes in 100 minutes) + --user-agent set custom user-agent string for pool -B, --background run the miner in the background -c, --config=FILE load a JSON-format configuration file - --max-cpu-usage=N maximum cpu usage for automatic threads mode (default 75) - --safe safe adjust threads and av settings for current cpu + -l, --log-file=FILE log all output to a file + --max-cpu-usage=N maximum CPU usage for automatic threads mode (default 75) + --safe safe adjust threads and av settings for current CPU --nicehash enable nicehash support --print-time=N print hashrate report every N seconds -h, --help display this help and exit -V, --version output version information and exit ``` +Also you can use configuration via config file, default **config.json**. You can load multiple config files and combine it with command line options. + ## Algorithm variations Since version 0.8.0. * `--av=1` For CPUs with hardware AES. From fbaae0f08056df8f9fda3599f27b43a6b8a3337c Mon Sep 17 00:00:00 2001 From: xmrig Date: Fri, 18 Aug 2017 17:11:26 +0300 Subject: [PATCH 22/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a714540..981ae317 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ XMRig is high performance Monero (XMR) CPU miner, with the official full Windows support. Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 complete rewritten from scratch on C++. - + #### Table of contents * [Features](#features) From 55bfab95f96a5dcb241e6bb02b5c48b97447622a Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 20 Aug 2017 09:42:35 +0300 Subject: [PATCH 23/26] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d465c52..800a7184 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Added `--cpu-priority` option (0 idle, 2 normal to 5 highest). - Added `--user-agent` option, to set custom user-agent string for pool. For example `cpuminer-multi/0.1`. - Added `--no-huge-pages` option, to disable huge pages support. +- [#62](https://github.com/xmrig/xmrig/issues/62) Don't send the login to the dev pool. - Force reconnect if pool block miner IP address. helps switch to backup pool. - Fixed: failed open default config file if path contains non English characters. - Fixed: error occurred if try use unavailable stdin or stdout, regression since version 2.2.0. From fa5e326d5e0f25114d5775d7db487d9216d9aa72 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 20 Aug 2017 09:48:31 +0300 Subject: [PATCH 24/26] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 981ae317..2a44fbba 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ XMRig is high performance Monero (XMR) CPU miner, with the official full Windows support. Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 complete rewritten from scratch on C++. +* This is the CPU-mining version, there is also an [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia). + #### Table of contents From 076a69907c053ba86c82787e27c576a5e56c1d80 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 20 Aug 2017 09:55:03 +0300 Subject: [PATCH 25/26] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a44fbba..4707c757 100644 --- a/README.md +++ b/README.md @@ -96,8 +96,8 @@ Since version 0.8.0. ### CPU mining performance -* **i7-6700** - 290+ H/s (4 threads, cpu affinity 0xAA) -* **Dual E5620** - 377 H/s (12 threads, cpu affinity 0xEEEE) +* **Intel i7-7700** - 307 H/s (4 threads) +* **AMD Ryzen 7 1700X** - 560 H/s (8 threads) Please note performance is highly dependent on system load. The numbers above are obtained on an idle system. Tasks heavily using a processor cache, such as video playback, can greatly degrade hashrate. Optimal number of threads depends on the size of the L3 cache of a processor, 1 thread requires 2 MB of cache. From bb4aeed8748e18649b2e8c26767c954df25de656 Mon Sep 17 00:00:00 2001 From: xmrig Date: Sun, 20 Aug 2017 10:02:52 +0300 Subject: [PATCH 26/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4707c757..972777df 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ XMRig is high performance Monero (XMR) CPU miner, with the official full Windows support. Originally based on cpuminer-multi with heavy optimizations/rewrites and removing a lot of legacy code, since version 1.0.0 complete rewritten from scratch on C++. -* This is the CPU-mining version, there is also an [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia). +* This is the CPU-mining version, there is also a [NVIDIA GPU version](https://github.com/xmrig/xmrig-nvidia).