From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 9268CA054D;
	Tue,  7 Jun 2022 15:00:43 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 78E0142836;
	Tue,  7 Jun 2022 15:00:27 +0200 (CEST)
Received: from NAM12-DM6-obe.outbound.protection.outlook.com
 (mail-dm6nam12on2054.outbound.protection.outlook.com [40.107.243.54])
 by mails.dpdk.org (Postfix) with ESMTP id 361AC42836
 for <dev@dpdk.org>; Tue,  7 Jun 2022 15:00:26 +0200 (CEST)
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
 b=iJd17N5Hxju+NkwbiAa1fp5wOTIwUI81UdZhzafqBQMUkpj7VtYEn120Po6cQs0b6Uyb9UYbdjeVcHT42Fp4Way8K2nsNCUqAFW9+pJyIN2iEggo27mAWFxFSzQ19saF8gN6dPSdVRrqgqZw+b9dsd6zsdEEIVRFTxjfXKUOkof2O3w+w5g8mbHm1fuf+9pum4jYLkhwYKibS4YibiZXJGE/VVdYmhQqQzZEO4jW3P4NrqycNopIDTeZUcNv/k29N2CjqurCUwOiisM2Z0bw5H14j/PMmrT34hXZBo9k5n1fWxb03LgPG6hQOJwrkWnhlNMWSR7peKcw7Hn13JO8iA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; 
 s=arcselector9901;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
 bh=xWPWJshn+X4j5+Q6Z8Ju5taemn/MF653H3iICGlu0VY=;
 b=j3sgDjz7k7uK1U+H2dikpV9qUBlH655OhhlVfdfxhbBVL2Rj8wMC1AXh0ih1Q/TXiP/NeB1mhfUzwm4w8u4ABfSrHmyvUjikEGcLPMDL+ZaSggcC1kgDv3ex9z3clOM+LjQYXzu3cSJoL0ZHdjnMQNwf+MrBu/XGVKEzQ9iYrMRi69A4I0KkQz2jEXtyQMMfgs8d0uMPbryqfXWLPvLEKqjhp+T0FWb7TNBMO9BpnYUYyjVz8WyUpswvANoTQ5hSLmQ31dOCxo7FpAqgYkNZMkshOMepDbw4NthW7Q0bLtWUiXGZZZDlk+7IzgEIc2P4pTpIC3+PuqetYHrxikoGtg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 12.22.5.235) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com;
 dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com;
 dkim=none (message not signed); arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com;
 s=selector2;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=xWPWJshn+X4j5+Q6Z8Ju5taemn/MF653H3iICGlu0VY=;
 b=WgOh56z737aNN26CYaw+Xn9TWuQ5xCCSmXJdInlv6KwUmbfyEpLso5sauYJZ+w5B/r8rvo538X+jSlM1LEjUlEgLuwNyctOl8+WzIjFDGT5LqOCo1qAmA4fAVHJeLuu23P2/5qducV1QpSupFae6HTYiEQzPMU3x0ohbKvElnPqrJtubu0O2t11bc2MQdzTNc8I7xC9WCbrM4v/sx7Pcbr777wfpID/F949DXnXHPj3E3w8KqPPTtJly3P+3IRrDsKA4HSE+2tQZ5ZopheBxSSXqlB74lFjqVKW53Vg7Op8TepHZFoiPCxZFqDYazdBEPXAWHZtv6v90pIZV376wUQ==
Received: from MWHPR11CA0008.namprd11.prod.outlook.com (2603:10b6:301:1::18)
 by BL1PR12MB5173.namprd12.prod.outlook.com (2603:10b6:208:308::9) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.19; Tue, 7 Jun
 2022 13:00:23 +0000
Received: from CO1NAM11FT030.eop-nam11.prod.protection.outlook.com
 (2603:10b6:301:1:cafe::bd) by MWHPR11CA0008.outlook.office365.com
 (2603:10b6:301:1::18) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5314.12 via Frontend
 Transport; Tue, 7 Jun 2022 13:00:23 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235)
 smtp.mailfrom=nvidia.com; dkim=none (message not signed)
 header.d=none;dmarc=pass action=none header.from=nvidia.com;
Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates
 12.22.5.235 as permitted sender) receiver=protection.outlook.com;
 client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C
Received: from mail.nvidia.com (12.22.5.235) by
 CO1NAM11FT030.mail.protection.outlook.com (10.13.174.125) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id
 15.20.5314.12 via Frontend Transport; Tue, 7 Jun 2022 13:00:23 +0000
Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com
 (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32;
 Tue, 7 Jun 2022 13:00:22 +0000
Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com
 (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Tue, 7 Jun 2022
 06:00:18 -0700
From: Spike Du <spiked@nvidia.com>
To: <matan@nvidia.com>, <viacheslavo@nvidia.com>, <orika@nvidia.com>,
 <thomas@monjalon.net>, Xiaoyun Li <xiaoyun.li@intel.com>, Aman Singh
 <aman.deep.singh@intel.com>, Yuying Zhang <yuying.zhang@intel.com>
CC: <andrew.rybchenko@oktetlabs.ru>, <stephen@networkplumber.org>,
 <mb@smartsharesystems.com>, <dev@dpdk.org>, <rasland@nvidia.com>
Subject: [PATCH v5 7/7] app/testpmd: add Host Shaper command
Date: Tue, 7 Jun 2022 15:59:42 +0300
Message-ID: <20220607125942.241379-8-spiked@nvidia.com>
X-Mailer: git-send-email 2.27.0
In-Reply-To: <20220607125942.241379-1-spiked@nvidia.com>
References: <20220603124821.1148119-1-spiked@nvidia.com>
 <20220607125942.241379-1-spiked@nvidia.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain
X-Originating-IP: [10.126.231.35]
X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To
 rnnvmail201.nvidia.com (10.129.68.8)
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-Office365-Filtering-Correlation-Id: ec30bcad-4f16-4dd4-950f-08da4885af14
X-MS-TrafficTypeDiagnostic: BL1PR12MB5173:EE_
X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr
X-Microsoft-Antispam-PRVS: <BL1PR12MB5173FDF003C1D60D09FA2722A8A59@BL1PR12MB5173.namprd12.prod.outlook.com>
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;
X-Microsoft-Antispam-Message-Info: DFpCw7sCuTsxqeGqkLOrnvam4c688F50OcKcrTB/XugP+AW2IGfsA8Mg1TdVx6KYzIoO3otGg+KtIOrwVebP4M12ou17HYg8N5fr+mLTLaGEUoV3VTl0BpKn6Jap3HYRML0Gau8XhLRZMs/p++g5wazL/GiaUHgZ86OiSKCttRnS5SV2n9FTt0XlpsobK7+1SewvSyon8EvC1sVs/YL/ILOUdCUU0kgZexslMChFkEFK/TDf7BY3UO8/r1HXy0/4xJFWR33II+xeeHnN+SM549MB/EEk3UaB4s03mNCE+FWC55Ym6I31AKCXMo1bOqh66AgJaNr10fxnPtmcFtD7Z55ifJnKqWs2P3v0+yr46efnffr5mlk89hExlwkFdauO3sBUxLqtDu11E201nuVIBa7pOjyifg+21Dfw2cTnjfAq3O8DzrgAklsDGJgE2qQzBn1tWJX1KIgwspEiLHGlVePvxpH/lwz7ZuHDvO3OEgzBNKUd6CDE7E75VP8VZ0ILDg7Fizz7po12RpC7IxZXHFm8oJBb1ET+EXgSoi0/aEhjuYklJfB3xr06/Op+aVZod+TE/WQPFgS082iH78T7kw8mIifFw1dSCjtMAwfx6e3AZPFdmm3RKwU1ANnfU8vK2RJnI06vJHo58ZgSEWfqYcn2njQam67KJkBhnoM1/vxHf8jr6qSMXUzG2QYKKXwAyb0+3suuBmfP+bj8Hkoj1g==
X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:;
 IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE;
 SFS:(13230001)(4636009)(46966006)(40470700004)(36840700001)(508600001)(83380400001)(36756003)(6666004)(2906002)(6286002)(7696005)(336012)(107886003)(26005)(1076003)(186003)(8936002)(16526019)(47076005)(40460700003)(426003)(2616005)(86362001)(30864003)(36860700001)(82310400005)(5660300002)(356005)(316002)(81166007)(54906003)(110136005)(70586007)(70206006)(55016003)(8676002)(4326008)(36900700001);
 DIR:OUT; SFP:1101; 
X-OriginatorOrg: Nvidia.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jun 2022 13:00:23.0152 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: ec30bcad-4f16-4dd4-950f-08da4885af14
X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235];
 Helo=[mail.nvidia.com]
X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT030.eop-nam11.prod.protection.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5173
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

Add command line options to support host shaper configure.
- Command syntax:
  mlx5 set port <port_id> host_shaper avail_thresh_triggered <0|1> rate
<rate_num>

- Example commands:
To enable avail_thresh_triggered on port 1 and disable current host
shaper:
testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 1 rate 0

To disable avail_thresh_triggered and current host shaper on port 1:
testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 0 rate 0

The rate unit is 100Mbps.
To disable avail_thresh_triggered and configure a shaper of 5Gbps on
port 1:
testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 0 rate 50

Add sample code to handle rxq available descriptor threshold event, it
delays a while so that rxq empties, then disables host shaper and
rearms available descriptor threshold event.

Signed-off-by: Spike Du <spiked@nvidia.com>
---
 app/test-pmd/testpmd.c          |   6 ++
 doc/guides/nics/mlx5.rst        |  46 +++++++++
 drivers/net/mlx5/meson.build    |   4 +
 drivers/net/mlx5/mlx5_testpmd.c | 201 ++++++++++++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_testpmd.h |  26 ++++++
 5 files changed, 283 insertions(+)
 create mode 100644 drivers/net/mlx5/mlx5_testpmd.c
 create mode 100644 drivers/net/mlx5/mlx5_testpmd.h

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index 33d9b85..e15882d 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -69,6 +69,9 @@
 #ifdef RTE_NET_BOND
 #include <rte_eth_bond.h>
 #endif
+#ifdef RTE_NET_MLX5
+#include "mlx5_testpmd.h"
+#endif
 
 #include "testpmd.h"
 
@@ -3659,6 +3662,9 @@ struct pmd_test_command {
 				break;
 			printf("Received avail_thresh event, port:%d rxq_id:%d\n",
 			       port_id, rxq_id);
+#ifdef RTE_NET_MLX5
+			mlx5_test_avail_thresh_event_handler(port_id, rxq_id);
+#endif
 		}
 		break;
 	default:
diff --git a/doc/guides/nics/mlx5.rst b/doc/guides/nics/mlx5.rst
index a1e13e7..b5a3ee3 100644
--- a/doc/guides/nics/mlx5.rst
+++ b/doc/guides/nics/mlx5.rst
@@ -1727,3 +1727,49 @@ which can be installed from OFED mstflint package.
 Meson detects ``libmtcr_ul`` existence at configure stage.
 If the library is detected, the application must link with ``-lmtcr_ul``,
 as done by the pkg-config file libdpdk.pc.
+
+How to use available descriptor threshold and Host Shaper
+------------------------------
+
+There are sample command lines to configure available descriptor threshold in testpmd.
+Testpmd also contains sample logic to handle available descriptor threshold event.
+The typical workflow is: testpmd configure available descriptor threshold for Rx queues, enable
+avail_thresh_triggered in host shaper and register a callback, when traffic from host is
+too high and Rx queue emptiness is below available descriptor threshold, PMD receives an event and
+firmware configures a 100Mbps shaper on host port automatically, then PMD call
+the callback registered previously, which will delay a while to let Rx queue
+empty, then disable host shaper.
+
+Let's assume we have a simple Blue Field 2 setup: port 0 is uplink, port 1
+is VF representor. Each port has 2 Rx queues.
+In order to control traffic from host to ARM, we can enable available descriptor threshold in testpmd by:
+
+.. code-block:: console
+
+   testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 1 rate 0
+   testpmd> set port 1 rxq 0 avail_thresh 70
+   testpmd> set port 1 rxq 1 avail_thresh 70
+
+The first command disables current host shaper, and enables available descriptor threshold triggered mode.
+The left commands configure available descriptor threshold to 70% of Rx queue size for both Rx queues,
+When traffic from host is too high, you can see testpmd console prints log
+about available descriptor threshold event receiving, then host shaper is disabled.
+The traffic rate from host is controlled and less drop happens in Rx queues.
+
+When disable available descriptor threshold and avail_thresh_triggered, we can invoke below commands in testpmd:
+
+.. code-block:: console
+
+   testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 0 rate 0
+   testpmd> set port 1 rxq 0 avail_thresh 0
+   testpmd> set port 1 rxq 1 avail_thresh 0
+
+It's recommended an application disables available descriptor threshold and avail_thresh_triggered before exit,
+if it enables them before.
+
+We can also configure the shaper with a value, the rate unit is 100Mbps, below
+command sets current shaper to 5Gbps and disables avail_thresh_triggered.
+
+.. code-block:: console
+
+   testpmd> mlx5 set port 1 host_shaper avail_thresh_triggered 0 rate 50
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index 99210fd..941642b 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -68,4 +68,8 @@ if get_option('buildtype').contains('debug')
 else
     cflags += [ '-UPEDANTIC' ]
 endif
+
+testpmd_sources += files('mlx5_testpmd.c')
+testpmd_drivers_deps += 'net_mlx5'
+
 subdir(exec_env)
diff --git a/drivers/net/mlx5/mlx5_testpmd.c b/drivers/net/mlx5/mlx5_testpmd.c
new file mode 100644
index 0000000..071254a
--- /dev/null
+++ b/drivers/net/mlx5/mlx5_testpmd.c
@@ -0,0 +1,201 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 6WIND S.A.
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rte_prefetch.h>
+#include <rte_common.h>
+#include <rte_branch_prediction.h>
+#include <rte_ether.h>
+#include <rte_alarm.h>
+#include <rte_pmd_mlx5.h>
+#include <rte_ethdev.h>
+#include "mlx5_testpmd.h"
+#include "testpmd.h"
+
+static uint8_t host_shaper_avail_thresh_triggered[RTE_MAX_ETHPORTS];
+#define SHAPER_DISABLE_DELAY_US 100000 /* 100ms */
+
+/**
+ * Disable the host shaper and re-arm available descriptor threshold event.
+ *
+ * @param[in] args
+ *   uint32_t integer combining port_id and rxq_id.
+ */
+static void
+mlx5_test_host_shaper_disable(void *args)
+{
+	uint32_t port_rxq_id = (uint32_t)(uintptr_t)args;
+	uint16_t port_id = port_rxq_id & 0xffff;
+	uint16_t qid = (port_rxq_id >> 16) & 0xffff;
+	struct rte_eth_rxq_info qinfo;
+
+	printf("%s disable shaper\n", __func__);
+	if (rte_eth_rx_queue_info_get(port_id, qid, &qinfo)) {
+		printf("rx_queue_info_get returns error\n");
+		return;
+	}
+	/* Rearm the available descriptor threshold event. */
+	if (rte_eth_rx_avail_thresh_set(port_id, qid, qinfo.avail_thresh)) {
+		printf("config avail_thresh returns error\n");
+		return;
+	}
+	/* Only disable the shaper when avail_thresh_triggered is set. */
+	if (host_shaper_avail_thresh_triggered[port_id] &&
+	    rte_pmd_mlx5_host_shaper_config(port_id, 0, 0))
+		printf("%s disable shaper returns error\n", __func__);
+}
+
+void
+mlx5_test_avail_thresh_event_handler(uint16_t port_id, uint16_t rxq_id)
+{
+	uint32_t port_rxq_id = port_id | (rxq_id << 16);
+
+	rte_eal_alarm_set(SHAPER_DISABLE_DELAY_US,
+			  mlx5_test_host_shaper_disable,
+			  (void *)(uintptr_t)port_rxq_id);
+	printf("%s port_id:%u rxq_id:%u\n", __func__, port_id, rxq_id);
+}
+
+/**
+ * Configure host shaper's avail_thresh_triggered and current rate.
+ *
+ * @param[in] avail_thresh_triggered
+ *   Disable/enable avail_thresh_triggered.
+ * @param[in] rate
+ *   Configure current host shaper rate.
+ * @return
+ *   On success, returns 0.
+ *   On failure, returns < 0.
+ */
+static int
+mlx5_test_set_port_host_shaper(uint16_t port_id, uint16_t avail_thresh_triggered, uint8_t rate)
+{
+	struct rte_eth_link link;
+	bool port_id_valid = false;
+	uint16_t pid;
+	int ret;
+
+	RTE_ETH_FOREACH_DEV(pid)
+		if (port_id == pid) {
+			port_id_valid = true;
+			break;
+		}
+	if (!port_id_valid)
+		return -EINVAL;
+	ret = rte_eth_link_get_nowait(port_id, &link);
+	if (ret < 0)
+		return ret;
+	host_shaper_avail_thresh_triggered[port_id] = avail_thresh_triggered ? 1 : 0;
+	if (!avail_thresh_triggered) {
+		ret = rte_pmd_mlx5_host_shaper_config(port_id, 0,
+		RTE_BIT32(MLX5_HOST_SHAPER_FLAG_AVAIL_THRESH_TRIGGERED));
+	} else {
+		ret = rte_pmd_mlx5_host_shaper_config(port_id, 1,
+		RTE_BIT32(MLX5_HOST_SHAPER_FLAG_AVAIL_THRESH_TRIGGERED));
+	}
+	if (ret)
+		return ret;
+	ret = rte_pmd_mlx5_host_shaper_config(port_id, rate, 0);
+	if (ret)
+		return ret;
+	return 0;
+}
+
+/* *** SET HOST_SHAPER FOR A PORT *** */
+struct cmd_port_host_shaper_result {
+	cmdline_fixed_string_t mlx5;
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t port;
+	uint16_t port_num;
+	cmdline_fixed_string_t host_shaper;
+	cmdline_fixed_string_t avail_thresh_triggered;
+	uint16_t fr;
+	cmdline_fixed_string_t rate;
+	uint8_t rate_num;
+};
+
+static void cmd_port_host_shaper_parsed(void *parsed_result,
+		__rte_unused struct cmdline *cl,
+		__rte_unused void *data)
+{
+	struct cmd_port_host_shaper_result *res = parsed_result;
+	int ret = 0;
+
+	if ((strcmp(res->mlx5, "mlx5") == 0) &&
+	    (strcmp(res->set, "set") == 0) &&
+	    (strcmp(res->port, "port") == 0) &&
+	    (strcmp(res->host_shaper, "host_shaper") == 0) &&
+	    (strcmp(res->avail_thresh_triggered, "avail_thresh_triggered") == 0) &&
+	    (strcmp(res->rate, "rate") == 0))
+		ret = mlx5_test_set_port_host_shaper(res->port_num, res->fr,
+					   res->rate_num);
+	if (ret < 0)
+		printf("cmd_port_host_shaper error: (%s)\n", strerror(-ret));
+}
+
+cmdline_parse_token_string_t cmd_port_host_shaper_mlx5 =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				mlx5, "mlx5");
+cmdline_parse_token_string_t cmd_port_host_shaper_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				set, "set");
+cmdline_parse_token_string_t cmd_port_host_shaper_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				port, "port");
+cmdline_parse_token_num_t cmd_port_host_shaper_portnum =
+	TOKEN_NUM_INITIALIZER(struct cmd_port_host_shaper_result,
+				port_num, RTE_UINT16);
+cmdline_parse_token_string_t cmd_port_host_shaper_host_shaper =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				 host_shaper, "host_shaper");
+cmdline_parse_token_string_t cmd_port_host_shaper_avail_thresh_triggered =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				 avail_thresh_triggered, "avail_thresh_triggered");
+cmdline_parse_token_num_t cmd_port_host_shaper_fr =
+	TOKEN_NUM_INITIALIZER(struct cmd_port_host_shaper_result,
+			      fr, RTE_UINT16);
+cmdline_parse_token_string_t cmd_port_host_shaper_rate =
+	TOKEN_STRING_INITIALIZER(struct cmd_port_host_shaper_result,
+				 rate, "rate");
+cmdline_parse_token_num_t cmd_port_host_shaper_rate_num =
+	TOKEN_NUM_INITIALIZER(struct cmd_port_host_shaper_result,
+			      rate_num, RTE_UINT8);
+cmdline_parse_inst_t mlx5_test_cmd_port_host_shaper = {
+	.f = cmd_port_host_shaper_parsed,
+	.data = (void *)0,
+	.help_str = "mlx5 set port <port_id> host_shaper avail_thresh_triggered <0|1> "
+	"rate <rate_num>: Set HOST_SHAPER avail_thresh_triggered and rate with port_id",
+	.tokens = {
+		(void *)&cmd_port_host_shaper_mlx5,
+		(void *)&cmd_port_host_shaper_set,
+		(void *)&cmd_port_host_shaper_port,
+		(void *)&cmd_port_host_shaper_portnum,
+		(void *)&cmd_port_host_shaper_host_shaper,
+		(void *)&cmd_port_host_shaper_avail_thresh_triggered,
+		(void *)&cmd_port_host_shaper_fr,
+		(void *)&cmd_port_host_shaper_rate,
+		(void *)&cmd_port_host_shaper_rate_num,
+		NULL,
+	}
+};
+
+struct testpmd_driver_commands mlx5_driver_cmds = {
+	.commands = {
+		{
+			.ctx = &mlx5_test_cmd_port_host_shaper,
+			.help = "mlx5 set port (port_id) host_shaper avail_thresh_triggered (on|off)"
+			"rate (rate_num):\n"
+			"    Set HOST_SHAPER avail_thresh_triggered and rate with port_id\n\n",
+		},
+		{
+			.ctx = NULL,
+		},
+	}
+};
+TESTPMD_ADD_DRIVER_COMMANDS(mlx5_driver_cmds);
+
diff --git a/drivers/net/mlx5/mlx5_testpmd.h b/drivers/net/mlx5/mlx5_testpmd.h
new file mode 100644
index 0000000..7a54658
--- /dev/null
+++ b/drivers/net/mlx5/mlx5_testpmd.h
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2021 6WIND S.A.
+ * Copyright 2021 Mellanox Technologies, Ltd
+ */
+
+#ifndef RTE_PMD_MLX5_TEST_H_
+#define RTE_PMD_MLX5_TEST_H_
+
+#include <cmdline_parse.h>
+#include <cmdline_parse_num.h>
+#include <cmdline_parse_string.h>
+
+/**
+ * RTE_ETH_EVENT_RX_AVAIL_THRESH handler sample code.
+ * It's called in testpmd, the work flow here is delay a while until
+ * RX queueu is empty, then disable host shaper.
+ *
+ * @param[in] port_id
+ *   Port identifier.
+ * @param[in] rxq_id
+ *   Rx queue identifier.
+ */
+void
+mlx5_test_avail_thresh_event_handler(uint16_t port_id, uint16_t rxq_id);
+
+#endif
-- 
1.8.3.1