[compiler-rt] r299922 - [XRay][compiler-rt] Add support for TSC emulation for x86_64 to xray_fdr_logging.cc

Douglas Yung via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 11 00:45:16 PDT 2017


Author: dyung
Date: Tue Apr 11 02:45:16 2017
New Revision: 299922

URL: http://llvm.org/viewvc/llvm-project?rev=299922&view=rev
Log:
[XRay][compiler-rt] Add support for TSC emulation for x86_64 to xray_fdr_logging.cc

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

Modified:
    compiler-rt/trunk/lib/xray/xray_fdr_logging.cc

Modified: compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/xray/xray_fdr_logging.cc?rev=299922&r1=299921&r2=299922&view=diff
==============================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_logging.cc (original)
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging.cc Tue Apr 11 02:45:16 2017
@@ -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);




More information about the llvm-commits mailing list