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