Skip to content

fd_tickcount support on Arm via cntvct_el0 #5645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/util/fd_util_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
#define FD_HAS_AESNI 0
#endif

/* FD_HAS_ARM: If the build target supports armv8-a specific features
and can benefit from aarch64 specific optimizations, define
FD_HAS_ARM. */

#ifndef FD_HAS_ARM
#define FD_HAS_ARM 0
#endif

/* FD_HAS_LZ4 indicates that the target supports LZ4 compression.
Roughly, does "#include <lz4.h>" and the APIs therein work? */

Expand Down Expand Up @@ -1229,6 +1237,8 @@ fd_hash_memcpy( ulong seed,
#ifndef FD_TICKCOUNT_STYLE
#if FD_HAS_X86 /* Use RDTSC */
#define FD_TICKCOUNT_STYLE 1
#elif FD_HAS_ARM /* Use CNTVCT_EL0 */
#define FD_TICKCOUNT_STYLE 2
#else /* Use portable fallback */
#define FD_TICKCOUNT_STYLE 0
#endif
Expand Down Expand Up @@ -1274,6 +1284,22 @@ fd_hash_memcpy( ulong seed,

#define fd_tickcount() ((long)__builtin_ia32_rdtsc())

#elif FD_TICKCOUNT_STYLE==2 /* armv8 (fast) */

/* fd_tickcount (ARM): Placeholder, may return incorrect results. */

static inline long
fd_tickcount( void ) {
/* consider using 'isb' */
ulong value;
__asm__ __volatile__ (
"isb\n"
"mrs %0, cntvct_el0\n"
"nop"
: "=r" (value) );
return (long)value;
}

#else
#error "Unknown FD_TICKCOUNT_STYLE"
#endif
Expand Down
Loading