+set ( TIME_INCLUDES
+ clock_defs.h
+ packet_time.h
+ stopwatch.h
+)
+
set ( TIME_INTERNAL_SOURCES
packet_time.cc
periodic.cc
periodic.h
timersub.h
- tsc_clock.cc
)
+if ( USE_TSC_CLOCK )
+ list ( APPEND TIME_INCLUDES tsc_clock.h )
+ list ( APPEND TIME_INTERNAL_SOURCES tsc_clock.cc )
+endif ( USE_TSC_CLOCK )
+
if ( ENABLE_UNIT_TESTS )
list ( APPEND TIME_INTERNAL_SOURCES stopwatch_test.cc )
endif ( ENABLE_UNIT_TESTS )
-set ( TIME_INCLUDES
- clock_defs.h
- packet_time.h
- stopwatch.h
- tsc_clock.h
-)
-
add_library ( time OBJECT
${TIME_INTERNAL_SOURCES}
${TIME_INCLUDES}
static uint64_t counter()
{
-#if defined(__aarch64__)
+#if defined(__i386__) || defined(__x86_64__)
+ uint32_t lo, hi;
+ asm volatile("rdtsc" : "=a" (lo), "=d" (hi));
+ return ((uint64_t)hi << 32) | lo;
+#elif 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;
+#error "TscClock is not supported on this architecture!"
#endif
}