[dpdk-dev] [PATCH v3 3/3] app/testpmd: enable GRO feature

Wu, Jingjing jingjing.wu at intel.com
Wed Jun 7 11:24:58 CEST 2017



> -----Original Message-----
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Jiayu Hu
> Sent: Monday, April 24, 2017 4:10 PM
> To: dev at dpdk.org
> Cc: Ananyev, Konstantin <konstantin.ananyev at intel.com>; Wiles, Keith
> <keith.wiles at intel.com>; yuanhan.liu at linux.intel.com; Hu, Jiayu <jiayu.hu at intel.com>
> Subject: [dpdk-dev] [PATCH v3 3/3] app/testpmd: enable GRO feature
> 
> This patch demonstrates the usage of GRO library in testpmd. By default,
> GRO is turned off. Command, "gro on (port_id)", turns on GRO for the
> given port; command, "gro off (port_id)", turns off GRO for the given
> port. Note that, current GRO only supports TCP IPv4 packets.
> 
> Once the feature is turned on, all received packets are performed GRO
> procedure before returned from rte_eth_rx_burst.
> 
> Signed-off-by: Jiayu Hu <jiayu.hu at intel.com>
> ---
>  app/test-pmd/cmdline.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  app/test-pmd/config.c  | 26 ++++++++++++++++++++++++++
>  app/test-pmd/iofwd.c   |  1 +
>  app/test-pmd/testpmd.c |  5 +++++
>  app/test-pmd/testpmd.h |  3 +++
>  5 files changed, 80 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
> index f6bd75b..200ac3c 100644
> --- a/app/test-pmd/cmdline.c
> +++ b/app/test-pmd/cmdline.c
> @@ -76,6 +76,7 @@
>  #include <rte_devargs.h>
>  #include <rte_eth_ctrl.h>
>  #include <rte_flow.h>
> +#include <rte_gro.h>
> 
>  #include <cmdline_rdline.h>
>  #include <cmdline_parse.h>
> @@ -420,6 +421,9 @@ static void cmd_help_long_parsed(void *parsed_result,
>  			"tso show (portid)"
>  			"    Display the status of TCP Segmentation Offload.\n\n"
> 
> +			"gro (on|off) (port_id)"
> +			"    Enable or disable Generic Receive Offload.\n\n"
> +
>  			"set fwd (%s)\n"
>  			"    Set packet forwarding mode.\n\n"
> 
> @@ -3825,6 +3829,46 @@ cmdline_parse_inst_t cmd_tunnel_tso_show = {
>  	},
>  };
> 
> +/* *** SET GRO FOR A PORT *** */
> +struct cmd_gro_result {
> +	cmdline_fixed_string_t cmd_keyword;
> +	cmdline_fixed_string_t mode;
> +	uint8_t port_id;
> +};
> +
> +static void
> +cmd_set_gro_parsed(void *parsed_result,
> +		__attribute__((unused)) struct cmdline *cl,
> +		__attribute__((unused)) void *data)
> +{
> +	struct cmd_gro_result *res;
> +
> +	res = parsed_result;
> +	setup_gro(res->mode, res->port_id);
> +}
> +
> +cmdline_parse_token_string_t cmd_gro_keyword =
> +	TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
> +			cmd_keyword, "gro");
> +cmdline_parse_token_string_t cmd_gro_mode =
> +	TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
> +			mode, NULL);
You can define gro_mode like
cmdline_parse_token_string_t cmd_gro_mode =
	TOKEN_STRING_INITIALIZER(struct cmd_gro_result,
			mode, "on#off");
Then only two options are valid in this command.

> +cmdline_parse_token_num_t cmd_gro_pid =
> +	TOKEN_NUM_INITIALIZER(struct cmd_gro_result,
> +			port_id, UINT8);
> +
> +cmdline_parse_inst_t cmd_set_gro = {
> +	.f = cmd_set_gro_parsed,
> +	.data = NULL,
> +	.help_str = "gro (on|off) (port_id)",
> +	.tokens = {
> +		(void *)&cmd_gro_keyword,
> +		(void *)&cmd_gro_mode,
> +		(void *)&cmd_gro_pid,
> +		NULL,
> +	},
> +};
> +
>  /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */
>  struct cmd_set_flush_rx {
>  	cmdline_fixed_string_t set;
> @@ -13592,6 +13636,7 @@ cmdline_parse_ctx_t main_ctx[] = {
>  	(cmdline_parse_inst_t *)&cmd_tso_show,
>  	(cmdline_parse_inst_t *)&cmd_tunnel_tso_set,
>  	(cmdline_parse_inst_t *)&cmd_tunnel_tso_show,
> +	(cmdline_parse_inst_t *)&cmd_set_gro,
>  	(cmdline_parse_inst_t *)&cmd_link_flow_control_set,
>  	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx,
>  	(cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx,
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index ef07925..525f83b 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -97,6 +97,7 @@
>  #ifdef RTE_LIBRTE_IXGBE_PMD
>  #include <rte_pmd_ixgbe.h>
>  #endif
> +#include <rte_gro.h>
> 
>  #include "testpmd.h"
> 
> @@ -2423,6 +2424,31 @@ set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs)
>  	tx_pkt_nb_segs = (uint8_t) nb_segs;
>  }
> 
> +void
> +setup_gro(const char *mode, uint8_t port_id)
> +{
> +	if (!rte_eth_dev_is_valid_port(port_id)) {
> +		printf("invalid port id %u\n", port_id);
> +		return;
> +	}
> +	if (strcmp(mode, "on") == 0) {
> +		if (test_done == 0) {
> +			printf("before enable GRO,"
> +					" please stop forwarding first\n");
> +			return;
> +		}
> +		rte_gro_enable(port_id, rte_eth_dev_socket_id(port_id));
> +	} else if (strcmp(mode, "off") == 0) {
> +		if (test_done == 0) {
> +			printf("before disable GRO,"
> +					" please stop forwarding first\n");
> +			return;
> +		}
> +		rte_gro_disable(port_id);
> +	} else
> +		printf("unsupported GRO mode\n");

When you change gro mode to "on#off", then the else branch is not needed.
And you can move the checking of forwarding to the beginning of this function.

At last, you also need to update the testpmd doc: doc/guides/testpmd_app_ug/ due to new command line.

Thanks
Jingjing


More information about the dev mailing list