From patchwork Tue Oct 4 12:05:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 16364 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 455515A33; Tue, 4 Oct 2016 14:05:33 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 5830D2C56 for ; Tue, 4 Oct 2016 14:05:31 +0200 (CEST) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A4D69C04B95C; Tue, 4 Oct 2016 12:05:30 +0000 (UTC) Received: from max-t460s.redhat.com (vpn1-5-203.ams2.redhat.com [10.36.5.203]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u94C5Spl002533; Tue, 4 Oct 2016 08:05:29 -0400 From: Maxime Coquelin To: olivier.matz@6wind.com, dev@dpdk.org Cc: stephen@networkplumber.org, mst@redhat.com, yuanhan.liu@linux.intel.com, Maxime Coquelin Date: Tue, 4 Oct 2016 14:05:23 +0200 Message-Id: <1475582724-5202-1-git-send-email-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 04 Oct 2016 12:05:30 +0000 (UTC) Subject: [dpdk-dev] [PATCH v2 1/2] mbuf: add rte_pktmbuff_reset_headroom function X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 Acked-by: Olivier Matz --- 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;