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 C57AAA0C49; Tue, 15 Jun 2021 10:01:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC9554067E; Tue, 15 Jun 2021 10:01:11 +0200 (CEST) Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by mails.dpdk.org (Postfix) with ESMTP id 4DB774067A for ; Tue, 15 Jun 2021 10:01:10 +0200 (CEST) Received: by mail-io1-f50.google.com with SMTP id l64so20806511ioa.7 for ; Tue, 15 Jun 2021 01:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=EbIJ0+x2A6q5eR4GBUPS/HuwDZOS2PEhV6Z2WP5iNfs=; b=bSzYdnYml12QhE+leRAOuMGweGvB98VPdRsY3S3A02QdALWAjewZ4H9yMCtMSvFxf7 0D//qXM4j7F0fYankM2YblGdOPlXeIj8v8bchOKq9qTxg+cLq3YSnrkLrWbAeNYB8shO Hz/DaO+5m6OvDCZvzzhpJVFvhNUJLKPHInE82ZAOqHg5i+2gOWsMS8kuMGMHETdk4PKP cVUXNXxZBekK6sAyoZ0jBz3bjp8LprGVv/xPJku2ly/i4SO8LADsD3DXiKJEEnuengSg VrIrEX8gx7zbjA2CenPH427quLCEWh6NjKLGJ6JZZ8/ZacQalaiL612eHtdURamUu5hY Ge0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=EbIJ0+x2A6q5eR4GBUPS/HuwDZOS2PEhV6Z2WP5iNfs=; b=HgYwcJxCPhsK+hUPdicwayzTmxCUUSOCjVtuAJOh2kRIE+R+RSznwyxR0jb89qUTel J4YPFTCQj6FNq/hQpIw0fabXLGM+Q+LAAwcrhSO0Cci/1a4xaHflqR1+uc6s5bN7XmeN /5Rhp1hxxKFeOeH0pXI/jIAGDMxq0rfX4rzC6FIexua74LX7H/jjtFqYO0d2MYJgol11 Q8XhB631HrHe/cfg2uJQu+LqPrF0C7rjIOxrkEbVq4bl9FBhhallfvcskU2RJeNXjw9F k4aLSoegEfLqrjY1FBjvJfXWTgrPBUHeuTJkMBhMcGsYmPN4Os4ntDwysCHiAzx5+HV3 nnuQ== X-Gm-Message-State: AOAM530XE9MtzIvYmTCUuQ8bvtZqe67Velpt2zO8CVeDshpgiK/MP1Jm oxErbq1jmQz4zJloKF5R7zDzT8O/ZdC+L1QxJLg= X-Google-Smtp-Source: ABdhPJyVgVUwnhDz6QIKMjeyqG54ZL3b5D5K+uFAESQLIn7nmFuXm8NhQ42DT5IVFgB90hqN1eAWkabGVcOgN4KTiLQ= X-Received: by 2002:a6b:8f83:: with SMTP id r125mr1781090iod.123.1623744069561; Tue, 15 Jun 2021 01:01:09 -0700 (PDT) MIME-Version: 1.0 References: <20210614105839.3379790-1-thomas@monjalon.net> <52380960.E65VIl4Blx@thomas> In-Reply-To: <52380960.E65VIl4Blx@thomas> From: Jerin Jacob Date: Tue, 15 Jun 2021 13:30:53 +0530 Message-ID: To: Thomas Monjalon Cc: "Ananyev, Konstantin" , "Richardson, Bruce" , =?UTF-8?Q?Morten_Br=C3=B8rup?= , "dev@dpdk.org" , "olivier.matz@6wind.com" , "andrew.rybchenko@oktetlabs.ru" , "honnappa.nagarahalli@arm.com" , "Yigit, Ferruh" , "jerinj@marvell.com" , "gakhil@marvell.com" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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" On Tue, Jun 15, 2021 at 12:22 PM Thomas Monjalon wrot= e: > > 14/06/2021 17:48, Jerin Jacob: > > On Mon, Jun 14, 2021 at 8:29 PM Ananyev, Konstantin > > wrote: > > > > 14/06/2021 15:15, Bruce Richardson: > > > > > On Mon, Jun 14, 2021 at 02:22:42PM +0200, Morten Br=C3=B8rup wrot= e: > > > > > > > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas M= onjalon > > > > > > > Sent: Monday, 14 June 2021 12.59 > > > > > > > > > > > > > > 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. > > > > > > > > > > > > > > An approach to this problem is to allocate the array at runti= me, > > > > > > > being as efficient as static arrays, but still limited to a m= aximum. > > > > > > > > > > > > > > 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 perfor= mance. > > > > > > > > > > > > > > After resize, the previous array is kept until the next resiz= e > > > > > > > to avoid crashs during a read without any lock. > > > > > > > > > > > > > > Each element is a pointer to a memory chunk dynamically alloc= ated. > > > > > > > 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. > > > > > > > > > > > > > > There is not much locks, so the API is for internal use only. > > > > > > > This API may be used to completely remove some compilation-ti= me > > > > > > > maximums. > > > > > > > > > > > > I get the purpose and overall intention of this library. > > > > > > > > > > > > I probably already mentioned that I prefer "embedded style prog= ramming" with fixed size arrays, rather than runtime configurability. It's > > > > my personal opinion, and the DPDK Tech Board clearly prefers reduci= ng 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 lib= rary. :-) > > > > > > > > > > > > This library is likely to become a core library of DPDK, so I t= hink it is important getting it right. Could you please mention a few examp= les > > > > where you think this internal library should be used, 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 in= tended to be used for dynamically sized packet queues that grow and shrink = in > > > > the fast path. > > > > > > > > > > > > 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 a= pplications might also need dynamically sized arrays for their > > > > application specific per-port runtime data, and this library could = serve that purpose too. > > > > > > > > > > > > > > > > Thanks Thomas for starting this discussion and Morten for follow-= up. > > > > > > > > > > My thinking is as follows, and I'm particularly keeping in mind t= he cases > > > > > of e.g. RTE_MAX_ETHPORTS, as a leading candidate here. > > > > > > > > > > While I dislike the hard-coded limits in DPDK, I'm also not convi= nced that > > > > > we should switch away from the flat arrays or that we need fully = dynamic > > > > > arrays that grow/shrink at runtime for ethdevs. I would suggest a= half-way > > > > > house here, where we keep the ethdevs as an array, but one alloca= ted/sized > > > > > at runtime rather than statically. This would allow us to have a > > > > > compile-time default value, but, for use cases that need it, allo= w use of a > > > > > flag e.g. "max-ethdevs" to change the size of the parameter give= n to the > > > > > malloc call for the array. This max limit could then be provided= to apps > > > > > too if they want to match any array sizes. [Alternatively those a= pps could > > > > > check the provided size and error out if the size has been increa= sed beyond > > > > > what the app is designed to use?]. There would be no extra derefe= rences per > > > > > rx/tx burst call in this scenario so performance should be the sa= me as > > > > > before (potentially better if array is in hugepage memory, I supp= ose). > > > > > > > > I think we need some benchmarks to decide what is the best tradeoff= . > > > > I spent time on this implementation, but sorry I won't have time fo= r benchmarks. > > > > Volunteers? > > > > > > I had only a quick look at your approach so far. > > > But from what I can read, in MT environment your suggestion will requ= ire > > > extra synchronization for each read-write access to such parray eleme= nt (lock, rcu, ...). > > > I think what Bruce suggests will be much ligther, easier to implement= and less error prone. > > > At least for rte_ethdevs[] and friends. > > > > +1 > > Please could you have a deeper look and tell me why we need more locks? We don't need more locks (It is fat mutex) now in the implementation. If it needs to use in fastpath, we need more state of art synchronization like RCU. Also, you can take look at VPP dynamic array implementation which is used in fastpath. https://docs.fd.io/vpp/21.10/db/d65/vec_8h.html So the question is the use case for this API. Is it for slowpath item like ethdev[] memory or fastpath items like holding an array of mbuf etc. > The element pointers doesn't change. > Only the array pointer change at resize, > but the old one is still usable until the next resize. > I think we don't need more. > >