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

Function mlx5_ipool_grow

dpdk/drivers/net/mlx5/mlx5_utils.c:121–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119}
120
121static int
122mlx5_ipool_grow(struct mlx5_indexed_pool *pool)
123{
124 struct mlx5_indexed_trunk *trunk;
125 struct mlx5_indexed_trunk **trunk_tmp;
126 struct mlx5_indexed_trunk **p;
127 size_t trunk_size = 0;
128 size_t data_size;
129 size_t bmp_size;
130 uint32_t idx, cur_max_idx, i;
131
132 cur_max_idx = mlx5_trunk_idx_offset_get(pool, pool->n_trunk_valid);
133 if (pool->n_trunk_valid == TRUNK_MAX_IDX ||
134 cur_max_idx >= pool->cfg.max_idx)
135 return -ENOMEM;
136 if (pool->n_trunk_valid == pool->n_trunk) {
137 /* No free trunk flags, expand trunk list. */
138 int n_grow = pool->n_trunk_valid ? pool->n_trunk :
139 RTE_CACHE_LINE_SIZE / sizeof(void *);
140
141 p = pool->cfg.malloc(0, (pool->n_trunk_valid + n_grow) *
142 sizeof(struct mlx5_indexed_trunk *),
143 RTE_CACHE_LINE_SIZE, rte_socket_id());
144 if (!p)
145 return -ENOMEM;
146 if (pool->trunks)
147 memcpy(p, pool->trunks, pool->n_trunk_valid *
148 sizeof(struct mlx5_indexed_trunk *));
149 memset(RTE_PTR_ADD(p, pool->n_trunk_valid * sizeof(void *)), 0,
150 n_grow * sizeof(void *));
151 trunk_tmp = pool->trunks;
152 pool->trunks = p;
153 if (trunk_tmp)
154 pool->cfg.free(trunk_tmp);
155 pool->n_trunk += n_grow;
156 }
157 if (!pool->cfg.release_mem_en) {
158 idx = pool->n_trunk_valid;
159 } else {
160 /* Find the first available slot in trunk list */
161 for (idx = 0; idx < pool->n_trunk; idx++)
162 if (pool->trunks[idx] == NULL)
163 break;
164 }
165 trunk_size += sizeof(*trunk);
166 data_size = mlx5_trunk_size_get(pool, idx);
167 bmp_size = rte_bitmap_get_memory_footprint(data_size);
168 /* rte_bitmap requires memory cacheline aligned. */
169 trunk_size += RTE_CACHE_LINE_ROUNDUP(data_size * pool->cfg.size);
170 trunk_size += bmp_size;
171 trunk = pool->cfg.malloc(0, trunk_size,
172 RTE_CACHE_LINE_SIZE, rte_socket_id());
173 if (!trunk)
174 return -ENOMEM;
175 pool->trunks[idx] = trunk;
176 trunk->idx = idx;
177 trunk->free = data_size;
178 trunk->prev = TRUNK_INVALID;

Callers 1

mlx5_ipool_mallocFunction · 0.85

Calls 8

rte_socket_idFunction · 0.85
memsetFunction · 0.85
mlx5_trunk_size_getFunction · 0.85
rte_bitmap_clearFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected