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);
}
}
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);
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
{
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);
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)
{
getpid (), fd, fd, func_str, sid, sid, buf, n, flags);
size = vppcom_session_sendto (sid, (void *) buf, n, flags, NULL);
- if (size != VPPCOM_OK)
+ if (size < VPPCOM_OK)
{
errno = -size;
size = -1;
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(): "
}
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;
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)
return -1;
}
- time_to_wait = ((timeout >= 0) ? (double) timeout / (double) 1000 : 0);
+ time_to_wait = ((timeout >= 0) ? (double) timeout : 0);
time_out = clib_time_now (&ldp->clib_time) + time_to_wait;
func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
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)
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 ());
}
/* 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 ());
}