]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Allow use of ARM64 CNTVCT_EL0 register for timing (#46)
authorJonathan McDowell <noodles-github@earth.li>
Fri, 23 Mar 2018 00:35:52 +0000 (00:35 +0000)
committersnortadmin <snortadmin@users.noreply.github.com>
Fri, 23 Mar 2018 00:35:52 +0000 (20:35 -0400)
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.

src/time/tsc_clock.h

index 68dd81b5375a15d0fefbfe15a78df7c26ee5a9ba..c7729808abdb5c1bbfa55d2a955631ab561ad8b9 100644 (file)
@@ -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