Skip to content

Commit

Permalink
issue: 601270 optimize accept() call
Browse files Browse the repository at this point in the history
1. do poll OS only if bound to any address
2. do one CQ poll and go to sleep (unless infinite polling was set)

TODO:
1. do one CQ poll and go to sleep even if infinite polling was set
2. do poll OS only if waken-up by OS fd

Change-Id: Ifab922f1323fca202bf4d09813bd939d38d57161
Signed-off-by: Or Kehati <[email protected]>
  • Loading branch information
orkmellanox committed Sep 8, 2015
1 parent bd94221 commit 03ea953
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/vma/sock/sockinfo_tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2031,7 +2031,8 @@ int sockinfo_tcp::listen(int backlog)
int sockinfo_tcp::accept_helper(struct sockaddr *__addr, socklen_t *__addrlen, int __flags /* = 0 */)
{
sockinfo_tcp *ns;
int poll_count = 0;
//todo do one CQ poll and go to sleep even if infinite polling was set
int poll_count = mce_sys.rx_poll_num; //do one poll and go to sleep (if blocking)
int ret;

si_tcp_logfuncall("");
Expand Down Expand Up @@ -2063,25 +2064,29 @@ int sockinfo_tcp::accept_helper(struct sockaddr *__addr, socklen_t *__addrlen, i
errno = EINVAL;
return -1;
}
// Poll OS socket for pending connection
// smart bit to switch between the two
pollfd os_fd[1];
os_fd[0].fd = m_fd;
os_fd[0].events = POLLIN;
ret = orig_os_api.poll(os_fd, 1, 0); // Zero timeout - just poll and return quickly
if (unlikely(ret == -1)) {
m_p_socket_stats->counters.n_rx_os_errors++;
si_tcp_logdbg("orig_os_api.poll returned with error (errno=%d %m)", errno);
unlock_tcp_con();
return -1;
}
if (ret == 1) {
si_tcp_logdbg("orig_os_api.poll returned with packet");
unlock_tcp_con();
if (__flags)
return orig_os_api.accept4(m_fd, __addr, __addrlen, __flags);
else
return orig_os_api.accept(m_fd, __addr, __addrlen);

//todo instead of doing blind poll, check if waken-up by OS fd in rx_wait
if (m_bound.is_anyaddr()) {
// Poll OS socket for pending connection
// smart bit to switch between the two
pollfd os_fd[1];
os_fd[0].fd = m_fd;
os_fd[0].events = POLLIN;
ret = orig_os_api.poll(os_fd, 1, 0); // Zero timeout - just poll and return quickly
if (unlikely(ret == -1)) {
m_p_socket_stats->counters.n_rx_os_errors++;
si_tcp_logdbg("orig_os_api.poll returned with error (errno=%d %m)", errno);
unlock_tcp_con();
return -1;
}
if (ret == 1) {
si_tcp_logdbg("orig_os_api.poll returned with packet");
unlock_tcp_con();
if (__flags)
return orig_os_api.accept4(m_fd, __addr, __addrlen, __flags);
else
return orig_os_api.accept(m_fd, __addr, __addrlen);
}
}

if (rx_wait(poll_count, m_b_blocking) < 0) {
Expand Down

0 comments on commit 03ea953

Please sign in to comment.