api: API trace improvements
[vpp.git] / src / vppinfra / time.c
index 27758dc..3377828 100644 (file)
@@ -135,7 +135,7 @@ done:
   return cpu_freq;
 }
 
-f64
+__clib_export f64
 os_cpu_clock_frequency (void)
 {
 #if defined (__aarch64__)
@@ -165,7 +165,7 @@ os_cpu_clock_frequency (void)
 
       clib_get_cpuid (0x15, &eax, &ebx, &ecx, &edx);
       if (ebx && ecx)
-       return ecx * ebx / eax;
+       return (u64) ecx *ebx / eax;
 
       if (max_leaf >= 0x16)
        {
@@ -203,7 +203,7 @@ os_cpu_clock_frequency (void)
 #endif /* CLIB_UNIX */
 
 /* Initialize time. */
-void
+__clib_export void
 clib_time_init (clib_time_t * c)
 {
   clib_memset (c, 0, sizeof (c[0]));
@@ -247,19 +247,36 @@ clib_time_init (clib_time_t * c)
   c->damping_constant = exp (-1.0 / 3.75);
 }
 
-void
+__clib_export void
 clib_time_verify_frequency (clib_time_t * c)
 {
   f64 now_reference, delta_reference, delta_reference_max;
-  u64 delta_clock;
+  f64 delta_clock_in_seconds;
+  u64 now_clock, delta_clock;
   f64 new_clocks_per_second, delta;
 
   /* Ask the kernel and the CPU what time it is... */
   now_reference = unix_time_now ();
-  c->last_cpu_time = clib_cpu_time_now ();
+  now_clock = clib_cpu_time_now ();
 
-  /* Calculate a new clock rate sample */
+  /* Compute change in the reference clock */
   delta_reference = now_reference - c->last_verify_reference_time;
+
+  /* And change in the CPU clock */
+  delta_clock_in_seconds = (f64) (now_clock - c->last_verify_cpu_time) *
+    c->seconds_per_clock;
+
+  /*
+   * Recompute vpp start time reference, and total clocks
+   * using the current clock rate
+   */
+  c->init_reference_time += (delta_reference - delta_clock_in_seconds);
+  c->total_cpu_time = (now_reference - c->init_reference_time)
+    * c->clocks_per_second;
+
+  c->last_cpu_time = now_clock;
+
+  /* Calculate a new clock rate sample */
   delta_clock = c->last_cpu_time - c->last_verify_cpu_time;
 
   c->last_verify_cpu_time = c->last_cpu_time;
@@ -311,7 +328,7 @@ clib_time_verify_frequency (clib_time_t * c)
 }
 
 
-u8 *
+__clib_export u8 *
 format_clib_time (u8 * s, va_list * args)
 {
   clib_time_t *c = va_arg (*args, clib_time_t *);