Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp682754ybb; Fri, 3 Apr 2020 09:53:43 -0700 (PDT) X-Google-Smtp-Source: APiQypLWbxmVx761OGeSq/gWv7Uq6vvk22KpdMy5oNeJa5n5qk39/bpIaBhUC+SbYfDPP2UmFeWO X-Received: by 2002:a9d:1b6d:: with SMTP id l100mr6697632otl.70.1585932822993; Fri, 03 Apr 2020 09:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585932822; cv=none; d=google.com; s=arc-20160816; b=gDU4WNbXyIYqmsGeXFKE831mvtbWQOMB4Nty1TdWcJfVPJC11MAkuj+b1ETLMiO9Vi s4JG6RLFd1ADtrBRJl2vdmYdAoyxR0QT0VBsUr5C1TWocPBukqCZmp0VkydijTAA3AUW TUY8YVBW/70x28WHGrwB1E3P6rawJw2NtnlcDySyBu2By5eGqPuwRvsb+YQRWko+JdFt YBmyU2RbZKu8KaH/aQoC1vlOSypiXno1lhqGjeDZNhQKf/5baQIrCCudXaH3vJb1krxc WmQz2/tbJ4fKEy5E0AfDih+0AdET6tCmsJQb/wW/71EaZI2WFakT4NYuomVsuMzKU7p3 MBGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dbrbXbuWyZrlOy+yoiqtbmywqt31syCjQq35ukfw0g0=; b=qAEPL+6ozlg/ihzIdi1y31/r6LpUnBXugLcBBsAXBdAF2h9U0GsB9rlgIwakAt7M5G 3NM4dlhIs+dYs2HR8GaWzY4PR9mXMkNU/tbF9a+jpILKPiQNGWqBCcE2jp/tJd5Ohlmn /yCG4TC8lxV16S8EuN5lIkON7U+VZZ1HoqkU3RG3+DN1qh/wwPcZULkb4QqoMvNFlXCU tVrJcRiXHVoCpYf0xzlE96s08Kffdrkfs+LNCQD8jDOdJTY/Xu6KRNR1UtYI3t7/8hN9 yDCC1kt5TPWRrvxPKNcb6bhgijebJBzOKshomInGpCoE64xOfY3NXAGL6dzEJLYZv8GW 75Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=I8KRA969; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w203si3941980oig.54.2020.04.03.09.53.30; Fri, 03 Apr 2020 09:53:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=I8KRA969; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404681AbgDCQwF (ORCPT + 99 others); Fri, 3 Apr 2020 12:52:05 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:58755 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2404658AbgDCQwC (ORCPT ); Fri, 3 Apr 2020 12:52:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585932721; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dbrbXbuWyZrlOy+yoiqtbmywqt31syCjQq35ukfw0g0=; b=I8KRA969fTic+vT08w4EJflld+8yqAWLSNA1wIkPYpld2Turaz2y+iTf9egzQB1E3FizyS 8ehMk1YQvhNoKTZSV+sNXZCZ99LCipXzFEC/kRpqOMNIXYxy2oaJGULWWpy5A9YjodTrG2 jKgcGepQPu05sh6pWf9d5sOFtvD3iKE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-292-Z_cMZfXAOEaxuRn1K_5rog-1; Fri, 03 Apr 2020 12:51:56 -0400 X-MC-Unique: Z_cMZfXAOEaxuRn1K_5rog-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7DD48018A8; Fri, 3 Apr 2020 16:51:54 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-28.ams2.redhat.com [10.36.113.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 76E8D18A85; Fri, 3 Apr 2020 16:51:52 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" Cc: kvm list , "virtualization@lists.linux-foundation.org" , Linux Next Mailing List , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Stephen Rothwell , Cornelia Huck , Halil Pasic , "linux-kernel@vger.kernel.org" , Christian Borntraeger Subject: [PATCH 7/8] tools/virtio: Reset index in virtio_test --reset. Date: Fri, 3 Apr 2020 18:51:18 +0200 Message-Id: <20200403165119.5030-8-eperezma@redhat.com> In-Reply-To: <20200403165119.5030-1-eperezma@redhat.com> References: <20200403165119.5030-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This way behavior for vhost is more like a VM. Signed-off-by: Eugenio P=C3=A9rez --- tools/virtio/virtio_test.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index 7b7829e510c0..82902fc3ba2a 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -20,7 +20,6 @@ #include "../../drivers/vhost/test.h" =20 #define RANDOM_BATCH -1 -#define RANDOM_RESET -1 =20 /* Unused */ void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end; @@ -49,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) { @@ -174,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 @@ -224,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; } @@ -249,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"; @@ -312,7 +333,7 @@ static void help(void) " [--no-virtio-1]" " [--delayed-interrupt]" " [--batch=3Drandom/N]" - " [--reset=3Drandom/N]" + " [--reset=3DN]" "\n"); } =20 @@ -360,11 +381,9 @@ int main(int argc, char **argv) case 'r': if (!optarg) { reset =3D 1; - } else if (0 =3D=3D strcmp(optarg, "random")) { - reset =3D RANDOM_RESET; } else { reset =3D strtol(optarg, NULL, 10); - assert(reset >=3D 0); + assert(reset > 0); assert(reset < (long)INT_MAX + 1); } break; --=20 2.18.1