From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com [209.85.212.176]) by dpdk.org (Postfix) with ESMTP id C7CE9C63C for ; Thu, 30 Jul 2015 18:22:56 +0200 (CEST) Received: by wicmv11 with SMTP id mv11so27605005wic.0 for ; Thu, 30 Jul 2015 09:22:56 -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=8ram/LzKdU616cswDN2iMwCCBMjIfhqclyjx6d7sirs=; b=ehkH9me0yOK1dmMn4pA4YAYWkUOpixBXDLPetZmqDJCR45cerGahxrttj0p1ITavmk l4PHD5SJfmiZNoF/4W4aqaMJZ76tf3t/ApAVG67TKaIzcyOxjPg2Ks+3/CgI9SKuiCBM AHT1Fc8OhauP0DOUaX/7sQOX7bKdAnEQjd3Nqj0XqA+hvUHIdko2ytroK8JxR4U0ldg3 A/7Bl+UQYHqR7Xtt7sfoU4H1/4OovAvUADYKko03MdXp6knLIZ5Yq68ZUaZuvz8MAkib dECSqhumTW0Q++Gv/WvHHVi4obuM3yC/Tw4vvfsLaodKKanf0NNmhXk+ydgCrAb97Pfg 1vgg== X-Gm-Message-State: ALoCoQmkq9W3IXgyVTOMrQTJ6nPLCRqAynakoejrbS1TpKVRX/grVrWAFDXLtzN65UrzZHDQn9T0 X-Received: by 10.194.85.130 with SMTP id h2mr95949755wjz.2.1438273376697; Thu, 30 Jul 2015 09:22:56 -0700 (PDT) Received: from glumotte.dev.6wind.com (6wind.net2.nerim.net. [213.41.151.210]) by smtp.gmail.com with ESMTPSA id ev2sm3793433wib.21.2015.07.30.09.22.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Jul 2015 09:22:56 -0700 (PDT) From: Olivier Matz To: dev@dpdk.org Date: Thu, 30 Jul 2015 18:22:17 +0200 Message-Id: <1438273337-13211-1-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1438264561-18359-1-git-send-email-olivier.matz@6wind.com> References: <1438264561-18359-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v2] mbuf: enforce alignment of mbuf private area 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: , X-List-Received-Date: Thu, 30 Jul 2015 16:22:57 -0000 It looks better to have a data buffer address that is aligned to 8 bytes. This is the case when there is no mbuf private area, but if there is one, the alignment depends on the size of this area that is located between the mbuf structure and the data buffer. Indeed, some drivers expects to have the buffer address aligned to an even address, and moreover an unaligned buffer may impact the performance when accessing to network headers. Add a check in rte_pktmbuf_pool_create() to verify the alignment constraint before creating the mempool. For applications that use the alternative way (direct call to rte_mempool_create), also add an assertion in rte_pktmbuf_init(). By the way, also add the MBUF log type. Signed-off-by: Olivier Matz --- lib/librte_eal/common/include/rte_log.h | 1 + lib/librte_mbuf/rte_mbuf.c | 9 ++++++++- lib/librte_mbuf/rte_mbuf.h | 7 +++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/common/include/rte_log.h index 24a55cc..ede0dca 100644 --- a/lib/librte_eal/common/include/rte_log.h +++ b/lib/librte_eal/common/include/rte_log.h @@ -77,6 +77,7 @@ extern struct rte_logs rte_logs; #define RTE_LOGTYPE_PORT 0x00002000 /**< Log related to port. */ #define RTE_LOGTYPE_TABLE 0x00004000 /**< Log related to table. */ #define RTE_LOGTYPE_PIPELINE 0x00008000 /**< Log related to pipeline. */ +#define RTE_LOGTYPE_MBUF 0x00010000 /**< Log related to mbuf. */ /* these log types can be used in an application */ #define RTE_LOGTYPE_USER1 0x01000000 /**< User-defined log type 1. */ diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index 4320dd4..e416312 100644 --- a/lib/librte_mbuf/rte_mbuf.c +++ b/lib/librte_mbuf/rte_mbuf.c @@ -58,6 +58,7 @@ #include #include #include +#include /* * ctrlmbuf constructor, given as a callback function to @@ -125,6 +126,7 @@ rte_pktmbuf_init(struct rte_mempool *mp, mbuf_size = sizeof(struct rte_mbuf) + priv_size; buf_len = rte_pktmbuf_data_room_size(mp); + RTE_MBUF_ASSERT(RTE_ALIGN(priv_size, RTE_MBUF_PRIV_ALIGN) == priv_size); RTE_MBUF_ASSERT(mp->elt_size >= mbuf_size); RTE_MBUF_ASSERT(buf_len <= UINT16_MAX); @@ -154,7 +156,12 @@ rte_pktmbuf_pool_create(const char *name, unsigned n, struct rte_pktmbuf_pool_private mbp_priv; unsigned elt_size; - + if (RTE_ALIGN(priv_size, RTE_MBUF_PRIV_ALIGN) != priv_size) { + RTE_LOG(ERR, MBUF, "mbuf priv_size=%u is not aligned\n", + priv_size); + rte_errno = EINVAL; + return NULL; + } elt_size = sizeof(struct rte_mbuf) + (unsigned)priv_size + (unsigned)data_room_size; mbp_priv.mbuf_data_room_size = data_room_size; diff --git a/lib/librte_mbuf/rte_mbuf.h b/lib/librte_mbuf/rte_mbuf.h index 010b32d..c3b8c98 100644 --- a/lib/librte_mbuf/rte_mbuf.h +++ b/lib/librte_mbuf/rte_mbuf.h @@ -698,6 +698,9 @@ extern "C" { RTE_PTYPE_INNER_L4_MASK)) #endif /* RTE_NEXT_ABI */ +/** Alignment constraint of mbuf private area. */ +#define RTE_MBUF_PRIV_ALIGN 8 + /** * Get the name of a RX offload flag * @@ -1238,7 +1241,7 @@ void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg); * details. * @param priv_size * Size of application private are between the rte_mbuf structure - * and the data buffer. + * and the data buffer. This value must be aligned to RTE_MBUF_PRIV_ALIGN. * @param data_room_size * Size of data buffer in each mbuf, including RTE_PKTMBUF_HEADROOM. * @param socket_id @@ -1250,7 +1253,7 @@ void rte_pktmbuf_pool_init(struct rte_mempool *mp, void *opaque_arg); * with rte_errno set appropriately. Possible rte_errno values include: * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure * - E_RTE_SECONDARY - function was called from a secondary process instance - * - EINVAL - cache size provided is too large + * - EINVAL - cache size provided is too large, or priv_size is not aligned. * - ENOSPC - the maximum number of memzones has already been allocated * - EEXIST - a memzone with the same name already exists * - ENOMEM - no appropriate memory area found in which to create memzone -- 2.1.4