Received: from eggs.gnu.org ([2001:4830:134:3::10]:56797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKxhK-0006B7-P1 for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKxhI-0006hy-0k for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58305) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKxhH-0006ht-Os for qemu-devel@nongnu.org; Wed, 06 Jul 2016 21:01:43 -0400 From: marcandre.lureau@redhat.com Date: Thu, 7 Jul 2016 03:00:51 +0200 Message-Id: <20160707010053.28008-28-marcandre.lureau@redhat.com> In-Reply-To: <20160707010053.28008-1-marcandre.lureau@redhat.com> References: <20160707010053.28008-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v4 27/29] tests: add a simple /vhost-user/multiqueue test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mukawa@igel.co.jp, yuanhan.liu@linux.intel.com, victork@redhat.com, jonshin@cisco.com, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau This test just checks that 2 virtio-net queues can be setup over vhost-user and waits for them to be started. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/Makefile.include | 2 +- tests/vhost-user-test.c | 108 ++++++++++++++++++++++++++++++++++++++++++= +++++- 2 files changed, 107 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 2010b11..3cb57b8 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -611,7 +611,7 @@ tests/usb-hcd-ehci-test$(EXESUF): tests/usb-hcd-ehci-= test.o $(libqos-usb-obj-y) tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb= -obj-y) tests/pc-cpu-test$(EXESUF): tests/pc-cpu-test.o tests/postcopy-test$(EXESUF): tests/postcopy-test.o -tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu= -timer.o $(qtest-obj-y) $(test-io-obj-y) +tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu= -timer.o $(qtest-obj-y) $(test-io-obj-y) $(libqos-pc-obj-y) $(libqos-virt= io-obj-y) tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket= _scm_helper.o tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o $(test-util-obj-y) tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test= -block-obj-y) diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 6595243..aedbea6 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -16,6 +16,11 @@ #include "sysemu/char.h" #include "sysemu/sysemu.h" =20 +#include "libqos/pci-pc.h" +#include "libqos/virtio-pci.h" +#include "libqos/malloc-pc.h" +#include "hw/virtio/virtio-net.h" + #include #include #include @@ -46,6 +51,7 @@ #define VHOST_MEMORY_MAX_NREGIONS 8 =20 #define VHOST_USER_F_PROTOCOL_FEATURES 30 +#define VHOST_USER_PROTOCOL_F_MQ 0 #define VHOST_USER_PROTOCOL_F_LOG_SHMFD 1 =20 #define VHOST_LOG_PAGE 0x1000 @@ -68,6 +74,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_VRING_ERR =3D 14, VHOST_USER_GET_PROTOCOL_FEATURES =3D 15, VHOST_USER_SET_PROTOCOL_FEATURES =3D 16, + VHOST_USER_GET_QUEUE_NUM =3D 17, VHOST_USER_SET_VRING_ENABLE =3D 18, VHOST_USER_MAX } VhostUserRequest; @@ -132,6 +139,7 @@ typedef struct TestServer { int log_fd; uint64_t rings; bool test_fail; + int queues; } TestServer; =20 static const char *tmpfs; @@ -253,6 +261,9 @@ static void chr_read(void *opaque, const uint8_t *buf= , int size) msg.size =3D sizeof(m.payload.u64); msg.payload.u64 =3D 0x1ULL << VHOST_F_LOG_ALL | 0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES; + if (s->queues > 1) { + msg.payload.u64 |=3D 0x1ULL << VIRTIO_NET_F_MQ; + } p =3D (uint8_t *) &msg; qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); break; @@ -267,6 +278,9 @@ static void chr_read(void *opaque, const uint8_t *buf= , int size) msg.flags |=3D VHOST_USER_REPLY_MASK; msg.size =3D sizeof(m.payload.u64); msg.payload.u64 =3D 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; + if (s->queues > 1) { + msg.payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_MQ; + } p =3D (uint8_t *) &msg; qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); break; @@ -279,7 +293,7 @@ static void chr_read(void *opaque, const uint8_t *buf= , int size) p =3D (uint8_t *) &msg; qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); =20 - assert(msg.payload.state.index < 2); + assert(msg.payload.state.index < s->queues * 2); s->rings &=3D ~(0x1ULL << msg.payload.state.index); break; =20 @@ -319,10 +333,18 @@ static void chr_read(void *opaque, const uint8_t *b= uf, int size) break; =20 case VHOST_USER_SET_VRING_BASE: - assert(msg.payload.state.index < 2); + assert(msg.payload.state.index < s->queues * 2); s->rings |=3D 0x1ULL << msg.payload.state.index; break; =20 + case VHOST_USER_GET_QUEUE_NUM: + msg.flags |=3D VHOST_USER_REPLY_MASK; + msg.size =3D sizeof(m.payload.u64); + msg.payload.u64 =3D s->queues; + p =3D (uint8_t *) &msg; + qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); + break; + default: break; } @@ -369,6 +391,7 @@ static TestServer *test_server_new(const gchar *name) g_cond_init(&server->data_cond); =20 server->log_fd =3D -1; + server->queues =3D 1; =20 return server; } @@ -722,6 +745,86 @@ static void test_connect_fail(void) =20 #endif =20 +static QVirtioPCIDevice *virtio_net_pci_init(QPCIBus *bus, int slot) +{ + QVirtioPCIDevice *dev; + + dev =3D qvirtio_pci_device_find(bus, VIRTIO_ID_NET); + g_assert(dev !=3D NULL); + g_assert_cmphex(dev->vdev.device_type, =3D=3D, VIRTIO_ID_NET); + + qvirtio_pci_device_enable(dev); + qvirtio_reset(&qvirtio_pci, &dev->vdev); + qvirtio_set_acknowledge(&qvirtio_pci, &dev->vdev); + qvirtio_set_driver(&qvirtio_pci, &dev->vdev); + + return dev; +} + +static void driver_init(const QVirtioBus *bus, QVirtioDevice *dev) +{ + uint32_t features; + + features =3D qvirtio_get_features(bus, dev); + features =3D features & ~(QVIRTIO_F_BAD_FEATURE | + (1u << VIRTIO_RING_F_INDIRECT_DESC) | + (1u << VIRTIO_RING_F_EVENT_IDX)); + qvirtio_set_features(bus, dev, features); + + qvirtio_set_driver_ok(bus, dev); +} + +#define PCI_SLOT 0x04 + +static void test_multiqueue(void) +{ + const int queues =3D 2; + TestServer *s =3D test_server_new("mq"); + QVirtioPCIDevice *dev; + QPCIBus *bus; + QVirtQueuePCI *vq[queues * 2]; + QGuestAllocator *alloc; + char *cmd; + int i; + + s->queues =3D queues; + test_server_listen(s); + + cmd =3D g_strdup_printf(QEMU_CMD_ACCEL QEMU_CMD_MEM QEMU_CMD_CHR + QEMU_CMD_NETDEV ",queues=3D%d " + "-device virtio-net-pci,netdev=3Dnet0,mq=3Don,= vectors=3D%d", + 512, 512, root, s->chr_name, + s->socket_path, "", s->chr_name, + queues, queues * 2 + 2); + qtest_start(cmd); + g_free(cmd); + + bus =3D qpci_init_pc(); + dev =3D virtio_net_pci_init(bus, PCI_SLOT); + + alloc =3D pc_alloc_init(); + for (i =3D 0; i < queues * 2; i++) { + vq[i] =3D (QVirtQueuePCI *)qvirtqueue_setup(&qvirtio_pci, &dev->= vdev, + alloc, i); + } + + driver_init(&qvirtio_pci, &dev->vdev); + wait_for_rings_started(s, queues * 2); + + /* End test */ + for (i =3D 0; i < queues * 2; i++) { + qvirtqueue_cleanup(&qvirtio_pci, &vq[i]->vq, alloc); + } + pc_alloc_uninit(alloc); + qvirtio_pci_device_disable(dev); + g_free(dev->pdev); + g_free(dev); + qpci_free_pc(bus); + qtest_end(); + + test_server_free(s); +} + int main(int argc, char **argv) { QTestState *s =3D NULL; @@ -766,6 +869,7 @@ int main(int argc, char **argv) =20 qtest_add_data_func("/vhost-user/read-guest-mem", server, read_guest= _mem); qtest_add_func("/vhost-user/migrate", test_migrate); + qtest_add_func("/vhost-user/multiqueue", test_multiqueue); #ifdef CONFIG_HAS_GLIB_SUBPROCESS_TESTS qtest_add_func("/vhost-user/reconnect/subprocess", test_reconnect_subprocess); --=20 2.9.0