mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 04:16:32 +02:00
RandomX: update to v1.1.4
* Faster cache initialization with SSSE3/AVX2 * Automatic detection of CPU capabilities in RandomX * Fixed a possible out-of-bounds access in superscalar program generator * Use MONERO_RANDOMX_UMASK to manually disable RandomX flags in monerod
This commit is contained in:
parent
aa72c21d84
commit
ea813cfb1b
2
external/randomx
vendored
2
external/randomx
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 298cc77095c8992e30ecdd4ca0aa09a969a62bc1
|
Subproject commit b53f0ed145c1a51df6ca0708a215089b76d0c056
|
@ -34,6 +34,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "randomx.h"
|
#include "randomx.h"
|
||||||
#include "c_threads.h"
|
#include "c_threads.h"
|
||||||
@ -74,84 +75,41 @@ static void local_abort(const char *msg)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static inline int disabled_flags(void) {
|
||||||
* @brief uses cpuid to determine if the CPU supports the AES instructions
|
static int flags = -1;
|
||||||
* @return true if the CPU supports AES, false otherwise
|
|
||||||
*/
|
|
||||||
|
|
||||||
static inline int force_software_aes(void)
|
if (flags != -1) {
|
||||||
{
|
return flags;
|
||||||
static int use = -1;
|
|
||||||
|
|
||||||
if (use != -1)
|
|
||||||
return use;
|
|
||||||
|
|
||||||
const char *env = getenv("MONERO_USE_SOFTWARE_AES");
|
|
||||||
if (!env) {
|
|
||||||
use = 0;
|
|
||||||
}
|
}
|
||||||
else if (!strcmp(env, "0") || !strcmp(env, "no")) {
|
|
||||||
use = 0;
|
const char *env = getenv("MONERO_RANDOMX_UMASK");
|
||||||
|
if (!env) {
|
||||||
|
flags = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
use = 1;
|
char* endptr;
|
||||||
|
long int value = strtol(env, &endptr, 0);
|
||||||
|
if (endptr != env && value >= 0 && value < INT_MAX) {
|
||||||
|
flags = value;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
flags = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return use;
|
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpuid(int CPUInfo[4], int InfoType)
|
static inline int enabled_flags(void) {
|
||||||
{
|
static int flags = -1;
|
||||||
#if defined(__x86_64__)
|
|
||||||
__asm __volatile__
|
|
||||||
(
|
|
||||||
"cpuid":
|
|
||||||
"=a" (CPUInfo[0]),
|
|
||||||
"=b" (CPUInfo[1]),
|
|
||||||
"=c" (CPUInfo[2]),
|
|
||||||
"=d" (CPUInfo[3]) :
|
|
||||||
"a" (InfoType), "c" (0)
|
|
||||||
);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
static inline int check_aes_hw(void)
|
|
||||||
{
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
int cpuid_results[4];
|
|
||||||
static int supported = -1;
|
|
||||||
|
|
||||||
if(supported >= 0)
|
if (flags != -1) {
|
||||||
return supported;
|
return flags;
|
||||||
|
|
||||||
cpuid(cpuid_results,1);
|
|
||||||
return supported = cpuid_results[2] & (1 << 25);
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static volatile int use_rx_jit_flag = -1;
|
|
||||||
|
|
||||||
static inline int use_rx_jit(void)
|
|
||||||
{
|
|
||||||
#if defined(__x86_64__)
|
|
||||||
|
|
||||||
if (use_rx_jit_flag != -1)
|
|
||||||
return use_rx_jit_flag;
|
|
||||||
|
|
||||||
const char *env = getenv("MONERO_USE_RX_JIT");
|
|
||||||
if (!env) {
|
|
||||||
use_rx_jit_flag = 1;
|
|
||||||
}
|
}
|
||||||
else if (!strcmp(env, "0") || !strcmp(env, "no")) {
|
|
||||||
use_rx_jit_flag = 0;
|
flags = randomx_get_flags();
|
||||||
}
|
|
||||||
else {
|
return flags;
|
||||||
use_rx_jit_flag = 1;
|
|
||||||
}
|
|
||||||
return use_rx_jit_flag;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SEEDHASH_EPOCH_BLOCKS 2048 /* Must be same as BLOCKS_SYNCHRONIZING_MAX_COUNT in cryptonote_config.h */
|
#define SEEDHASH_EPOCH_BLOCKS 2048 /* Must be same as BLOCKS_SYNCHRONIZING_MAX_COUNT in cryptonote_config.h */
|
||||||
@ -236,7 +194,7 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
|||||||
char *hash, int miners, int is_alt) {
|
char *hash, int miners, int is_alt) {
|
||||||
uint64_t s_height = rx_seedheight(mainheight);
|
uint64_t s_height = rx_seedheight(mainheight);
|
||||||
int toggle = (s_height & SEEDHASH_EPOCH_BLOCKS) != 0;
|
int toggle = (s_height & SEEDHASH_EPOCH_BLOCKS) != 0;
|
||||||
randomx_flags flags = RANDOMX_FLAG_DEFAULT;
|
randomx_flags flags = enabled_flags() & ~disabled_flags();
|
||||||
rx_state *rx_sp;
|
rx_state *rx_sp;
|
||||||
randomx_cache *cache;
|
randomx_cache *cache;
|
||||||
|
|
||||||
@ -263,8 +221,6 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
|||||||
|
|
||||||
cache = rx_sp->rs_cache;
|
cache = rx_sp->rs_cache;
|
||||||
if (cache == NULL) {
|
if (cache == NULL) {
|
||||||
if (use_rx_jit())
|
|
||||||
flags |= RANDOMX_FLAG_JIT;
|
|
||||||
if (cache == NULL) {
|
if (cache == NULL) {
|
||||||
cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
|
cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
|
||||||
if (cache == NULL) {
|
if (cache == NULL) {
|
||||||
@ -282,14 +238,12 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
|||||||
memcpy(rx_sp->rs_hash, seedhash, HASH_SIZE);
|
memcpy(rx_sp->rs_hash, seedhash, HASH_SIZE);
|
||||||
}
|
}
|
||||||
if (rx_vm == NULL) {
|
if (rx_vm == NULL) {
|
||||||
randomx_flags flags = RANDOMX_FLAG_DEFAULT;
|
if ((flags & RANDOMX_FLAG_JIT) && !miners) {
|
||||||
if (use_rx_jit()) {
|
flags |= RANDOMX_FLAG_SECURE & ~disabled_flags();
|
||||||
flags |= RANDOMX_FLAG_JIT;
|
}
|
||||||
if (!miners)
|
if (miners && (disabled_flags() & RANDOMX_FLAG_FULL_MEM)) {
|
||||||
flags |= RANDOMX_FLAG_SECURE;
|
miners = 0;
|
||||||
}
|
}
|
||||||
if(!force_software_aes() && check_aes_hw())
|
|
||||||
flags |= RANDOMX_FLAG_HARD_AES;
|
|
||||||
if (miners) {
|
if (miners) {
|
||||||
CTHR_MUTEX_LOCK(rx_dataset_mutex);
|
CTHR_MUTEX_LOCK(rx_dataset_mutex);
|
||||||
if (rx_dataset == NULL) {
|
if (rx_dataset == NULL) {
|
||||||
|
Loading…
Reference in New Issue
Block a user