[dpdk-dev] [PATCH v2 09/12] virtio: add Rx checksum offload support

Olivier Matz olivier.matz at 6wind.com
Wed Oct 5 13:56:36 CEST 2016


Hi Maxime,

On 10/03/2016 02:51 PM, Maxime Coquelin wrote:
>> --- a/drivers/net/virtio/virtio_rxtx.c
>> +++ b/drivers/net/virtio/virtio_rxtx.c
>> @@ -50,6 +50,7 @@
>>  #include <rte_string_fns.h>
>>  #include <rte_errno.h>
>>  #include <rte_byteorder.h>
>> +#include <rte_net.h>
>>
>>  #include "virtio_logs.h"
>>  #include "virtio_ethdev.h"
>> @@ -627,6 +628,56 @@ virtio_update_packet_stats(struct virtnet_stats
>> *stats, struct rte_mbuf *mbuf)
>>      }
>>  }
>>
>> +/* Optionally fill offload information in structure */
>> +static int
>> +virtio_rx_offload(struct rte_mbuf *m, struct virtio_net_hdr *hdr)
>> +{
>> +    struct rte_net_hdr_lens hdr_lens;
>> +    uint32_t hdrlen, ptype;
>> +    int l4_supported = 0;
>> +
>> +    /* nothing to do */
>> +    if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
>> +        return 0;
> Maybe we could first check whether offload features were negotiated?
> Doing this, we could return before accessing the header and so avoid a
> cache miss.

Yes, doing this would avoid reading the virtio header when the rx
function is virtio_recv_pkts(). When using virtio_recv_mergeable_pkts(),
it won't have a big impact since we already need to read hdr->num_buffers.


I plan to do something like this in both recv functions:

@@ -854,6 +854,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
**rx_pkts, uint16_t nb_pkts)
        int error;
        uint32_t i, nb_enqueued;
        uint32_t hdr_size;
+       uint64_t features;
        struct virtio_net_hdr *hdr;

        nb_used = VIRTQUEUE_NUSED(vq);
@@ -872,6 +873,7 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
**rx_pkts, uint16_t nb_pkts)
        nb_rx = 0;
        nb_enqueued = 0;
        hdr_size = hw->vtnet_hdr_size;
+       features = hw->guest_features;

        for (i = 0; i < num ; i++) {
                rxm = rcv_pkts[i];
@@ -903,7 +905,8 @@ virtio_recv_pkts(void *rx_queue, struct rte_mbuf
**rx_pkts, uint16_t nb_pkts)
                        rte_vlan_strip(rxm);

                /* Update offload features */
-               if (virtio_rx_offload(rxm, hdr) < 0) {
+               if ((features & VIRTIO_NET_F_GUEST_CSUM) &&
+                               virtio_rx_offload(rxm, hdr) < 0) {
                        virtio_discard_rxbuf(vq, rxm);
                        rxvq->stats.errors++;
                        continue;


Thank you for the feedback.
Olivier


More information about the dev mailing list