qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
	"Daniel P. Berrangé" <berrange@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	qemu-block@nongnu.org,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Coiby Xu" <Coiby.Xu@gmail.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>
Subject: [PULL v2 23/28] block/export: add vhost-user-blk multi-queue support
Date: Thu, 22 Oct 2020 12:27:21 +0100	[thread overview]
Message-ID: <20201022112726.736757-24-stefanha@redhat.com> (raw)
In-Reply-To: <20201022112726.736757-1-stefanha@redhat.com>

Allow the number of queues to be configured using --export
vhost-user-blk,num-queues=N. This setting should match the QEMU --device
vhost-user-blk-pci,num-queues=N setting but QEMU vhost-user-blk.c lowers
its own value if the vhost-user-blk backend offers fewer queues than
QEMU.

The vhost-user-blk-server.c code is already capable of multi-queue. All
virtqueue processing runs in the same AioContext. No new locking is
needed.

Add the num-queues=N option and set the VIRTIO_BLK_F_MQ feature bit.
Note that the feature bit only announces the presence of the num_queues
configuration space field. It does not promise that there is more than 1
virtqueue, so we can set it unconditionally.

I tested multi-queue by running a random read fio test with numjobs=4 on
an -smp 4 guest. After the benchmark finished the guest /proc/interrupts
file showed activity on all 4 virtio-blk MSI-X. The /sys/block/vda/mq/
directory shows that Linux blk-mq has 4 queues configured.

An automated test is included in the next commit.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Message-id: 20201001144604.559733-2-stefanha@redhat.com
[Fixed accidental tab characters as suggested by Markus Armbruster
--Stefan]
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 qapi/block-export.json               | 10 +++++++---
 block/export/vhost-user-blk-server.c | 24 ++++++++++++++++++------
 2 files changed, 25 insertions(+), 9 deletions(-)

diff --git a/qapi/block-export.json b/qapi/block-export.json
index 8a4ced817f..480c497690 100644
--- a/qapi/block-export.json
+++ b/qapi/block-export.json
@@ -93,11 +93,15 @@
 #        SocketAddress types are supported. Passed fds must be UNIX domain
 #        sockets.
 # @logical-block-size: Logical block size in bytes. Defaults to 512 bytes.
+# @num-queues: Number of request virtqueues. Must be greater than 0. Defaults
+#              to 1.
 #
 # Since: 5.2
 ##
 { 'struct': 'BlockExportOptionsVhostUserBlk',
-  'data': { 'addr': 'SocketAddress', '*logical-block-size': 'size' } }
+  'data': { 'addr': 'SocketAddress',
+	    '*logical-block-size': 'size',
+            '*num-queues': 'uint16'} }
 
 ##
 # @NbdServerAddOptions:
@@ -233,8 +237,8 @@
 { 'union': 'BlockExportOptions',
   'base': { 'type': 'BlockExportType',
             'id': 'str',
-	    '*fixed-iothread': 'bool',
-	    '*iothread': 'str',
+            '*fixed-iothread': 'bool',
+            '*iothread': 'str',
             'node-name': 'str',
             '*writable': 'bool',
             '*writethrough': 'bool' },
diff --git a/block/export/vhost-user-blk-server.c b/block/export/vhost-user-blk-server.c
index 286eb5fb9a..41f4933d6e 100644
--- a/block/export/vhost-user-blk-server.c
+++ b/block/export/vhost-user-blk-server.c
@@ -21,7 +21,7 @@
 #include "util/block-helpers.h"
 
 enum {
-    VHOST_USER_BLK_MAX_QUEUES = 1,
+    VHOST_USER_BLK_NUM_QUEUES_DEFAULT = 1,
 };
 struct virtio_blk_inhdr {
     unsigned char status;
@@ -242,6 +242,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)
                1ull << VIRTIO_BLK_F_DISCARD |
                1ull << VIRTIO_BLK_F_WRITE_ZEROES |
                1ull << VIRTIO_BLK_F_CONFIG_WCE |
+               1ull << VIRTIO_BLK_F_MQ |
                1ull << VIRTIO_F_VERSION_1 |
                1ull << VIRTIO_RING_F_INDIRECT_DESC |
                1ull << VIRTIO_RING_F_EVENT_IDX |
@@ -338,7 +339,9 @@ static void blk_aio_detach(void *opaque)
 
 static void
 vu_blk_initialize_config(BlockDriverState *bs,
-                           struct virtio_blk_config *config, uint32_t blk_size)
+                         struct virtio_blk_config *config,
+                         uint32_t blk_size,
+                         uint16_t num_queues)
 {
     config->capacity = bdrv_getlength(bs) >> BDRV_SECTOR_BITS;
     config->blk_size = blk_size;
@@ -346,7 +349,7 @@ vu_blk_initialize_config(BlockDriverState *bs,
     config->seg_max = 128 - 2;
     config->min_io_size = 1;
     config->opt_io_size = 1;
-    config->num_queues = VHOST_USER_BLK_MAX_QUEUES;
+    config->num_queues = num_queues;
     config->max_discard_sectors = 32768;
     config->max_discard_seg = 1;
     config->discard_sector_alignment = config->blk_size >> 9;
@@ -368,6 +371,7 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
     BlockExportOptionsVhostUserBlk *vu_opts = &opts->u.vhost_user_blk;
     Error *local_err = NULL;
     uint64_t logical_block_size;
+    uint16_t num_queues = VHOST_USER_BLK_NUM_QUEUES_DEFAULT;
 
     vexp->writable = opts->writable;
     vexp->blkcfg.wce = 0;
@@ -385,15 +389,23 @@ static int vu_blk_exp_create(BlockExport *exp, BlockExportOptions *opts,
     }
     vexp->blk_size = logical_block_size;
     blk_set_guest_block_size(exp->blk, logical_block_size);
+
+    if (vu_opts->has_num_queues) {
+        num_queues = vu_opts->num_queues;
+    }
+    if (num_queues == 0) {
+        error_setg(errp, "num-queues must be greater than 0");
+        return -EINVAL;
+    }
+
     vu_blk_initialize_config(blk_bs(exp->blk), &vexp->blkcfg,
-                               logical_block_size);
+                             logical_block_size, num_queues);
 
     blk_add_aio_context_notifier(exp->blk, blk_aio_attached, blk_aio_detach,
                                  vexp);
 
     if (!vhost_user_server_start(&vexp->vu_server, vu_opts->addr, exp->ctx,
-                                 VHOST_USER_BLK_MAX_QUEUES, &vu_blk_iface,
-                                 errp)) {
+                                 num_queues, &vu_blk_iface, errp)) {
         blk_remove_aio_context_notifier(exp->blk, blk_aio_attached,
                                         blk_aio_detach, vexp);
         return -EADDRNOTAVAIL;
-- 
2.26.2


  parent reply	other threads:[~2020-10-22 11:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 11:26 [PULL v2 00/28] Block patches Stefan Hajnoczi
2020-10-22 11:26 ` [PULL v2 01/28] block/nvme: Add driver statistics for access alignment and hw errors Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 02/28] libvhost-user: Allow vu_message_read to be replaced Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 03/28] libvhost-user: remove watch for kick_fd when de-initialize vu-dev Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 04/28] util/vhost-user-server: generic vhost user server Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 05/28] block: move logical block size check function to a common utility function Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 06/28] block/export: vhost-user block device backend server Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 07/28] MAINTAINERS: Add vhost-user block device backend server maintainer Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 08/28] util/vhost-user-server: s/fileds/fields/ typo fix Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 09/28] util/vhost-user-server: drop unnecessary QOM cast Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 10/28] util/vhost-user-server: drop unnecessary watch deletion Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 11/28] block/export: consolidate request structs into VuBlockReq Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 12/28] util/vhost-user-server: drop unused DevicePanicNotifier Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 13/28] util/vhost-user-server: fix memory leak in vu_message_read() Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 14/28] util/vhost-user-server: check EOF when reading payload Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 15/28] util/vhost-user-server: rework vu_client_trip() coroutine lifecycle Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 16/28] block/export: report flush errors Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 17/28] block/export: convert vhost-user-blk server to block export API Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 18/28] util/vhost-user-server: move header to include/ Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 19/28] util/vhost-user-server: use static library in meson.build Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 20/28] qemu-storage-daemon: avoid compiling blockdev_ss twice Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 21/28] block: move block exports to libblockdev Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 22/28] block/export: add iothread and fixed-iothread options Stefan Hajnoczi
2020-10-22 11:27 ` Stefan Hajnoczi [this message]
2020-10-22 11:27 ` [PULL v2 24/28] block/io: fix bdrv_co_block_status_above Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 25/28] block/io: bdrv_common_block_status_above: support include_base Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 26/28] block/io: bdrv_common_block_status_above: support bs == base Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 27/28] block/io: fix bdrv_is_allocated_above Stefan Hajnoczi
2020-10-22 11:27 ` [PULL v2 28/28] iotests: add commit top->base cases to 274 Stefan Hajnoczi
2020-10-22 12:12 ` [PULL v2 00/28] Block patches no-reply
2020-10-22 14:09 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201022112726.736757-24-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).