virtio-net: allow increasing rx queue size
PATCH 1/1 virtio-net: allow increasing rx queue size
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)
include/hw/virtio/virtio-net.h +1 -0
@@ -35,6 +35,7 @@ typedef struct virtio_net_confuint32_t txtimer;int32_t txburst;char *tx; +uint16_t rx_queue_size; } virtio_net_conf;/* Maximum packet size we can receive from tap device: header + 64k */
hw/net/virtio-net.c +21 -1
@@ -1412,7 +1412,8 @@ static void virtio_net_add_queue(VirtIONet *n, int index) {VirtIODevice *vdev =VIRTIO_DEVICE (n); - n->vqs[index].rx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_rx); + n->vqs[index].rx_vq =virtio_add_queue (vdev, n->net_conf.rx_queue_size, + virtio_net_handle_rx);if (n->net_conf.tx && !strcmp (n->net_conf.tx,"timer" )) { n->vqs[index].tx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_tx_timer);
@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ; +if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), +DEFINE_PROP_UINT16 ("rx_queue_size" , VirtIONet, net_conf.rx_queue_size,256 ), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
MST
Quoted 11 lines · Michael S. Tsirkin
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
Quoted 8 lines
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Signed-off-by Michael S. Tsirkin <[email protected]>
Forgot to say: this was originally suggested by Patrik Hermansson <[email protected]>
Quoted 70 lines
--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)include/hw/virtio/virtio-net.h +1
-0@@ -35,6 +35,7 @@ typedef struct virtio_net_confuint32_t txtimer;int32_t txburst;char *tx; +uint16_t rx_queue_size; } virtio_net_conf;/* Maximum packet size we can receive from tap device: header + 64k */ hw/net/virtio-net.c +21
-1@@ -1412,7 +1412,8 @@ static void virtio_net_add_queue(VirtIONet *n, int index) {VirtIODevice *vdev =VIRTIO_DEVICE (n); - n->vqs[index].rx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_rx); + n->vqs[index].rx_vq =virtio_add_queue (vdev, n->net_conf.rx_queue_size, + virtio_net_handle_rx);if (n->net_conf.tx && !strcmp (n->net_conf.tx,"timer" )) { n->vqs[index].tx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_tx_timer);@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ; +if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), +DEFINE_PROP_UINT16 ("rx_queue_size" , VirtIONet, net_conf.rx_queue_size,256 ), DEFINE_PROP_END_OF_LIST(), };Signature · 1 line
MST
Quoted 80 lines · Michael S. Tsirkin
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)include/hw/virtio/virtio-net.h +1
-0@@ -35,6 +35,7 @@ typedef struct virtio_net_confuint32_t txtimer;int32_t txburst;char *tx; +uint16_t rx_queue_size; } virtio_net_conf;/* Maximum packet size we can receive from tap device: header + 64k */ hw/net/virtio-net.c +20
-1@@ -1412,7 +1412,8 @@ static void virtio_net_add_queue(VirtIONet *n, int index) {VirtIODevice *vdev =VIRTIO_DEVICE (n); - n->vqs[index].rx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_rx); + n->vqs[index].rx_vq =virtio_add_queue (vdev, n->net_conf.rx_queue_size, + virtio_net_handle_rx);if (n->net_conf.tx && !strcmp (n->net_conf.tx,"timer" )) { n->vqs[index].tx_vq =virtio_add_queue (vdev,256 , virtio_net_handle_tx_timer);@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ; +if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1905
Quoted 7 lines
hw/net/virtio-net.c +1
-0@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), +DEFINE_PROP_UINT16 ("rx_queue_size" , VirtIONet, net_conf.rx_queue_size,256 ), DEFINE_PROP_END_OF_LIST(), };
Quoted 11 lines · On Thu, 4 Aug 2016 02:16:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
Quoted 6 lines
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Do we need some kind of sanity check that the guest did not resize below a reasonable limit?
Quoted 14 lines
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 1730
Quoted 10 lines
hw/net/virtio-net.c +6
-0virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ;
I'd find it more readable to introduce a #define with the old queue size as the minimum size...
Quoted 15 lines
hw/net/virtio-net.c +11
-0+if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1902
Quoted 4 lines
hw/net/virtio-net.c +1
-0@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 256),
...and defaulting to that #define (or one derived from the #define above) here.
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1905
Quoted 3 lines
hw/net/virtio-net.c +0
-0DEFINE_PROP_END_OF_LIST(), };
Do we need compat handling for the new property?
Quoted 21 lines · Cornelia Huck
Quoted 11 lines · On Thu, 4 Aug 2016 02:16:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
Quoted 6 lines
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Quoted 2 lines
Do we need some kind of sanity check that the guest did not resize below a reasonable limit?
Unfortunately the spec does not have an interface for that. Guests expect they can get away with any size.
Quoted 42 lines
Quoted 14 lines
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 1730
Quoted 10 lines
hw/net/virtio-net.c +6
-0virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ;I'd find it more readable to introduce a #define with the old queue size as the minimum size...
Quoted 14 lines
hw/net/virtio-net.c +11
-0+if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "
Quoted 8 lines
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1902
Quoted 5 lines
hw/net/virtio-net.c +1
-0@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 256),...and defaulting to that #define (or one derived from the #define above) here.
These happen to be the same, but they are in fact
unrelated: one is the default, the other is the
min value.
Quoted 5 lines
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1905
Quoted 3 lines
hw/net/virtio-net.c +0
-0DEFINE_PROP_END_OF_LIST(), };Do we need compat handling for the new property?
No since we did not change the default :)
Quoted 22 lines · On Thu, 4 Aug 2016 22:52:29 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 21 lines · Cornelia Huck
Quoted 17 lines · On Thu, 4 Aug 2016 02:16:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Quoted 5 lines
Quoted 2 lines
Do we need some kind of sanity check that the guest did not resize below a reasonable limit?
Unfortunately the spec does not have an interface for that. Guests expect they can get away with any size.
Might be a good idea to add this in the future, so that the guest is able to discover the minimum and the host can refuse to work if the configured queue is too small.
(I can easily reject the setup ccw on virtio-ccw, but is there an elegant way to refuse setting up the queues with virtio-pci?)
Quoted 52 lines
Quoted 43 lines
Quoted 15 lines
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 1730
Quoted 10 lines
hw/net/virtio-net.c +6
-0virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ;I'd find it more readable to introduce a #define with the old queue size as the minimum size...
Quoted 14 lines
hw/net/virtio-net.c +11
-0+if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) { error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "Quoted 8 lines
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1902
Quoted 5 lines
hw/net/virtio-net.c +1
-0@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 256),...and defaulting to that #define (or one derived from the #define above) here.
Quoted 3 lines
These happen to be the same, but they are in fact
unrelated: one is the default, the other is the
min value.
Hm...
/* previously fixed value */
#define VIRTIO_NET_RX_DEFAULT_SIZE 256
/* for now, only allow larger queues; with virtio-1, guest can downsize */ #define VIRTIO_NET_RX_MIN_SIZE VIRTIO_NET_RX_DEFAULT_SIZE
This would allow getting rid of the new local variable and gets us a speaking define in the property definition.
Quoted 86 lines · Cornelia Huck
Quoted 21 lines · On Thu, 4 Aug 2016 22:52:29 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 20 lines · Cornelia Huck
Quoted 17 lines · On Thu, 4 Aug 2016 02:16:14 +0300 "Michael S. Tsirkin" <[email protected]> wrote:
This allows increasing the rx queue size up to 1024: unlike with tx, guests don't put in huge S/G lists into RX so the risk of running into the max 1024 limitation due to some off-by-one seems small.
It's helpful for users like OVS-DPDK which don't do any buffering on the host - 1K roughly matches 500 entries in tun + 256 in the current rx queue, which seems to work reasonably well. We could probably make do with ~750 entries but virtio spec limits us to powers of two. It might be a good idea to specify an s/g size limit in a future version.
It also might be possible to make the queue size smaller down the road, 64 seems like the minimal value which will still work (as guests seem to assume a queue full of 1.5K buffers is enough to process the largest incoming packet, which is ~64K). No one actually asked for this, and with virtio 1 guests can reduce ring size without need for host configuration, so don't bother with this for now.
Quoted 4 lines
Quoted 2 lines
Do we need some kind of sanity check that the guest did not resize below a reasonable limit?
Unfortunately the spec does not have an interface for that. Guests expect they can get away with any size.
Might be a good idea to add this in the future, so that the guest is able to discover the minimum and the host can refuse to work if the configured queue is too small.
(I can easily reject the setup ccw on virtio-ccw, but is there an elegant way to refuse setting up the queues with virtio-pci?)
Quoted 46 lines
Quoted 38 lines
Quoted 12 lines
Signed-off-by Michael S. Tsirkin <[email protected]>--- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -1716,10 +1717,28 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)VirtIONet *n =VIRTIO_NET (dev);NetClientState *nc;int i; +int min_rx_queue_size;hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 1730
Quoted 10 lines
hw/net/virtio-net.c +6
-0virtio_net_set_config_size (n, n->host_features);virtio_init (vdev,"virtio-net" ,VIRTIO_ID_NET , n->config_size); +/* +* We set a lower limit on RX queue size to what it always was. +* Guests that want a smaller ring can always resize it without +* help from us (using virtio 1 and up). +*/ + min_rx_queue_size =256 ;I'd find it more readable to introduce a #define with the old queue size as the minimum size...
Quoted 13 lines
hw/net/virtio-net.c +11
-0+if (n->net_conf.rx_queue_size < min_rx_queue_size || + n->net_conf.rx_queue_size >VIRTQUEUE_MAX_SIZE || + (n->net_conf.rx_queue_size & (n->net_conf.rx_queue_size -1 ))) { +error_setg (errp,"Invalid rx_queue_size (= %" PRIu16"), " +"must be a power of 2 between %d and %d." , + n->net_conf.rx_queue_size, min_rx_queue_size, +VIRTQUEUE_MAX_SIZE ); +virtio_cleanup (vdev); +return ; + } + n->max_queues =MAX (n->nic_conf.peers.queues,1 );if (n->max_queues *2 +1 >VIRTIO_QUEUE_MAX ) {Quoted 8 lines
hw/net/virtio-net.c static Property virtio_net_properties[] = { · line 1902
Quoted 6 lines
hw/net/virtio-net.c +1
-0error_setg(errp, "Invalid number of queues (= %" PRIu32 "), "@@ -1880,6 +1899,7 @@ static Property virtio_net_properties[] = { TX_TIMER_INTERVAL),DEFINE_PROP_INT32 ("x-txburst" , VirtIONet, net_conf.txburst,TX_BURST ),DEFINE_PROP_STRING ("tx" , VirtIONet, net_conf.tx), + DEFINE_PROP_UINT16("rx_queue_size", VirtIONet, net_conf.rx_queue_size, 256),...and defaulting to that #define (or one derived from the #define above) here.
Quoted 3 lines
These happen to be the same, but they are in fact
unrelated: one is the default, the other is the
min value.Hm...
Quoted 9 lines
/* previously fixed value */
#defineVIRTIO_NET_RX_DEFAULT_SIZE256
/* for now, only allow larger queues; with virtio-1, guest can downsize */ #defineVIRTIO_NET_RX_MIN_SIZEVIRTIO_NET_RX_DEFAULT_SIZEThis would allow getting rid of the new local variable and gets us a speaking define in the property definition.
This makes sense. What's your opinion Michael?
Thanks