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 293C643E20; Sun, 7 Apr 2024 11:31:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 54F48402BF; Sun, 7 Apr 2024 11:31:54 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id C80834029A for ; Sun, 7 Apr 2024 11:31:52 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 4B79A1E5DB for ; Sun, 7 Apr 2024 11:31:52 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 245E21E5D9; Sun, 7 Apr 2024 11:31:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.3 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 61EC31E680; Sun, 7 Apr 2024 11:31:49 +0200 (CEST) Message-ID: Date: Sun, 7 Apr 2024 11:31:48 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/4] RFC samples converting VLA to alloca To: Tyler Retzlaff , dev@dpdk.org Cc: Bruce Richardson , Stephen Hemminger , Thomas Monjalon , =?UTF-8?Q?Morten_Br=C3=B8rup?= References: <20231107193220.GA15232@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <1712250913-1977-1-git-send-email-roretzla@linux.microsoft.com> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <1712250913-1977-1-git-send-email-roretzla@linux.microsoft.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP 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 On 2024-04-04 19:15, Tyler Retzlaff wrote: > This series is not intended for merge. It insteat provides examples of > converting use of VLAs to alloca() would look like. > > what's the advantages of VLA over alloca()? > > * sizeof(array) works as expected. > > * multi-dimensional arrays are still arrays instead of pointers to > dynamically allocated space. this means multiple subscript syntax > works (unlike on a pointer) and calculation of addresses into allocated > space in ascending order is performed by the compiler instead of manually. > alloca() is a pretty obscure mechanism, and also not a part of the C standard. VLAs are C99, and well-known and understood, and very efficient. > what's the disadvantage of VLA over alloca()? > > * VLA generation is subtl/implicit, there do appear to be places where > a VLA is being used where it perhaps was not intended but it is hard > to spot. e.g. hotpath rte_mbuf *array[burst_size]; where burst_size > is not a constant expression, e.g. unintended in other syntax positions > that are not intuitive, see patchwork link. > > https://patchwork.dpdk.org/project/dpdk/patch/1699896038-28106-1-git-send-email-roretzla@linux.microsoft.com/ > > for the above reasons i'd recommend only converting to alloca() where > necessary (msvc has to compile it) and for the other instances leave > them as they are. > > Tyler Retzlaff (4): > latencystats: use alloca instead of vla trivial > hash: use alloca instead of vla trivial > vhost: use alloca instead of vla sizeof > dispatcher: use alloca instead of vla multi dimensional > > lib/dispatcher/rte_dispatcher.c | 6 +++--- > lib/hash/rte_thash.c | 2 +- > lib/latencystats/rte_latencystats.c | 2 +- > lib/vhost/socket.c | 5 +++-- > 4 files changed, 8 insertions(+), 7 deletions(-) >