mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
Add Mem class.
This commit is contained in:
parent
ef3af1c4fd
commit
30642881bf
5 changed files with 107 additions and 27 deletions
|
@ -6,14 +6,15 @@ option(WITH_AEON "CryptoNight-Lite support" ON)
|
||||||
|
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
src/App.h
|
src/App.h
|
||||||
|
src/Console.h
|
||||||
|
src/Cpu.h
|
||||||
src/interfaces/IClientListener.h
|
src/interfaces/IClientListener.h
|
||||||
|
src/Mem.h
|
||||||
src/net/Client.h
|
src/net/Client.h
|
||||||
src/net/Job.h
|
src/net/Job.h
|
||||||
src/net/Network.h
|
src/net/Network.h
|
||||||
src/net/Url.h
|
src/net/Url.h
|
||||||
src/Options.h
|
src/Options.h
|
||||||
src/Console.h
|
|
||||||
src/Cpu.h
|
|
||||||
src/Summary.h
|
src/Summary.h
|
||||||
src/version.h
|
src/version.h
|
||||||
)
|
)
|
||||||
|
@ -34,12 +35,13 @@ set(HEADERS_CRYPTO
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
src/App.cpp
|
src/App.cpp
|
||||||
|
src/Console.cpp
|
||||||
|
src/Mem.cpp
|
||||||
src/net/Client.cpp
|
src/net/Client.cpp
|
||||||
src/net/Job.cpp
|
src/net/Job.cpp
|
||||||
src/net/Network.cpp
|
src/net/Network.cpp
|
||||||
src/net/Url.cpp
|
src/net/Url.cpp
|
||||||
src/Options.cpp
|
src/Options.cpp
|
||||||
src/Console.cpp
|
|
||||||
src/Summary.cpp
|
src/Summary.cpp
|
||||||
src/xmrig.cpp
|
src/xmrig.cpp
|
||||||
)
|
)
|
||||||
|
@ -61,6 +63,7 @@ if (WIN32)
|
||||||
src/3rdparty/winansi.cpp
|
src/3rdparty/winansi.cpp
|
||||||
src/3rdparty/winansi.h
|
src/3rdparty/winansi.h
|
||||||
src/Cpu_win.cpp
|
src/Cpu_win.cpp
|
||||||
|
src/Mem_win.cpp
|
||||||
src/net/Network_win.cpp
|
src/net/Network_win.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include "Console.h"
|
#include "Console.h"
|
||||||
#include "Cpu.h"
|
#include "Cpu.h"
|
||||||
#include "crypto/CryptoNight.h"
|
#include "crypto/CryptoNight.h"
|
||||||
|
#include "Mem.h"
|
||||||
#include "net/Client.h"
|
#include "net/Client.h"
|
||||||
#include "net/Network.h"
|
#include "net/Network.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
@ -67,6 +68,7 @@ App::exec()
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash());
|
||||||
Summary::print();
|
Summary::print();
|
||||||
|
|
||||||
m_network->connect();
|
m_network->connect();
|
||||||
|
|
28
src/Mem.cpp
Normal file
28
src/Mem.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Mem.h"
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t *Mem::m_memory = nullptr;
|
||||||
|
int Mem::m_flags = 0;
|
51
src/Mem.h
Normal file
51
src/Mem.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/* XMRig
|
||||||
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||||
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||||
|
* 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>
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __MEM_H__
|
||||||
|
#define __MEM_H__
|
||||||
|
|
||||||
|
|
||||||
|
#include "crypto/CryptoNight.h"
|
||||||
|
|
||||||
|
|
||||||
|
class Mem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum Flags {
|
||||||
|
HUGEPAGES_AVAILABLE = 1,
|
||||||
|
HUGEPAGES_ENABLED = 2,
|
||||||
|
LOCK = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
static bool allocate(int algo, int threads, bool doubleHash);
|
||||||
|
static void release();
|
||||||
|
|
||||||
|
static inline int flags() { return m_flags; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static uint8_t *m_memory __attribute__((aligned(16)));
|
||||||
|
static int m_flags;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __MEM_H__ */
|
|
@ -21,20 +21,16 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __MEMORY_H__
|
|
||||||
#define __MEMORY_H__
|
|
||||||
|
|
||||||
|
#include <winsock2.h>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <ntsecapi.h>
|
#include <ntsecapi.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#include "options.h"
|
|
||||||
#include "persistent_memory.h"
|
|
||||||
#include "utils/applog.h"
|
|
||||||
|
|
||||||
|
#include "Mem.h"
|
||||||
char *persistent_memory;
|
#include "Console.h"
|
||||||
int persistent_memory_flags = 0;
|
#include "Options.h"
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
|
@ -122,7 +118,7 @@ static BOOL ObtainLockPagesPrivilege() {
|
||||||
LSA_UNICODE_STRING str = StringToLsaUnicodeString(_T(SE_LOCK_MEMORY_NAME));
|
LSA_UNICODE_STRING str = StringToLsaUnicodeString(_T(SE_LOCK_MEMORY_NAME));
|
||||||
|
|
||||||
if (LsaAddAccountRights(handle, user->User.Sid, &str, 1) == 0) {
|
if (LsaAddAccountRights(handle, user->User.Sid, &str, 1) == 0) {
|
||||||
applog_notime(LOG_WARNING, "Huge pages support was successfully enabled, but reboot required to use it");
|
LOG_DEBUG("Huge pages support was successfully enabled, but reboot required to use it");
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,33 +139,33 @@ static BOOL TrySetLockPagesPrivilege() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char * persistent_memory_allocate() {
|
bool Mem::allocate(int algo, int threads, bool doubleHash)
|
||||||
const int ratio = (opt_double_hash && opt_algo != ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
{
|
||||||
const int size = MEMORY * (opt_n_threads * ratio + 1);
|
const int ratio = (doubleHash && algo != Options::ALGO_CRYPTONIGHT_LITE) ? 2 : 1;
|
||||||
|
const size_t size = MEMORY * (threads * ratio + 1);
|
||||||
|
|
||||||
if (TrySetLockPagesPrivilege()) {
|
if (TrySetLockPagesPrivilege()) {
|
||||||
persistent_memory_flags |= MEMORY_HUGEPAGES_AVAILABLE;
|
m_flags |= HUGEPAGES_AVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
persistent_memory = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE);
|
m_memory = static_cast<uint8_t*>(VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE));
|
||||||
if (!persistent_memory) {
|
if (!m_memory) {
|
||||||
persistent_memory = _mm_malloc(size, 16);
|
m_memory = static_cast<uint8_t*>(_mm_malloc(size, 16));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
persistent_memory_flags |= MEMORY_HUGEPAGES_ENABLED;
|
m_flags |= HUGEPAGES_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return persistent_memory;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void persistent_memory_free() {
|
void Mem::release()
|
||||||
if (persistent_memory_flags & MEMORY_HUGEPAGES_ENABLED) {
|
{
|
||||||
VirtualFree(persistent_memory, 0, MEM_RELEASE);
|
if (m_flags & HUGEPAGES_ENABLED) {
|
||||||
|
VirtualFree(m_memory, 0, MEM_RELEASE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_mm_free(persistent_memory);
|
_mm_free(m_memory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* __MEMORY_H__ */
|
|
Loading…
Reference in a new issue