Merge branch 'vs'
This commit is contained in:
commit
7f31f70876
15 changed files with 300 additions and 228 deletions
36
src/Cpu.cpp
36
src/Cpu.cpp
|
@ -41,33 +41,40 @@ int Cpu::m_totalThreads = 0;
|
|||
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
if (m_totalThreads == 1) {
|
||||
if(m_totalThreads == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cache = 0;
|
||||
if (m_l3_cache) {
|
||||
if(m_l3_cache)
|
||||
{
|
||||
cache = m_l2_exclusive ? (m_l2_cache + m_l3_cache) : m_l3_cache;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
cache = m_l2_cache;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
||||
|
||||
if (cache) {
|
||||
if(cache)
|
||||
{
|
||||
count = cache / size;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
count = m_totalThreads / 2;
|
||||
}
|
||||
|
||||
if (count > m_totalThreads) {
|
||||
if(count > m_totalThreads)
|
||||
{
|
||||
count = m_totalThreads;
|
||||
}
|
||||
|
||||
if (((float) count / m_totalThreads * 100) > maxCpuUsage) {
|
||||
if(((float) count / m_totalThreads * 100) > maxCpuUsage)
|
||||
{
|
||||
count = (int) ceil((float) m_totalThreads * (maxCpuUsage / 100.0));
|
||||
}
|
||||
|
||||
|
@ -88,7 +95,8 @@ void Cpu::initCommon()
|
|||
m_totalThreads = data.total_logical_cpus;
|
||||
m_sockets = m_totalThreads / data.num_logical_cpus;
|
||||
|
||||
if (m_sockets == 0) {
|
||||
if(m_sockets == 0)
|
||||
{
|
||||
m_sockets = 1;
|
||||
}
|
||||
|
||||
|
@ -96,11 +104,13 @@ void Cpu::initCommon()
|
|||
m_l3_cache = data.l3_cache > 0 ? data.l3_cache * m_sockets : 0;
|
||||
|
||||
// Workaround for AMD CPUs https://github.com/anrieff/libcpuid/issues/97
|
||||
if (data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17) {
|
||||
if(data.vendor == VENDOR_AMD && data.ext_family >= 0x15 && data.ext_family < 0x17)
|
||||
{
|
||||
m_l2_cache = data.l2_cache * (m_totalCores / 2) * m_sockets;
|
||||
m_l2_exclusive = true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
m_l2_cache = data.l2_cache > 0 ? data.l2_cache * m_totalCores * m_sockets : 0;
|
||||
}
|
||||
|
||||
|
@ -108,11 +118,13 @@ void Cpu::initCommon()
|
|||
m_flags |= X86_64;
|
||||
# endif
|
||||
|
||||
if (data.flags[CPU_FEATURE_AES]) {
|
||||
if(data.flags[CPU_FEATURE_AES])
|
||||
{
|
||||
m_flags |= AES;
|
||||
}
|
||||
|
||||
if (data.flags[CPU_FEATURE_BMI2]) {
|
||||
if(data.flags[CPU_FEATURE_BMI2])
|
||||
{
|
||||
m_flags |= BMI2;
|
||||
}
|
||||
}
|
||||
|
|
43
src/Cpu.h
43
src/Cpu.h
|
@ -31,7 +31,8 @@
|
|||
class Cpu
|
||||
{
|
||||
public:
|
||||
enum Flags {
|
||||
enum Flags
|
||||
{
|
||||
X86_64 = 1,
|
||||
AES = 2,
|
||||
BMI2 = 4
|
||||
|
@ -41,14 +42,38 @@ public:
|
|||
static void init();
|
||||
static void setAffinity(int id, uint64_t mask);
|
||||
|
||||
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; }
|
||||
static inline int l3() { return m_l3_cache; }
|
||||
static inline int sockets() { return m_sockets; }
|
||||
static inline int threads() { return m_totalThreads; }
|
||||
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;
|
||||
}
|
||||
static inline int l3()
|
||||
{
|
||||
return m_l3_cache;
|
||||
}
|
||||
static inline int sockets()
|
||||
{
|
||||
return m_sockets;
|
||||
}
|
||||
static inline int threads()
|
||||
{
|
||||
return m_totalThreads;
|
||||
}
|
||||
|
||||
private:
|
||||
static void initCommon();
|
||||
|
|
|
@ -56,27 +56,30 @@ void Cpu::init()
|
|||
|
||||
void Cpu::setAffinity(int id, uint64_t mask)
|
||||
{
|
||||
/*
|
||||
cpu_set_t set;
|
||||
CPU_ZERO(&set);
|
||||
|
||||
for (int i = 0; i < m_totalThreads; i++) {
|
||||
if (mask & (1UL << i)) {
|
||||
for(int i = 0; i < m_totalThreads; i++)
|
||||
{
|
||||
if(mask & (1UL << i))
|
||||
{
|
||||
CPU_SET(i, &set);
|
||||
}
|
||||
}
|
||||
|
||||
if (id == -1) {
|
||||
if(id == -1)
|
||||
{
|
||||
# ifndef __FreeBSD__
|
||||
sched_setaffinity(0, sizeof(&set), &set);
|
||||
# endif
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
# ifndef __ANDROID__
|
||||
pthread_setaffinity_np(pthread_self(), sizeof(&set), &set);
|
||||
# else
|
||||
sched_setaffinity(gettid(), sizeof(&set), &set);
|
||||
# endif
|
||||
}
|
||||
*/
|
||||
}
|
||||
#endif
|
|
@ -43,10 +43,12 @@ void Cpu::init()
|
|||
|
||||
void Cpu::setAffinity(int id, uint64_t mask)
|
||||
{
|
||||
if (id == -1) {
|
||||
if(id == -1)
|
||||
{
|
||||
SetProcessAffinityMask(GetCurrentProcess(), mask);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
SetThreadAffinityMask(GetCurrentThread(), mask);
|
||||
}
|
||||
}
|
||||
|
|
12
src/Mem.cpp
12
src/Mem.cpp
|
@ -41,12 +41,14 @@ uint8_t *Mem::m_memory = nullptr;
|
|||
cryptonight_ctx* Mem::create(int threadId)
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (m_algo == Options::ALGO_CRYPTONIGHT_LITE) {
|
||||
if(m_algo == Options::ALGO_CRYPTONIGHT_LITE)
|
||||
{
|
||||
return createLite(threadId);
|
||||
}
|
||||
# endif
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
cryptonight_ctx* ctx = reinterpret_cast<cryptonight_ctx*>(&m_memory[MEMORY - sizeof(cryptonight_ctx) *
|
||||
(threadId + 1)]);
|
||||
|
||||
const int ratio = m_doubleHash ? 2 : 1;
|
||||
ctx->memory = &m_memory[MEMORY * (threadId * ratio + 1)];
|
||||
|
@ -68,10 +70,12 @@ void *Mem::calloc(size_t num, size_t size)
|
|||
|
||||
|
||||
#ifndef XMRIG_NO_AEON
|
||||
cryptonight_ctx *Mem::createLite(int threadId) {
|
||||
cryptonight_ctx* Mem::createLite(int threadId)
|
||||
{
|
||||
cryptonight_ctx* ctx;
|
||||
|
||||
if (!m_doubleHash) {
|
||||
if(!m_doubleHash)
|
||||
{
|
||||
const size_t offset = MEMORY * (threadId + 1);
|
||||
|
||||
ctx = reinterpret_cast<cryptonight_ctx*>(&m_memory[offset + MEMORY_LITE]);
|
||||
|
|
|
@ -91,10 +91,17 @@ const uint8_t saes_sbox[256] = saes_data(saes_h0);
|
|||
|
||||
static inline __m128i soft_aesenc(__m128i in, __m128i key)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
const uint32_t x0 = in.m128i_u32[0];
|
||||
const uint32_t x1 = in.m128i_u32[1];
|
||||
const uint32_t x2 = in.m128i_u32[2];
|
||||
const uint32_t x3 = in.m128i_u32[3];
|
||||
#else
|
||||
const uint32_t x0 = _mm_cvtsi128_si32(in);
|
||||
const uint32_t x1 = _mm_cvtsi128_si32(_mm_shuffle_epi32(in, 0x55));
|
||||
const uint32_t x2 = _mm_cvtsi128_si32(_mm_shuffle_epi32(in, 0xAA));
|
||||
const uint32_t x3 = _mm_cvtsi128_si32(_mm_shuffle_epi32(in, 0xFF));
|
||||
#endif
|
||||
|
||||
__m128i out = _mm_set_epi32(
|
||||
(saes_table[0][x3 & 0xff] ^ saes_table[1][(x0 >> 8) & 0xff] ^ saes_table[2][(x1 >> 16) & 0xff] ^
|
||||
|
|
|
@ -55,7 +55,8 @@ public:
|
|||
}
|
||||
|
||||
|
||||
inline JobResult &operator=(const Job &job) {
|
||||
inline JobResult & operator=(const Job & job)
|
||||
{
|
||||
jobId = job.id();
|
||||
poolId = job.poolId();
|
||||
diff = job.diff();
|
||||
|
|
|
@ -39,12 +39,30 @@ public:
|
|||
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; }
|
||||
inline IWorker *worker() const { return m_worker; }
|
||||
inline void setWorker(IWorker *worker) { m_worker = worker; }
|
||||
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;
|
||||
}
|
||||
inline IWorker* worker() const
|
||||
{
|
||||
return m_worker;
|
||||
}
|
||||
inline void setWorker(IWorker* worker)
|
||||
{
|
||||
m_worker = worker;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_priority;
|
||||
|
|
|
@ -308,8 +308,8 @@
|
|||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<AssemblyDebug>true</AssemblyDebug>
|
||||
<ProgramDatabaseFile>$(ProjectName)$(Platform)d.pdb</ProgramDatabaseFile>
|
||||
<LinkStatus>true</LinkStatus>
|
||||
<MapExports>true</MapExports>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='vc-release|x64'">
|
||||
|
@ -328,7 +328,7 @@
|
|||
<AdditionalLibraryDirectories>$(SolutionDir)\..\..\libuv-1.x\Release\$(Platform)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libuv.lib;advapi32.lib;iphlpapi.lib;psapi.lib;shell32.lib;user32.lib;userenv.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>LIBCMTD;LIBCMT</IgnoreSpecificDefaultLibraries>
|
||||
<LinkStatus>true</LinkStatus>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='vc-debug|Win32'">
|
||||
|
@ -342,12 +342,12 @@
|
|||
<AdditionalLibraryDirectories>$(SolutionDir)\..\..\libuv-1.x\Release\$(Platform)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<IgnoreSpecificDefaultLibraries>LIBCMTD;LIBCMT</IgnoreSpecificDefaultLibraries>
|
||||
<AdditionalDependencies>libuv.lib;advapi32.lib;iphlpapi.lib;psapi.lib;shell32.lib;user32.lib;userenv.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<LinkStatus>true</LinkStatus>
|
||||
<ProgramDatabaseFile>$(ProjectName)$(Platform)d.pdb</ProgramDatabaseFile>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<GenerateMapFile>true</GenerateMapFile>
|
||||
<MapExports>true</MapExports>
|
||||
<AssemblyDebug>true</AssemblyDebug>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='vc-release|Win32'">
|
||||
|
@ -367,7 +367,7 @@
|
|||
<AdditionalLibraryDirectories>$(SolutionDir)\..\..\libuv-1.x\Release\$(Platform)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>libuv.lib;advapi32.lib;iphlpapi.lib;psapi.lib;shell32.lib;user32.lib;userenv.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<IgnoreSpecificDefaultLibraries>LIBCMTD;LIBCMT</IgnoreSpecificDefaultLibraries>
|
||||
<LinkStatus>true</LinkStatus>
|
||||
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -519,24 +519,6 @@
|
|||
<ClInclude Include="..\src\net\strategies\SinglePoolStrategy.h">
|
||||
<Filter>Archivos de encabezado\net\strategies</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\DoubleWorker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Handle.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Hashrate.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\SingleWorker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Worker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Workers.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\3rdparty\libcpuid\amd_code_t.h">
|
||||
<Filter>Archivos de encabezado\3rdparty\libcpuid</Filter>
|
||||
</ClInclude>
|
||||
|
@ -570,6 +552,24 @@
|
|||
<ClInclude Include="..\src\3rdparty\libcpuid\recog_amd.h">
|
||||
<Filter>Archivos de encabezado\3rdparty\libcpuid</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Workers.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\DoubleWorker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Handle.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Hashrate.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\SingleWorker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\src\workers\Worker.h">
|
||||
<Filter>Archivos de encabezado\workers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<MASM Include="..\src\3rdparty\libcpuid\masm-x64.asm">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue