DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function
@ 2016-10-04 12:05 Maxime Coquelin
  2016-10-04 12:05 ` [dpdk-dev] [PATCH v2 2/2] app/testpmd/txonly: Reset headroom after raw packet allocation Maxime Coquelin
  2016-10-05 12:02 ` [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Olivier Matz
  0 siblings, 2 replies; 3+ messages in thread
From: Maxime Coquelin @ 2016-10-04 12:05 UTC (permalink / raw)
  To: olivier.matz, dev; +Cc: stephen, mst, yuanhan.liu, Maxime Coquelin

Some application use rte_mbuf_raw_alloc() function to improve
performance by not resetting mbuf's fields to their default state.

This can be however problematic for mbuf consumers that need some
headroom, meaning that data_off field gets decremented after
allocation. When the mbuf is re-used afterwards, there might not
be enough room for the consumer to prepend anything, if the data_off
field is not reset to its default value.

This patch adds a new rte_pktmbuf_reset_headroom() function that
applications can call to reset the data_off field.
This patch also replaces current data_off affectations in the mbuf
lib with a call to this function.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
Changes since v2:
=================
 - Specify headroom may be reset only if segment is empty.

 lib/librte_mbuf/rte_mbuf.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h
index 23b7bf8..85a653c 100644
--- a/lib/librte_mbuf/rte_mbuf.h
+++ b/lib/librte_mbuf/rte_mbuf.h
@@ -1387,6 +1387,19 @@ rte_pktmbuf_priv_size(struct rte_mempool *mp)
 }
 
 /**
+ * Reset the data_off field of a packet mbuf to its default value.
+ *
+ * The given mbuf must have only one segment, which should be empty.
+ *
+ * @param m
+ *   The packet mbuf's data_off field has to be reset.
+ */
+static inline void rte_pktmbuf_reset_headroom(struct rte_mbuf *m)
+{
+	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len);
+}
+
+/**
  * Reset the fields of a packet mbuf to their default values.
  *
  * The given mbuf must have only one segment.
@@ -1406,8 +1419,7 @@ static inline void rte_pktmbuf_reset(struct rte_mbuf *m)
 
 	m->ol_flags = 0;
 	m->packet_type = 0;
-	m->data_off = (RTE_PKTMBUF_HEADROOM <= m->buf_len) ?
-			RTE_PKTMBUF_HEADROOM : m->buf_len;
+	rte_pktmbuf_reset_headroom(m);
 
 	m->data_len = 0;
 	__rte_mbuf_sanity_check(m, 1);
@@ -1571,7 +1583,7 @@ static inline void rte_pktmbuf_detach(struct rte_mbuf *m)
 	m->buf_addr = (char *)m + mbuf_size;
 	m->buf_physaddr = rte_mempool_virt2phy(mp, m) + mbuf_size;
 	m->buf_len = (uint16_t)buf_len;
-	m->data_off = RTE_MIN(RTE_PKTMBUF_HEADROOM, (uint16_t)m->buf_len);
+	rte_pktmbuf_reset_headroom(m);
 	m->data_len = 0;
 	m->ol_flags = 0;
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [dpdk-dev] [PATCH v2 2/2] app/testpmd/txonly: Reset headroom after raw packet allocation
  2016-10-04 12:05 [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Maxime Coquelin
@ 2016-10-04 12:05 ` Maxime Coquelin
  2016-10-05 12:02 ` [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Olivier Matz
  1 sibling, 0 replies; 3+ messages in thread
From: Maxime Coquelin @ 2016-10-04 12:05 UTC (permalink / raw)
  To: olivier.matz, dev; +Cc: stephen, mst, yuanhan.liu, Maxime Coquelin

This patch fixes txonly raw packets allocations by resetting the
available headroom.

Indeed, some PMDs such as Virtio might prepend some data to the
packet, resulting in mbuf's data_off field to be decremented each
time the mbuf gets re-allocated.

For Virtio PMD, it means that we use only single descriptors for the
first times mbufs get allocated, as at some point there is not
enough headroom to store the header.

Other alternative would be use standard API to allocate the packets,
which does reset the headroom, but the impact on performance is too
big to consider this an option.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 app/test-pmd/txonly.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c
index d2736b7..8513a06 100644
--- a/app/test-pmd/txonly.c
+++ b/app/test-pmd/txonly.c
@@ -222,6 +222,14 @@ pkt_burst_transmit(struct fwd_stream *fs)
 				return;
 			break;
 		}
+
+		/*
+		 * Using raw alloc is good to improve performance,
+		 * but some consumers may use the headroom and so
+		 * decrement data_off. We need to make sure it is
+		 * reset to default value.
+		 */
+		rte_pktmbuf_reset_headroom(pkt);
 		pkt->data_len = tx_pkt_seg_lengths[0];
 		pkt_seg = pkt;
 		if (tx_pkt_split == TX_PKT_SPLIT_RND)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function
  2016-10-04 12:05 [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Maxime Coquelin
  2016-10-04 12:05 ` [dpdk-dev] [PATCH v2 2/2] app/testpmd/txonly: Reset headroom after raw packet allocation Maxime Coquelin
@ 2016-10-05 12:02 ` Olivier Matz
  1 sibling, 0 replies; 3+ messages in thread
From: Olivier Matz @ 2016-10-05 12:02 UTC (permalink / raw)
  To: Maxime Coquelin, dev; +Cc: stephen, mst, yuanhan.liu

Hi Maxime,

On 10/04/2016 02:05 PM, Maxime Coquelin wrote:
> Some application use rte_mbuf_raw_alloc() function to improve
> performance by not resetting mbuf's fields to their default state.
> 
> This can be however problematic for mbuf consumers that need some
> headroom, meaning that data_off field gets decremented after
> allocation. When the mbuf is re-used afterwards, there might not
> be enough room for the consumer to prepend anything, if the data_off
> field is not reset to its default value.
> 
> This patch adds a new rte_pktmbuf_reset_headroom() function that
> applications can call to reset the data_off field.
> This patch also replaces current data_off affectations in the mbuf
> lib with a call to this function.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Series:

Acked-by: Olivier Matz <olivier.matz@6wind.com>

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-05 12:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-04 12:05 [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Maxime Coquelin
2016-10-04 12:05 ` [dpdk-dev] [PATCH v2 2/2] app/testpmd/txonly: Reset headroom after raw packet allocation Maxime Coquelin
2016-10-05 12:02 ` [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function Olivier Matz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).