app/testpmd: support cleanup Tx queue mbufs
authorChengwen Feng <fengchengwen@huawei.com>
Wed, 21 Apr 2021 08:45:02 +0000 (16:45 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 21 Apr 2021 11:25:19 +0000 (13:25 +0200)
This patch supports cleanup txq mbufs command:
port cleanup (port_id) txq (queue_id) (free_cnt)

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Signed-off-by: Lijun Ou <oulijun@huawei.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
app/test-pmd/cmdline.c
doc/guides/rel_notes/release_21_05.rst
doc/guides/testpmd_app_ug/testpmd_funcs.rst

index 11f9c01..62caf70 100644 (file)
@@ -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 <port_id> txq <queue_id> <free_cnt>",
+       .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
index 11d3283..80b0aca 100644 (file)
@@ -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.
index dd362f9..f9df105 100644 (file)
@@ -2436,6 +2436,15 @@ hash of input [IP] packets received on port::
                      ipv6-udp-ex <string of hex digits \
                      (variable length, NIC dependent)>)
 
+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
 ----------------