Loading include/arch/posix/driver/counter.h +18 −1 Original line number Diff line number Diff line Loading @@ -9,13 +9,21 @@ #include <stdint.h> #include <time.h> typedef int64_t counter_value_t; #ifdef CONFIG_arch_posix_driver_counter_tsc #include <x86intrin.h> #endif typedef uint64_t counter_value_t; typedef uint8_t counter_overflow_t; class Counter { private: Counter(const Counter ©); #ifdef CONFIG_arch_posix_driver_counter_tsc uint64_t start_tsc; #else int64_t start_sec, start_nsec; #endif public: uint64_t value; Loading @@ -24,18 +32,27 @@ class Counter { Counter() : overflow(0) {} inline void start() { #ifdef CONFIG_arch_posix_driver_counter_tsc start_tsc = __rdtsc(); #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); start_sec = ts.tv_sec; start_nsec = ts.tv_nsec; #endif } inline void stop() { #ifdef CONFIG_arch_posix_driver_counter_tsc uint64_t stop_tsc = __rdtsc(); value = stop_tsc - start_tsc; #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); value = (ts.tv_sec - start_sec) * 1000000000L; value += ts.tv_nsec - start_nsec; #endif } }; Loading src/arch/posix/Kconfig +4 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,10 @@ config arch_posix_driver_counter bool "Cycle counter" select meta_driver_counter config arch_posix_driver_counter_tsc bool "Use TSC (x86 only)" depends on arch_posix_driver_counter config arch_posix_driver_i2c bool "I2C via /dev/i2c" select meta_driver_hardware_i2c Loading Loading
include/arch/posix/driver/counter.h +18 −1 Original line number Diff line number Diff line Loading @@ -9,13 +9,21 @@ #include <stdint.h> #include <time.h> typedef int64_t counter_value_t; #ifdef CONFIG_arch_posix_driver_counter_tsc #include <x86intrin.h> #endif typedef uint64_t counter_value_t; typedef uint8_t counter_overflow_t; class Counter { private: Counter(const Counter ©); #ifdef CONFIG_arch_posix_driver_counter_tsc uint64_t start_tsc; #else int64_t start_sec, start_nsec; #endif public: uint64_t value; Loading @@ -24,18 +32,27 @@ class Counter { Counter() : overflow(0) {} inline void start() { #ifdef CONFIG_arch_posix_driver_counter_tsc start_tsc = __rdtsc(); #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); start_sec = ts.tv_sec; start_nsec = ts.tv_nsec; #endif } inline void stop() { #ifdef CONFIG_arch_posix_driver_counter_tsc uint64_t stop_tsc = __rdtsc(); value = stop_tsc - start_tsc; #else struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); value = (ts.tv_sec - start_sec) * 1000000000L; value += ts.tv_nsec - start_nsec; #endif } }; Loading
src/arch/posix/Kconfig +4 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,10 @@ config arch_posix_driver_counter bool "Cycle counter" select meta_driver_counter config arch_posix_driver_counter_tsc bool "Use TSC (x86 only)" depends on arch_posix_driver_counter config arch_posix_driver_i2c bool "I2C via /dev/i2c" select meta_driver_hardware_i2c Loading