diff options
author | luigi1111 <luigi1111w@gmail.com> | 2019-10-22 10:16:39 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2019-10-22 10:16:39 -0500 |
commit | 3fb85857e0346a1ff23f4d1cbc6d0d0bca101d31 (patch) | |
tree | 4b63ed0205cfc00b14530dcf0ae2e674a092e46c | |
parent | Merge pull request #5977 (diff) | |
parent | RandomX: update to v1.1.4 (diff) | |
download | monero-3fb85857e0346a1ff23f4d1cbc6d0d0bca101d31.tar.xz |
Merge pull request #5980
ea813cf RandomX: update to v1.1.4 (tevador)
m--------- | external/randomx | 0 | ||||
-rw-r--r-- | src/crypto/rx-slow-hash.c | 106 |
2 files changed, 30 insertions, 76 deletions
diff --git a/external/randomx b/external/randomx -Subproject 298cc77095c8992e30ecdd4ca0aa09a969a62bc +Subproject b53f0ed145c1a51df6ca0708a215089b76d0c05 diff --git a/src/crypto/rx-slow-hash.c b/src/crypto/rx-slow-hash.c index 59bd89d13..a7a459ad3 100644 --- a/src/crypto/rx-slow-hash.c +++ b/src/crypto/rx-slow-hash.c @@ -34,6 +34,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <limits.h> #include "randomx.h" #include "c_threads.h" @@ -74,84 +75,41 @@ static void local_abort(const char *msg) #endif } -/** - * @brief uses cpuid to determine if the CPU supports the AES instructions - * @return true if the CPU supports AES, false otherwise - */ +static inline int disabled_flags(void) { + static int flags = -1; -static inline int force_software_aes(void) -{ - static int use = -1; - - if (use != -1) - return use; + if (flags != -1) { + return flags; + } - const char *env = getenv("MONERO_USE_SOFTWARE_AES"); + const char *env = getenv("MONERO_RANDOMX_UMASK"); if (!env) { - use = 0; - } - else if (!strcmp(env, "0") || !strcmp(env, "no")) { - use = 0; + flags = 0; } 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; -} -static void cpuid(int CPUInfo[4], int InfoType) -{ -#if defined(__x86_64__) - __asm __volatile__ - ( - "cpuid": - "=a" (CPUInfo[0]), - "=b" (CPUInfo[1]), - "=c" (CPUInfo[2]), - "=d" (CPUInfo[3]) : - "a" (InfoType), "c" (0) - ); -#endif + return flags; } -static inline int check_aes_hw(void) -{ -#if defined(__x86_64__) - int cpuid_results[4]; - static int supported = -1; - if(supported >= 0) - return supported; +static inline int enabled_flags(void) { + static int flags = -1; - 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 (flags != -1) { + return flags; + } - if (use_rx_jit_flag != -1) - return use_rx_jit_flag; + flags = randomx_get_flags(); - 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; - } - else { - use_rx_jit_flag = 1; - } - return use_rx_jit_flag; -#else - return 0; -#endif + return flags; } #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) { uint64_t s_height = rx_seedheight(mainheight); 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; 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; if (cache == NULL) { - if (use_rx_jit()) - flags |= RANDOMX_FLAG_JIT; if (cache == NULL) { cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES); 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); } if (rx_vm == NULL) { - randomx_flags flags = RANDOMX_FLAG_DEFAULT; - if (use_rx_jit()) { - flags |= RANDOMX_FLAG_JIT; - if (!miners) - flags |= RANDOMX_FLAG_SECURE; + if ((flags & RANDOMX_FLAG_JIT) && !miners) { + flags |= RANDOMX_FLAG_SECURE & ~disabled_flags(); + } + if (miners && (disabled_flags() & RANDOMX_FLAG_FULL_MEM)) { + miners = 0; } - if(!force_software_aes() && check_aes_hw()) - flags |= RANDOMX_FLAG_HARD_AES; if (miners) { CTHR_MUTEX_LOCK(rx_dataset_mutex); if (rx_dataset == NULL) { |