00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CUFLOW_TIME_H
00019 #define CUFLOW_TIME_H
00020
00021 #include <cuflow/fwd.h>
00022 #include <time.h>
00023
00024 CU_BEGIN_DECLARATIONS
00025
00026 #ifdef CUCONF_HAVE_LIBRT
00027
00028 typedef uint64_t cuflow_cputime_t;
00029 typedef uint64_t cuflow_walltime_t;
00030
00031 #define CUFLOW_CPUTIME_SECOND UINT64_C(1000000000)
00032 #define CUFLOW_WALLTIME_SECOND UINT64_C(1000000000)
00033
00034 CU_SINLINE cuflow_cputime_t cuflow_threadtime(void)
00035 {
00036 struct timespec tv;
00037 clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tv);
00038 return (uint64_t)tv.tv_nsec + UINT64_C(1000000000)*(uint64_t)tv.tv_sec;
00039 }
00040
00041 CU_SINLINE cuflow_walltime_t cuflow_walltime(void)
00042 {
00043 struct timespec tv;
00044 clock_gettime(CLOCK_MONOTONIC, &tv);
00045 return (uint64_t)tv.tv_nsec + UINT64_C(1000000000)*(uint64_t)tv.tv_sec;
00046 }
00047
00048 #else
00049
00050 typedef clock_t cuflow_cputime_t;
00051 typedef uint64_t cuflow_walltime_t;
00052
00053 #define cuflow_threadtime clock
00054
00055 CU_SINLINE cuflow_walltime_t cuflow_walltime(void)
00056 {
00057 struct timeval tv;
00058 gettimeofday(&tv, NULL);
00059 return (uint64_t)tv.tv_usec + UINT64_C(1000000)*(uint64_t)tv.tv_sec;
00060 }
00061
00062 #define CUCONF_CPUTIME_SECOND CLOCKS_PER_SEC
00063 #define CUCONF_WALLTIME_SECOND UINT64_C(1000000)
00064
00065 #endif
00066
00067 cuflow_cputime_t cuflowP_threadtime_granularity;
00068
00069 CU_SINLINE cuflow_cputime_t cuflow_threadtime_granularity(void)
00070 { return cuflowP_threadtime_granularity; }
00071
00072 CU_END_DECLARATIONS
00073
00074 #endif