Skip to content

Commit

Permalink
inf: set tx sys mem pool size to (nb_tx_desc + 1024)
Browse files Browse the repository at this point in the history
Fix ptp mbuf alloc fail with "--ptp --nb_tx_desc 4096"

Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx committed Oct 23, 2023
1 parent 6afb0f1 commit 69af3e3
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions lib/src/dev/mt_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ static int dev_start_port(struct mt_interface* inf) {
struct rte_mempool* mbuf_pool;
for (uint16_t q = 0; q < nb_rx_q; q++) {
mbuf_pool = inf->rx_queues[q].mbuf_pool ? inf->rx_queues[q].mbuf_pool
: mt_get_rx_mempool(impl, port);
: mt_sys_rx_mempool(impl, port);
if (!mbuf_pool) {
err("%s(%d), no mbuf_pool for queue %d\n", __func__, port, q);
return -ENOMEM;
Expand Down Expand Up @@ -1138,7 +1138,7 @@ static int dev_start_port(struct mt_interface* inf) {

if (mt_has_virtio_user(impl, port)) {
mbuf_pool = inf->rx_queues[0].mbuf_pool ? inf->rx_queues[0].mbuf_pool
: mt_get_rx_mempool(impl, port);
: mt_sys_rx_mempool(impl, port);
ret = rte_eth_rx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL, mbuf_pool);
if (ret < 0) {
err("%s(%d), rte_eth_rx_queue_setup fail %d for virtio port\n", __func__, port,
Expand Down Expand Up @@ -2246,7 +2246,7 @@ int mt_dev_if_init(struct mtl_main_impl* impl) {
}

/* Create default mempool in memory to hold the system tx mbufs */
mbuf_elements = 1024;
mbuf_elements = inf->nb_tx_desc + 1024;
if (mt_has_tx_mono_pool(impl)) {
/* append as tx queues, double as tx ring */
mbuf_elements += inf->nb_tx_q * inf->nb_tx_desc * 2;
Expand All @@ -2271,7 +2271,7 @@ int mt_dev_if_init(struct mtl_main_impl* impl) {
}

inf->pad =
mt_build_pad(impl, mt_get_tx_mempool(impl, i), i, RTE_ETHER_TYPE_IPV4, 1024);
mt_build_pad(impl, mt_sys_tx_mempool(impl, i), i, RTE_ETHER_TYPE_IPV4, 1024);
if (!inf->pad) {
err("%s(%d), pad alloc fail\n", __func__, i);
mt_dev_if_uinit(impl);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/mt_arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static int arp_receive_request(struct mtl_main_impl* impl, struct rte_arp_hdr* r
return -EINVAL;
}

struct rte_mbuf* rpl_pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
struct rte_mbuf* rpl_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!rpl_pkt) {
err("%s(%d), rpl_pkt alloc fail\n", __func__, port);
return -ENOMEM;
Expand Down Expand Up @@ -132,7 +132,7 @@ static int arp_receive_reply(struct mtl_main_impl* impl, struct rte_arp_hdr* rep
}

static int arp_send_req(struct mtl_main_impl* impl, enum mtl_port port, uint32_t ip) {
struct rte_mbuf* req_pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
struct rte_mbuf* req_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!req_pkt) {
err("%s(%d), req_pkt malloc fail\n", __func__, port);
return -ENOMEM;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/mt_dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static int dhcp_send_discover(struct mtl_main_impl* impl, enum mtl_port port) {
uint8_t* options;
size_t hdr_offset = 0;

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s(%d), pkt alloc fail\n", __func__, port);
return -ENOMEM;
Expand Down Expand Up @@ -128,7 +128,7 @@ static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) {
uint8_t* options;
size_t hdr_offset = 0;

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s(%d), pkt alloc fail\n", __func__, port);
return -ENOMEM;
Expand Down Expand Up @@ -360,7 +360,7 @@ static int dhcp_send_release(struct mtl_main_impl* impl, enum mtl_port port) {
uint8_t* options;
size_t hdr_offset = 0;

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s(%d), pkt alloc fail\n", __func__, port);
return -ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/mt_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1523,12 +1523,12 @@ static inline uint32_t mt_sch_schedule_ns(struct mtl_main_impl* impl) {
return impl->sch_schedule_ns;
}

static inline struct rte_mempool* mt_get_tx_mempool(struct mtl_main_impl* impl,
static inline struct rte_mempool* mt_sys_tx_mempool(struct mtl_main_impl* impl,
enum mtl_port port) {
return mt_if(impl, port)->tx_mbuf_pool;
}

static inline struct rte_mempool* mt_get_rx_mempool(struct mtl_main_impl* impl,
static inline struct rte_mempool* mt_sys_rx_mempool(struct mtl_main_impl* impl,
enum mtl_port port) {
return mt_if(impl, port)->rx_mbuf_pool;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/mt_mcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int mcast_membership_general_query(struct mtl_main_impl* impl, enum mtl_port por
size_t hdr_offset = 0;
size_t mb_query_len = sizeof(struct mcast_mb_query_v3);

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s, report packet alloc failed\n", __func__);
return -ENOMEM;
Expand Down Expand Up @@ -142,7 +142,7 @@ static int mcast_membership_report(struct mtl_main_impl* impl,

dbg("%s(%d), group_num: %d\n", __func__, port, group_num);

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s, report packet alloc failed\n", __func__);
return -ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mt_ptp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp,
ptp->impl = impl;
ptp->port = port;
ptp->port_id = port_id;
ptp->mbuf_pool = mt_get_tx_mempool(impl, port);
ptp->mbuf_pool = mt_sys_tx_mempool(impl, port);
ptp->master_initialized = false;
ptp->t3_sequence_id = 0x1000 * port;
ptp->coefficient = 1.0;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mt_rtcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) {
if (now < rx->nacks_send_time) return 0;
rx->nacks_send_time = now + rx->nacks_send_interval;

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s(%s), pkt alloc fail\n", __func__, rx->name);
return -ENOMEM;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/st2110/st_tx_ancillary_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl,
port = mt_port_logic2phy(s->port_maps, i);

if (s->tx_mono_pool) {
s->mbuf_mempool_hdr[i] = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_hdr[i] = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono hdr mempool(%p) for port %d\n", __func__, idx,
s->mbuf_mempool_hdr[i], i);
} else if (s->mbuf_mempool_hdr[i]) {
Expand Down Expand Up @@ -1235,7 +1235,7 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl,
if (ops->type == ST40_TYPE_RTP_LEVEL) n += ops->rtp_ring_size;

if (s->tx_mono_pool) {
s->mbuf_mempool_chain = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono chain mempool(%p)\n", __func__, idx,
s->mbuf_mempool_chain);
} else if (s->mbuf_mempool_chain) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/st2110/st_tx_audio_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl,
for (int i = 0; i < num_port; i++) {
port = mt_port_logic2phy(s->port_maps, i);
if (s->tx_mono_pool) {
s->mbuf_mempool_hdr[i] = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_hdr[i] = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono hdr mempool(%p) for port %d\n", __func__, idx,
s->mbuf_mempool_hdr[i], i);
} else if (s->mbuf_mempool_hdr[i]) {
Expand Down Expand Up @@ -1239,7 +1239,7 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl,
if (ops->type == ST30_TYPE_RTP_LEVEL) n += ops->rtp_ring_size;

if (s->tx_mono_pool) {
s->mbuf_mempool_chain = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono chain mempool(%p)\n", __func__, idx,
s->mbuf_mempool_chain);
} else if (s->mbuf_mempool_chain) {
Expand Down
10 changes: 5 additions & 5 deletions lib/src/st2110/st_tx_video_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg
} else {
/* reuse rx mempool for zero copy */
if (mt_has_rx_mono_pool(impl))
s->mbuf_mempool_hdr[i] = mt_get_rx_mempool(impl, port);
s->mbuf_mempool_hdr[i] = mt_sys_rx_mempool(impl, port);
else
s->mbuf_mempool_hdr[i] = mt_if(impl, port)->rx_queues[queue_id].mbuf_pool;
info("%s(%d,%d), reuse rx mempool(%p) for port %d\n", __func__, mgr_idx, idx,
Expand All @@ -2453,7 +2453,7 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg
/* disable now, always use no zc mempool for the flush pad */
pad_mempool = s->mbuf_mempool_hdr[i];
} else {
pad_mempool = mt_get_tx_mempool(impl, port);
pad_mempool = mt_sys_tx_mempool(impl, port);
}
for (int j = 0; j < ST20_PKT_TYPE_MAX; j++) {
if (!s->st20_pkt_info[j].number) continue;
Expand Down Expand Up @@ -2547,7 +2547,7 @@ static int tv_mempool_init(struct mtl_main_impl* impl,
if (s->mbuf_mempool_reuse_rx[i]) {
s->mbuf_mempool_hdr[i] = NULL; /* reuse rx mempool for zero copy */
} else if (s->tx_mono_pool) {
s->mbuf_mempool_hdr[i] = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_hdr[i] = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono hdr mempool(%p) for port %d\n", __func__, idx,
s->mbuf_mempool_hdr[i], i);
} else {
Expand Down Expand Up @@ -2580,7 +2580,7 @@ static int tv_mempool_init(struct mtl_main_impl* impl,
if (ops->type == ST20_TYPE_RTP_LEVEL) n += ops->rtp_ring_size;

if (s->tx_mono_pool) {
s->mbuf_mempool_chain = mt_get_tx_mempool(impl, port);
s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port);
info("%s(%d), use tx mono chain mempool(%p)\n", __func__, idx,
s->mbuf_mempool_chain);
} else {
Expand Down Expand Up @@ -3712,7 +3712,7 @@ int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_i
struct st20_rfc4175_rtp_hdr* rtp;
struct rte_udp_hdr* udp;

pkt = rte_pktmbuf_alloc(mt_get_tx_mempool(impl, port));
pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port));
if (!pkt) {
err("%s(%d), pkt alloc fail\n", __func__, port);
return -ENOMEM;
Expand Down

0 comments on commit 69af3e3

Please sign in to comment.