From: Jonathan McDowell Date: Fri, 23 Mar 2018 00:35:52 +0000 (+0000) Subject: Allow use of ARM64 CNTVCT_EL0 register for timing (#46) X-Git-Tag: 3.0.0-245~73 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fc465074c99962dbbb2d9716709963831de689f1;p=thirdparty%2Fsnort3.git Allow use of ARM64 CNTVCT_EL0 register for timing (#46) snort supports the use of rdtsc to get fast, accurate-enough timing on x86 platforms. The CNTVCT_EL0 register on ARM64 provides a usable equivalent to userspace code on that platform. It's not the actual processor clock rate but can vary in accuracy from 1-50Mhz. Its use gives a ~10% performance improvement on an A53 based platform. --- diff --git a/src/time/tsc_clock.h b/src/time/tsc_clock.h index 68dd81b53..c7729808a 100644 --- a/src/time/tsc_clock.h +++ b/src/time/tsc_clock.h @@ -48,9 +48,17 @@ struct TscClock static uint64_t counter() { +#if defined(__aarch64__) + uint64_t ticks; + + asm volatile("mrs %0, CNTVCT_EL0" : "=r" (ticks)); + return ticks; +#else + // Default to x86, other archs will compile error anyway uint32_t lo, hi; asm volatile("rdtsc" : "=a" (lo), "=d" (hi)); return ((uint64_t)hi << 32) | lo; +#endif } static time_point now() noexcept