vcl: accept vcl spurious wakeup in epoll wait eventfd
[vpp.git] / src / vcl / ldp.c
index 9e8858f..9e01ac9 100644 (file)
 #define SOCKADDR_GET_SA(__addr) _addr;
 #endif
 
+#ifndef UDP_SEGMENT
+#define UDP_SEGMENT 103
+#endif
+
 typedef struct ldp_worker_ctx_
 {
   u8 *io_buffer;
@@ -155,15 +159,14 @@ ldp_worker_get_current (void)
 static inline void
 ldp_set_app_name (char *app_name)
 {
-  snprintf (ldp->app_name, LDP_APP_NAME_MAX,
-           "ldp-%d-%s", getpid (), app_name);
+  snprintf (ldp->app_name, LDP_APP_NAME_MAX, "%s-ldp-%d", app_name, getpid ());
 }
 
 static inline char *
 ldp_get_app_name ()
 {
   if (ldp->app_name[0] == '\0')
-    ldp_set_app_name ("app");
+    ldp_set_app_name (program_invocation_short_name);
 
   return ldp->app_name;
 }
@@ -328,16 +331,16 @@ close (int fd)
       epfd = vls_attr (vlsh, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0);
       if (epfd > 0)
        {
+         ldp_worker_ctx_t *ldpw = ldp_worker_get_current ();
+         u32 size = sizeof (epfd);
+
          LDBG (0, "fd %d: calling libc_close: epfd %u", fd, epfd);
 
-         rv = libc_close (epfd);
-         if (rv < 0)
-           {
-             u32 size = sizeof (epfd);
-             epfd = 0;
+         libc_close (epfd);
+         ldpw->mq_epfd_added = 0;
 
-             (void) vls_attr (vlsh, VPPCOM_ATTR_SET_LIBC_EPFD, &epfd, &size);
-           }
+         epfd = 0;
+         (void) vls_attr (vlsh, VPPCOM_ATTR_SET_LIBC_EPFD, &epfd, &size);
        }
       else if (PREDICT_FALSE (epfd < 0))
        {
@@ -2564,7 +2567,7 @@ ldp_epoll_pwait_eventfd (int epfd, struct epoll_event *events,
                         int maxevents, int timeout, const sigset_t * sigmask)
 {
   ldp_worker_ctx_t *ldpw;
-  int libc_epfd, rv = 0, num_ev;
+  int libc_epfd, rv = 0, num_ev, vcl_wups = 0;
   vls_handle_t ep_vlsh;
 
   ldp_init_check ();
@@ -2648,6 +2651,7 @@ ldp_epoll_pwait_eventfd (int epfd, struct epoll_event *events,
       goto done;
     }
 
+epoll_again:
   rv = libc_epoll_pwait (libc_epfd, events, maxevents, timeout, sigmask);
   if (rv <= 0)
     goto done;
@@ -2665,6 +2669,9 @@ ldp_epoll_pwait_eventfd (int epfd, struct epoll_event *events,
          num_ev = vls_epoll_wait (ep_vlsh, &events[rv], maxevents - rv, 0);
          if (PREDICT_TRUE (num_ev > 0))
            rv += num_ev;
+         /* Woken up by vcl but no events generated. Accept it once */
+         if (rv == 0 && vcl_wups++ < 1)
+           goto epoll_again;
          break;
        }
     }