From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id E6CF7AFD0 for ; Mon, 26 May 2014 09:45:39 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 26 May 2014 00:45:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,911,1392192000"; d="scan'208";a="517705879" Received: from shilc102.sh.intel.com ([10.239.39.44]) by orsmga001.jf.intel.com with ESMTP; 26 May 2014 00:45:49 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shilc102.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4Q7ji6L010540; Mon, 26 May 2014 15:45:46 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s4Q7jf8Y018577; Mon, 26 May 2014 15:45:43 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s4Q7jfYw018573; Mon, 26 May 2014 15:45:41 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Mon, 26 May 2014 15:45:31 +0800 Message-Id: <1401090331-18455-4-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1401090331-18455-1-git-send-email-changchun.ouyang@intel.com> References: <1401090331-18455-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v2 3/3] testpmd: Add commands to test the functionality of setting TX rate for queue or VF X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 May 2014 07:45:40 -0000 This patch adds commands in testpmd to test the functionality of setting TX rate for queue or VF. Signed-off-by: Ouyang Changchun --- 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