CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
25  unsigned long long int x;
26  __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
27  return x;
28  }
29 #elif defined(__x86_64__)
30 
31 
32  static __inline__ unsigned long long rdtsc(void)
33  {
34  unsigned hi, lo;
35  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
36  return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
37  }
38 
39 #elif defined(__powerpc__)
40 
41 
42  static __inline__ unsigned long long rdtsc(void)
43  {
44  unsigned long long int result=0;
45  unsigned long int upper, lower,tmp;
46  __asm__ volatile(
47  "0: \n"
48  "\tmftbu %0 \n"
49  "\tmftb %1 \n"
50  "\tmftbu %2 \n"
51  "\tcmpw %2,%0 \n"
52  "\tbne 0b \n"
53  : "=r"(upper),"=r"(lower),"=r"(tmp)
54  );
55  result = upper;
56  result = result<<32;
57  result = result|lower;
58 
59  return(result);
60  }
61 #elif defined(__arm__)
62 #warning unsigned long long rdtsc(void) is not implemented on ARMv7 architecture. Returning 0 by default.
63  static __inline__ unsigned long long rdtsc(void)
64  {
65  return 0;
66  }
67 #elif defined(__aarch64__)
68 #warning unsigned long long rdtsc(void) is not implemented on ARMv8 (AArch64) architecture. Returning 0 by default.
69  static __inline__ unsigned long long rdtsc(void)
70  {
71  return 0;
72  }
73 #else
74 #error The file FWCore/Utilities/interface/HRRealTime.h needs to be set up for your CPU type.
75 #endif
76  }
77 }
78 
79 namespace edm {
80 
81  typedef long long int HRTimeDiffType;
82  typedef unsigned long long int HRTimeType;
83 
84  // High Precision real time in clock-units
86  return details::rdtsc();
87  }
88 
89 }
90 
91 
92 #endif // FWCore_Utilities__HRRealTime_H
tuple result
Definition: mps_fire.py:95
T x() const
Cartesian x coordinate.
HRTimeType hrRealTime()
Definition: HRRealTime.h:85
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
long long int HRTimeDiffType
Definition: HRRealTime.h:81
unsigned long long int HRTimeType
Definition: HRRealTime.h:82