[dpdk]rte_mempool_ops_table
生活随笔
收集整理的這篇文章主要介紹了
[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 作為全局變量,內部ops數組存儲已注冊的ops信息,ops包括操作內存池的一系列(alloc、free、dequeue、enqueue)函數指針。每個進程內部都有存儲 ops 數組,這樣mempool 可以在主進程和輔助進程之間共享(自己未這樣使用過)。訪問ops 數組的索引在進程之間是有效的,但是mempool結構里直接存儲的函數指針,在進程間未必是有效的。這就導致我們在mempool結構體內有個"ops_index" 的變量。
ops數組的初始化
/* /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函數執行前完成ops數組的初始化。
如何設置mempool結構體內的“ops_index”
rte_mempool_create 的最后一個變量flag,可設置內存池操作方式是否支持多 producer 和 多 consumer。未主動設置情況下,支持多 producer 和 多 consumer 。如此能確定 ops_index 對應 “ring_mp_mc” 的ops數組元素的下標。
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; }總結
以上是生活随笔為你收集整理的[dpdk]rte_mempool_ops_table的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qualcomm msm8996 调试A
- 下一篇: 什么是蛋白质组学?