Basic advanced config reader, only single hash supported.

This commit is contained in:
XMRig 2018-04-14 07:01:12 +07:00
parent c44b299750
commit c81401ab2d
7 changed files with 62 additions and 11 deletions

View file

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

View file

@ -76,7 +76,7 @@ public:
inline const std::vector<IThread *> &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);

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -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);
}

View file

@ -4,8 +4,8 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,6 +25,7 @@
#define __LOG_H__
#include <assert.h>
#include <uv.h>
#include <vector>
@ -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<ILogBackend*> m_backends;
uv_mutex_t m_mutex;
};

View file

@ -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<AlgoVariant>(av), multiway, data.affinity, priority, softAES, false);
}
xmrig::CpuThread::Data xmrig::CpuThread::parse(const rapidjson::Value &object)
{
Data data;

View file

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

View file

@ -112,6 +112,8 @@ void Workers::start(xmrig::Controller *controller)
{
const std::vector<xmrig::IThread *> &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<Handle*>(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);
}
}