[XRay][compiler-rt] Add support for TSC emulation for x86_64 to xray_fdr_logging.cc
authorDouglas Yung <douglas.yung@sony.com>
Tue, 11 Apr 2017 07:45:16 +0000 (07:45 +0000)
committerDouglas Yung <douglas.yung@sony.com>
Tue, 11 Apr 2017 07:45:16 +0000 (07:45 +0000)
Previously in r297800, a work-around was created to use TSC emulation on x86_64 when RDTSCP was not available on the host. A similar change was needed in the file xray_fdr_logging.cc which this patch ports over to that file.

Eventually the code should be refactored as there will be 3 locations with the same code, but that can be done as a separate step. This patch is just to keep the test from failing on my machine due to an illegal instruction since RDTSCP is not available on my x86_64 linux VM.

Reviewers: dberris

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D31909

llvm-svn: 299922

compiler-rt/lib/xray/xray_fdr_logging.cc

index ba1a6ab2c51487be48762418d9d74fa64779bdd2..f2ff4076e3c3d3e98623f654ef02a365c354a3c1 100644 (file)
@@ -192,7 +192,21 @@ void fdrLoggingHandleArg0(int32_t FuncId,
   // we've seen this CPU before. We also do it before we load anything else, to
   // allow for forward progress with the scheduling.
   unsigned char CPU;
-  uint64_t TSC = __xray::readTSC(CPU);
+  uint64_t TSC;
+
+  if(probeRequiredCPUFeatures()) {
+    TSC = __xray::readTSC(CPU);
+  } else {
+    // FIXME: This code needs refactoring as it appears in multiple locations
+    timespec TS;
+    int result = clock_gettime(CLOCK_REALTIME, &TS);
+    if (result != 0) {
+      Report("clock_gettime(2) return %d, errno=%d", result, int(errno));
+      TS = {0, 0};
+    }
+    CPU = 0;
+    TSC = TS.tv_sec * __xray::NanosecondsPerSecond + TS.tv_nsec;
+  }
 
   __xray_fdr_internal::processFunctionHook(FuncId, Entry, TSC, CPU,
                                            clock_gettime, LoggingStatus, BQ);