papi: Use CMSG_SPACE for sizing ancillary buffer space
[vpp.git] / src / vppinfra / time.c
index 0b00a11..5a6aaf1 100644 (file)
@@ -74,7 +74,6 @@ clock_frequency_from_proc_filesystem (void)
 {
   f64 cpu_freq = 1e9;          /* better than 40... */
   f64 ppc_timebase = 0;                /* warnings be gone */
-  int fd;
   unformat_input_t input;
 
 /* $$$$ aarch64 kernel doesn't report "cpu MHz" */
@@ -83,26 +82,24 @@ clock_frequency_from_proc_filesystem (void)
 #endif
 
   cpu_freq = 0;
-  fd = open ("/proc/cpuinfo", 0);
-  if (fd < 0)
-    return cpu_freq;
-
-  unformat_init_clib_file (&input, fd);
 
   ppc_timebase = 0;
-  while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
+  if (unformat_init_file (&input, "/proc/cpuinfo"))
     {
-      if (unformat (&input, "cpu MHz : %f", &cpu_freq))
-       cpu_freq *= 1e6;
-      else if (unformat (&input, "timebase : %f", &ppc_timebase))
-       ;
-      else
-       unformat_skip_line (&input);
-    }
-
-  unformat_free (&input);
+      while (unformat_check_input (&input) != UNFORMAT_END_OF_INPUT)
+       {
+         if (unformat (&input, "cpu MHz : %f", &cpu_freq))
+           cpu_freq *= 1e6;
+         else if (unformat (&input, "timebase : %f", &ppc_timebase))
+           ;
+         else
+           unformat_skip_line (&input);
+       }
 
-  close (fd);
+      unformat_free (&input);
+    }
+  else
+    return cpu_freq;
 
   /* Override CPU frequency with time base for PPC. */
   if (ppc_timebase != 0)
@@ -117,25 +114,23 @@ static f64
 clock_frequency_from_sys_filesystem (void)
 {
   f64 cpu_freq = 0.0;
-  int fd;
   unformat_input_t input;
 
   /* Time stamp always runs at max frequency. */
   cpu_freq = 0;
-  fd = open ("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", 0);
-  if (fd < 0)
-    goto done;
-
-  unformat_init_clib_file (&input, fd);
-  (void) unformat (&input, "%f", &cpu_freq);
-  cpu_freq *= 1e3;             /* measured in kHz */
-  unformat_free (&input);
-  close (fd);
-done:
+
+  if (unformat_init_file (
+       &input, "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"))
+    {
+      if (unformat (&input, "%f", &cpu_freq))
+       cpu_freq *= 1e3; /* measured in kHz */
+      unformat_free (&input);
+    }
+
   return cpu_freq;
 }
 
-f64
+__clib_export f64
 os_cpu_clock_frequency (void)
 {
 #if defined (__aarch64__)
@@ -203,7 +198,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,7 +242,7 @@ 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;
@@ -328,7 +323,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 *);