X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvppinfra%2Ftime.h;h=39bc188ebe587075671e93b03494c06966ec8641;hb=ed2fe93fd1ee7bfdad54f323946d76da91aa3398;hp=3b89cf789fedeb2539e66c3521bef0c9bc716d85;hpb=7cd468a3d7dee7d6c92f69a0bb7061ae208ec727;p=vpp.git diff --git a/src/vppinfra/time.h b/src/vppinfra/time.h index 3b89cf789fe..39bc188ebe5 100644 --- a/src/vppinfra/time.h +++ b/src/vppinfra/time.h @@ -114,6 +114,16 @@ clib_cpu_time_now (void) return (u64) lo + ((u64) hi2 << (u64) 32); } +#elif defined (__aarch64__) +always_inline u64 +clib_cpu_time_now (void) +{ + u64 vct; + /* User access to cntvct_el0 is enabled in Linux kernel since 3.12. */ + asm volatile ("mrs %0, cntvct_el0":"=r" (vct)); + return vct; +} + #elif defined (__arm__) #if defined(__ARM_ARCH_8A__) always_inline u64 @@ -164,18 +174,6 @@ clib_cpu_time_now (void) return ((u64) h << 32) | l; } -#elif defined (__aarch64__) -always_inline u64 -clib_cpu_time_now (void) -{ - u64 tsc; - - /* Works on Cavium ThunderX. Other platforms: YMMV */ - asm volatile ("mrs %0, cntvct_el0":"=r" (tsc)); - - return tsc; -} - #else #error "don't know how to read CPU time stamp" @@ -198,6 +196,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) { @@ -242,6 +243,15 @@ unix_time_now_nsec (void) return 1e9 * ts.tv_sec + ts.tv_nsec; } +always_inline void +unix_time_now_nsec_fraction (u32 * sec, u32 * nsec) +{ + struct timespec ts; + syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts); + *sec = ts.tv_sec; + *nsec = ts.tv_nsec; +} + always_inline f64 unix_usage_now (void) { @@ -254,10 +264,12 @@ unix_usage_now (void) always_inline void unix_sleep (f64 dt) { - struct timespec t; - t.tv_sec = dt; - t.tv_nsec = 1e9 * dt; - nanosleep (&t, 0); + struct timespec ts, tsrem; + ts.tv_sec = dt; + ts.tv_nsec = 1e9 * (dt - (f64) ts.tv_sec); + + while (nanosleep (&ts, &tsrem) < 0) + ts = tsrem; } #else /* ! CLIB_UNIX */ @@ -274,6 +286,11 @@ unix_time_now_nsec (void) return 0; } +always_inline void +unix_time_now_nsec_fraction (u32 * sec, u32 * nsec) +{ +} + always_inline f64 unix_usage_now (void) {