diff mbox

[v2,3/3] linux-generic: pktio: don't return packet after failed enqueue

Message ID 1462462509-13337-4-git-send-email-zoltan.kiss@linaro.org
State Accepted
Commit 12520b241bee42f61ff062283ef23459596f4426
Headers show

Commit Message

Zoltan Kiss May 5, 2016, 3:35 p.m. UTC
If queue_enq() fails, there is a serious internal error, the packet
should be released instead of passing it back to pktin_poll() for
enqueueing on an another one.
Also return the error if there is any, not just the queue_enq() ones.
If CoS drops the packet, doesn't report it as an error

Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
---

v2:
- rebase
- don't report discards as failure
- add comment

 .../linux-generic/include/odp_packet_io_internal.h |  3 +-
 platform/linux-generic/pktio/dpdk.c                | 10 +++---
 platform/linux-generic/pktio/netmap.c              |  8 ++---
 platform/linux-generic/pktio/pktio_common.c        | 36 +++++++++++++++++-----
 platform/linux-generic/pktio/socket.c              |  9 +++---
 platform/linux-generic/pktio/socket_mmap.c         |  7 ++---
 6 files changed, 46 insertions(+), 27 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h
index de6dab6..7dd578b 100644
--- a/platform/linux-generic/include/odp_packet_io_internal.h
+++ b/platform/linux-generic/include/odp_packet_io_internal.h
@@ -211,8 +211,7 @@  typedef struct pktio_if_ops {
 } pktio_if_ops_t;
 
 int _odp_packet_cls_enq(pktio_entry_t *pktio_entry, const uint8_t *base,
-			uint16_t buf_len, odp_time_t *ts,
-			odp_packet_t *pkt_ret);
+			uint16_t buf_len, odp_time_t *ts);
 
 extern void *pktio_entry_ptr[];
 
diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c
index 5315297..57c7d6e 100644
--- a/platform/linux-generic/pktio/dpdk.c
+++ b/platform/linux-generic/pktio/dpdk.c
@@ -712,10 +712,12 @@  static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry,
 		pkt_len = rte_pktmbuf_pkt_len(mbuf);
 
 		if (pktio_cls_enabled(pktio_entry)) {
-			if (_odp_packet_cls_enq(pktio_entry,
-						(const uint8_t *)buf, pkt_len,
-						ts, &pkt_table[nb_pkts]))
-				nb_pkts++;
+			int ret;
+			ret = _odp_packet_cls_enq(pktio_entry,
+						  (const uint8_t *)buf,
+						  pkt_len, ts);
+			if (ret && ret != -ENOENT)
+				nb_pkts = ret;
 		} else {
 			pkt = packet_alloc(pktio_entry->s.pkt_dpdk.pool,
 					   pkt_len, 1);
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c
index 6065922..3e6a4f0 100644
--- a/platform/linux-generic/pktio/netmap.c
+++ b/platform/linux-generic/pktio/netmap.c
@@ -608,10 +608,10 @@  static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry,
 
 	if (pktio_cls_enabled(pktio_entry)) {
 		ret = _odp_packet_cls_enq(pktio_entry, (const uint8_t *)buf,
-					  len, ts, pkt_out);
-		if (ret)
-			return 0;
-		return -1;
+					  len, ts);
+		if (ret && ret != -ENOENT)
+			return ret;
+		return 0;
 	} else {
 		odp_packet_hdr_t *pkt_hdr;
 
diff --git a/platform/linux-generic/pktio/pktio_common.c b/platform/linux-generic/pktio/pktio_common.c
index 942ea8c..8a01477 100644
--- a/platform/linux-generic/pktio/pktio_common.c
+++ b/platform/linux-generic/pktio/pktio_common.c
@@ -7,10 +7,27 @@ 
 
 #include <odp_packet_io_internal.h>
 #include <odp_classification_internal.h>
+#include <errno.h>
 
+/**
+ * Classify packet, copy it in a odp_packet_t and enqueue to the right queue
+ *
+ * pktio_entry	pktio where it arrived
+ * base		packet data
+ * buf_len	packet length
+ *
+ * Return values:
+ * 0 on success, packet is consumed
+ * -ENOENT CoS dropped the packet
+ * -EFAULT Bug
+ * -EINVAL Config error
+ * -ENOMEM Target CoS pool exhausted
+ *
+ * Note: *base is not released, only pkt if there is an error
+ *
+ */
 int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
-			const uint8_t *base, uint16_t buf_len,
-			odp_time_t *ts, odp_packet_t *pkt_ret)
+			const uint8_t *base, uint16_t buf_len, odp_time_t *ts)
 {
 	cos_t *cos;
 	odp_packet_t pkt;
@@ -25,14 +42,17 @@  int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
 	cos = pktio_select_cos(pktio_entry, base, &src_pkt_hdr);
 
 	/* if No CoS found then drop the packet */
-	if (cos == NULL || cos->s.queue == NULL || cos->s.pool == NULL)
-		return 0;
+	if (cos == NULL)
+		return -EINVAL;
+
+	if (cos->s.queue == NULL || cos->s.pool == NULL)
+		return -EFAULT;
 
 	pool = cos->s.pool->s.pool_hdl;
 
 	pkt = odp_packet_alloc(pool, buf_len);
 	if (odp_unlikely(pkt == ODP_PACKET_INVALID))
-		return 0;
+		return -ENOMEM;
 	pkt_hdr = odp_packet_hdr(pkt);
 
 	copy_packet_parser_metadata(&src_pkt_hdr, pkt_hdr);
@@ -40,7 +60,7 @@  int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
 
 	if (odp_packet_copy_from_mem(pkt, 0, buf_len, base) != 0) {
 		odp_packet_free(pkt);
-		return 0;
+		return -EFAULT;
 	}
 
 	packet_set_ts(pkt_hdr, ts);
@@ -49,8 +69,8 @@  int _odp_packet_cls_enq(pktio_entry_t *pktio_entry,
 	odp_packet_pull_tail(pkt, odp_packet_len(pkt) - buf_len);
 	ret = queue_enq(cos->s.queue, odp_buf_to_hdr((odp_buffer_t)pkt), 0);
 	if (ret < 0) {
-		*pkt_ret = pkt;
-		return 1;
+		odp_packet_free(pkt);
+		return -EFAULT;
 	}
 
 	return 0;
diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c
index 6f06170..a0aa9af 100644
--- a/platform/linux-generic/pktio/socket.c
+++ b/platform/linux-generic/pktio/socket.c
@@ -659,11 +659,10 @@  static int sock_mmsg_recv(pktio_entry_t *pktio_entry,
 							eth_hdr->h_source)))
 				continue;
 
-			ret = _odp_packet_cls_enq(pktio_entry, base,
-						  pkt_len, ts,
-						  &pkt_table[nb_rx]);
-			if (ret)
-				nb_rx++;
+			ret = _odp_packet_cls_enq(pktio_entry, base, pkt_len,
+						  ts);
+			if (ret && ret != -ENOENT)
+				nb_rx = ret;
 		}
 	} else {
 		struct iovec iovecs[ODP_PACKET_SOCKET_MAX_BURST_RX]
diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c
index cbd71ba..4170456 100644
--- a/platform/linux-generic/pktio/socket_mmap.c
+++ b/platform/linux-generic/pktio/socket_mmap.c
@@ -195,10 +195,9 @@  static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry,
 
 		if (pktio_cls_enabled(pktio_entry)) {
 			ret = _odp_packet_cls_enq(pktio_entry, pkt_buf,
-						  pkt_len, ts,
-						  &pkt_table[nb_rx]);
-			if (ret)
-				nb_rx++;
+						  pkt_len, ts);
+			if (ret && ret != -ENOENT)
+				nb_rx = ret;
 		} else {
 			odp_packet_hdr_t *hdr;