DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ouyang Changchun <changchun.ouyang@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 3/3] testpmd: Add commands to test the functionality of setting TX rate for queue or VF
Date: Mon, 26 May 2014 15:45:31 +0800	[thread overview]
Message-ID: <1401090331-18455-4-git-send-email-changchun.ouyang@intel.com> (raw)
In-Reply-To: <1401090331-18455-1-git-send-email-changchun.ouyang@intel.com>

This patch adds commands in testpmd to test the functionality of setting TX rate for queue or VF.

Signed-off-by: Ouyang Changchun <changchun.ouyang@intel.com>
---
 app/test-pmd/cmdline.c | 159 ++++++++++++++++++++++++++++++++++++++++++++++++-
 app/test-pmd/config.c  |  47 +++++++++++++++
 app/test-pmd/testpmd.h |   3 +
 3 files changed, 208 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index b3824f9..83b2665 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -342,7 +342,14 @@ static void cmd_help_long_parsed(void *parsed_result,
 			"    BAM:accepts broadcast packets;"
 			"MPE:accepts all multicast packets\n\n"
 			"    Enable/Disable a VF receive mode of a port\n\n"
-			
+
+			"set port (port_id) queue (queue_id) rate (rate_num)\n"
+			"    Set rate limit for a queue of a port\n\n"
+
+			"set port (port_id) vf (vf_id) rate (rate_num) "
+			"queue_mask (queue_mask_value)\n"
+			"    Set rate limit for queues in VF of a port\n\n"
+
 			"set port (port_id) mirror-rule (rule_id)" 
 			"(pool-mirror|vlan-mirror)\n"
 			" (poolmask|vlanid[,vlanid]*) dst-pool (pool_id) (on|off)\n"
@@ -4790,6 +4797,154 @@ cmdline_parse_inst_t cmd_vf_rxvlan_filter = {
 	},
 };
 
+/* *** SET RATE LIMIT FOR A QUEUE OF A PORT *** */
+struct cmd_queue_rate_limit_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t port;
+	uint8_t port_num;
+	cmdline_fixed_string_t queue;
+	uint8_t queue_num;
+	cmdline_fixed_string_t rate;
+	uint16_t rate_num;
+};
+
+static void cmd_queue_rate_limit_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_queue_rate_limit_result *res = parsed_result;
+	int ret = 0;
+
+	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
+		&& (strcmp(res->queue, "queue") == 0)
+		&& (strcmp(res->rate, "rate") == 0))
+		ret = set_queue_rate_limit(res->port_num, res->queue_num,
+					res->rate_num);
+	if (ret < 0)
+		printf("queue_rate_limit_cmd error: (%s)\n", strerror(-ret));
+
+}
+
+cmdline_parse_token_string_t cmd_queue_rate_limit_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
+				set, "set");
+cmdline_parse_token_string_t cmd_queue_rate_limit_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
+				port, "port");
+cmdline_parse_token_num_t cmd_queue_rate_limit_portnum =
+	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
+				port_num, UINT8);
+cmdline_parse_token_string_t cmd_queue_rate_limit_queue =
+	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
+				queue, "queue");
+cmdline_parse_token_num_t cmd_queue_rate_limit_queuenum =
+	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
+				queue_num, UINT8);
+cmdline_parse_token_string_t cmd_queue_rate_limit_rate =
+	TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result,
+				rate, "rate");
+cmdline_parse_token_num_t cmd_queue_rate_limit_ratenum =
+	TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result,
+				rate_num, UINT16);
+
+cmdline_parse_inst_t cmd_queue_rate_limit = {
+	.f = cmd_queue_rate_limit_parsed,
+	.data = (void *)0,
+	.help_str = "set port X queue Y rate Z:(X = port number,"
+	"Y = queue number,Z = rate number)set rate limit for a queue on port X",
+	.tokens = {
+		(void *)&cmd_queue_rate_limit_set,
+		(void *)&cmd_queue_rate_limit_port,
+		(void *)&cmd_queue_rate_limit_portnum,
+		(void *)&cmd_queue_rate_limit_queue,
+		(void *)&cmd_queue_rate_limit_queuenum,
+		(void *)&cmd_queue_rate_limit_rate,
+		(void *)&cmd_queue_rate_limit_ratenum,
+		NULL,
+	},
+};
+
+
+/* *** SET RATE LIMIT FOR A VF OF A PORT *** */
+struct cmd_vf_rate_limit_result {
+	cmdline_fixed_string_t set;
+	cmdline_fixed_string_t port;
+	uint8_t port_num;
+	cmdline_fixed_string_t vf;
+	uint8_t vf_num;
+	cmdline_fixed_string_t rate;
+	uint16_t rate_num;
+	cmdline_fixed_string_t q_msk;
+	uint64_t q_msk_val;
+};
+
+static void cmd_vf_rate_limit_parsed(void *parsed_result,
+		__attribute__((unused)) struct cmdline *cl,
+		__attribute__((unused)) void *data)
+{
+	struct cmd_vf_rate_limit_result *res = parsed_result;
+	int ret = 0;
+
+	if ((strcmp(res->set, "set") == 0) && (strcmp(res->port, "port") == 0)
+		&& (strcmp(res->vf, "vf") == 0)
+		&& (strcmp(res->rate, "rate") == 0)
+		&& (strcmp(res->q_msk, "queue_mask") == 0))
+		ret = set_vf_rate_limit(res->port_num, res->vf_num,
+					res->rate_num, res->q_msk_val);
+	if (ret < 0)
+		printf("vf_rate_limit_cmd error: (%s)\n", strerror(-ret));
+
+}
+
+cmdline_parse_token_string_t cmd_vf_rate_limit_set =
+	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
+				set, "set");
+cmdline_parse_token_string_t cmd_vf_rate_limit_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
+				port, "port");
+cmdline_parse_token_num_t cmd_vf_rate_limit_portnum =
+	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
+				port_num, UINT8);
+cmdline_parse_token_string_t cmd_vf_rate_limit_vf =
+	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
+				vf, "vf");
+cmdline_parse_token_num_t cmd_vf_rate_limit_vfnum =
+	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
+				vf_num, UINT8);
+cmdline_parse_token_string_t cmd_vf_rate_limit_rate =
+	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
+				rate, "rate");
+cmdline_parse_token_num_t cmd_vf_rate_limit_ratenum =
+	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
+				rate_num, UINT16);
+cmdline_parse_token_string_t cmd_vf_rate_limit_q_msk =
+	TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result,
+				q_msk, "queue_mask");
+cmdline_parse_token_num_t cmd_vf_rate_limit_q_msk_val =
+	TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result,
+				q_msk_val, UINT64);
+
+cmdline_parse_inst_t cmd_vf_rate_limit = {
+	.f = cmd_vf_rate_limit_parsed,
+	.data = (void *)0,
+	.help_str = "set port X vf Y rate Z queue_mask V:(X = port number,"
+	"Y = VF number,Z = rate number, V = queue mask value)set rate limit "
+	"for queues of VF on port X",
+	.tokens = {
+		(void *)&cmd_vf_rate_limit_set,
+		(void *)&cmd_vf_rate_limit_port,
+		(void *)&cmd_vf_rate_limit_portnum,
+		(void *)&cmd_vf_rate_limit_vf,
+		(void *)&cmd_vf_rate_limit_vfnum,
+		(void *)&cmd_vf_rate_limit_rate,
+		(void *)&cmd_vf_rate_limit_ratenum,
+		(void *)&cmd_vf_rate_limit_q_msk,
+		(void *)&cmd_vf_rate_limit_q_msk_val,
+		NULL,
+	},
+};
+
+
 /* *** CONFIGURE VM MIRROR VLAN/POOL RULE *** */
 struct cmd_set_mirror_mask_result {
 	cmdline_fixed_string_t set;
@@ -5230,6 +5385,8 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_vf_mac_addr_filter ,
 	(cmdline_parse_inst_t *)&cmd_set_vf_traffic,
 	(cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter,
+	(cmdline_parse_inst_t *)&cmd_queue_rate_limit,
+	(cmdline_parse_inst_t *)&cmd_vf_rate_limit,
 	(cmdline_parse_inst_t *)&cmd_set_mirror_mask,
 	(cmdline_parse_inst_t *)&cmd_set_mirror_link,
 	(cmdline_parse_inst_t *)&cmd_reset_mirror_rule,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 20ad0a8..002bc50 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1731,3 +1731,50 @@ set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on)
 	       "diag=%d\n", port_id, diag);
 }
 
+int
+set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate)
+{
+	int diag;
+	struct rte_eth_link link;
+
+	if (port_id_is_invalid(port_id))
+		return 1;
+	rte_eth_link_get_nowait(port_id, &link);
+	if (rate > link.link_speed) {
+		printf("Invalid rate value:%u bigger than link speed: %u\n",
+			rate, link.link_speed);
+		return 1;
+	}
+	diag = rte_eth_set_queue_rate_limit(port_id, queue_idx, rate);
+	if (diag == 0)
+		return diag;
+	printf("rte_eth_set_queue_rate_limit for port_id=%d failed diag=%d\n",
+		port_id, diag);
+	return diag;
+}
+
+int
+set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk)
+{
+	int diag;
+	struct rte_eth_link link;
+
+	if (q_msk == 0)
+		return 0;
+
+	if (port_id_is_invalid(port_id))
+		return 1;
+	rte_eth_link_get_nowait(port_id, &link);
+	if (rate > link.link_speed) {
+		printf("Invalid rate value:%u bigger than link speed: %u\n",
+			rate, link.link_speed);
+		return 1;
+	}
+	diag = rte_eth_set_vf_rate_limit(port_id, vf, rate, q_msk);
+	if (diag == 0)
+		return diag;
+	printf("rte_eth_set_vf_rate_limit for port_id=%d failed diag=%d\n",
+		port_id, diag);
+	return diag;
+}
+
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 2bdb1a2..f3f8bc2 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -528,6 +528,9 @@ void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on);
 void set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, 
 		uint64_t vf_mask, uint8_t on);
 
+int set_queue_rate_limit(portid_t port_id, uint16_t queue_idx, uint16_t rate);
+int set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate,
+				uint64_t q_msk);
 /*
  * Work-around of a compilation error with ICC on invocations of the
  * rte_be_to_cpu_16() function.
-- 
1.9.0

  parent reply	other threads:[~2014-05-26  7:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26  7:45 [dpdk-dev] [PATCH v2 0/3] Support setting TX rate for queue and VF Ouyang Changchun
2014-05-26  7:45 ` [dpdk-dev] [PATCH v2 1/3] ether: Add API to support " Ouyang Changchun
2014-05-27 22:47   ` Thomas Monjalon
2014-06-05  3:30     ` Ouyang, Changchun
2014-06-10 23:02       ` Thomas Monjalon
2014-05-26  7:45 ` [dpdk-dev] [PATCH v2 2/3] ixgbe: Implement the functionality of setting TX rate for queue or VF in IXGBE PMD Ouyang Changchun
2014-05-26  7:45 ` Ouyang Changchun [this message]
2014-05-26 22:52 ` [dpdk-dev] [PATCH v2 0/3] Support setting TX rate for queue and VF Neil Horman
2014-06-05  3:11   ` Ouyang, Changchun
2014-06-05 11:01     ` Neil Horman
     [not found] ` <F52918179C57134FAEC9EA62FA2F9625117C89F0@shsmsx102.ccr.corp.intel.com>
2014-06-05  5:32   ` Liu, Jijiang
2014-06-05 12:41 ` Cao, Waterman
2014-06-06  6:52 ` Xie, Huawei
2014-06-11 14:05   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401090331-18455-4-git-send-email-changchun.ouyang@intel.com \
    --to=changchun.ouyang@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).