CMS 3D CMS Logo

HRRealTime.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_HRRealTime_H
2 #define FWCore_Utilities_HRRealTime_H
3 /*
4  * High Resolution Real Timer
5  * inline high-resolution real timer
6  * to be used for precise measurements of performance of
7  * "small" chunks of code.
8  *
9  * returns time in "nominal" cpu-clock unit
10  * on most recent hw-architecure it is compensated for clock-rate variations
11  * so to get seconds it shall be multiplied for a nominal cpu-clock unit
12  * Performance comparison make sense only if the clock-rate has been fixed
13  */
14 
15 namespace edm {
16  namespace details {
17 
18  //
19  // defines "rdtsc"
20  //
21 #if defined(__i386__)
22 
23  static __inline__ unsigned long long rdtsc(void) {
24  unsigned long long int x;
25  __asm__ volatile(".byte 0x0f, 0x31" : "=A"(x));
26  return x;
27  }
28 #elif defined(__x86_64__)
29 
30  static __inline__ unsigned long long rdtsc(void) {
31  unsigned hi, lo;
32  __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
33  return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
34  }
35 
36 #elif defined(__powerpc__)
37 
38  static __inline__ unsigned long long rdtsc(void) {
39  unsigned long long int result = 0;
40  unsigned long int upper, lower, tmp;
41  __asm__ volatile(
42  "0: \n"
43  "\tmftbu %0 \n"
44  "\tmftb %1 \n"
45  "\tmftbu %2 \n"
46  "\tcmpw %2,%0 \n"
47  "\tbne 0b \n"
48  : "=r"(upper), "=r"(lower), "=r"(tmp));
49  result = upper;
50  result = result << 32;
51  result = result | lower;
52 
53  return (result);
54  }
55 #elif defined(__arm__)
56 #warning unsigned long long rdtsc(void) is not implemented on ARMv7 architecture. Returning 0 by default.
57  static __inline__ unsigned long long rdtsc(void) { return 0; }
58 #elif defined(__aarch64__)
59  static __inline__ unsigned long long rdtsc(void) {
60  // We will be reading CNTVCT_EL0 (the virtual counter), which is prepared for us by OS.
61  // The system counter sits outside multiprocessor in SOC and runs on a different frequency.
62  // Increments at a fixed frequency, typically in the range 1-50MHz.
63  // Applications can figure out system counter configuration via CNTFRQ_EL0.
64  //
65  // Notice:
66  // Reads of CNTVCT_EL0 can occur speculatively and out of order relative to other
67  // instructions executed on the same PE.
68  // For example, if a read from memory is used to obtain a signal from another agent
69  // that indicates that CNTVCT_EL0 must be read, an ISB is used to ensure that the
70  // read of CNTVCT_EL0 occurs after the signal has been read from memory
71  //
72  // More details:
73  // Chapter D6: The Generic Timer in AArch64 state
74  // ARM DDI 0487B.a, ID033117 (file: DDI0487B_a_armv8_arm.pdf)
75  unsigned long long ret; // unsigned 64-bit value
76  __asm__ __volatile__("isb; mrs %0, cntvct_el0" : "=r"(ret));
77  return ret;
78  }
79 #else
80 #error The file FWCore/Utilities/interface/HRRealTime.h needs to be set up for your CPU type.
81 #endif
82  } // namespace details
83 } // namespace edm
84 
85 namespace edm {
86 
87  typedef long long int HRTimeDiffType;
88  typedef unsigned long long int HRTimeType;
89 
90  // High Precision real time in clock-units
91  inline HRTimeType hrRealTime() { return details::rdtsc(); }
92 
93 } // namespace edm
94 
95 #endif // FWCore_Utilities__HRRealTime_H
Definition: helper.h:68
HRTimeType hrRealTime()
Definition: HRRealTime.h:91
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
HLT enums.
long long int HRTimeDiffType
Definition: HRRealTime.h:87
unsigned long long int HRTimeType
Definition: HRRealTime.h:88