Skip to content

Commit

Permalink
tx/st2110: fix redundant on tx_no_chain path (#542)
Browse files Browse the repository at this point in the history
use alloc + hdr init + payload copy

---------

Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx authored Oct 23, 2023
1 parent 63e83fa commit 6afb0f1
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 75 deletions.
2 changes: 1 addition & 1 deletion lib/src/dev/mt_af_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq,

uint32_t idx;
if (!xsk_ring_prod__reserve(pd, 1, &idx)) {
err("%s(%d, %u), socket_tx reserve fail\n", __func__, port, q);
dbg("%s(%d, %u), socket_tx reserve fail\n", __func__, port, q);
xq->stat_tx_prod_reserve_fail++;
rte_pktmbuf_free(local);
goto exit;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/mt_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ struct rte_mempool* mt_mempool_create_by_ops(struct mtl_main_impl* impl,
} else {
float size_m = (float)n * (data_room_size + priv_size) / (1024 * 1024);
info("%s(%d), succ at %p size %fm n %u d %u for %s\n", __func__, port, mbuf_pool,
size_m, n, element_size, name);
size_m, n, element_size, name_with_idx);
#ifdef MTL_HAS_ASAN
g_mt_mempool_create_cnt++;
#endif
Expand Down
3 changes: 3 additions & 0 deletions lib/src/st2110/st_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ enum sti_ret_code {
STI_FRAME_PKT_ALLOC_FAIL,
STI_FRAME_PKT_ENQUEUE_FAIL,
STI_FRAME_PKT_R_ENQUEUE_FAIL,
STI_FRAME_PKT_ALLOC_CHAIN_FAIL,
STI_FRAME_PKT_ALLOC_R_FAIL,
STI_FRAME_PKT_ALLOC_COPY_FAIL,
/* st rtp build stat */
STI_RTP_RING_FULL = 240,
STI_RTP_INFLIGHT_ENQUEUE_FAIL,
Expand Down
21 changes: 12 additions & 9 deletions lib/src/st2110/st_tx_ancillary_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,21 @@ static int tx_ancillary_sessions_tasklet_start(void* priv) {
}

static int tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl* s,
struct rte_mbuf* pkt) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*);
struct rte_mbuf* pkt_r,
const struct rte_mbuf* pkt_base) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*);
struct mt_udp_hdr* hdr_base = rte_pktmbuf_mtod(pkt_base, struct mt_udp_hdr*);
struct rte_ipv4_hdr* ipv4 = &hdr->ipv4;
struct rte_ipv4_hdr* ipv4_base = &hdr_base->ipv4;
struct rte_udp_hdr* udp = &hdr->udp;

/* update the hdr: eth, ip, udp */
rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_R].eth, sizeof(hdr->eth));
ipv4->src_addr = s->hdr[MTL_SESSION_PORT_R].ipv4.src_addr;
ipv4->dst_addr = s->hdr[MTL_SESSION_PORT_R].ipv4.dst_addr;
udp->src_port = s->hdr[MTL_SESSION_PORT_R].udp.src_port;
udp->dst_port = s->hdr[MTL_SESSION_PORT_R].udp.dst_port;
rte_memcpy(hdr, &s->hdr[MTL_SESSION_PORT_R], sizeof(*hdr));

ipv4->packet_id = ipv4_base->packet_id;
ipv4->total_length = htons(pkt_r->pkt_len - pkt_r->l2_len);

udp->dgram_len = htons(pkt_r->pkt_len - pkt_r->l2_len - pkt_r->l3_len);
if (!s->eth_ipv4_cksum_offload[MTL_SESSION_PORT_R]) {
/* generate cksum if no offload */
ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
Expand Down Expand Up @@ -835,7 +838,7 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl,
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
tx_ancillary_session_update_redundant(s, pkt_r);
tx_ancillary_session_update_redundant(s, pkt_r, pkt);
}
}

Expand Down Expand Up @@ -1000,7 +1003,7 @@ static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl* impl,
s->stat_build_ret_code = -STI_RTP_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
tx_ancillary_session_update_redundant(s, pkt_r);
tx_ancillary_session_update_redundant(s, pkt_r, pkt);
} else {
tx_ancillary_session_build_packet_chain(impl, s, pkt_r, pkt_rtp,
MTL_SESSION_PORT_R);
Expand Down
21 changes: 12 additions & 9 deletions lib/src/st2110/st_tx_audio_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,21 @@ static int tx_audio_sessions_tasklet_start(void* priv) {
}

static int tx_audio_session_update_redundant(struct st_tx_audio_session_impl* s,
struct rte_mbuf* pkt) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*);
struct rte_mbuf* pkt_r,
const struct rte_mbuf* pkt_base) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*);
struct mt_udp_hdr* hdr_base = rte_pktmbuf_mtod(pkt_base, struct mt_udp_hdr*);
struct rte_ipv4_hdr* ipv4 = &hdr->ipv4;
struct rte_ipv4_hdr* ipv4_base = &hdr_base->ipv4;
struct rte_udp_hdr* udp = &hdr->udp;

/* update the hdr: eth, ip, udp */
rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_R].eth, sizeof(hdr->eth));
ipv4->src_addr = s->hdr[MTL_SESSION_PORT_R].ipv4.src_addr;
ipv4->dst_addr = s->hdr[MTL_SESSION_PORT_R].ipv4.dst_addr;
udp->src_port = s->hdr[MTL_SESSION_PORT_R].udp.src_port;
udp->dst_port = s->hdr[MTL_SESSION_PORT_R].udp.dst_port;
rte_memcpy(hdr, &s->hdr[MTL_SESSION_PORT_R], sizeof(*hdr));

ipv4->packet_id = ipv4_base->packet_id;
ipv4->total_length = htons(pkt_r->pkt_len - pkt_r->l2_len);

udp->dgram_len = htons(pkt_r->pkt_len - pkt_r->l2_len - pkt_r->l3_len);
if (!s->eth_ipv4_cksum_offload[MTL_SESSION_PORT_R]) {
/* generate cksum if no offload */
ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
Expand Down Expand Up @@ -747,7 +750,7 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl,
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
tx_audio_session_update_redundant(s, pkt_r);
tx_audio_session_update_redundant(s, pkt_r, pkt);
}
}

Expand Down Expand Up @@ -918,7 +921,7 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl* impl,
s->stat_build_ret_code = -STI_RTP_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
tx_audio_session_update_redundant(s, pkt_r);
tx_audio_session_update_redundant(s, pkt_r, pkt);
} else {
tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, MTL_SESSION_PORT_R);
}
Expand Down
104 changes: 49 additions & 55 deletions lib/src/st2110/st_tx_video_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,23 +885,35 @@ static int tv_init_rtcp(struct mtl_main_impl* impl, struct st_tx_video_sessions_
return 0;
}

static int tv_update_redundant(struct st_tx_video_session_impl* s, struct rte_mbuf* pkt) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*);
static int tv_build_st20_redundant(struct st_tx_video_session_impl* s,
struct rte_mbuf* pkt_r,
const struct rte_mbuf* pkt_base) {
struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*);
struct mt_udp_hdr* hdr_base = rte_pktmbuf_mtod(pkt_base, struct mt_udp_hdr*);
struct rte_ipv4_hdr* ipv4 = &hdr->ipv4;
struct rte_ipv4_hdr* ipv4_base = &hdr_base->ipv4;
struct rte_udp_hdr* udp = &hdr->udp;

/* update the hdr: eth, ip, udp */
rte_memcpy(&hdr->eth, &s->s_hdr[MTL_SESSION_PORT_R].eth, sizeof(hdr->eth));
ipv4->src_addr = s->s_hdr[MTL_SESSION_PORT_R].ipv4.src_addr;
ipv4->dst_addr = s->s_hdr[MTL_SESSION_PORT_R].ipv4.dst_addr;
udp->src_port = s->s_hdr[MTL_SESSION_PORT_R].udp.src_port;
udp->dst_port = s->s_hdr[MTL_SESSION_PORT_R].udp.dst_port;

rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_R], sizeof(*hdr));
mt_mbuf_init_ipv4(pkt_r);
pkt_r->data_len = pkt_base->data_len;
pkt_r->pkt_len = pkt_r->data_len;
ipv4->packet_id = ipv4_base->packet_id;
ipv4->total_length = htons(pkt_r->pkt_len - pkt_r->l2_len);
udp->dgram_len = htons(pkt_r->pkt_len - pkt_r->l2_len - pkt_r->l3_len);
if (!s->eth_ipv4_cksum_offload[MTL_SESSION_PORT_R]) {
/* generate cksum if no offload */
ipv4->hdr_checksum = rte_ipv4_cksum(ipv4);
}

/* copy rtp and payload, assume it's only one segment */
size_t hdr_sz = sizeof(*hdr_base);
void* pd_base = rte_pktmbuf_mtod_offset(pkt_base, void*, hdr_sz);
void* pd_r = rte_pktmbuf_mtod_offset(pkt_r, void*, hdr_sz);
size_t pd_len = pkt_base->pkt_len - hdr_sz;
rte_memcpy(pd_r, pd_base, pd_len);

return 0;
}

Expand Down Expand Up @@ -1134,7 +1146,7 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb

static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl* s,
struct rte_mbuf* pkt_r,
struct rte_mbuf* pkt_base) {
const struct rte_mbuf* pkt_base) {
struct st_rfc4175_video_hdr* hdr;
struct st_rfc4175_video_hdr* hdr_base;
struct rte_ipv4_hdr* ipv4;
Expand Down Expand Up @@ -1775,18 +1787,19 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl,
if (ret < 0) {
dbg("%s(%d), pkts chain alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_CHAIN_FAIL;
return MT_TASKLET_ALL_DONE;
}
if (send_r) {
ret = rte_pktmbuf_alloc_bulk(hdr_pool_r, pkts_r, bulk);
if (ret < 0) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
rte_pktmbuf_free_bulk(pkts_chain, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
}

if (send_r) {
ret = rte_pktmbuf_alloc_bulk(hdr_pool_r, pkts_r, bulk);
if (ret < 0) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL;
return MT_TASKLET_ALL_DONE;
}
}

Expand All @@ -1807,23 +1820,12 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl,
pacing_set_mbuf_time_stamp(pkts[i], pacing);

if (send_r) {
if (s->tx_no_chain) {
pkts_r[i] = rte_pktmbuf_copy(pkts[i], hdr_pool_r, 0, UINT32_MAX);
if (pkts_r[i] == NULL) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
rte_pktmbuf_free_bulk(pkts_r, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
s->st20_pkt_idx -= i; /* todo: revert all status */
return MT_TASKLET_ALL_DONE;
}
}
st_tx_mbuf_set_priv(pkts_r[i], &s->st20_frames[s->st20_frame_idx]);
if (s->st20_pkt_idx >= s->st20_total_pkts) {
st_tx_mbuf_set_idx(pkts_r[i], ST_TX_DUMMY_PKT_IDX);
} else {
if (s->tx_no_chain) {
tv_update_redundant(s, pkts_r[i]);
tv_build_st20_redundant(s, pkts_r[i], pkts[i]);
} else
tv_build_st20_redundant_chain(s, pkts_r[i], pkts[i]);
st_tx_mbuf_set_idx(pkts_r[i], s->st20_pkt_idx);
Expand Down Expand Up @@ -2012,7 +2014,7 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl,

if (send_r) {
if (s->tx_no_chain) {
pkts_r[i] = rte_pktmbuf_copy(pkts[i], hdr_pool_r, 0, UINT32_MAX);
pkts_r[i] = rte_pktmbuf_alloc(hdr_pool_r);
if (pkts_r[i] == NULL) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
Expand All @@ -2021,7 +2023,7 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl,
s->st20_pkt_idx -= i; /* todo: revert all status */
return MT_TASKLET_ALL_DONE;
}
tv_update_redundant(s, pkts_r[i]);
tv_build_st20_redundant(s, pkts_r[i], pkts[i]);
} else
tv_build_rtp_redundant_chain(s, pkts_r[i], pkts[i]);
st_tx_mbuf_set_idx(pkts_r[i], s->st20_pkt_idx);
Expand Down Expand Up @@ -2232,18 +2234,19 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl,
if (ret < 0) {
dbg("%s(%d), pkts chain alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_CHAIN_FAIL;
return MT_TASKLET_ALL_DONE;
}
if (send_r) {
ret = rte_pktmbuf_alloc_bulk(hdr_pool_r, pkts_r, bulk);
if (ret < 0) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
rte_pktmbuf_free_bulk(pkts_chain, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL;
return MT_TASKLET_ALL_DONE;
}
}

if (send_r) {
ret = rte_pktmbuf_alloc_bulk(hdr_pool_r, pkts_r, bulk);
if (ret < 0) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL;
return MT_TASKLET_ALL_DONE;
}
}

Expand All @@ -2267,18 +2270,9 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl,
if (s->st20_pkt_idx >= st22_info->st22_total_pkts) {
st_tx_mbuf_set_idx(pkts_r[i], ST_TX_DUMMY_PKT_IDX);
} else {
if (s->tx_no_chain) {
pkts_r[i] = rte_pktmbuf_copy(pkts[i], hdr_pool_r, 0, UINT32_MAX);
if (pkts_r[i] == NULL) {
dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret);
rte_pktmbuf_free_bulk(pkts, bulk);
rte_pktmbuf_free_bulk(pkts_r, bulk);
s->stat_build_ret_code = -STI_ST22_PKT_ALLOC_FAIL;
s->st20_pkt_idx -= i; /* todo: revert all status */
return MT_TASKLET_ALL_DONE;
}
tv_update_redundant(s, pkts_r[i]);
} else
if (s->tx_no_chain)
tv_build_st20_redundant(s, pkts_r[i], pkts[i]);
else
tv_build_st22_redundant_chain(s, pkts_r[i], pkts[i]);
st_tx_mbuf_set_idx(pkts_r[i], s->st20_pkt_idx);
s->port_user_stats[MTL_SESSION_PORT_R].build++;
Expand Down
Loading

0 comments on commit 6afb0f1

Please sign in to comment.