vcl: accept vcl spurious wakeup in epoll wait eventfd
[vpp.git] / src / vcl / ldp.c
index 0bb8134..9e01ac9 100644 (file)
@@ -331,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))
        {
@@ -2567,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 ();
@@ -2651,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;
@@ -2668,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;
        }
     }