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

Function ntb_mbuf_pool_create

dpdk/examples/ntb/ntb_fwd.c:1093–1200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1091}
1092
1093static struct rte_mempool *
1094ntb_mbuf_pool_create(uint16_t mbuf_seg_size, uint32_t nb_mbuf,
1095 struct ntb_dev_info ntb_info,
1096 struct ntb_dev_config *ntb_conf,
1097 unsigned int socket_id)
1098{
1099 size_t mz_len, total_elt_sz, max_mz_len, left_sz;
1100 struct rte_pktmbuf_pool_private mbp_priv;
1101 char pool_name[RTE_MEMPOOL_NAMESIZE];
1102 char mz_name[RTE_MEMZONE_NAMESIZE];
1103 const struct rte_memzone *mz;
1104 struct rte_mempool *mp;
1105 uint64_t align;
1106 uint32_t mz_id;
1107 int ret;
1108
1109 snprintf(pool_name, sizeof(pool_name), "ntb_mbuf_pool_%u", socket_id);
1110 mp = rte_mempool_create_empty(pool_name, nb_mbuf,
1111 (mbuf_seg_size + sizeof(struct rte_mbuf)),
1112 MEMPOOL_CACHE_SIZE,
1113 sizeof(struct rte_pktmbuf_pool_private),
1114 socket_id, 0);
1115 if (mp == NULL)
1116 return NULL;
1117
1118 if (rte_mempool_set_ops_byname(mp, rte_mbuf_best_mempool_ops(), NULL)) {
1119 printf("error setting mempool handler\n");
1120 goto fail;
1121 }
1122
1123 memset(&mbp_priv, 0, sizeof(mbp_priv));
1124 mbp_priv.mbuf_data_room_size = mbuf_seg_size;
1125 mbp_priv.mbuf_priv_size = 0;
1126 rte_pktmbuf_pool_init(mp, &mbp_priv);
1127
1128 ntb_conf->mz_list = rte_zmalloc("ntb_memzone_list",
1129 sizeof(struct rte_memzone *) *
1130 ntb_info.mw_cnt, 0);
1131 if (ntb_conf->mz_list == NULL)
1132 goto fail;
1133
1134 /* Put ntb header on mw0. */
1135 if (ntb_info.mw_size[0] < ntb_info.ntb_hdr_size) {
1136 printf("mw0 (size: %" PRIu64 ") is not enough for ntb hdr"
1137 " (size: %u)\n", ntb_info.mw_size[0],
1138 ntb_info.ntb_hdr_size);
1139 goto fail;
1140 }
1141
1142 total_elt_sz = mp->header_size + mp->elt_size + mp->trailer_size;
1143 left_sz = total_elt_sz * nb_mbuf;
1144 for (mz_id = 0; mz_id < ntb_info.mw_cnt; mz_id++) {
1145 /* If populated mbuf is enough, no need to reserve extra mz. */
1146 if (!left_sz)
1147 break;
1148 snprintf(mz_name, sizeof(mz_name), "ntb_mw_%d", mz_id);
1149 align = ntb_info.mw_size_align ? ntb_info.mw_size[mz_id] :
1150 RTE_CACHE_LINE_SIZE;

Callers 1

mainFunction · 0.85

Calls 13

snprintfFunction · 0.85
rte_mempool_create_emptyFunction · 0.85
memsetFunction · 0.85
rte_pktmbuf_pool_initFunction · 0.85
rte_zmallocFunction · 0.85
rte_memzone_freeFunction · 0.85
rte_mempool_freeFunction · 0.85
rte_mempool_obj_iterFunction · 0.85

Tested by

no test coverage detected