| 76 | } |
| 77 | |
| 78 | struct mlx5_indexed_pool * |
| 79 | mlx5_ipool_create(struct mlx5_indexed_pool_config *cfg) |
| 80 | { |
| 81 | struct mlx5_indexed_pool *pool; |
| 82 | uint32_t i; |
| 83 | |
| 84 | if (!cfg || (!cfg->malloc ^ !cfg->free) || |
| 85 | (cfg->per_core_cache && cfg->release_mem_en) || |
| 86 | (cfg->trunk_size && ((cfg->trunk_size & (cfg->trunk_size - 1)) || |
| 87 | ((__builtin_ffs(cfg->trunk_size) + TRUNK_IDX_BITS) > 32)))) |
| 88 | return NULL; |
| 89 | pool = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*pool) + cfg->grow_trunk * |
| 90 | sizeof(pool->grow_tbl[0]), RTE_CACHE_LINE_SIZE, |
| 91 | SOCKET_ID_ANY); |
| 92 | if (!pool) |
| 93 | return NULL; |
| 94 | pool->cfg = *cfg; |
| 95 | if (!pool->cfg.trunk_size) |
| 96 | pool->cfg.trunk_size = MLX5_IPOOL_DEFAULT_TRUNK_SIZE; |
| 97 | if (!cfg->malloc && !cfg->free) { |
| 98 | pool->cfg.malloc = mlx5_malloc; |
| 99 | pool->cfg.free = mlx5_free; |
| 100 | } |
| 101 | if (pool->cfg.need_lock) |
| 102 | rte_spinlock_init(&pool->rsz_lock); |
| 103 | /* |
| 104 | * Initialize the dynamic grow trunk size lookup table to have a quick |
| 105 | * lookup for the trunk entry index offset. |
| 106 | */ |
| 107 | for (i = 0; i < cfg->grow_trunk; i++) { |
| 108 | pool->grow_tbl[i] = cfg->trunk_size << (cfg->grow_shift * i); |
| 109 | if (i > 0) |
| 110 | pool->grow_tbl[i] += pool->grow_tbl[i - 1]; |
| 111 | } |
| 112 | if (!pool->cfg.max_idx) |
| 113 | pool->cfg.max_idx = |
| 114 | mlx5_trunk_idx_offset_get(pool, TRUNK_MAX_IDX + 1); |
| 115 | if (!cfg->per_core_cache) |
| 116 | pool->free_list = TRUNK_INVALID; |
| 117 | rte_spinlock_init(&pool->lcore_lock); |
| 118 | return pool; |
| 119 | } |
| 120 | |
| 121 | static int |
| 122 | mlx5_ipool_grow(struct mlx5_indexed_pool *pool) |
no test coverage detected