Use unsigned type for intensity.

This commit is contained in:
XMRig 2019-08-17 05:22:09 +07:00
parent d254aafb93
commit bd9255136c
10 changed files with 27 additions and 29 deletions

View file

@ -166,18 +166,7 @@ namespace xmrig {
template<> template<>
xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle) xmrig::IWorker *xmrig::Workers<CpuLaunchData>::create(Thread<CpuLaunchData> *handle)
{ {
const uint32_t intensity = static_cast<uint32_t>(handle->config().intensity); switch (handle->config().intensity) {
# if defined(XMRIG_ALGO_RANDOMX) || defined(XMRIG_ALGO_CN_GPU)
if (intensity > handle->config().algorithm.maxIntensity()) {
LOG_WARN("CPU thread %zu warning: \"intensity %d not supported for %s algorithm\".", handle->index(), handle->config().intensity, handle->config().algorithm.shortName());
return new CpuWorker<1>(handle->index(), handle->config());
}
# endif
switch (intensity) {
case 1: case 1:
return new CpuWorker<1>(handle->index(), handle->config()); return new CpuWorker<1>(handle->index(), handle->config());

View file

@ -24,6 +24,9 @@
*/ */
#include <algorithm>
#include "backend/cpu/CpuLaunchData.h" #include "backend/cpu/CpuLaunchData.h"
#include "backend/cpu/CpuConfig.h" #include "backend/cpu/CpuConfig.h"
@ -33,10 +36,10 @@ xmrig::CpuLaunchData::CpuLaunchData(const Miner *miner, const Algorithm &algorit
assembly(config.assembly()), assembly(config.assembly()),
hugePages(config.isHugePages()), hugePages(config.isHugePages()),
hwAES(config.isHwAES()), hwAES(config.isHwAES()),
intensity(thread.intensity()),
priority(config.priority()), priority(config.priority()),
affinity(thread.affinity()), affinity(thread.affinity()),
miner(miner) miner(miner),
intensity(std::min<uint32_t>(thread.intensity(), algorithm.maxIntensity()))
{ {
} }

View file

@ -58,10 +58,10 @@ public:
const Assembly assembly; const Assembly assembly;
const bool hugePages; const bool hugePages;
const bool hwAES; const bool hwAES;
const int intensity;
const int priority; const int priority;
const int64_t affinity; const int64_t affinity;
const Miner *miner; const Miner *miner;
const uint32_t intensity;
}; };

View file

@ -31,11 +31,11 @@
xmrig::CpuThread::CpuThread(const rapidjson::Value &value) xmrig::CpuThread::CpuThread(const rapidjson::Value &value)
{ {
if (value.IsArray() && value.Size() >= 2) { if (value.IsArray() && value.Size() >= 2) {
m_intensity = value[0].GetInt(); m_intensity = value[0].GetUint();
m_affinity = value[1].GetInt(); m_affinity = value[1].GetInt();
} }
else if (value.IsInt()) { else if (value.IsInt()) {
m_intensity = -1; m_intensity = 0;
m_affinity = value.GetInt(); m_affinity = value.GetInt();
} }
} }
@ -44,7 +44,7 @@ xmrig::CpuThread::CpuThread(const rapidjson::Value &value)
rapidjson::Value xmrig::CpuThread::toJSON(rapidjson::Document &doc) const rapidjson::Value xmrig::CpuThread::toJSON(rapidjson::Document &doc) const
{ {
using namespace rapidjson; using namespace rapidjson;
if (m_intensity == -1) { if (m_intensity == 0) {
return Value(m_affinity); return Value(m_affinity);
} }

View file

@ -36,14 +36,14 @@ class CpuThread
{ {
public: public:
inline constexpr CpuThread() {} inline constexpr CpuThread() {}
inline constexpr CpuThread(int64_t affinity, int intensity) : m_intensity(intensity), m_affinity(affinity) {} inline constexpr CpuThread(int64_t affinity, uint32_t intensity) : m_affinity(affinity), m_intensity(intensity) {}
CpuThread(const rapidjson::Value &value); CpuThread(const rapidjson::Value &value);
inline bool isEqual(const CpuThread &other) const { return other.m_affinity == m_affinity && other.m_intensity == m_intensity; } inline bool isEqual(const CpuThread &other) const { return other.m_affinity == m_affinity && other.m_intensity == m_intensity; }
inline bool isValid() const { return m_intensity == -1 || (m_intensity >= 1 && m_intensity <= 5); } inline bool isValid() const { return m_intensity <= 5; }
inline int intensity() const { return m_intensity == -1 ? 1 : m_intensity; }
inline int64_t affinity() const { return m_affinity; } inline int64_t affinity() const { return m_affinity; }
inline uint32_t intensity() const { return m_intensity == 0 ? 1 : m_intensity; }
inline bool operator!=(const CpuThread &other) const { return !isEqual(other); } inline bool operator!=(const CpuThread &other) const { return !isEqual(other); }
inline bool operator==(const CpuThread &other) const { return isEqual(other); } inline bool operator==(const CpuThread &other) const { return isEqual(other); }
@ -51,8 +51,8 @@ public:
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;
private: private:
int m_intensity = -1; int64_t m_affinity = -1;
int64_t m_affinity = -1; uint32_t m_intensity = 0;
}; };

View file

@ -94,7 +94,7 @@ xmrig::CpuThreads::CpuThreads(const rapidjson::Value &value)
} }
} }
else if (value.IsObject()) { else if (value.IsObject()) {
int intensity = Json::getInt(value, kIntensity, 1); uint32_t intensity = Json::getUint(value, kIntensity, 1);
const size_t threads = std::min<unsigned>(Json::getUint(value, kThreads), 1024); const size_t threads = std::min<unsigned>(Json::getUint(value, kThreads), 1024);
m_affinity = getAffinityMask(Json::getValue(value, kAffinity)); m_affinity = getAffinityMask(Json::getValue(value, kAffinity));
m_format = ObjectFormat; m_format = ObjectFormat;
@ -110,7 +110,7 @@ xmrig::CpuThreads::CpuThreads(const rapidjson::Value &value)
} }
xmrig::CpuThreads::CpuThreads(size_t count, int intensity) xmrig::CpuThreads::CpuThreads(size_t count, uint32_t intensity)
{ {
m_data.reserve(count); m_data.reserve(count);

View file

@ -42,13 +42,13 @@ public:
inline CpuThreads(size_t count) : m_data(count) {} inline CpuThreads(size_t count) : m_data(count) {}
CpuThreads(const rapidjson::Value &value); CpuThreads(const rapidjson::Value &value);
CpuThreads(size_t count, int intensity); CpuThreads(size_t count, uint32_t intensity);
inline bool isEmpty() const { return m_data.empty(); } inline bool isEmpty() const { return m_data.empty(); }
inline const std::vector<CpuThread> &data() const { return m_data; } inline const std::vector<CpuThread> &data() const { return m_data; }
inline size_t count() const { return m_data.size(); } inline size_t count() const { return m_data.size(); }
inline void add(CpuThread &&thread) { m_data.push_back(thread); } inline void add(CpuThread &&thread) { m_data.push_back(thread); }
inline void add(int64_t affinity, int intensity) { add(CpuThread(affinity, intensity)); } inline void add(int64_t affinity, uint32_t intensity) { add(CpuThread(affinity, intensity)); }
inline void reserve(size_t capacity) { m_data.reserve(capacity); } inline void reserve(size_t capacity) { m_data.reserve(capacity); }
rapidjson::Value toJSON(rapidjson::Document &doc) const; rapidjson::Value toJSON(rapidjson::Document &doc) const;

View file

@ -145,7 +145,7 @@ xmrig::CpuThreads xmrig::AdvancedCpuInfo::threads(const Algorithm &algorithm) co
count = threads() / 2; count = threads() / 2;
} }
int intensity = algorithm.maxIntensity() == 1 ? -1 : 1; uint32_t intensity = algorithm.maxIntensity() == 1 ? 0 : 1;
# ifdef XMRIG_ALGO_CN_PICO # ifdef XMRIG_ALGO_CN_PICO
if (algorithm == Algorithm::CN_PICO_0 && (count / cores()) >= 2) { if (algorithm == Algorithm::CN_PICO_0 && (count / cores()) >= 2) {

View file

@ -221,5 +221,11 @@ xmrig::CpuThreads xmrig::BasicCpuInfo::threads(const Algorithm &algorithm) const
} }
# endif # endif
# ifdef XMRIG_ALGO_ARGON2
if (algorithm.family() == Algorithm::ARGON2) {
return count;
}
# endif
return CpuThreads(std::max<size_t>(count / 2, 1), 1); return CpuThreads(std::max<size_t>(count / 2, 1), 1);
} }

View file

@ -251,7 +251,7 @@ void xmrig::HwlocCpuInfo::processTopLevelCache(hwloc_obj_t cache, const Algorith
int L2_associativity = 0; int L2_associativity = 0;
size_t extra = 0; size_t extra = 0;
const size_t scratchpad = algorithm.l3(); const size_t scratchpad = algorithm.l3();
int intensity = algorithm.maxIntensity() == 1 ? -1 : 1; uint32_t intensity = algorithm.maxIntensity() == 1 ? 0 : 1;
if (cache->attr->cache.depth == 3) { if (cache->attr->cache.depth == 3) {
for (size_t i = 0; i < cache->arity; ++i) { for (size_t i = 0; i < cache->arity; ++i) {