Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3813019ybb; Tue, 31 Mar 2020 12:29:18 -0700 (PDT) X-Google-Smtp-Source: APiQypKBTL2M9VY7Oc4dkrBmfUpKGVmGJkfE3RTPN+5hWQDdxogevpxm0FoKPHLfCJepbL0llgdy X-Received: by 2002:aca:eac6:: with SMTP id i189mr341876oih.164.1585682958571; Tue, 31 Mar 2020 12:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585682958; cv=none; d=google.com; s=arc-20160816; b=Yj2Ce+6Za7SdpAwDMP2W5J0MP2Kq5ChoYYgrMpoapyZBbofOACNhFbhqM1urKtUzKb BeiQWt9aPwN7RGP/QNcq35ReNcqu2ktbWgwJ3EW8RrVijXETG+JR/Mx6Vcy0o3uadWCy 6kHYwOdHmDHLb+mc8PihRac4wmixvNyL8JCpgymXxGjMaiDXyul0iVPolRujJYqqanc+ y+NNujSmhVH2NXgjer+x8h0xzqjC4JzHR+HDFAk78zVx6+EMqBoHoF5+ynCszYuPpg6u to1nijgGGJ/P/NP1XVTcM8qF8uLWMvmzyd3CKjjiyfGK6K+2CKt1DiwUda/mPwKbasKv WKBA== 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=FFJYGGwUu9B8h+W1ItcNL0y6xF04SMRsuHG1jktXLH4=; b=hWFb2McHUMPtL+pLRe2RPBkbaiSe/eiEvPCXrI1hPr8c93v4hPawRU7YIvrrQXGWV/ OmUKsH9ka3ROi7dNNHJtfVmbDd8dwkyRm9zfn0VpsHtEH9BpnEho31fcL/b97F4Sfgg7 kbGccY0q9QaGEnDKBuaf7AlHbDLggGgnEa6yz/f15gAS0Hy/wavlJ8S2jqDrLwxYAxlz ObP4TmVOMDfg4R33jIflncgilGki0mwpFEcjKCXmys1e+qvNIcm+fgCul4u8iFsCVCVT eAxIRJmk6xxnCx632fLcezn/YGim5eApjXYtlFFqfNol7QVj75VVBFRZzlWaYmD/PUJe TtXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TFta4mtk; 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 v9si7429648oib.201.2020.03.31.12.29.06; Tue, 31 Mar 2020 12:29:18 -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=TFta4mtk; 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 S1731032AbgCaT2e (ORCPT + 99 others); Tue, 31 Mar 2020 15:28:34 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:56465 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730784AbgCaT2a (ORCPT ); Tue, 31 Mar 2020 15:28:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585682909; 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=FFJYGGwUu9B8h+W1ItcNL0y6xF04SMRsuHG1jktXLH4=; b=TFta4mtkeZ8NTzg7KZ0m7lPYLBnwQUT9W9gIai2lMS0t8f8luJv6A9x3JqiIUlbHA5+/hV LkoeG+I6T4BlJww2zoiOEWaUBECPPAY3pOomRk8coVyoSBJ5hWi73pZJvtXRDnG3QGy/UO H98+RXHIOGeRDbrONjxUIO/cy9xbDIQ= 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-331-dkaiGsPsOiCWn_R3Tcx7Pw-1; Tue, 31 Mar 2020 15:28:27 -0400 X-MC-Unique: dkaiGsPsOiCWn_R3Tcx7Pw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 14FB8102CE19; Tue, 31 Mar 2020 19:28:26 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-92.ams2.redhat.com [10.36.112.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC5E78EA1A; Tue, 31 Mar 2020 19:28:23 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" Cc: "linux-kernel@vger.kernel.org" , Stephen Rothwell , kvm list , Linux Next Mailing List , "virtualization@lists.linux-foundation.org" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Christian Borntraeger , Halil Pasic , Cornelia Huck Subject: [PATCH v3 5/8] tools/virtio: Add --batch option Date: Tue, 31 Mar 2020 21:28:01 +0200 Message-Id: <20200331192804.6019-6-eperezma@redhat.com> In-Reply-To: <20200331192804.6019-1-eperezma@redhat.com> References: <20200331192804.6019-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.13 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 allow to test vhost having >1 buffers in flight Signed-off-by: Eugenio P=C3=A9rez --- tools/virtio/virtio_test.c | 47 ++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index b427def67e7e..c30de9088f3c 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #define _GNU_SOURCE #include +#include #include #include #include @@ -152,11 +153,11 @@ static void wait_for_interrupt(struct vdev_info *de= v) } =20 static void run_test(struct vdev_info *dev, struct vq_info *vq, - bool delayed, int bufs) + bool delayed, int batch, int bufs) { struct scatterlist sl; long started =3D 0, completed =3D 0; - long completed_before; + long completed_before, started_before; int r, test =3D 1; unsigned len; long long spurious =3D 0; @@ -165,28 +166,42 @@ static void run_test(struct vdev_info *dev, struct = vq_info *vq, for (;;) { virtqueue_disable_cb(vq->vq); completed_before =3D completed; + started_before =3D started; do { - if (started < bufs) { + while (started < bufs && + (started - completed) < batch) { sg_init_one(&sl, dev->buf, dev->buf_size); r =3D virtqueue_add_outbuf(vq->vq, &sl, 1, dev->buf + started, GFP_ATOMIC); - if (likely(r =3D=3D 0)) { - ++started; - if (unlikely(!virtqueue_kick(vq->vq))) + if (unlikely(r !=3D 0)) { + if (r =3D=3D -ENOSPC && + started > started_before) + r =3D 0; + else r =3D -1; + break; } - } else + + ++started; + + if (unlikely(!virtqueue_kick(vq->vq))) { + r =3D -1; + break; + } + } + + if (started >=3D bufs) r =3D -1; =20 /* Flush out completed bufs if any */ - if (virtqueue_get_buf(vq->vq, &len)) { + while (virtqueue_get_buf(vq->vq, &len)) { ++completed; r =3D 0; } =20 } while (r =3D=3D 0); - if (completed =3D=3D completed_before) + if (completed =3D=3D completed_before && started =3D=3D started_before= ) ++spurious; assert(completed <=3D bufs); assert(started <=3D bufs); @@ -244,6 +259,11 @@ const struct option longopts[] =3D { .name =3D "no-delayed-interrupt", .val =3D 'd', }, + { + .name =3D "batch", + .val =3D 'b', + .has_arg =3D required_argument, + }, { } }; @@ -255,6 +275,7 @@ static void help(void) " [--no-event-idx]" " [--no-virtio-1]" " [--delayed-interrupt]" + " [--batch=3DN]" "\n"); } =20 @@ -263,6 +284,7 @@ int main(int argc, char **argv) struct vdev_info dev; unsigned long long features =3D (1ULL << VIRTIO_RING_F_INDIRECT_DESC) | (1ULL << VIRTIO_RING_F_EVENT_IDX) | (1ULL << VIRTIO_F_VERSION_1); + long batch =3D 1; int o; bool delayed =3D false; =20 @@ -289,6 +311,11 @@ int main(int argc, char **argv) case 'D': delayed =3D true; break; + case 'b': + batch =3D strtol(optarg, NULL, 10); + assert(batch > 0); + assert(batch < (long)INT_MAX + 1); + break; default: assert(0); break; @@ -298,6 +325,6 @@ int main(int argc, char **argv) done: vdev_info_init(&dev, features); vq_info_add(&dev, 256); - run_test(&dev, &dev.vqs[0], delayed, 0x100000); + run_test(&dev, &dev.vqs[0], delayed, batch, 0x100000); return 0; } --=20 2.18.1