diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-12-13 14:24:34 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-12-13 14:24:34 +0100 |
commit | 566e698caf23dc034335cfbb05641726ec4c273b (patch) | |
tree | 62d60388c11a76ccd18f2d71b742caedcebab732 | |
parent | ebd3e2890cad3fbc9b0293b91173995d191ee804 (diff) |
add fake counter driver for arch=posix
-rw-r--r-- | include/arch/posix/driver/counter.h | 31 | ||||
-rw-r--r-- | src/arch/posix/driver/counter.cc | 3 |
2 files changed, 34 insertions, 0 deletions
diff --git a/include/arch/posix/driver/counter.h b/include/arch/posix/driver/counter.h new file mode 100644 index 0000000..6390d14 --- /dev/null +++ b/include/arch/posix/driver/counter.h @@ -0,0 +1,31 @@ +#include <stdint.h> +#include <time.h> + +class Counter { + private: + Counter(const Counter ©); + uint64_t start_sec, start_nsec; + + public: + uint64_t value; + volatile uint8_t overflowed; + + Counter() : overflowed(0) {} + + inline void start() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + start_sec = ts.tv_sec; + start_nsec = ts.tv_nsec; + } + + inline void stop() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + + value = (ts.tv_sec - start_sec) * 1000000000UL; + value += ts.tv_nsec - start_nsec; + } +}; + +extern Counter counter; diff --git a/src/arch/posix/driver/counter.cc b/src/arch/posix/driver/counter.cc new file mode 100644 index 0000000..17a0f95 --- /dev/null +++ b/src/arch/posix/driver/counter.cc @@ -0,0 +1,3 @@ +#include "driver/counter.h" + +Counter counter; |