New summary information about 1GB pages.

This commit is contained in:
XMRig 2019-12-08 14:21:28 +07:00
parent 91b50f1ac8
commit 86e25a13e3
No known key found for this signature in database
GPG key ID: 446A53638BE94409
4 changed files with 46 additions and 22 deletions

View file

@ -60,26 +60,28 @@ inline static const char *asmName(Assembly::Id assembly)
static void print_memory(Config *config) { static void print_memory(Config *config) {
# ifdef _WIN32 # ifdef XMRIG_OS_WIN
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
"HUGE PAGES", config->cpu().isHugePages() ? (VirtualMemory::isHugepagesAvailable() ? GREEN_BOLD("permission granted") : RED_BOLD("unavailable")) : RED_BOLD("disabled")); "HUGE PAGES", config->cpu().isHugePages() ? (VirtualMemory::isHugepagesAvailable() ? GREEN_BOLD("permission granted") : RED_BOLD("unavailable")) : RED_BOLD("disabled"));
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", "1GB PAGES", YELLOW_BOLD("unavailable"));
# else
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", "HUGE PAGES", config->cpu().isHugePages() ? GREEN_BOLD("supported") : RED_BOLD("disabled"));
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s", Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") "%s",
"1GB PAGES", Cpu::info()->hasOneGbPages() ? GREEN_BOLD("available on Linux") : RED_BOLD("unavailable")); "1GB PAGES", config->cpu().isOneGbPages() ? (VirtualMemory::isOneGbPagesAvailable() ? GREEN_BOLD("supported") : YELLOW_BOLD("unavailable")) : YELLOW_BOLD("disabled"));
# endif # endif
} }
static void print_cpu(Config *) static void print_cpu(Config *)
{ {
const ICpuInfo *info = Cpu::info(); const auto info = Cpu::info();
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu)") " %sx64 %sAES %sPDPE1GB", Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s%s (%zu)") " %sx64 %sAES",
"CPU", "CPU",
info->brand(), info->brand(),
info->packages(), info->packages(),
info->isX64() ? GREEN_BOLD_S : RED_BOLD_S "-", info->isX64() ? GREEN_BOLD_S : RED_BOLD_S "-",
info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-", info->hasAES() ? GREEN_BOLD_S : RED_BOLD_S "-"
info->hasOneGbPages() ? GREEN_BOLD_S : RED_BOLD_S "-"
); );
# if defined(XMRIG_FEATURE_LIBCPUID) || defined (XMRIG_FEATURE_HWLOC) # if defined(XMRIG_FEATURE_LIBCPUID) || defined (XMRIG_FEATURE_HWLOC)
Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("L2:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" L3:") WHITE_BOLD("%.1f MB") Log::print(WHITE_BOLD(" %-13s") BLACK_BOLD("L2:") WHITE_BOLD("%.1f MB") BLACK_BOLD(" L3:") WHITE_BOLD("%.1f MB")

View file

@ -58,6 +58,7 @@ public:
} }
static bool isHugepagesAvailable(); static bool isHugepagesAvailable();
static bool isOneGbPagesAvailable();
static uint32_t bindToNUMANode(int64_t affinity); static uint32_t bindToNUMANode(int64_t affinity);
static void *allocateExecutableMemory(size_t size); static void *allocateExecutableMemory(size_t size);
static void *allocateLargePagesMemory(size_t size); static void *allocateLargePagesMemory(size_t size);

View file

@ -29,6 +29,7 @@
#include <sys/mman.h> #include <sys/mman.h>
#include "backend/cpu/Cpu.h"
#include "crypto/common/portable/mm_malloc.h" #include "crypto/common/portable/mm_malloc.h"
#include "crypto/common/VirtualMemory.h" #include "crypto/common/VirtualMemory.h"
@ -38,12 +39,27 @@
#endif #endif
#if defined (XMRIG_OS_LINUX) && (defined(MAP_HUGE_1GB) || defined(MAP_HUGE_SHIFT))
# define XMRIG_HAS_1GB_PAGES
#endif
bool xmrig::VirtualMemory::isHugepagesAvailable() bool xmrig::VirtualMemory::isHugepagesAvailable()
{ {
return true; return true;
} }
bool xmrig::VirtualMemory::isOneGbPagesAvailable()
{
# ifdef XMRIG_HAS_1GB_PAGES
return Cpu::info()->hasOneGbPages();
# else
return false;
# endif
}
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size) void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
{ {
# if defined(__APPLE__) # if defined(__APPLE__)
@ -72,12 +88,8 @@ void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
void *xmrig::VirtualMemory::allocateOneGbPagesMemory(size_t size) void *xmrig::VirtualMemory::allocateOneGbPagesMemory(size_t size)
{ {
# if defined(__APPLE__) # ifdef XMRIG_HAS_1GB_PAGES
void *mem = MAP_FAILED; if (isOneGbPagesAvailable()) {
# elif defined(__FreeBSD__)
void *mem = MAP_FAILED;
# else
# if defined(MAP_HUGE_1GB) # if defined(MAP_HUGE_1GB)
constexpr int flag_1gb = MAP_HUGE_1GB; constexpr int flag_1gb = MAP_HUGE_1GB;
# elif defined(MAP_HUGE_SHIFT) # elif defined(MAP_HUGE_SHIFT)
@ -87,10 +99,13 @@ void *xmrig::VirtualMemory::allocateOneGbPagesMemory(size_t size)
# endif # endif
void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE | flag_1gb, 0, 0); void *mem = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE | flag_1gb, 0, 0);
# endif
return mem == MAP_FAILED ? nullptr : mem; return mem == MAP_FAILED ? nullptr : mem;
} }
# endif
return nullptr;
}
void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size) void xmrig::VirtualMemory::flushInstructionCache(void *p, size_t size)

View file

@ -156,6 +156,12 @@ bool xmrig::VirtualMemory::isHugepagesAvailable()
} }
bool xmrig::VirtualMemory::isOneGbPagesAvailable()
{
return false;
}
void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size) void *xmrig::VirtualMemory::allocateExecutableMemory(size_t size)
{ {
return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); return VirtualAlloc(nullptr, size, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
@ -175,7 +181,7 @@ void *xmrig::VirtualMemory::allocateLargePagesMemory(size_t size)
} }
void *xmrig::VirtualMemory::allocateOneGbPagesMemory(size_t size) void *xmrig::VirtualMemory::allocateOneGbPagesMemory(size_t)
{ {
return nullptr; return nullptr;
} }