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