[RFC] eal: mark rte_malloc with malloc attribute
Checks
Commit Message
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(+)
@@ -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
@@ -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);