[dpdk-dev,v3,6/8] driver/virtio:enqueue vhost TX offload

Message ID 1446634456-413-7-git-send-email-jijiang.liu@intel.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Jijiang Liu Nov. 4, 2015, 10:54 a.m. UTC
  Enqueue vhost TX checksum and TSO4/6 offload in virtio-net lib.

Signed-off-by: Jijiang Liu <jijiang.liu@intel.com>
---
 drivers/net/virtio/virtio_rxtx.c |   61 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 deletions(-)
  

Comments

Thomas Monjalon Nov. 4, 2015, 11:17 a.m. UTC | #1
2015-11-04 18:54, Jijiang Liu:
> +       /* if vhost TX checksum offload is required */
> +       if (m->ol_flags & PKT_TX_IP_CKSUM) {
> +               hdr->csum_start = m->l2_len;
> +               hdr->csum_offset = offsetof(struct ipv4_hdr, hdr_checksum);
> +       } else if (m->ol_flags & PKT_TX_L4_MASK) {
> +               hdr->csum_start = m->l2_len + m->l3_len;
> +               switch (m->ol_flags & PKT_TX_L4_MASK) {
> +               case PKT_TX_TCP_CKSUM:
> +                       hdr->csum_offset = offsetof(struct tcp_hdr, cksum);
> +                       break;
> +               case PKT_TX_UDP_CKSUM:
> +                       hdr->csum_offset = offsetof(struct udp_hdr,
> +                                                       dgram_cksum);
> +                       break;
> +               case PKT_TX_SCTP_CKSUM:
> +                       hdr->csum_offset = offsetof(struct sctp_hdr, cksum);
> +                       break;
> +               default:
> +                       break;
> +               }

The header checksum to offload is deduced from csum_offset.
Your vhost implementation do some parsing to deduce it:

> +	parse_ethernet(m, &l4_proto, &l4_hdr);
> +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> +		if ((hdr->csum_start == m->l2_len) &&
> +			(hdr->csum_offset == offsetof(struct ipv4_hdr,
> +						hdr_checksum)))
> +			m->ol_flags |= PKT_TX_IP_CKSUM;
> +		else if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> +			switch (hdr->csum_offset) {
> +			case (offsetof(struct tcp_hdr, cksum)):
> +				if (l4_proto == IPPROTO_TCP)
> +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> +				break;
> +			case (offsetof(struct udp_hdr, dgram_cksum)):
> +				if (l4_proto == IPPROTO_UDP)
> +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> +				break;
> +			case (offsetof(struct sctp_hdr, cksum)):
> +				if (l4_proto == IPPROTO_SCTP)
> +					m->ol_flags |= PKT_TX_SCTP_CKSUM;
> +				break;
> +			default:
> +				break;
> +			}
> +		}

The kernel doesn't work this way.
Please could you check that your virtio implementation works with a
vanilla Linux with or without vhost?
Thanks
  
Jijiang Liu Nov. 4, 2015, 12:52 p.m. UTC | #2
Hi Thomas,


> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, November 4, 2015 7:18 PM
> To: Liu, Jijiang
> Cc: dev@dpdk.org; Michael S. Tsirkin
> Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost 


The following code is not in the patch 6, please review the latest patch set.


> > +	parse_ethernet(m, &l4_proto, &l4_hdr);
> > +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> > +		if ((hdr->csum_start == m->l2_len) &&
> > +			(hdr->csum_offset == offsetof(struct ipv4_hdr,
> > +						hdr_checksum)))
> > +			m->ol_flags |= PKT_TX_IP_CKSUM;
> > +		else if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> > +			switch (hdr->csum_offset) {
> > +			case (offsetof(struct tcp_hdr, cksum)):
> > +				if (l4_proto == IPPROTO_TCP)
> > +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> > +				break;
> > +			case (offsetof(struct udp_hdr, dgram_cksum)):
> > +				if (l4_proto == IPPROTO_UDP)
> > +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> > +				break;
> > +			case (offsetof(struct sctp_hdr, cksum)):
> > +				if (l4_proto == IPPROTO_SCTP)
> > +					m->ol_flags |= PKT_TX_SCTP_CKSUM;
> > +				break;
> > +			default:
> > +				break;
> > +			}
> > +		}
> 
> The kernel doesn't work this way.
> Please could you check that your virtio implementation works with a vanilla
> Linux with or without vhost?
> Thanks

This is vhost lib implementation, not virtio-net side.
We have already validated with a vanilla Linux with or without virtio-net, and it passed.
Could you please review latest patch v3?

Xu Qian can send the test report out.
  
Jijiang Liu Nov. 4, 2015, 1:06 p.m. UTC | #3
Hi Thomas,

> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> Sent: Wednesday, November 4, 2015 7:18 PM
> To: Liu, Jijiang
> Cc: dev@dpdk.org; Michael S. Tsirkin
> Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX
> offload
> 
> 2015-11-04 18:54, Jijiang Liu:
> > +       /* if vhost TX checksum offload is required */
> > +       if (m->ol_flags & PKT_TX_IP_CKSUM) {
> > +               hdr->csum_start = m->l2_len;
> > +               hdr->csum_offset = offsetof(struct ipv4_hdr, hdr_checksum);
> > +       } else if (m->ol_flags & PKT_TX_L4_MASK) {
> > +               hdr->csum_start = m->l2_len + m->l3_len;
> > +               switch (m->ol_flags & PKT_TX_L4_MASK) {
> > +               case PKT_TX_TCP_CKSUM:
> > +                       hdr->csum_offset = offsetof(struct tcp_hdr, cksum);
> > +                       break;
> > +               case PKT_TX_UDP_CKSUM:
> > +                       hdr->csum_offset = offsetof(struct udp_hdr,
> > +                                                       dgram_cksum);
> > +                       break;
> > +               case PKT_TX_SCTP_CKSUM:
> > +                       hdr->csum_offset = offsetof(struct sctp_hdr, cksum);
> > +                       break;
> > +               default:
> > +                       break;
> > +               }
> 
> The header checksum to offload is deduced from csum_offset.
> Your vhost implementation do some parsing to deduce it:
> 
 The ol_flag is set in application, we have to fill 'csum_start' and  'csum_offset' based on these offload flags. 
As long as the 'csum_start' and  'csum_offset'  fileds are set correctly, and it can work well with a vanilla linux with vhost.

But in DPDK vhost lib, we need to parse the 'csum_start' and  'csum_offset' filed to get the which offload flags should be set, and the l2_len, l3_len and l3_len also should be filled.

So I think it is necessary to do this in both side.
We can continue discuss this if you have further comments. Thanks

--Jijiang Liu
  
Jijiang Liu Nov. 4, 2015, 1:08 p.m. UTC | #4
> -----Original Message-----
> From: Liu, Jijiang
> Sent: Wednesday, November 4, 2015 8:52 PM
> To: 'Thomas Monjalon'
> Cc: dev@dpdk.org; Michael S. Tsirkin
> Subject: RE: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX
> offload
> 
> Hi Thomas,
> 
> 
> > -----Original Message-----
> > From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > Sent: Wednesday, November 4, 2015 7:18 PM
> > To: Liu, Jijiang
> > Cc: dev@dpdk.org; Michael S. Tsirkin
> > Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost
> 
> 
> The following code is not in the patch 6, please review the latest patch set.

Got it. You copy the codes from vhost side here for the comparison. The v3 is latest.

> 
> > > +	parse_ethernet(m, &l4_proto, &l4_hdr);
> > > +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> > > +		if ((hdr->csum_start == m->l2_len) &&
> > > +			(hdr->csum_offset == offsetof(struct ipv4_hdr,
> > > +						hdr_checksum)))
> > > +			m->ol_flags |= PKT_TX_IP_CKSUM;
> > > +		else if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> > > +			switch (hdr->csum_offset) {
> > > +			case (offsetof(struct tcp_hdr, cksum)):
> > > +				if (l4_proto == IPPROTO_TCP)
> > > +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> > > +				break;
> > > +			case (offsetof(struct udp_hdr, dgram_cksum)):
> > > +				if (l4_proto == IPPROTO_UDP)
> > > +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> > > +				break;
> > > +			case (offsetof(struct sctp_hdr, cksum)):
> > > +				if (l4_proto == IPPROTO_SCTP)
> > > +					m->ol_flags |= PKT_TX_SCTP_CKSUM;
> > > +				break;
> > > +			default:
> > > +				break;
> > > +			}
> > > +		}
> >
> > The kernel doesn't work this way.
> > Please could you check that your virtio implementation works with a
> vanilla
> > Linux with or without vhost?
> > Thanks
> 
> This is vhost lib implementation, not virtio-net side.
> We have already validated with a vanilla Linux with or without virtio-net,
> and it passed.
> Could you please review latest patch v3?
> 
> Xu Qian can send the test report out.
  
Jijiang Liu Nov. 4, 2015, 1:15 p.m. UTC | #5
The following structure  is defined in virtio standard,

struct virtio_net_hdr {
#define VIRTIO_NET_HDR_F_NEEDS_CSUM 1
u8 flags;
#define VIRTIO_NET_HDR_GSO_NONE 0
#define VIRTIO_NET_HDR_GSO_TCPV4 1
#define VIRTIO_NET_HDR_GSO_UDP 3
#define VIRTIO_NET_HDR_GSO_TCPV6 4
#define VIRTIO_NET_HDR_GSO_ECN 0x80
u8 gso_type;
le16 hdr_len;
le16 gso_size;
le16 csum_start;
le16 csum_offset;
le16 num_buffers;
};

For checksum. The 'flags', ' csum_start' and csum_offset filed need to be filled.

For TSO, the 'gso_type', 'hdr_len' and 'csum_offset' fileds need to be filled.


> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Liu, Jijiang
> Sent: Wednesday, November 4, 2015 9:08 PM
> To: Thomas Monjalon
> Cc: dev@dpdk.org; Michael S. Tsirkin
> Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX
> offload
> 
> 
> 
> > -----Original Message-----
> > From: Liu, Jijiang
> > Sent: Wednesday, November 4, 2015 8:52 PM
> > To: 'Thomas Monjalon'
> > Cc: dev@dpdk.org; Michael S. Tsirkin
> > Subject: RE: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX
> > offload
> >
> > Hi Thomas,
> >
> >
> > > -----Original Message-----
> > > From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > > Sent: Wednesday, November 4, 2015 7:18 PM
> > > To: Liu, Jijiang
> > > Cc: dev@dpdk.org; Michael S. Tsirkin
> > > Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost
> >
> >
> > The following code is not in the patch 6, please review the latest patch set.
> 
> Got it. You copy the codes from vhost side here for the comparison. The v3 is
> latest.
> 
> >
> > > > +	parse_ethernet(m, &l4_proto, &l4_hdr);
> > > > +	if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> > > > +		if ((hdr->csum_start == m->l2_len) &&
> > > > +			(hdr->csum_offset == offsetof(struct ipv4_hdr,
> > > > +						hdr_checksum)))
> > > > +			m->ol_flags |= PKT_TX_IP_CKSUM;
> > > > +		else if (hdr->csum_start == (m->l2_len + m->l3_len)) {
> > > > +			switch (hdr->csum_offset) {
> > > > +			case (offsetof(struct tcp_hdr, cksum)):
> > > > +				if (l4_proto == IPPROTO_TCP)
> > > > +					m->ol_flags |= PKT_TX_TCP_CKSUM;
> > > > +				break;
> > > > +			case (offsetof(struct udp_hdr, dgram_cksum)):
> > > > +				if (l4_proto == IPPROTO_UDP)
> > > > +					m->ol_flags |= PKT_TX_UDP_CKSUM;
> > > > +				break;
> > > > +			case (offsetof(struct sctp_hdr, cksum)):
> > > > +				if (l4_proto == IPPROTO_SCTP)
> > > > +					m->ol_flags |= PKT_TX_SCTP_CKSUM;
> > > > +				break;
> > > > +			default:
> > > > +				break;
> > > > +			}
> > > > +		}
> > >
> > > The kernel doesn't work this way.
> > > Please could you check that your virtio implementation works with a
> > vanilla
> > > Linux with or without vhost?
> > > Thanks
> >
> > This is vhost lib implementation, not virtio-net side.
> > We have already validated with a vanilla Linux with or without
> > virtio-net, and it passed.
> > Could you please review latest patch v3?
> >
> > Xu Qian can send the test report out.
  
Thomas Monjalon Nov. 4, 2015, 1:18 p.m. UTC | #6
2015-11-04 12:52, Liu, Jijiang:
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > Please could you check that your virtio implementation works with a vanilla
> > Linux with or without vhost?
> > Thanks
[...]
> Xu Qian can send the test report out.  

Yes please, I'd like to see a test report showing this virtio running
with Linux vhost and without vhost.
We must check that the checksum is well offloaded and sent packets are valids.
Thanks
  
Xu, Qian Q Nov. 5, 2015, 8:49 a.m. UTC | #7
Tested-by: Qian Xu <qian.q.xu@intel.com>

- Test Commit: c4d404d7c1257465176deb5bb8c84e627d2d5eee
- OS/Kernel: Fedora 21/4.1.8
- GCC: gcc (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
- CPU: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz
- NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Target: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Total 2 cases, 2 passed, 0 failed. DPDK vhost + legacy virtio or virtio-pmd can work well with TSO. 

Test Case 1:  test_dpdk vhost+ virtio-pmd tso 
======================================

On host:

1. Start up vhost-switch, mergeable 1 means the jubmo frame feature is enabled. vm2vm 0 means only one vm without vm to vm communication::

    taskset -c 1-3 <dpdk_folder>/examples/vhost/build/vhost-switch -c 0xf -n 4 --huge-dir /mnt/huge --socket-mem 1024,1024 -- -p 1 --mergeable 1 --zero-copy 0 --vm2vm 0 --tso 1 --tx-csum 1
   

2. Start VM with vhost cuse as backend::

    taskset -c 4-6  /home/qxu10/qemu-2.2.0/x86_64-softmmu/qemu-system-x86_64 -object memory-backend-file, id=mem,size=2048M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
    -enable-kvm -m 2048 -smp 4 -cpu host -name dpdk1-vm1 \
    -drive file=/home/img/dpdk1-vm1.img \
    -netdev tap,id=vhost3,ifname=tap_vhost3,vhost=on,script=no \
    -device virtio-net pci,netdev=vhost3,mac=52:54:00:00:00:01,id=net3 \
    -netdev tap,id=vhost4,ifname=tap_vhost4,vhost=on,script=no \
    -device virtio-net-pci,netdev=vhost4,mac=52:54:00:00:00:02,id=net4 \
    -netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:00:00:00:00:01 \
    -localtime -nographic

On guest:

3. ensure the dpdk folder copied to the guest with the same config file and build process as host. Then bind 2 virtio devices to igb_uio and start testpmd, below is the step for reference::

    ./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0 00:04.0

    ./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c f -n 4 -- -i --txqflags 0x0f00 --max-pkt-len 9000 
    
    $ >set fwd csum
    
    $ >tso set 1000 0
    $ >tso set 1000 1

    $ >start tx_first

4.  Send TCP packets to virtio1, and the packet size is 5000, then at the virtio side, it will receive 1 packet ant let vhost to do TSO, vhost will let NIC do TSO, so at IXIA, we expected 5 packets, each ~1k size, then also capture the received packets and check if the checksum is correct.

Result:  All the behavior is expected as step4. So the case is PASS.

Test Case 2:  test_dpdk vhost+legacy virtio iperf tso
===========================================
Hardware config: Connect one physical port(port1) to another physical port(port2). Port1 is the NIC port that will do the TSO.
1. Start dpdk vhost sample, the command is same as above case. Port1 is binded to igb_uio
2. start VM with 1 virtio
3. let port2 and 1virtio in VM do iperf test, since iperf test will send out 
VIRTIO: ifconfig eth0 1.1.1.2
Port2: ifconfig p2p6 1.1.1.8
Make ping work: ping 1.1.1.8 
Then run iperf server at port2: iperf -s -I 1
Run iperf client at port1: iperf -c 1.1.1.8 -t 60 -I 1

Check the packet size at virtio and port2 to see if there are many 64KB packet, if has, then pass. The reason is that vhost/virtio will first negotiate if each other supports tso, if supports, then the TCP/IP stack will compose BIG packets such as 64KB, since NIC has the TSO capability, vhost will let NIC do the TSO work, then at port2, the small packets will be composed to big packets with TCP/IP stack.  

Result: there are many 64KB packet in both virtio and port2, so it is pass. 
 
Thanks
Qian


-----Original Message-----
From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Thomas Monjalon
Sent: Wednesday, November 04, 2015 9:18 PM
To: Liu, Jijiang
Cc: dev@dpdk.org; Michael S. Tsirkin
Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX offload

2015-11-04 12:52, Liu, Jijiang:
> From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com]
> > Please could you check that your virtio implementation works with a 
> > vanilla Linux with or without vhost?
> > Thanks
[...]
> Xu Qian can send the test report out.  

Yes please, I'd like to see a test report showing this virtio running with Linux vhost and without vhost.
We must check that the checksum is well offloaded and sent packets are valids.
Thanks
  
Thomas Monjalon Nov. 5, 2015, 9:02 a.m. UTC | #8
2015-11-05 08:49, Xu, Qian Q:
> Test Case 1:  test_dpdk vhost+ virtio-pmd tso 
[...]
> Test Case 2:  test_dpdk vhost+legacy virtio iperf tso
[...]
> Yes please, I'd like to see a test report showing this virtio running with Linux vhost and without vhost.
> We must check that the checksum is well offloaded and sent packets are valids.
> Thanks

Thanks for doing some tests.
I had no doubt it works with DPDK vhost.
Please could you do some tests without vhost and with kernel vhost?
We need to check that the checksum is not missing in such cases.
  
Xu, Qian Q Nov. 5, 2015, 10:44 a.m. UTC | #9
OK, I will check it tomorrow. 
Another comment is that "Legacy vhost + virtio-pmd" is not the common use case. Firstly, in this case, virtio-pmd has no TCP/IP stack, TSO is not very meaningful; secondly, we can't get performance benefit from this case compared to "Legacy vhost+ legacy virtio". So I'm afraid no customer would like to try this case since the fake TSO and poor performance. 


Thanks
Qian


-----Original Message-----
From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com] 
Sent: Thursday, November 05, 2015 5:02 PM
To: Xu, Qian Q
Cc: Liu, Jijiang; dev@dpdk.org; Michael S. Tsirkin
Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX offload

2015-11-05 08:49, Xu, Qian Q:
> Test Case 1:  test_dpdk vhost+ virtio-pmd tso 
[...]
> Test Case 2:  test_dpdk vhost+legacy virtio iperf tso
[...]
> Yes please, I'd like to see a test report showing this virtio running with Linux vhost and without vhost.
> We must check that the checksum is well offloaded and sent packets are valids.
> Thanks

Thanks for doing some tests.
I had no doubt it works with DPDK vhost.
Please could you do some tests without vhost and with kernel vhost?
We need to check that the checksum is not missing in such cases.
  
Xu, Qian Q Nov. 6, 2015, 8:24 a.m. UTC | #10
Tested-by: Qian Xu <qian.q.xu@intel.com>

- Test Commit: c4d404d7c1257465176deb5bb8c84e627d2d5eee
- OS/Kernel: Fedora 21/4.1.8
- GCC: gcc (GCC) 4.9.2 20141101 (Red Hat 4.9.2-1)
- CPU: Intel(R) Xeon(R) CPU E5-2699 v3 @ 2.30GHz
- NIC: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Target: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
- Total 1 cases, 1 passed, 0 failed. Legacy vhost + virtio-pmd can work well with TSO. 

Test Case 1:  test_legacy_vhost+ virtio-pmd tso 
=======================================

On host:

1. Start VM with legacy-vhost as backend::

    taskset -c 4-6  /home/qxu10/qemu-2.2.0/x86_64-softmmu/qemu-system-x86_64 -object memory-backend-file, id=mem,size=2048M,mem-path=/mnt/huge,share=on -numa node,memdev=mem -mem-prealloc \
    -enable-kvm -m 2048 -smp 4 -cpu host -name dpdk1-vm1 \
    -drive file=/home/img/dpdk1-vm1.img \
    -netdev tap,id=vhost3,ifname=tap_vhost3,vhost=on,script=no \
    -device virtio-net pci,netdev=vhost3,mac=52:54:00:00:00:01,id=net3 \
    -netdev tap,id=ipvm1,ifname=tap3,script=/etc/qemu-ifup -device rtl8139,netdev=ipvm1,id=net0,mac=00:00:00:00:00:01 \
    -localtime -nographic

2.  Set up the bridge on host: 

brctl addbr br1
brctl addif br1 ens260f0 # The interface is 85:00.0 connected to ixia card3 port9
brctl addif br1 tap0
brctl addif br1 tap1

ifconfig ens260f0 up
ifconfig ens260f0 promisc
ifconfig tap0 up
ifconfig tap1 up
ifconfig tap0 promisc
ifconfig tap1 promisc
brctl stp br1 off
ifconfig br1 up
brctl show

3. Disable firewall and Network manager on host:

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl stop ip6tables.service
systemctl disable ip6tables.service
systemctl stop iptables.service
systemctl disable iptables.service
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

4.  Let br1 learn the MAC : 02:00:00:00:00:00, since in the VM, the virtio device run testpmd, then it will send packets with the DEST MAC as 02:00:00:00:00:00. Then the br1 will know this packet can go to the NIC and then it will go back to the traffic generator. So here we send a packet from IXIA with the SRC MAC=02:00:00:00:00:00 and DEST MAC=52:54:00:00:00:01 to let the br1 know the MAC. We can verify the macs that the bridge knows by running: brctl br1 showmacs

port no mac addr                is local?       ageing timer
  3     02:00:00:00:00:00       no                 6.06
  1     42:fa:45:4d:aa:4d       yes                0.00
  1     42:fa:45:4d:aa:4d       yes                0.00
  1     52:54:00:00:00:01       no                 6.06
  2     8e:d7:22:bf:c9:8d       yes                0.00
  2     8e:d7:22:bf:c9:8d       yes                0.00
  3     90:e2:ba:4a:55:1c       yes                0.00
  3     90:e2:ba:4a:55:1c       yes                0.00


On guest:

5. ensure the dpdk folder copied to the guest with the same config file and build process as host. Then bind 2 virtio devices to igb_uio and start testpmd, below is the step for reference::

    ./<dpdk_folder>/tools/dpdk_nic_bind.py --bind igb_uio 00:03.0 

    ./<dpdk_folder>/x86_64-native-linuxapp-gcc/app/test-pmd/testpmd -c f -n 4 -- -i --txqflags 0x0f00 --max-pkt-len 9000 
    
    $ >set fwd csum
    
    $ >tso set 1000 0
    $ >tso set 1000 1

    $ >start 

6.  Send TCP packets to virtio1, and the packet size is 5000, then at the virtio side, it will receive 1 packet ant let vhost to do TSO, vhost will let NIC do TSO, so at IXIA, we expected 5 packets, each ~1k size, then also capture the received packets and check if the checksum is correct.

Result:  All the behavior is expected and cksum is correct. So the case is PASS.


Thanks
Qian


-----Original Message-----
From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Xu, Qian Q
Sent: Thursday, November 05, 2015 6:45 PM
To: Thomas Monjalon
Cc: dev@dpdk.org; Michael S. Tsirkin
Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX offload

OK, I will check it tomorrow. 
Another comment is that "Legacy vhost + virtio-pmd" is not the common use case. Firstly, in this case, virtio-pmd has no TCP/IP stack, TSO is not very meaningful; secondly, we can't get performance benefit from this case compared to "Legacy vhost+ legacy virtio". So I'm afraid no customer would like to try this case since the fake TSO and poor performance. 


Thanks
Qian


-----Original Message-----
From: Thomas Monjalon [mailto:thomas.monjalon@6wind.com] 
Sent: Thursday, November 05, 2015 5:02 PM
To: Xu, Qian Q
Cc: Liu, Jijiang; dev@dpdk.org; Michael S. Tsirkin
Subject: Re: [dpdk-dev] [PATCH v3 6/8] driver/virtio:enqueue vhost TX offload

2015-11-05 08:49, Xu, Qian Q:
> Test Case 1:  test_dpdk vhost+ virtio-pmd tso 
[...]
> Test Case 2:  test_dpdk vhost+legacy virtio iperf tso
[...]
> Yes please, I'd like to see a test report showing this virtio running with Linux vhost and without vhost.
> We must check that the checksum is well offloaded and sent packets are valids.
> Thanks

Thanks for doing some tests.
I had no doubt it works with DPDK vhost.
Please could you do some tests without vhost and with kernel vhost?
We need to check that the checksum is not missing in such cases.
  

Patch

diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index c5b53bb..b99f5b5 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -50,6 +50,10 @@ 
 #include <rte_string_fns.h>
 #include <rte_errno.h>
 #include <rte_byteorder.h>
+#include <rte_tcp.h>
+#include <rte_ip.h>
+#include <rte_udp.h>
+#include <rte_sctp.h>
 
 #include "virtio_logs.h"
 #include "virtio_ethdev.h"
@@ -199,6 +203,58 @@  virtqueue_enqueue_recv_refill(struct virtqueue *vq, struct rte_mbuf *cookie)
 }
 
 static int
+virtqueue_enqueue_offload(struct virtqueue *txvq, struct rte_mbuf *m,
+			uint16_t idx, uint16_t hdr_sz)
+{
+	struct virtio_net_hdr *hdr = (struct virtio_net_hdr *)(uintptr_t)
+				(txvq->virtio_net_hdr_addr + idx * hdr_sz);
+
+	hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
+
+	/* if vhost TX checksum offload is required */
+	if (m->ol_flags & PKT_TX_IP_CKSUM) {
+		hdr->csum_start = m->l2_len;
+		hdr->csum_offset = offsetof(struct ipv4_hdr, hdr_checksum);
+	} else if (m->ol_flags & PKT_TX_L4_MASK) {
+		hdr->csum_start = m->l2_len + m->l3_len;
+		switch (m->ol_flags & PKT_TX_L4_MASK) {
+		case PKT_TX_TCP_CKSUM:
+			hdr->csum_offset = offsetof(struct tcp_hdr, cksum);
+			break;
+		case PKT_TX_UDP_CKSUM:
+			hdr->csum_offset = offsetof(struct udp_hdr,
+							dgram_cksum);
+			break;
+		case PKT_TX_SCTP_CKSUM:
+			hdr->csum_offset = offsetof(struct sctp_hdr, cksum);
+			break;
+		default:
+			break;
+		}
+	} else
+		hdr->flags = 0;
+
+	/* if vhost TSO offload is required */
+	if (m->tso_segsz != 0 && m->ol_flags & PKT_TX_TCP_SEG) {
+		if (m->ol_flags & PKT_TX_IPV4) {
+			if (!vtpci_with_feature(txvq->hw,
+				VIRTIO_NET_F_HOST_TSO4))
+				return -1;
+			hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
+		} else if (m->ol_flags & PKT_TX_IPV6) {
+			if (!vtpci_with_feature(txvq->hw,
+				VIRTIO_NET_F_HOST_TSO6))
+				return -1;
+			hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
+		}
+		hdr->gso_size = m->tso_segsz;
+		hdr->hdr_len = m->l2_len + m->l3_len + m->l4_len;
+	} else
+		hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
+	return 0;
+}
+
+static int
 virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie)
 {
 	struct vq_desc_extra *dxp;
@@ -221,6 +277,11 @@  virtqueue_enqueue_xmit(struct virtqueue *txvq, struct rte_mbuf *cookie)
 	dxp->cookie = (void *)cookie;
 	dxp->ndescs = needed;
 
+	if (vtpci_with_feature(txvq->hw, VIRTIO_NET_F_CSUM)) {
+		if (virtqueue_enqueue_offload(txvq, cookie, idx, head_size) < 0)
+			return -EPERM;
+	}
+
 	start_dp = txvq->vq_ring.desc;
 	start_dp[idx].addr =
 		txvq->virtio_net_hdr_mem + idx * head_size;