[PATCH] D32067: [XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot determine the CPU frequency
Douglas Yung via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 17 20:37:57 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL300525: [XRay][compiler-rt] Use emulated TSC when CPU supports rdtscp, but cannot… (authored by dyung).
Changed prior to commit:
https://reviews.llvm.org/D32067?vs=95512&id=95525#toc
Repository:
rL LLVM
https://reviews.llvm.org/D32067
Files:
compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
compiler-rt/trunk/lib/xray/xray_inmemory_log.cc
compiler-rt/trunk/lib/xray/xray_x86_64.cc
Index: compiler-rt/trunk/lib/xray/xray_inmemory_log.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_inmemory_log.cc
+++ compiler-rt/trunk/lib/xray/xray_inmemory_log.cc
@@ -79,15 +79,19 @@
int F = getLogFD();
if (F == -1)
return -1;
+
+ // Test for required CPU features and cache the cycle frequency
+ static bool TSCSupported = probeRequiredCPUFeatures();
+ static uint64_t CycleFrequency = TSCSupported ? getTSCFrequency()
+ : __xray::NanosecondsPerSecond;
+
// Since we're here, we get to write the header. We set it up so that the
// header will only be written once, at the start, and let the threads
// logging do writes which just append.
XRayFileHeader Header;
Header.Version = 1;
Header.Type = FileTypes::NAIVE_LOG;
- Header.CycleFrequency = probeRequiredCPUFeatures()
- ? getTSCFrequency()
- : __xray::NanosecondsPerSecond;
+ Header.CycleFrequency = CycleFrequency;
// FIXME: Actually check whether we have 'constant_tsc' and 'nonstop_tsc'
// before setting the values in the header.
Index: compiler-rt/trunk/lib/xray/xray_x86_64.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_x86_64.cc
+++ compiler-rt/trunk/lib/xray/xray_x86_64.cc
@@ -214,6 +214,12 @@
Report("Missing rdtscp support.\n");
return false;
}
+ // Also check whether we can determine the CPU frequency, since if we cannot,
+ // we should use the emulated TSC instead.
+ if (!getTSCFrequency()) {
+ Report("Unable to determine CPU frequency.\n");
+ return false;
+ }
return true;
}
Index: compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
===================================================================
--- compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
+++ compiler-rt/trunk/lib/xray/xray_fdr_logging.cc
@@ -118,11 +118,15 @@
return Result;
}
+ // Test for required CPU features and cache the cycle frequency
+ static bool TSCSupported = probeRequiredCPUFeatures();
+ static uint64_t CycleFrequency = TSCSupported ? getTSCFrequency()
+ : __xray::NanosecondsPerSecond;
+
XRayFileHeader Header;
Header.Version = 1;
Header.Type = FileTypes::FDR_LOG;
- Header.CycleFrequency = probeRequiredCPUFeatures()
- ? getTSCFrequency() : __xray::NanosecondsPerSecond;
+ Header.CycleFrequency = CycleFrequency;
// FIXME: Actually check whether we have 'constant_tsc' and 'nonstop_tsc'
// before setting the values in the header.
Header.ConstantTSC = 1;
@@ -196,7 +200,10 @@
unsigned char CPU;
uint64_t TSC;
- if(probeRequiredCPUFeatures()) {
+ // Test once for required CPU features
+ static bool TSCSupported = probeRequiredCPUFeatures();
+
+ if(TSCSupported) {
TSC = __xray::readTSC(CPU);
} else {
// FIXME: This code needs refactoring as it appears in multiple locations
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32067.95525.patch
Type: text/x-patch
Size: 3033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170418/ac9c7823/attachment.bin>
More information about the llvm-commits
mailing list