From patchwork Wed Apr 22 09:57:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olivier Matz X-Patchwork-Id: 4425 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 EEC15C364; Wed, 22 Apr 2015 11:57:47 +0200 (CEST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by dpdk.org (Postfix) with ESMTP id 0D7B96A80 for ; Wed, 22 Apr 2015 11:57:45 +0200 (CEST) Received: by widdi4 with SMTP id di4so50923676wid.0 for ; Wed, 22 Apr 2015 02:57:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=69GWWdRahK/A6o7FAnX1eL76fS63TDLC8YTzdWXGZno=; b=kENlXWKoG2Kv4IjMb2IWDL/SSZmsJ/kBqVeaWtiFb+SLydSLAvVN0/aAoe74Z8CGke XXCk062AWGcSUffxzkhKlVOKLVEdxXv8ce2dVOZcDt/jIEzGmKRwQBS148fHkWe0cXoq G3+sorOhCeUw1ywM9RIS1hSoeyztQxE+oOItCUnPRr5S4Cq7Y84DF2K9xLbiJSZehlSF Uos4obUMmYTX5uhiygG26DTlhgR7clVFTiy8Q2d/bDdJ8zqrmnkRtI8yudQNUtYewlt7 WHQAohpNZYNk5Tswf4v4nlvsdPvgZDUu2IZhYmGFzUgxZREr+Ndi818d5RitqBoRp5kf p6/g== X-Gm-Message-State: ALoCoQl/KDiI3W0ivZHxi0Vs8APPi/7veK9evTZ/PYxn8zETFzmtsgr2MdVhWUG5oXHK6ni460tt X-Received: by 10.180.77.83 with SMTP id q19mr4236607wiw.89.1429696664932; Wed, 22 Apr 2015 02:57:44 -0700 (PDT) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.180.237]) by mx.google.com with ESMTPSA id yr1sm6570006wjc.37.2015.04.22.02.57.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 22 Apr 2015 02:57:43 -0700 (PDT) From: Olivier Matz To: dev@dpdk.org Date: Wed, 22 Apr 2015 11:57:18 +0200 Message-Id: <1429696650-9043-2-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1429696650-9043-1-git-send-email-olivier.matz@6wind.com> References: <1429610122-30943-1-git-send-email-olivier.matz@6wind.com> <1429696650-9043-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v6 01/13] mbuf: fix mbuf data room size calculation rte_pktmbuf_pool_init 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" Deduct the mbuf data room size from mempool->elt_size and priv_size, instead of using an hardcoded value that is not related to the real buffer size. To use rte_pktmbuf_pool_init(), the user can either: - give a NULL parameter to rte_pktmbuf_pool_init(): in this case, the private size is assumed to be 0, and the room size is mp->elt_size - sizeof(struct rte_mbuf). - give the rte_pktmbuf_pool_private filled with appropriate data_room_size and priv_size values. Signed-off-by: Olivier Matz Acked-by: Neil Horman --- app/test-pmd/testpmd.c | 1 + doc/guides/rel_notes/updating_apps.rst | 12 ++++++++++++ examples/vhost/main.c | 5 ++--- lib/librte_mbuf/rte_mbuf.c | 27 ++++++++++++++++++++------- lib/librte_mbuf/rte_mbuf.h | 3 ++- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 3057791..10e4347 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -443,6 +443,7 @@ testpmd_mbuf_pool_ctor(struct rte_mempool *mp, mbp_ctor_arg = (struct mbuf_pool_ctor_arg *) opaque_arg; mbp_priv = rte_mempool_get_priv(mp); mbp_priv->mbuf_data_room_size = mbp_ctor_arg->seg_buf_size; + mbp_priv->mbuf_priv_size = 0; } static void diff --git a/doc/guides/rel_notes/updating_apps.rst b/doc/guides/rel_notes/updating_apps.rst index 4dbf268..f513615 100644 --- a/doc/guides/rel_notes/updating_apps.rst +++ b/doc/guides/rel_notes/updating_apps.rst @@ -4,6 +4,18 @@ Updating Applications from Previous Versions Although backward compatibility is being maintained across DPDK releases, code written for previous versions of the DPDK may require some code updates to benefit from performance and user experience enhancements provided in later DPDK releases. +DPDK 2.0 to DPDK 2.1 +-------------------- + +* The second argument of rte_pktmbuf_pool_init(mempool, opaque) is now a + pointer to a struct rte_pktmbuf_pool_private instead of a uint16_t + casted into a pointer. Backward compatibility is preserved when the + argument was NULL which is the majority of use cases, but not if the + opaque pointer was not NULL, as it is not technically feasible. In + this case, the application has to be modified to properly fill a + rte_pktmbuf_pool_private structure and pass it to + rte_pktmbuf_pool_init(). + DPDK 1.7 to DPDK 1.8 -------------------- diff --git a/examples/vhost/main.c b/examples/vhost/main.c index ad10f82..fc73d1e 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -2844,11 +2844,10 @@ static void setup_mempool_tbl(int socket, uint32_t index, char *pool_name, char *ring_name, uint32_t nb_mbuf) { - uint16_t roomsize = VIRTIO_DESCRIPTOR_LEN_ZCP + RTE_PKTMBUF_HEADROOM; vpool_array[index].pool = rte_mempool_create(pool_name, nb_mbuf, MBUF_SIZE_ZCP, MBUF_CACHE_SIZE_ZCP, sizeof(struct rte_pktmbuf_pool_private), - rte_pktmbuf_pool_init, (void *)(uintptr_t)roomsize, + rte_pktmbuf_pool_init, NULL, rte_pktmbuf_init, NULL, socket, 0); if (vpool_array[index].pool != NULL) { vpool_array[index].ring @@ -2870,7 +2869,7 @@ setup_mempool_tbl(int socket, uint32_t index, char *pool_name, } /* Need consider head room. */ - vpool_array[index].buf_size = roomsize - RTE_PKTMBUF_HEADROOM; + vpool_array[index].buf_size = VIRTIO_DESCRIPTOR_LEN_ZCP; } else { rte_exit(EXIT_FAILURE, "mempool_create(%s) failed", pool_name); } diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 526b18d..231cfb8 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -81,17 +81,30 @@ rte_ctrlmbuf_init(struct rte_mempool *mp, void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg) { - struct rte_pktmbuf_pool_private *mbp_priv; + struct rte_pktmbuf_pool_private *user_mbp_priv, *mbp_priv; + struct rte_pktmbuf_pool_private default_mbp_priv; uint16_t roomsz; - mbp_priv = rte_mempool_get_priv(mp); - roomsz = (uint16_t)(uintptr_t)opaque_arg; + RTE_MBUF_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf)); - /* Use default data room size. */ - if (0 == roomsz) - roomsz = 2048 + RTE_PKTMBUF_HEADROOM; + /* if no structure is provided, assume no mbuf private area */ + user_mbp_priv = opaque_arg; + if (user_mbp_priv == NULL) { + default_mbp_priv.mbuf_priv_size = 0; + if (mp->elt_size > sizeof(struct rte_mbuf)) + roomsz = mp->elt_size - sizeof(struct rte_mbuf); + else + roomsz = 0; + default_mbp_priv.mbuf_data_room_size = roomsz; + user_mbp_priv = &default_mbp_priv; + } - mbp_priv->mbuf_data_room_size = roomsz; + RTE_MBUF_ASSERT(mp->elt_size >= sizeof(struct rte_mbuf) + + user_mbp_priv->mbuf_data_room_size + + user_mbp_priv->mbuf_priv_size); + + mbp_priv = rte_mempool_get_priv(mp); + memcpy(mbp_priv, user_mbp_priv, sizeof(*mbp_priv)); } /* diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 45f73c2..13fd626 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -348,7 +348,8 @@ struct rte_mbuf { * appended after the mempool structure (in private data). */ struct rte_pktmbuf_pool_private { - uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf.*/ + uint16_t mbuf_data_room_size; /**< Size of data space in each mbuf. */ + uint16_t mbuf_priv_size; /**< Size of private area in each mbuf. */ }; #ifdef RTE_LIBRTE_MBUF_DEBUG