From: Chengwen Feng Date: Wed, 21 Apr 2021 08:45:02 +0000 (+0800) Subject: app/testpmd: support cleanup Tx queue mbufs X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=bafe8a68f033e3d1fd3e7af7dad778b18daa06bc app/testpmd: support cleanup Tx queue mbufs This patch supports cleanup txq mbufs command: port cleanup (port_id) txq (queue_id) (free_cnt) Signed-off-by: Chengwen Feng Signed-off-by: Lijun Ou Reviewed-by: Ferruh Yigit --- diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 11f9c015c9..62caf7050a 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -908,6 +908,9 @@ static void cmd_help_long_parsed(void *parsed_result, " Register a dynf and Set/clear this flag on Tx. " "Testpmd will set this value to any Tx packet " "sent from this port\n\n" + + "port cleanup (port_id) txq (queue_id) (free_cnt)\n" + " Cleanup txq mbufs for a specific Tx queue\n\n" ); } @@ -2458,6 +2461,90 @@ cmdline_parse_inst_t cmd_config_rss_hash_key = { }, }; +/* *** cleanup txq mbufs *** */ +struct cmd_cleanup_txq_mbufs_result { + cmdline_fixed_string_t port; + cmdline_fixed_string_t keyword; + cmdline_fixed_string_t name; + uint16_t port_id; + uint16_t queue_id; + uint32_t free_cnt; +}; + +static void +cmd_cleanup_txq_mbufs_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_cleanup_txq_mbufs_result *res = parsed_result; + uint16_t port_id = res->port_id; + uint16_t queue_id = res->queue_id; + uint32_t free_cnt = res->free_cnt; + struct rte_eth_txq_info qinfo; + int ret; + + if (test_done == 0) { + printf("Please stop forwarding first\n"); + return; + } + + if (rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo)) { + printf("Failed to get port %u Tx queue %u info\n", + port_id, queue_id); + return; + } + + if (qinfo.queue_state != RTE_ETH_QUEUE_STATE_STARTED) { + printf("Tx queue %u not started\n", queue_id); + return; + } + + ret = rte_eth_tx_done_cleanup(port_id, queue_id, free_cnt); + if (ret < 0) { + printf("Failed to cleanup mbuf for port %u Tx queue %u " + "error desc: %s(%d)\n", + port_id, queue_id, strerror(-ret), ret); + return; + } + + printf("Cleanup port %u Tx queue %u mbuf nums: %u\n", + port_id, queue_id, ret); +} + +cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_port = + TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port, + "port"); +cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_cleanup = + TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, keyword, + "cleanup"); +cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, port_id, + RTE_UINT16); +cmdline_parse_token_string_t cmd_cleanup_txq_mbufs_txq = + TOKEN_STRING_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, name, + "txq"); +cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_queue_id = + TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, queue_id, + RTE_UINT16); +cmdline_parse_token_num_t cmd_cleanup_txq_mbufs_free_cnt = + TOKEN_NUM_INITIALIZER(struct cmd_cleanup_txq_mbufs_result, free_cnt, + RTE_UINT32); + +cmdline_parse_inst_t cmd_cleanup_txq_mbufs = { + .f = cmd_cleanup_txq_mbufs_parsed, + .data = NULL, + .help_str = "port cleanup txq ", + .tokens = { + (void *)&cmd_cleanup_txq_mbufs_port, + (void *)&cmd_cleanup_txq_mbufs_cleanup, + (void *)&cmd_cleanup_txq_mbufs_port_id, + (void *)&cmd_cleanup_txq_mbufs_txq, + (void *)&cmd_cleanup_txq_mbufs_queue_id, + (void *)&cmd_cleanup_txq_mbufs_free_cnt, + NULL, + }, +}; + /* *** configure port rxq/txq ring size *** */ struct cmd_config_rxtx_ring_size { cmdline_fixed_string_t port; @@ -17413,6 +17500,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_showport_rss_hash, (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, + (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs, (cmdline_parse_inst_t *)&cmd_dump, (cmdline_parse_inst_t *)&cmd_dump_one, #ifdef RTE_NET_I40E diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst index 11d3283730..80b0acaed4 100644 --- a/doc/guides/rel_notes/release_21_05.rst +++ b/doc/guides/rel_notes/release_21_05.rst @@ -233,6 +233,8 @@ New Features ``dpdk-testpmd -- --eth-link-speed N`` * Added command to display Rx queue used descriptor count. ``show port (port_id) rxq (queue_id) desc used count`` + * Added command to cleanup a Tx queue's mbuf on a port. + ``port cleanup (port_id) txq (queue_id) (free_cnt)`` * Added command to dump internal representation information of single flow. ``flow dump (port_id) rule (rule_id)`` * Added commands to create and delete meter policy. diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index dd362f9631..f9df1053e2 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -2436,6 +2436,15 @@ hash of input [IP] packets received on port:: ipv6-udp-ex ) +port cleanup txq mbufs +~~~~~~~~~~~~~~~~~~~~~~ + +To cleanup txq mbufs currently cached by driver:: + + testpmd> port cleanup (port_id) txq (queue_id) (free_cnt) + +If the value of ``free_cnt`` is 0, driver should free all cached mbufs. + Device Functions ----------------