From patchwork Fri Nov 27 15:02:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrik Hermansson X-Patchwork-Id: 549544 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1E69D1402DD for ; Sat, 28 Nov 2015 03:58:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=S2DLJI29; dkim-atps=neutral Received: from localhost ([::1]:57606 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2MMI-0001P4-7P for incoming@patchwork.ozlabs.org; Fri, 27 Nov 2015 11:58:54 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2KYX-0006s0-QQ for qemu-devel@nongnu.org; Fri, 27 Nov 2015 10:03:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a2KYU-0002gz-Hs for qemu-devel@nongnu.org; Fri, 27 Nov 2015 10:03:25 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:36658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a2KYU-0002gT-A1 for qemu-devel@nongnu.org; Fri, 27 Nov 2015 10:03:22 -0500 Received: by wmww144 with SMTP id w144so58645132wmw.1 for ; Fri, 27 Nov 2015 07:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=8ZIwsuoDbwUGtcbCzyoFLcrg4y1CY4NML86ykZl0tgo=; b=S2DLJI29WbbnVIT0LV9HjbWY22rSXLud9X7dvhQ1UDvPbhgjyirBRANUONHEv1Jd5b P+aa2OsS9ZSRw9mabicUM6a2MPLVvvXA2SyCSuzPOgXFu7bDqwzQF98A/h2ttO3kVXxC wjFPl/0QgY7jALbIJFyEjnptQzdeRLOPlo+CuYKutOpln7DAE/FxcOgjVjWrh0Zyg+Ny CNcIE4Apz7WJWsdi2smGPG5Ot7YXNPWsHEpBTuBiiWZt5jz4tdqhcdHa641nLfng32Yc LTNqPSkys1GcE+I1VD5KgSuQTkv/A1gMuHLC/T1V7TNcX2+V8JuZR1eOhtwv77GQ/XtH +mYw== X-Received: by 10.28.156.83 with SMTP id f80mr11679818wme.41.1448636601364; Fri, 27 Nov 2015 07:03:21 -0800 (PST) Received: from elx72320vmr.ln.sw.ericsson.se (sessfw99-sesbfw99-86.ericsson.net. [192.176.1.86]) by smtp.gmail.com with ESMTPSA id o65sm7915692wmg.3.2015.11.27.07.03.20 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Nov 2015 07:03:20 -0800 (PST) From: Patrik Hermansson To: qemu-devel@nongnu.org Date: Fri, 27 Nov 2015 16:02:39 +0100 Message-Id: <1448636559-2140-1-git-send-email-phermansson@gmail.com> X-Mailer: git-send-email 1.9.1 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c09::236 X-Mailman-Approved-At: Fri, 27 Nov 2015 11:57:12 -0500 Cc: Patrik Hermansson , mst@redhat.com Subject: [Qemu-devel] [PATCH] virtio-net: Make virtio queue sizes configurable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds the option to specify virtio queue sizes. Currently the queue sizes is hard coded to 256, which might not be suitable for all types of applications. This patch makes it possible to specify the queue size between 256 to 1024. The minimum value is chosen based on the current sizes of the virtio queues. The maximum queue size is based upon VIRTQUEUE_SIZE_MAX. --- hw/net/virtio-net.c | 31 ++++++++++++++++++++++++++++--- include/hw/virtio/virtio-net.h | 8 +++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a877614..c4fcb39 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -1326,20 +1326,40 @@ static void virtio_net_tx_bh(void *opaque) } } +static void virtio_net_validate_queue_limit(uint16_t *queue_size) +{ + if (*queue_size > VIRTIO_QUEUE_SIZE_MAX) { + error_report("queue-size: %d, exceeds maximum allowed queue-size(%d)," + "queue-size set to %d", *queue_size, VIRTIO_QUEUE_SIZE_MAX, + VIRTIO_QUEUE_SIZE_MAX); + *queue_size = VIRTIO_QUEUE_SIZE_MAX; + } else if (*queue_size < VIRTIO_QUEUE_SIZE_MIN) { + error_report("queue-size: %d, below minimum allowed queue-size(%d)," + "queue-size set to %d", *queue_size, VIRTIO_QUEUE_SIZE_MIN, + VIRTIO_QUEUE_SIZE_MIN); + *queue_size = VIRTIO_QUEUE_SIZE_MIN; + } +} + 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); + virtio_net_validate_queue_limit(&n->net_conf.rx_virtqueue_sz); + virtio_net_validate_queue_limit(&n->net_conf.tx_virtqueue_sz); + n->vqs[index].rx_vq = virtio_add_queue(vdev, n->net_conf.rx_virtqueue_sz, + 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); + virtio_add_queue(vdev, n->net_conf.tx_virtqueue_sz, + virtio_net_handle_tx_timer); n->vqs[index].tx_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, virtio_net_tx_timer, &n->vqs[index]); } else { n->vqs[index].tx_vq = - virtio_add_queue(vdev, 256, virtio_net_handle_tx_bh); + virtio_add_queue(vdev, n->net_conf.tx_virtqueue_sz, + virtio_net_handle_tx_bh); n->vqs[index].tx_bh = qemu_bh_new(virtio_net_tx_bh, &n->vqs[index]); } @@ -1826,6 +1846,11 @@ static Property virtio_net_properties[] = { DEFINE_PROP_UINT32("x-txtimer", VirtIONet, net_conf.txtimer, TX_TIMER_INTERVAL), DEFINE_PROP_INT32("x-txburst", VirtIONet, net_conf.txburst, TX_BURST), + DEFINE_PROP_UINT16("rx_virtqueue_sz", VirtIONet, net_conf.rx_virtqueue_sz, + RX_VIRTQUEUE_SIZE), + DEFINE_PROP_UINT16("tx_virtqueue_sz", VirtIONet, net_conf.tx_virtqueue_sz, + TX_VIRTQUEUE_SIZE), + DEFINE_PROP_STRING("tx", VirtIONet, net_conf.tx), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index f3cc25f..dbcabbf 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -28,13 +28,19 @@ * ensures fairness in the io path. 256 conveniently matches the * length of the TX queue and shows a good balance of performance * and latency. */ -#define TX_BURST 256 +#define VIRTIO_QUEUE_SIZE_MIN 256 +#define VIRTIO_QUEUE_SIZE_MAX VIRTQUEUE_MAX_SIZE +#define RX_VIRTQUEUE_SIZE VIRTIO_QUEUE_SIZE_MIN +#define TX_VIRTQUEUE_SIZE VIRTIO_QUEUE_SIZE_MIN +#define TX_BURST TX_VIRTQUEUE_SIZE typedef struct virtio_net_conf { uint32_t txtimer; int32_t txburst; char *tx; + uint16_t rx_virtqueue_sz; + uint16_t tx_virtqueue_sz; } virtio_net_conf; /* Maximum packet size we can receive from tap device: header + 64k */