From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id A2367C64E for ; Thu, 30 Jul 2015 17:33:09 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 30 Jul 2015 08:33:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,577,1432623600"; d="scan'208";a="738887471" Received: from pgsmsx106.gar.corp.intel.com ([10.221.44.98]) by orsmga001.jf.intel.com with ESMTP; 30 Jul 2015 08:33:07 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by PGSMSX106.gar.corp.intel.com (10.221.44.98) with Microsoft SMTP Server (TLS) id 14.3.224.2; Thu, 30 Jul 2015 23:33:04 +0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.45]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.18]) with mapi id 14.03.0224.002; Thu, 30 Jul 2015 23:33:03 +0800 From: "Zhang, Helin" To: Olivier Matz , "dev@dpdk.org" Thread-Topic: [PATCH] mbuf: enforce alignment of mbuf private area Thread-Index: AQHQys+t1jPOh1QHIUGRJ8jLFVgf4530JB6g Date: Thu, 30 Jul 2015 15:33:02 +0000 Message-ID: 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-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 15:33:10 -0000 > -----Original Message----- > From: Olivier Matz [mailto:olivier.matz@6wind.com] > Sent: Thursday, July 30, 2015 6:56 AM > To: dev@dpdk.org > Cc: Ananyev, Konstantin; olivier.matz@6wind.com; Zhang, Helin; > martin.weiser@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 ther= e is one, > the alignment depends on the size of this area that is located between th= e mbuf > structure and the data buffer. >=20 > Indeed, some drivers expects to have the buffer address aligned to an eve= n > 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 constrai= nt > before creating the mempool. For applications that use the alternative wa= y > (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/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. */ >=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 inde= x > 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); Using RTE_ALIGN() could be more readable? > 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) { Using RTE_ALIGN() could be more readable? > + 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" { >=20 > 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_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 a= ligned. > * - 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