VPP-327 Coding standards cleanup for vppinfra
[vpp.git] / vppinfra / vppinfra / time.c
index 9af599a..e62ee86 100644 (file)
 #include <sys/time.h>
 #include <fcntl.h>
 
-/* Not very accurate way of determining cpu clock frequency 
+/* Not very accurate way of determining cpu clock frequency
    for unix.  Better to use /proc/cpuinfo on linux. */
-static f64 estimate_clock_frequency (f64 sample_time)
+static f64
+estimate_clock_frequency (f64 sample_time)
 {
   /* Round to nearest 100KHz. */
   const f64 round_to_units = 100e5;
@@ -70,11 +71,12 @@ static f64 estimate_clock_frequency (f64 sample_time)
 }
 
 /* Fetch cpu frequency via parseing /proc/cpuinfo.
-   Only works for Linux. */ 
-static f64 clock_frequency_from_proc_filesystem (void)
+   Only works for Linux. */
+static f64
+clock_frequency_from_proc_filesystem (void)
 {
-  f64 cpu_freq=1e9;             /* better than 40... */
-  f64 ppc_timebase=0;           /* warnings be gone */
+  f64 cpu_freq = 1e9;          /* better than 40... */
+  f64 ppc_timebase = 0;                /* warnings be gone */
   int fd;
   unformat_input_t input;
 
@@ -82,7 +84,7 @@ static f64 clock_frequency_from_proc_filesystem (void)
 #if defined(__aarch64__)
   return 0.0;
 #endif
-  
+
   cpu_freq = 0;
   fd = open ("/proc/cpuinfo", 0);
   if (fd < 0)
@@ -113,8 +115,9 @@ static f64 clock_frequency_from_proc_filesystem (void)
 }
 
 /* Fetch cpu frequency via reading /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
-   Only works for Linux. */ 
-static f64 clock_frequency_from_sys_filesystem (void)
+   Only works for Linux. */
+static f64
+clock_frequency_from_sys_filesystem (void)
 {
   f64 cpu_freq;
   int fd;
@@ -131,11 +134,12 @@ static f64 clock_frequency_from_sys_filesystem (void)
   cpu_freq *= 1e3;             /* measured in kHz */
   unformat_free (&input);
   close (fd);
- done:
+done:
   return cpu_freq;
 }
 
-f64 os_cpu_clock_frequency (void)
+f64
+os_cpu_clock_frequency (void)
 {
   f64 cpu_freq;
 
@@ -157,7 +161,8 @@ f64 os_cpu_clock_frequency (void)
 #endif /* CLIB_UNIX */
 
 /* Initialize time. */
-void clib_time_init (clib_time_t * c)
+void
+clib_time_init (clib_time_t * c)
 {
   memset (c, 0, sizeof (c[0]));
   c->clocks_per_second = os_cpu_clock_frequency ();
@@ -172,7 +177,8 @@ void clib_time_init (clib_time_t * c)
   c->init_cpu_time = c->last_verify_cpu_time = c->last_cpu_time;
 }
 
-void clib_time_verify_frequency (clib_time_t * c)
+void
+clib_time_verify_frequency (clib_time_t * c)
 {
   f64 now_reference = unix_time_now ();
   f64 dtr = now_reference - c->last_verify_reference_time;
@@ -183,13 +189,13 @@ void clib_time_verify_frequency (clib_time_t * c)
   c->last_verify_cpu_time = c->last_cpu_time;
   c->last_verify_reference_time = now_reference;
 
-  /* 
-   * Is the reported reference interval non-positive, 
-   * or off by a factor of two - or 8 seconds - whichever is larger? 
+  /*
+   * Is the reported reference interval non-positive,
+   * or off by a factor of two - or 8 seconds - whichever is larger?
    * Someone reset the clock behind our back.
    */
-  dtr_max = (f64)(2ULL<<c->log2_clocks_per_frequency_verify) /
-      (f64)(1ULL<<c->log2_clocks_per_second);
+  dtr_max = (f64) (2ULL << c->log2_clocks_per_frequency_verify) /
+    (f64) (1ULL << c->log2_clocks_per_second);
   dtr_max = dtr_max > 8.0 ? dtr_max : 8.0;
 
   if (dtr <= 0.0 || dtr > dtr_max)
@@ -198,10 +204,19 @@ void clib_time_verify_frequency (clib_time_t * c)
       return;
     }
 
-  c->clocks_per_second = flt_round_nearest ((f64) dtc / (dtr * round_units)) * round_units;
+  c->clocks_per_second =
+    flt_round_nearest ((f64) dtc / (dtr * round_units)) * round_units;
   c->seconds_per_clock = 1 / c->clocks_per_second;
 
   /* Double time between verifies; max at 64 secs ~ 1 minute. */
   if (c->log2_clocks_per_frequency_verify < c->log2_clocks_per_second + 6)
     c->log2_clocks_per_frequency_verify += 1;
 }
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */