Andrew Geissler | 6972109 | 2021-07-23 12:57:00 -0400 | [diff] [blame] | 1 | implement timer for arm >= v6 |
| 2 | |
| 3 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 4 | --- a/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h |
| 5 | +++ b/utilities/transactions/lock/range/range_tree/lib/portability/toku_time.h |
| 6 | @@ -161,6 +161,20 @@ static inline tokutime_t toku_time_now(v |
| 7 | struct timeval tv; |
| 8 | gettimeofday(&tv, nullptr); |
| 9 | return (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
| 10 | +#elif (__ARM_ARCH >= 6) |
| 11 | + uint32_t pmccntr; |
| 12 | + uint32_t pmuseren; |
| 13 | + uint32_t pmcntenset; |
| 14 | + // Read the user mode perf monitor counter access permissions. |
| 15 | + asm volatile("mrc p15, 0, %0, c9, c14, 0" : "=r"(pmuseren)); |
| 16 | + if (pmuseren & 1) { // Allows reading perfmon counters for user mode code. |
| 17 | + asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r"(pmcntenset)); |
| 18 | + if (pmcntenset & 0x80000000ul) { // Is it counting? |
| 19 | + asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(pmccntr)); |
| 20 | + // The counter is set up to count every 64th cycle |
| 21 | + return (uint64_t)pmccntr * 64; // Should optimize to << 6 |
| 22 | + } |
| 23 | + } |
| 24 | #else |
| 25 | #error No timer implementation for this platform |
| 26 | #endif |