CMS 3D CMS Logo

HRRealTime.h

Go to the documentation of this file.
00001 #ifndef  FWCore_Utilities_HRRealTime_H
00002 #define  FWCore_Utilities_HRRealTime_H
00003 /*  
00004  *  High Resolution Real Timer
00005  *  inline high-resolution real timer
00006  *  to be used for precise measurements of performance of
00007  *  "small" chunks of code.  
00008  *
00009  *  returns time in "nominal" cpu-clock unit
00010  *  on most recent hw-architecure it is compensated for clock-rate variations
00011  *  so to get seconds it shall be multiplied for a nominal cpu-clock unit
00012  *  Performance comparison make sense only if the clock-rate has been fixed
00013  */
00014 
00015 namespace edm {
00016   namespace details {
00017     
00018     //
00019     //  defines "rdtsc"
00020     //
00021 #if defined(__i386__)
00022 
00023     static __inline__ unsigned long long rdtsc(void)
00024     {
00025       unsigned long long int x;
00026       __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
00027       return x;
00028     }
00029 #elif defined(__x86_64__)
00030 
00031 
00032     static __inline__ unsigned long long rdtsc(void)
00033     {
00034       unsigned hi, lo;
00035       __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
00036       return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
00037     }
00038 
00039 #elif defined(__powerpc__)
00040 
00041 
00042     static __inline__ unsigned long long rdtsc(void)
00043     {
00044       unsigned long long int result=0;
00045       unsigned long int upper, lower,tmp;
00046       __asm__ volatile(
00047                        "0:                  \n"
00048                        "\tmftbu   %0           \n"
00049                        "\tmftb    %1           \n"
00050                        "\tmftbu   %2           \n"
00051                        "\tcmpw    %2,%0        \n"
00052                        "\tbne     0b         \n"
00053                        : "=r"(upper),"=r"(lower),"=r"(tmp)
00054                        );
00055       result = upper;
00056       result = result<<32;
00057       result = result|lower;
00058       
00059       return(result);
00060     }
00061 #else
00062 #error The file FWCore/Utilities/interface/RealTime.h needs to be set up for your CPU type.
00063 
00064 #endif
00065  }
00066 }
00067 
00068 namespace edm {
00069 
00070   typedef long long int HRTimeDiffType;
00071   typedef unsigned long long int HRTimeType;
00072 
00073   // High Precision real time in clock-units
00074   inline HRTimeType hrRealTime() {
00075     return details::rdtsc();
00076   }
00077 
00078 }
00079 
00080 
00081 #endif //   FWCore_Utilities__HRRealTime_H

Generated on Tue Jun 9 17:36:41 2009 for CMSSW by  doxygen 1.5.4