From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [dpdk-dev] [RFC] eal: mark rte_malloc with malloc attribute
Date: Thu, 30 Jul 2020 10:13:12 -0700 [thread overview]
Message-ID: <20200730171312.20351-1-stephen@networkplumber.org> (raw)
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 <stephen@networkplumber.org>
---
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);
--
2.27.0
reply other threads:[~2020-07-30 17:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200730171312.20351-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).