From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id E1A92592C for ; Wed, 26 Nov 2014 22:23:22 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 26 Nov 2014 13:23:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,464,1413270000"; d="scan'208";a="638668267" Received: from irsmsx109.ger.corp.intel.com ([163.33.3.23]) by fmsmga002.fm.intel.com with ESMTP; 26 Nov 2014 13:23:20 -0800 Received: from irsmsx105.ger.corp.intel.com ([169.254.7.144]) by IRSMSX109.ger.corp.intel.com ([169.254.13.244]) with mapi id 14.03.0195.001; Wed, 26 Nov 2014 21:23:19 +0000 From: "Ananyev, Konstantin" To: Olivier Matz , "dev@dpdk.org" Thread-Topic: [PATCH v4 12/13] testpmd: support TSO in csum forward engine Thread-Index: AQHQCYqFxMfAbGP8+UiGADbwk8GMLJxzaxIQ Date: Wed, 26 Nov 2014 21:23:18 +0000 Message-ID: <2601191342CEEE43887BDE71AB977258213BAABB@IRSMSX105.ger.corp.intel.com> References: <1416524335-22753-1-git-send-email-olivier.matz@6wind.com> <1417014295-29064-1-git-send-email-olivier.matz@6wind.com> <1417014295-29064-13-git-send-email-olivier.matz@6wind.com> In-Reply-To: <1417014295-29064-13-git-send-email-olivier.matz@6wind.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "jigsaw@gmail.com" Subject: Re: [dpdk-dev] [PATCH v4 12/13] testpmd: support TSO in csum forward engine 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: Wed, 26 Nov 2014 21:23:23 -0000 > From: Olivier Matz [mailto:olivier.matz@6wind.com] > Sent: Wednesday, November 26, 2014 3:05 PM > To: dev@dpdk.org > Cc: olivier.matz@6wind.com; Walukiewicz, Miroslaw; Liu, Jijiang; Liu, Yon= g; jigsaw@gmail.com; Richardson, Bruce; Ananyev, Konstantin > Subject: [PATCH v4 12/13] testpmd: support TSO in csum forward engine >=20 > Add two new commands in testpmd: >=20 > - tso set > - tso show >=20 > These commands can be used enable TSO when transmitting TCP packets in > the csum forward engine. Ex: >=20 > set fwd csum > tx_checksum set ip hw 0 > tso set 800 0 > start >=20 > Signed-off-by: Olivier Matz Acked-by: Konstantin Ananyev > --- > app/test-pmd/cmdline.c | 92 +++++++++++++++++++++++++++++++++++++++++++= ++++++ > app/test-pmd/csumonly.c | 64 ++++++++++++++++++++++++---------- > app/test-pmd/testpmd.h | 1 + > 3 files changed, 139 insertions(+), 18 deletions(-) >=20 > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c > index 722cd76..2a8c260 100644 > --- a/app/test-pmd/cmdline.c > +++ b/app/test-pmd/cmdline.c > @@ -329,6 +329,14 @@ static void cmd_help_long_parsed(void *parsed_result= , > "tx_checksum show (port_id)\n" > " Display tx checksum offload configuration\n\n" >=20 > + "tso set (segsize) (portid)\n" > + " Enable TCP Segmentation Offload in csum forward" > + " engine.\n" > + " Please check the NIC datasheet for HW limits.\n\n" > + > + "tso show (portid)" > + " Display the status of TCP Segmentation Offload.\n\n" > + > "set fwd (%s)\n" > " Set packet forwarding mode.\n\n" >=20 > @@ -2984,6 +2992,88 @@ cmdline_parse_inst_t cmd_tx_cksum_show =3D { > }, > }; >=20 > +/* *** ENABLE HARDWARE SEGMENTATION IN TX PACKETS *** */ > +struct cmd_tso_set_result { > + cmdline_fixed_string_t tso; > + cmdline_fixed_string_t mode; > + uint16_t tso_segsz; > + uint8_t port_id; > +}; > + > +static void > +cmd_tso_set_parsed(void *parsed_result, > + __attribute__((unused)) struct cmdline *cl, > + __attribute__((unused)) void *data) > +{ > + struct cmd_tso_set_result *res =3D parsed_result; > + struct rte_eth_dev_info dev_info; > + > + if (port_id_is_invalid(res->port_id)) > + return; > + > + if (!strcmp(res->mode, "set")) > + ports[res->port_id].tso_segsz =3D res->tso_segsz; > + > + if (ports[res->port_id].tso_segsz =3D=3D 0) > + printf("TSO is disabled\n"); > + else > + printf("TSO segment size is %d\n", > + ports[res->port_id].tso_segsz); > + > + /* display warnings if configuration is not supported by the NIC */ > + rte_eth_dev_info_get(res->port_id, &dev_info); > + if ((ports[res->port_id].tso_segsz !=3D 0) && > + (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_TCP_TSO) =3D=3D 0) { > + printf("Warning: TSO enabled but not " > + "supported by port %d\n", res->port_id); > + } > +} > + > +cmdline_parse_token_string_t cmd_tso_set_tso =3D > + TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, > + tso, "tso"); > +cmdline_parse_token_string_t cmd_tso_set_mode =3D > + TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, > + mode, "set"); > +cmdline_parse_token_num_t cmd_tso_set_tso_segsz =3D > + TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, > + tso_segsz, UINT16); > +cmdline_parse_token_num_t cmd_tso_set_portid =3D > + TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, > + port_id, UINT8); > + > +cmdline_parse_inst_t cmd_tso_set =3D { > + .f =3D cmd_tso_set_parsed, > + .data =3D NULL, > + .help_str =3D "Set TSO segment size for csum engine (0 to disable): " > + "tso set ", > + .tokens =3D { > + (void *)&cmd_tso_set_tso, > + (void *)&cmd_tso_set_mode, > + (void *)&cmd_tso_set_tso_segsz, > + (void *)&cmd_tso_set_portid, > + NULL, > + }, > +}; > + > +cmdline_parse_token_string_t cmd_tso_show_mode =3D > + TOKEN_STRING_INITIALIZER(struct cmd_tso_set_result, > + mode, "show"); > + > + > +cmdline_parse_inst_t cmd_tso_show =3D { > + .f =3D cmd_tso_set_parsed, > + .data =3D NULL, > + .help_str =3D "Show TSO segment size for csum engine: " > + "tso show ", > + .tokens =3D { > + (void *)&cmd_tso_set_tso, > + (void *)&cmd_tso_show_mode, > + (void *)&cmd_tso_set_portid, > + NULL, > + }, > +}; > + > /* *** ENABLE/DISABLE FLUSH ON RX STREAMS *** */ > struct cmd_set_flush_rx { > cmdline_fixed_string_t set; > @@ -8660,6 +8750,8 @@ cmdline_parse_ctx_t main_ctx[] =3D { > (cmdline_parse_inst_t *)&cmd_tx_vlan_set_pvid, > (cmdline_parse_inst_t *)&cmd_tx_cksum_set, > (cmdline_parse_inst_t *)&cmd_tx_cksum_show, > + (cmdline_parse_inst_t *)&cmd_tso_set, > + (cmdline_parse_inst_t *)&cmd_tso_show, > (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/csumonly.c b/app/test-pmd/csumonly.c > index 9a5408e..490342f 100644 > --- a/app/test-pmd/csumonly.c > +++ b/app/test-pmd/csumonly.c > @@ -88,12 +88,12 @@ > #endif >=20 > static uint16_t > -get_psd_sum(void *l3_hdr, uint16_t ethertype) > +get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags) > { > if (ethertype =3D=3D _htons(ETHER_TYPE_IPv4)) > - return rte_ipv4_phdr_cksum(l3_hdr); > + return rte_ipv4_phdr_cksum(l3_hdr, ol_flags); > else /* assume ethertype =3D=3D ETHER_TYPE_IPv6 */ > - return rte_ipv6_phdr_cksum(l3_hdr); > + return rte_ipv6_phdr_cksum(l3_hdr, ol_flags); > } >=20 > static uint16_t > @@ -108,14 +108,15 @@ get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uin= t16_t ethertype) > /* > * Parse an ethernet header to fill the ethertype, l2_len, l3_len and > * ipproto. This function is able to recognize IPv4/IPv6 with one option= al vlan > - * header. > + * header. The l4_len argument is only set in case of TCP (useful for TS= O). > */ > static void > parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t = *l2_len, > - uint16_t *l3_len, uint8_t *l4_proto) > + uint16_t *l3_len, uint8_t *l4_proto, uint16_t *l4_len) > { > struct ipv4_hdr *ipv4_hdr; > struct ipv6_hdr *ipv6_hdr; > + struct tcp_hdr *tcp_hdr; >=20 > *l2_len =3D sizeof(struct ether_hdr); > *ethertype =3D eth_hdr->ether_type; > @@ -143,6 +144,14 @@ parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *= ethertype, uint16_t *l2_len, > *l4_proto =3D 0; > break; > } > + > + if (*l4_proto =3D=3D IPPROTO_TCP) { > + tcp_hdr =3D (struct tcp_hdr *)((char *)eth_hdr + > + *l2_len + *l3_len); > + *l4_len =3D (tcp_hdr->data_off & 0xf0) >> 2; > + } > + else > + *l4_len =3D 0; > } >=20 > /* modify the IPv4 or IPv4 source address of a packet */ > @@ -165,7 +174,7 @@ change_ip_addresses(void *l3_hdr, uint16_t ethertype) > * depending on the testpmd command line configuration */ > static uint64_t > process_inner_cksums(void *l3_hdr, uint16_t ethertype, uint16_t l3_len, > - uint8_t l4_proto, uint16_t testpmd_ol_flags) > + uint8_t l4_proto, uint16_t tso_segsz, uint16_t testpmd_ol_flags) > { > struct ipv4_hdr *ipv4_hdr =3D l3_hdr; > struct udp_hdr *udp_hdr; > @@ -177,11 +186,16 @@ process_inner_cksums(void *l3_hdr, uint16_t etherty= pe, uint16_t l3_len, > ipv4_hdr =3D l3_hdr; > ipv4_hdr->hdr_checksum =3D 0; >=20 > - if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) > + if (tso_segsz !=3D 0 && l4_proto =3D=3D IPPROTO_TCP) { > ol_flags |=3D PKT_TX_IP_CKSUM; > - else > - ipv4_hdr->hdr_checksum =3D rte_ipv4_cksum(ipv4_hdr); > - > + } > + else { > + if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM) > + ol_flags |=3D PKT_TX_IP_CKSUM; > + else > + ipv4_hdr->hdr_checksum =3D > + rte_ipv4_cksum(ipv4_hdr); > + } > ol_flags |=3D PKT_TX_IPV4; > } > else if (ethertype =3D=3D _htons(ETHER_TYPE_IPv6)) > @@ -197,7 +211,7 @@ process_inner_cksums(void *l3_hdr, uint16_t ethertype= , uint16_t l3_len, > if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) { > ol_flags |=3D PKT_TX_UDP_CKSUM; > udp_hdr->dgram_cksum =3D get_psd_sum(l3_hdr, > - ethertype); > + ethertype, ol_flags); > } > else { > udp_hdr->dgram_cksum =3D > @@ -209,9 +223,13 @@ process_inner_cksums(void *l3_hdr, uint16_t ethertyp= e, uint16_t l3_len, > else if (l4_proto =3D=3D IPPROTO_TCP) { > tcp_hdr =3D (struct tcp_hdr *)((char *)l3_hdr + l3_len); > tcp_hdr->cksum =3D 0; > - if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) { > + if (tso_segsz !=3D 0) { > + ol_flags |=3D PKT_TX_TCP_SEG; > + tcp_hdr->cksum =3D get_psd_sum(l3_hdr, ethertype, ol_flags); > + } > + else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) { > ol_flags |=3D PKT_TX_TCP_CKSUM; > - tcp_hdr->cksum =3D get_psd_sum(l3_hdr, ethertype); > + tcp_hdr->cksum =3D get_psd_sum(l3_hdr, ethertype, ol_flags); > } > else { > tcp_hdr->cksum =3D > @@ -282,6 +300,8 @@ process_outer_cksums(void *outer_l3_hdr, uint16_t out= er_ethertype, > * - modify the IPs in inner headers and in outer headers if any > * - reprocess the checksum of all supported layers. This is done in SW > * or HW, depending on testpmd command line configuration > + * - if TSO is enabled in testpmd command line, also flag the mbuf for = TCP > + * segmentation offload (this implies HW TCP checksum) > * Then transmit packets on the output port. > * > * (1) Supported packets are: > @@ -312,7 +332,9 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) > uint16_t testpmd_ol_flags; > uint8_t l4_proto; > uint16_t ethertype =3D 0, outer_ethertype =3D 0; > - uint16_t l2_len =3D 0, l3_len =3D 0, outer_l2_len =3D 0, outer_l3_len = =3D 0; > + uint16_t l2_len =3D 0, l3_len =3D 0, l4_len =3D 0; > + uint16_t outer_l2_len =3D 0, outer_l3_len =3D 0; > + uint16_t tso_segsz; > int tunnel =3D 0; > uint32_t rx_bad_ip_csum; > uint32_t rx_bad_l4_csum; > @@ -342,6 +364,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) >=20 > txp =3D &ports[fs->tx_port]; > testpmd_ol_flags =3D txp->tx_ol_flags; > + tso_segsz =3D txp->tso_segsz; >=20 > for (i =3D 0; i < nb_rx; i++) { >=20 > @@ -357,7 +380,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) > * and inner headers */ >=20 > eth_hdr =3D rte_pktmbuf_mtod(m, struct ether_hdr *); > - parse_ethernet(eth_hdr, ðertype, &l2_len, &l3_len, &l4_proto); > + parse_ethernet(eth_hdr, ðertype, &l2_len, &l3_len, > + &l4_proto, &l4_len); > l3_hdr =3D (char *)eth_hdr + l2_len; >=20 > /* check if it's a supported tunnel (only vxlan for now) */ > @@ -385,7 +409,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) > sizeof(struct vxlan_hdr)); >=20 > parse_ethernet(eth_hdr, ðertype, &l2_len, > - &l3_len, &l4_proto); > + &l3_len, &l4_proto, &l4_len); > l3_hdr =3D (char *)eth_hdr + l2_len; > } > } > @@ -399,11 +423,12 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) >=20 > /* step 3: depending on user command line configuration, > * recompute checksum either in software or flag the > - * mbuf to offload the calculation to the NIC */ > + * mbuf to offload the calculation to the NIC. If TSO > + * is configured, prepare the mbuf for TCP segmentation. */ >=20 > /* process checksums of inner headers first */ > ol_flags |=3D process_inner_cksums(l3_hdr, ethertype, > - l3_len, l4_proto, testpmd_ol_flags); > + l3_len, l4_proto, tso_segsz, testpmd_ol_flags); >=20 > /* Then process outer headers if any. Note that the software > * checksum will be wrong if one of the inner checksums is > @@ -432,6 +457,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) > sizeof(struct udp_hdr) + > sizeof(struct vxlan_hdr) + l2_len; > m->l3_len =3D l3_len; > + m->l4_len =3D l4_len; > } > } else { > /* this is only useful if an offload flag is > @@ -439,7 +465,9 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) > * case */ > m->l2_len =3D l2_len; > m->l3_len =3D l3_len; > + m->l4_len =3D l4_len; > } > + m->tso_segsz =3D tso_segsz; > m->ol_flags =3D ol_flags; >=20 > } > diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h > index 83311fa..16c6fbf 100644 > --- a/app/test-pmd/testpmd.h > +++ b/app/test-pmd/testpmd.h > @@ -149,6 +149,7 @@ struct rte_port { > struct fwd_stream *tx_stream; /**< Port TX stream, if unique */ > unsigned int socket_id; /**< For NUMA support */ > uint16_t tx_ol_flags;/**< TX Offload Flags (TESTPMD_TX_O= FFLOAD...). */ > + uint16_t tso_segsz; /**< MSS for segmentation offload. = */ > uint16_t tx_vlan_id; /**< Tag Id. in TX VLAN packets. */ > void *fwd_ctx; /**< Forwarding mode context */ > uint64_t rx_bad_ip_csum; /**< rx pkts with bad ip checks= um */ > -- > 2.1.0