From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 9CC6DC634 for ; Thu, 30 Jul 2015 16:13:16 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 30 Jul 2015 07:13:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,577,1432623600"; d="scan'208";a="773270938" Received: from irsmsx106.ger.corp.intel.com ([163.33.3.31]) by fmsmga002.fm.intel.com with ESMTP; 30 Jul 2015 07:13:14 -0700 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.223]) by IRSMSX106.ger.corp.intel.com ([169.254.8.137]) with mapi id 14.03.0224.002; Thu, 30 Jul 2015 15:13:13 +0100 From: "Ananyev, Konstantin" To: Olivier Matz Thread-Topic: [PATCH] mbuf: enforce alignment of mbuf private area Thread-Index: AQHQys+vRwZLBGxbZUufkYO22WwAiZ30DIgA Date: Thu, 30 Jul 2015 14:13:12 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725836A6B237@irsmsx105.ger.corp.intel.com> References: <1682615.eOc1hvvtSx@xps13> <1438264561-18359-1-git-send-email-olivier.matz@6wind.com> In-Reply-To: <1438264561-18359-1-git-send-email-olivier.matz@6wind.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH] 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 14:13:17 -0000 Hi Olivier, If fails to compile for me: /local/kananye1/dpdk.org-mbprv1/lib/librte_mbuf/rte_mbuf.c: In function =E2= rte_pktmbuf_pool_create=E2: /local/kananye1/dpdk.org-mbprv1/lib/librte_mbuf/rte_mbuf.c:161:3: error: = =E2rte_errno=E2 undeclared (first use in this function) rte_errno =3D EINVAL; ^ /local/kananye1/dpdk.org-mbprv1/lib/librte_mbuf/rte_mbuf.c:161:3: note: eac= h undeclared identifier is reported only once for each function it appears = in I had to add: diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c index a1ddbb3..04344c0 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 Apart from that - looks good to me. Konstantin =20 > -----Original Message----- > From: Olivier Matz [mailto:olivier.matz@6wind.com] > Sent: Thursday, July 30, 2015 2:56 PM > To: dev@dpdk.org > Cc: Ananyev, Konstantin; olivier.matz@6wind.com; Zhang, Helin; martin.wei= ser@allegro-packets.com; thomas.monjalon@6wind.com > Subject: [PATCH] mbuf: enforce alignment of mbuf private area >=20 > 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. >=20 > 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. >=20 > 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(). >=20 > By the way, also add the MBUF log type. >=20 > Signed-off-by: Olivier Matz > --- > lib/librte_eal/common/include/rte_log.h | 1 + > lib/librte_mbuf/rte_mbuf.c | 8 +++++++- > lib/librte_mbuf/rte_mbuf.h | 7 +++++-- > 3 files changed, 13 insertions(+), 3 deletions(-) >=20 > diff --git a/lib/librte_eal/common/include/rte_log.h b/lib/librte_eal/com= mon/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. */ >=20 > /* 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..a1ddbb3 100644 > --- a/lib/librte_mbuf/rte_mbuf.c > +++ b/lib/librte_mbuf/rte_mbuf.c > @@ -125,6 +125,7 @@ rte_pktmbuf_init(struct rte_mempool *mp, > mbuf_size =3D sizeof(struct rte_mbuf) + priv_size; > buf_len =3D rte_pktmbuf_data_room_size(mp); >=20 > + RTE_MBUF_ASSERT((priv_size & (RTE_MBUF_PRIV_ALIGN - 1)) =3D=3D 0); > RTE_MBUF_ASSERT(mp->elt_size >=3D mbuf_size); > RTE_MBUF_ASSERT(buf_len <=3D UINT16_MAX); >=20 > @@ -154,7 +155,12 @@ rte_pktmbuf_pool_create(const char *name, unsigned n= , > struct rte_pktmbuf_pool_private mbp_priv; > unsigned elt_size; >=20 > - > + if ((priv_size & (RTE_MBUF_PRIV_ALIGN - 1)) !=3D 0) { > + RTE_LOG(ERR, MBUF, "mbuf priv_size=3D%u is not aligned\n", > + priv_size); > + rte_errno =3D EINVAL; > + return NULL; > + } > elt_size =3D sizeof(struct rte_mbuf) + (unsigned)priv_size + > (unsigned)data_room_size; > mbp_priv.mbuf_data_room_size =3D 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 */ >=20 > +/** 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_AL= IGN. > * @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 s= tructure > * - E_RTE_SECONDARY - function was called from a secondary process i= nstance > - * - EINVAL - cache size provided is too large > + * - EINVAL - cache size provided is too large, or priv_size is not a= ligned. > * - ENOSPC - the maximum number of memzones has already been allocat= ed > * - EEXIST - a memzone with the same name already exists > * - ENOMEM - no appropriate memory area found in which to create mem= zone > -- > 2.1.4