From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1E37BA0C44; Mon, 14 Jun 2021 15:28:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F0EC74067A; Mon, 14 Jun 2021 15:28:21 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by mails.dpdk.org (Postfix) with ESMTP id EA5984003F for ; Mon, 14 Jun 2021 15:28:19 +0200 (CEST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 415FF5C0054; Mon, 14 Jun 2021 09:28:19 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 14 Jun 2021 09:28:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=fm1; bh= KOI395g6kLSFqywDmYgQT7So9YV1SoFEOMc7O/xzyCM=; b=vOmE2bcU5Nq+5A/E ZMj5CH/xobBzXtM/0ZqhvNtp6fGxRHU3dB7h6s+mP+dVsjQy6lApykrRMf3og68x WrkFBi4JG8AkUTd8LbRS1TMXzB/Fp0cfGKFRZUIYSkZXMFaaSwPhLFUmjGkcj+z3 fRgKhC4AxZTXprdGvZsYsJNVwEwOD6VV0mTZBS4Sde4C2X0KPwK3VITVIEvuncxV pZuHrUnfcDhBt9ACepLkLfKzujODyD3y3yr+936nx4h3BxklAL+vqAgC6o9Bj0/M weThdsDAomGcHGPP+mPgMTafOXwuX2sEcd6ijJasIrDIiWUfsSYEP7Lgiq41jw94 pWEaXA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=KOI395g6kLSFqywDmYgQT7So9YV1SoFEOMc7O/xzy CM=; b=dz4ea5qL9J88fbC1/0J/9oiP/jsPpOLYW4zMsnNygmX4vmQGrbZ7v18m7 HKOmXoZ4/WxX5yIuP1XuHNUS0IrEqcctfF+7vOzQBmoYJ8KB51SBANZmzQRneHAO nGUBe4EHaT6AcCIuOLOrFTTP7rWzNimvHt+gr3ihC/Q9/VLVpLtUag/9MDELatIZ Mwj24yhR5hDPYSUu8GZZxHvQ6sja7PrOp5yuxvVsgMuS8bT+8wIPNmwmlxeNifsN EFIvt0P34so0ah2ulUFOaxF2HSalwr7hADn/hnbrxThY9VLncSrhenU0K7jFYiLM zwJbwRDeJw9237fZA6eQFyNOLXPLQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfedvhedgieduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkfgjfhgggfgtsehtqhertddttddunecuhfhrohhmpefvhhhomhgr shcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjhgrlhhonhdrnhgvtheqnecugg ftrfgrthhtvghrnhepfeegffeihfeftedthfdvgfetkeffffdukeevtdevtddvgfevuedu veegvdeggedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvth X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 14 Jun 2021 09:28:16 -0400 (EDT) From: Thomas Monjalon To: Morten =?ISO-8859-1?Q?Br=F8rup?= Cc: dev@dpdk.org, olivier.matz@6wind.com, andrew.rybchenko@oktetlabs.ru, honnappa.nagarahalli@arm.com, konstantin.ananyev@intel.com, bruce.richardson@intel.com, ferruh.yigit@intel.com, jerinj@marvell.com, gakhil@marvell.com Date: Mon, 14 Jun 2021 15:28:14 +0200 Message-ID: <4219595.Gpeg8gzPfc@thomas> In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35C6184E@smartserver.smartshare.dk> References: <20210614105839.3379790-1-thomas@monjalon.net> <98CBD80474FA8B44BF855DF32C47DC35C6184E@smartserver.smartshare.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Subject: Re: [dpdk-dev] [PATCH] parray: introduce internal API for dynamic arrays X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 14/06/2021 14:22, Morten Br=F8rup: > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon > > Sent: Monday, 14 June 2021 12.59 > >=20 > > Performance of access in a fixed-size array is very good > > because of cache locality > > and because there is a single pointer to dereference. > > The only drawback is the lack of flexibility: > > the size of such an array cannot be increase at runtime. > >=20 > > An approach to this problem is to allocate the array at runtime, > > being as efficient as static arrays, but still limited to a maximum. > >=20 > > That's why the API rte_parray is introduced, > > allowing to declare an array of pointer which can be resized > > dynamically > > and automatically at runtime while keeping a good read performance. > >=20 > > After resize, the previous array is kept until the next resize > > to avoid crashs during a read without any lock. > >=20 > > Each element is a pointer to a memory chunk dynamically allocated. > > This is not good for cache locality but it allows to keep the same > > memory per element, no matter how the array is resized. > > Cache locality could be improved with mempools. > > The other drawback is having to dereference one more pointer > > to read an element. > >=20 > > There is not much locks, so the API is for internal use only. > > This API may be used to completely remove some compilation-time > > maximums. >=20 > I get the purpose and overall intention of this library. >=20 > I probably already mentioned that I prefer > "embedded style programming" with fixed size arrays, > rather than runtime configurability. > It's my personal opinion, and the DPDK Tech Board clearly prefers > reducing the amount of compile time configurability, > so there is no way for me to stop this progress, > and I do not intend to oppose to this library. :-) Embedded-style is highly customized and limited. DPDK is more used in standard servers where deployment must be easy and dynamically configurable. That's my view on where we go, but I understand some can have opposite goals. Thus the discussion :) > This library is likely to become a core library of DPDK, > so I think it is important getting it right. > Could you please mention a few examples where > you think this internal library should be used, It could be used for device arrays which are managed (alloc/free) in the main thread as part of init and hotplug operations. Other threads should be readers only. > and where it should not be used. > Then it is easier to discuss if the border line > between control path and data plane is correct. > E.g. this library is not intended to be used for dynamically > sized packet queues that grow and shrink in the fast path. Correct. If fast path threads need to alloc/free, this is not the right API. That's not a queue, just a growing array where each element has an index. > If the library becomes a core DPDK library, > it should probably be public instead of internal. > E.g. if the library is used to make RTE_MAX_ETHPORTS dynamic > instead of compile time fixed, > then some applications might also need dynamically sized arrays > for their application specific per-port runtime data, > and this library could serve that purpose too. It could be convenient but risky if users don't understand well the limitations. I am not sure what to do. > [snip] >=20 > > + > > +/** Main object representing a dynamic array of pointers. */ > > +struct rte_parray { > > + /** Array of pointer to dynamically allocated struct. */ > > + void **array; > > + /** Old array before resize, freed on next resize. */ > > + void **old_array; > > + /* Lock for alloc/free operations. */ > > + pthread_mutex_t mutex; > > + /** Current size of the full array. */ > > + int32_t size; > > + /** Number of allocated elements. */ > > + int32_t count; > > + /** Last allocated element. */ > > + int32_t last; > > +}; >=20 > Why not uint32_t for size, count and last? 2 reasons: 1/ anyway we are limited to int32_t for the index. 2/ having the same type for all avoid compiler complaining when comparing values. > Consider if the hot members of the struct should be moved > closer together, for increasing the probability > that they end up in the same cache line > if the structure is not cache line aligned. Probably not important, > just wanted to mention it. The only hot member is the array itself. Depending on mutex implementation, all could be in a single cacheline.