* [dpdk-dev] [RFC] eal: mark rte_malloc with malloc attribute
@ 2020-07-30 17:13 Stephen Hemminger
0 siblings, 0 replies; only message in thread
From: Stephen Hemminger @ 2020-07-30 17:13 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-07-30 17:13 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-30 17:13 [dpdk-dev] [RFC] eal: mark rte_malloc with malloc attribute Stephen Hemminger
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).