[dpdk]rte_mempool_ops_table
定義
/* /lib/librte_mempool/rte_mempool_ops.c */ struct rte_mempool_ops_table rte_mempool_ops_table = {.sl = RTE_SPINLOCK_INITIALIZER,.num_ops = 0 }; /* lib/librte_mempool/rte_mempool.h*/ struct rte_mempool_ops_table {rte_spinlock_t sl; /**< Spinlock for add/delete. */uint32_t num_ops; /**< Number of used ops structs in the table. *//*** Storage for all possible ops structs.*/struct rte_mempool_ops ops[RTE_MEMPOOL_MAX_OPS_IDX]; } __rte_cache_aligned;rte_mempool_ops_table 作為全局變量,內(nèi)部ops數(shù)組存儲已注冊的ops信息,ops包括操作內(nèi)存池的一系列(alloc、free、dequeue、enqueue)函數(shù)指針。每個進(jìn)程內(nèi)部都有存儲 ops 數(shù)組,這樣mempool 可以在主進(jìn)程和輔助進(jìn)程之間共享(自己未這樣使用過)。訪問ops 數(shù)組的索引在進(jìn)程之間是有效的,但是mempool結(jié)構(gòu)里直接存儲的函數(shù)指針,在進(jìn)程間未必是有效的。這就導(dǎo)致我們在mempool結(jié)構(gòu)體內(nèi)有個"ops_index" 的變量。
ops數(shù)組的初始化
/* /drivers/mempool/ring/rte_mempool_ring.c */MEMPOOL_REGISTER_OPS(ops_mp_mc); MEMPOOL_REGISTER_OPS(ops_sp_sc); MEMPOOL_REGISTER_OPS(ops_mp_sc); MEMPOOL_REGISTER_OPS(ops_sp_mc); MEMPOOL_REGISTER_OPS(ops_mt_rts); MEMPOOL_REGISTER_OPS(ops_mt_hts);static const struct rte_mempool_ops ops_mp_mc = {.name = "ring_mp_mc",.alloc = common_ring_alloc,.free = common_ring_free,.enqueue = common_ring_mp_enqueue,.dequeue = common_ring_mc_dequeue,.get_count = common_ring_get_count, };/* /lib/librte_mempool/rte_mempool.h */#define MEMPOOL_REGISTER_OPS(ops) \RTE_INIT(mp_hdlr_init_##ops) \{ \rte_mempool_register_ops(&ops); \}通過宏定義和 ops_mp_mc 的定義,在程序main函數(shù)執(zhí)行前完成ops數(shù)組的初始化。
如何設(shè)置mempool結(jié)構(gòu)體內(nèi)的“ops_index”
rte_mempool_create 的最后一個變量flag,可設(shè)置內(nèi)存池操作方式是否支持多 producer 和 多 consumer。未主動設(shè)置情況下,支持多 producer 和 多 consumer 。如此能確定 ops_index 對應(yīng) “ring_mp_mc” 的ops數(shù)組元素的下標(biāo)。
int rte_mempool_set_ops_byname(struct rte_mempool *mp, const char *name,void *pool_config) {struct rte_mempool_ops *ops = NULL;unsigned i;/* too late, the mempool is already populated. */if (mp->flags & MEMPOOL_F_POOL_CREATED)return -EEXIST;for (i = 0; i < rte_mempool_ops_table.num_ops; i++) {if (!strcmp(name,rte_mempool_ops_table.ops[i].name)) {ops = &rte_mempool_ops_table.ops[i];break;}}if (ops == NULL)return -EINVAL;mp->ops_index = i;mp->pool_config = pool_config;rte_mempool_trace_set_ops_byname(mp, name, pool_config);return 0; }總結(jié)
以上是生活随笔為你收集整理的[dpdk]rte_mempool_ops_table的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qualcomm msm8996 调试A
- 下一篇: 已解决idea连接数据库异常:Excep