| 119 | } |
| 120 | |
| 121 | static int |
| 122 | mlx5_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; |
no test coverage detected