diff mbox series

[API-NEXT,v6,2/3] linux-generic: pktio: drop support for indefinite waits in recv_tmo

Message ID 1516896022-8965-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v6,1/3] test: validation: drop use of indefinite wait in pktio test | expand

Commit Message

Github ODP bot Jan. 25, 2018, 4 p.m. UTC
From: Bill Fischofer <bill.fischofer@linaro.org>


Drop support for the deprecated ODP_PKTIN_WAIT option on
odp_pktin_recv_tmo() and odp_pktin_recv_mq_tmo()

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
/** Email created from pull request 410 (Bill-Fischofer-Linaro:pktio-dropwait)
 ** https://github.com/Linaro/odp/pull/410
 ** Patch: https://github.com/Linaro/odp/pull/410.patch
 ** Base sha: 44974a09b01c79adb9637a5dff38539598a76737
 ** Merge commit sha: 50db898f5d832f31dfc63c6fc1360a29e700bdb4
 **/
 include/odp/api/abi-default/packet_io.h     |  1 -
 platform/linux-generic/odp_packet_io.c      | 76 +++++++++++++++--------------
 platform/linux-generic/pktio/netmap.c       |  6 +--
 platform/linux-generic/pktio/pktio_common.c |  3 +-
 platform/linux-generic/pktio/socket.c       |  6 +--
 platform/linux-generic/pktio/socket_mmap.c  |  6 +--
 6 files changed, 46 insertions(+), 52 deletions(-)
diff mbox series

Patch

diff --git a/include/odp/api/abi-default/packet_io.h b/include/odp/api/abi-default/packet_io.h
index 4795f8fc3..7cd3edd75 100644
--- a/include/odp/api/abi-default/packet_io.h
+++ b/include/odp/api/abi-default/packet_io.h
@@ -46,7 +46,6 @@  typedef struct odp_pktout_queue_t {
 #define ODP_PKTIO_MACADDR_MAXSIZE 16
 
 #define ODP_PKTIN_NO_WAIT 0
-#define ODP_PKTIN_WAIT    UINT64_MAX
 
 /**
  * @}
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index 095f6be12..21236f799 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -40,6 +40,9 @@ 
  * Must be power of two. */
 #define SLEEP_CHECK 32
 
+/* Max wait time supported to avoid potential overflow */
+#define MAX_WAIT_TIME (UINT64_MAX / 1024)
+
 static pktio_table_t *pktio_tbl;
 
 /* pktio pointer entries ( for inlines) */
@@ -1699,33 +1702,31 @@  int odp_pktin_recv_tmo(odp_pktin_queue_t queue, odp_packet_t packets[], int num,
 	while (1) {
 		ret = entry->s.ops->recv(entry, queue.index, packets, num);
 
-		if (ret != 0)
+		if (ret != 0 || wait == 0)
 			return ret;
 
-		if (wait == 0)
-			return 0;
-
-		if (wait != ODP_PKTIN_WAIT) {
-			/* Avoid unnecessary system calls. Record the start time
-			 * only when needed and after the first call to recv. */
-			if (odp_unlikely(!started)) {
-				odp_time_t t;
-
-				t = odp_time_local_from_ns(wait * 1000);
-				started = 1;
-				t1 = odp_time_sum(odp_time_local(), t);
-			}
+		/* Avoid unnecessary system calls. Record the start time
+		 * only when needed and after the first call to recv. */
+		if (odp_unlikely(!started)) {
+			odp_time_t t;
+
+			/* Avoid overflow issues for large wait times */
+			if (wait > MAX_WAIT_TIME)
+				wait = MAX_WAIT_TIME;
+			t = odp_time_local_from_ns(wait * 1000);
+			started = 1;
+			t1 = odp_time_sum(odp_time_local(), t);
+		}
 
-			/* Check every SLEEP_CHECK rounds if total wait time
-			 * has been exceeded. */
-			if ((++sleep_round & (SLEEP_CHECK - 1)) == 0) {
-				t2 = odp_time_local();
+		/* Check every SLEEP_CHECK rounds if total wait time
+		 * has been exceeded. */
+		if ((++sleep_round & (SLEEP_CHECK - 1)) == 0) {
+			t2 = odp_time_local();
 
-				if (odp_time_cmp(t2, t1) > 0)
-					return 0;
-			}
-			wait = wait > SLEEP_USEC ? wait - SLEEP_USEC : 0;
+			if (odp_time_cmp(t2, t1) > 0)
+				return 0;
 		}
+		wait = wait > SLEEP_USEC ? wait - SLEEP_USEC : 0;
 
 		nanosleep(&ts, NULL);
 	}
@@ -1779,25 +1780,26 @@  int odp_pktin_recv_mq_tmo(const odp_pktin_queue_t queues[], unsigned num_q,
 		if (wait == 0)
 			return 0;
 
-		if (wait != ODP_PKTIN_WAIT) {
-			if (odp_unlikely(!started)) {
-				odp_time_t t;
+		if (odp_unlikely(!started)) {
+			odp_time_t t;
 
-				t = odp_time_local_from_ns(wait * 1000);
-				started = 1;
-				t1 = odp_time_sum(odp_time_local(), t);
-			}
+			/* Avoid overflow issues for large wait times */
+			if (wait > MAX_WAIT_TIME)
+				wait = MAX_WAIT_TIME;
+			t = odp_time_local_from_ns(wait * 1000);
+			started = 1;
+			t1 = odp_time_sum(odp_time_local(), t);
+		}
 
-			/* Check every SLEEP_CHECK rounds if total wait time
-			 * has been exceeded. */
-			if ((++sleep_round & (SLEEP_CHECK - 1)) == 0) {
-				t2 = odp_time_local();
+		/* Check every SLEEP_CHECK rounds if total wait time
+		 * has been exceeded. */
+		if ((++sleep_round & (SLEEP_CHECK - 1)) == 0) {
+			t2 = odp_time_local();
 
-				if (odp_time_cmp(t2, t1) > 0)
-					return 0;
-			}
-			wait = wait > SLEEP_USEC ? wait - SLEEP_USEC : 0;
+			if (odp_time_cmp(t2, t1) > 0)
+				return 0;
 		}
+		wait = wait > SLEEP_USEC ? wait - SLEEP_USEC : 0;
 
 		nanosleep(&ts, NULL);
 	}
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index 7200ceea8..bbd0d6cdf 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -834,8 +834,7 @@  static int netmap_recv_tmo(pktio_entry_t *pktio_entry, int index,
 	FD_ZERO(&readfds);
 	maxfd = netmap_fd_set(pktio_entry, index, &readfds);
 
-	if (select(maxfd + 1, &readfds, NULL, NULL,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	return netmap_recv(pktio_entry, index, pkt_table, num);
@@ -872,8 +871,7 @@  static int netmap_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,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	for (i = 0; i < num_q; i++) {
diff --git a/platform/linux-generic/pktio/pktio_common.c b/platform/linux-generic/pktio/pktio_common.c
index f6fb4a73d..c7a1c3ab9 100644
--- a/platform/linux-generic/pktio/pktio_common.c
+++ b/platform/linux-generic/pktio/pktio_common.c
@@ -107,8 +107,7 @@  static int sock_recv_mq_tmo_select(pktio_entry_t * const *entry,
 	timeout.tv_sec = usecs / (1000 * 1000);
 	timeout.tv_usec = usecs - timeout.tv_sec * (1000ULL * 1000ULL);
 
-	if (select(maxfd + 1, readfds, NULL, NULL,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	for (i = 0; i < num_q; i++) {
diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index 2d0296b8a..5abf05e34 100644
--- a/platform/linux-generic/pktio/socket.c
+++ b/platform/linux-generic/pktio/socket.c
@@ -726,8 +726,7 @@  static int sock_recv_tmo(pktio_entry_t *pktio_entry, int index,
 	FD_ZERO(&readfds);
 	maxfd = sock_fd_set(pktio_entry, index, &readfds);
 
-	if (select(maxfd + 1, &readfds, NULL, NULL,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	return sock_mmsg_recv(pktio_entry, index, pkt_table, num);
@@ -764,8 +763,7 @@  static int sock_recv_mq_tmo(pktio_entry_t *pktio_entry[], int index[],
 			maxfd = maxfd2;
 	}
 
-	if (select(maxfd + 1, &readfds, NULL, NULL,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	for (i = 0; i < num_q; i++) {
diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c
index f16670960..04c44bc85 100644
--- a/platform/linux-generic/pktio/socket_mmap.c
+++ b/platform/linux-generic/pktio/socket_mmap.c
@@ -692,8 +692,7 @@  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,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	return sock_mmap_recv(pktio_entry, index, pkt_table, num);
@@ -730,8 +729,7 @@  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,
-		   usecs == ODP_PKTIN_WAIT ? NULL : &timeout) == 0)
+	if (select(maxfd + 1, &readfds, NULL, NULL, &timeout) == 0)
 		return 0;
 
 	for (i = 0; i < num_q; i++) {