Skip to content

Commit 762faee

Browse files
fengidrimstsirkin
authored andcommitted
virtio_net: set the default max ring size by find_vqs()
Use virtio_find_vqs_ctx_size() to specify the maximum ring size of tx, rx at the same time. | rx/tx ring size ------------------------------------------- speed == UNKNOWN or < 10G| 1024 speed < 40G | 4096 speed >= 40G | 8192 Call virtnet_update_settings() once before calling init_vqs() to update speed. Signed-off-by: Xuan Zhuo <[email protected]> Acked-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent fe3dc04 commit 762faee

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

drivers/net/virtio_net.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,13 +3225,37 @@ static unsigned int mergeable_min_buf_len(struct virtnet_info *vi, struct virtqu
32253225
(unsigned int)GOOD_PACKET_LEN);
32263226
}
32273227

3228+
static void virtnet_config_sizes(struct virtnet_info *vi, u32 *sizes)
3229+
{
3230+
u32 i, rx_size, tx_size;
3231+
3232+
if (vi->speed == SPEED_UNKNOWN || vi->speed < SPEED_10000) {
3233+
rx_size = 1024;
3234+
tx_size = 1024;
3235+
3236+
} else if (vi->speed < SPEED_40000) {
3237+
rx_size = 1024 * 4;
3238+
tx_size = 1024 * 4;
3239+
3240+
} else {
3241+
rx_size = 1024 * 8;
3242+
tx_size = 1024 * 8;
3243+
}
3244+
3245+
for (i = 0; i < vi->max_queue_pairs; i++) {
3246+
sizes[rxq2vq(i)] = rx_size;
3247+
sizes[txq2vq(i)] = tx_size;
3248+
}
3249+
}
3250+
32283251
static int virtnet_find_vqs(struct virtnet_info *vi)
32293252
{
32303253
vq_callback_t **callbacks;
32313254
struct virtqueue **vqs;
32323255
int ret = -ENOMEM;
32333256
int i, total_vqs;
32343257
const char **names;
3258+
u32 *sizes;
32353259
bool *ctx;
32363260

32373261
/* We expect 1 RX virtqueue followed by 1 TX virtqueue, followed by
@@ -3259,10 +3283,15 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
32593283
ctx = NULL;
32603284
}
32613285

3286+
sizes = kmalloc_array(total_vqs, sizeof(*sizes), GFP_KERNEL);
3287+
if (!sizes)
3288+
goto err_sizes;
3289+
32623290
/* Parameters for control virtqueue, if any */
32633291
if (vi->has_cvq) {
32643292
callbacks[total_vqs - 1] = NULL;
32653293
names[total_vqs - 1] = "control";
3294+
sizes[total_vqs - 1] = 64;
32663295
}
32673296

32683297
/* Allocate/initialize parameters for send/receive virtqueues */
@@ -3277,8 +3306,10 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
32773306
ctx[rxq2vq(i)] = true;
32783307
}
32793308

3280-
ret = virtio_find_vqs_ctx(vi->vdev, total_vqs, vqs, callbacks,
3281-
names, ctx, NULL);
3309+
virtnet_config_sizes(vi, sizes);
3310+
3311+
ret = virtio_find_vqs_ctx_size(vi->vdev, total_vqs, vqs, callbacks,
3312+
names, sizes, ctx, NULL);
32823313
if (ret)
32833314
goto err_find;
32843315

@@ -3298,6 +3329,8 @@ static int virtnet_find_vqs(struct virtnet_info *vi)
32983329

32993330

33003331
err_find:
3332+
kfree(sizes);
3333+
err_sizes:
33013334
kfree(ctx);
33023335
err_ctx:
33033336
kfree(names);
@@ -3648,6 +3681,9 @@ static int virtnet_probe(struct virtio_device *vdev)
36483681
vi->curr_queue_pairs = num_online_cpus();
36493682
vi->max_queue_pairs = max_queue_pairs;
36503683

3684+
virtnet_init_settings(dev);
3685+
virtnet_update_settings(vi);
3686+
36513687
/* Allocate/initialize the rx/tx queues, and invoke find_vqs */
36523688
err = init_vqs(vi);
36533689
if (err)
@@ -3660,8 +3696,6 @@ static int virtnet_probe(struct virtio_device *vdev)
36603696
netif_set_real_num_tx_queues(dev, vi->curr_queue_pairs);
36613697
netif_set_real_num_rx_queues(dev, vi->curr_queue_pairs);
36623698

3663-
virtnet_init_settings(dev);
3664-
36653699
if (virtio_has_feature(vdev, VIRTIO_NET_F_STANDBY)) {
36663700
vi->failover = net_failover_create(vi->dev);
36673701
if (IS_ERR(vi->failover)) {

0 commit comments

Comments
 (0)