[API-NEXT,v1,2/2] linux-gen: pktio: fix recv timeout issue with socket mmap

Message ID 1517922007-6874-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • Fix recv timeout issue with socket mmap
Related show

Commit Message

Github ODP bot Feb. 6, 2018, 1 p.m.
From: Petri Savolainen <petri.savolainen@linaro.org>


Validation test failed sometimes when select returned that
there are packets but sock_mmap_recv did find those (or it
dropped those). Continue timeout wait with select if
sock_mmap_recv didn't find any packets. Select updates
timeout value automatically to reflect the amount of
time not slept.

Fixes https://bugs.linaro.org/show_bug.cgi?id=3615

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 455 (psavol:next-fix-recv-tmo)
 ** https://github.com/Linaro/odp/pull/455
 ** Patch: https://github.com/Linaro/odp/pull/455.patch
 ** Base sha: 1836820278b57de6144c75872e148976d49d28a2
 ** Merge commit sha: 7aa3734cf260df25134c8b302983d3a79cf7c47c
 **/
 platform/linux-generic/pktio/socket_mmap.c | 40 ++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 13 deletions(-)

Patch

diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c
index 04c44bc85..924d8e279 100644
--- a/platform/linux-generic/pktio/socket_mmap.c
+++ b/platform/linux-generic/pktio/socket_mmap.c
@@ -692,10 +692,19 @@  static int sock_mmap_recv_tmo(pktio_entry_t *pktio_entry, int index,
 	FD_ZERO(&readfds);
 	maxfd = sock_mmap_fd_set(pktio_entry, index, &readfds);
 
-	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
-		return 0;
+	while (1) {
+		ret = select(maxfd + 1, &readfds, NULL, NULL, &timeout);
+
+		if (ret <= 0)
+			return ret;
+
+		ret = sock_mmap_recv(pktio_entry, index, pkt_table, num);
+
+		if (ret)
+			return ret;
 
-	return sock_mmap_recv(pktio_entry, index, pkt_table, num);
+		/* If no packets, continue wait until timeout expires */
+	}
 }
 
 static int sock_mmap_recv_mq_tmo(pktio_entry_t *pktio_entry[], int index[],
@@ -729,20 +738,25 @@  static int sock_mmap_recv_mq_tmo(pktio_entry_t *pktio_entry[], int index[],
 	timeout.tv_sec = usecs / (1000 * 1000);
 	timeout.tv_usec = usecs - timeout.tv_sec * (1000ULL * 1000ULL);
 
-	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
-		return 0;
+	while (1) {
+		ret = select(maxfd + 1, &readfds, NULL, NULL, &timeout);
 
-	for (i = 0; i < num_q; i++) {
-		ret = sock_mmap_recv(pktio_entry[i], index[i], pkt_table, num);
+		if (ret <= 0)
+			return ret;
 
-		if (ret > 0 && from)
-			*from = i;
+		for (i = 0; i < num_q; i++) {
+			ret = sock_mmap_recv(pktio_entry[i], index[i],
+					     pkt_table, num);
 
-		if (ret != 0)
-			return ret;
-	}
+			if (ret > 0 && from)
+				*from = i;
 
-	return 0;
+			if (ret)
+				return ret;
+		}
+
+		/* If no packets, continue wait until timeout expires */
+	}
 }
 
 static int sock_mmap_send(pktio_entry_t *pktio_entry, int index ODP_UNUSED,