MCPcopy Create free account
hub / github.com/F-Stack/f-stack / mlx4_mallocv_inline

Function mlx4_mallocv_inline

dpdk/drivers/net/mlx4/mlx4_utils.c:52–97  ·  view source on GitHub ↗

* Internal helper to allocate memory once for several disparate objects. * * The most restrictive alignment constraint for standard objects is assumed * to be sizeof(double) and is used as a default value. * * C11 code would include stdalign.h and use alignof(max_align_t) however * we'll stick with C99 for the time being. */

Source from the content-addressed store, hash-verified

50 * we'll stick with C99 for the time being.
51 */
52static inline size_t
53mlx4_mallocv_inline(const char *type, const struct mlx4_malloc_vec *vec,
54 unsigned int cnt, int zero, int socket)
55{
56 unsigned int i;
57 size_t size;
58 size_t least;
59 uint8_t *data = NULL;
60 int fill = !vec[0].addr;
61
62fill:
63 size = 0;
64 least = 0;
65 for (i = 0; i < cnt; ++i) {
66 size_t align = (uintptr_t)vec[i].align;
67
68 if (!align) {
69 align = sizeof(double);
70 } else if (!rte_is_power_of_2(align)) {
71 rte_errno = EINVAL;
72 goto error;
73 }
74 if (least < align)
75 least = align;
76 align = RTE_ALIGN_CEIL(size, align);
77 size = align + vec[i].size;
78 if (fill && vec[i].addr)
79 *vec[i].addr = data + align;
80 }
81 if (fill)
82 return size;
83 if (!zero)
84 data = rte_malloc_socket(type, size, least, socket);
85 else
86 data = rte_zmalloc_socket(type, size, least, socket);
87 if (data) {
88 fill = 1;
89 goto fill;
90 }
91 rte_errno = ENOMEM;
92error:
93 for (i = 0; i != cnt; ++i)
94 if (vec[i].addr)
95 *vec[i].addr = NULL;
96 return 0;
97}
98
99/**
100 * Allocate memory once for several disparate objects.

Callers 4

mlx4_mallocvFunction · 0.85
mlx4_zmallocvFunction · 0.85
mlx4_mallocv_socketFunction · 0.85
mlx4_zmallocv_socketFunction · 0.85

Calls 3

rte_malloc_socketFunction · 0.85
rte_zmalloc_socketFunction · 0.85
rte_is_power_of_2Function · 0.50

Tested by

no test coverage detected