diff --git a/src/core/Config.cpp b/src/core/Config.cpp index 2b8809ff7..ddce69806 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -156,6 +156,18 @@ bool xmrig::Config::adjust() return false; } + if (m_aesMode == AES_AUTO) { + m_aesMode = Cpu::hasAES() ? AES_SOFT : AES_SOFT; + } + + if (!m_threads.cpu.empty()) { + for (size_t i = 0; i < m_threads.cpu.size(); ++i) { + m_threads.list.push_back(CpuThread::createFromData(i, m_algorithm, m_threads.cpu[i], m_priority, m_aesMode == AES_SOFT)); + } + + return true; + } + m_algoVariant = getAlgoVariant(); if (m_algoVariant == AV_DOUBLE || m_algoVariant == AV_DOUBLE_SOFT) { m_doubleHash = true; diff --git a/src/core/Config.h b/src/core/Config.h index 657679ec3..720557a7d 100644 --- a/src/core/Config.h +++ b/src/core/Config.h @@ -76,7 +76,7 @@ public: inline const std::vector &threads() const { return m_threads.list; } inline int printTime() const { return m_printTime; } inline int priority() const { return m_priority; } - inline int threadsCount() const { return m_threads.count; } + inline int threadsCount() const { return m_threads.list.size(); } inline int64_t affinity() const { return m_threads.mask; } static Config *load(int argc, char **argv, IWatcherListener *listener); diff --git a/src/log/Log.cpp b/src/log/Log.cpp index 3e5d5671a..131faa54b 100644 --- a/src/log/Log.cpp +++ b/src/log/Log.cpp @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 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 @@ -38,6 +38,8 @@ Log *Log::m_self = nullptr; void Log::message(Log::Level level, const char* fmt, ...) { + uv_mutex_lock(&m_mutex); + va_list args; va_list copy; va_start(args, fmt); @@ -47,11 +49,15 @@ void Log::message(Log::Level level, const char* fmt, ...) backend->message(level, fmt, copy); va_end(copy); } + + uv_mutex_unlock(&m_mutex); } void Log::text(const char* fmt, ...) { + uv_mutex_lock(&m_mutex); + va_list args; va_list copy; va_start(args, fmt); @@ -63,6 +69,8 @@ void Log::text(const char* fmt, ...) } va_end(args); + + uv_mutex_unlock(&m_mutex); } diff --git a/src/log/Log.h b/src/log/Log.h index fd944d800..f8c6a4016 100644 --- a/src/log/Log.h +++ b/src/log/Log.h @@ -4,8 +4,8 @@ * Copyright 2014 Lucas Jones * Copyright 2014-2016 Wolf9466 * Copyright 2016 Jay D Dee - * Copyright 2016-2017 XMRig - * + * Copyright 2017-2018 XMR-Stak , + * Copyright 2016-2018 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 @@ -25,6 +25,7 @@ #define __LOG_H__ +#include #include #include @@ -54,20 +55,28 @@ public: constexpr static const char* kCL_GRAY = "\x1B[90m"; # endif - static inline Log* i() { return m_self; } + static inline Log* i() { assert(m_self != nullptr); return m_self; } static inline void add(ILogBackend *backend) { i()->m_backends.push_back(backend); } - static inline void init() { if (!m_self) { m_self = new Log();} } - static inline void release() { delete m_self; } + static inline void init() { if (!m_self) { new Log(); } } + static inline void release() { assert(m_self != nullptr); delete m_self; } void message(Level level, const char* fmt, ...); void text(const char* fmt, ...); private: - inline Log() {} + inline Log() { + assert(m_self == nullptr); + + uv_mutex_init(&m_mutex); + + m_self = this; + } + ~Log(); static Log *m_self; std::vector m_backends; + uv_mutex_t m_mutex; }; diff --git a/src/workers/CpuThread.cpp b/src/workers/CpuThread.cpp index 5a707a585..07fbbb64e 100644 --- a/src/workers/CpuThread.cpp +++ b/src/workers/CpuThread.cpp @@ -197,6 +197,24 @@ xmrig::CpuThread *xmrig::CpuThread::createFromAV(size_t index, Algo algorithm, A } +xmrig::CpuThread *xmrig::CpuThread::createFromData(size_t index, Algo algorithm, const CpuThread::Data &data, int priority, bool softAES) +{ + int av = AV_AUTO; + const Multiway multiway = data.multiway; + + if (multiway <= DoubleWay) { + av = softAES ? (multiway + 2) : multiway; + } + else { + av = softAES ? (multiway + 5) : (multiway + 2); + } + + assert(av > AV_AUTO && av < AV_MAX); + + return new CpuThread(index, algorithm, static_cast(av), multiway, data.affinity, priority, softAES, false); +} + + xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object) { Data data; diff --git a/src/workers/CpuThread.h b/src/workers/CpuThread.h index f9640a6c3..9d1bc4e73 100644 --- a/src/workers/CpuThread.h +++ b/src/workers/CpuThread.h @@ -72,6 +72,7 @@ public: static cn_hash_fun fn(Algo algorithm, AlgoVariant av, Variant variant); static CpuThread *createFromAV(size_t index, Algo algorithm, AlgoVariant av, int64_t affinity, int priority); + static CpuThread *createFromData(size_t index, Algo algorithm, const CpuThread::Data &data, int priority, bool softAES); static Data parse(const rapidjson::Value &object); inline bool isPrefetch() const { return m_prefetch; } diff --git a/src/workers/Workers.cpp b/src/workers/Workers.cpp index 00941c7be..44ac399f3 100644 --- a/src/workers/Workers.cpp +++ b/src/workers/Workers.cpp @@ -112,6 +112,8 @@ void Workers::start(xmrig::Controller *controller) { const std::vector &threads = controller->config()->threads(); + LOG_NOTICE("- %d", std::this_thread::get_id()); + size_t totalWays = 0; for (const xmrig::IThread *thread : threads) { totalWays += thread->multiway(); @@ -165,6 +167,9 @@ void Workers::submit(const JobResult &result) void Workers::onReady(void *arg) { auto handle = static_cast(arg); + + LOG_NOTICE("%zu %d", handle->threadId(), std::this_thread::get_id()); + if (Mem::isDoubleHash()) { handle->setWorker(new DoubleWorker(handle)); } @@ -175,9 +180,7 @@ void Workers::onReady(void *arg) const bool rc = handle->worker()->start(); if (!rc) { - uv_mutex_lock(&m_mutex); LOG_ERR("thread %zu error: \"hash self-test failed\".", handle->worker()->id()); - uv_mutex_unlock(&m_mutex); } }