X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Ftime.h;h=64370d523bb376cc9b3aaaae1c90f546cbdeb181;hb=a22ba8859a108569b457d18873a52a91f1387a38;hp=ead4b7d8ea4753f94e7768a5b3ef2de3f41ab3ef;hpb=c0379aec241c78fe07074fa7e63a5009a4e7944a;p=vpp.git diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h index ead4b7d8ea4..64370d523bb 100644 --- a/src/vppinfra/time.h +++ b/src/vppinfra/time.h @@ -174,6 +174,16 @@ clib_cpu_time_now (void) return ((u64) h << 32) | l; } +#elif defined(_mips) && __mips == 64 + +always_inline u64 +clib_cpu_time_now (void) +{ + u64 result; + asm volatile ("rdhwr %0,$31\n":"=r" (result)); + return result; +} + #else #error "don't know how to read CPU time stamp" @@ -196,6 +206,9 @@ clib_time_now_internal (clib_time_t * c, u64 n) return t * c->seconds_per_clock; } +/* Maximum f64 value as max clib_time */ +#define CLIB_TIME_MAX (1.7976931348623157e+308) + always_inline f64 clib_time_now (clib_time_t * c) { @@ -224,10 +237,14 @@ void clib_time_init (clib_time_t * c); always_inline f64 unix_time_now (void) { + struct timespec ts; +#ifdef __MACH__ + clock_gettime (CLOCK_REALTIME, &ts); +#else /* clock_gettime without indirect syscall uses GLIBC wrappers which we don't want. Just the bare metal, please. */ - struct timespec ts; syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); +#endif return ts.tv_sec + 1e-9 * ts.tv_nsec; } @@ -236,7 +253,11 @@ always_inline u64 unix_time_now_nsec (void) { struct timespec ts; +#ifdef __MACH__ + clock_gettime (CLOCK_REALTIME, &ts); +#else syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); +#endif return 1e9 * ts.tv_sec + ts.tv_nsec; } @@ -244,7 +265,11 @@ always_inline void unix_time_now_nsec_fraction (u32 * sec, u32 * nsec) { struct timespec ts; +#ifdef __MACH__ + clock_gettime (CLOCK_REALTIME, &ts); +#else syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); +#endif *sec = ts.tv_sec; *nsec = ts.tv_nsec; }