mdbx-test: fix/refine entropy_ticks() for ARM.

Change-Id: I03b10edfcbee33c1b3107a0c1a5714aac61cf12f
This commit is contained in:
Leonid Yuriev 2018-11-26 18:52:31 +03:00
parent 68be9b39a8
commit cbdb10a05c
2 changed files with 37 additions and 11 deletions

View File

@ -376,6 +376,10 @@ int main(int argc, char *const argv[]) {
if (global::config::cleanup_before) if (global::config::cleanup_before)
cleanup(); cleanup();
log_trace(">> probe entropy_ticks()");
entropy_ticks();
log_trace("<< probe entropy_ticks()");
if (global::actors.size() == 1) { if (global::actors.size() == 1) {
logging::setup("main"); logging::setup("main");
global::singlemode = true; global::singlemode = true;

View File

@ -1,4 +1,4 @@
/* /*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru> * Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file. * and other libmdbx authors: please see AUTHORS file.
* All rights reserved. * All rights reserved.
@ -190,10 +190,34 @@ uint64_t entropy_ticks(void) {
uint64_t virtual_timer; uint64_t virtual_timer;
__asm __volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer)); __asm __volatile("mrs %0, cntvct_el0" : "=r"(virtual_timer));
return virtual_timer; return virtual_timer;
#elif defined(__ARM_ARCH) && __ARM_ARCH > 5 && __ARM_ARCH < 8 #elif (defined(__ARM_ARCH) && __ARM_ARCH > 5 && __ARM_ARCH < 8) || \
unsigned long pmccntr; defined(_M_ARM)
__asm __volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr)); static uint32_t pmcntenset = 0x00425B00;
return pmccntr; if (unlikely(pmcntenset == 0x00425B00)) {
uint32_t pmuseren;
#ifdef _M_ARM
pmuseren = _MoveFromCoprocessor(15, 0, 9, 14, 0);
#else
__asm("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren));
#endif
if (1 & pmuseren /* Is it allowed for user mode code? */) {
#ifdef _M_ARM
pmcntenset = _MoveFromCoprocessor(15, 0, 9, 12, 1);
#else
__asm("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset));
#endif
} else
pmcntenset = 0;
}
if (pmcntenset & 0x80000000ul /* Is it counting? */) {
#ifdef _M_ARM
return __rdpmccntr64();
#else
uint32_t pmccntr;
__asm __volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr));
return pmccntr;
#endif
}
#elif defined(__mips__) || defined(__mips) || defined(_R4000) #elif defined(__mips__) || defined(__mips) || defined(_R4000)
unsigned count; unsigned count;
__asm __volatile("rdhwr %0, $2" : "=r"(count)); __asm __volatile("rdhwr %0, $2" : "=r"(count));
@ -203,8 +227,6 @@ uint64_t entropy_ticks(void) {
#if defined(__e2k__) || defined(__ia32__) #if defined(__e2k__) || defined(__ia32__)
return __rdtsc(); return __rdtsc();
#elif defined(_M_ARM)
return __rdpmccntr64();
#elif defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) #elif defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
LARGE_INTEGER PerformanceCount; LARGE_INTEGER PerformanceCount;
if (QueryPerformanceCounter(&PerformanceCount)) if (QueryPerformanceCounter(&PerformanceCount))
@ -213,13 +235,13 @@ uint64_t entropy_ticks(void) {
#else #else
struct timespec ts; struct timespec ts;
#if defined(CLOCK_MONOTONIC_COARSE) #if defined(CLOCK_MONOTONIC_COARSE)
clockid_t clock = CLOCK_MONOTONIC_COARSE; clockid_t clk_id = CLOCK_MONOTONIC_COARSE;
#elif defined(CLOCK_MONOTONIC_RAW) #elif defined(CLOCK_MONOTONIC_RAW)
clockid_t clock = CLOCK_MONOTONIC_RAW; clockid_t clk_id = CLOCK_MONOTONIC_RAW;
#else #else
clockid_t clock = CLOCK_MONOTONIC; clockid_t clk_id = CLOCK_MONOTONIC;
#endif #endif
int rc = clock_gettime(clock, &ts); int rc = clock_gettime(clk_id, &ts);
if (unlikely(rc)) if (unlikely(rc))
failure_perror("clock_gettime()", rc); failure_perror("clock_gettime()", rc);