X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fldp.c;h=d31cd2cabd48920d62d8f0f5a348d809812a0e40;hb=3f2dd30b0bf7cf3d82c720d5065178c1fa628c6b;hp=1cf2445f4fcfde63994747713aaf858f12a40593;hpb=2a8652701d0ce7185c60cc05e407950e87a6c150;p=vpp.git diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c index 1cf2445f4fc..d31cd2cabd4 100644 --- a/src/vcl/ldp.c +++ b/src/vcl/ldp.c @@ -144,9 +144,10 @@ ldp_init (void) else { ldp->debug = tmp; - clib_warning ("LDP<%d>: configured LDP debug level (%u) " - "from the env var " LDP_ENV_DEBUG "!", - getpid (), ldp->debug); + if (LDP_DEBUG > 0) + clib_warning ("LDP<%d>: configured LDP debug level (%u) " + "from the env var " LDP_ENV_DEBUG "!", + getpid (), ldp->debug); } } @@ -154,9 +155,10 @@ ldp_init (void) if (env_var_str) { ldp_set_app_name (env_var_str); - clib_warning ("LDP<%d>: configured LDP app name (%s) " - "from the env var " LDP_ENV_APP_NAME "!", - getpid (), ldp->app_name); + if (LDP_DEBUG > 0) + clib_warning ("LDP<%d>: configured LDP app name (%s) " + "from the env var " LDP_ENV_APP_NAME "!", + getpid (), ldp->app_name); } env_var_str = getenv (LDP_ENV_SID_BIT); @@ -203,15 +205,17 @@ ldp_init (void) ldp->sid_bit_val = (1 << sb); ldp->sid_bit_mask = ldp->sid_bit_val - 1; - clib_warning ("LDP<%d>: configured LDP sid bit (%u) " - "from " LDP_ENV_SID_BIT - "! sid bit value %d (0x%x)", getpid (), - sb, ldp->sid_bit_val, ldp->sid_bit_val); + if (LDP_DEBUG > 0) + clib_warning ("LDP<%d>: configured LDP sid bit (%u) " + "from " LDP_ENV_SID_BIT + "! sid bit value %d (0x%x)", getpid (), + sb, ldp->sid_bit_val, ldp->sid_bit_val); } } clib_time_init (&ldp->clib_time); - clib_warning ("LDP<%d>: LDP initialization: done!", getpid ()); + if (LDP_DEBUG > 0) + clib_warning ("LDP<%d>: LDP initialization: done!", getpid ()); } else { @@ -792,43 +796,17 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, return -1; } - if (nfds <= ldp->sid_bit_val) - { - func_str = "libc_pselect"; - - if (LDP_DEBUG > 3) - clib_warning - ("LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, " - "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds, - readfds, writefds, exceptfds, timeout, sigmask); - - rv = libc_pselect (nfds, readfds, writefds, exceptfds, - timeout, sigmask); - goto done; - } - - if (PREDICT_FALSE (ldp->sid_bit_val > FD_SETSIZE / 2)) - { - clib_warning ("LDP<%d>: ERROR: LDP sid bit value %d (0x%x) > " - "FD_SETSIZE/2 %d (0x%x)!", getpid (), - ldp->sid_bit_val, ldp->sid_bit_val, - FD_SETSIZE / 2, FD_SETSIZE / 2); - errno = EOVERFLOW; - return -1; - } - if (timeout) { time_out = (timeout->tv_sec == 0 && timeout->tv_nsec == 0) ? (f64) 0 : (f64) timeout->tv_sec + - (f64) timeout->tv_nsec / (f64) 1000000000 + - (f64) (timeout->tv_nsec % 1000000000) / (f64) 1000000000; + (f64) timeout->tv_nsec / (f64) 1000000000; /* select as fine grained sleep */ if (!nfds) { if (LDP_DEBUG > 3) - clib_warning ("LDP<%d>: sleeping for %f seconds", + clib_warning ("LDP<%d>: sleeping for %.02f seconds", getpid (), time_out); time_out += clib_time_now (&ldp->clib_time); @@ -845,6 +823,32 @@ ldp_pselect (int nfds, fd_set * __restrict readfds, else time_out = -1; + + if (nfds <= ldp->sid_bit_val) + { + func_str = "libc_pselect"; + + if (LDP_DEBUG > 3) + clib_warning + ("LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, " + "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds, + readfds, writefds, exceptfds, timeout, sigmask); + + rv = libc_pselect (nfds, readfds, writefds, exceptfds, + timeout, sigmask); + goto done; + } + + if (PREDICT_FALSE (ldp->sid_bit_val > FD_SETSIZE / 2)) + { + clib_warning ("LDP<%d>: ERROR: LDP sid bit value %d (0x%x) > " + "FD_SETSIZE/2 %d (0x%x)!", getpid (), + ldp->sid_bit_val, ldp->sid_bit_val, + FD_SETSIZE / 2, FD_SETSIZE / 2); + errno = EOVERFLOW; + return -1; + } + sid_bits = libc_bits = 0; if (readfds) { @@ -3010,13 +3014,18 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) if ((errno = -ldp_init ())) return -1; - if (vep_idx != INVALID_SESSION_ID) + if (PREDICT_TRUE (vep_idx != INVALID_SESSION_ID)) { u32 sid = ldp_sid_from_fd (fd); + if (LDP_DEBUG > 1) + clib_warning ("LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x), " + "sid %d (0x%x)", getpid (), epfd, epfd, + vep_idx, vep_idx, sid, sid); + if (sid != INVALID_SESSION_ID) { - func_str = "vppcom_epoll_create"; + func_str = "vppcom_epoll_ctl"; if (LDP_DEBUG > 1) clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): " @@ -3033,30 +3042,45 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) } else { - int epfd; + int libc_epfd; u32 size = sizeof (epfd); func_str = "vppcom_session_attr[GET_LIBC_EPFD]"; - epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, - 0, 0); - if (!epfd) + libc_epfd = vppcom_session_attr (vep_idx, + VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0); + if (LDP_DEBUG > 1) + clib_warning ("LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x): " + "%s() returned libc_epfd %d (0x%x)", + getpid (), epfd, epfd, vep_idx, vep_idx, + func_str, libc_epfd, libc_epfd); + + if (!libc_epfd) { func_str = "libc_epoll_create1"; if (LDP_DEBUG > 1) - clib_warning ("LDP<%d>: calling %s(): EPOLL_CLOEXEC", - getpid (), func_str); + clib_warning ("LDP<%d>: epfd %d (0x%x), vep_idx %d (0x%x): " + "calling %s(): EPOLL_CLOEXEC", + getpid (), epfd, epfd, vep_idx, vep_idx, + func_str); - epfd = libc_epoll_create1 (EPOLL_CLOEXEC); - if (epfd < 0) + libc_epfd = libc_epoll_create1 (EPOLL_CLOEXEC); + if (libc_epfd < 0) { - rv = epfd; + rv = libc_epfd; goto done; } func_str = "vppcom_session_attr[SET_LIBC_EPFD]"; + if (LDP_DEBUG > 1) + clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): " + "vep_idx %d (0x%x), VPPCOM_ATTR_SET_LIBC_EPFD, " + "libc_epfd %d (0x%x), size %d", + getpid (), epfd, epfd, func_str, + vep_idx, vep_idx, libc_epfd, libc_epfd, size); + rv = vppcom_session_attr (vep_idx, VPPCOM_ATTR_SET_LIBC_EPFD, - &epfd, &size); + &libc_epfd, &size); if (rv < 0) { errno = -rv; @@ -3064,18 +3088,32 @@ epoll_ctl (int epfd, int op, int fd, struct epoll_event *event) goto done; } } - else if (PREDICT_FALSE (epfd < 0)) + else if (PREDICT_FALSE (libc_epfd < 0)) { errno = -epfd; rv = -1; goto done; } - rv = libc_epoll_ctl (epfd, op, fd, event); + func_str = "libc_epoll_ctl"; + + if (LDP_DEBUG > 1) + clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): " + "libc_epfd %d (0x%x), op %d, " + "fd %d (0x%x), event %p", + getpid (), epfd, epfd, func_str, + libc_epfd, libc_epfd, op, fd, fd, event); + + rv = libc_epoll_ctl (libc_epfd, op, fd, event); } } else { + /* The LDP epoll_create1 always creates VCL epfd's. + * The app should never have a kernel base epoll fd unless it + * was acquired outside of the LD_PRELOAD process context. + * In any case, if we get one, punt it to libc_epoll_ctl. + */ func_str = "libc_epoll_ctl"; if (LDP_DEBUG > 1) @@ -3148,9 +3186,10 @@ ldp_epoll_pwait (int epfd, struct epoll_event *events, if (LDP_DEBUG > 2) clib_warning ("LDP<%d>: epfd %d (0x%x): vep_idx %d (0x%x), " "libc_epfd %d (0x%x), events %p, maxevents %d, " - "timeout %d, sigmask %p", getpid (), epfd, epfd, - vep_idx, vep_idx, libc_epfd, libc_epfd, events, - maxevents, timeout, sigmask); + "timeout %d, sigmask %p: time_to_wait %.02f", + getpid (), epfd, epfd, vep_idx, vep_idx, + libc_epfd, libc_epfd, events, maxevents, timeout, + sigmask, time_to_wait, time_out); do { if (!ldp->epoll_wait_vcl) @@ -3413,7 +3452,7 @@ ldp_constructor (void) if (ldp_init () != 0) fprintf (stderr, "\nLDP<%d>: ERROR: ldp_constructor: failed!\n", getpid ()); - else + else if (LDP_DEBUG > 0) clib_warning ("LDP<%d>: LDP constructor: done!\n", getpid ()); } @@ -3433,8 +3472,9 @@ ldp_destructor (void) /* Don't use clib_warning() here because that calls writev() * which will call ldp_init(). */ - printf ("%s:%d: LDP<%d>: LDP destructor: done!\n", - __func__, __LINE__, getpid ()); + if (LDP_DEBUG > 0) + printf ("%s:%d: LDP<%d>: LDP destructor: done!\n", + __func__, __LINE__, getpid ()); }