* [PATCH] vhost: Only access header if offloading is supported in dequeue path
@ 2016-10-06 17:00 Maxime Coquelin
2016-10-06 17:06 ` Maxime Coquelin
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-10-06 17:00 UTC (permalink / raw)
To: yuanhan.liu, dev
Cc: mst, jianfeng.tan, olivier.matz, stephen, Maxime Coquelin
If offloading features are not negotiated, parsing the virtio header
is not needed.
Micro-benchmark with testpmd shows that the gain is +4% with indirect
descriptors, +1% when using direct descriptors.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/librte_vhost/virtio_net.c | 47 ++++++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index a59c39b..5d51693 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -548,6 +548,18 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
return virtio_dev_rx(dev, queue_id, pkts, count);
}
+static inline bool
+virtio_net_with_host_offload(struct virtio_net *dev)
+{
+ if (dev->features &
+ (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_ECN |
+ VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 |
+ VIRTIO_NET_F_HOST_UFO))
+ return true;
+
+ return false;
+}
+
static void
parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
{
@@ -600,6 +612,9 @@ vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
void *l4_hdr = NULL;
struct tcp_hdr *tcp_hdr = NULL;
+ if (hdr->flags == 0 || hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
+ return;
+
parse_ethernet(m, &l4_proto, &l4_hdr);
if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
if (hdr->csum_start == (m->l2_len + m->l3_len)) {
@@ -684,12 +699,12 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
struct rte_mempool *mbuf_pool)
{
struct vring_desc *desc;
- uint64_t desc_addr;
+ uint64_t desc_addr = 0;
uint32_t desc_avail, desc_offset;
uint32_t mbuf_avail, mbuf_offset;
uint32_t cpy_len;
struct rte_mbuf *cur = m, *prev = m;
- struct virtio_net_hdr *hdr;
+ struct virtio_net_hdr *hdr = NULL;
/* A counter to avoid desc dead loop chain */
uint32_t nr_desc = 1;
@@ -698,12 +713,14 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
(desc->flags & VRING_DESC_F_INDIRECT))
return -1;
- desc_addr = gpa_to_vva(dev, desc->addr);
- if (unlikely(!desc_addr))
- return -1;
+ if (virtio_net_with_host_offload(dev)) {
+ desc_addr = gpa_to_vva(dev, desc->addr);
+ if (unlikely(!desc_addr))
+ return -1;
- hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
- rte_prefetch0(hdr);
+ hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
+ rte_prefetch0(hdr);
+ }
/*
* A virtio driver normally uses at least 2 desc buffers
@@ -720,18 +737,24 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
if (unlikely(!desc_addr))
return -1;
- rte_prefetch0((void *)(uintptr_t)desc_addr);
-
desc_offset = 0;
desc_avail = desc->len;
nr_desc += 1;
-
- PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);
} else {
+ if (!desc_addr) {
+ desc_addr = gpa_to_vva(dev, desc->addr);
+ if (unlikely(!desc_addr))
+ return -1;
+ }
+
desc_avail = desc->len - dev->vhost_hlen;
desc_offset = dev->vhost_hlen;
}
+ rte_prefetch0((void *)(uintptr_t)(desc_addr + desc_offset));
+
+ PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), desc_avail, 0);
+
mbuf_offset = 0;
mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
while (1) {
@@ -795,7 +818,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
prev->data_len = mbuf_offset;
m->pkt_len += mbuf_offset;
- if (hdr->flags != 0 || hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)
+ if (virtio_net_with_host_offload(dev))
vhost_dequeue_offload(hdr, m);
return 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] vhost: Only access header if offloading is supported in dequeue path
2016-10-06 17:00 [PATCH] vhost: Only access header if offloading is supported in dequeue path Maxime Coquelin
@ 2016-10-06 17:06 ` Maxime Coquelin
2016-10-11 7:45 ` [PATCH v2] " Maxime Coquelin
2016-10-14 8:07 ` [PATCH v3] " Maxime Coquelin
2 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-10-06 17:06 UTC (permalink / raw)
To: yuanhan.liu, dev; +Cc: mst, jianfeng.tan, olivier.matz, stephen
On 10/06/2016 07:00 PM, Maxime Coquelin wrote:
> If offloading features are not negotiated, parsing the virtio header
> is not needed.
>
> Micro-benchmark with testpmd shows that the gain is +4% with indirect
> descriptors, +1% when using direct descriptors.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
> lib/librte_vhost/virtio_net.c | 47 ++++++++++++++++++++++++++++++++-----------
> 1 file changed, 35 insertions(+), 12 deletions(-)
>
> diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
> index a59c39b..5d51693 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -548,6 +548,18 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
> return virtio_dev_rx(dev, queue_id, pkts, count);
> }
>
> +static inline bool
> +virtio_net_with_host_offload(struct virtio_net *dev)
> +{
> + if (dev->features &
> + (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_ECN |
> + VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 |
> + VIRTIO_NET_F_HOST_UFO))
> + return true;
> +
> + return false;
> +}
> +
> static void
> parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
> {
> @@ -600,6 +612,9 @@ vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
> void *l4_hdr = NULL;
> struct tcp_hdr *tcp_hdr = NULL;
>
> + if (hdr->flags == 0 || hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
> + return;
> +
Oops, just noticed I forgot to amend a fix I did.
Of course, the above test should be:
if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
It will be fixed in the v2.
Regards,
Maxime
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2] vhost: Only access header if offloading is supported in dequeue path
2016-10-06 17:00 [PATCH] vhost: Only access header if offloading is supported in dequeue path Maxime Coquelin
2016-10-06 17:06 ` Maxime Coquelin
@ 2016-10-11 7:45 ` Maxime Coquelin
2016-10-11 9:01 ` Yuanhan Liu
2016-10-14 8:07 ` [PATCH v3] " Maxime Coquelin
2 siblings, 1 reply; 7+ messages in thread
From: Maxime Coquelin @ 2016-10-11 7:45 UTC (permalink / raw)
To: yuanhan.liu, dev
Cc: mst, jianfeng.tan, olivier.matz, stephen, Maxime Coquelin
If offloading features are not negotiated, parsing the virtio header
is not needed.
Micro-benchmark with testpmd shows that the gain is +4% with indirect
descriptors, +1% when using direct descriptors.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
Changes since v1:
=================
- Rebased
- Fix early out check in vhost_dequeue_offload
lib/librte_vhost/virtio_net.c | 47 ++++++++++++++++++++++++++++++++-----------
1 file changed, 35 insertions(+), 12 deletions(-)
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index a59c39b..5e2fd75 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -548,6 +548,18 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
return virtio_dev_rx(dev, queue_id, pkts, count);
}
+static inline bool
+virtio_net_with_host_offload(struct virtio_net *dev)
+{
+ if (dev->features &
+ (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_ECN |
+ VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 |
+ VIRTIO_NET_F_HOST_UFO))
+ return true;
+
+ return false;
+}
+
static void
parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
{
@@ -600,6 +612,9 @@ vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
void *l4_hdr = NULL;
struct tcp_hdr *tcp_hdr = NULL;
+ if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
+ return;
+
parse_ethernet(m, &l4_proto, &l4_hdr);
if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
if (hdr->csum_start == (m->l2_len + m->l3_len)) {
@@ -684,12 +699,12 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
struct rte_mempool *mbuf_pool)
{
struct vring_desc *desc;
- uint64_t desc_addr;
+ uint64_t desc_addr = 0;
uint32_t desc_avail, desc_offset;
uint32_t mbuf_avail, mbuf_offset;
uint32_t cpy_len;
struct rte_mbuf *cur = m, *prev = m;
- struct virtio_net_hdr *hdr;
+ struct virtio_net_hdr *hdr = NULL;
/* A counter to avoid desc dead loop chain */
uint32_t nr_desc = 1;
@@ -698,12 +713,14 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
(desc->flags & VRING_DESC_F_INDIRECT))
return -1;
- desc_addr = gpa_to_vva(dev, desc->addr);
- if (unlikely(!desc_addr))
- return -1;
+ if (virtio_net_with_host_offload(dev)) {
+ desc_addr = gpa_to_vva(dev, desc->addr);
+ if (unlikely(!desc_addr))
+ return -1;
- hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
- rte_prefetch0(hdr);
+ hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
+ rte_prefetch0(hdr);
+ }
/*
* A virtio driver normally uses at least 2 desc buffers
@@ -720,18 +737,24 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
if (unlikely(!desc_addr))
return -1;
- rte_prefetch0((void *)(uintptr_t)desc_addr);
-
desc_offset = 0;
desc_avail = desc->len;
nr_desc += 1;
-
- PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);
} else {
+ if (!desc_addr) {
+ desc_addr = gpa_to_vva(dev, desc->addr);
+ if (unlikely(!desc_addr))
+ return -1;
+ }
+
desc_avail = desc->len - dev->vhost_hlen;
desc_offset = dev->vhost_hlen;
}
+ rte_prefetch0((void *)(uintptr_t)(desc_addr + desc_offset));
+
+ PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), desc_avail, 0);
+
mbuf_offset = 0;
mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
while (1) {
@@ -795,7 +818,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
prev->data_len = mbuf_offset;
m->pkt_len += mbuf_offset;
- if (hdr->flags != 0 || hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)
+ if (virtio_net_with_host_offload(dev))
vhost_dequeue_offload(hdr, m);
return 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] vhost: Only access header if offloading is supported in dequeue path
2016-10-11 7:45 ` [PATCH v2] " Maxime Coquelin
@ 2016-10-11 9:01 ` Yuanhan Liu
2016-10-14 7:24 ` Maxime Coquelin
0 siblings, 1 reply; 7+ messages in thread
From: Yuanhan Liu @ 2016-10-11 9:01 UTC (permalink / raw)
To: Maxime Coquelin; +Cc: dev, mst, jianfeng.tan, olivier.matz, stephen
On Tue, Oct 11, 2016 at 09:45:27AM +0200, Maxime Coquelin wrote:
> @@ -684,12 +699,12 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
> struct rte_mempool *mbuf_pool)
> {
> struct vring_desc *desc;
> - uint64_t desc_addr;
> + uint64_t desc_addr = 0;
> uint32_t desc_avail, desc_offset;
> uint32_t mbuf_avail, mbuf_offset;
> uint32_t cpy_len;
> struct rte_mbuf *cur = m, *prev = m;
> - struct virtio_net_hdr *hdr;
> + struct virtio_net_hdr *hdr = NULL;
> /* A counter to avoid desc dead loop chain */
> uint32_t nr_desc = 1;
>
> @@ -698,12 +713,14 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
> (desc->flags & VRING_DESC_F_INDIRECT))
> return -1;
>
> - desc_addr = gpa_to_vva(dev, desc->addr);
> - if (unlikely(!desc_addr))
> - return -1;
> + if (virtio_net_with_host_offload(dev)) {
> + desc_addr = gpa_to_vva(dev, desc->addr);
> + if (unlikely(!desc_addr))
> + return -1;
>
> - hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
> - rte_prefetch0(hdr);
> + hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
> + rte_prefetch0(hdr);
> + }
>
> /*
> * A virtio driver normally uses at least 2 desc buffers
> @@ -720,18 +737,24 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
> if (unlikely(!desc_addr))
> return -1;
>
> - rte_prefetch0((void *)(uintptr_t)desc_addr);
> -
> desc_offset = 0;
> desc_avail = desc->len;
> nr_desc += 1;
> -
> - PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);
> } else {
> + if (!desc_addr) {
> + desc_addr = gpa_to_vva(dev, desc->addr);
> + if (unlikely(!desc_addr))
> + return -1;
> + }
> +
I think this piece of code make things a bit complex. I think what you
want to achieve is, besides saving hdr prefetch, to save one call to
gpa_to_vva() for the non-ANY_LAYOUT case. Does that matter too much?
How about just saving the hdr prefetch?
if (virtio_net_with_host_offload(dev)) {
hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
rte_prefetch0(hdr);
}
--yliu
> desc_avail = desc->len - dev->vhost_hlen;
> desc_offset = dev->vhost_hlen;
> }
>
> + rte_prefetch0((void *)(uintptr_t)(desc_addr + desc_offset));
> +
> + PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), desc_avail, 0);
> +
> mbuf_offset = 0;
> mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
> while (1) {
> @@ -795,7 +818,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
> prev->data_len = mbuf_offset;
> m->pkt_len += mbuf_offset;
>
> - if (hdr->flags != 0 || hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)
> + if (virtio_net_with_host_offload(dev))
> vhost_dequeue_offload(hdr, m);
>
> return 0;
> --
> 2.7.4
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] vhost: Only access header if offloading is supported in dequeue path
2016-10-11 9:01 ` Yuanhan Liu
@ 2016-10-14 7:24 ` Maxime Coquelin
0 siblings, 0 replies; 7+ messages in thread
From: Maxime Coquelin @ 2016-10-14 7:24 UTC (permalink / raw)
To: Yuanhan Liu; +Cc: dev, mst, jianfeng.tan, olivier.matz, stephen
On 10/11/2016 11:01 AM, Yuanhan Liu wrote:
> On Tue, Oct 11, 2016 at 09:45:27AM +0200, Maxime Coquelin wrote:
>> @@ -684,12 +699,12 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
>> struct rte_mempool *mbuf_pool)
>> {
>> struct vring_desc *desc;
>> - uint64_t desc_addr;
>> + uint64_t desc_addr = 0;
>> uint32_t desc_avail, desc_offset;
>> uint32_t mbuf_avail, mbuf_offset;
>> uint32_t cpy_len;
>> struct rte_mbuf *cur = m, *prev = m;
>> - struct virtio_net_hdr *hdr;
>> + struct virtio_net_hdr *hdr = NULL;
>> /* A counter to avoid desc dead loop chain */
>> uint32_t nr_desc = 1;
>>
>> @@ -698,12 +713,14 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
>> (desc->flags & VRING_DESC_F_INDIRECT))
>> return -1;
>>
>> - desc_addr = gpa_to_vva(dev, desc->addr);
>> - if (unlikely(!desc_addr))
>> - return -1;
>> + if (virtio_net_with_host_offload(dev)) {
>> + desc_addr = gpa_to_vva(dev, desc->addr);
>> + if (unlikely(!desc_addr))
>> + return -1;
>>
>> - hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
>> - rte_prefetch0(hdr);
>> + hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
>> + rte_prefetch0(hdr);
>> + }
>>
>> /*
>> * A virtio driver normally uses at least 2 desc buffers
>> @@ -720,18 +737,24 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
>> if (unlikely(!desc_addr))
>> return -1;
>>
>> - rte_prefetch0((void *)(uintptr_t)desc_addr);
>> -
>> desc_offset = 0;
>> desc_avail = desc->len;
>> nr_desc += 1;
>> -
>> - PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);
>> } else {
>> + if (!desc_addr) {
>> + desc_addr = gpa_to_vva(dev, desc->addr);
>> + if (unlikely(!desc_addr))
>> + return -1;
>> + }
>> +
>
> I think this piece of code make things a bit complex. I think what you
> want to achieve is, besides saving hdr prefetch, to save one call to
> gpa_to_vva() for the non-ANY_LAYOUT case. Does that matter too much?
>
> How about just saving the hdr prefetch?
>
> if (virtio_net_with_host_offload(dev)) {
> hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
> rte_prefetch0(hdr);
> }
Oops, you reply slipped through the cracks...
You're right, it doesn't matter too much, the thing to avoid id
definitely the hdr prefetch and access.
I'm sending a v3 now.
Thanks,
Maxime
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3] vhost: Only access header if offloading is supported in dequeue path
2016-10-06 17:00 [PATCH] vhost: Only access header if offloading is supported in dequeue path Maxime Coquelin
2016-10-06 17:06 ` Maxime Coquelin
2016-10-11 7:45 ` [PATCH v2] " Maxime Coquelin
@ 2016-10-14 8:07 ` Maxime Coquelin
2016-10-18 14:30 ` Yuanhan Liu
2 siblings, 1 reply; 7+ messages in thread
From: Maxime Coquelin @ 2016-10-14 8:07 UTC (permalink / raw)
To: yuanhan.liu, dev
Cc: mst, jianfeng.tan, olivier.matz, stephen, Maxime Coquelin
If offloading features are not negotiated, parsing the virtio header
is not needed.
Micro-benchmark with testpmd shows that the gain is +4% with indirect
descriptors, +1% when using direct descriptors.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
Changes since v2:
=================
- Simplify code by translating first desc address
unconditionnaly (Yuanhan)
- Instead of checking features again, check whether
hdr has been assign to call offload function.
Changes since v1:
=================
- Rebased
- Fix early out check in vhost_dequeue_offload
lib/librte_vhost/virtio_net.c | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 812e5d3..15ef0b0 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -555,6 +555,18 @@ rte_vhost_enqueue_burst(int vid, uint16_t queue_id,
return virtio_dev_rx(dev, queue_id, pkts, count);
}
+static inline bool
+virtio_net_with_host_offload(struct virtio_net *dev)
+{
+ if (dev->features &
+ (VIRTIO_NET_F_CSUM | VIRTIO_NET_F_HOST_ECN |
+ VIRTIO_NET_F_HOST_TSO4 | VIRTIO_NET_F_HOST_TSO6 |
+ VIRTIO_NET_F_HOST_UFO))
+ return true;
+
+ return false;
+}
+
static void
parse_ethernet(struct rte_mbuf *m, uint16_t *l4_proto, void **l4_hdr)
{
@@ -607,6 +619,9 @@ vhost_dequeue_offload(struct virtio_net_hdr *hdr, struct rte_mbuf *m)
void *l4_hdr = NULL;
struct tcp_hdr *tcp_hdr = NULL;
+ if (hdr->flags == 0 && hdr->gso_type == VIRTIO_NET_HDR_GSO_NONE)
+ return;
+
parse_ethernet(m, &l4_proto, &l4_hdr);
if (hdr->flags == VIRTIO_NET_HDR_F_NEEDS_CSUM) {
if (hdr->csum_start == (m->l2_len + m->l3_len)) {
@@ -702,7 +717,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint32_t mbuf_avail, mbuf_offset;
uint32_t cpy_len;
struct rte_mbuf *cur = m, *prev = m;
- struct virtio_net_hdr *hdr;
+ struct virtio_net_hdr *hdr = NULL;
/* A counter to avoid desc dead loop chain */
uint32_t nr_desc = 1;
@@ -715,8 +730,10 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
if (unlikely(!desc_addr))
return -1;
- hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
- rte_prefetch0(hdr);
+ if (virtio_net_with_host_offload(dev)) {
+ hdr = (struct virtio_net_hdr *)((uintptr_t)desc_addr);
+ rte_prefetch0(hdr);
+ }
/*
* A virtio driver normally uses at least 2 desc buffers
@@ -733,18 +750,18 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
if (unlikely(!desc_addr))
return -1;
- rte_prefetch0((void *)(uintptr_t)desc_addr);
-
desc_offset = 0;
desc_avail = desc->len;
nr_desc += 1;
-
- PRINT_PACKET(dev, (uintptr_t)desc_addr, desc->len, 0);
} else {
desc_avail = desc->len - dev->vhost_hlen;
desc_offset = dev->vhost_hlen;
}
+ rte_prefetch0((void *)(uintptr_t)(desc_addr + desc_offset));
+
+ PRINT_PACKET(dev, (uintptr_t)(desc_addr + desc_offset), desc_avail, 0);
+
mbuf_offset = 0;
mbuf_avail = m->buf_len - RTE_PKTMBUF_HEADROOM;
while (1) {
@@ -831,7 +848,7 @@ copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
prev->data_len = mbuf_offset;
m->pkt_len += mbuf_offset;
- if (hdr->flags != 0 || hdr->gso_type != VIRTIO_NET_HDR_GSO_NONE)
+ if (hdr)
vhost_dequeue_offload(hdr, m);
return 0;
--
2.7.4
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3] vhost: Only access header if offloading is supported in dequeue path
2016-10-14 8:07 ` [PATCH v3] " Maxime Coquelin
@ 2016-10-18 14:30 ` Yuanhan Liu
0 siblings, 0 replies; 7+ messages in thread
From: Yuanhan Liu @ 2016-10-18 14:30 UTC (permalink / raw)
To: Maxime Coquelin; +Cc: dev, mst, jianfeng.tan, olivier.matz, stephen
On Fri, Oct 14, 2016 at 10:07:07AM +0200, Maxime Coquelin wrote:
> If offloading features are not negotiated, parsing the virtio header
> is not needed.
>
> Micro-benchmark with testpmd shows that the gain is +4% with indirect
> descriptors, +1% when using direct descriptors.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Applied to dpdk-next-virtio.
Thanks.
--yliu
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-18 14:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-06 17:00 [PATCH] vhost: Only access header if offloading is supported in dequeue path Maxime Coquelin
2016-10-06 17:06 ` Maxime Coquelin
2016-10-11 7:45 ` [PATCH v2] " Maxime Coquelin
2016-10-11 9:01 ` Yuanhan Liu
2016-10-14 7:24 ` Maxime Coquelin
2016-10-14 8:07 ` [PATCH v3] " Maxime Coquelin
2016-10-18 14:30 ` Yuanhan Liu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.