Show CUDA version, fix Visual Studio warnings.
parent
d56e365521
commit
a8a06b858c
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
project(xmrig)
|
||||
project(xmrig-nvidia)
|
||||
|
||||
option(WITH_AEON "CryptoNight-Lite support" ON)
|
||||
|
||||
|
@ -146,5 +146,5 @@ include_directories(${UV_INCLUDE_DIR})
|
|||
|
||||
add_subdirectory(src/3rdparty/jansson)
|
||||
|
||||
add_executable(xmrig ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG})
|
||||
target_link_libraries(xmrig xmrig-cuda jansson ${UV_LIBRARIES} ${LIBS} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
add_executable(${PROJECT_NAME} ${HEADERS} ${SOURCES} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG})
|
||||
target_link_libraries(${PROJECT_NAME} xmrig-cuda jansson ${UV_LIBRARIES} ${LIBS} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wall -Wno-strict-aliasing")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wall")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall -std=c++14 -fno-exceptions -fno-rtti")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
||||
|
||||
if (WIN32)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
|
||||
|
@ -19,18 +18,16 @@ if (CMAKE_CXX_COMPILER_ID MATCHES GNU)
|
|||
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES MSVC)
|
||||
|
||||
message(${CMAKE_C_FLAGS_RELEASE})
|
||||
message(${CMAKE_CXX_FLAGS_RELEASE})
|
||||
|
||||
set(CMAKE_C_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "/MT /O2 /Ob2 /DNDEBUG")
|
||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||
add_definitions(/D_CRT_NONSTDC_NO_WARNINGS)
|
||||
|
||||
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes -Wall")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall -std=c++14 -fno-exceptions -fno-rtti")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fmerge-all-constants")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
||||
|
||||
endif()
|
|
@ -24,7 +24,7 @@ VS_VERSION_INFO VERSIONINFO
|
|||
VALUE "FileDescription", APP_DESC
|
||||
VALUE "FileVersion", APP_VERSION
|
||||
VALUE "LegalCopyright", APP_COPYRIGHT
|
||||
VALUE "OriginalFilename", "xmrig.exe"
|
||||
VALUE "OriginalFilename", "xmrig-nvidia.exe"
|
||||
VALUE "ProductName", APP_NAME
|
||||
VALUE "ProductVersion", APP_VERSION
|
||||
END
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
* 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
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
* 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 <jansson_private_config.h>
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -87,7 +87,7 @@ static inline bool has_aes_ni()
|
|||
int cpu_info[4] = { 0 };
|
||||
cpuid(PROCESSOR_INFO, cpu_info);
|
||||
|
||||
return cpu_info[ECX_Reg] & bit_AES;
|
||||
return (cpu_info[ECX_Reg] & bit_AES) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -95,7 +95,7 @@ static inline bool has_bmi2() {
|
|||
int cpu_info[4] = { 0 };
|
||||
cpuid(EXTENDED_FEATURES, cpu_info);
|
||||
|
||||
return cpu_info[EBX_Reg] & bit_BMI2;
|
||||
return (cpu_info[EBX_Reg] & bit_BMI2) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "Cpu.h"
|
||||
#include "donate.h"
|
||||
#include "net/Url.h"
|
||||
#include "nvidia/cryptonight.h"
|
||||
#include "Options.h"
|
||||
#include "version.h"
|
||||
#include "workers/GpuThread.h"
|
||||
|
@ -53,7 +54,6 @@ Options *Options::m_self = nullptr;
|
|||
static char const usage[] = "\
|
||||
Usage: " APP_ID " [OPTIONS]\n\
|
||||
Options:\n\
|
||||
-a, --algo=ALGO cryptonight (default) or cryptonight-lite\n\
|
||||
-o, --url=URL URL of mining server\n\
|
||||
-O, --userpass=U:P username:password pair for mining server\n\
|
||||
-u, --user=USERNAME username for mining server\n\
|
||||
|
@ -71,7 +71,6 @@ Options:\n\
|
|||
-S, --syslog use system log for output messages\n"
|
||||
# endif
|
||||
"\
|
||||
--safe safe adjust threads and av settings for current CPU\n\
|
||||
--nicehash enable nicehash support\n\
|
||||
--print-time=N print hashrate report every N seconds\n\
|
||||
-h, --help display this help and exit\n\
|
||||
|
@ -599,6 +598,9 @@ void Options::showVersion()
|
|||
|
||||
printf("\nlibuv/%s\n", uv_version_string());
|
||||
printf("libjansson/%s\n", JANSSON_VERSION);
|
||||
|
||||
const int cudaVersion = cuda_get_runtime_version();
|
||||
printf("CUDA/%d.%d\n", cudaVersion / 1000, cudaVersion % 100);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "Cpu.h"
|
||||
#include "log/Log.h"
|
||||
#include "net/Url.h"
|
||||
#include "nvidia/cryptonight.h"
|
||||
#include "Options.h"
|
||||
#include "Summary.h"
|
||||
#include "version.h"
|
||||
|
@ -49,9 +50,9 @@ static void print_versions()
|
|||
buf[0] = '\0';
|
||||
# endif
|
||||
|
||||
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s%s" : " * VERSIONS: XMRig/%s libuv/%s%s",
|
||||
APP_VERSION, uv_version_string(), buf);
|
||||
const int cudaVersion = cuda_get_runtime_version();
|
||||
Log::i()->text(Options::i()->colors() ? "\x1B[01;32m * \x1B[01;37mVERSIONS: \x1B[01;36mXMRig/%s\x1B[01;37m libuv/%s CUDA/%d.%d%s" : " * VERSIONS: XMRig/%s libuv/%s CUDA/%d.%d%s",
|
||||
APP_VERSION, uv_version_string(), cudaVersion / 1000, cudaVersion % 100, buf);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ static inline void cn_implode_scratchpad(const __m128i *input, __m128i *output)
|
|||
template<size_t ITERATIONS, size_t MEM, size_t MASK, bool SOFT_AES>
|
||||
inline void cryptonight_hash(const void *__restrict__ input, size_t size, void *__restrict__ output, cryptonight_ctx *__restrict__ ctx)
|
||||
{
|
||||
keccak(static_cast<const uint8_t*>(input), size, ctx->state0, 200);
|
||||
keccak(static_cast<const uint8_t*>(input), (int) size, ctx->state0, 200);
|
||||
|
||||
cn_explode_scratchpad<MEM, SOFT_AES>((__m128i*) ctx->state0, (__m128i*) ctx->memory);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
virtual void connect() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void tick(uint64_t now) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<uv_fs_t*>(malloc(sizeof(uv_fs_t)));
|
||||
req->data = buf.base;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<char*>(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,12 +94,12 @@ 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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -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<char*>(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,19 +453,20 @@ 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);
|
||||
}
|
||||
|
||||
m_failures++;
|
||||
m_listener->onClose(this, m_failures);
|
||||
m_listener->onClose(this, (int) 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
|
||||
}
|
||||
|
||||
|
||||
|
@ -476,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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -523,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();;
|
||||
|
|
|
@ -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<int64_t, SubmitResult> 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
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ public:
|
|||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(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; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(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; }
|
||||
|
||||
|
@ -68,7 +68,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;
|
||||
|
||||
|
|
|
@ -21,6 +21,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <memory>
|
||||
|
@ -39,7 +42,6 @@
|
|||
|
||||
|
||||
Network::Network(const Options *options) :
|
||||
m_donateActive(false),
|
||||
m_options(options),
|
||||
m_donate(nullptr),
|
||||
m_accepted(0),
|
||||
|
@ -62,6 +64,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 +171,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<Network*>(handle->data)->tick();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
#include "net/Network.h"
|
||||
#include "nvidia/cryptonight.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
|
@ -51,15 +52,16 @@ static inline OSVERSIONINFOEX winOsVersion()
|
|||
char *Network::userAgent()
|
||||
{
|
||||
const auto osver = winOsVersion();
|
||||
const size_t max = 128;
|
||||
const size_t max = 160;
|
||||
const int cudaVersion = cuda_get_runtime_version();
|
||||
|
||||
char *buf = static_cast<char*>(malloc(max));
|
||||
char *buf = new char[128];
|
||||
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)
|
||||
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string());
|
||||
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s CUDA/%d.%d", uv_version_string(), cudaVersion / 1000, cudaVersion % 100);
|
||||
# else
|
||||
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
|
||||
length += snprintf(buf + length, max - length, ") libuv/%s CUDA/%d.%d", uv_version_string(), cudaVersion / 1000, cudaVersion % 100);
|
||||
# endif
|
||||
|
||||
# ifdef __GNUC__
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,12 @@ void DonateStrategy::stop()
|
|||
}
|
||||
|
||||
|
||||
void DonateStrategy::tick(uint64_t now)
|
||||
{
|
||||
m_client->tick(now);
|
||||
}
|
||||
|
||||
|
||||
void DonateStrategy::onClose(Client *client, int failures)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -132,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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct {
|
|||
extern "C" {
|
||||
|
||||
int cuda_get_devicecount();
|
||||
int cuda_get_runtime_version();
|
||||
int cuda_get_deviceinfo(nvid_ctx *ctx);
|
||||
int cryptonight_extra_cpu_init(nvid_ctx *ctx);
|
||||
void cryptonight_extra_cpu_set_data( nvid_ctx* ctx, const void *data, uint32_t len);
|
||||
|
|
|
@ -261,6 +261,16 @@ extern "C" int cuda_get_devicecount()
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int cuda_get_runtime_version()
|
||||
{
|
||||
int runtimeVersion = 0;
|
||||
if (cudaRuntimeGetVersion(&runtimeVersion) == cudaSuccess) {
|
||||
return runtimeVersion;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int cuda_get_deviceinfo(nvid_ctx* ctx)
|
||||
{
|
||||
cudaError_t err;
|
||||
|
|
|
@ -71,7 +71,7 @@ void CudaWorker::start()
|
|||
consumeJob();
|
||||
}
|
||||
|
||||
cryptonight_extra_cpu_set_data(&m_ctx, m_job.blob(), m_job.size());
|
||||
cryptonight_extra_cpu_set_data(&m_ctx, m_job.blob(), (uint32_t) m_job.size());
|
||||
|
||||
while (!Workers::isOutdated(m_sequence)) {
|
||||
uint32_t foundNonce[10];
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -120,7 +120,7 @@ void Workers::setJob(const Job &job)
|
|||
void Workers::start(const std::vector<GpuThread*> &threads)
|
||||
{
|
||||
const size_t count = threads.size();
|
||||
m_hashrate = new Hashrate(count);
|
||||
m_hashrate = new Hashrate((int) count);
|
||||
|
||||
uv_mutex_init(&m_mutex);
|
||||
uv_rwlock_init(&m_rwlock);
|
||||
|
@ -133,7 +133,7 @@ void Workers::start(const std::vector<GpuThread*> &threads)
|
|||
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
Handle *handle = new Handle(i, threads[i], count);
|
||||
Handle *handle = new Handle((int) i, threads[i], (int) count);
|
||||
m_workers.push_back(handle);
|
||||
handle->start(Workers::onReady);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue