ldp: initialize clib time 52/17152/3
authorFlorin Coras <fcoras@cisco.com>
Wed, 30 Jan 2019 05:28:16 +0000 (21:28 -0800)
committerDamjan Marion <dmarion@me.com>
Wed, 30 Jan 2019 09:06:30 +0000 (09:06 +0000)
Change-Id: Ie598443f024a677a9c6938b3f3634960fd712b09
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vcl/ldp.c

index ab4cfbf..f3ac310 100644 (file)
@@ -261,7 +261,12 @@ ldp_init (void)
        }
     }
 
-  clib_time_init (&ldpw->clib_time);
+  /* *INDENT-OFF* */
+  pool_foreach (ldpw, ldp->workers, ({
+    clib_memset (&ldpw->clib_time, 0, sizeof (ldpw->clib_time));
+  }));
+  /* *INDENT-ON* */
+
   LDBG (0, "LDP initialization: done!");
 
   return 0;
@@ -668,6 +673,9 @@ ldp_pselect (int nfds, fd_set * __restrict readfds,
       return -1;
     }
 
+  if (PREDICT_FALSE (ldpw->clib_time.init_cpu_time == 0))
+    clib_time_init (&ldpw->clib_time);
+
   if (timeout)
     {
       time_out = (timeout->tv_sec == 0 && timeout->tv_nsec == 0) ?
@@ -2165,6 +2173,8 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, int maxevents,
       return -1;
     }
 
+  if (PREDICT_FALSE (ldpw->clib_time.init_cpu_time == 0))
+    clib_time_init (&ldpw->clib_time);
   time_to_wait = ((timeout >= 0) ? (double) timeout / 1000 : 0);
   max_time = clib_time_now (&ldpw->clib_time) + time_to_wait;
 
@@ -2232,14 +2242,15 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout)
   int rv, i, n_revents = 0;
   vls_handle_t vlsh;
   vcl_poll_t *vp;
-  double wait_for_time;
+  double max_time;
 
   LDBG (3, "fds %p, nfds %d, timeout %d", fds, nfds, timeout);
 
-  if (timeout >= 0)
-    wait_for_time = (f64) timeout / 1000;
-  else
-    wait_for_time = -1;
+  if (PREDICT_FALSE (ldpw->clib_time.init_cpu_time == 0))
+    clib_time_init (&ldpw->clib_time);
+
+  max_time = (timeout >= 0) ? (f64) timeout / 1000 : 0;
+  max_time += clib_time_now (&ldpw->clib_time);
 
   for (i = 0; i < nfds; i++)
     {
@@ -2299,8 +2310,7 @@ poll (struct pollfd *fds, nfds_t nfds, int timeout)
          goto done;
        }
     }
-  while ((wait_for_time == -1) ||
-        (clib_time_now (&ldpw->clib_time) < wait_for_time));
+  while ((timeout < 0) || (clib_time_now (&ldpw->clib_time) < max_time));
   rv = 0;
 
 done: