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 DF02B45A48; Sat, 28 Sep 2024 00:09:39 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C97FF402EF; Sat, 28 Sep 2024 00:09:39 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id B523740156 for ; Sat, 28 Sep 2024 00:09:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727474977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5vqEyWXMVrqh+Zuo10aBoDyO01hsjE/JYWSrp3ItldY=; b=AL2g+rouE6wBvh4H596P6E8aXkb25aKt+D1aXZjn17Z1KHWMteKtx7LaQjYv9ujXCc0x0I fgoHQpPRJKsZeU1W1bqccjHyPli2AFMGnG4hoc6SBBspo6JlIGKyWH5hthbxi4SwfZSoWl J6XFhj9kIM16DpuqXG7EruBIcEgXcW4= Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-eRRVhC1fOf-vkkI8QCLKBg-1; Fri, 27 Sep 2024 18:09:36 -0400 X-MC-Unique: eRRVhC1fOf-vkkI8QCLKBg-1 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-53658eafe8eso2569864e87.1 for ; Fri, 27 Sep 2024 15:09:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727474974; x=1728079774; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5vqEyWXMVrqh+Zuo10aBoDyO01hsjE/JYWSrp3ItldY=; b=eyWalCoWSddauRBCrRxZ5xJtKFyJkEWmVe42tlzwIpgS3sYEM5Mw5urKbtf6XECl5K Nsxj5KT6aloNSZVy0JO+JmgUD6wj1M+f3NLAdp38P85i5U5E8RtyGo1gFCnBtxCQ1nmx T0RnPOMtgoggweGPgtOa/Bg4hVtVsODuxw8DEf4X1Ln5qog3nSLOq4YcW6X5qRHy17vF QwaVGlSr2BppqkbHFzkmt3mT30Ha6gcdZtsulUPRiJSqxnlYLCUHd2JqiRXorxqJyfXx uWkpW/cXgmjGuffdZfHZ6z6y3HAvu/zf+iNLo9SQUcSEVMWSrB927vOvWutAlrTEVfaQ p52Q== X-Gm-Message-State: AOJu0Yw6yhEM8Kg/I1OaofMNQKAc1HnO7Vqa191TOajeC78EuG0AkGrW B39siy3IGNess49b/NS5Z4Adwa6MJ5OIIDPS1+3LVJi1q72cfmN7ct9Jx9umBC2DPvy9kMtcRQe j1nP9vA6huKmzU25Cwslx2oBMZb3OtTCP2zVWSydp394CruqAHNlgqtbcmAUgk/rVW6cYVTNCaP eNiWwG2qGk1/d4l8o= X-Received: by 2002:a05:6512:230e:b0:536:54c2:fb83 with SMTP id 2adb3069b0e04-5389fc36745mr3067861e87.23.1727474974517; Fri, 27 Sep 2024 15:09:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMLGKuZmMRCWB53x8blU+lduSInBBw804maG9LKot5GUHNDOrTWbyg6kg8X6/uosOFXCzpUGkwjvxQNmE5tiM= X-Received: by 2002:a05:6512:230e:b0:536:54c2:fb83 with SMTP id 2adb3069b0e04-5389fc36745mr3067851e87.23.1727474974058; Fri, 27 Sep 2024 15:09:34 -0700 (PDT) MIME-Version: 1.0 References: <20240927204742.546164-1-stephen@networkplumber.org> <20240927204742.546164-2-stephen@networkplumber.org> In-Reply-To: <20240927204742.546164-2-stephen@networkplumber.org> From: David Marchand Date: Fri, 27 Sep 2024 18:09:22 -0400 Message-ID: Subject: Re: [PATCH 01/16] eal: add function attributes for allocation functions To: Stephen Hemminger Cc: dev@dpdk.org, Tyler Retzlaff , Anatoly Burakov X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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, 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(). Interesting tool. > > 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 pointe= r > + * 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) Even though it is probably equivalent, GCC_VERSION is set with RTE_CC_GCC. > +#define __rte_alloc_func(free_func) \ > + __attribute__((malloc, malloc(free_func))) I read that this malloc attribute can also make use of the arg index to assume the pointer is freed. Did you try this feature? Something like: @@ -248,14 +248,13 @@ typedef uint16_t unaligned_uint16_t; * dealloctor function is used for this pointer. */ #if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >=3D 110000) -#define __rte_alloc_func(free_func) \ - __attribute__((malloc, malloc(free_func))) - +#define __rte_alloc_func(...) \ + __attribute__((malloc, malloc(__VA_ARGS__))) #elif defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) -#define __rte_alloc_func(free_func) \ +#define __rte_alloc_func(...) \ __attribute__((malloc)) #else -#define __rte_alloc_func(free_func) +#define __rte_alloc_func(...) #endif #define RTE_PRIORITY_LOG 101 > + > +#elif defined(RTE_CC_GCC) || defined(RTE_CC_CLANG) > +#define __rte_alloc_func(free_func) \ > + __attribute__((malloc)) > +#else > +#define __rte_alloc_func(free_func) > +#endif > + > #define RTE_PRIORITY_LOG 101 > #define RTE_PRIORITY_BUS 110 > #define RTE_PRIORITY_CLASS 120 --=20 David Marchand