basic in order support for vhost_net
Subsystems (5)
cover basic in order support for vhost_net
Hi:
This series implement basic in order feature support for vhost_net. This feature requires both driver and device to use descriptors in order which can simplify the implementation and optimizaton for both side. The series also implement a simple optimization that avoid read available ring. Test shows 10% performance improvement.
More optimizations could be done on top.
Jason Wang (3):
virtio: introduce in order feature bit
vhost_net: support in order feature
vhost: don't touch avail ring if in_order is negotiated
drivers/vhost/net.c | 6 ++++-- drivers/vhost/vhost.c | 19 ++++++++++++------- include/uapi/linux/virtio_config.h | 6 ++++++ 3 files changed, 22 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 virtio: introduce in order feature bit
--- include/uapi/linux/virtio_config.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/linux/virtio_config.h +6 -0
@@ -75,6 +75,12 @@*/ #define VIRTIO_F_IOMMU_PLATFORM 33 +/* +* Device uses buffers in the same order in which they have been +* available. +*/ +#define VIRTIO_F_IN_ORDER 35 +/* * Does the device support Single Root I/O Virtualization? */
Signature · 1 line
2.17.1
PATCH 1/3 virtio: introduce in order feature bit
In reply to Jason Wang--- include/uapi/linux/virtio_config.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/uapi/linux/virtio_config.h +6 -0
@@ -75,6 +75,12 @@*/ #define VIRTIO_F_IOMMU_PLATFORM 33 +/* +* Device uses buffers in the same order in which they have been +* available. +*/ +#define VIRTIO_F_IN_ORDER 35 +/* * Does the device support Single Root I/O Virtualization? */
Signature · 1 line
2.17.1
PATCH 2/3 vhost_net: support in order feature
In reply to Jason WangThis makes vhost_net to support in order feature. This is as simple as use datacopy path when it was negotiated. An alternative is not to advertise in order when zerocopy is enabled which tends to be suboptimal consider zerocopy may suffer from e.g HOL issues.
--- drivers/vhost/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/net.c +4 -2
@@ -74,7 +74,8 @@ enum {VHOST_NET_FEATURES =VHOST_FEATURES | (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ) | (1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | - (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) + (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) | + (1ULL <<VIRTIO_F_IN_ORDER ) };enum {
@@ -971,7 +972,8 @@ static void handle_tx(struct vhost_net *net)vhost_disable_notify (&net->dev, vq);vhost_net_disable_vq (net, vq); -if (vhost_sock_zcopy (sock)) +if (vhost_sock_zcopy (sock) && + !vhost_has_feature (vq,VIRTIO_F_IN_ORDER ))handle_tx_zerocopy (net, sock);else handle_tx_copy (net, sock);
Signature · 1 line
2.17.1
Michael S. Tsirkin
maintainerRe: [PATCH net-next 2/3] vhost_net: support in order feature
Quoted 4 lines · Jason Wang
This makes
vhost_netto support in order feature. This is as simple as use datacopy path when it was negotiated. An alternative is not to advertise in order when zerocopy is enabled which tends to be suboptimal consider zerocopy may suffer from e.g HOL issues.
Well IIRC vhost_zerocopy_signal_used is used to actually reorder used ring to match available ring. So with a big comment explaining why it is so, we could just enable IN_ORDER there too.
Quoted 32 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +4
-2@@ -74,7 +74,8 @@ enum {VHOST_NET_FEATURES =VHOST_FEATURES | (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ) | (1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | - (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) + (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) | + (1ULL <<VIRTIO_F_IN_ORDER ) };enum {@@ -971,7 +972,8 @@ static void handle_tx(struct vhost_net *net)vhost_disable_notify (&net->dev, vq);vhost_net_disable_vq (net, vq); -if (vhost_sock_zcopy (sock)) +if (vhost_sock_zcopy (sock) && + !vhost_has_feature (vq,VIRTIO_F_IN_ORDER ))handle_tx_zerocopy (net, sock);else handle_tx_copy (net, sock);Signature · 1 line
2.17.1
Re: [PATCH net-next 2/3] vhost_net: support in order feature
Quoted 10 lines · Michael S. Tsirkin
Quoted 4 lines · Jason Wang
This makes
vhost_netto support in order feature. This is as simple as use datacopy path when it was negotiated. An alternative is not to advertise in order when zerocopy is enabled which tends to be suboptimal consider zerocopy may suffer from e.g HOL issues.Well IIRC
vhost_zerocopy_signal_usedis used to actually reorder used ring to match available ring. So with a big comment explaining why it is so, we could just enableIN_ORDERthere too.
The problem is we allow switching between zerocopy and datacopy.
And what's more important, if we allow in order for zerocopy, a single packet delay may hang all the rest.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH net-next 2/3] vhost_net: support in order feature
In reply to Jason WangQuoted 4 lines · Jason Wang
This makes
vhost_netto support in order feature. This is as simple as use datacopy path when it was negotiated. An alternative is not to advertise in order when zerocopy is enabled which tends to be suboptimal consider zerocopy may suffer from e.g HOL issues.
Well IIRC vhost_zerocopy_signal_used is used to actually reorder used ring to match available ring. So with a big comment explaining why it is so, we could just enable IN_ORDER there too.
Quoted 32 lines
Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/vhost/net.c +4
-2@@ -74,7 +74,8 @@ enum {VHOST_NET_FEATURES =VHOST_FEATURES | (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ) | (1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | - (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) + (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) | + (1ULL <<VIRTIO_F_IN_ORDER ) };enum {@@ -971,7 +972,8 @@ static void handle_tx(struct vhost_net *net)vhost_disable_notify (&net->dev, vq);vhost_net_disable_vq (net, vq); -if (vhost_sock_zcopy (sock)) +if (vhost_sock_zcopy (sock) && + !vhost_has_feature (vq,VIRTIO_F_IN_ORDER ))handle_tx_zerocopy (net, sock);else handle_tx_copy (net, sock);Signature · 1 line
2.17.1
PATCH 2/3 vhost_net: support in order feature
In reply to Jason WangThis makes vhost_net to support in order feature. This is as simple as use datacopy path when it was negotiated. An alternative is not to advertise in order when zerocopy is enabled which tends to be suboptimal consider zerocopy may suffer from e.g HOL issues.
--- drivers/vhost/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/net.c +4 -2
@@ -74,7 +74,8 @@ enum {VHOST_NET_FEATURES =VHOST_FEATURES | (1ULL <<VHOST_NET_F_VIRTIO_NET_HDR ) | (1ULL <<VIRTIO_NET_F_MRG_RXBUF ) | - (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) + (1ULL <<VIRTIO_F_IOMMU_PLATFORM ) | + (1ULL <<VIRTIO_F_IN_ORDER ) };enum {
@@ -971,7 +972,8 @@ static void handle_tx(struct vhost_net *net)vhost_disable_notify (&net->dev, vq);vhost_net_disable_vq (net, vq); -if (vhost_sock_zcopy (sock)) +if (vhost_sock_zcopy (sock) && + !vhost_has_feature (vq,VIRTIO_F_IN_ORDER ))handle_tx_zerocopy (net, sock);else handle_tx_copy (net, sock);
Signature · 1 line
2.17.1
PATCH 3/3 vhost: don't touch avail ring if in_order is negotiated
In reply to Jason WangDevice use descriptors table in order, so there's no need to read index from available ring. This eliminate the cache contention on avail ring completely.
Virito-user + vhost_kernel + XDP_DROP gives about ~10% improvement on TX from 4.8Mpps to 5.3Mpps on Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz.
--- drivers/vhost/vhost.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/vhost/vhost.c +12 -7
@@ -2002,6 +2002,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,__virtio16 avail_idx;__virtio16 ring_head;int ret, access; +bool in_order =vhost_has_feature (vq,VIRTIO_F_IN_ORDER );/* Check it isn't doing very strange things with descriptor numbers. */ last_avail_idx = vq->last_avail_idx;
@@ -2034,15 +2035,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ -if (unlikely (vhost_get_avail (vq, ring_head, - &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { -vq_err (vq,"Failed to read head: idx %d address %p\n" , - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); -return -EFAULT ; +if (!in_order) { +if (unlikely (vhost_get_avail (vq, ring_head, + &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return -EFAULT ; + } + head =vhost16_to_cpu (vq, ring_head); + }else { + head = last_avail_idx & (vq->num -1 ); } - head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */ if (unlikely (head >= vq->num)) {
Signature · 1 line
2.17.1
Michael S. Tsirkin
maintainerRe: [PATCH net-next 3/3] vhost: don't touch avail ring if in_order is negotiated
Quoted 3 lines · Jason Wang
Device use descriptors table in order, so there's no need to read index from available ring. This eliminate the cache contention on avail ring completely.
Well this isn't what the in order feature says in the spec.
It forces the used ring to be in the same order as the available ring. So I don't think you can skip checking the available ring. And in fact depending on ring size and workload, using all of descriptor buffer might cause a slowdown.
Rather you should be able to get
about the same speedup, but from skipping checking the used ring in virtio.
Quoted 50 lines
Virito-user +
vhost_kernel+XDP_DROPgives about ~10% improvement on TX from 4.8Mpps to 5.3Mpps on Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vhost.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/vhost/vhost.c +12
-7@@ -2002,6 +2002,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,__virtio16 avail_idx;__virtio16 ring_head;int ret, access; +bool in_order =vhost_has_feature (vq,VIRTIO_F_IN_ORDER );/* Check it isn't doing very strange things with descriptor numbers. */ last_avail_idx = vq->last_avail_idx;@@ -2034,15 +2035,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ -if (unlikely (vhost_get_avail (vq, ring_head, - &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { -vq_err (vq,"Failed to read head: idx %d address %p\n" , - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); -return -EFAULT ; +if (!in_order) { +if (unlikely (vhost_get_avail (vq, ring_head, + &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return -EFAULT ; + } + head =vhost16_to_cpu (vq, ring_head); + }else { + head = last_avail_idx & (vq->num -1 ); } - head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */ if (unlikely (head >= vq->num)) {Signature · 1 line
2.17.1
Re: [PATCH net-next 3/3] vhost: don't touch avail ring if in_order is negotiated
Quoted 9 lines · Michael S. Tsirkin
Quoted 3 lines · Jason Wang
Device use descriptors table in order, so there's no need to read index from available ring. This eliminate the cache contention on avail ring completely.
Well this isn't what the in order feature says in the spec.
It forces the used ring to be in the same order as the available ring. So I don't think you can skip checking the available ring.
Maybe I miss something. The spec (https://github.com/oasis-tcs/virtio-spec master) said: "If VIRTIO_F_IN_ORDER has been negotiated, driver uses descriptors in ring order: starting from offset 0 in the table, and wrapping around at the end of the table."
Even if I was wrong, maybe it's time to force this consider the obvious improvement it brings? And maybe what you said is the reason that we only allow the following optimization only for packed ring?
"notify the use of a batch of buffers to the driver by only writing out a single used descriptor with the Buffer ID corresponding to the last descriptor in the batch. "
This seems another good optimization for packed ring as well.
Quoted 3 lines
And in fact depending on
ring size and workload, using all of descriptor buffer might cause a slowdown.
This is not the sin of in order but the size of the queue I believe?
Quoted 3 lines
Rather you should be able to get
about the same speedup, but from skipping checking the used ring in virtio.
Yes, I've made such changes in virtio-net pmd. But since we're testing it with vhost-kernel, the main contention was on available. So the improvement was not obvious.
Thanks
Quoted 46 lines
Quoted 46 lines
Virito-user +
vhost_kernel+XDP_DROPgives about ~10% improvement on TX from 4.8Mpps to 5.3Mpps on Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vhost.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/vhost/vhost.c +12
-6@@ -2002,6 +2002,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,__virtio16 avail_idx;__virtio16 ring_head;int ret, access; +bool in_order =vhost_has_feature (vq,VIRTIO_F_IN_ORDER );/* Check it isn't doing very strange things with descriptor numbers. */ last_avail_idx = vq->last_avail_idx;@@ -2034,15 +2035,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ -if (unlikely (vhost_get_avail (vq, ring_head, - &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { -vq_err (vq,"Failed to read head: idx %d address %p\n" , - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); -return -EFAULT ; +if (!in_order) { +if (unlikely (vhost_get_avail (vq, ring_head, + &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return -EFAULT ; + } + head =vhost16_to_cpu (vq, ring_head); + }else { + head = last_avail_idx & (vq->num -1 ); }
Quoted 6 lines
Quoted 6 lines
drivers/vhost/vhost.c +0
-1- head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */ if (unlikely (head >= vq->num)) {Signature · 1 line
2.17.1
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Michael S. Tsirkin
maintainerRe: [PATCH net-next 3/3] vhost: don't touch avail ring if in_order is negotiated
In reply to Jason WangQuoted 3 lines · Jason Wang
Device use descriptors table in order, so there's no need to read index from available ring. This eliminate the cache contention on avail ring completely.
Well this isn't what the in order feature says in the spec.
It forces the used ring to be in the same order as the available ring. So I don't think you can skip checking the available ring. And in fact depending on ring size and workload, using all of descriptor buffer might cause a slowdown.
Rather you should be able to get
about the same speedup, but from skipping checking the used ring in virtio.
Quoted 50 lines
Virito-user +
vhost_kernel+XDP_DROPgives about ~10% improvement on TX from 4.8Mpps to 5.3Mpps on Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz.Signed-off-by Jason Wang <[email protected]>--- drivers/vhost/vhost.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/vhost/vhost.c +12
-7@@ -2002,6 +2002,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,__virtio16 avail_idx;__virtio16 ring_head;int ret, access; +bool in_order =vhost_has_feature (vq,VIRTIO_F_IN_ORDER );/* Check it isn't doing very strange things with descriptor numbers. */ last_avail_idx = vq->last_avail_idx;@@ -2034,15 +2035,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ -if (unlikely (vhost_get_avail (vq, ring_head, - &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { -vq_err (vq,"Failed to read head: idx %d address %p\n" , - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); -return -EFAULT ; +if (!in_order) { +if (unlikely (vhost_get_avail (vq, ring_head, + &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return -EFAULT ; + } + head =vhost16_to_cpu (vq, ring_head); + }else { + head = last_avail_idx & (vq->num -1 ); } - head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */ if (unlikely (head >= vq->num)) {Signature · 1 line
2.17.1
PATCH 3/3 vhost: don't touch avail ring if in_order is negotiated
In reply to Jason WangDevice use descriptors table in order, so there's no need to read index from available ring. This eliminate the cache contention on avail ring completely.
Virito-user + vhost_kernel + XDP_DROP gives about ~10% improvement on TX from 4.8Mpps to 5.3Mpps on Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz.
--- drivers/vhost/vhost.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/vhost/vhost.c +12 -7
@@ -2002,6 +2002,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,__virtio16 avail_idx;__virtio16 ring_head;int ret, access; +bool in_order =vhost_has_feature (vq,VIRTIO_F_IN_ORDER );/* Check it isn't doing very strange things with descriptor numbers. */ last_avail_idx = vq->last_avail_idx;
@@ -2034,15 +2035,19 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,/* Grab the next descriptor number they're advertising, and increment * the index we've seen. */ -if (unlikely (vhost_get_avail (vq, ring_head, - &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { -vq_err (vq,"Failed to read head: idx %d address %p\n" , - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); -return -EFAULT ; +if (!in_order) { +if (unlikely (vhost_get_avail (vq, ring_head, + &vq->avail->ring[last_avail_idx & (vq->num -1 )]))) { +vq_err (vq,"Failed to read head: idx %d address %p\n" , + last_avail_idx, + &vq->avail->ring[last_avail_idx % vq->num]); +return -EFAULT ; + } + head =vhost16_to_cpu (vq, ring_head); + }else { + head = last_avail_idx & (vq->num -1 ); } - head =vhost16_to_cpu (vq, ring_head);/* If their number is silly, that's an error. */ if (unlikely (head >= vq->num)) {
Signature · 1 line
2.17.1