Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1552854ybz; Sat, 18 Apr 2020 03:28:44 -0700 (PDT) X-Google-Smtp-Source: APiQypLn/zDxjcNG4cCjOH1E342zYhT03viS6PRfjQyo9XDB7gQUGMblJwbtkYNhjyZhr115E374 X-Received: by 2002:a17:906:90cc:: with SMTP id v12mr7184784ejw.211.1587205724502; Sat, 18 Apr 2020 03:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587205724; cv=none; d=google.com; s=arc-20160816; b=qOYx4fSybCRgEucknV4QGyk92k/eb3YLs32JP/gm1FRh4wYsmtfJvNCaRykTjUFIA4 LCfRshKoW3LEJ1mySi8bsfTfr5wTUOiSS4VGl5KZrSq4w88HyYo5N7MvqVVOK+bCQff5 npXUVz5mO4gvQR0+EdLYwJWU5pSoW6K3wimmuUZVRT4dKS29ttjuCCb34BaBo+WRfPwl S3enVAYPLeqhWGpdgBdSdAT9V1ACh3gohAxhd+BDNEIENlybWkCBOoPZYsmWt/apJPj0 HnIP3BjIlNPEvkK7zbg9lqi8CtmZs/DgSjCDqAbqzdSiURRKizBiuwlAt/XZ/QmVVnlM W3Uw== 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=BDGQ+vnTVFGn9TVgolSt1bfIz8O9bB41pVMjf36t0iE=; b=NH+/jvrJeSej6hVHSQ+RwNk/pKvSyt46GgnYEny4/2Fv+4kt5Utegex+rbxyDE+s8W K5GOgsKKFUX+9c4mP19H+5z8TWy+9wO3VHeAt+0sagYuPxoAsUBMxfn2u84kdzxiGEtP g7zowwn6qmbPmRAtSLo9RT8MhC/Flwg997u6HZ9dbP+ayRGNlFaUFGsvLJUSisZrUmGE AMrZkqohALIVgj5XkfbQMM9p7g0OUAR8HU9etC3fqV2Qh1k8auzII7HWKz248hLga/fK smz1VVt+gmugILGXmRYH3cEOnJvLRflllJ+WCPJ8u2uduufL3Q/TsxR28sk30BOlxWyR crtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KmsMPGvS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v26si8607348ejq.460.2020.04.18.03.28.22; Sat, 18 Apr 2020 03:28:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KmsMPGvS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1725994AbgDRKYn (ORCPT + 99 others); Sat, 18 Apr 2020 06:24:43 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:25880 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725990AbgDRKWn (ORCPT ); Sat, 18 Apr 2020 06:22:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587205361; 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=BDGQ+vnTVFGn9TVgolSt1bfIz8O9bB41pVMjf36t0iE=; b=KmsMPGvSIvRD8EijtQ8+y4fWVAUZApAYy2TOMkZ0LBQyNDsrxyIE5Q5xPfUz69EAHXaus7 IQM+JqqncAP0q5DhHVHcGQgvHOkgAc/YaZrmUACH/K0Y8PG3P9XlXcQ0OIZ47T7y0p8DFU WejhZ9D8cfShL2UcoSoNaWcge+M+YTo= 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-177-C5AFofX2OT-XupaHthE7JA-1; Sat, 18 Apr 2020 06:22:35 -0400 X-MC-Unique: C5AFofX2OT-XupaHthE7JA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1D43B8017F6; Sat, 18 Apr 2020 10:22:34 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-94.ams2.redhat.com [10.36.112.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6A101036D1B; Sat, 18 Apr 2020 10:22:29 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= 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 Subject: [PATCH v3 2/8] tools/virtio: Add --batch option Date: Sat, 18 Apr 2020 12:22:11 +0200 Message-Id: <20200418102217.32327-3-eperezma@redhat.com> In-Reply-To: <20200418102217.32327-1-eperezma@redhat.com> References: <20200418102217.32327-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 Link: https://lore.kernel.org/r/20200401183118.8334-5-eperezma@redhat.com Signed-off-by: Michael S. Tsirkin --- 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