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 D1EB0459FA; Sat, 28 Sep 2024 01:10:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 93E4A40156; Sat, 28 Sep 2024 01:10:40 +0200 (CEST) Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by mails.dpdk.org (Postfix) with ESMTP id E09BF40144 for ; Sat, 28 Sep 2024 01:10:38 +0200 (CEST) Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7179802b8fcso1997778b3a.1 for ; Fri, 27 Sep 2024 16:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1727478638; x=1728083438; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ftd4td21A5aOCzIk13PTOBpRjSzaqsE7bC8L3Yb9kCs=; b=ICOReyYCrQG6Yfgkg+iFjpiSt7TcfHGt21d9FifJAy1evfgB1b4+gPP52ip8ZlEIKW rp/zOm1PfqCAe6I16clyAnM5EYiXJTLNGAVNA7UNxXU6I+nmoZO/AHPD+qUTnv11h+hk Z2UnqNCZJ81SupVgBu/C+Mtsle73gIUbd6+R/Hxs35x7U8AvQ+1mi6Sssk6i0z1iZrDi pczuNzzzAtKvUuu/z7AE6CHJOPwfsGsj1O2jnwDsjN2NDK7/3gWfv3CP7D6XbkYciY29 BqRfq1R2Un6pi5tc9q0Qib4BNsaTWZ5EZmZ9PirtIbduD9w7TO3ldTZP5kICpXuyGKWZ sKzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727478638; x=1728083438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ftd4td21A5aOCzIk13PTOBpRjSzaqsE7bC8L3Yb9kCs=; b=ENbAj43a4oYAHV1PHNuv7d6U5nMshbWZUjFHGqPKViHB3pYwA5tQK00QPIIeJ7JMAW TqF1GoRxO74P+NLmnI69SQ8ve4GGzetGHAuNWykkAVYsvUByJdpVuQD2pflvVQd1JuA/ eOXtwsTcRBYZTzQpggN/z9x5WbUk6mRdMcd4IjIf0Nyx3RFJC8OS+PR5sL0Rp2sXmYND 7eL+6F+jhCssfgUVnH1UK4PUxEQQMgicjhWwQjOxuOyju5VktWUm2zW0hKBYDTwm/K0/ 6MmVU6HjEDXI+Z5VuTviQGqF5vP9im1TaTjfWCKNSdT3XLUFZ8TujZ1GjPwPhVRuvxpV MdNA== X-Gm-Message-State: AOJu0YylyEmajPak0aPVdlV15/5lgWH72Ltc3XfhMPzn40rqY4LyPEvM dUMba2G00T3J/+jSPVervSc7vLJrkIOfAjGbNw4OgsuTOL2CZ7LVER6jayQ8FYM= X-Google-Smtp-Source: AGHT+IHepVcCPs7vuwGip3rYMq1HTWSOuv5vKBg5sfgLgk1a6hsIt2L0xNkOXuparAUKzduSq1Ccuw== X-Received: by 2002:aa7:8887:0:b0:70a:f65e:b13d with SMTP id d2e1a72fcca58-71b26066827mr7283135b3a.27.1727478637482; Fri, 27 Sep 2024 16:10:37 -0700 (PDT) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71b264bc896sm2132808b3a.76.2024.09.27.16.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 16:10:37 -0700 (PDT) Date: Fri, 27 Sep 2024 16:10:35 -0700 From: Stephen Hemminger To: David Marchand Cc: dev@dpdk.org, Tyler Retzlaff , Anatoly Burakov Subject: Re: [PATCH 01/16] eal: add function attributes for allocation functions Message-ID: <20240927161035.5a72dba0@hermes.local> In-Reply-To: References: <20240927204742.546164-1-stephen@networkplumber.org> <20240927204742.546164-2-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 Fri, 27 Sep 2024 18:09:22 -0400 David Marchand wrote: > On Fri, Sep 27, 2024 at 4:48=E2=80=AFPM Stephen Hemminger > wrote: > > > > The allocation functions take a alignment argument that > > can be useful to hint the compiler optimizer. > > > > This is supported by Gcc and Clang but only useful with > > Gcc because Clang gives warning if alignment is 0. > > > > Recent versions of GCC have a malloc attribute that can > > be used to find mismatches between allocation and free; > > the typical problem caught is a pointer allocated with > > rte_malloc() that is then incorrectly freed using free(). =20 >=20 > Interesting tool. >=20 > > > > Signed-off-by: Stephen Hemminger > > --- > > lib/eal/include/rte_common.h | 30 ++++++++++++++++++++++++++++++ > > lib/eal/include/rte_malloc.h | 24 ++++++++++++++++-------- > > 2 files changed, 46 insertions(+), 8 deletions(-) > > > > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h > > index eec0400dad..1b3781274d 100644 > > --- a/lib/eal/include/rte_common.h > > +++ b/lib/eal/include/rte_common.h > > @@ -228,6 +228,36 @@ typedef uint16_t unaligned_uint16_t; > > #define __rte_alloc_size(...) > > #endif > > > > +/** > > + * Tells the compiler that the function returns a value that points to > > + * memory aligned by a function argument. > > + * Not enabled on clang because it warns if align argument is zero. > > + */ > > +#if defined(RTE_CC_GCC) > > +#define __rte_alloc_align(align_arg) \ > > + __attribute__((alloc_align(align_arg))) > > +#else > > +#define __rte_alloc_align(...) > > +#endif > > + > > +/** > > + * Tells the compiler this is a function like malloc and that the poin= ter > > + * returned cannot alias any other pointer (ie new memory). > > + * > > + * Also, with recent GCC versions also able to track that proper > > + * dealloctor function is used for this pointer. > > + */ > > +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 110000) =20 >=20 > Even though it is probably equivalent, GCC_VERSION is set with RTE_CC_GCC. >=20 > > +#define __rte_alloc_func(free_func) \ > > + __attribute__((malloc, malloc(free_func))) =20 >=20 > I read that this malloc attribute can also make use of the arg index > to assume the pointer is freed. >=20 > Did you try this feature? Yes, but all DPDK functions use first arg, so not really that relevant