From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 60AD093F4 for ; Mon, 16 Nov 2015 08:56:11 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP; 15 Nov 2015 23:56:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,301,1444719600"; d="scan'208";a="851633853" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga002.jf.intel.com with ESMTP; 15 Nov 2015 23:56:11 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 15 Nov 2015 23:56:08 -0800 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.248.2; Sun, 15 Nov 2015 23:56:08 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.83]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.193]) with mapi id 14.03.0248.002; Mon, 16 Nov 2015 15:56:06 +0800 From: "Liu, Jijiang" To: 'Yuanhan Liu' Thread-Topic: [dpdk-dev] [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib Thread-Index: AQHRHUK39XnQLzEnLkS31nlYOLgT556ZAb4AgAUyHoA= Date: Mon, 16 Nov 2015 07:56:06 +0000 Message-ID: <1ED644BD7E0A5F4091CF203DAFB8E4CC22BDBEA8@SHSMSX101.ccr.corp.intel.com> References: <1447330026-16685-1-git-send-email-jijiang.liu@intel.com> <1447330026-16685-2-git-send-email-jijiang.liu@intel.com> <20151113070158.GP2326@yliu-dev.sh.intel.com> In-Reply-To: <20151113070158.GP2326@yliu-dev.sh.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "dev@dpdk.org" Subject: Re: [dpdk-dev] [PATCH v5 1/4] vhost/lib: add vhost TX offload capabilities in vhost lib 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, 16 Nov 2015 07:56:12 -0000 Hi Yunhan, > -----Original Message----- > From: Yuanhan Liu [mailto:yuanhan.liu@linux.intel.com] > Sent: Friday, November 13, 2015 3:02 PM > To: Liu, Jijiang > Cc: dev@dpdk.org > Subject: Re: [dpdk-dev] [PATCH v5 1/4] vhost/lib: add vhost TX offload > capabilities in vhost lib >=20 > On Thu, Nov 12, 2015 at 08:07:03PM +0800, Jijiang Liu wrote: > > Add vhost TX offload(CSUM and TSO) support capabilities in vhost lib. > > > > Refer to feature bits in Virtual I/O Device (VIRTIO) Version 1.0 > > below, > > > > VIRTIO_NET_F_CSUM (0) Device handles packets with partial checksum. > This "checksum offload" is a common feature on modern network cards. > > VIRTIO_NET_F_HOST_TSO4 (11) Device can receive TSOv4. > > VIRTIO_NET_F_HOST_TSO6 (12) Device can receive TSOv6. > > > > In order to support these features, and the following changes are > > added, > > > > 1. Extend 'VHOST_SUPPORTED_FEATURES' macro to add the offload > features negotiation. > > > > 2. Dequeue TX offload: convert the fileds in virtio_net_hdr to the rela= ted > fileds in mbuf. > > > > > > Signed-off-by: Jijiang Liu > ... > > +static void > > +parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr) > > +{ > > + struct ipv4_hdr *ipv4_hdr; > > + struct ipv6_hdr *ipv6_hdr; > > + void *l3_hdr =3D NULL; > > + struct ether_hdr *eth_hdr; > > + uint16_t ethertype; > > + > > + eth_hdr =3D rte_pktmbuf_mtod(m, struct ether_hdr *); > > + > > + m->l2_len =3D sizeof(struct ether_hdr); > > + ethertype =3D rte_be_to_cpu_16(eth_hdr->ether_type); > > + > > + if (ethertype =3D=3D ETHER_TYPE_VLAN) { > > + struct vlan_hdr *vlan_hdr =3D (struct vlan_hdr *)(eth_hdr + 1); > > + > > + m->l2_len +=3D sizeof(struct vlan_hdr); > > + ethertype =3D rte_be_to_cpu_16(vlan_hdr->eth_proto); > > + } > > + > > + l3_hdr =3D (char *)eth_hdr + m->l2_len; > > + > > + switch (ethertype) { > > + case ETHER_TYPE_IPv4: > > + ipv4_hdr =3D (struct ipv4_hdr *)l3_hdr; > > + *l4_proto =3D ipv4_hdr->next_proto_id; > > + m->l3_len =3D (ipv4_hdr->version_ihl & 0x0f) * 4; > > + *l4_hdr =3D (char *)l3_hdr + m->l3_len; > > + m->ol_flags |=3D PKT_TX_IPV4; > > + break; > > + case ETHER_TYPE_IPv6: > > + ipv6_hdr =3D (struct ipv6_hdr *)l3_hdr; > > + *l4_proto =3D ipv6_hdr->proto; > > + m->l3_len =3D sizeof(struct ipv6_hdr); > > + *l4_hdr =3D (char *)l3_hdr + m->l3_len; > > + m->ol_flags |=3D PKT_TX_IPV6; > > + break; >=20 > Note that I'm still not that satisfied with putting all those kind of cal= culation > into vhost library. >=20 > Every application requesting TSO and CSUM offload features need setup > them, so I'm wondering _if_ we can put them into a libraray, say lib_ethe= r, > and let the application just set few key fields and left others to that l= ib. >=20 > That could leaves us from touching those chaos, such as TCP and IP, here = and > there. And, that, IMO, would be a more elegant way to leverage hardware > TSO and CSUM offload features. >=20 > And I guess that might need some efforts and more discussions, so I'm oka= y > to left that in later versions. (Hence, I gave my ack). >=20 > (I know little about lib_ether and DPDK hardware TSO settings, so I could= be > wrong, and sorry for that if so) You suggestion is good, I also think we should add some L2/L3 protocols par= se into DPDK libs. as you said, there need more discussions for this, maybe we can do this in = the future. But now, it is necessary to add parse_ethernet() function here to get the e= ssential information. >=20 > --yliu >=20 > > + default: > > + m->l3_len =3D 0; > > + *l4_proto =3D 0; > > + break; > > + } > > +} > > + > > +static inline void __attribute__((always_inline)) > > +vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m) > > +{ > > + uint16_t l4_proto =3D 0; > > + void *l4_hdr =3D NULL; > > + struct tcp_hdr *tcp_hdr =3D NULL; > > + > > + parse_ethernet(m, &l4_proto, &l4_hdr); > > + if (hdr->flags =3D=3D VIRTIO_NET_HDR_F_NEEDS_CSUM) { > > + if (hdr->csum_start =3D=3D (m->l2_len + m->l3_len)) { > > + switch (hdr->csum_offset) { > > + case (offsetof(struct tcp_hdr, cksum)): > > + if (l4_proto =3D=3D IPPROTO_TCP) > > + m->ol_flags |=3D PKT_TX_TCP_CKSUM; > > + break; > > + case (offsetof(struct udp_hdr, dgram_cksum)): > > + if (l4_proto =3D=3D IPPROTO_UDP) > > + m->ol_flags |=3D PKT_TX_UDP_CKSUM; > > + break; > > + case (offsetof(struct sctp_hdr, cksum)): > > + if (l4_proto =3D=3D IPPROTO_SCTP) > > + m->ol_flags |=3D > PKT_TX_SCTP_CKSUM; > > + break; > > + default: > > + break; > > + } > > + } > > + } > > + > > + if (hdr->gso_type !=3D VIRTIO_NET_HDR_GSO_NONE) { > > + switch (hdr->gso_type & ~VIRTIO_NET_HDR_GSO_ECN) { > > + case VIRTIO_NET_HDR_GSO_TCPV4: > > + case VIRTIO_NET_HDR_GSO_TCPV6: > > + tcp_hdr =3D (struct tcp_hdr *)l4_hdr; > > + m->ol_flags |=3D PKT_TX_TCP_SEG; > > + m->tso_segsz =3D hdr->gso_size; > > + m->l4_len =3D (tcp_hdr->data_off & 0xf0) >> 2; > > + break; > > + default: > > + RTE_LOG(WARNING, VHOST_DATA, > > + "unsupported gso type %u.\n", hdr- > >gso_type); > > + break; > > + } > > + } > > +}