From patchwork Thu Jul 30 17:13:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 75049 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7C061A052B; Thu, 30 Jul 2020 19:13:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 073A9E07; Thu, 30 Jul 2020 19:13:19 +0200 (CEST) Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by dpdk.org (Postfix) with ESMTP id F2E403B5 for ; Thu, 30 Jul 2020 19:13:16 +0200 (CEST) Received: by mail-pl1-f181.google.com with SMTP id d1so14735387plr.8 for ; Thu, 30 Jul 2020 10:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=A8bDmWxko8dr8qONgHXgAib5/gJtT/XbSPYfz0p/nAg=; b=NGLSeCL/V2VQlVFzJtbnycHrWeeJImW//Q64flSB0VFvTdlnoOzBv1dH3PueV9HFeF KRKRHG6zTPYIeIcNWVlIIr13+FOTGMXN0etACxTr3IaX7luhZ5n+fT7EW0kSNTND3LUu 4guFmjodBqsD+x96s0h4Ywr4ZkzEMQ8cDUC4J5FjpVEvh//EVQYyfuIQkIeILKgvTKTT us8vKTR1tTV2ru447+fsFLGzoLbNrT/sZADfsdQqfJpPw7gsecGYriKK/5A8R5DolEyp vu/5pUuaBvL9Haf7y8PO08skC+xvXxqjm6t8YJVgVoYd+QrkZv+TJr1IHNJ+M8CvDBAs HZ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=A8bDmWxko8dr8qONgHXgAib5/gJtT/XbSPYfz0p/nAg=; b=skz6QMRd70GQBtoKaNqF7U1JXSBSD4v9p8zVK+R5A4jpHwUq1MuPWm2l4Yr3/oBRYJ AueMopkVsXqSnmJsEvsJqPamEv125A+trIUTSyFjXfR/NmdQc88CR6aISJdGf9u0sC/w ZVFBmSUt3UU6LT1SqG87aSeMt+GTj8mI6uW4nyTSZ0xSP+V1soKm7N+2aONlZcvzOFPA o9eVhfu1mBumAhrTQstdcGEPufGdlFAaKUmoVWXk784qaEMRKxcarfNEu/XWBZuWjMq3 s4ciDrJG+aQUKR6sqB9mJR1kuiL72YC4CeakPErKkzf6QGpnb9bOwKBnv+f7Tihjfhmw N58w== X-Gm-Message-State: AOAM533f+XBtP2nI4Vlbv+1gaG5uJSmHwaLwErIvmhgeWmon+z/V+i1G jyyC9gvxHpDkmPLoZ47uhtdtBSlfZ7l6uQ== X-Google-Smtp-Source: ABdhPJyJYfAQuQ3P+6M1i7pst3B/CI3LO3K9stHIMwokZ14Wkl9D9/DlX71HMbEgbcMuSg52jJyAgg== X-Received: by 2002:a17:902:9a07:: with SMTP id v7mr186821plp.312.1596129195404; Thu, 30 Jul 2020 10:13:15 -0700 (PDT) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p127sm6705818pfb.17.2020.07.30.10.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jul 2020 10:13:14 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 30 Jul 2020 10:13:12 -0700 Message-Id: <20200730171312.20351-1-stephen@networkplumber.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [dpdk-dev] [RFC] eal: mark rte_malloc with malloc attribute X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 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" Gcc (and recent versions of Clang) have a function attribute that hints to the optimizer that it doesn't need to worry about aliasing on a pointer returned from malloc. Signed-off-by: Stephen Hemminger --- lib/librte_eal/include/rte_common.h | 11 +++++++++++ lib/librte_eal/include/rte_malloc.h | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/lib/librte_eal/include/rte_common.h b/lib/librte_eal/include/rte_common.h index 8f487a563dfc..6b85374c0fe5 100644 --- a/lib/librte_eal/include/rte_common.h +++ b/lib/librte_eal/include/rte_common.h @@ -112,6 +112,17 @@ typedef uint16_t unaligned_uint16_t; #define __rte_restrict restrict #endif +/** + * Mark function as returing a pointer which if non-NULL + * cannot alias any other valid pointer and that the memory + * contents are undefined. I.e behaves like malloc. + */ +#if RTE_CC_IS_GNU +#define __rte_malloc __attribute__((malloc)) +#else +#define __rte_malloc +#endif + /** * definition to mark a variable or function parameter as used so * as to avoid a compiler warning diff --git a/lib/librte_eal/include/rte_malloc.h b/lib/librte_eal/include/rte_malloc.h index 42ca05182f8e..721560122c70 100644 --- a/lib/librte_eal/include/rte_malloc.h +++ b/lib/librte_eal/include/rte_malloc.h @@ -79,6 +79,7 @@ rte_malloc(const char *type, size_t size, unsigned align); * align is not a power of two). * - Otherwise, the pointer to the allocated object. */ +__rte_malloc void * rte_zmalloc(const char *type, size_t size, unsigned align); @@ -105,6 +106,7 @@ rte_zmalloc(const char *type, size_t size, unsigned align); * align is not a power of two). * - Otherwise, the pointer to the allocated object. */ +__rte_malloc void * rte_calloc(const char *type, size_t num, size_t size, unsigned align); @@ -180,6 +182,7 @@ rte_realloc_socket(void *ptr, size_t size, unsigned int align, int socket); * align is not a power of two). * - Otherwise, the pointer to the allocated object. */ +__rte_malloc void * rte_malloc_socket(const char *type, size_t size, unsigned align, int socket); @@ -236,6 +239,7 @@ rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket); * align is not a power of two). * - Otherwise, the pointer to the allocated object. */ +__rte_malloc void * rte_calloc_socket(const char *type, size_t num, size_t size, unsigned align, int socket);