Skip to content

Commit

Permalink
tx/st2110: fix redundant on tx_no_chain path
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Du <[email protected]>
  • Loading branch information
frankdjx committed Oct 20, 2023
1 parent 63e83fa commit 19e24d0
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 39 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
46 changes: 27 additions & 19 deletions lib/src/st2110/st_tx_video_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,18 +885,21 @@ 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_update_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));

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 @@ -1134,7 +1137,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,7 +1778,7 @@ 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) {
Expand All @@ -1784,7 +1787,7 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl,
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;
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL;
return MT_TASKLET_ALL_DONE;
}
}
Expand All @@ -1808,12 +1811,17 @@ static int tv_tasklet_frame(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);
if (s->st20_pkt_idx >= s->st20_total_pkts) {
/* copy will fail for dummy since it's a zero pkt */
pkts_r[i] = rte_pktmbuf_alloc(hdr_pool_r);
} else {
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;
rte_pktmbuf_free_bulk(pkts_r, i);
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_COPY_FAIL;
s->st20_pkt_idx -= i; /* todo: revert all status */
return MT_TASKLET_ALL_DONE;
}
Expand All @@ -1823,7 +1831,7 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl,
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_update_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 @@ -2021,7 +2029,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_update_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,7 +2240,7 @@ 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) {
Expand All @@ -2241,7 +2249,7 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl,
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;
s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL;
return MT_TASKLET_ALL_DONE;
}
}
Expand Down Expand Up @@ -2273,11 +2281,11 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl,
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->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_COPY_FAIL;
s->st20_pkt_idx -= i; /* todo: revert all status */
return MT_TASKLET_ALL_DONE;
}
tv_update_redundant(s, pkts_r[i]);
tv_update_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);
Expand Down
102 changes: 102 additions & 0 deletions tests/script/native_af_xdp_json/loop_rtp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"interfaces": [
{
"name": "native_af_xdp:enp175s0f0np0",
},
{
"name": "native_af_xdp:enp175s0f1np1",
}
],
"tx_sessions": [
{
"dip": [
"local:1"
],
"interface": [
0
],
"video": [
{
"replicas": 1,
"type": "rtp",
"pacing": "gap",
"packing": "BPM",
"start_port": 20000,
"payload_type": 112,
"tr_offset": "default",
"video_format": "i1080p59",
"pg_format": "YUV_422_10bit",
"video_url": "./test.yuv"
}
],
"audio": [
{
"replicas": 1,
"type": "rtp",
"start_port": 30000,
"payload_type": 111,
"audio_format": "PCM16",
"audio_channel": ["ST"],
"audio_sampling": "48kHz",
"audio_ptime": "1",
"audio_url": "./test.wav"
}
],
"ancillary": [
{
"replicas": 1,
"start_port": 40000,
"payload_type": 113,
"type": "rtp",
"ancillary_format": "closed_caption",
"ancillary_url": "./test.txt",
"ancillary_fps": "p59"
}
]
}
],
"rx_sessions": [
{
"ip": [
"local:0"
],
"interface": [
1
],
"video": [
{
"replicas": 1,
"type": "rtp",
"pacing": "gap",
"start_port": 20000,
"payload_type": 112,
"tr_offset": "default",
"video_format": "i1080p59",
"pg_format": "YUV_422_10bit",
"display": false,
"measure_latency": true,
}
],
"audio": [
{
"replicas": 1,
"type": "rtp",
"start_port": 30000,
"payload_type": 111,
"audio_format": "PCM16",
"audio_channel": ["ST"],
"audio_sampling": "48kHz",
"audio_ptime": "1",
"audio_url": "./test.wav"
}
],
"ancillary": [
{
"replicas": 1,
"payload_type": 113,
"start_port": 40000
}
]
}
]
}
Loading

0 comments on commit 19e24d0

Please sign in to comment.