[v19,1/3] linux-generic: pktio: change SLEEP_NSEC into SLEEP_USEC

Message ID 1514678424-26695-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • linux-generic: pktio: genuinely sleep in timeout receive
Related show

Commit Message

Github ODP bot Dec. 31, 2017, midnight
From: Juha-Matti Tilli <juha-matti.tilli@iki.fi>


Change SLEEP_NSEC into SLEEP_USEC and make odp_pktin_wait_time return
always microseconds.

Signed-off-by: Juha-Matti Tilli <juha-matti.tilli@iki.fi>

---
/** Email created from pull request 341 (jmtilli:genuinesleep)
 ** https://github.com/Linaro/odp/pull/341
 ** Patch: https://github.com/Linaro/odp/pull/341.patch
 ** Base sha: 49ebafae0edebbc750742d8874ad0a7588286dea
 ** Merge commit sha: f2f5f1123d2231807e90af3417a2634844b811ee
 **/
 platform/linux-generic/odp_packet_io.c | 44 ++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 20 deletions(-)

Patch

diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c
index ffbc73b26..bb1e61fdc 100644
--- a/platform/linux-generic/odp_packet_io.c
+++ b/platform/linux-generic/odp_packet_io.c
@@ -33,9 +33,9 @@ 
 #include <time.h>
 
 /* Sleep this many nanoseconds between pktin receive calls */
-#define SLEEP_NSEC  1000
+#define SLEEP_USEC  1
 
-/* Check total sleep time about every SLEEP_CHECK * SLEEP_NSEC nanoseconds.
+/* Check total sleep time about every SLEEP_CHECK * SLEEP_USEC microseconds.
  * Must be power of two. */
 #define SLEEP_CHECK 32
 
@@ -1679,9 +1679,10 @@  int odp_pktin_recv_tmo(odp_pktin_queue_t queue, odp_packet_t packets[], int num,
 	odp_time_t t1, t2;
 	struct timespec ts;
 	int started = 0;
+	int i;
 
 	ts.tv_sec  = 0;
-	ts.tv_nsec = SLEEP_NSEC;
+	ts.tv_nsec = 1000 * SLEEP_USEC;
 
 	while (1) {
 		ret = odp_pktin_recv(queue, packets, num);
@@ -1698,21 +1699,22 @@  int odp_pktin_recv_tmo(odp_pktin_queue_t queue, odp_packet_t packets[], int num,
 			if (odp_unlikely(!started)) {
 				odp_time_t t;
 
-				t = odp_time_local_from_ns(wait * SLEEP_NSEC);
+				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 ((wait & (SLEEP_CHECK - 1)) == 0) {
-				t2 = odp_time_local();
+			for (i = 0; i < SLEEP_USEC; i++) {
+				if ((wait & (SLEEP_CHECK - 1)) == 0) {
+					t2 = odp_time_local();
 
-				if (odp_time_cmp(t2, t1) > 0)
-					return 0;
+					if (odp_time_cmp(t2, t1) > 0)
+						return 0;
+				}
+				wait--;
 			}
-
-			wait--;
 		}
 
 		nanosleep(&ts, NULL);
@@ -1730,7 +1732,7 @@  int odp_pktin_recv_mq_tmo(const odp_pktin_queue_t queues[], unsigned num_q,
 	int started = 0;
 
 	ts.tv_sec  = 0;
-	ts.tv_nsec = SLEEP_NSEC;
+	ts.tv_nsec = 1000 * SLEEP_USEC;
 
 	while (1) {
 		for (i = 0; i < num_q; i++) {
@@ -1750,19 +1752,21 @@  int odp_pktin_recv_mq_tmo(const odp_pktin_queue_t queues[], unsigned num_q,
 			if (odp_unlikely(!started)) {
 				odp_time_t t;
 
-				t = odp_time_local_from_ns(wait * SLEEP_NSEC);
+				t = odp_time_local_from_ns(wait * 1000);
 				started = 1;
 				t1 = odp_time_sum(odp_time_local(), t);
 			}
 
-			if ((wait & (SLEEP_CHECK - 1)) == 0) {
-				t2 = odp_time_local();
+			for (i = 0; i < SLEEP_USEC; i++) {
+				if ((wait & (SLEEP_CHECK - 1)) == 0) {
+					t2 = odp_time_local();
 
-				if (odp_time_cmp(t2, t1) > 0)
-					return 0;
-			}
+					if (odp_time_cmp(t2, t1) > 0)
+						return 0;
+				}
 
-			wait--;
+				wait--;
+			}
 		}
 
 		nanosleep(&ts, NULL);
@@ -1774,9 +1778,9 @@  uint64_t odp_pktin_wait_time(uint64_t nsec)
 	if (nsec == 0)
 		return 0;
 
-	/* number of nanosleep calls rounded up by one, so that
+	/* number of microseconds rounded up by one, so that
 	 * recv_mq_tmo call waits at least 'nsec' nanoseconds. */
-	return (nsec / SLEEP_NSEC) + 1;
+	return (nsec / (1000)) + 1;
 }
 
 int odp_pktout_send(odp_pktout_queue_t queue, const odp_packet_t packets[],