From patchwork Sat Dec 6 16:52:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 418408 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 E34DD1400D5 for ; Sun, 7 Dec 2014 03:53:40 +1100 (AEDT) Received: from localhost ([::1]:54899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxIbv-00024p-Ek for incoming@patchwork.ozlabs.org; Sat, 06 Dec 2014 11:53:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxIbU-0001Zc-2w for qemu-devel@nongnu.org; Sat, 06 Dec 2014 11:53:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XxIbN-0007cA-Vg for qemu-devel@nongnu.org; Sat, 06 Dec 2014 11:53:08 -0500 Received: from mail-wi0-f179.google.com ([209.85.212.179]:60986) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XxIbN-0007br-MQ for qemu-devel@nongnu.org; Sat, 06 Dec 2014 11:53:01 -0500 Received: by mail-wi0-f179.google.com with SMTP id ex7so1368115wid.6 for ; Sat, 06 Dec 2014 08:52:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:from:to:cc:date:message-id:user-agent :mime-version:content-type:content-transfer-encoding; bh=K7hlm2ebbKMfD6XLhaEx+uvJtG+/PDRCIpaGTtWNRlQ=; b=fKtsSJp06aIHPEJQMFhwnTrHCgHotFnLpwaYTWDk4ZeGjOUnUBpeA+LQglyqpI/vyM L7K6tgGSmK0sEHheQ3o073KASBSN/rr+8F1RGh+HdaxrVLyPZZjdXPv8Qn6g+VzAVWWu GfOl69ZqQCf72nl6O8Oqh62lVQ1hl4SDeLBGlT9oirbzoiS4PuHXxfxMIMrd5tQE6Hz9 9yZHgAWA77z3Ek2trYDHJRCKczKPMIsfRsA82Cst9cQFoN7+RlE2HJq8aAE8OKqu2F7K e9ek4N1otapDNy183NkWJrFDjPacsKEWGkADfgnoCZhRY47wzgJLHyMnMOqOyThKx64j Xu+Q== X-Gm-Message-State: ALoCoQnI3Efs2reGtOLMvoker7OpZboKxyYaPvgIfMK+XgZngBem/VyOR7aUImMRcZJ7VSJtQFzd X-Received: by 10.180.82.227 with SMTP id l3mr12579436wiy.0.1417884779735; Sat, 06 Dec 2014 08:52:59 -0800 (PST) Received: from [127.0.1.1] ([82.146.27.14]) by mx.google.com with ESMTPSA id ej10sm2521107wib.1.2014.12.06.08.52.57 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Dec 2014 08:52:58 -0800 (PST) From: Nikolay Nikolaev To: thomas.long@intel.com, snabb-devel@googlegroups.com, eblake@redhat.com, qemu-devel@nongnu.org, mst@redhat.com Date: Sat, 06 Dec 2014 18:52:56 +0200 Message-ID: <20141206165241.4064.61867.stgit@i3820> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.179 Cc: tech@virtualopensystems.com, n.nikolaev@virtualopensystems.com Subject: [Qemu-devel] [PATCH] vhost-user: multiqueue support 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 Vhost-user will implement the multiqueueu support in a similar way to what vhost already has - a separate thread for each queue. To enable multiquue funcionality - a new command line parameter "queues" is introduced for the vhost-user netdev. Signed-off-by: Nikolay Nikolaev --- docs/specs/vhost-user.txt | 7 +++++++ hw/virtio/vhost-user.c | 6 +++++- net/vhost-user.c | 35 +++++++++++++++++++++++------------ qapi-schema.json | 5 ++++- qemu-options.hx | 5 +++-- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/docs/specs/vhost-user.txt b/docs/specs/vhost-user.txt index 650bb18..d3857f5 100644 --- a/docs/specs/vhost-user.txt +++ b/docs/specs/vhost-user.txt @@ -127,6 +127,13 @@ in the ancillary data: If Master is unable to send the full message or receives a wrong reply it will close the connection. An optional reconnection mechanism can be implemented. +Multi queue suport +--------------------- +The protocol supports multiple queues by setting all index fields in the sent +messages to a value calculated by the following formula: + + +The is increased by 2. + Message types ------------- diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index aefe0bb..83ebcaa 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -253,17 +253,20 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, case VHOST_SET_VRING_NUM: case VHOST_SET_VRING_BASE: memcpy(&msg.state, arg, sizeof(struct vhost_vring_state)); + msg.state.index += dev->vq_index; msg.size = sizeof(m.state); break; case VHOST_GET_VRING_BASE: memcpy(&msg.state, arg, sizeof(struct vhost_vring_state)); + msg.state.index += dev->vq_index; msg.size = sizeof(m.state); need_reply = 1; break; case VHOST_SET_VRING_ADDR: memcpy(&msg.addr, arg, sizeof(struct vhost_vring_addr)); + msg.addr.index += dev->vq_index; msg.size = sizeof(m.addr); break; @@ -271,7 +274,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, case VHOST_SET_VRING_CALL: case VHOST_SET_VRING_ERR: file = arg; - msg.u64 = file->index & VHOST_USER_VRING_IDX_MASK; + msg.u64 = (file->index + dev->vq_index) & VHOST_USER_VRING_IDX_MASK; msg.size = sizeof(m.u64); if (ioeventfd_enabled() && file->fd > 0) { fds[fd_num++] = file->fd; @@ -313,6 +316,7 @@ static int vhost_user_call(struct vhost_dev *dev, unsigned long int request, error_report("Received bad msg size.\n"); return -1; } + msg.state.index -= dev->vq_index; memcpy(arg, &msg.state, sizeof(struct vhost_vring_state)); break; default: diff --git a/net/vhost-user.c b/net/vhost-user.c index 24e050c..1ea2f98 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -134,25 +134,27 @@ static void net_vhost_user_event(void *opaque, int event) static int net_vhost_user_init(NetClientState *peer, const char *device, const char *name, CharDriverState *chr, - bool vhostforce) + bool vhostforce, uint32_t queues) { NetClientState *nc; VhostUserState *s; + int i; - nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); + for (i = 0; i < queues; i++) { + nc = qemu_new_net_client(&net_vhost_user_info, peer, device, name); - snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user to %s", - chr->label); + snprintf(nc->info_str, sizeof(nc->info_str), "vhost-user%d to %s", + i, chr->label); - s = DO_UPCAST(VhostUserState, nc, nc); + s = DO_UPCAST(VhostUserState, nc, nc); - /* We don't provide a receive callback */ - s->nc.receive_disabled = 1; - s->chr = chr; - s->vhostforce = vhostforce; - - qemu_chr_add_handlers(s->chr, NULL, NULL, net_vhost_user_event, s); + /* We don't provide a receive callback */ + s->nc.receive_disabled = 1; + s->chr = chr; + s->vhostforce = vhostforce; + qemu_chr_add_handlers(s->chr, NULL, NULL, net_vhost_user_event, s); + } return 0; } @@ -228,6 +230,7 @@ static int net_vhost_check_net(QemuOpts *opts, void *opaque) int net_init_vhost_user(const NetClientOptions *opts, const char *name, NetClientState *peer) { + uint32_t queues; const NetdevVhostUserOptions *vhost_user_opts; CharDriverState *chr; bool vhostforce; @@ -254,5 +257,13 @@ int net_init_vhost_user(const NetClientOptions *opts, const char *name, vhostforce = false; } - return net_vhost_user_init(peer, "vhost_user", name, chr, vhostforce); + /* number of queues for multiqueue */ + if (vhost_user_opts->has_queues) { + queues = vhost_user_opts->queues; + } else { + queues = 1; + } + + return net_vhost_user_init(peer, "vhost_user", name, chr, vhostforce, + queues); } diff --git a/qapi-schema.json b/qapi-schema.json index 9ffdcf8..aa3bb6f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2208,12 +2208,15 @@ # # @vhostforce: #optional vhost on for non-MSIX virtio guests (default: false). # +# @queues: #optional number of queues to be created for multiqueue vhost-user +# # Since 2.1 ## { 'type': 'NetdevVhostUserOptions', 'data': { 'chardev': 'str', - '*vhostforce': 'bool' } } + '*vhostforce': 'bool', + '*queues': 'uint32' } } ## # @NetClientOptions diff --git a/qemu-options.hx b/qemu-options.hx index 64af16d..23f010f 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1893,13 +1893,14 @@ The hubport netdev lets you connect a NIC to a QEMU "vlan" instead of a single netdev. @code{-net} and @code{-device} with parameter @option{vlan} create the required hub automatically. -@item -netdev vhost-user,chardev=@var{id}[,vhostforce=on|off] +@item -netdev vhost-user,chardev=@var{id}[,vhostforce=on|off][,queues=n] Establish a vhost-user netdev, backed by a chardev @var{id}. The chardev should be a unix domain socket backed one. The vhost-user uses a specifically defined protocol to pass vhost ioctl replacement messages to an application on the other end of the socket. On non-MSIX guests, the feature can be forced with -@var{vhostforce}. +@var{vhostforce}. Use 'queues=@var{n}' to specify the number of queues to +be created for multiqueue vhost-user. Example: @example