Support Receive-Segment-Offload(RSC) for WHQL
v5 cover Support Receive-Segment-Offload(RSC) for WHQL
From: Wei Xu <[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.
Another suggestion from Jason is to adjust part of the code to make it more readable, since there maybe still few change about the flowchart in the future, such as timestamp, duplicate ack, so i'd like to delay it temporarily.
Changes in V4:
- Add new host feature bit
- Replace using fixed header lenght with dynamic header lenght in VirtIONet
- Change ip/ip6 header union in NetRscUnit to void* pointer
- Add macro prefix, adjust code indent, etc.
Changes in V3:
- Removed big param list, replace it with 'NetRscUnit'
- Different virtio header size
- Modify callback function to direct call.
- Needn't check the failure of g_malloc()
- Other code format adjustment, macro naming, etc
Changes in V2:
- Add detailed commit log
This patch is to support WHQL test for Windows guest, while this feature also benifits other guest works as a kernel 'gro' like feature with userspace implementation.
Feature information:
http://msdn.microsoft.com/en-us/library/windows/hardware/jj853324
Both IPv4 and IPv6 are supported, though performance with userspace virtio is slow than vhost-net, there is about 1.5x to 2x performance improvement to userspace virtio, this is done by turning this feature on and disable 'tso/gso/gro' on corresponding tap interface and guest interface, while get less improment with all these feature on.
Linux guest performance data(Netperf):
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 192.168.2.101 () port 0 AF_INET : nodelay
Size Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec
87380 16384 64 6.00 1221.20 87380 16384 64 6.00 1260.30
87380 16384 128 6.00 1978.51 87380 16384 128 6.00 2286.05
87380 16384 256 6.00 2677.94 87380 16384 256 6.00 4615.42
87380 16384 512 6.00 2956.54 87380 16384 512 6.00 5356.39
87380 16384 1024 6.00 2798.17 87380 16384 1024 6.00 4943.30
87380 16384 2048 6.00 2681.09 87380 16384 2048 6.00 4835.81
87380 16384 4096 6.00 3390.14 87380 16384 4096 6.00 5391.54
87380 16384 8092 6.00 3008.27 87380 16384 8092 6.00 5381.68
87380 16384 10240 6.00 2999.89 87380 16384 10240 6.00 5393.11
Test steps:
Although this feature is mainly used for window guest, i used linux guest to help test the feature, to make things simple, i used 3 steps to test the patch as i moved on.
1. With a tcp socket client/server pair running on 2 linux guest, thus i can control
the traffic and debugging the code as i want.
2. Netperf on linux guest test the throughput.
3. WHQL test with 2 Windows guests.
Wei Xu (2):
virtio-net rsc: support coalescing ipv4 tcp traffic virtio-net rsc: support coalescing ipv6 tcp traffic
hw/net/virtio-net.c | 623 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 ++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 699 insertions(+), 3 deletions(-)
Signature · 1 line
2.7.1
RFC PATCH v5 1/2 virtio-net rsc: support coalescing ipv4 tcp traffic
From: Wei Xu <[email protected]>
All the data packets in a tcp connection will be cached to a big buffer in every receive interval, and will be sent out via a timer, the 'virtio_net_rsc_timeout' controls the interval, the value will influent the performance and response of tcp connection extremely, 50000(50us) is a experience value to gain a performance improvement, since the whql test sends packets every 100us, so '300000(300us)' can pass the test case, this is also the default value, it's tunable via the command line parameter 'rsc_interval' with 'virtio-net-pci' device, for example, below parameter is to launch a guest with interval set as '500000'.
'virtio-net-pci,netdev=hostnet1,bus=pci.0,id=net1,mac=00,rsc_interval=500000' will
The timer will only be triggered if the packets pool is not empty, and it'll drain off all the cached packets.
'NetRscChain' is used to save the segments of different protocols in a VirtIONet device.
The main handler of TCP includes TCP window update, duplicated ACK check and the real data coalescing if the new segment passed sanity check and is identified as an 'wanted' one.
An 'wanted' segment means:
1. Segment is within current window and the sequence is the expected one.
2. 'ACK' of the segment is in the valid window.
Sanity check includes:
1. Incorrect version in IP header
2. IP options & IP fragment
3. Not a TCP packets
4. Sanity size check to prevent buffer overflow attack.
There maybe more cases should be considered such as ip identification other flags, while it broke the test because windows set it to the same even it's not a fragment.
Normally it includes 2 typical ways to handle a TCP control flag, 'bypass' and 'finalize', 'bypass' means should be sent out directly, and 'finalize' means the packets should also be bypassed, and this should be done after searching for the same connection packets in the pool and sending all of them out, this is to avoid out of data.
All the 'SYN' packets will be bypassed since this always begin a new' connection, other flags such 'FIN/RST' will trigger a finalization, because this normally happens upon a connection is going to be closed, an 'URG' packet also finalize current coalescing unit.
Statistics can be used to monitor the basic coalescing status, the 'out of order' and 'out of window' means how many retransmitting packets, thus describe the performance intuitively.
--- hw/net/virtio-net.c | 487 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 +++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 563 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +484 -3
@@ -15,10 +15,12 @@#include "qemu/iov.h" #include "hw/virtio/virtio.h" #include "net/net.h" +#include "net/eth.h" #include "net/checksum.h" #include "net/tap.h" #include "qemu/error-report.h" #include "qemu/timer.h" +#include "qemu/sockets.h" #include "hw/virtio/virtio-net.h" #include "net/vhost_net.h" #include "hw/virtio/virtio-bus.h"
@@ -38,6 +40,25 @@#define endof (container, field) \ (offsetof(container, field) + sizeof(((container *)0)->field)) +#define VIRTIO_NET_IP4_ADDR_SIZE 8/* ipv4 saddr + daddr */ +#define VIRTIO_NET_TCP_PORT_SIZE 4/* sport + dport */ + +#define VIRTIO_NET_TCP_FLAG 0x3F +#define VIRTIO_NET_TCP_HDR_LENGTH 0xF000 + +/* IPv4 max payload, 16 bits in the header */ +#define VIRTIO_NET_MAX_IP4_PAYLOAD (65535 - sizeof(struct ip_header)) +#define VIRTIO_NET_MAX_TCP_PAYLOAD 65535 + +/* header length value in ip header without option */ +#define VIRTIO_NET_IP4_HEADER_LENGTH 5 + +/* Purge coalesced packets timer interval, This value affects the performance +a lot, and should be tuned carefully, '300000'(300us) is the recommended +value to pass the WHQL test, '50000' can gain 2x netperf throughput with +tso/gso/gro 'off'. */ +#define VIRTIO_NET_RSC_INTERVAL 300000 + typedef struct VirtIOFeature { uint32_t flags; size_t end;
@@ -1688,20 +1709,476 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,return 0 ; } +static void virtio_net_rsc_extract_unit4 (NetRscChain *chain, +const uint8_t *buf,NetRscUnit * unit) +{ +uint16_t hdr_len; +uint16_t ip_hdrlen; +struct ip_header *ip; + + hdr_len = chain->n->guest_hdr_len; + ip = (struct ip_header *)(buf + hdr_len +sizeof (struct eth_header )); + unit->ip = (void *)ip; + ip_hdrlen = (ip->ip_ver_len &0xF ) <<2 ; + unit->ip_plen = &ip->ip_len; + unit->tcp = (struct tcp_header *)(((uint8_t *)unit->ip) + ip_hdrlen); + unit->tcp_hdrlen = (htons (unit->tcp->th_offset_flags) &0xF000 ) >>10 ; + unit->payload =htons (*unit->ip_plen) - ip_hdrlen - unit->tcp_hdrlen; +} + +static void virtio_net_rsc_ipv4_checksum (struct virtio_net_hdr * vhdr, +struct ip_header *ip) +{ +uint32_t sum; + + ip->ip_sum =0 ; + sum =net_checksum_add_cont (sizeof (struct ip_header ), (uint8_t *)ip,0 ); + ip->ip_sum =cpu_to_be16 (net_checksum_finish (sum)); + vhdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM ; + vhdr->flags |=VIRTIO_NET_HDR_F_DATA_VALID ; +} + +static size_t virtio_net_rsc_drain_seg (NetRscChain *chain,NetRscSeg *seg) +{ +int ret; +struct virtio_net_hdr *h; + + h = (struct virtio_net_hdr *)seg->buf; +virtio_net_rsc_ipv4_checksum (h, seg->unit.ip); + h->coalesced = seg->packets; + h->dup_ack = seg->dup_ack_count; + h->gso_type = chain->gso_type; + h->gso_size = chain->max_payload; + ret =virtio_net_do_receive (seg->nc, seg->buf, seg->size); +QTAILQ_REMOVE (&chain->buffers, seg, next); +g_free (seg->buf); +g_free (seg); + +return ret; +} + +static void virtio_net_rsc_purge (void *opq) +{ +NetRscSeg *seg, *rn; +NetRscChain *chain = (NetRscChain *)opq; + + QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, rn) { +if (virtio_net_rsc_drain_seg (chain, seg) ==0 ) { + chain->stat.purge_failed++; +continue ; + } + } + + chain->stat.timer++; +if (!QTAILQ_EMPTY (&chain->buffers)) { +timer_mod (chain->drain_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + chain->n->rsc_timeout); + } +} + +static void virtio_net_rsc_cleanup (VirtIONet *n) +{ +NetRscChain *chain, *rn_chain; +NetRscSeg *seg, *rn_seg; + + QTAILQ_FOREACH_SAFE(chain, &n->rsc_chains, next, rn_chain) { + QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, rn_seg) { +QTAILQ_REMOVE (&chain->buffers, seg, next); +g_free (seg->buf); +g_free (seg); + } + +timer_del (chain->drain_timer); +timer_free (chain->drain_timer); +QTAILQ_REMOVE (&n->rsc_chains, chain, next); +g_free (chain); + } +} + +static void virtio_net_rsc_cache_buf (NetRscChain *chain,NetClientState *nc, +const uint8_t *buf,size_t size) +{ +uint16_t hdr_len; +NetRscSeg *seg; + + hdr_len = chain->n->guest_hdr_len; + seg =g_malloc (sizeof (NetRscSeg)); + seg->buf =g_malloc (hdr_len +sizeof (struct eth_header )\ + +VIRTIO_NET_MAX_TCP_PAYLOAD ); +memcpy (seg->buf, buf, size); + seg->size = size; + seg->packets =1 ; + seg->dup_ack_count =0 ; + seg->is_coalesced =0 ; + seg->nc = nc; + +QTAILQ_INSERT_TAIL (&chain->buffers, seg, next); + chain->stat.cache++; + +virtio_net_rsc_extract_unit4 (chain, seg->buf, &seg->unit); +} + +static int32_t virtio_net_rsc_handle_ack (NetRscChain *chain, +NetRscSeg *seg,const uint8_t *buf, +struct tcp_header *n_tcp, +struct tcp_header *o_tcp) +{ +uint32_t nack, oack; +uint16_t nwin, owin; + + nack =htonl (n_tcp->th_ack); + nwin =htons (n_tcp->th_win); + oack =htonl (o_tcp->th_ack); + owin =htons (o_tcp->th_win); + +if ((nack - oack) >=VIRTIO_NET_MAX_TCP_PAYLOAD ) { + chain->stat.ack_out_of_win++; +return RSC_FINAL ; + }else if (nack == oack) { +/* duplicated ack or window probe */ +if (nwin == owin) { +/* duplicated ack, add dup ack count due to whql test up to 1 */ + chain->stat.dup_ack++; +return RSC_FINAL ; + }else { +/* Coalesce window update */ + o_tcp->th_win = n_tcp->th_win; + chain->stat.win_update++; +return RSC_COALESCE ; + } + }else { +/* pure ack, go to 'C', finalize*/ + chain->stat.pure_ack++; +return RSC_FINAL ; + } +} + +static int32_t virtio_net_rsc_coalesce_data (NetRscChain *chain, +NetRscSeg *seg,const uint8_t *buf, +NetRscUnit *n_unit) +{ +void *data; +uint16_t o_ip_len; +uint32_t nseq, oseq; +NetRscUnit *o_unit; + + o_unit = &seg->unit; + o_ip_len =htons (*o_unit->ip_plen); + nseq =htonl (n_unit->tcp->th_seq); + oseq =htonl (o_unit->tcp->th_seq); + +/* out of order or retransmitted. */ +if ((nseq - oseq) >VIRTIO_NET_MAX_TCP_PAYLOAD ) { + chain->stat.data_out_of_win++; +return RSC_FINAL ; + } + + data = ((uint8_t *)n_unit->tcp) + n_unit->tcp_hdrlen; +if (nseq == oseq) { +if ((o_unit->payload ==0 ) && n_unit->payload) { +/* From no payload to payload, normal case, not a dup ack or etc */ + chain->stat.data_after_pure_ack++; + goto coalesce; + }else { +return virtio_net_rsc_handle_ack (chain, seg, buf, + n_unit->tcp, o_unit->tcp); + } + }else if ((nseq - oseq) != o_unit->payload) { +/* Not a consistent packet, out of order */ + chain->stat.data_out_of_order++; +return RSC_FINAL ; + }else { +coalesce: +if ((o_ip_len + n_unit->payload) > chain->max_payload) { + chain->stat.over_size++; +return RSC_FINAL ; + } + +/* Here comes the right data, the payload length in v4/v6 is different, +so use the field value to update and record the new data len */ + o_unit->payload += n_unit->payload;/* update new data len */ + +/* update field in ip header */ + *o_unit->ip_plen =htons (o_ip_len + n_unit->payload); + +/* Bring 'PUSH' big, the whql test guide says 'PUSH' can be coalesced +for windows guest, while this may change the behavior for linux +guest. */ + o_unit->tcp->th_offset_flags = n_unit->tcp->th_offset_flags; + + o_unit->tcp->th_ack = n_unit->tcp->th_ack; + o_unit->tcp->th_win = n_unit->tcp->th_win; + +memmove (seg->buf + seg->size, data, n_unit->payload); + seg->size += n_unit->payload; + seg->packets++; + chain->stat.coalesced++; +return RSC_COALESCE ; + } +} + +static int32_t virtio_net_rsc_coalesce4 (NetRscChain *chain,NetRscSeg *seg, +const uint8_t *buf,size_t size, +NetRscUnit *unit) +{ +struct ip_header *ip1, *ip2; + + ip1 = (struct ip_header *)(unit->ip); + ip2 = (struct ip_header *)(seg->unit.ip); +if ((ip1->ip_src ^ ip2->ip_src) || (ip1->ip_dst ^ ip2->ip_dst) + || (unit->tcp->th_sport ^ seg->unit.tcp->th_sport) + || (unit->tcp->th_dport ^ seg->unit.tcp->th_dport)) { + chain->stat.no_match++; +return RSC_NO_MATCH ; + } + +return virtio_net_rsc_coalesce_data (chain, seg, buf, unit); +} + +/* Pakcets with 'SYN' should bypass, other flag should be sent after drain +* to prevent out of order */ +static int virtio_net_rsc_tcp_ctrl_check (NetRscChain *chain, +struct tcp_header *tcp) +{ +uint16_t tcp_hdr; +uint16_t tcp_flag; + + tcp_flag =htons (tcp->th_offset_flags); + tcp_hdr = (tcp_flag &VIRTIO_NET_TCP_HDR_LENGTH ) >>10 ; + tcp_flag &=VIRTIO_NET_TCP_FLAG ; + tcp_flag =htons (tcp->th_offset_flags) &0x3F ; +if (tcp_flag &TH_SYN ) { + chain->stat.tcp_syn++; +return RSC_BYPASS ; + } + +if (tcp_flag & (TH_FIN |TH_URG |TH_RST )) { + chain->stat.tcp_ctrl_drain++; +return RSC_FINAL ; + } + +if (tcp_hdr >sizeof (struct tcp_header )) { + chain->stat.tcp_all_opt++; +return RSC_FINAL ; + } + +return RSC_WANT ; +} + +static bool virtio_net_rsc_empty_cache (NetRscChain *chain,NetClientState *nc, +const uint8_t *buf,size_t size) +{ +if (QTAILQ_EMPTY (&chain->buffers)) { + chain->stat.empty_cache++; +virtio_net_rsc_cache_buf (chain, nc, buf, size); +timer_mod (chain->drain_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + chain->n->rsc_timeout); +return 1 ; + } + +return 0 ; +} + +static size_t virtio_net_rsc_do_coalesce (NetRscChain *chain,NetClientState *nc, +const uint8_t *buf,size_t size, +NetRscUnit *unit) +{ +int ret; +NetRscSeg *seg, *nseg; + + QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, nseg) { + ret =virtio_net_rsc_coalesce4 (chain, seg, buf, size, unit); + +if (ret ==RSC_FINAL ) { +if (virtio_net_rsc_drain_seg (chain, seg) ==0 ) { +/* Send failed */ + chain->stat.final_failed++; +return 0 ; + } + +/* Send current packet */ +return virtio_net_do_receive (nc, buf, size); + }else if (ret ==RSC_NO_MATCH ) { +continue ; + }else { +/* Coalesced, mark coalesced flag to tell calc cksum for ipv4 */ + seg->is_coalesced =1 ; +return size; + } + } + + chain->stat.no_match_cache++; +virtio_net_rsc_cache_buf (chain, nc, buf, size); +return size; +} + +/* Drain a connection data, this is to avoid out of order segments */ +static size_t virtio_net_rsc_drain_flow (NetRscChain *chain,NetClientState *nc, +const uint8_t *buf,size_t size, +uint16_t ip_start,uint16_t ip_size, +uint16_t tcp_port,uint16_t port_size) +{ +NetRscSeg *seg, *nseg; + + QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, nseg) { +if (memcmp (buf + ip_start, seg->buf + ip_start, ip_size) + ||memcmp (buf + tcp_port, seg->buf + tcp_port, port_size)) { +continue ; + } +if (virtio_net_rsc_drain_seg (chain, seg) ==0 ) { + chain->stat.drain_failed++; + } + +break ; + } + +return virtio_net_do_receive (nc, buf, size); +} + +static int32_t virtio_net_rsc_sanity_check4 (NetRscChain *chain, +struct ip_header *ip, +const uint8_t *buf,size_t size) +{ +uint16_t ip_len; +uint16_t hdr_len; + + hdr_len = chain->n->guest_hdr_len; +if (size < (hdr_len +sizeof (struct eth_header ) +sizeof (struct ip_header ) + +sizeof (struct tcp_header ))) { +return RSC_BYPASS ; + } + +/* Not an ipv4 one */ +if (((ip->ip_ver_len &0xF0 ) >>4 ) !=IP_HEADER_VERSION_4 ) { + chain->stat.ip_option++; +return RSC_BYPASS ; + } + +/* Don't handle packets with ip option */ +if (VIRTIO_NET_IP4_HEADER_LENGTH != (ip->ip_ver_len &0xF )) { + chain->stat.ip_option++; +return RSC_BYPASS ; + } + +if (ip->ip_p !=IPPROTO_TCP ) { + chain->stat.bypass_not_tcp++; +return RSC_BYPASS ; + } + +/* Don't handle packets with ip fragment */ +if (!(htons (ip->ip_off) &IP_DF )) { + chain->stat.ip_frag++; +return RSC_BYPASS ; + } + + ip_len =htons (ip->ip_len); +if (ip_len < (sizeof (struct ip_header ) +sizeof (struct tcp_header )) + || ip_len > (size - hdr_len -sizeof (struct eth_header ))) { + chain->stat.ip_hacked++; +return RSC_BYPASS ; + } + +return RSC_WANT ; +} + +static size_t virtio_net_rsc_receive4 (NetRscChain *chain,NetClientState * nc, +const uint8_t *buf,size_t size) +{ +int32_t ret; +uint16_t hdr_len; +NetRscUnit unit; + + hdr_len = ((VirtIONet *)(chain->n))->guest_hdr_len; +virtio_net_rsc_extract_unit4 (chain, buf, &unit); +if (RSC_WANT !=virtio_net_rsc_sanity_check4 (chain, unit.ip, buf, size)) { +return virtio_net_do_receive (nc, buf, size); + } + + ret =virtio_net_rsc_tcp_ctrl_check (chain, unit.tcp); +if (ret ==RSC_BYPASS ) { +return virtio_net_do_receive (nc, buf, size); + }else if (ret ==RSC_FINAL ) { +return virtio_net_rsc_drain_flow (chain, nc, buf, size, + ((hdr_len +sizeof (struct eth_header )) +12 ), +VIRTIO_NET_IP4_ADDR_SIZE , + hdr_len +sizeof (struct eth_header ) +sizeof (struct ip_header ), +VIRTIO_NET_TCP_PORT_SIZE ); + } + +if (virtio_net_rsc_empty_cache (chain, nc, buf, size)) { +return size; + } + +return virtio_net_rsc_do_coalesce (chain, nc, buf, size, &unit); +} + +static NetRscChain *virtio_net_rsc_lookup_chain (VirtIONet * n, +NetClientState *nc, +uint16_t proto) +{ +NetRscChain *chain; + +if (proto != (uint16_t )ETH_P_IP ) { +return NULL ; + } + + QTAILQ_FOREACH(chain, &n->rsc_chains, next) { +if (chain->proto == proto) { +return chain; + } + } + + chain =g_malloc (sizeof (*chain)); + chain->n = n; + chain->proto = proto; + chain->max_payload =VIRTIO_NET_MAX_IP4_PAYLOAD ; + chain->gso_type =VIRTIO_NET_HDR_GSO_TCPV4 ; + chain->drain_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , + virtio_net_rsc_purge, chain); +memset (&chain->stat,0 ,sizeof (chain->stat)); + +QTAILQ_INIT (&chain->buffers); +QTAILQ_INSERT_TAIL (&n->rsc_chains, chain, next); + +return chain; +}static ssize_t virtio_net_rsc_receive (NetClientState *nc,const uint8_t *buf,size_t size) { -return virtio_net_do_receive (nc, buf, size); +uint16_t proto; +NetRscChain *chain; +struct eth_header *eth; +VirtIONet *n; + + n =qemu_get_nic_opaque (nc); +if (size < (n->guest_hdr_len +sizeof (struct eth_header ))) { +return virtio_net_do_receive (nc, buf, size); + } + + eth = (struct eth_header *)(buf + n->guest_hdr_len); + proto =htons (eth->h_proto); + + chain =virtio_net_rsc_lookup_chain (n, nc, proto); +if (!chain) { +return virtio_net_do_receive (nc, buf, size); + }else { + chain->stat.received++; +return virtio_net_rsc_receive4 (chain, nc, buf, size); + } }static ssize_t virtio_net_receive (NetClientState *nc,const uint8_t *buf,size_t size) {VirtIONet *n; +struct virtio_net_hdr *h; n =qemu_get_nic_opaque (nc); -if (n->curr_guest_offloads &VIRTIO_NET_F_GUEST_RSC ) { +if (n->curr_guest_offloads & (1ULL <<VIRTIO_NET_F_GUEST_RSC )) { + h = (struct virtio_net_hdr *)buf; + h->coalesced =0 ; + h->dup_ack =0 ;return virtio_net_rsc_receive (nc, buf, size); }else {return virtio_net_do_receive (nc, buf, size);
@@ -1837,6 +2314,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;register_savevm (dev,"virtio-net" ,-1 ,VIRTIO_NET_VM_VERSION , virtio_net_save, virtio_net_load, n);
@@ -1871,6 +2349,7 @@ static void virtio_net_device_unrealize(DeviceState *dev, Error **errp)g_free (n->vqs);qemu_del_nic (n->nic);virtio_cleanup (vdev); +virtio_net_rsc_cleanup (n); }static void virtio_net_instance_init (Object *obj)
@@ -1933,7 +2412,9 @@ static Property virtio_net_properties[] = {DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx),DEFINE_PROP_BIT ("guest_rsc" , VirtIONet, host_features, -VIRTIO_NET_F_GUEST_RSC , true), +VIRTIO_NET_F_GUEST_RSC , false), +DEFINE_PROP_UINT32 ("rsc_interval" , VirtIONet, rsc_timeout, +VIRTIO_NET_RSC_INTERVAL ), DEFINE_PROP_END_OF_LIST(), };
include/hw/virtio/virtio-net.h +2 -0
@@ -59,6 +59,8 @@ typedef struct VirtIONet {VirtIONetQueue *vqs;VirtQueue *ctrl_vq;NICState *nic; + QTAILQ_HEAD(, NetRscChain) rsc_chains; +uint32_t rsc_timeout;uint32_t tx_timeout;int32_t tx_burst;uint32_t has_vnet_hdr;
include/hw/virtio/virtio.h +75 -0
87 lines not on this page · raw message
include/standard-headers/linux/virtio_net.h +2 -0
@@ -114,6 +114,8 @@ struct virtio_net_hdr {__virtio16 gso_size;/* Bytes to append to hdr_len per frame */ __virtio16 csum_start;/* Position to start checksumming from */ __virtio16 csum_offset;/* Offset after that to place checksum */ +__virtio16 coalesced; +__virtio16 dup_ack; };/* This is the version of the header to use when the MRG_RXBUF
Signature · 1 line
2.7.1
RFC PATCH v5 2/2 virtio-net rsc: support coalescing ipv6 tcp traffic
In reply to [email protected]From: Wei Xu <[email protected]>
Most stuffs are like ipv4 2 differences between ipv4 and ipv6.
1. Fragment length in ipv4 header includes itself, while it's not included for ipv6, thus means ipv6 can carry a real '65535' payload.
2. IPv6 header does not need calculate header checksum.
--- hw/net/virtio-net.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 144 insertions(+), 8 deletions(-)
hw/net/virtio-net.c +144 -8
@@ -53,6 +53,10 @@/* header length value in ip header without option */ #define VIRTIO_NET_IP4_HEADER_LENGTH 5 +#define ETH_IP6_HDR_SZ (ETH_HDR_SZ + IP6_HDR_SZ) +#define VIRTIO_NET_IP6_ADDR_SIZE 32/* ipv6 saddr + daddr */ +#define VIRTIO_NET_MAX_IP6_PAYLOAD VIRTIO_NET_MAX_TCP_PAYLOAD +/* Purge coalesced packets timer interval, This value affects the performance a lot, and should be tuned carefully, '300000'(300us) is the recommended value to pass the WHQL test, '50000' can gain 2x netperf throughput with
@@ -1726,6 +1730,25 @@ static void virtio_net_rsc_extract_unit4(NetRscChain *chain, unit->payload =htons (*unit->ip_plen) - ip_hdrlen - unit->tcp_hdrlen; } +static void virtio_net_rsc_extract_unit6 (NetRscChain *chain, +const uint8_t *buf,NetRscUnit * unit) +{ +uint16_t hdr_len; +struct ip6_header *ip6; + + hdr_len = ((VirtIONet *)(chain->n))->guest_hdr_len; + ip6 = (struct ip6_header *)(buf + hdr_len +sizeof (struct eth_header )); + unit->ip = ip6; + unit->ip_plen = &(ip6->ip6_ctlun.ip6_un1.ip6_un1_plen); + unit->tcp = (struct tcp_header *)(((uint8_t *)unit->ip)\ + +sizeof (struct ip6_header )); + unit->tcp_hdrlen = (htons (unit->tcp->th_offset_flags) &0xF000 ) >>10 ; + +/* There is a difference between payload lenght in ipv4 and v6, +ip header is excluded in ipv6 */ + unit->payload =htons (*unit->ip_plen) - unit->tcp_hdrlen; +} +static void virtio_net_rsc_ipv4_checksum (struct virtio_net_hdr * vhdr,struct ip_header *ip) {
@@ -1744,7 +1767,9 @@ static size_t virtio_net_rsc_drain_seg(NetRscChain *chain, NetRscSeg *seg)struct virtio_net_hdr *h; h = (struct virtio_net_hdr *)seg->buf; -virtio_net_rsc_ipv4_checksum (h, seg->unit.ip); +if ((chain->proto ==ETH_P_IP ) && seg->is_coalesced) { +virtio_net_rsc_ipv4_checksum (h, seg->unit.ip); + } h->coalesced = seg->packets; h->dup_ack = seg->dup_ack_count; h->gso_type = chain->gso_type;
@@ -1804,7 +1829,7 @@ static void virtio_net_rsc_cache_buf(NetRscChain *chain, NetClientState *nc, hdr_len = chain->n->guest_hdr_len; seg =g_malloc (sizeof (NetRscSeg)); seg->buf =g_malloc (hdr_len +sizeof (struct eth_header )\ - +VIRTIO_NET_MAX_TCP_PAYLOAD ); + +sizeof (struct ip6_header ) +VIRTIO_NET_MAX_TCP_PAYLOAD );memcpy (seg->buf, buf, size); seg->size = size; seg->packets =1 ;
@@ -1815,7 +1840,18 @@ static void virtio_net_rsc_cache_buf(NetRscChain *chain, NetClientState *nc,QTAILQ_INSERT_TAIL (&chain->buffers, seg, next); chain->stat.cache++; -virtio_net_rsc_extract_unit4 (chain, seg->buf, &seg->unit); +switch (chain->proto) { +case ETH_P_IP : +virtio_net_rsc_extract_unit4 (chain, seg->buf, &seg->unit); +break ; + +case ETH_P_IPV6 : +virtio_net_rsc_extract_unit6 (chain, seg->buf, &seg->unit); +break ; + +default : +g_assert_not_reached (); + } } static int32_t virtio_net_rsc_handle_ack(NetRscChain *chain,
@@ -1935,6 +1971,24 @@ static int32_t virtio_net_rsc_coalesce4(NetRscChain *chain, NetRscSeg *seg,return virtio_net_rsc_coalesce_data (chain, seg, buf, unit); } +static int32_t virtio_net_rsc_coalesce6 (NetRscChain *chain,NetRscSeg *seg, +const uint8_t *buf,size_t size,NetRscUnit *unit) +{ +struct ip6_header *ip1, *ip2; + + ip1 = (struct ip6_header *)(unit->ip); + ip2 = (struct ip6_header *)(seg->unit.ip); +if (memcmp (&ip1->ip6_src, &ip2->ip6_src,sizeof (struct in6_address )) + ||memcmp (&ip1->ip6_dst, &ip2->ip6_dst,sizeof (struct in6_address )) + || (unit->tcp->th_sport ^ seg->unit.tcp->th_sport) + || (unit->tcp->th_dport ^ seg->unit.tcp->th_dport)) { + chain->stat.no_match++; +return RSC_NO_MATCH ; + } + +return virtio_net_rsc_coalesce_data (chain, seg, buf, unit); +} +/* Pakcets with 'SYN' should bypass, other flag should be sent after drain * to prevent out of order */ static int virtio_net_rsc_tcp_ctrl_check(NetRscChain *chain,
@@ -1987,7 +2041,11 @@ static size_t virtio_net_rsc_do_coalesce(NetRscChain *chain, NetClientState *nc,NetRscSeg *seg, *nseg; QTAILQ_FOREACH_SAFE(seg, &chain->buffers, next, nseg) { - ret =virtio_net_rsc_coalesce4 (chain, seg, buf, size, unit); +if (chain->proto ==ETH_P_IP ) { + ret =virtio_net_rsc_coalesce4 (chain, seg, buf, size, unit); + }else { + ret =virtio_net_rsc_coalesce6 (chain, seg, buf, size, unit); + }if (ret ==RSC_FINAL ) {if (virtio_net_rsc_drain_seg (chain, seg) ==0 ) {
@@ -2112,13 +2170,82 @@ static size_t virtio_net_rsc_receive4(NetRscChain *chain, NetClientState* nc,return virtio_net_rsc_do_coalesce (chain, nc, buf, size, &unit); } +static int32_t virtio_net_rsc_sanity_check6 (NetRscChain *chain, +struct ip6_header *ip6, +const uint8_t *buf,size_t size) +{ +uint16_t ip_len; +uint16_t hdr_len; + + hdr_len = ((VirtIONet *)(chain->n))->guest_hdr_len; +if (size < (hdr_len +sizeof (struct eth_header ) +sizeof (struct ip6_header ) + +sizeof (tcp_header))) { +return RSC_BYPASS ; + } + +if (((ip6->ip6_ctlun.ip6_un1.ip6_un1_flow &0xF0 ) >>4 ) + !=IP_HEADER_VERSION_6 ) { +return RSC_BYPASS ; + } + +/* Both option and protocol is checked in this */ +if (ip6->ip6_ctlun.ip6_un1.ip6_un1_nxt !=IPPROTO_TCP ) { + chain->stat.bypass_not_tcp++; +return RSC_BYPASS ; + } + + ip_len =htons (ip6->ip6_ctlun.ip6_un1.ip6_un1_plen); +if (ip_len <sizeof (struct tcp_header ) + || ip_len > (size - hdr_len -sizeof (struct eth_header ) + -sizeof (struct ip6_header ))) { + chain->stat.ip_hacked++; +return RSC_BYPASS ; + } + +return RSC_WANT ; +} + +static size_t virtio_net_rsc_receive6 (void *opq,NetClientState * nc, +const uint8_t *buf,size_t size) +{ +int32_t ret; +uint16_t hdr_len; +NetRscChain *chain; +NetRscUnit unit; + + chain = (NetRscChain *)opq; + hdr_len = ((VirtIONet *)(chain->n))->guest_hdr_len; +virtio_net_rsc_extract_unit6 (chain, buf, &unit); +if (RSC_WANT !=virtio_net_rsc_sanity_check6 (chain, + unit.ip, buf, size)) { +return virtio_net_do_receive (nc, buf, size); + } + + ret =virtio_net_rsc_tcp_ctrl_check (chain, unit.tcp); +if (ret ==RSC_BYPASS ) { +return virtio_net_do_receive (nc, buf, size); + }else if (ret ==RSC_FINAL ) { +return virtio_net_rsc_drain_flow (chain, nc, buf, size, + ((hdr_len +sizeof (struct eth_header )) +8 ), +VIRTIO_NET_IP6_ADDR_SIZE , + hdr_len +sizeof (struct eth_header ) +sizeof (struct ip6_header ), +VIRTIO_NET_TCP_PORT_SIZE ); + } + +if (virtio_net_rsc_empty_cache (chain, nc, buf, size)) { +return size; + } + +return virtio_net_rsc_do_coalesce (chain, nc, buf, size, &unit); +} +static NetRscChain *virtio_net_rsc_lookup_chain (VirtIONet * n,NetClientState *nc,uint16_t proto) {NetRscChain *chain; -if (proto != (uint16_t )ETH_P_IP ) { +if ((proto != (uint16_t )ETH_P_IP ) && (proto != (uint16_t )ETH_P_IPV6 )) {return NULL ; }
@@ -2131,8 +2258,13 @@ static NetRscChain *virtio_net_rsc_lookup_chain(VirtIONet * n, chain =g_malloc (sizeof (*chain)); chain->n = n; chain->proto = proto; - chain->max_payload =VIRTIO_NET_MAX_IP4_PAYLOAD ; - chain->gso_type =VIRTIO_NET_HDR_GSO_TCPV4 ; +if (proto == (uint16_t )ETH_P_IP ) { + chain->max_payload =VIRTIO_NET_MAX_IP4_PAYLOAD ; + chain->gso_type =VIRTIO_NET_HDR_GSO_TCPV4 ; + }else { + chain->max_payload =VIRTIO_NET_MAX_IP6_PAYLOAD ; + chain->gso_type =VIRTIO_NET_HDR_GSO_TCPV6 ; + } chain->drain_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , virtio_net_rsc_purge, chain);memset (&chain->stat,0 ,sizeof (chain->stat));
@@ -2164,7 +2296,11 @@ static ssize_t virtio_net_rsc_receive(NetClientState *nc,return virtio_net_do_receive (nc, buf, size); }else { chain->stat.received++; -return virtio_net_rsc_receive4 (chain, nc, buf, size); +if (proto == (uint16_t )ETH_P_IP ) { +return virtio_net_rsc_receive4 (chain, nc, buf, size); + }else { +return virtio_net_rsc_receive6 (chain, nc, buf, size); + } } }
Signature · 1 line
2.7.1
Quoted 11 lines · On 2016年05月24日 04:14, [email protected] wrote:
From: Wei Xu <[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.
Patch does not apply on master ...
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.
Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
Quoted 87 lines
Another suggestion from Jason is to adjust part of the code to make it more readable, since there maybe still few change about the flowchart in the future, such as timestamp, duplicate ack, so i'd like to delay it temporarily.
Changes in V4:
- Add new host feature bit
- Replace using fixed header lenght with dynamic header lenght in VirtIONet
- Change ip/ip6 header union in NetRscUnit to void* pointer
- Add macro prefix, adjust code indent, etc.Changes in V3:
- Removed big param list, replace it with 'NetRscUnit'
- Different virtio header size
- Modify callback function to direct call.
- Needn't check the failure ofg_malloc()
- Other code format adjustment, macro naming, etcChanges in V2:
- Add detailed commit logThis patch is to support WHQL test for Windows guest, while this feature also benifits other guest works as a kernel 'gro' like feature with userspace implementation.
Feature information:http://msdn.microsoft.com/en-us/library/windows/hardware/jj853324Both IPv4 and IPv6 are supported, though performance with userspace virtio is slow than vhost-net, there is about 1.5x to 2x performance improvement to userspace virtio, this is done by turning this feature on and disable 'tso/gso/gro' on corresponding tap interface and guest interface, while get less improment with all these feature on.
Linux guest performance data(Netperf):
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.2.101 () port 0AF_INET: nodelaySize Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec87380 16384 64 6.00 1221.20 87380 16384 64 6.00 1260.3087380 16384 128 6.00 1978.51 87380 16384 128 6.00 2286.0587380 16384 256 6.00 2677.94 87380 16384 256 6.00 4615.4287380 16384 512 6.00 2956.54 87380 16384 512 6.00 5356.3987380 16384 1024 6.00 2798.17 87380 16384 1024 6.00 4943.3087380 16384 2048 6.00 2681.09 87380 16384 2048 6.00 4835.8187380 16384 4096 6.00 3390.14 87380 16384 4096 6.00 5391.5487380 16384 8092 6.00 3008.27 87380 16384 8092 6.00 5381.6887380 16384 10240 6.00 2999.89 87380 16384 10240 6.00 5393.11Test steps:
Although this feature is mainly used for window guest, i used linux guest to help test the feature, to make things simple, i used 3 steps to test the patch as i moved on.1. With a tcp socket client/server pair running on 2 linux guest, thus i can control
the traffic and debugging the code as i want.
2. Netperf on linux guest test the throughput.
3. WHQL test with 2 Windows guests.Wei Xu (2):
virtio-net rsc: support coalescing ipv4 tcp traffic virtio-net rsc: support coalescing ipv6 tcp traffichw/net/virtio-net.c | 623 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 ++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 699 insertions(+), 3 deletions(-)
Quoted 30 lines · Jason Wang
Quoted 11 lines · On 2016年05月24日 04:14, [email protected] wrote:
From: Wei Xu <[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.Patch does not apply on master ...
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
Quoted 5 lines
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
True but disabling everything when feature is not negotiated reduces the risk somewhat.
Quoted 87 lines
Quoted 87 lines
Another suggestion from Jason is to adjust part of the code to make it more readable, since there maybe still few change about the flowchart in the future, such as timestamp, duplicate ack, so i'd like to delay it temporarily.
Changes in V4:
- Add new host feature bit
- Replace using fixed header lenght with dynamic header lenght in VirtIONet
- Change ip/ip6 header union in NetRscUnit to void* pointer
- Add macro prefix, adjust code indent, etc.Changes in V3:
- Removed big param list, replace it with 'NetRscUnit'
- Different virtio header size
- Modify callback function to direct call.
- Needn't check the failure ofg_malloc()
- Other code format adjustment, macro naming, etcChanges in V2:
- Add detailed commit logThis patch is to support WHQL test for Windows guest, while this feature also benifits other guest works as a kernel 'gro' like feature with userspace implementation.
Feature information:
http://msdn.microsoft.com/en-us/library/windows/hardware/jj853324Both IPv4 and IPv6 are supported, though performance with userspace virtio is slow than vhost-net, there is about 1.5x to 2x performance improvement to userspace virtio, this is done by turning this feature on and disable 'tso/gso/gro' on corresponding tap interface and guest interface, while get less improment with all these feature on.
Linux guest performance data(Netperf):
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.2.101 () port 0AF_INET: nodelaySize Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec87380 16384 64 6.00 1221.20 87380 16384 64 6.00 1260.3087380 16384 128 6.00 1978.51 87380 16384 128 6.00 2286.0587380 16384 256 6.00 2677.94 87380 16384 256 6.00 4615.4287380 16384 512 6.00 2956.54 87380 16384 512 6.00 5356.3987380 16384 1024 6.00 2798.17 87380 16384 1024 6.00 4943.3087380 16384 2048 6.00 2681.09 87380 16384 2048 6.00 4835.8187380 16384 4096 6.00 3390.14 87380 16384 4096 6.00 5391.5487380 16384 8092 6.00 3008.27 87380 16384 8092 6.00 5381.6887380 16384 10240 6.00 2999.89 87380 16384 10240 6.00 5393.11Test steps:
Although this feature is mainly used for window guest, i used linux guest to help test the feature, to make things simple, i used 3 steps to test the patch as i moved on.1. With a tcp socket client/server pair running on 2 linux guest, thus i can control
the traffic and debugging the code as i want.
2. Netperf on linux guest test the throughput.
3. WHQL test with 2 Windows guests.Wei Xu (2):
virtio-net rsc: support coalescing ipv4 tcp traffic virtio-net rsc: support coalescing ipv6 tcp traffichw/net/virtio-net.c | 623 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 ++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 699 insertions(+), 3 deletions(-)
Re: [Qemu-devel] [ RFC Patch v5 1/2] virtio-net rsc: support coalescing ipv4 tcp traffic/
In reply to [email protected]include/standard-headers/linux/virtio_net.h struct virtio_net_hdr { · line 121
Quoted 13 lines · On Tue, May 24, 2016 at 04:14:44AM +0800, [email protected] wrote:
include/standard-headers/linux/virtio_net.h +2
-0@@ -114,6 +114,8 @@ struct virtio_net_hdr {__virtio16 gso_size;/* Bytes to append to hdr_len per frame */ __virtio16 csum_start;/* Position to start checksumming from */ __virtio16 csum_offset;/* Offset after that to place checksum */ +__virtio16 coalesced; +__virtio16 dup_ack; };/* This is the version of the header to use when the MRG_RXBUF
OK so please post a proposal documenting feature bit and new fields to virtio TC mailing list.
No need to wait to get it upstream.
Quoted 2 lines
Signature · 1 line
2.7.1
Quoted 26 lines · Jason Wang
Quoted 11 lines · On 2016年05月24日 04:14, [email protected] wrote:
From: Wei Xu <[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.Patch does not apply on master ...
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.
Quoted 3 lines
Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
OK.
Quoted 6 lines
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
Exactly, both ipv4/6 passed whql test actually, so maybe leave the feature bit and header issue alone.
Quoted 100 lines
Quoted 98 lines
Another suggestion from Jason is to adjust part of the code to make it more readable, since there maybe still few change about the flowchart in the future, such as timestamp, duplicate ack, so i'd like to delay it temporarily.
Changes in V4:
- Add new host feature bit
- Replace using fixed header lenght with dynamic header lenght in VirtIONet
- Change ip/ip6 header union in NetRscUnit to void* pointer
- Add macro prefix, adjust code indent, etc.Changes in V3:
- Removed big param list, replace it with 'NetRscUnit'
- Different virtio header size
- Modify callback function to direct call.
- Needn't check the failure ofg_malloc()
- Other code format adjustment, macro naming, etcChanges in V2:
- Add detailed commit logThis patch is to support WHQL test for Windows guest, while this feature also
benifits other guest works as a kernel 'gro' like feature with userspace implementation.
Feature information:http://msdn.microsoft.com/en-us/library/windows/hardware/jj853324Both IPv4 and IPv6 are supported, though performance with userspace virtio
is slow than vhost-net, there is about 1.5x to 2x performance improvement to
userspace virtio, this is done by turning this feature on and disable 'tso/gso/gro' on corresponding tap interface and guest interface, while get
less improment with all these feature on.Linux guest performance data(Netperf):
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.2.101 () port 0AF_INET: nodelaySize Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec87380 16384 64 6.00 1221.20 87380 16384 64 6.00 1260.3087380 16384 128 6.00 1978.51 87380 16384 128 6.00 2286.0587380 16384 256 6.00 2677.94 87380 16384 256 6.00 4615.4287380 16384 512 6.00 2956.54 87380 16384 512 6.00 5356.3987380 16384 1024 6.00 2798.17 87380 16384 1024 6.00 4943.3087380 16384 2048 6.00 2681.09 87380 16384 2048 6.00 4835.8187380 16384 4096 6.00 3390.14 87380 16384 4096 6.00 5391.5487380 16384 8092 6.00 3008.27 87380 16384 8092 6.00 5381.6887380 16384 10240 6.00 2999.89 87380 16384 10240 6.00 5393.11Test steps:
Although this feature is mainly used for window guest, i used linux guest to
help test the feature, to make things simple, i used 3 steps to test the patch
as i moved on.1. With a tcp socket client/server pair running on 2 linux guest, thus i can
control
the traffic and debugging the code as i want.
2. Netperf on linux guest test the throughput.
3. WHQL test with 2 Windows guests.Wei Xu (2):
virtio-net rsc: support coalescing ipv4 tcp traffic virtio-net rsc: support coalescing ipv6 tcp traffichw/net/virtio-net.c | 623 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 ++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 699 insertions(+), 3 deletions(-)
Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Jason Wang
Quoted 11 lines · On 2016年05月24日 04:14, [email protected] wrote:
From: Wei Xu <[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.Patch does not apply on master ...
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
Quoted 8 lines
Quoted 5 lines
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
True but disabling everything when feature is not negotiated reduces the risk somewhat.
Sure.
Quoted 88 lines
Quoted 88 lines
Quoted 88 lines
Another suggestion from Jason is to adjust part of the code to make it more readable, since there maybe still few change about the flowchart in the future, such as timestamp, duplicate ack, so i'd like to delay it temporarily.
Changes in V4:
- Add new host feature bit
- Replace using fixed header lenght with dynamic header lenght in VirtIONet
- Change ip/ip6 header union in NetRscUnit to void* pointer
- Add macro prefix, adjust code indent, etc.Changes in V3:
- Removed big param list, replace it with 'NetRscUnit'
- Different virtio header size
- Modify callback function to direct call.
- Needn't check the failure ofg_malloc()
- Other code format adjustment, macro naming, etcChanges in V2:
- Add detailed commit logThis patch is to support WHQL test for Windows guest, while this feature also benifits other guest works as a kernel 'gro' like feature with userspace implementation.
Feature information:http://msdn.microsoft.com/en-us/library/windows/hardware/jj853324Both IPv4 and IPv6 are supported, though performance with userspace virtio is slow than vhost-net, there is about 1.5x to 2x performance improvement to userspace virtio, this is done by turning this feature on and disable 'tso/gso/gro' on corresponding tap interface and guest interface, while get less improment with all these feature on.
Linux guest performance data(Netperf):
MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0AF_INETto 192.168.2.101 () port 0AF_INET: nodelaySize Size Size Time Throughput bytes bytes bytes secs. 10^6bits/sec87380 16384 64 6.00 1221.20 87380 16384 64 6.00 1260.3087380 16384 128 6.00 1978.51 87380 16384 128 6.00 2286.0587380 16384 256 6.00 2677.94 87380 16384 256 6.00 4615.4287380 16384 512 6.00 2956.54 87380 16384 512 6.00 5356.3987380 16384 1024 6.00 2798.17 87380 16384 1024 6.00 4943.3087380 16384 2048 6.00 2681.09 87380 16384 2048 6.00 4835.8187380 16384 4096 6.00 3390.14 87380 16384 4096 6.00 5391.5487380 16384 8092 6.00 3008.27 87380 16384 8092 6.00 5381.6887380 16384 10240 6.00 2999.89 87380 16384 10240 6.00 5393.11Test steps:
Although this feature is mainly used for window guest, i used linux guest to help test the feature, to make things simple, i used 3 steps to test the patch as i moved on.1. With a tcp socket client/server pair running on 2 linux guest, thus i can control
the traffic and debugging the code as i want.
2. Netperf on linux guest test the throughput.
3. WHQL test with 2 Windows guests.Wei Xu (2):
virtio-net rsc: support coalescing ipv4 tcp traffic virtio-net rsc: support coalescing ipv6 tcp traffichw/net/virtio-net.c | 623 +++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + include/hw/virtio/virtio.h | 75 ++++ include/standard-headers/linux/virtio_net.h | 2 + 4 files changed, 699 insertions(+), 3 deletions(-)
Quoted 31 lines · Michael S. Tsirkin
Quoted 30 lines · Jason Wang
Quoted 30 lines · On 2016年05月24日 04:14,[email protected] wrote:
Quoted 11 lines
Quoted 11 lines
From: Wei Xu<[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.Patch does not apply on master ...
Quoted 8 lines
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
True but disabling everything when feature is not negotiated reduces the risk somewhat.
Yes, but I believe we can only merge the patch with new virtio features after they were accepted by spec?
Quoted 39 lines · Jason Wang
Quoted 36 lines · Michael S. Tsirkin
Quoted 35 lines · Jason Wang
Quoted 35 lines · On 2016年05月24日 04:14,[email protected] wrote:
Quoted 11 lines
Quoted 11 lines
From: Wei Xu<[email protected]>
Changes in V5:
- Passed all IPv4/6 test cases
- Add new fields in 'virtio_net_hdr'
- Set 'gso_type' & 'coalesced packets' in new field.
- Bypass all 'tcp option' packet
- Bypass all 'pure ack' packet
- Bypass all 'duplicate ack' packet
- Change 'guest_rsc' feature bit to 'false' by default
- Feedbacks from v4, typo, etc.Patch does not apply on master ...
Quoted 8 lines
Quoted 8 lines
Note:
There is still a few pending issues about the feature bit, and need to be discussed with windows driver maintainer, so linux guests with this patch won't work at current, haven't figure it out yet, but i'm guessing it's caused by the 'gso_type' is set to 'VIRTIO_NET_HDR_GSO_TCPV4/6', will fix it after get the final solution, the below test steps and performance data is based on v4.Can we split the patches into smaller ones to make review or merging easier? E.g can we send the patches without any feature negotiation and vnet header extension?
We can focus on the coalescing (maybe ipv4) without any guest involvement in this series. In this way, the issues were limited and can be converged soon. After this has been merged, we can add patches that co-operate with guests on top (since it needs agreement on virtio specs). Does this sounds a good plan?
Quoted 6 lines
Quoted 3 lines
True but disabling everything when feature is not negotiated reduces the risk somewhat.
Yes, but I believe we can only merge the patch with new virtio features after they were accepted by spec?
Spec acceptance takes a lot of time. I think it's required to send proposal to virtio tc and to give a week or two for people to comment, but if there are no comments I don't think we must hold up code.
I am interested in hearing whether new fields should be added to all packets, or rather to packets with a specific bit set in flags or gso_type field.
Signature · 1 line
MST