From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= Subject: [PATCH v3 7/8] tools/virtio: Reset index in virtio_test --reset. Date: Sat, 18 Apr 2020 12:22:16 +0200 Message-ID: <20200418102217.32327-8-eperezma@redhat.com> References: <20200418102217.32327-1-eperezma@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20200418102217.32327-1-eperezma@redhat.com> Sender: kvm-owner@vger.kernel.org To: "Michael S. Tsirkin" Cc: "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Halil Pasic , Cornelia Huck , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Christian Borntraeger , kvm list , Stephen Rothwell , Linux Next Mailing List List-Id: virtualization@lists.linuxfoundation.org This way behavior for vhost is more like a VM. Signed-off-by: Eugenio P=C3=A9rez --- tools/virtio/virtio_test.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index bc16c818bda3..82902fc3ba2a 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -48,6 +48,7 @@ struct vdev_info { =20 static const struct vhost_vring_file no_backend =3D { .fd =3D -1 }, backend =3D { .fd =3D 1 }; +static const struct vhost_vring_state null_state =3D {}; =20 bool vq_notify(struct virtqueue *vq) { @@ -173,14 +174,19 @@ static void run_test(struct vdev_info *dev, struct = vq_info *vq, unsigned len; long long spurious =3D 0; const bool random_batch =3D batch =3D=3D RANDOM_BATCH; + r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); assert(r >=3D 0); + if (!reset_n) { + next_reset =3D INT_MAX; + } + for (;;) { virtqueue_disable_cb(vq->vq); completed_before =3D completed; started_before =3D started; do { - const bool reset =3D reset_n && completed > next_reset; + const bool reset =3D completed > next_reset; if (random_batch) batch =3D (random() % vq->vring.num) + 1; =20 @@ -223,10 +229,24 @@ static void run_test(struct vdev_info *dev, struct = vq_info *vq, } =20 if (reset) { + struct vhost_vring_state s =3D { .index =3D 0 }; + + vq_reset(vq, vq->vring.num, &dev->vdev); + + r =3D ioctl(dev->control, VHOST_GET_VRING_BASE, + &s); + assert(!r); + + s.num =3D 0; + r =3D ioctl(dev->control, VHOST_SET_VRING_BASE, + &null_state); + assert(!r); + r =3D ioctl(dev->control, VHOST_TEST_SET_BACKEND, &backend); assert(!r); =20 + started =3D completed; while (completed > next_reset) next_reset +=3D completed; } @@ -248,7 +268,9 @@ static void run_test(struct vdev_info *dev, struct vq= _info *vq, test =3D 0; r =3D ioctl(dev->control, VHOST_TEST_RUN, &test); assert(r >=3D 0); - fprintf(stderr, "spurious wakeups: 0x%llx\n", spurious); + fprintf(stderr, + "spurious wakeups: 0x%llx started=3D0x%lx completed=3D0x%lx\n", + spurious, started, completed); } =20 const char optstring[] =3D "h"; --=20 2.18.1