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

Function mr_btree_insert

dpdk/drivers/common/mlx5/mlx5_common_mr.c:168–202  ·  view source on GitHub ↗

* Insert an entry to B-tree lookup table. * * @param bt * Pointer to B-tree structure. * @param entry * Pointer to new entry to insert. * * @return * 0 on success, -1 on failure. */

Source from the content-addressed store, hash-verified

166 * 0 on success, -1 on failure.
167 */
168static int
169mr_btree_insert(struct mlx5_mr_btree *bt, struct mr_cache_entry *entry)
170{
171 struct mr_cache_entry *lkp_tbl;
172 uint32_t idx = 0;
173 size_t shift;
174
175 MLX5_ASSERT(bt != NULL);
176 MLX5_ASSERT(bt->len <= bt->size);
177 MLX5_ASSERT(bt->len > 0);
178 lkp_tbl = *bt->table;
179 /* Find out the slot for insertion. */
180 if (mr_btree_lookup(bt, &idx, entry->start) != UINT32_MAX) {
181 DRV_LOG(DEBUG,
182 "abort insertion to B-tree(%p): already exist at"
183 " idx=%u [0x%" PRIxPTR ", 0x%" PRIxPTR ") lkey=0x%x",
184 (void *)bt, idx, entry->start, entry->end, entry->lkey);
185 /* Already exist, return. */
186 return 0;
187 }
188 /* Caller must ensure that there is enough place for a new entry. */
189 MLX5_ASSERT(bt->len < bt->size);
190 /* Insert entry. */
191 ++idx;
192 shift = (bt->len - idx) * sizeof(struct mr_cache_entry);
193 if (shift)
194 memmove(&lkp_tbl[idx + 1], &lkp_tbl[idx], shift);
195 lkp_tbl[idx] = *entry;
196 bt->len++;
197 DRV_LOG(DEBUG,
198 "inserted B-tree(%p)[%u],"
199 " [0x%" PRIxPTR ", 0x%" PRIxPTR ") lkey=0x%x",
200 (void *)bt, idx, entry->start, entry->end, entry->lkey);
201 return 0;
202}
203
204/**
205 * Initialize B-tree and allocate memory for lookup table.

Callers 5

mlx5_mr_insert_cacheFunction · 0.70
mlx5_mr_create_primaryFunction · 0.70
mr_lookup_cachesFunction · 0.70
mlx5_lookup_mempool_regsFunction · 0.70

Calls 2

mr_btree_lookupFunction · 0.70
memmoveFunction · 0.50

Tested by

no test coverage detected