[dpdk-dev,v3,1/5] rte_mbuf: add rte_pktmbuf_linearize
diff mbox

Message ID 1483607556-21460-2-git-send-email-tomaszx.kulasek@intel.com
State Superseded, archived
Delegated to: Pablo de Lara Guarch
Headers show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Tomasz Kulasek Jan. 5, 2017, 9:12 a.m. UTC
This patch adds function rte_pktmbuf_linearize to let crypto PMD coalesce
chained mbuf before crypto operation and extend their capabilities to
support segmented mbufs when device cannot handle them natively.

Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
---
 lib/librte_mbuf/rte_mbuf.h |   56 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

Comments

Pablo de Lara Jan. 5, 2017, 3:37 p.m. UTC | #1
Hi Tomasz,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tomasz Kulasek
> Sent: Thursday, January 05, 2017 9:13 AM
> To: dev@dpdk.org
> Subject: [dpdk-dev] [PATCH v3 1/5] rte_mbuf: add rte_pktmbuf_linearize
> 
> This patch adds function rte_pktmbuf_linearize to let crypto PMD coalesce
> chained mbuf before crypto operation and extend their capabilities to
> support segmented mbufs when device cannot handle them natively.
> 
> Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>

Could you separate this patch and patch 2/5 out of this patchset and CC Olivier,
the mbuf maintainer, so it can be better reviewed?
(you can send it as a single patch, both lib and test code)
Then, send another patchset with the other 3 patches,
stating that it depends on that patchset.

Thanks,
Pablo
Tomasz Kulasek Jan. 5, 2017, 4:52 p.m. UTC | #2
Hi Pablo

> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Thursday, January 5, 2017 16:37
> To: Kulasek, TomaszX <tomaszx.kulasek@intel.com>; dev@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH v3 1/5] rte_mbuf: add
> rte_pktmbuf_linearize
> 
> Hi Tomasz,
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Tomasz Kulasek
> > Sent: Thursday, January 05, 2017 9:13 AM
> > To: dev@dpdk.org
> > Subject: [dpdk-dev] [PATCH v3 1/5] rte_mbuf: add rte_pktmbuf_linearize
> >
> > This patch adds function rte_pktmbuf_linearize to let crypto PMD
> coalesce
> > chained mbuf before crypto operation and extend their capabilities to
> > support segmented mbufs when device cannot handle them natively.
> >
> > Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
> 
> Could you separate this patch and patch 2/5 out of this patchset and CC
> Olivier,
> the mbuf maintainer, so it can be better reviewed?
> (you can send it as a single patch, both lib and test code)
> Then, send another patchset with the other 3 patches,
> stating that it depends on that patchset.
> 
> Thanks,
> Pablo

Done.

Tomasz

Patch
diff mbox

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index ead7c6e..b11a31d 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1647,6 +1647,62 @@  static inline int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail
 }
 
 /**
+ * Linearize data in mbuf.
+ *
+ * This function coalesce mbuf merging data in the first segment, unchaining
+ * rest, and then frees them.
+ *
+ * All operations are done in-place, so the structure of incoming mbuf
+ * is changed.
+ *
+ * @param mbuf
+ *   mbuf to linearize
+ * @return
+ *   - 0, on success
+ *   - -1, on error
+ */
+static inline int
+rte_pktmbuf_linearize(struct rte_mbuf *mbuf)
+{
+	int l, n;
+	struct rte_mbuf *m;
+	struct rte_mbuf *m_next;
+	char *buffer;
+
+	if (rte_pktmbuf_is_contiguous(mbuf))
+		return 0;
+
+	/* Extend first segment to the total packet length
+	 */
+	n = rte_pktmbuf_pkt_len(mbuf) - rte_pktmbuf_data_len(mbuf);
+
+	if (unlikely(n > rte_pktmbuf_tailroom(mbuf)))
+		return -1;
+
+	buffer = rte_pktmbuf_mtod_offset(mbuf, char *, mbuf->data_len);
+	mbuf->data_len = (uint16_t)(mbuf->pkt_len);
+
+	/* Append data from next segments to the first one
+	 */
+	m = mbuf->next;
+	while (m != NULL) {
+		m_next = m->next;
+
+		l = rte_pktmbuf_data_len(m);
+		rte_memcpy(buffer, rte_pktmbuf_mtod(m, char *), l);
+		buffer += l;
+
+		rte_pktmbuf_free_seg(m);
+		m = m_next;
+	}
+
+	mbuf->next = NULL;
+	mbuf->nb_segs = 1;
+
+	return 0;
+}
+
+/**
  * Dump an mbuf structure to a file.
  *
  * Dump all fields for the given packet mbuf and all its associated