mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-22 18:54:43 +00:00
Fix autoconfig and memory allocation for heavy algo.
This commit is contained in:
parent
5c6ec587ac
commit
7d5a97137d
7 changed files with 42 additions and 14 deletions
19
src/Cpu.cpp
19
src/Cpu.cpp
|
@ -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
|
||||
|
@ -39,7 +39,7 @@ int Cpu::m_totalCores = 0;
|
|||
int Cpu::m_totalThreads = 0;
|
||||
|
||||
|
||||
int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
||||
int Cpu::optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage)
|
||||
{
|
||||
if (m_totalThreads == 1) {
|
||||
return 1;
|
||||
|
@ -54,7 +54,18 @@ int Cpu::optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage)
|
|||
}
|
||||
|
||||
int count = 0;
|
||||
const int size = (algo ? 1024 : 2048) * (doubleHash ? 2 : 1);
|
||||
int size = 2048;
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_LITE) {
|
||||
size = 1024;
|
||||
}
|
||||
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
size = 4096;
|
||||
}
|
||||
|
||||
if (doubleHash) {
|
||||
size *= 2;
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
count = cache / size;
|
||||
|
|
|
@ -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
|
||||
|
@ -28,6 +28,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
class Cpu
|
||||
{
|
||||
public:
|
||||
|
@ -37,7 +40,7 @@ public:
|
|||
BMI2 = 4
|
||||
};
|
||||
|
||||
static int optimalThreadsCount(int algo, bool doubleHash, int maxCpuUsage);
|
||||
static int optimalThreadsCount(xmrig::Algo algo, bool doubleHash, int maxCpuUsage);
|
||||
static void init();
|
||||
static void setAffinity(int id, uint64_t mask);
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
|
||||
|
||||
#include "crypto/CryptoNight.h"
|
||||
#include "crypto/CryptoNight_constants.h"
|
||||
#include "Mem.h"
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::m_doubleHash = false;
|
||||
|
@ -48,10 +48,13 @@ cryptonight_ctx *Mem::create(int threadId)
|
|||
}
|
||||
# endif
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[MONERO_MEMORY - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
const size_t size = m_algo == xmrig::CRYPTONIGHT_HEAVY ? xmrig::cn_select_memory<xmrig::CRYPTONIGHT_HEAVY>()
|
||||
: xmrig::cn_select_memory<xmrig::CRYPTONIGHT>();
|
||||
|
||||
cryptonight_ctx *ctx = reinterpret_cast<cryptonight_ctx *>(&m_memory[size - sizeof(cryptonight_ctx) * (threadId + 1)]);
|
||||
|
||||
const int ratio = m_doubleHash ? 2 : 1;
|
||||
ctx->memory = &m_memory[MONERO_MEMORY * (threadId * ratio + 1)];
|
||||
ctx->memory = &m_memory[size * (threadId * ratio + 1)];
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "xmrig.h"
|
||||
|
||||
|
||||
struct cryptonight_ctx;
|
||||
|
||||
|
||||
|
@ -42,7 +45,7 @@ public:
|
|||
Lock = 4
|
||||
};
|
||||
|
||||
static bool allocate(int algo, int threads, bool doubleHash, bool enabled);
|
||||
static bool allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled);
|
||||
static cryptonight_ctx *create(int threadId);
|
||||
static void *calloc(size_t num, size_t size);
|
||||
static void release();
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include "xmrig.h"
|
||||
|
||||
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
|
@ -49,6 +49,10 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
|||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
|
|
@ -145,7 +145,7 @@ static BOOL TrySetLockPagesPrivilege() {
|
|||
}
|
||||
|
||||
|
||||
bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
||||
bool Mem::allocate(xmrig::Algo algo, int threads, bool doubleHash, bool enabled)
|
||||
{
|
||||
m_algo = algo;
|
||||
m_threads = threads;
|
||||
|
@ -154,6 +154,10 @@ bool Mem::allocate(int algo, int threads, bool doubleHash, bool enabled)
|
|||
const int ratio = (doubleHash && algo != xmrig::CRYPTONIGHT_LITE) ? 2 : 1;
|
||||
m_size = MONERO_MEMORY * (threads * ratio + 1);
|
||||
|
||||
if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
||||
m_size *= 2;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
m_memory = static_cast<uint8_t*>(_mm_malloc(m_size, 16));
|
||||
return true;
|
||||
|
|
|
@ -116,7 +116,7 @@ bool SingleWorker::selfTest()
|
|||
}
|
||||
# endif
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue