Skip to contentSkip to conversation

enables vhost/virtio any layout feature

PATCH In review Yuanhan Liu 6 participants 45 messages Sep 26, 2016 – Nov 10, 2016 1 message not in the archive Network drivers

lore
Share & tools
lore
#0 lore raw

cover enables vhost/virtio any layout feature

The feature is actually supported both in virtio PMD and vhost lib. We just haven't enabled it yet. This patchset simply enables it.

---
Yuanhan Liu (2):
vhost: enable any layout feature
net/virtio: enable any layout feature

 drivers/net/virtio/virtio_ethdev.h | 1 +
 lib/librte_vhost/vhost.c           | 1 +
 lib/librte_vhost/vhost.h           | 3 +++
 3 files changed, 5 insertions(+)
Signature · 1 line
1.9.0
#1 lore raw

PATCH 1/2 vhost: enable any layout feature

The VIRTIO_F_ANY_LAYOUT feature allows virtio-net header and packet data in single vring desc if possible. Before that, it is assumed they will always take two descs.

DPDK vhost removes this assumption since commit bc7f87a2c19f ("vhost:
refactor dequeueing"), meaning we actually support this feature. But it is not enabled.

Thus, this patch enables it.

---
 lib/librte_vhost/vhost.c | 1 +
 lib/librte_vhost/vhost.h | 3 +++
 2 files changed, 4 insertions(+)
lib/librte_vhost/vhost.c +1 -0
index 46095c3..1d8d941 100644
@@ -57,6 +57,7 @@
 				(1ULL << VIRTIO_NET_F_CTRL_RX) | \
 				(1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) | \
 				(VHOST_SUPPORTS_MQ)            | \
+				(1ULL << VIRTIO_F_ANY_LAYOUT)  | \
 				(1ULL << VIRTIO_F_VERSION_1)   | \
 				(1ULL << VHOST_F_LOG_ALL)      | \
 				(1ULL << VHOST_USER_F_PROTOCOL_FEATURES) | \
lib/librte_vhost/vhost.h +3 -0
index c2dfc3c..5ee6c6c 100644
@@ -92,6 +92,9 @@ struct vhost_virtqueue {
  #define VIRTIO_NET_F_GUEST_ANNOUNCE 21
 #endif
 
+#ifndef VIRTIO_F_ANY_LAYOUT
+ #define VIRTIO_F_ANY_LAYOUT 27
+#endif
 
 /*
  * Make an extra wrapper for VIRTIO_NET_F_MQ and
Signature · 1 line
1.9.0
#2 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

I assume that if using Version 1 that the bit will be ignored

#3 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 2 lines · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

One way is to require that users specify all flags fully when creating the virtio net device. QEMU could verify that all required flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

Signature · 1 line
MST
#4 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

Quoted 5 lines

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

One way is to require that users specify all flags fully when creating the virtio net device.

Like how? By a new command line option? And user has to type all those features?

Quoted 11 lines

QEMU could verify that all required
flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

That means the management tool would somehow has a dependency on DPDK project, which I have no objection at all. But, is that a good idea?

BTW, I'm not quite sure I followed your idea. I mean, how it supposed to fix the ANY_LAYOUT issue here? How this flag will be set for legacy device?

	--yliu
#5 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 10 lines · On Tue, 27 Sep 2016 11:11:58 +0800 Yuanhan Liu <[email protected]>…
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

Quoted 7 lines

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

- I'm following the way Linux kernel takes: it also set both features.

Agreed, just do what the Linux kernel does.

#6 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

In reply to Yuanhan Liu
Quoted 16 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

Quoted 8 lines

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

Quoted 8 lines
Quoted 5 lines

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

One way is to require that users specify all flags fully when creating the virtio net device.

Like how? By a new command line option? And user has to type all those features?

Make libvirt do this. users use management normally. those that don't likely don't migrate VMs.

Quoted 12 lines
Quoted 11 lines

QEMU could verify that all required
flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

Quoted 3 lines

That means the management tool would somehow has a dependency on DPDK project, which I have no objection at all. But, is that a good idea?

It already starts the bridge somehow, does it not?

Quoted 5 lines

BTW, I'm not quite sure I followed your idea. I mean, how it supposed to fix the ANY_LAYOUT issue here? How this flag will be set for legacy device?

	--yliu

For ANY_LAYOUT, I think we should just set in in qemu, but only for new machine types. This addresses migration concerns.

But there will be more new features in the future and it is necessary to think how we will enable them without breaking migration.

Signature · 1 line
MST
#7 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 33 lines · Michael S. Tsirkin
Quoted 16 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

Quoted 8 lines

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

Quoted 3 lines
Quoted 3 lines

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

One way is to require that users specify all flags fully when creating the virtio net device.

Like how? By a new command line option? And user has to type all those features?

Make libvirt do this. users use management normally. those that don't likely don't migrate VMs.

Fair enough.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

QEMU could verify that all required
flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

Will the feature negotiation between DPDK and QEMU still exist in your proposal?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

Quoted 5 lines
Quoted 3 lines

That means the management tool would somehow has a dependency on DPDK project, which I have no objection at all. But, is that a good idea?

It already starts the bridge somehow, does it not?

Indeed. I was firstly thinking about reading the dpdk source file to determine the DPDK supported feature list, with which the bind is too tight. I later realized you may ask DPDK to provide a binary to dump the list, or something like that.

Quoted 9 lines
Quoted 6 lines

BTW, I'm not quite sure I followed your idea. I mean, how it supposed to fix the ANY_LAYOUT issue here? How this flag will be set for legacy device?

	--yliu

For ANY_LAYOUT, I think we should just set in in qemu, but only for new machine types.

What do you mean by "new machine types"? Virtio device with newer virtio-spec version?

Quoted 2 lines

This addresses migration
concerns.

To make sure I followed you, do you mean the migration issue from an older "dpdk + qemu" combo to a newer "dpdk + qemu" combo (that more new features might be shipped)?

Besides that, your proposal looks like a big work to accomplish. Are you okay to make it simple first: set it consistently like what Linux kernel does? This would at least make the ANY_LAYOUT actually be enabled for legacy device (which is also the default one that's widely used so far).

	--yliu
Quoted 7 lines

But there will be more new features in the future and it is necessary to think how we will enable them without breaking migration.

Signature · 1 line
MST
#8 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 93 lines · Yuanhan Liu
Quoted 33 lines · Michael S. Tsirkin
Quoted 16 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

Quoted 8 lines

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

Quoted 3 lines
Quoted 3 lines

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

One way is to require that users specify all flags fully when creating the virtio net device.

Like how? By a new command line option? And user has to type all those features?

Make libvirt do this. users use management normally. those that don't likely don't migrate VMs.

Fair enough.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

QEMU could verify that all required
flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

Will the feature negotiation between DPDK and QEMU still exist in your proposal?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

Quoted 5 lines
Quoted 3 lines

That means the management tool would somehow has a dependency on DPDK project, which I have no objection at all. But, is that a good idea?

It already starts the bridge somehow, does it not?

Indeed. I was firstly thinking about reading the dpdk source file to determine the DPDK supported feature list, with which the bind is too tight. I later realized you may ask DPDK to provide a binary to dump the list, or something like that.

Quoted 9 lines
Quoted 6 lines

BTW, I'm not quite sure I followed your idea. I mean, how it supposed to fix the ANY_LAYOUT issue here? How this flag will be set for legacy device?

	--yliu

For ANY_LAYOUT, I think we should just set in in qemu, but only for new machine types.

What do you mean by "new machine types"? Virtio device with newer virtio-spec version?

Quoted 2 lines

This addresses migration
concerns.

To make sure I followed you, do you mean the migration issue from an older "dpdk + qemu" combo to a newer "dpdk + qemu" combo (that more new features might be shipped)?

Quoted 5 lines

Besides that, your proposal looks like a big work to accomplish. Are you okay to make it simple first: set it consistently like what Linux kernel does? This would at least make the ANY_LAYOUT actually be enabled for legacy device (which is also the default one that's widely used so far).

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

-- Maxime
[0]: For testing, you'll need these patches, else only first packets will use a single slot:
- http://dpdk.org/dev/patchwork/patch/16222/
- http://dpdk.org/dev/patchwork/patch/16223/

#9 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 108 lines · Maxime Coquelin
Quoted 93 lines · Yuanhan Liu
Quoted 33 lines · Michael S. Tsirkin
Quoted 16 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

Quoted 8 lines

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

Quoted 3 lines
Quoted 3 lines

Therein lies a problem. If dpdk tweaks flags, updating it will break guest migration.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

One way is to require that users specify all flags fully when creating the virtio net device.

Like how? By a new command line option? And user has to type all those features?

Make libvirt do this. users use management normally. those that don't likely don't migrate VMs.

Fair enough.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

QEMU could verify that all required
flags are set, and fail init if not.

This has other advantages, e.g. it adds ability to init device without waiting for dpdk to connect.

Will the feature negotiation between DPDK and QEMU still exist in your proposal?

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

However, enabling each new feature would now require management work. How about dpdk ships the list
of supported features instead?
Management tools could read them on source and destination and select features supported on both sides.

Quoted 5 lines
Quoted 3 lines

That means the management tool would somehow has a dependency on DPDK project, which I have no objection at all. But, is that a good idea?

It already starts the bridge somehow, does it not?

Indeed. I was firstly thinking about reading the dpdk source file to determine the DPDK supported feature list, with which the bind is too tight. I later realized you may ask DPDK to provide a binary to dump the list, or something like that.

Quoted 9 lines
Quoted 6 lines

BTW, I'm not quite sure I followed your idea. I mean, how it supposed to fix the ANY_LAYOUT issue here? How this flag will be set for legacy device?

	--yliu

For ANY_LAYOUT, I think we should just set in in qemu, but only for new machine types.

What do you mean by "new machine types"? Virtio device with newer virtio-spec version?

Quoted 2 lines

This addresses migration
concerns.

To make sure I followed you, do you mean the migration issue from an older "dpdk + qemu" combo to a newer "dpdk + qemu" combo (that more new features might be shipped)?

Quoted 5 lines

Besides that, your proposal looks like a big work to accomplish. Are you okay to make it simple first: set it consistently like what Linux kernel does? This would at least make the ANY_LAYOUT actually be enabled for legacy device (which is also the default one that's widely used so far).

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

Quoted 4 lines

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

What will happen? Will the header be uninitialized?

The spec says:
The driver can send a completely checksummed packet. In this case, flags will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set flags to zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have been negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Quoted 5 lines

-- Maxime
[0]: For testing, you'll need these patches, else only first packets will use a single slot:
- http://dpdk.org/dev/patchwork/patch/16222/
- http://dpdk.org/dev/patchwork/patch/16223/

#10 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 1 line · Michael S. Tsirkin

On Thu, Sep 29, 2016 at 05:30:53PM +0200, Maxime Coquelin wrote:

...

Quoted 7 lines
Quoted 7 lines

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

Quoted 6 lines
Quoted 4 lines

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

What will happen? Will the header be uninitialized?

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

Quoted 12 lines

The spec says:
The driver can send a completely checksummed packet. In this case, flags will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set flags to zero and SHOULD supply a fully
checksummed packet to the device.

Quoted 7 lines

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have been negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

From the micro-benchmarks results, we can expect +10% compared to indirect descriptors, and + 5% compared to using 2 descs in the virtqueue.
Also, it should have the same benefits as indirect descriptors for 0% pkt loss (as we can fill 2x more packets in the virtqueue).

What do you think?

Thanks,
Maxime

#11 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 17 lines · Maxime Coquelin
Quoted 1 line · Michael S. Tsirkin

On Thu, Sep 29, 2016 at 05:30:53PM +0200, Maxime Coquelin wrote:

...

Quoted 12 lines
Quoted 11 lines

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

Quoted 5 lines
Quoted 1 line

What will happen? Will the header be uninitialized?

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

In linux guest skbs are initialized AFAIK. See virtio_net_hdr_from_skb first thing it does is

        memset(hdr, 0, sizeof(*hdr));
Quoted 17 lines
Quoted 17 lines

The spec says:
The driver can send a completely checksummed packet. In this case, flags will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set flags to zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have been negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

Quoted 6 lines
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

Yes but two points.

1. why is this memset expensive? Is the test completely skipping looking at the packet otherwise?

2. As long as we are doing this, see

	Alignment vs. Networking
	========================

in Documentation/unaligned-memory-access.txt

Quoted 10 lines

From the micro-benchmarks results, we can expect +10% compared to indirect descriptors, and + 5% compared to using 2 descs in the virtqueue.
Also, it should have the same benefits as indirect descriptors for 0% pkt loss (as we can fill 2x more packets in the virtqueue).

What do you think?

Thanks,
Maxime

#12 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Maxime Coquelin
Quoted 1 line · Michael S. Tsirkin

On Thu, Sep 29, 2016 at 05:30:53PM +0200, Maxime Coquelin wrote:

...

Quoted 13 lines
Quoted 11 lines

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

What will happen? Will the header be uninitialized?

Quoted 8 lines
Quoted 4 lines

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

In linux guest skbs are initialized AFAIK. See virtio_net_hdr_from_skb first thing it does is

        memset(hdr, 0, sizeof(*hdr));

I meant in vhost-net linux implementation, the header is just skipped:

static void handle_tx(struct vhost_net *net)
{
...

		/* Skip header. TODO: support TSO. */
		len = iov_length(vq->iov, out);
		iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
		iov_iter_advance(&msg.msg_iter, hdr_size);

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

	/*
	 * A virtio driver normally uses at least 2 desc buffers
	 * for Tx: the first for storing the header, and others
	 * for storing the data.
	 */
	if (likely((desc->len == dev->vhost_hlen) &&
		   (desc->flags & VRING_DESC_F_NEXT) != 0)) {
		desc = &descs[desc->next];
		if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
			return -1;

		desc_addr = gpa_to_vva(dev, desc->addr);
		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;
	}
Quoted 27 lines
Quoted 20 lines
Quoted 20 lines

The spec says:
The driver can send a completely checksummed packet. In this case, flags will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set flags to zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have been negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

Quoted 6 lines
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

Quoted 4 lines

Yes but two points.

1. why is this memset expensive? Is the test completely skipping looking at the packet otherwise?

Yes.

Quoted 5 lines

2. As long as we are doing this, see

	Alignment vs. Networking
	========================

in Documentation/unaligned-memory-access.txt

Thanks, I'll have a look tomorrow.

Maxime

#13 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 68 lines · Maxime Coquelin
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Maxime Coquelin
Quoted 1 line · Michael S. Tsirkin

On Thu, Sep 29, 2016 at 05:30:53PM +0200, Maxime Coquelin wrote:

...

Quoted 14 lines
Quoted 8 lines

Before enabling anything by default, we should first optimize the 1 slot
case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

Quoted 4 lines

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

What will happen? Will the header be uninitialized?

Quoted 8 lines
Quoted 4 lines

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

In linux guest skbs are initialized AFAIK. See virtio_net_hdr_from_skb first thing it does is

        memset(hdr, 0, sizeof(*hdr));

I meant in vhost-net linux implementation, the header is just skipped:

static void handle_tx(struct vhost_net *net)
{
...

        /* Skip header. TODO: support TSO. */
        len = iov_length(vq->iov, out);
        iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
        iov_iter_advance(&msg.msg_iter, hdr_size);

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        if (unlikely(!desc_addr))
            return -1;

        rte_prefetch0((void *)(uintptr_t)desc_addr);

        desc_offset = 0;
Quoted 8 lines
        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;
    }

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

Quoted 34 lines
Quoted 30 lines
Quoted 23 lines
Quoted 23 lines

The spec says:
The driver can send a completely checksummed packet. In this
case, flags
will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set
flags to
zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have
been
negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

Quoted 6 lines
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

Quoted 4 lines

Yes but two points.

1. why is this memset expensive? Is the test completely skipping looking at the packet otherwise?

Quoted 7 lines

Yes.

Quoted 5 lines

2. As long as we are doing this, see
Alignment vs. Networking
========================
in Documentation/unaligned-memory-access.txt

Thanks, I'll have a look tomorrow.

I did a rough prototype which removes Tx headers unconditionally, to see what gain we could expect. I expect the results to be a little lower with no headers in full implementation, as some more checks will have to be done.

For PVP use-case with 0.05% acceptable packets loss:
- Original (with headers): 9.43Mpps
- Indirect descs: 9.36 Mpps
- Prototype (no headers): 10.65Mpps

For PVP use-case with 0% acceptable packets loss:
- Original (with headers): 5.23Mpps
- Indirect descs: 7.13 Mpps
- Prototype (no headers): 7.92Mpps

Maxime

#14 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 80 lines · Maxime Coquelin
Quoted 68 lines · Maxime Coquelin
Quoted 20 lines · Michael S. Tsirkin
Quoted 19 lines · Maxime Coquelin
Quoted 1 line · Michael S. Tsirkin

On Thu, Sep 29, 2016 at 05:30:53PM +0200, Maxime Coquelin wrote:

...

Quoted 14 lines
Quoted 8 lines

Before enabling anything by default, we should first optimize the 1 slot
case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

Quoted 4 lines

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

What will happen? Will the header be uninitialized?

Quoted 8 lines
Quoted 4 lines

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

In linux guest skbs are initialized AFAIK. See virtio_net_hdr_from_skb first thing it does is

        memset(hdr, 0, sizeof(*hdr));

I meant in vhost-net linux implementation, the header is just skipped:

static void handle_tx(struct vhost_net *net)
{
...

        /* Skip header. TODO: support TSO. */
        len = iov_length(vq->iov, out);
        iov_iter_init(&msg.msg_iter, WRITE, vq->iov, out, len);
        iov_iter_advance(&msg.msg_iter, hdr_size);

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        if (unlikely(!desc_addr))
            return -1;

        rte_prefetch0((void *)(uintptr_t)desc_addr);

        desc_offset = 0;
Quoted 8 lines
        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;
    }
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

Quoted 58 lines
Quoted 34 lines
Quoted 30 lines
Quoted 23 lines
Quoted 23 lines

The spec says:
The driver can send a completely checksummed packet. In this
case, flags
will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set
flags to
zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have
been
negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

Quoted 6 lines
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

Quoted 4 lines

Yes but two points.

1. why is this memset expensive? Is the test completely skipping looking at the packet otherwise?

Quoted 7 lines

Yes.

Quoted 5 lines

2. As long as we are doing this, see
Alignment vs. Networking
========================
in Documentation/unaligned-memory-access.txt

Thanks, I'll have a look tomorrow.

I did a rough prototype which removes Tx headers unconditionally, to see what gain we could expect. I expect the results to be a little lower with no headers in full implementation, as some more checks will have to be done.

For PVP use-case with 0.05% acceptable packets loss:
- Original (with headers): 9.43Mpps
- Indirect descs: 9.36 Mpps
- Prototype (no headers): 10.65Mpps

For PVP use-case with 0% acceptable packets loss:
- Original (with headers): 5.23Mpps
- Indirect descs: 7.13 Mpps
- Prototype (no headers): 7.92Mpps

Maxime

author Acked-by Huawei Xie Tested-by Rich Lane
#15 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 35 lines · Michael S. Tsirkin
Quoted 35 lines
Quoted 34 lines

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        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;
    }
Quoted 7 lines
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

It's added by following commit, which yields about 10% performance boosts for PVP case (with 64B packet size).

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

#16 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 47 lines · Yuanhan Liu
Quoted 35 lines · Michael S. Tsirkin
Quoted 35 lines
Quoted 34 lines

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        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;
    }
Quoted 7 lines
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

It's added by following commit, which yields about 10% performance boosts for PVP case (with 64B packet size).

Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 9 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Quoted 8 lines

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?
Should be a simple matter to apply this optimization for indirect.

#17 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 71 lines · Michael S. Tsirkin
Quoted 47 lines · Yuanhan Liu
Quoted 35 lines · Michael S. Tsirkin
Quoted 35 lines
Quoted 34 lines

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        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;
    }
Quoted 7 lines
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

It's added by following commit, which yields about 10% performance boosts for PVP case (with 64B packet size).

Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

	--yliu
#18 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 72 lines · Yuanhan Liu
Quoted 71 lines · Michael S. Tsirkin
Quoted 47 lines · Yuanhan Liu
Quoted 35 lines · Michael S. Tsirkin
Quoted 35 lines
Quoted 34 lines

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        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;
    }
Quoted 7 lines
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

It's added by following commit, which yields about 10% performance boosts for PVP case (with 64B packet size).

Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

It's not needed there though - you only use 1 desc, no point in fetching the next one.

Quoted 5 lines
Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

	--yliu
#19 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

In reply to Yuanhan Liu
Quoted 76 lines · Yuanhan Liu
Quoted 75 lines · Michael S. Tsirkin
Quoted 47 lines · Yuanhan Liu
Quoted 35 lines · Michael S. Tsirkin
Quoted 35 lines
Quoted 34 lines

And the same is done is done in DPDK:

static inline int __attribute__((always_inline)) copy_desc_to_mbuf(struct virtio_net *dev, struct vring_desc *descs,
uint16_t max_desc, struct rte_mbuf *m, uint16_t desc_idx, struct rte_mempool *mbuf_pool)
{
...

    /*
     * A virtio driver normally uses at least 2 desc buffers
     * for Tx: the first for storing the header, and others
     * for storing the data.
     */
    if (likely((desc->len == dev->vhost_hlen) &&
           (desc->flags & VRING_DESC_F_NEXT) != 0)) {
        desc = &descs[desc->next];
        if (unlikely(desc->flags & VRING_DESC_F_INDIRECT))
            return -1;

        desc_addr = gpa_to_vva(dev, desc->addr);
        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;
    }
Quoted 7 lines
Quoted 3 lines

Actually, the header is parsed in DPDK vhost implementation. But as Virtio PMD provides a zero'ed header, we could just parse the header only if VIRTIO_NET_F_NO_TX_HEADER is not negotiated.

host can always skip the header parse if it wants to. It didn't seem worth it to add branches there but if I'm wrong, by all means code it up.

It's added by following commit, which yields about 10% performance boosts for PVP case (with 64B packet size).

Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 17 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 7 lines
Quoted 2 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Maxime

#20 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 30 lines · Maxime Coquelin
Quoted 30 lines
Quoted 29 lines
Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 9 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Quoted 8 lines

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Quoted 7 lines
Quoted 4 lines

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Aha..., you are right!

	--yliu
#21 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 32 lines · Yuanhan Liu
Quoted 31 lines · Maxime Coquelin
Quoted 31 lines
Quoted 23 lines
Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Aha..., you are right!

The interesting thing is that the patch I send on Thursday that removes header access when no offload has been negotiated[0] seems to reduce almost to zero the performance seen with indirect descriptors enabled. I see this with 64 bytes packets using testpmd on both ends.

When I did the patch, I would have expected the same gain with both modes, whereas I measured +1% for direct and +4% for indirect.

Maxime
[0]: http://dpdk.org/dev/patchwork/patch/16423/

#22 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 39 lines · Maxime Coquelin
Quoted 36 lines · Yuanhan Liu
Quoted 35 lines · Maxime Coquelin
Quoted 34 lines
Quoted 23 lines
Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Aha..., you are right!

The interesting thing is that the patch I send on Thursday that removes header access when no offload has been negotiated[0] seems to reduce almost to zero the performance seen with indirect descriptors enabled.

Didn't follow that.

Quoted 4 lines

I see this with 64 bytes packets using testpmd on both ends.

When I did the patch, I would have expected the same gain with both modes, whereas I measured +1% for direct and +4% for indirect.

IIRC, I did a test before (remove those offload code piece), and the performance was basically the same before and after that. Well, there might be some small difference, say 1% as you said. But the result has never been steady.

Anyway, I think your patch is good to have: I just didn't see v2.

	--yliu
#23 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 56 lines · Yuanhan Liu
Quoted 39 lines · Maxime Coquelin
Quoted 36 lines · Yuanhan Liu
Quoted 35 lines · Maxime Coquelin
Quoted 34 lines
Quoted 23 lines
Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Aha..., you are right!

The interesting thing is that the patch I send on Thursday that removes header access when no offload has been negotiated[0] seems to reduce almost to zero the performance seen with indirect descriptors enabled.

Didn't follow that.

Quoted 4 lines

I see this with 64 bytes packets using testpmd on both ends.

When I did the patch, I would have expected the same gain with both modes, whereas I measured +1% for direct and +4% for indirect.

Quoted 6 lines

IIRC, I did a test before (remove those offload code piece), and the performance was basically the same before and after that. Well, there might be some small difference, say 1% as you said. But the result has never been steady.

Anyway, I think your patch is good to have: I just didn't see v2.

I waited to gather some comments/feedback before sending the v2. I'll send it today or tomorrow.

Thanks,
Maxime

#24 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 64 lines · Maxime Coquelin
Quoted 61 lines · Yuanhan Liu
Quoted 39 lines · Maxime Coquelin
Quoted 36 lines · Yuanhan Liu
Quoted 35 lines · Maxime Coquelin
Quoted 34 lines
Quoted 23 lines
Quoted 6 lines

At that time, a packet always use 2 descs. Since indirect desc is enabled (by default) now, the assumption is not true then. What's worse, it might even slow things a bit down. That should also be part of the reason why performance is slightly worse than before.

	--yliu

I'm not sure I get what you are saying

Quoted 14 lines

commit 1d41d77cf81c448c1b09e1e859bfd300e2054a98

Author: Yuanhan Liu <[email protected]>
Date:   Mon May 2 17:46:17 2016 -0700

vhost: optimize dequeue for small packets

A virtio driver normally uses at least 2 desc buffers for Tx: the first for storing the header, and the others for storing the data.

Therefore, we could fetch the first data desc buf before the main loop, and do the copy first before the check of "are we done yet?". This could save one check for small packets that just have one data desc buffer and need one mbuf to store it.

Quoted 6 lines
Quoted 3 lines

This fast-paths the 2-descriptors format but it's not active for indirect descriptors. Is this what you mean?

Yes. It's also not active when ANY_LAYOUT is actually turned on.

Quoted 1 line

Should be a simple matter to apply this optimization for indirect.

Might be.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

If I understand the code correctly, indirect descs also benefit from this optimization, or am I missing something?

Aha..., you are right!

The interesting thing is that the patch I send on Thursday that removes header access when no offload has been negotiated[0] seems to reduce almost to zero the performance seen with indirect descriptors enabled.

Didn't follow that.

Quoted 4 lines

I see this with 64 bytes packets using testpmd on both ends.

When I did the patch, I would have expected the same gain with both modes, whereas I measured +1% for direct and +4% for indirect.

IIRC, I did a test before (remove those offload code piece), and the performance was basically the same before and after that. Well, there might be some small difference, say 1% as you said. But the result has never been steady.

Quoted 4 lines
Quoted 1 line

Anyway, I think your patch is good to have: I just didn't see v2.

I waited to gather some comments/feedback before sending the v2. I'll send it today or tomorrow.

Interesting, I saw a deadlock then: I haven't looked at the code carefully once you said there is a v2, thus I'm waiting for it. However, you are waitting for my review. :)

Anyway, I will take time to look at it shortly.

	--yliu
#25 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

In reply to Michael S. Tsirkin
Quoted 54 lines · Michael S. Tsirkin
Quoted 17 lines · Maxime Coquelin
Quoted 17 lines · Michael S. Tsirkin
Quoted 1 line
Quoted 1 line · Maxime Coquelin

...

Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Quoted 11 lines

Before enabling anything by default, we should first optimize the 1 slot case. Indeed, micro-benchmark using testpmd in txonly[0] shows ~17% perf regression for 64 bytes case:
- 2 descs per packet: 11.6Mpps
- 1 desc per packet: 9.6Mpps

This is due to the virtio header clearing in virtqueue_enqueue_xmit(). Removing it, we get better results than with 2 descs (1.20Mpps). Since the Virtio PMD doesn't support offloads, I wonder whether we can just drop the memset?

Quoted 5 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line

What will happen? Will the header be uninitialized?

Yes..
I didn't look closely at the spec, but just looked at DPDK's and Linux vhost implementations. IIUC, the header is just skipped in the two implementations.

In linux guest skbs are initialized AFAIK. See virtio_net_hdr_from_skb first thing it does is

        memset(hdr, 0, sizeof(*hdr));
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

The spec says:
The driver can send a completely checksummed packet. In this case, flags will be zero, and gso_type
will be VIRTIO_NET_HDR_GSO_NONE.

and
The driver MUST set num_buffers to zero.
If VIRTIO_NET_F_CSUM is not negotiated, the driver MUST set flags to zero and SHOULD supply a fully
checksummed packet to the device.

and
If none of the VIRTIO_NET_F_HOST_TSO4, TSO6 or UFO options have been negotiated, the driver MUST
set gso_type to VIRTIO_NET_HDR_GSO_NONE.

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

Yes but two points.

Quoted 7 lines

1. why is this memset expensive? Is the test completely skipping looking at the packet otherwise?

2. As long as we are doing this, see

	Alignment vs. Networking
	========================

in Documentation/unaligned-memory-access.txt

This change will not have an impact on the IP header alignment, as is offset in the mbuf will not change.

Regards,
Maxime

#26 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

In reply to Michael S. Tsirkin
Quoted 7 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Yes but two points.

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth. BTW, It's kind of an overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu
Quoted 19 lines

Is the test completely skipping looking
at the packet otherwise?

2. As long as we are doing this, see

	Alignment vs. Networking
	========================

in Documentation/unaligned-memory-access.txt

Quoted 10 lines

From the micro-benchmarks results, we can expect +10% compared to indirect descriptors, and + 5% compared to using 2 descs in the virtqueue.
Also, it should have the same benefits as indirect descriptors for 0% pkt loss (as we can fill 2x more packets in the virtqueue).

What do you think?

Thanks,
Maxime

#27 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 5 lines · Yuanhan Liu
Quoted 4 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Quoted 8 lines
Quoted 3 lines

Yes but two points.

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Quoted 12 lines

BTW, It's kind of an
overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

Quoted 7 lines

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Quoted 19 lines
Quoted 19 lines

Is the test completely skipping looking
at the packet otherwise?

2. As long as we are doing this, see

	Alignment vs. Networking
	========================

in Documentation/unaligned-memory-access.txt

Quoted 10 lines

From the micro-benchmarks results, we can expect +10% compared to indirect descriptors, and + 5% compared to using 2 descs in the virtqueue.
Also, it should have the same benefits as indirect descriptors for 0% pkt loss (as we can fill 2x more packets in the virtqueue).

What do you think?

Thanks,
Maxime

#28 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Yuanhan Liu
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Yes but two points.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Good to know!

Quoted 15 lines
Quoted 15 lines

overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

Quoted 6 lines
Quoted 3 lines

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

	--yliu
#29 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 48 lines

-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Monday, October 10, 2016 11:59 AM
To: Michael S. Tsirkin <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; qemu- [email protected]; Wang, Zhihong <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Yuanhan Liu
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Yes but two points.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Good to know!

Quoted 17 lines
Quoted 17 lines

overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

Quoted 7 lines
Quoted 4 lines
Quoted 1 line
	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes serious frontend issue.

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

Quoted 2 lines
	--yliu
#30 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 53 lines · Zhihong
Quoted 53 lines

-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Monday, October 10, 2016 11:59 AM
To: Michael S. Tsirkin <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; qemu- [email protected]; Wang, Zhihong <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Yuanhan Liu
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Yes but two points.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Good to know!

Quoted 21 lines
Quoted 11 lines

overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

Quoted 7 lines

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Quoted 7 lines
Quoted 2 lines

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes serious frontend issue.

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

I just wrote some test code and compiled with gcc -O2, it did get inlined.

It's probably this:

        uint16_t head_size = vq->hw->vtnet_hdr_size;
...
                memset(hdr, 0, head_size);

IOW head_size is not known to compiler.

Try sticking a bool there instead of vtnet_hdr_size, and

	 memset(hdr, 0, bigheader ? 10 : 12);
Quoted 2 lines
Quoted 2 lines
	--yliu
#31 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

In reply to Wang, Zhihong
Quoted 53 lines · Zhihong
Quoted 53 lines

-----Original Message-----
From: Yuanhan Liu [mailto:[email protected]]
Sent: Monday, October 10, 2016 11:59 AM
To: Michael S. Tsirkin <[email protected]>
Cc: Maxime Coquelin <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; qemu- [email protected]; Wang, Zhihong <[email protected]>
Subject: Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Yuanhan Liu
Quoted 6 lines · Michael S. Tsirkin
Quoted 3 lines · Maxime Coquelin

On 09/29/2016 07:57 PM, Michael S. Tsirkin wrote:

Yes but two points.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Good to know!

Quoted 21 lines
Quoted 11 lines

overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

Quoted 7 lines

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Quoted 7 lines
Quoted 2 lines

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes serious frontend issue.

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

So try something like this then:

drivers/net/virtio/virtio_pci.h +10 -0
index dd7693f..7a3f88e 100644
@@ -292,6 +292,16 @@ vtpci_with_feature(struct virtio_hw *hw, uint64_t bit)
 	return (hw->guest_features & (1ULL << bit)) != 0;
 }
 
+static inline int
+vtnet_hdr_size(struct virtio_hw *hw)
+{
+	if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
+	    vtpci_with_feature(hw, VIRTIO_F_VERSION_1))
+		return sizeof(struct virtio_net_hdr_mrg_rxbuf);
+	else
+		return sizeof(struct virtio_net_hdr);
+}
+
 /*
  * Function declaration from virtio_pci.c
  */
drivers/net/virtio/virtio_rxtx.c +1 -1
index a27208e..21a45e1 100644
@@ -216,7 +216,7 @@ virtqueue_enqueue_xmit(struct virtnet_tx *txvq, struct rte_mbuf *cookie,
 	struct vring_desc *start_dp;
 	uint16_t seg_num = cookie->nb_segs;
 	uint16_t head_idx, idx;
-	uint16_t head_size = vq->hw->vtnet_hdr_size;
+	uint16_t head_size = vtnet_hdr_size(vq->hw);
 	unsigned long offs;
 
 	head_idx = vq->vq_desc_head_idx;

Generally pointer chasing in vq->hw->vtnet_hdr_size can't be good for performance. Move fields used on data path into vq and use from there to avoid indirections?

#32 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 36 lines · Michael S. Tsirkin
Quoted 36 lines
Quoted 35 lines
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

1. why is this memset expensive?

I don't have the exact answer, but just some rough thoughts:

It's an external clib function: there is a call stack and the IP register will bounch back and forth.

for memset 0? gcc 5.3.1 on fedora happily inlines it.

Good to know!

Quoted 15 lines
Quoted 15 lines

overkill to use that for resetting 14 bytes structure.

Some trick like

    *(struct virtio_net_hdr *)hdr = {0, };

Or even

    hdr->xxx = 0;
    hdr->yyy = 0;

should behaviour better.

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC) on my Ivybridge server: it has no such issue on his server though.

Quoted 6 lines
Quoted 3 lines

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

Quoted 7 lines
Quoted 4 lines

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes serious frontend issue.

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

So try something like this then:

Yes, I saw memset is inlined when this diff is applied.

So, mind to send a formal patch? You might want to try build at least:
it doesn't build.

Quoted 3 lines

Generally pointer chasing in vq->hw->vtnet_hdr_size can't be good for performance. Move fields used on data path into vq and use from there to avoid indirections?

Good suggestion!

	--yliu
#33 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 2 lines · Yuanhan Liu
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC)

Though it doesn't matter now, but I have verified it yesterday (with and wihtout memset), the drop could be up to 30+%.

This is to let you know that it could behaviour badly if memset is not inlined.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu

I'd say that's weird. what's your config? any chance you are using an old compiler?

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes serious frontend issue.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

So try something like this then:

Yes, I saw memset is inlined when this diff is applied.

I have another concern though: It's a trick could let gcc do the inline, I am not quite sure whether that's ture with other compilers (i.e. clang, icc, or even, older gcc).

For this case, I think I still prefer some trick like

    *(struct ..*) = {0, }

Or even, we may could introduce rte_memset(). IIRC, that has been proposed somehow before?

	--yliu

A message that is not in the archive (sent off-list or not yet received): F5DF4F0E3AFEF648ADC1C3C33AD4DBF16C2409EB@SHSMSX101.ccr.corp.intel.com

#35 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Hi, Yuanhan:

Quoted 49 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Yuanhan Liu
Sent: Wednesday, October 12, 2016 11:22 AM
To: Michael S. Tsirkin <[email protected]>; Thomas Monjalon <[email protected]>
Cc: Wang, Zhihong <[email protected]>; Maxime Coquelin <[email protected]>; Stephen Hemminger <[email protected]>; [email protected]; qemu- [email protected]
Subject: Re: [dpdk-dev] [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

Quoted 3 lines · Yuanhan Liu
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

There was an example: the vhost enqueue optmization patchset from Zhihong [0] uses memset, and it introduces more than 15% drop (IIRC)

Though it doesn't matter now, but I have verified it yesterday (with and wihtout memset), the drop could be up to 30+%.

This is to let you know that it could behaviour badly if memset is not inlined.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

on my Ivybridge server: it has no such issue on his server though.

[0]: http://dpdk.org/ml/archives/dev/2016-August/045272.html

	--yliu
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I'd say that's weird. what's your config? any chance you are using an old compiler?

Not really, it's gcc 5.3.1. Maybe Zhihong could explain more. IIRC, he said the memset is not well optimized for Ivybridge server.

The dst is remote in that case. It's fine on Haswell but has complication in Ivy Bridge which (wasn't supposed to but) causes

serious frontend issue.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

I don't think gcc inlined it there. I'm using fc24 gcc 6.1.1.

So try something like this then:

Yes, I saw memset is inlined when this diff is applied.

I have another concern though: It's a trick could let gcc do the inline, I am not quite sure whether that's ture with other compilers (i.e. clang, icc, or even, older gcc).

Quoted 6 lines

For this case, I think I still prefer some trick like

    *(struct ..*) = {0, }

Or even, we may could introduce rte_memset(). IIRC, that has been proposed somehow before?

I'm trying to introduce rte_memset to have a prototype It have Gotten some performance enhancement For small size, I'm optimize it further.

--Zhiyong

Quoted 1 line
	--yliu
#36 lore raw

Re: [Qemu-devel] [PATCH 1/2] vhost: enable any layout feature

In reply to Maxime Coquelin
Quoted 6 lines · Maxime Coquelin
Quoted 2 lines

so doing this unconditionally would be a spec violation, but if you see value in this, we can add a feature bit.

Right it would be a spec violation, so it should be done conditionally. If a feature bit is to be added, what about VIRTIO_NET_F_NO_TX_HEADER? It would imply VIRTIO_NET_F_CSUM not set, and no GSO features set. If negotiated, we wouldn't need to prepend a header.

If we could skip Tx header, I think we could also skip Rx header, in the case when mrg-rx is aslo turned off?

Quoted 7 lines

From the micro-benchmarks results, we can expect +10% compared to indirect descriptors, and + 5% compared to using 2 descs in the virtqueue.
Also, it should have the same benefits as indirect descriptors for 0% pkt loss (as we can fill 2x more packets in the virtqueue).

What do you think?

I would vote for this. It should yield maximum performance for the case that it's guaranteed that packet size will always fit in a typical MTU (1500).

	--yliu
#37 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

In reply to Yuanhan Liu
Quoted 22 lines · Yuanhan Liu
Quoted 21 lines · Michael S. Tsirkin
Quoted 20 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

So I guess at this point, we can teach vhost-user in qemu that version 1 implies any_layout but only for machine types qemu 2.8 and up. It sets a bad precedent but oh well.

Signature · 1 line
MST
#38 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Yuanhan Liu
Quoted 26 lines · Michael S. Tsirkin
Quoted 24 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

So I guess at this point, we can teach vhost-user in qemu that version 1 implies any_layout but only for machine types qemu 2.8 and up. It sets a bad precedent but oh well.

It should work.

	--yliu
#39 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 32 lines · Yuanhan Liu
Quoted 31 lines · Michael S. Tsirkin
Quoted 29 lines · Yuanhan Liu
Quoted 28 lines · Michael S. Tsirkin
Quoted 16 lines · Yuanhan Liu
Quoted 2 lines · Michael S. Tsirkin
Quoted 1 line · Stephen Hemminger

I assume that if using Version 1 that the bit will be ignored

Yes, but I will just quote what you just said: what if the guest virtio device is a legacy device? I also gave my reasons in another email why I consistently set this flag:

- we have to return all features we support to the guest.

We don't know the guest is a modern or legacy device. That means we should claim we support both: VERSION_1 and ANY_LAYOUT.

Assume guest is a legacy device and we just set VERSION_1 (the current case), ANY_LAYOUT will never be negotiated.

Quoted 8 lines

- I'm following the way Linux kernel takes: it also set both features.

Maybe, we could unset ANY_LAYOUT when VERSION_1 is _negotiated_?

The unset after negotiation I proposed turned out it won't work: the feature is already negotiated; unsetting it only in vhost side doesn't change anything. Besides, it may break the migration as Michael stated below.

I think the reverse. Teach vhost user that for future machine types only VERSION_1 implies ANY_LAYOUT.

Quoted 7 lines
Quoted 3 lines

So I guess at this point, we can teach vhost-user in qemu that version 1 implies any_layout but only for machine types qemu 2.8 and up. It sets a bad precedent but oh well.

It should work.

	--yliu

Cool. Want to post a patch?

Signature · 1 line
MST
#40 lore raw

Re: [PATCH 1/2] vhost: enable any layout feature

Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines
Quoted 3 lines

So I guess at this point, we can teach vhost-user in qemu that version 1 implies any_layout but only for machine types qemu 2.8 and up. It sets a bad precedent but oh well.

It should work.

	--yliu

Cool. Want to post a patch?

I could have a try this week (Well, it's very unlikely though). If not, it will be postponed for a while: I am traveling next week.

	--yliu
#41 lore raw

PATCH 2/2 net/virtio: enable any layout feature

In reply to Yuanhan Liu

The feature VIRTIO_F_ANY_LAYOUT was actually supported by commit dd856dfcb9e7 ("virtio: use any layout on Tx"). But it's not enabled. Here this patch enables it.

---
 drivers/net/virtio/virtio_ethdev.h | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_ethdev.h +1 -0
index 04d626b..3e31e6a 100644
@@ -64,6 +64,7 @@
 	 1u << VIRTIO_NET_F_CTRL_VLAN	  |	\
 	 1u << VIRTIO_NET_F_MRG_RXBUF	  |	\
 	 1u << VIRTIO_RING_F_INDIRECT_DESC |    \
+	 1u << VIRTIO_F_ANY_LAYOUT |    \
 	 1ULL << VIRTIO_F_VERSION_1)
 
 /*
Signature · 1 line
1.9.0
#43 lore raw

Re: [PATCH 2/2] net/virtio: enable any layout feature

In reply to Yuanhan Liu
Quoted 5 lines · Yuanhan Liu

The feature VIRTIO_F_ANY_LAYOUT was actually supported by commit dd856dfcb9e7 ("virtio: use any layout on Tx"). But it's not enabled. Here this patch enables it.

Well this will break cross-version migration if just done unconditionally.
Let's add a protocol feature for this bugfix?

Quoted 18 lines
---
 drivers/net/virtio/virtio_ethdev.h | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_ethdev.h +1 -0
index 04d626b..3e31e6a 100644
@@ -64,6 +64,7 @@
 	 1u << VIRTIO_NET_F_CTRL_VLAN	  |	\
 	 1u << VIRTIO_NET_F_MRG_RXBUF	  |	\
 	 1u << VIRTIO_RING_F_INDIRECT_DESC |    \
+	 1u << VIRTIO_F_ANY_LAYOUT |    \
 	 1ULL << VIRTIO_F_VERSION_1)
 
 /*
Signature · 1 line
1.9.0
#44 lore raw

Re: [PATCH 2/2] net/virtio: enable any layout feature

Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Yuanhan Liu

The feature VIRTIO_F_ANY_LAYOUT was actually supported by commit dd856dfcb9e7 ("virtio: use any layout on Tx"). But it's not enabled. Here this patch enables it.

Well this will break cross-version migration if just done unconditionally.
Let's add a protocol feature for this bugfix?

Hmm OTOH the bug is in dpdk not qemu ... this needs some thought.

Quoted 18 lines
Quoted 18 lines
---
 drivers/net/virtio/virtio_ethdev.h | 1 +
 1 file changed, 1 insertion(+)
drivers/net/virtio/virtio_ethdev.h +1 -0
index 04d626b..3e31e6a 100644
@@ -64,6 +64,7 @@
 	 1u << VIRTIO_NET_F_CTRL_VLAN	  |	\
 	 1u << VIRTIO_NET_F_MRG_RXBUF	  |	\
 	 1u << VIRTIO_RING_F_INDIRECT_DESC |    \
+	 1u << VIRTIO_F_ANY_LAYOUT |    \
 	 1ULL << VIRTIO_F_VERSION_1)
 
 /*
Signature · 1 line
1.9.0
#45 lore raw
In reply to Yuanhan Liu
Quoted 2 lines · Yuanhan Liu

The feature is actually supported both in virtio PMD and vhost lib. We just haven't enabled it yet. This patchset simply enables it.

Any input on handling versioning? Do people prefer to handle it completely at the backend, or through libvirt?

Quoted 12 lines

---
Yuanhan Liu (2):
vhost: enable any layout feature
net/virtio: enable any layout feature

 drivers/net/virtio/virtio_ethdev.h | 1 +
 lib/librte_vhost/vhost.c           | 1 +
 lib/librte_vhost/vhost.h           | 3 +++
 3 files changed, 5 insertions(+)
Signature · 1 line
1.9.0